Skip to content

Commit 4693baf

Browse files
committed
Add CUtlHashtable and KeyValues3
1 parent a1aa57c commit 4693baf

2 files changed

Lines changed: 71 additions & 11 deletions

File tree

scripts/find-missing-types.ts

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,21 @@ const schemasDir = resolve(__dirname, "../schemas");
1212

1313
const intrinsicNames = new Set(intrinsicDeclarations.keys());
1414

15+
type MissingTypeInfo = { sources: Set<string>; count: number };
16+
1517
function collectMissing(
1618
type: SchemaFieldType,
17-
atomics: Map<string, Set<string>>,
18-
declared: Map<string, Set<string>>,
19+
atomics: Map<string, MissingTypeInfo>,
20+
declared: Map<string, MissingTypeInfo>,
1921
knownKeys: Set<string>,
2022
source: string,
2123
) {
2224
switch (type.category) {
2325
case "atomic":
2426
if (!intrinsicNames.has(type.name)) {
25-
if (!atomics.has(type.name)) atomics.set(type.name, new Set());
26-
atomics.get(type.name)!.add(source);
27+
if (!atomics.has(type.name)) atomics.set(type.name, { sources: new Set(), count: 0 });
28+
atomics.get(type.name)!.sources.add(source);
29+
atomics.get(type.name)!.count++;
2730
}
2831
if (type.inner) collectMissing(type.inner, atomics, declared, knownKeys, source);
2932
if (type.inner2) collectMissing(type.inner2, atomics, declared, knownKeys, source);
@@ -32,8 +35,9 @@ function collectMissing(
3235
case "declared_enum": {
3336
const key = declarationKey(type.module, type.name);
3437
if (!knownKeys.has(key)) {
35-
if (!declared.has(key)) declared.set(key, new Set());
36-
declared.get(key)!.add(source);
38+
if (!declared.has(key)) declared.set(key, { sources: new Set(), count: 0 });
39+
declared.get(key)!.sources.add(source);
40+
declared.get(key)!.count++;
3741
}
3842
break;
3943
}
@@ -47,8 +51,8 @@ function collectMissing(
4751
}
4852
}
4953

50-
const missingAtomics = new Map<string, Set<string>>();
51-
const missingDeclared = new Map<string, Set<string>>();
54+
const missingAtomics = new Map<string, MissingTypeInfo>();
55+
const missingDeclared = new Map<string, MissingTypeInfo>();
5256

5357
for (const game of GAME_LIST) {
5458
const data = await readGzippedJson<SchemasJson>(`${schemasDir}/${game.id}.json.gz`);
@@ -67,14 +71,14 @@ for (const game of GAME_LIST) {
6771
}
6872
}
6973

70-
function printSection(title: string, entries: Map<string, Set<string>>) {
74+
function printSection(title: string, entries: Map<string, MissingTypeInfo>) {
7175
const sorted = [...entries.entries()].sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0));
7276
if (sorted.length === 0) {
7377
console.log(`No ${title} found.`);
7478
} else {
7579
console.log(`${sorted.length} ${title}:\n`);
76-
for (const [name, sources] of sorted) {
77-
console.log(` ${name} [${[...sources].join(", ")}]`);
80+
for (const [name, info] of sorted) {
81+
console.log(` (${info.count}) ${name} [${[...info.sources].join(", ")}]`);
7882
}
7983
}
8084
}

src/data/intrinsics.ts

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,62 @@ const types: IntrinsicDef[] = [
286286
],
287287
size: 24,
288288
},
289+
{
290+
name: "CUtlHashtable",
291+
fields: [
292+
{ name: "m_table", offset: 0, type: { category: "ptr", inner: b("void") } },
293+
{ name: "m_nUsed", offset: 24, type: b("int32") },
294+
{ name: "m_nTableSize", offset: 28, type: b("int32") },
295+
{ name: "m_nMinSize", offset: 32, type: b("int32") },
296+
{ name: "m_bSizeLocked", offset: 36, type: b("bool") },
297+
{ name: "m_eq", offset: 40, type: { category: "ptr", inner: b("void") } },
298+
{ name: "m_hash", offset: 48, type: { category: "ptr", inner: b("void") } },
299+
],
300+
size: 56,
301+
},
302+
303+
// ---- KeyValues3 types ----
304+
305+
{
306+
// Other aliases: CKV3MemberNameSet
307+
name: "KeyValues3",
308+
fields: [
309+
{ name: "m_bContextIndependent", offset: 0, type: bf(1) },
310+
{ name: "m_bFreeArrayMemory", offset: 0, type: bf(1) },
311+
{ name: "m_TypeEx", offset: 0, type: bf(8) },
312+
{ name: "m_SubType", offset: 0, type: bf(8) },
313+
{ name: "m_nFlags", offset: 0, type: bf(8) },
314+
{ name: "m_nClusterElement", offset: 0, type: bf(16) },
315+
{ name: "m_nNumArrayElements", offset: 0, type: bf(5) },
316+
{ name: "m_Data", offset: 8, type: b("uint64") },
317+
],
318+
size: 16,
319+
},
320+
{
321+
name: "CKeyValues3Array",
322+
fields: [
323+
{ name: "m_nClusterElement", offset: 0, type: b("int32") },
324+
{ name: "m_nAllocatedChunks", offset: 4, type: b("int32") },
325+
{ name: "m_nCount", offset: 8, type: b("int32") },
326+
{ name: "m_nInitialSize", offset: 12, type: b("uint8") },
327+
{ name: "m_bIsDynamicallySized", offset: 13, type: b("bool") },
328+
{ name: "m_pDynamicElements", offset: 16, type: { category: "ptr", inner: b("void") } },
329+
],
330+
size: 64,
331+
},
332+
{
333+
name: "CKeyValues3Table",
334+
fields: [
335+
{ name: "m_nClusterElement", offset: 0, type: b("int32") },
336+
{ name: "m_nAllocatedChunks", offset: 4, type: b("int32") },
337+
{ name: "m_pFastSearch", offset: 8, type: { category: "ptr", inner: b("void") } },
338+
{ name: "m_nCount", offset: 16, type: b("int32") },
339+
{ name: "m_nInitialSize", offset: 20, type: b("uint8") },
340+
{ name: "m_bIsDynamicallySized", offset: 21, type: b("bool") },
341+
{ name: "m_pDynamicBuffer", offset: 24, type: { category: "ptr", inner: b("void") } },
342+
],
343+
size: 192,
344+
},
289345

290346
// ---- Resource / Handle types ----
291347

0 commit comments

Comments
 (0)