Add fix_packet
This commit is contained in:
parent
ed24691719
commit
f1e8c30820
1185
cmdid_gc_update.json
1185
cmdid_gc_update.json
File diff suppressed because it is too large
Load Diff
145
op.js
145
op.js
|
@ -22,6 +22,9 @@ const folder_proto_gc_gen =
|
|||
const read_cmdid_gc =
|
||||
"../Grasscutter-Yuuki/src/main/java/emu/grasscutter/net/packet/PacketOpcodes.java";
|
||||
|
||||
const folder_packet_gc =
|
||||
"../Grasscutter-Yuuki/src/main/java/emu/grasscutter/server/packet/";
|
||||
|
||||
//const read_cmdid = fs.readFileSync("cmdid.csv");
|
||||
//const read_packetopcodes = fs.readFileSync("PacketOpcodes.java");
|
||||
|
||||
|
@ -126,6 +129,7 @@ function update_cmdid_gc() {
|
|||
rename_name_cmdid++;
|
||||
//console.log("Wow rename -> ID: "+id+" | Name: "+name+" > "+found_id.name);
|
||||
// rename json_cmdid_old
|
||||
s.replace = s.name;
|
||||
s.name = found_id.name;
|
||||
}
|
||||
} else {
|
||||
|
@ -221,7 +225,7 @@ function save(raw, file) {
|
|||
console.log("An error occured while writing to File.");
|
||||
return console.log(err);
|
||||
}
|
||||
console.log("File has been saved.");
|
||||
console.log("File has been saved: " + file);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -247,11 +251,148 @@ function cmdid_to_op() {
|
|||
save(melon, write_op); // use "npx prettier --write PacketOpcodes.java" for better Formatter
|
||||
}
|
||||
|
||||
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;
|
||||
function fix_packet(p = "recv", saveit = false) {
|
||||
var path = folder_packet_gc + p;
|
||||
fs.readdir(path, function (err, files) {
|
||||
//handling error
|
||||
if (err) {
|
||||
return console.log("Unable to scan directory: " + err);
|
||||
}
|
||||
|
||||
const cmd_last = fs.readFileSync(read_cmdid_output);
|
||||
const cmd_old = fs.readFileSync(read_cmdid_output_gc);
|
||||
const cmdidfix_raw = fs.readFileSync(read_cmdid_output_gc_update);
|
||||
const json_cmdid_last = JSON.parse(cmd_last);
|
||||
const json_cmdid_old = JSON.parse(cmd_old);
|
||||
const json_cmdidfix_raw = JSON.parse(cmdidfix_raw);
|
||||
|
||||
files.forEach(function (file) {
|
||||
var f = path + "/" + file;
|
||||
const read = fs.readFileSync(f);
|
||||
var real = read.toString();
|
||||
var r = real.match(/\(.*?\)/g).map((x) => x.replace(/[()]/g, ""));
|
||||
|
||||
var name;
|
||||
r.forEach(function (s, index) {
|
||||
if (s.match("PacketOpcodes.")) {
|
||||
name = s.split("PacketOpcodes.")[1];
|
||||
if (name.match(",")) {
|
||||
name = name.split(",")[0];
|
||||
}
|
||||
return;
|
||||
}
|
||||
});
|
||||
|
||||
if (!name) {
|
||||
console.log("no found");
|
||||
return;
|
||||
}
|
||||
|
||||
//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
|
||||
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++;
|
||||
});
|
||||
console.log(
|
||||
"Index file: " +
|
||||
index_file_packet +
|
||||
" | found " +
|
||||
index_file_packet_found +
|
||||
" | No found " +
|
||||
index_file_packet_nofound +
|
||||
" | Rename " +
|
||||
index_file_packet_rename +
|
||||
" | NoRename " +
|
||||
index_file_packet_norename
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
function isBlank(str) {
|
||||
return !!!str || /^\s*$/.test(str);
|
||||
}
|
||||
|
||||
cmdid_to_op();
|
||||
fix_packet("send", false);
|
||||
//fix_packet("recv");
|
||||
//cmdid_to_op();
|
||||
//update_cmdid_gc();
|
||||
//get_cmdid_gc();
|
||||
//get_cmdid_json();
|
||||
|
|
Loading…
Reference in New Issue