Skip to content

Commit 307b262

Browse files
committed
Add modules_metadata to dump
Utilizes ExtractModuleMetadata functionality and provides it as is
1 parent dd476c2 commit 307b262

File tree

4 files changed

+77
-6
lines changed

4 files changed

+77
-6
lines changed

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,11 @@ This command supports the following arguments:
1414
* ``metatags``: Dump metatags.
1515
* ``atomics``: Dump atomics.
1616
* ``pulse_bindings``: Dump pulse bindings.
17+
* ``module_metadata``: Dump module metadata. Only windows is currently supported!
1718
* ``split_atomics``: Splits templated atomic names and leaves only base name leaving templated stuff. (Makes ``CUtlVector<int>`` to be named as ``CUtlVector`` for example).
1819
* ``ignore_parents``: Ignores parent scope decls and removes inlined structs/classes converting them from A::B to A__B.
1920
* ``apply_netvar_overrides``: Applies netvar overrides to types (MNetworkVarTypeOverride metatags).
20-
* ``all``: Shorthand version of providing ``metatags``, ``atomics`` and ``pulse_bindings`` flags.
21+
* ``all``: Shorthand version of providing ``metatags``, ``atomics``, ``pulse_bindings`` and ``module_metadata`` flags.
2122
* ``for_cpp``: Use optimal flags for cpp generation later, similar to providing ``split_atomics``, ``ignore_parents`` and ``apply_netvar_overrides`` flags.
2223
> [!NOTE]
2324
> Pulse bindings are heavily under development by valve, so these are expected to break with each engine update in the supported game list, and would require manual update to the code most likely!
@@ -231,6 +232,10 @@ class CUtlAbstractDelegate { char pad[16]; };
231232
* ``default_value``: Return default value (If it has one set);
232233
* Can also have metatags at ``traits/metatags``;
233234
* Can also have metatags at ``traits/metatags``;
235+
* ``modules_metadata``: An array of module metadata provided by game binaries in the following format:
236+
* ``module_name``: Name of the module;
237+
* ``additional_info``: Additional info provided by the module;
238+
* Other data is provided as is from the game binaries and may contain entries such as ``resource_manifests``, ``pulse_fingerprints``, ``pulse_bindings``, etc.
234239

235240
### Metatags
236241

src/pulse_metadata.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ enum PulseValueType_t : int32
4646
PVAL_TEST_HANDLE = 27,
4747
PVAL_ARRAY = 28,
4848
PVAL_TYPESAFE_INT64 = 29,
49-
PVAL_COUNT = 30,
49+
PVAL_PARTICLE_EHANDLE = 30,
50+
PVAL_COUNT = 31,
5051
};
5152

5253
struct PulseParamType
@@ -105,6 +106,8 @@ struct PulseParamType
105106
case PVAL_SCHEMA_ENUM: ss << "enum {" << m_LibraryClass << "}"; break;
106107
case PVAL_PANORAMA_PANEL_HANDLE: ss << "panorama_panel_handle"; break;
107108
case PVAL_TEST_HANDLE: ss << "testhandle<" << (m_LibraryClass ? m_LibraryClass : "") << ">"; break;
109+
case PVAL_PARTICLE_EHANDLE: ss << "particle_ehandle"; break;
110+
108111
default:
109112
{
110113
if(SchemaReader::IsVerboseLogging())

src/schemareader.cpp

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@
88
#include <filesystem>
99
#include <ctime>
1010

11+
#if PLATFORM_WINDOWS
12+
#include <windows.h>
13+
#include <tlhelp32.h>
14+
#endif
15+
1116
CSchemaSystem *SchemaReader::SchemaSystem()
1217
{
1318
static CSchemaSystem *s_SchemaSystem = nullptr;
@@ -163,6 +168,7 @@ void SchemaReader::ReadSchema( uint32 flags )
163168
ReadDeclEnums();
164169
ReadAtomics();
165170
ReadPulseBindings();
171+
ReadModuleMetadata();
166172
}
167173

168174
void SchemaReader::SetOutDir( const std::filesystem::path &out_dir )
@@ -799,6 +805,58 @@ void SchemaReader::ReadPulseBindings()
799805
ReadPulseDomainsInfo( pulse_bindings, domains );
800806
}
801807

808+
void SchemaReader::ReadModuleMetadata()
809+
{
810+
if(!IsDumpingModuleMetadata())
811+
return;
812+
813+
#ifndef PLATFORM_WINDOWS
814+
META_CONPRINTF( "Reading module metadata is only supported on windows, skipping...\n" );
815+
#else
816+
META_CONPRINTF( "Reading module metadata...\n" );
817+
818+
auto modules_metadata = GetRoot()->FindOrCreateMember( "modules_metadata" );
819+
modules_metadata->SetArrayElementCount( 0 );
820+
821+
HANDLE snapshot = CreateToolhelp32Snapshot( TH32CS_SNAPMODULE | TH32CS_SNAPMODULE32, GetCurrentProcessId() );
822+
823+
if(snapshot != INVALID_HANDLE_VALUE)
824+
{
825+
MODULEENTRY32 module_entry = { sizeof( module_entry ) };
826+
if(Module32First( snapshot, &module_entry ))
827+
{
828+
do
829+
{
830+
if(module_entry.hModule)
831+
{
832+
auto func = (KeyValues3 * (*)(CUtlString *))GetProcAddress( module_entry.hModule, "ExtractModuleMetadata" );
833+
if(func)
834+
{
835+
CUtlString additional_info;
836+
auto metadata = func( &additional_info );
837+
838+
if(metadata->IsNull())
839+
continue;
840+
841+
auto entry = modules_metadata->ArrayAddElementToTail();
842+
843+
*entry = *metadata;
844+
entry->SetMemberString( "module_name", module_entry.szModule );
845+
846+
if(!additional_info.IsEmpty())
847+
entry->SetMemberString( "additional_info", additional_info );
848+
}
849+
850+
}
851+
852+
} while(Module32Next( snapshot, &module_entry ));
853+
}
854+
855+
CloseHandle( snapshot );
856+
}
857+
#endif
858+
}
859+
802860
CSchemaType_DeclaredClass *SchemaReader::FindSchemaTypeInTypeScopes( const char *name )
803861
{
804862
auto ci = SchemaSystem()->FindClassByScopedName( name ).Get();

src/schemareader.h

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ class SchemaReader
5151
static bool IsDumpingMetaTags() { return (s_Flags & SR_DUMP_METATAGS) != 0; }
5252
static bool IsDumpingAtomics() { return (s_Flags & SR_DUMP_ATOMICS) != 0; }
5353
static bool IsDumpingPulseBindings() { return (s_Flags & SR_DUMP_PULSE_BINDINGS) != 0; }
54+
static bool IsDumpingModuleMetadata() { return (s_Flags & SR_DUMP_MODULE_METADATA) != 0; }
5455
static bool IsSplittingAtomicNames() { return (s_Flags & SR_SPLIT_ATOMIC_NAMES) != 0; }
5556
static bool IsIgnoringParentScopes() { return (s_Flags & SR_IGNORE_PARENT_SCOPE) != 0; }
5657
static bool IsApplyingNetVarOverrides() { return (s_Flags & SR_APPLY_NETVAR_OVERRIDES) != 0; }
@@ -71,6 +72,7 @@ class SchemaReader
7172
void ReadMetaTags( KeyValues3 *root, SchemaMetadataEntryData_t *data, int count, bool append_traits = false );
7273
void ReadFlags( KeyValues3 *root, CSchemaType *type );
7374
void ReadPulseBindings();
75+
void ReadModuleMetadata();
7476

7577
template <typename METATAG>
7678
void ReadPulseDomains( KeyValues3 *root, std::map<std::string, KeyValues3 *> &domains );
@@ -131,15 +133,17 @@ class SchemaReader
131133
// Dump pulse bindings
132134
SR_DUMP_PULSE_BINDINGS = (1 << 5),
133135

136+
SR_DUMP_MODULE_METADATA = (1 << 6),
137+
134138
// Splits templated atomic names and leaves only base name leaving templated stuff
135-
SR_SPLIT_ATOMIC_NAMES = (1 << 6),
139+
SR_SPLIT_ATOMIC_NAMES = (1 << 7),
136140

137141
// Ignores parent scope decls and removes inlined structs/classes
138142
// converting them from A::B to A__B
139-
SR_IGNORE_PARENT_SCOPE = (1 << 7),
143+
SR_IGNORE_PARENT_SCOPE = (1 << 8),
140144

141145
// Applies netvar overrides to types (MNetworkVarTypeOverride metatags)
142-
SR_APPLY_NETVAR_OVERRIDES = (1 << 8)
146+
SR_APPLY_NETVAR_OVERRIDES = (1 << 9)
143147
};
144148

145149
struct DumpFlags_t
@@ -157,12 +161,13 @@ class SchemaReader
157161
{ SR_DUMP_METATAGS, "metatags", "has_metatags", "Dump metatags" },
158162
{ SR_DUMP_ATOMICS, "atomics", "has_atomics", "Dump atomics" },
159163
{ SR_DUMP_PULSE_BINDINGS, "pulse_bindings", "has_pulse_bindings", "Dump pulse bindings" },
164+
{ SR_DUMP_MODULE_METADATA, "module_metadata", "has_module_metadata", "Dump module metadata" },
160165
{ SR_SPLIT_ATOMIC_NAMES, "split_atomics", "atomic_names_split", "Splits templated atomic names and leaves only base name leaving templated stuff" },
161166
{ SR_IGNORE_PARENT_SCOPE, "ignore_parents", "no_parent_scope", "Ignores parent scope decls and removes inlined structs/classes converting them from A::B to A__B" },
162167
{ SR_APPLY_NETVAR_OVERRIDES, "apply_netvar_overrides", "netvars_overriden", "Applies netvar overrides to types (MNetworkVarTypeOverride metatags)" },
163168

164169
// Supplementary definitions
165-
{ SR_DUMP_METATAGS | SR_DUMP_ATOMICS | SR_DUMP_PULSE_BINDINGS, "all", nullptr, "Dumps everything" },
170+
{ SR_DUMP_METATAGS | SR_DUMP_ATOMICS | SR_DUMP_PULSE_BINDINGS | SR_DUMP_MODULE_METADATA, "all", nullptr, "Dumps everything" },
166171
{ SR_SPLIT_ATOMIC_NAMES | SR_IGNORE_PARENT_SCOPE | SR_APPLY_NETVAR_OVERRIDES, "for_cpp", nullptr, "Use optimal flags for cpp generation later" },
167172
};
168173
};

0 commit comments

Comments
 (0)