add clean_proto_gen
This commit is contained in:
parent
238dd43a77
commit
302d35f51a
File diff suppressed because it is too large
Load Diff
334
op.js
334
op.js
|
@ -9,6 +9,7 @@ const read_cmdid_output = "cmdid.json";
|
|||
const read_cmdid_output_gc = "cmdid_gc.json";
|
||||
const read_cmdid_output_gc_update = "cmdid_gc_update.json";
|
||||
const read_cmdid_output_gc_nofound = "cmdid_gc_nofound.json";
|
||||
const file_gc_needed = "gc_needed.json";
|
||||
|
||||
const write_op = "PacketOpcodes.java";
|
||||
|
||||
|
@ -213,6 +214,10 @@ function update_cmdid_gc() {
|
|||
save_json(data_gc_cmdid_nofound, read_cmdid_output_gc_nofound);
|
||||
}
|
||||
|
||||
function read_json(file) {
|
||||
return JSON.parse(fs.readFileSync(file));
|
||||
}
|
||||
|
||||
// save json
|
||||
function save_json(raw, file) {
|
||||
var j = JSON.stringify(raw, null, 4);
|
||||
|
@ -257,141 +262,250 @@ 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);
|
||||
var file_gc_need = [];
|
||||
function fix_packet(saveit = false) {
|
||||
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) {
|
||||
//var f = path + "/" + file;
|
||||
const read = fs.readFileSync(file);
|
||||
var real = read.toString();
|
||||
|
||||
var name = getPacketOpcodes(real);
|
||||
if (!name) {
|
||||
console.log("no found");
|
||||
return;
|
||||
}
|
||||
|
||||
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);
|
||||
if (name === "NONE") {
|
||||
return;
|
||||
}
|
||||
|
||||
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 subdata = new Object();
|
||||
subdata["name"] = name;
|
||||
file_gc_need.push(subdata);
|
||||
|
||||
var name;
|
||||
r.forEach(function (s, index) {
|
||||
if (s.match("PacketOpcodes.")) {
|
||||
name = s.split("PacketOpcodes.")[1];
|
||||
if (name.match(",")) {
|
||||
name = name.split(",")[0];
|
||||
}
|
||||
return;
|
||||
}
|
||||
});
|
||||
//var name = c[1];
|
||||
|
||||
if (!name) {
|
||||
console.log("no found");
|
||||
return;
|
||||
}
|
||||
//console.log(r);
|
||||
|
||||
//var name = c[1];
|
||||
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
|
||||
);
|
||||
|
||||
//console.log(r);
|
||||
// rename all
|
||||
json_cmdidfix_raw.forEach(function (s) {
|
||||
var r = s.replace;
|
||||
if (r) {
|
||||
// var notify = HomeNewUnlockedBgmIdListNotify.Unk2700_MEBFPBDNPGO_ServerNotify
|
||||
// var notify = Unk2700MEBFPBDNPGOServerNotify.HomeNewUnlockedBgmIdListNotify
|
||||
|
||||
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
|
||||
);
|
||||
// Unk2700MEBFPBDNPGOServerNotify to HomeNewUnlockedBgmIdListNotifyOuterClass
|
||||
// Unk2700OGHMHELMBNNServerRsp to HomeChangeBgmRspOuterClass
|
||||
|
||||
// rename all
|
||||
json_cmdidfix_raw.forEach(function (s) {
|
||||
var r = s.replace;
|
||||
if (r) {
|
||||
// var notify = HomeNewUnlockedBgmIdListNotify.Unk2700_MEBFPBDNPGO_ServerNotify
|
||||
// var notify = Unk2700MEBFPBDNPGOServerNotify.HomeNewUnlockedBgmIdListNotify
|
||||
// - 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;
|
||||
|
||||
// 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);
|
||||
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(`${r}`, "g");
|
||||
real = real.replace(re, s.name);
|
||||
let re = new RegExp(`${realneed}`, "g");
|
||||
real = real.replace(re, tr);
|
||||
}
|
||||
});
|
||||
|
||||
// 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);
|
||||
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);
|
||||
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
|
||||
);
|
||||
//return;
|
||||
index_file_packet++;
|
||||
});
|
||||
save_json(file_gc_need, file_gc_needed);
|
||||
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);
|
||||
}
|
||||
|
||||
fix_packet("send", false);
|
||||
//fix_packet("recv");
|
||||
function getAllFiles(dirPath, arrayOfFiles) {
|
||||
files = fs.readdirSync(dirPath);
|
||||
|
||||
arrayOfFiles = arrayOfFiles || [];
|
||||
|
||||
files.forEach(function (file) {
|
||||
if (fs.statSync(dirPath + "/" + file).isDirectory()) {
|
||||
arrayOfFiles = getAllFiles(dirPath + "/" + file, arrayOfFiles);
|
||||
} else {
|
||||
arrayOfFiles.push(path.join(__dirname, dirPath, "/", file));
|
||||
}
|
||||
});
|
||||
|
||||
return arrayOfFiles;
|
||||
}
|
||||
|
||||
function getPacketOpcodes(raw) {
|
||||
var r = raw.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;
|
||||
}
|
||||
});
|
||||
return name;
|
||||
}
|
||||
|
||||
var file_toclean = [];
|
||||
var file_toaddmore = [];
|
||||
var found_noclean = 0;
|
||||
var found_needclean = 0;
|
||||
var found_maybe_related = 0;
|
||||
function clean_proto_gen() {
|
||||
//const files = getAllFiles(folder_proto_gc_gen);
|
||||
const files = getAllFiles("./proto");
|
||||
|
||||
const json_gc_needed = read_json(file_gc_needed);
|
||||
const json_gc_now = read_json(read_cmdid_output_gc);
|
||||
const json_gc_update = read_json(read_cmdid_output_gc_update);
|
||||
//console.log(json_gc_needed);
|
||||
|
||||
console.log(
|
||||
"File proto: " + files.length + " | Need " + json_gc_needed.length
|
||||
);
|
||||
|
||||
const regex = /\import "(.*?)\.proto"/g;
|
||||
|
||||
// find all file import
|
||||
files.forEach(function (file) {
|
||||
var found = json_gc_needed.find((j) => file.match(j.name));
|
||||
if (found) {
|
||||
// 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) {
|
||||
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++;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// all
|
||||
files.forEach(function (file) {
|
||||
// main file
|
||||
var found = json_gc_needed.find((j) => file.match(j.name));
|
||||
if (found) {
|
||||
found_noclean++;
|
||||
} else {
|
||||
var found1 = file_toaddmore.find((j) => file.match(j.name));
|
||||
if (found1) {
|
||||
found_noclean++;
|
||||
//console.log("Files sub are required: "+file);
|
||||
} else {
|
||||
found_needclean++;
|
||||
try {
|
||||
fs.unlinkSync(file);
|
||||
//file removed
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
//console.log(file_toaddmore);
|
||||
|
||||
console.log(
|
||||
"No clean: " +
|
||||
found_noclean +
|
||||
" | Need to clean: " +
|
||||
found_needclean +
|
||||
" | Related " +
|
||||
found_maybe_related
|
||||
);
|
||||
}
|
||||
|
||||
clean_proto_gen();
|
||||
//fix_packet(false);
|
||||
//cmdid_to_op();
|
||||
//update_cmdid_gc();
|
||||
//get_cmdid_gc();
|
||||
|
|
Loading…
Reference in New Issue