add scan gc

This commit is contained in:
Akbar Yahya 2022-11-12 14:49:41 +08:00
parent 95bcedf14b
commit d508ff6c88
No known key found for this signature in database
GPG Key ID: 0C9985FEC5C018C9
2 changed files with 1979 additions and 35 deletions

1880
gc_needed2.json Normal file

File diff suppressed because it is too large Load Diff

134
op.js
View File

@ -9,7 +9,9 @@ const read_cmdid_output = "cmdid.json";
const read_cmdid_output_gc = "cmdid_gc.json"; const read_cmdid_output_gc = "cmdid_gc.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";
@ -19,6 +21,7 @@ console.log(process.cwd());
// folder gc auto-generated proto // folder gc auto-generated proto
const folder_proto_gc_gen = const folder_proto_gc_gen =
"../Grasscutter-Yuuki/src/generated/main/java/emu/grasscutter/net/proto/"; "../Grasscutter-Yuuki/src/generated/main/java/emu/grasscutter/net/proto/";
// file PacketOpcodes currently in use // file PacketOpcodes currently in use
const read_cmdid_gc = const read_cmdid_gc =
"../Grasscutter-Yuuki/src/main/java/emu/grasscutter/net/packet/PacketOpcodes.java"; "../Grasscutter-Yuuki/src/main/java/emu/grasscutter/net/packet/PacketOpcodes.java";
@ -26,6 +29,8 @@ const read_cmdid_gc =
const folder_packet_gc = const folder_packet_gc =
"../Grasscutter-Yuuki/src/main/java/emu/grasscutter/server/packet/"; "../Grasscutter-Yuuki/src/main/java/emu/grasscutter/server/packet/";
const folder_gc_scan = "../Grasscutter-Yuuki/src/main/java/emu/grasscutter/";
//const read_cmdid = fs.readFileSync("cmdid.csv"); //const read_cmdid = fs.readFileSync("cmdid.csv");
//const read_packetopcodes = fs.readFileSync("PacketOpcodes.java"); //const read_packetopcodes = fs.readFileSync("PacketOpcodes.java");
@ -366,7 +371,7 @@ function fix_packet(saveit = false) {
//return; //return;
index_file_packet++; index_file_packet++;
}); });
save_json(file_gc_need, file_gc_needed); save_json(file_gc_need, file_gc_needed); // This only applies to PacketOpcodes
console.log( console.log(
"Index file: " + "Index file: " +
index_file_packet + index_file_packet +
@ -416,6 +421,8 @@ function getPacketOpcodes(raw) {
return name; return name;
} }
// C:\Users\Administrator\Desktop\Projek\Docker\GS\gs\Grasscutter-Yuuki\src\main\java\emu\grasscutter
var file_toclean = []; var file_toclean = [];
var file_toaddmore = []; var file_toaddmore = [];
var found_noclean = 0; var found_noclean = 0;
@ -426,10 +433,12 @@ function clean_proto_gen() {
const files = getAllFiles("./proto"); const files = getAllFiles("./proto");
const json_gc_needed = read_json(file_gc_needed); 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_now = read_json(read_cmdid_output_gc);
const json_gc_update = read_json(read_cmdid_output_gc_update); const json_gc_update = read_json(read_cmdid_output_gc_update);
//console.log(json_gc_needed);
//AbilityInvokeArgument
console.log( console.log(
"File proto: " + files.length + " | Need " + json_gc_needed.length "File proto: " + files.length + " | Need " + json_gc_needed.length
); );
@ -438,66 +447,72 @@ function clean_proto_gen() {
// find all file import // find all file import
files.forEach(function (file) { files.forEach(function (file) {
var found = json_gc_needed.find((j) => file.match(j.name)); // read file
if (found) { const read = fs.readFileSync(file);
// read file var rd = read.toString();
const read = fs.readFileSync(file);
var rd = read.toString(); // find import
// find import while ((m = regex.exec(rd)) !== null) {
while ((m = regex.exec(rd)) !== null) { // This is necessary to avoid infinite loops with zero-width matches
// This is necessary to avoid infinite loops with zero-width matches if (m.index === regex.lastIndex) {
if (m.index === regex.lastIndex) { 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) {
//found_maybe_related++;
//console.log(`Skip ${match}`);
} else {
var subdata = new Object();
subdata["name"] = match;
file_toaddmore.push(subdata);
found_maybe_related++;
}
}
});
} }
// 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 {
var subdata = new Object();
subdata["name"] = match;
file_toaddmore.push(subdata);
}
}
});
} }
}); });
// all // last try
files.forEach(function (file) { files.forEach(function (file) {
var todoremove = false; var todoremove = false;
// main file // main file
var found = json_gc_needed.find((j) => file.match(j.name)); var found = json_gc_needed.find((j) => file.match(j.name));
if (found) { if (found) {
found_noclean++; // skip
} else { } else {
var found1 = file_toaddmore.find((j) => file.match(j.name)); var found1 = file_toaddmore.find((j) => file.match(j.name)); // find import
if (found1) { if (found1) {
found_noclean++; // skip
//console.log("Files sub are required: "+file); //console.log("Files sub are required: "+file);
found_maybe_related++;
} else { } else {
found_needclean++;
if (file.match("Retcode")) { if (file.match("Retcode")) {
console.log("found"); console.log("found");
} else { } else {
todoremove = true; 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) { if (todoremove) {
found_needclean++;
try { try {
fs.unlinkSync(file); fs.unlinkSync(file);
//file removed //file removed
} catch (err) { } catch (err) {
console.error(err); console.error(err);
} }
} else {
found_noclean++;
} }
}); });
@ -513,6 +528,55 @@ function clean_proto_gen() {
); );
} }
var g_todump = [];
function scan_gc() {
const files = getAllFiles(folder_gc_scan);
console.log("index file: " + files.length);
const regex = /import emu.grasscutter.net.proto.(.*?);/g;
files.forEach(function (file) {
// read file
const read = fs.readFileSync(file);
var rd = read.toString();
// 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) {
if (match === "*") {
return;
}
if (match.match(".")) {
match = match.split(".")[0];
}
match = match.replace("OuterClass", "");
var found_rt = g_todump.find((j) => j.name === match);
if (found_rt) {
//found_maybe_related++;
//console.log(`Skip ${match}`);
} else {
var subdata = new Object();
subdata["name"] = match;
g_todump.push(subdata);
}
}
});
}
});
save_json(g_todump, file_gc_needed2); // This only applies to PacketOpcodes
//console.log(g_todump);
}
//scan_gc();
clean_proto_gen(); clean_proto_gen();
//fix_packet(false); //fix_packet(false);
//cmdid_to_op(); //cmdid_to_op();