-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathextract-simdata-types.ts
More file actions
105 lines (93 loc) · 3.25 KB
/
extract-simdata-types.ts
File metadata and controls
105 lines (93 loc) · 3.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import glob from "glob";
import path from "path";
import { Package, SimDataResource } from "../dst/models";
import { BinaryResourceType, SimDataGroup, TuningResourceType } from "../dst/enums";
import { ResourceKeyPair } from "../dst/lib/packages/types";
import { formatAsHexString } from "@s4tk/hashing/formatting";
import { registerPlugin } from "../dst/plugins";
import BufferFromFile from "@s4tk/plugin-bufferfromfile";
registerPlugin(BufferFromFile);
const directories = [
'/Applications/The Sims 4 Packs',
'/Applications/The Sims 4.app',
'C:/Program Files/EA Games/The Sims 4',
'D:/Program Files/EA Games/The Sims 4',
];
const groupsToIgnore = new Set([
0x00496642, // client stuff
0x00ABFFCF, // client stuff
0x0003C397, // BuildBuy stuff
0x006CA304, // Modules
0x0094E9AE, // NativeBuildBuy
0x003A5A65, // Native_SeasonsWeather
0x004B5265, // client stuff
0x00D16262, // Automation,
0x00057D11, // client stuff
0x0057C8BA, // RegionSortTuning (client thing)
]);
function findPackagePaths(): Promise<string[]> {
return new Promise(resolve => {
const packagePaths: string[] = [];
directories.forEach(directory => {
const files = glob.sync(directory + '/**/*.package');
packagePaths.push(...files.filter((p) => !path.basename(p).startsWith("Strings_")));
});
resolve(packagePaths);
});
}
console.log("Finding packages...");
findPackagePaths().then(packagePaths => {
console.log(`${packagePaths.length} packages found.`);
const allFiles: ResourceKeyPair[] = [];
console.log("Reading packages...");
packagePaths.forEach((path, i) => {
try {
const entries = Package.streamResources(path, {
resourceFilter(type, group, inst) {
if (type !== BinaryResourceType.SimData) return false;
if (groupsToIgnore.has(group)) return false;
if (group in SimDataGroup) return false;
return true;
}
});
allFiles.push(...entries);
} catch (error: any) {
console.error(error.message);
}
console.log(`(${i + 1}/${packagePaths.length}) Read ${path}`);
});
const matched = new Set();
const matches: { group: string; name: string; }[] = [];
const nonMatches: { [key: string]: Set<string> } = {};
allFiles.forEach((entry) => {
const group = entry.key.group;
if (matched.has(group)) return;
// FIXME: there must be a bug... there should always be a schema, but for
// some reason it's undefined sometimes
let name = (entry.value as SimDataResource).schema?.name;
if (name) name = name.replace("CAS", "Cas");
if (name in TuningResourceType) {
matched.add(group);
matches.push({
group: formatAsHexString(group, 8, true),
name
});
} else {
if (name?.includes('.')) return; // skip modules
if (name?.startsWith('Client_')) return; // skip client modules
const groupSet = nonMatches[formatAsHexString(group, 8, true)] ??= new Set();
groupSet.add(name);
}
});
console.log("===== MATCHES =====");
matches.forEach(({ group, name }) => {
console.log(`${name} = ${group},`);
});
console.log("===== NON-MATCHES =====");
for (const group in nonMatches) {
console.log(group);
nonMatches[group].forEach(name => {
console.log(` | ${name}`);
});
}
});