update etc

This commit is contained in:
Yuuki 2024-08-28 11:46:22 +08:00
parent a7e75aec06
commit d934542379
11 changed files with 80533 additions and 81241 deletions

File diff suppressed because it is too large Load Diff

22130
cmdid.json

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

63359
deobf.proto

File diff suppressed because it is too large Load Diff

4
nameTranslation.txt Normal file
View File

@ -0,0 +1,4 @@
# NAMETRANSLATION MANUAL, TODO
AICHHOBNIJK -> AbilityString
NEOLBFJNJNA -> type
CBFOMLLHKKK -> AbilityAttachedModifier

File diff suppressed because it is too large Load Diff

46
op.js
View File

@ -6,9 +6,9 @@ const readline = require("readline");
// cmdid current version
const read_cmdid_last = "cmdid_last.csv";
const read_cmdid = "cmdid.csv";
const read_cmdid_output = "cmdid.json";
const read_cmdid_latest_output = "cmdid.json";
const read_cmdid_ht_output = "cmdid_ht_40.json";
const read_cmdid_output_gc = "cmdid_gc.json";
const read_cmdid_gc_output = "cmdid_gc.json";
const read_cmdid_output_gc_full = "cmdid_gc_full.json";
const read_cmdid_output_gc_update = "cmdid_gc_update.json";
const read_cmdid_output_gc_nofound = "cmdid_gc_nofound.json";
@ -46,6 +46,8 @@ var index_file_gen = 0;
var index_file_cmdid = 0;
var index_cmdid_gc = 0;
var index_cmdid_gc_out = 0;
// ???
function check_gen() {
fs.readdir(folder_proto_gc_gen, function (err, files) {
//handling error
@ -59,8 +61,8 @@ function check_gen() {
});
}
// gen json file cmdid
function get_cmdid_json() {
// ???
function get_cmdid_csvtojson() {
const inputStreamcmdid = fs.createReadStream(read_cmdid);
var lineReadercmdid = readline.createInterface({
input: inputStreamcmdid,
@ -76,13 +78,13 @@ function get_cmdid_json() {
});
lineReadercmdid.on("close", function () {
console.log("found cmd id " + index_file_cmdid);
save_json(data, read_cmdid_output);
//save_json(data, read_cmdid_latest_output);
});
}
// ???
var data_gen = [];
var index_file_cmdid_gen = 0;
// gen json file cmdid
function read_cmdid_ht_json() {
const k = read_json(read_cmdid_ht_output);
// console.log(k);
@ -98,10 +100,10 @@ function read_cmdid_ht_json() {
}
console.log("found cmd id " + index_file_cmdid_gen);
save_json(data_gen, read_cmdid_output);
//save_json(data_gen, read_cmdid_latest_output);
}
// create cmdid from gc which comes from PacketOpcodes
// op java to json
var tes = 50000;
function get_cmdid_gc() {
const inputStreamcmdid = fs.createReadStream(read_cmdid_gc);
@ -147,24 +149,25 @@ function get_cmdid_gc() {
console.log(
"found cmd id " + index_cmdid_gc + " | no need " + index_cmdid_gc_out
);
save_json(data_gc2, read_cmdid_output_gc);
save_json(data_gc2, read_cmdid_gc_output);
save_json(data_gc, read_cmdid_output_gc_full);
});
}
// Update cmdid gc
var found_cmdid_new = 0;
var nofound_cmdid_new = 0;
var rename_name_cmdid = 0;
var noneed_rename_name_cmdid = 0;
var data_gc_cmdid_nofound = [];
var check_dunp_id = [];
var unkId = 50000;
function update_cmdid_gc() {
let melon = "";
// cmdid_gc.json (read_cmdid_output_gc) and cmdid.json (read_cmdid_output)
const json_cmdid_last = read_json(read_cmdid_output);
const json_cmdid_old = read_json(read_cmdid_output_gc);
let melon = "";
const json_cmdid_last = read_json(read_cmdid_latest_output);
const json_cmdid_old = read_json(read_cmdid_gc_output);
json_cmdid_old.forEach(function (s, index) {
var id = s.id;
@ -186,7 +189,9 @@ function update_cmdid_gc() {
s.id = found_id.id; // rename id
}
} else {
console.log("Wow nofound -> ID: " + id + " | Name: " + name);
unkId++
console.log("No found :( -> ID OLD: " + id + " > "+unkId+" | Name: " + name);
s.id = unkId;
data_gc_cmdid_nofound.push(s);
nofound_cmdid_new++;
}
@ -310,10 +315,9 @@ function cmdid_to_op() {
\n// Opcodes\
";
const cmdidfix_raw = fs.readFileSync(read_cmdid_output_gc);
const json_cmdidfix_raw = JSON.parse(cmdidfix_raw);
//const json_cmdidfix_raw = read_json(read_cmdid_output_gc_update);
const cmdidfix_raw = fs.readFileSync(read_cmdid_gc_output);
//const json_cmdidfix_raw = JSON.parse(cmdidfix_raw);
const json_cmdidfix_raw = read_json(read_cmdid_output_gc_update);
json_cmdidfix_raw.sort((a, b) => a.id - b.id);
@ -917,6 +921,8 @@ function cmdid_json_to_csv() {
// 2
//get_cmdid_gc();
// 3
//cmdid_to_op();
//update_cmdid_gc()
cmdid_to_op();
// 4
//clean_proto_gen();
// 5

213
proto_split.js Normal file
View File

@ -0,0 +1,213 @@
const fs = require('fs');
const path = require('path');
const systemNames = [
'uint32', 'uint64', 'int32', 'int64', 'sint32', 'sint64',
'fixed32', 'fixed64', 'sfixed32', 'sfixed64', 'float', 'double',
'bool', 'string', 'bytes'
];
const protoFilePath = "deobf.proto";
const outputPath1 = "./unimplemented";
const outputPath2 = "./proto";
const ntPath = '';
const version = `5.0`;
var cmdid_gen = [];
// Read the skip list
const skipFilePath = './skip2.txt';
let skipList;
try {
const skipFileContent = fs.readFileSync(skipFilePath, 'utf-8');
skipList = skipFileContent.split('\n').map(line => line.trim()).filter(line => line.length > 0);
} catch (err) {
console.error('Error reading skip file:', err);
skipList = [];
}
function splitProtoFile(protoFilePath, nameTranslationPath = null, version = "0.0") {
let ntMap = {};
const lines = fs.readFileSync(protoFilePath, 'utf-8').split('\n');
if (nameTranslationPath) {
const ntLines = fs.readFileSync(nameTranslationPath, 'utf-8').split('\n');
for (let ntLine of ntLines) {
if (ntLine.trim().startsWith('#')) continue;
const [key, value] = ntLine.trim().split(' -> ');
ntMap[key] = value;
}
}
let currentContent = [];
let currentName = null;
let cmdid = null;
for (let i = 0; i < lines.length; i++) {
const line = lines[i].trim();
if (line.startsWith('// CmdID: ')) {
cmdid = line;
} else if (line.startsWith("message") || line.startsWith("enum")) {
currentName = line.split(' ')[1];
currentContent.push(lines[i]);
} else if (line.startsWith("}")) {
currentContent.push(lines[i]);
// save
saveContent(currentName, currentContent, ntMap, cmdid, version);
if (cmdid) {
var d = new Object();
d["name"] = currentName;
d["id"] = parseInt(cmdid.replace(`// CmdID: `, ""));
cmdid_gen.push(d)
}
// clear
currentContent = [];
currentName = null;
cmdid = null;
} else if (currentName) {
currentContent.push(lines[i]);
}
}
save_json(cmdid_gen, `cmdid.json`);
}
function saveContent(name, content, ntMap = {}, cmdid = "", version = "") {
if (name in ntMap && !/[a-z]/.test(name)) {
name = ntMap[name];
}
const filename = `${name}.proto`;
const nestedMessages = findNestedMessages(content);
var isEnum = false
for (let i = 0; i < content.length; i++) {
let line = content[i];
if (isEnum && line.includes("_")) {
content[i] = renameConstant(line);
}
if (line.startsWith('enum')) {
isEnum = true;
}
}
let contentStr = content.join('\n');
for (const [key, value] of Object.entries(ntMap)) {
if (/[a-z]/.test(key)) continue;
contentStr = contentStr.replace(new RegExp(key, 'g'), value);
}
let output = `syntax = "proto3";\n\noption java_package = "emu.grasscutter.net.proto";\n// Version: ${version}\n`;
if (cmdid) {
//console.log(cmdid)
output += `${cmdid}\n`;
}
if (nestedMessages.length > 0) {
const importStatements = nestedMessages.map(nm => `import "${nm}.proto";`).join('\n');
output += `\n${importStatements}\n\n`;
} else {
output += '\n';
}
output += contentStr;
// update file proto
const filePath2 = path.join(outputPath2, filename);
const filePath1 = path.join(outputPath1, filename);
if (fs.existsSync(filePath2)) {
// skip update if file skip or broke
if (skipList.includes(filename.replace(".proto", ""))) {
console.log('Skipping update file:', filePath2);
// TODO: fix it
} else {
console.log(`File exist add to implemented: ${filePath2}`);
fs.writeFileSync(filePath2, output);
}
} else {
//console.log(`File does not exist add to unimplemented: ${filePath1}`);
fs.writeFileSync(filePath1, output);
}
}
function checkForNestedMessages(line) {
const nestedMessages = new Set();
if (line.startsWith('map<')) {
const mapsplit = line.replace('map<', '').replace('>', '').replace(',', '').split(' =')[0].split(' ').slice(0, -1);
for (const item of mapsplit) {
if (!systemNames.includes(item)) {
nestedMessages.add(item);
}
}
} else if (line.startsWith('repeated')) {
const part1 = line.split(' ')[1];
if (!systemNames.includes(part1)) {
nestedMessages.add(part1);
}
} else {
const part1 = line.split(' ')[0];
if (!systemNames.includes(part1)) {
nestedMessages.add(part1);
}
}
return nestedMessages;
}
function findNestedMessages(content) {
const nestedMessages = new Set();
const messageType = content[0].trim().split(' ')[0];
if (messageType === 'enum') return nestedMessages;
for (let line of content) {
line = line.trim();
if (line.startsWith('message') || line === '}' || line === '') continue;
const lineSplit = line.split(' ');
if (lineSplit[0] === 'oneof') continue;
const nested = checkForNestedMessages(line);
nested.forEach(nm => nestedMessages.add(nm));
}
return [...nestedMessages];
}
// save json
function save_json(raw, file) {
var j = JSON.stringify(raw, null, 4);
save(j, file);
}
function save(raw, file) {
fs.writeFile(file, raw, "utf8", function (err) {
if (err) {
console.log("An error occured while writing to File.");
return console.log(err);
}
console.log("File has been saved: " + file);
});
}
function renameConstant(declaration) {
// Split the declaration into the name and value parts
const [name, value] = declaration.split(" = ");
// Extract the relevant parts before and after the first underscore
const [prefix, relevantPart] = name.split("_", 2);
// Combine the prefix and the relevant part, and then convert to uppercase and replace camelCase with underscores
const newName = `${prefix}_${relevantPart}`.replace(/([a-z])([A-Z])/g, '$1_$2').toUpperCase();
// Return the renamed declaration
return `${newName} = ${value}`;
}
splitProtoFile(protoFilePath, ntPath, version);
console.log("Proto file split successfully!");

15
skip2.txt Normal file
View File

@ -0,0 +1,15 @@
AbilityString
AnimatorParameterValueInfo
AvatarInfo
TrialAvatarGrantRecord
SceneMonsterInfo
SceneEntityInfo
Item
Equip
SceneDataNotify
MaterialDeleteInfo
RoutePoint
SceneGadgetInfo
GadgetPlayInfo
AbilityMixinRecoverInfo
AbilityScalarValueEntry