-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnode_finder.wscript
More file actions
449 lines (370 loc) · 17.1 KB
/
node_finder.wscript
File metadata and controls
449 lines (370 loc) · 17.1 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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
// GENERIC NODE FINDER SCRIPT
// =========================
// Purpose: Find and display complete JSON snippets for any specified scene, or quest node type.
// Configurable: Node type, result limits, file limits, scene category, and output format
// =========================
// @author MisterChedda
// @version 0.1
import * as Logger from 'Logger.wscript';
import * as TypeHelper from 'TypeHelper.wscript';
// ===== CONFIGURATION SECTION =====
// Change these values to customize the search
// TARGET NODE TYPE - Change this to search for different node types
const TARGET_NODE_TYPE = "scnXorNode"; // Examples: "scnQuestNode", "scnSectionNode", "scnStartNode", "scnEndNode", "questFlowControlNodeDefinition"
// RESULT LIMITS
const MAX_RESULTS = 30; // Maximum number of results to display
const MAX_FILES_TO_PROCESS = 3000; // Maximum files to scan (set to 99999 for unlimited)
const MAX_NODES_PER_FILE = 250; // Skip files with more than this many nodes
// FILE TYPE SELECTION
const INCLUDE_SCENE = true; // Include .scene files
const INCLUDE_QUESTPHASE = true; // Include .questphase files
// SCENE CATEGORY FILTERING (only applies to .scene files)
const FILTER_BY_CATEGORY = "otherOpenWorld"; // Leave empty for all categories, or specify: "voiceset", "mainQuests", "sideQuests", "minorQuests", "otherQuests", "dialoguesQuests", "streetOpenWorld", "vendorsOpenWorld", "dancefloorsOpenWorld", "cityOpenWorld", "chatsOpenWorld", "otherOpenWorld", "holocalls", "other"
// PROGRESS REPORTING
const PROGRESS_INTERVAL = 100; // Show progress every N files
const SHOW_DETAILED_PROGRESS = true; // Show detailed progress info
// OUTPUT OPTIONS
const SAVE_RESULTS = true; // Save results to file
const SHOW_FULL_JSON = true; // Show complete JSON or just key properties
// ===== MAIN FUNCTION =====
function main() {
Logger.Info("=== GENERIC NODE FINDER ===");
Logger.Info(`Searching for node type: ${TARGET_NODE_TYPE}`);
Logger.Info(`Max results: ${MAX_RESULTS}`);
Logger.Info(`Max files to process: ${MAX_FILES_TO_PROCESS}`);
Logger.Info(`Include .scene files: ${INCLUDE_SCENE}`);
Logger.Info(`Include .questphase files: ${INCLUDE_QUESTPHASE}`);
Logger.Info(`Filter by category: ${FILTER_BY_CATEGORY || 'All categories'}`);
const state = initializeState();
try {
// Phase 1: Collect target files
Logger.Info("Phase 1: Collecting target files...");
collectTargetFiles(state);
if (state.targetFiles.length === 0) {
Logger.Warning("No target files found!");
return;
}
Logger.Info(`Found ${state.targetFiles.length} files to analyze`);
// Phase 2: Search for target nodes
Logger.Info("Phase 2: Searching for target nodes...");
searchForNodes(state);
// Phase 3: Display and save results
Logger.Info("Phase 3: Displaying and saving results...");
displayResults(state);
Logger.Info("=== Node search completed! ===");
} catch (error) {
Logger.Error("Fatal error during node search: " + error.message);
wkit.ShowMessageBox(
"Node search failed with error:\n" + error.message,
"Search Error", 2, 0
);
}
}
// ===== STATE INITIALIZATION =====
function initializeState() {
return {
targetFiles: [],
processedFiles: 0,
skippedFiles: 0,
startTime: Date.now(),
// Results tracking
foundNodes: [],
totalNodesFound: 0,
filesWithTargetNodes: 0,
categoryFilteredFiles: 0,
// Output file names
outputJson: `node_finder_${TARGET_NODE_TYPE}_${Date.now()}.json`,
outputTxt: `node_finder_${TARGET_NODE_TYPE}_${Date.now()}.txt`,
errors: []
};
}
// ===== FILE COLLECTION =====
function collectTargetFiles(state) {
Logger.Info("Scanning archives for target files...");
const archiveFiles = wkit.GetArchiveFiles();
let skippedVersions = 0;
let collectedFiles = 0;
for (const gameFile of archiveFiles) {
if (!gameFile || !gameFile.FileName) continue;
const fileName = gameFile.FileName.toLowerCase();
// Skip version folders
if (fileName.includes("versions")) {
skippedVersions++;
continue;
}
// Check file type inclusion
const shouldInclude =
(INCLUDE_SCENE && fileName.endsWith('.scene')) ||
(INCLUDE_QUESTPHASE && fileName.endsWith('.questphase'));
if (shouldInclude) {
state.targetFiles.push(gameFile);
collectedFiles++;
// Respect file limit
if (collectedFiles >= MAX_FILES_TO_PROCESS) {
Logger.Info(`Reached file limit of ${MAX_FILES_TO_PROCESS}, stopping collection`);
break;
}
}
}
Logger.Info(`Collected ${collectedFiles} files for processing`);
Logger.Info(`Skipped ${skippedVersions} files in version folders`);
}
// ===== NODE SEARCHING =====
function searchForNodes(state) {
let processed = 0;
for (const gameFile of state.targetFiles) {
try {
processed++;
// Progress update
if (processed % PROGRESS_INTERVAL === 0) {
const elapsed = Math.round((Date.now() - state.startTime) / 1000);
if (SHOW_DETAILED_PROGRESS) {
Logger.Info(`Progress: ${processed}/${state.targetFiles.length} files (${elapsed}s) | Found: ${state.totalNodesFound} nodes`);
}
}
// Early exit if we have enough results
if (state.foundNodes.length >= MAX_RESULTS) {
Logger.Info("Reached maximum results limit, stopping search");
break;
}
// Load and parse file
const fileContent = wkit.GameFileToJson(gameFile);
if (!fileContent) {
state.errors.push(`Failed to load: ${gameFile.FileName}`);
continue;
}
let parsedContent;
try {
parsedContent = TypeHelper.JsonParse(fileContent);
} catch (parseError) {
state.errors.push(`Failed to parse: ${gameFile.FileName}`);
continue;
}
if (!parsedContent) continue;
// Check scene category filter (only applies to .scene files)
if (FILTER_BY_CATEGORY && gameFile.FileName.toLowerCase().endsWith('.scene')) {
const sceneCategory = parsedContent?.Data?.RootChunk?.sceneCategoryTag;
if (sceneCategory && sceneCategory !== FILTER_BY_CATEGORY) {
state.categoryFilteredFiles++;
continue;
}
}
// Check node count and skip if file is too large
const nodeCount = getNodeCount(parsedContent, gameFile.FileName);
if (nodeCount > MAX_NODES_PER_FILE) {
state.skippedFiles++;
continue;
}
// Search for target nodes in this file
const foundInFile = searchFileForTargetNodes(parsedContent, gameFile.FileName);
if (foundInFile.length > 0) {
state.filesWithTargetNodes++;
state.totalNodesFound += foundInFile.length;
// Add to results (respecting max results limit)
for (const node of foundInFile) {
if (state.foundNodes.length < MAX_RESULTS) {
state.foundNodes.push(node);
}
}
Logger.Info(`Found ${foundInFile.length} ${TARGET_NODE_TYPE} nodes in ${gameFile.FileName}`);
}
} catch (error) {
Logger.Error(`Error processing ${gameFile.FileName}: ${error.message}`);
state.errors.push(`Error: ${gameFile.FileName} - ${error.message}`);
}
}
state.processedFiles = processed;
}
// ===== SEARCH INDIVIDUAL FILE =====
function searchFileForTargetNodes(parsedContent, fileName) {
const foundNodes = [];
try {
// Try scene file structure first
const sceneGraph = parsedContent?.Data?.RootChunk?.sceneGraph?.Data?.graph;
if (Array.isArray(sceneGraph)) {
for (const nodeHandle of sceneGraph) {
const nodeData = nodeHandle?.Data;
if (nodeData && nodeData.$type === TARGET_NODE_TYPE) {
foundNodes.push(createNodeResult(nodeData, fileName, "scene"));
}
}
}
// Try quest file structure
const questGraph = parsedContent?.Data?.RootChunk?.graph?.Data;
if (questGraph) {
const questNodes = questGraph.questNodes || questGraph.nodes || [];
if (Array.isArray(questNodes)) {
for (const nodeHandle of questNodes) {
const nodeData = nodeHandle?.Data;
if (nodeData && nodeData.$type === TARGET_NODE_TYPE) {
foundNodes.push(createNodeResult(nodeData, fileName, "quest"));
}
}
}
}
} catch (error) {
Logger.Warning(`Error searching nodes in ${fileName}: ${error.message}`);
}
return foundNodes;
}
// ===== CREATE NODE RESULT =====
function createNodeResult(nodeData, fileName, fileType) {
const nodeId = nodeData.nodeId?.id || nodeData.id || "unknown";
return {
fileName: fileName,
fileType: fileType,
nodeId: nodeId,
nodeType: nodeData.$type,
completeJson: SHOW_FULL_JSON ? JSON.stringify(nodeData, null, 2) : null,
keyProperties: extractKeyProperties(nodeData),
rawNodeData: nodeData // Keep reference for detailed analysis
};
}
// ===== EXTRACT KEY PROPERTIES =====
function extractKeyProperties(nodeData) {
const keyProps = {
type: nodeData.$type,
id: nodeData.nodeId?.id || nodeData.id || "unknown"
};
// Add common properties that might be interesting
if (nodeData.name) keyProps.name = nodeData.name;
if (nodeData.title) keyProps.title = nodeData.title;
if (nodeData.description) keyProps.description = nodeData.description;
if (nodeData.opensAt !== undefined) keyProps.opensAt = nodeData.opensAt;
if (nodeData.closesAt !== undefined) keyProps.closesAt = nodeData.closesAt;
if (nodeData.isOpen !== undefined) keyProps.isOpen = nodeData.isOpen;
if (nodeData.inputSockets) keyProps.inputSocketCount = nodeData.inputSockets.length;
if (nodeData.outputSockets) keyProps.outputSocketCount = nodeData.outputSockets.length;
return keyProps;
}
// ===== NODE COUNT HELPER =====
function getNodeCount(parsedContent, fileName) {
try {
// Try scene file structure
const sceneGraph = parsedContent?.Data?.RootChunk?.sceneGraph?.Data?.graph;
if (Array.isArray(sceneGraph)) {
return sceneGraph.length;
}
// Try quest file structure
const questGraph = parsedContent?.Data?.RootChunk?.graph?.Data;
if (questGraph) {
const questNodes = questGraph.questNodes || questGraph.nodes || [];
if (Array.isArray(questNodes)) {
return questNodes.length;
}
}
return 0;
} catch (error) {
Logger.Warning(`Error counting nodes in ${fileName}: ${error.message}`);
return 0;
}
}
// ===== DISPLAY RESULTS =====
function displayResults(state) {
const duration = Math.round((Date.now() - state.startTime) / 1000);
Logger.Info("=== SEARCH RESULTS ===");
Logger.Info(`Files processed: ${state.processedFiles}`);
Logger.Info(`Files skipped (too large): ${state.skippedFiles}`);
Logger.Info(`Files filtered by category: ${state.categoryFilteredFiles}`);
Logger.Info(`Files with target nodes: ${state.filesWithTargetNodes}`);
Logger.Info(`Total nodes found: ${state.totalNodesFound}`);
Logger.Info(`Showing first ${state.foundNodes.length} results`);
Logger.Info(`Duration: ${duration} seconds`);
Logger.Info("\n=== NODE DETAILS ===");
for (let i = 0; i < state.foundNodes.length; i++) {
const node = state.foundNodes[i];
Logger.Info(`\n--- Result ${i + 1} ---`);
Logger.Info(`File: ${node.fileName}`);
Logger.Info(`Node ID: ${node.nodeId}`);
Logger.Info(`Node Type: ${node.nodeType}`);
Logger.Info(`File Type: ${node.fileType}`);
if (SHOW_FULL_JSON && node.completeJson) {
Logger.Info(`Complete JSON:\n${node.completeJson}`);
} else {
Logger.Info(`Key Properties: ${JSON.stringify(node.keyProperties, null, 2)}`);
}
}
// Save results if enabled
if (SAVE_RESULTS) {
saveResults(state, duration);
}
// Show completion dialog
showCompletionDialog(state, duration);
}
// ===== SAVE RESULTS =====
function saveResults(state, duration) {
try {
// Save JSON data
const jsonData = {
metadata: {
searchDate: new Date().toISOString(),
targetNodeType: TARGET_NODE_TYPE,
categoryFilter: FILTER_BY_CATEGORY || "All categories",
filesProcessed: state.processedFiles,
filesSkipped: state.skippedFiles,
categoryFilteredFiles: state.categoryFilteredFiles,
totalNodesFound: state.totalNodesFound,
resultsShown: state.foundNodes.length,
duration: duration
},
results: state.foundNodes,
errors: state.errors
};
wkit.SaveToRaw(state.outputJson, JSON.stringify(jsonData, null, 2));
Logger.Info(`JSON results saved to: ${state.outputJson}`);
// Save text report
let textReport = `GENERIC NODE FINDER REPORT\n`;
textReport += `Target Node Type: ${TARGET_NODE_TYPE}\n`;
textReport += `Category Filter: ${FILTER_BY_CATEGORY || 'All categories'}\n`;
textReport += `Search Date: ${new Date().toISOString()}\n`;
textReport += `Files Processed: ${state.processedFiles}\n`;
textReport += `Files Skipped (too large): ${state.skippedFiles}\n`;
textReport += `Files Filtered by Category: ${state.categoryFilteredFiles}\n`;
textReport += `Total Nodes Found: ${state.totalNodesFound}\n`;
textReport += `Results Shown: ${state.foundNodes.length}\n`;
textReport += `Duration: ${duration} seconds\n\n`;
textReport += `DETAILED RESULTS:\n`;
textReport += `=`.repeat(40) + `\n`;
for (let i = 0; i < state.foundNodes.length; i++) {
const node = state.foundNodes[i];
textReport += `\nResult ${i + 1}:\n`;
textReport += `-`.repeat(20) + `\n`;
textReport += `File: ${node.fileName}\n`;
textReport += `Node ID: ${node.nodeId}\n`;
textReport += `Node Type: ${node.nodeType}\n`;
textReport += `File Type: ${node.fileType}\n`;
if (SHOW_FULL_JSON && node.completeJson) {
textReport += `Complete JSON:\n${node.completeJson}\n`;
} else {
textReport += `Key Properties:\n${JSON.stringify(node.keyProperties, null, 2)}\n`;
}
}
if (state.errors.length > 0) {
textReport += `\nERRORS:\n`;
for (const error of state.errors.slice(0, 20)) {
textReport += `${error}\n`;
}
}
wkit.SaveToRaw(state.outputTxt, textReport);
Logger.Info(`Text report saved to: ${state.outputTxt}`);
} catch (error) {
Logger.Error(`Could not save results: ${error.message}`);
}
}
// ===== COMPLETION DIALOG =====
function showCompletionDialog(state, duration) {
const message = `Generic Node Finder Complete!\n\n` +
`Target: ${TARGET_NODE_TYPE}\n` +
`Category Filter: ${FILTER_BY_CATEGORY || 'All categories'}\n` +
`Files processed: ${state.processedFiles}\n` +
`Files filtered by category: ${state.categoryFilteredFiles}\n` +
`Files with target nodes: ${state.filesWithTargetNodes}\n` +
`Total nodes found: ${state.totalNodesFound}\n` +
`Results displayed: ${state.foundNodes.length}\n` +
`Duration: ${duration} seconds\n\n` +
`Check the log for complete node details.\n` +
(SAVE_RESULTS ? `\nResults saved to:\n${state.outputJson}\n${state.outputTxt}` : '');
wkit.ShowMessageBox(message, 'Node Search Complete', 0, 0);
}
// ===== RUN THE SEARCH =====
main();