update tool clean proto

This commit is contained in:
Yuuki 2024-08-21 22:09:48 +08:00
parent a87f2aedc3
commit 8ae9236b56
6 changed files with 10221 additions and 8297 deletions

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

8634
cmdid_gc_full.json Normal file

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

242
op.js
View File

@ -9,16 +9,18 @@ const read_cmdid = "cmdid.csv";
const read_cmdid_output = "cmdid.json"; const read_cmdid_output = "cmdid.json";
const read_cmdid_ht_output = "cmdid_ht_40.json"; const read_cmdid_ht_output = "cmdid_ht_40.json";
const read_cmdid_output_gc = "cmdid_gc.json"; const read_cmdid_output_gc = "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_update = "cmdid_gc_update.json";
const read_cmdid_output_gc_nofound = "cmdid_gc_nofound.json"; const read_cmdid_output_gc_nofound = "cmdid_gc_nofound.json";
const file_gc_needed = "gc_needed.json"; const file_gc_needed = "gc_needed.json";
const file_gc_needed2 = "gc_needed2.json";
const write_op = "PacketOpcodes.java"; const write_op = "PacketOpcodes.java";
console.log(process.cwd()); console.log(process.cwd());
const json_gc_needed = read_json(file_gc_needed);
//(TODO: add input file) //(TODO: add input file)
// folder gc auto-generated proto // folder gc auto-generated proto
const folder_proto_gc_gen = const folder_proto_gc_gen =
@ -38,6 +40,7 @@ const folder_gc_scan = "../GSServer-GCOriginal/src/main/java/emu/grasscutter/";
var data = []; var data = [];
var data_gc = []; var data_gc = [];
var data_gc2 = [];
var index_file_gen = 0; var index_file_gen = 0;
var index_file_cmdid = 0; var index_file_cmdid = 0;
@ -120,10 +123,20 @@ function get_cmdid_gc() {
if (id == 8888888) { if (id == 8888888) {
id = tes++; id = tes++;
} }
var subdata = new Object(); var subdata = new Object();
subdata["name"] = name; subdata["name"] = name;
subdata["id"] = id; subdata["id"] = id;
data_gc.push(subdata); data_gc.push(subdata);
var found = json_gc_needed.find((j) => name.match(j.name));
if (!found) {
// skip bad
return;
}
data_gc2.push(subdata);
//console.log(name); //console.log(name);
index_cmdid_gc++; index_cmdid_gc++;
} else { } else {
@ -134,7 +147,8 @@ function get_cmdid_gc() {
console.log( console.log(
"found cmd id " + index_cmdid_gc + " | no need " + index_cmdid_gc_out "found cmd id " + index_cmdid_gc + " | no need " + index_cmdid_gc_out
); );
save_json(data_gc, read_cmdid_output_gc); save_json(data_gc2, read_cmdid_output_gc);
save_json(data_gc, read_cmdid_output_gc_full);
}); });
} }
@ -253,7 +267,7 @@ function update_cmdid_gc() {
// const csvData = csvRows.join("\n"); // const csvData = csvRows.join("\n");
fs.writeFileSync(read_cmdid_last, melon); fs.writeFileSync(read_cmdid_last, melon);
@ -296,14 +310,13 @@ function cmdid_to_op() {
\n// Opcodes\ \n// Opcodes\
"; ";
//const read_file_gcneed = fs.readFileSync(file_gc_needed2);
//const json_gcneed_raw = JSON.parse(read_file_gcneed);
const cmdidfix_raw = fs.readFileSync(read_cmdid_output_gc); const cmdidfix_raw = fs.readFileSync(read_cmdid_output_gc);
const json_cmdidfix_raw = JSON.parse(cmdidfix_raw); const json_cmdidfix_raw = JSON.parse(cmdidfix_raw);
//const json_cmdidfix_raw = read_json(read_cmdid_output_gc_update); //const json_cmdidfix_raw = read_json(read_cmdid_output_gc_update);
json_cmdidfix_raw.sort((a, b) => a.id - b.id);
json_cmdidfix_raw.forEach(function (s) { json_cmdidfix_raw.forEach(function (s) {
var found_id = dup_name.find((j) => j.name == s.name); var found_id = dup_name.find((j) => j.name == s.name);
if (!found_id) { if (!found_id) {
@ -331,127 +344,33 @@ function cmdid_to_op() {
} }
var index_file_packet = 0; var index_file_packet = 0;
var index_file_packet_found = 0;
var index_file_packet_nofound = 0;
var index_file_packet_rename = 0;
var index_file_packet_norename = 0;
var index_file_packet_renamemulti = 0;
var file_gc_need = []; var file_gc_need = [];
function fix_packet(saveit = false) {
function fix_packet() {
const files = getAllFiles(folder_packet_gc); const files = getAllFiles(folder_packet_gc);
const json_cmdid_last = read_json(read_cmdid_output);
const json_cmdid_old = read_json(read_cmdid_output_gc);
const json_cmdidfix_raw = read_json(read_cmdid_output_gc_update);
files.forEach(function (file) { files.forEach(function (file) {
//var f = path + "/" + file;
const read = fs.readFileSync(file); const read = fs.readFileSync(file);
var real = read.toString(); var real = read.toString();
const names = getPacketOpcodes(real); // Adjusted to get an array of names
var name = getPacketOpcodes(real); if (names.length === 0) {
if (!name) { return; // Skip if no PacketOpcodes.* found
console.log("no found");
return;
} }
if (name === "NONE") { // Iterate through the names and add them to the array
return; names.forEach(name => {
} const subdata = { name };
var subdata = new Object();
subdata["name"] = name;
file_gc_need.push(subdata); file_gc_need.push(subdata);
//var name = c[1];
//console.log(r);
var found_old = json_cmdid_old.find((j) => j.name === name);
if (found_old) {
//console.log(found_old);
index_file_packet_found++;
var found_new = json_cmdid_last.find((j) => j.id == found_old.id);
if (found_new) {
if (found_new.name != found_old.name) {
index_file_packet_rename++;
console.log(
"Found need rename: " + found_old.name + " > " + found_new.name
);
// rename all
json_cmdidfix_raw.forEach(function (s) {
var r = s.replace;
if (r) {
// var notify = HomeNewUnlockedBgmIdListNotify.Unk2700_MEBFPBDNPGO_ServerNotify
// var notify = Unk2700MEBFPBDNPGOServerNotify.HomeNewUnlockedBgmIdListNotify
// Unk2700MEBFPBDNPGOServerNotify to HomeNewUnlockedBgmIdListNotifyOuterClass
// Unk2700OGHMHELMBNNServerRsp to HomeChangeBgmRspOuterClass
// - Need More Auto like -
// addUnk2700ELJPLMIHNIP to addNewUnlockedBgmIdList (this should be found inside gen proto)
// setUnk2700BJHAMKKECEI to setBgmId
if (r.match("Unk")) {
//console.log(r);
var x = r.split("_");
var tr = x.join("");
var realneed = tr;
if (tr.match("ServerNotify")) {
//console.log("found: "+tr);
let re = new RegExp(`${tr}`, "g");
tr = tr.replace(re, `${s.name}OuterClass`);
//console.log("found: " + tr);
} else if (tr.match("ServerRsp")) {
let re = new RegExp(`${tr}`, "g");
tr = tr.replace(re, `${s.name}OuterClass`);
} else {
let re = new RegExp(`${tr}`, "g");
tr = tr.replace(re, s.name);
//console.log("found: " + tr);
}
let re = new RegExp(`${realneed}`, "g");
real = real.replace(re, tr);
}
let re = new RegExp(`${r}`, "g");
real = real.replace(re, s.name);
}
}); });
// simpel rename
//let re = new RegExp(`${found_old.name}`, "g");
//real = real.replace(re, found_new.name);
//console.log(real);
if (saveit) {
save(real, f);
}
}
} else {
index_file_packet_norename++;
//console.log("Same name "+name);
}
} else {
index_file_packet_nofound++;
console.log("No found " + name);
}
//return;
index_file_packet++; index_file_packet++;
}); });
save_json(file_gc_need, file_gc_needed); // This only applies to PacketOpcodes
save_json(file_gc_need, file_gc_needed);
console.log( console.log(
"Index file: " + "Index file: " +
index_file_packet + index_file_packet
" | found " +
index_file_packet_found +
" | No found " +
index_file_packet_nofound +
" | Rename " +
index_file_packet_rename +
" | NoRename " +
index_file_packet_norename
); );
} }
@ -476,18 +395,15 @@ function getAllFiles(dirPath, arrayOfFiles) {
} }
function getPacketOpcodes(raw) { function getPacketOpcodes(raw) {
var r = raw.match(/\(.*?\)/g).map((x) => x.replace(/[()]/g, "")); const packetOpcodesRegex = /PacketOpcodes\.\w+/g;
var name; const packetOpcodesMatches = raw.match(packetOpcodesRegex);
r.forEach(function (s, index) {
if (s.match("PacketOpcodes.")) { if (packetOpcodesMatches) {
name = s.split("PacketOpcodes.")[1]; return packetOpcodesMatches.map(match => match.replace('PacketOpcodes.', ''));
if (name.match(",")) { } else {
name = name.split(",")[0]; console.log('No PacketOpcodes.* found in the file.', raw);
return [];
} }
return;
}
});
return name;
} }
// C:\Users\Administrator\Desktop\Projek\Docker\GS\gs\GSServer-GC\src\main\java\emu\grasscutter // C:\Users\Administrator\Desktop\Projek\Docker\GS\gs\GSServer-GC\src\main\java\emu\grasscutter
@ -556,17 +472,22 @@ function find_import(file) {
return torequire; return torequire;
} }
// Read the skip list
const skipFilePath = './skip.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 clean_proto_gen() { function clean_proto_gen() {
//const files = getAllFiles(folder_proto_gc_gen);
const files = getAllFiles("./proto"); const files = getAllFiles("./proto");
const unimplemented = "./unimplemented/";
const json_gc_needed = read_json(file_gc_needed);
const json_gc_needed2 = read_json(file_gc_needed2);
const json_gc_now = read_json(read_cmdid_output_gc);
const json_gc_update = read_json(read_cmdid_output_gc_update);
//AbilityInvokeArgument
console.log( console.log(
"File proto: " + files.length + " | Need " + json_gc_needed.length "File proto: " + files.length + " | Need " + json_gc_needed.length
); );
@ -574,11 +495,9 @@ function clean_proto_gen() {
// find all file import // find all file import
files.forEach(function (file) { files.forEach(function (file) {
var name_file = path.parse(file).name; var name_file = path.parse(file).name;
var toaddfile = new Object(); var toaddfile = new Object();
toaddfile["file"] = name_file; toaddfile["file"] = name_file;
toaddfile["import"] = find_import(file); toaddfile["import"] = find_import(file);
file_proto.push(toaddfile); file_proto.push(toaddfile);
}); });
@ -592,6 +511,7 @@ function clean_proto_gen() {
var found_proto = file_proto.find((j) => name_file === j.file); // must same file var found_proto = file_proto.find((j) => name_file === j.file); // must same file
if (found_proto) { if (found_proto) {
// if found import // if found import
if (found_proto.import) { if (found_proto.import) {
found_proto.import.forEach(function (s) { found_proto.import.forEach(function (s) {
@ -619,8 +539,6 @@ function clean_proto_gen() {
return noe; return noe;
} }
//console.log(find_json_proto("ActivityInfo"));
// try with proto json // try with proto json
var filedonotdelete = []; var filedonotdelete = [];
files.forEach(function (file) { files.forEach(function (file) {
@ -636,16 +554,6 @@ function clean_proto_gen() {
// skip // skip
} }
// find miss scan
var found2 = json_gc_needed2.find((j) => name_file.match(j.name));
if (found2) {
findme = true;
} else {
// skip
}
// ModifierDurability >AbilityAppliedModifier -> AbilitySyncStateInfo -> AvatarEnterSceneInfo and multi file
// main file // main file
if (findme) { if (findme) {
var tosub = find_json_proto(name_file); var tosub = find_json_proto(name_file);
@ -665,6 +573,7 @@ function clean_proto_gen() {
if (file.match("ChannelerSlabChallenge")) { if (file.match("ChannelerSlabChallenge")) {
console.log(file); console.log(file);
} }
} }
}); });
@ -678,16 +587,19 @@ function clean_proto_gen() {
if (toskip) { if (toskip) {
found_noclean++; found_noclean++;
} else { } else {
found_needclean++;
// ActivityInfo if (skipList.includes(name_file)) {
if (file.match("ChannelerSlabChallenge")) { console.log('Skipping file:', file);
console.log("ChannelerSlabChallenge"); found_noclean++;
return;
} }
//console.log(name_file);
//console.log("Remove file: " + file); found_needclean++;
console.log("Move file: " + file);
const destinationFile = path.join(unimplemented, path.basename(file));
try { try {
fs.unlinkSync(file); fs.renameSync(file, destinationFile);
//file removed
} catch (err) { } catch (err) {
console.error(err); console.error(err);
} }
@ -727,7 +639,7 @@ function clean_proto_gen_v2() {
if (messageName === messageName.toUpperCase()) { if (messageName === messageName.toUpperCase()) {
console.log("Remove: " + file); console.log("Remove: " + file);
try { try {
fs.unlinkSync(file); //fs.unlinkSync(file);
//file removed //file removed
} catch (err) { } catch (err) {
console.error(err); console.error(err);
@ -781,7 +693,7 @@ function scan_gc() {
} }
}); });
save_json(g_todump, file_gc_needed2); // This only applies to PacketOpcodes //save_json(g_todump, file_gc_needed); // This only applies to PacketOpcodes
//console.log(g_todump); //console.log(g_todump);
} }
@ -855,7 +767,7 @@ function clean_proto_event() {
found_needclean++; found_needclean++;
//console.log(name_file); //console.log(name_file);
try { try {
fs.unlinkSync(file); //fs.unlinkSync(file);
console.log("Remove file: " + file); console.log("Remove file: " + file);
//file removed //file removed
} catch (err) { } catch (err) {
@ -948,7 +860,7 @@ function clean_proto_event_v2() {
found_needclean++; found_needclean++;
console.log(name_file); console.log(name_file);
try { try {
fs.unlinkSync(file); //fs.unlinkSync(file);
console.log("Remove file: " + file); console.log("Remove file: " + file);
//file removed //file removed
} catch (err) { } catch (err) {
@ -988,17 +900,23 @@ function cmdid_json_to_csv() {
// cmdid_json_to_csv(); // cmdid_json_to_csv();
// Update GC Proto // Update GC Proto
// get_cmdid_gc(); // 1. get cmd old gc
//read_cmdid_ht_json(); // 2 or //read_cmdid_ht_json(); // 2 or
// get_cmdid_json(); // 2. get last cmdid.csv to json // get_cmdid_json(); // 2. get last cmdid.csv to json
// now we have cmdid_gc.json and cmdid.json // now we have cmdid_gc.json and cmdid.json
// update_cmdid_gc(); // 3. update gc cmdid (mode by id) // update_cmdid_gc(); // 3. update gc cmdid (mode by id)
cmdid_to_op(); // 4. update op
// npx prettier --write PacketOpcodes.java // npx prettier --write PacketOpcodes.java
// scan_gc(); // 5. scan gc // scan_gc(); // 5. scan gc
// clean_proto_event(); // 6. clean event, need manual // clean_proto_event(); // 6. clean event, need manual
// clean_proto_gen(); // 6. clean proto
// clean_proto_gen_v2(); // clean_proto_gen_v2();
//console.log(skipList)
// TODO: clean DungeonSettleNotify // TODO: clean DungeonSettleNotify
// clean_proto_event_v2(); // clean_proto_event_v2();
// 1
//fix_packet();
// 2
//get_cmdid_gc();
// 3
//cmdid_to_op();
// 4
//clean_proto_gen();

36
skip.txt Normal file
View File

@ -0,0 +1,36 @@
Retcode
PacketHead
AttackResult
HitCollision
AttackHitEffectResult
AbilityMetaAddAbility
AbilityMetaReInitOverrideMap
AbilityMetaSetKilledState
AbilityMetaModifierChange
ModifierAction
EntityMoveInfo
AbilityActionGenerateElemBall
AbilityActionCreateGadget
AbilityActionSetRandomOverrideMapValue
AbilityActionSummon
AbilityIdentifier
EvtBeingHitInfo
EvtAnimatorParameterInfo
TrialAvatarActivityDetailInfo
TrialAvatarActivityRewardDetailInfo
ForceUpdateInfo
QueryCurrRegionHttpRsp
QueryRegionListHttpRsp
RegionInfo
RegionSimpleInfo
StopServerInfo
QuickUseWidgetReq
QuickUseWidgetRsp
WidgetCameraInfo
WidgetThunderBirdFeatherInfo
WidgetSorushInfo
SkyCrystalDetectorQuickUseResult
SetPlayerBornDataReq
CancelCoopTaskRsp
WidgetGadgetAllDataNotify
ModifierProperty