From 9f1aeb4135b1d04e5ed4b8e46a56fc7dbdb4a56c Mon Sep 17 00:00:00 2001 From: Akbar Yahya <11765082+akbaryahya@users.noreply.github.com> Date: Sun, 13 Nov 2022 04:35:53 +0800 Subject: [PATCH] add check sub proto --- op.js | 217 +++++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 156 insertions(+), 61 deletions(-) diff --git a/op.js b/op.js index 69610ebf..61095961 100644 --- a/op.js +++ b/op.js @@ -423,11 +423,64 @@ function getPacketOpcodes(raw) { // C:\Users\Administrator\Desktop\Projek\Docker\GS\gs\Grasscutter-Yuuki\src\main\java\emu\grasscutter -var file_toclean = []; -var file_toaddmore = []; +var file_proto = []; +var file_proto_more = []; + var found_noclean = 0; var found_needclean = 0; var found_maybe_related = 0; + +const regex_import = /\import "(.*?)\.proto"/g; + +// find import in file +function find_import(file) { + var torequire = []; + + var dir = path.parse(file).dir; + + if (file.match("ModifierDurability")) { + //console.log("fff"); + } + + // read file + const read = fs.readFileSync(file); + var rd = read.toString(); + + while ((m = regex_import.exec(rd)) !== null) { + // This is necessary to avoid infinite loops with zero-width matches + if (m.index === regex_import.lastIndex) { + regex_import.lastIndex++; + } + // The result can be accessed through the `m`-variable. + m.forEach((match, groupIndex) => { + // only index 1 grup + if (groupIndex == 1) { + var found_rt = torequire.find((j) => j === match); + if (found_rt) { + //console.log(`Skip ${match}`); + } else { + if (match.match("Unk")) { + //console.log(file + " require " + match); + } + //var subdata = new Object(); + //subdata["name"] = match; + var sub = find_import(dir + "/" + match + ".proto"); + if (sub) { + sub.forEach(function (k) { + var v = torequire.find((j) => j === k); + if (!v) { + torequire.push(k); + } + }); + } + torequire.push(match); + } + } + }); + } + return torequire; +} + function clean_proto_gen() { //const files = getAllFiles(folder_proto_gc_gen); const files = getAllFiles("./proto"); @@ -443,88 +496,130 @@ function clean_proto_gen() { "File proto: " + files.length + " | Need " + json_gc_needed.length ); - const regex = /\import "(.*?)\.proto"/g; - // find all file import files.forEach(function (file) { - // read file - const read = fs.readFileSync(file); - var rd = read.toString(); + var name_file = path.parse(file).name; - if (file.match("Unk")) { - console.log("unk: " + file); + var toaddfile = new Object(); + toaddfile["file"] = name_file; + toaddfile["import"] = find_import(file); + + file_proto.push(toaddfile); + }); + + //console.log(file_proto); + + function find_json_proto(name_file, newnew = null) { + var noe = []; + if (newnew) { + noe = newnew; } - // find import - while ((m = regex.exec(rd)) !== null) { - // This is necessary to avoid infinite loops with zero-width matches - if (m.index === regex.lastIndex) { - regex.lastIndex++; - } - // The result can be accessed through the `m`-variable. - m.forEach((match, groupIndex) => { - // only index 1 grup - if (groupIndex == 1) { - var found_rt = file_toaddmore.find((j) => j.name === match); - if (found_rt) { - //console.log(`Skip ${match}`); - } else { - if (match.match("Unk") || file.match("Unk")) { - console.log(file + " require " + match); - } - var subdata = new Object(); - subdata["name"] = match; - file_toaddmore.push(subdata); + var found_proto = file_proto.find((j) => name_file === j.file); // must same file + if (found_proto) { + // if found import + if (found_proto.import) { + found_proto.import.forEach(function (s) { + var f = noe.find((j) => j === s); + if (!f) { + noe.push(s); + // check sub + var sub = find_json_proto(s, noe); + sub.forEach(function (k) { + var v = noe.find((j) => j === k); + if (!v) { + noe.push(k); + } + }); } + }); + } + var ss = noe.find((j) => j === name_file); + if (!ss) { + noe.push(name_file); + } + } else { + // skip + } + return noe; + } + + //console.log(find_json_proto("ActivityInfo")); + + // try with proto json + var filedonotdelete = []; + files.forEach(function (file) { + var name_file = path.parse(file).name; + + var findme = false; + + // find main file + var found = json_gc_needed.find((j) => name_file.match(j.name)); + if (found) { + findme = true; + } else { + // 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 + if (findme) { + var tosub = find_json_proto(name_file); + tosub.forEach(function (k) { + var oo = filedonotdelete.find((j) => j === k); + if (!oo) { + filedonotdelete.push(k); } }); + } else { + // not main file + /* + if (name_file.match("ModifierDurability")) { + console.log("3"); + } + */ + if (file.match("ChannelerSlabChallenge")) { + console.log(file); + } } }); - // last try + // ModifierDurability + //console.log(filedonotdelete); + + // last files.forEach(function (file) { - var todoremove = false; - - // main file - var found = json_gc_needed.find((j) => file.match(j.name)); - if (found) { - // skip + var name_file = path.parse(file).name; + var toskip = filedonotdelete.find((j) => name_file === j); + if (toskip) { + found_noclean++; } else { - var found1 = file_toaddmore.find((j) => file.match(j.name)); // find import - if (found1) { - // skip - //console.log("Files sub are required: "+file); - found_maybe_related++; - } else { - if (file.match("Retcode")) { - console.log("found"); - } else { - var found2 = json_gc_needed2.find((j) => file.match(j.name)); // find miss scan - if (found2) { - // skip - found_maybe_related++; - } else { - todoremove = true; - } - } - } - } - - if (todoremove) { found_needclean++; - console.log("Remove file: "+file); + // ActivityInfo + if (file.match("ChannelerSlabChallenge")) { + console.log("ChannelerSlabChallenge"); + } + //console.log(name_file); + //console.log("Remove file: " + file); try { fs.unlinkSync(file); //file removed } catch (err) { console.error(err); } - } else { - found_noclean++; } }); - //console.log(file_toaddmore); + //console.log(filedonotdelete); console.log( "No clean: " +