GC-Proto/cmdid.js
2024-07-04 19:30:03 +08:00

38 lines
1.1 KiB
JavaScript

const fs = require('fs');
// Read the proto file
fs.readFile('deobf.proto', 'utf8', (err, data) => {
if (err) {
console.error(err);
return;
}
const pattern = /\/\/\s*CmdId:\s*(\d+)?\s*\n\s*message\s+(\w+)\s*{/g;
let match;
const messages = [];
// Find all matches
while ((match = pattern.exec(data)) !== null) {
const cmdId = match[1] ? parseInt(match[1], 10) : 0; // If cmdId is not present, set to 0
const name = match[2];
// Skip messages without CmdId
if (cmdId != 0) {
messages.push({ name, id: cmdId });
//console.log('Found message:', name, 'CmdId:', cmdId);
} else{
console.log('Not foundFound message:', name);
}
}
// Convert to JSON format
const jsonContent = JSON.stringify(messages, null, 4);
// Write to test.json
fs.writeFile('cmdid_deobf.json', jsonContent, 'utf8', (err) => {
if (err) {
console.error(err);
return;
}
console.log('test.json has been saved.');
});
});