mirror of
https://gitlab.com/YuukiPS/GC-Proto.git
synced 2024-12-25 07:59:24 +03:00
add json cmdid and gc from PacketOpcodes.
this is useful later to update proto and delete unused proto.
This commit is contained in:
parent
527f05cac6
commit
f1c902a71f
8210
cmdid.json
Normal file
8210
cmdid.json
Normal file
File diff suppressed because it is too large
Load Diff
7674
cmdid_gc.json
Normal file
7674
cmdid_gc.json
Normal file
File diff suppressed because it is too large
Load Diff
121
op.js
Normal file
121
op.js
Normal file
@ -0,0 +1,121 @@
|
|||||||
|
// Removed useless files, to speed up build process and make it clearer.
|
||||||
|
const path = require("path");
|
||||||
|
const fs = require("fs");
|
||||||
|
const readline = require("readline");
|
||||||
|
|
||||||
|
// cmdid current version
|
||||||
|
const read_cmdid = "cmdid.csv";
|
||||||
|
const read_cmdid_output = "cmdid.json";
|
||||||
|
const read_cmdid_output_gc = "cmdid_gc.json";
|
||||||
|
|
||||||
|
console.log(process.cwd());
|
||||||
|
|
||||||
|
//(TODO: add input file)
|
||||||
|
// folder gc auto-generated proto
|
||||||
|
const folder_proto_gc_gen =
|
||||||
|
"../Grasscutter-Yuuki/src/generated/main/java/emu/grasscutter/net/proto/";
|
||||||
|
// file PacketOpcodes currently in use
|
||||||
|
const read_cmdid_gc =
|
||||||
|
"../Grasscutter-Yuuki/src/main/java/emu/grasscutter/net/packet/PacketOpcodes.java";
|
||||||
|
|
||||||
|
//const read_cmdid = fs.readFileSync("cmdid.csv");
|
||||||
|
//const read_packetopcodes = fs.readFileSync("PacketOpcodes.java");
|
||||||
|
|
||||||
|
var data = [];
|
||||||
|
var data_gc = [];
|
||||||
|
|
||||||
|
var index_file_gen = 0;
|
||||||
|
var index_file_cmdid = 0;
|
||||||
|
var index_cmdid_gc = 0;
|
||||||
|
var index_cmdid_gc_out = 0;
|
||||||
|
function check_gen() {
|
||||||
|
fs.readdir(folder_proto_gc_gen, function (err, files) {
|
||||||
|
//handling error
|
||||||
|
if (err) {
|
||||||
|
return console.log("Unable to scan directory: " + err);
|
||||||
|
}
|
||||||
|
files.forEach(function (file) {
|
||||||
|
index_file_gen++;
|
||||||
|
});
|
||||||
|
console.log("file proto gen: " + index_file_gen);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// gen json file cmdid
|
||||||
|
function get_cmdid_json() {
|
||||||
|
const inputStreamcmdid = fs.createReadStream(read_cmdid);
|
||||||
|
var lineReadercmdid = readline.createInterface({
|
||||||
|
input: inputStreamcmdid,
|
||||||
|
terminal: false,
|
||||||
|
});
|
||||||
|
lineReadercmdid.on("line", function (line) {
|
||||||
|
var config = line.split(",");
|
||||||
|
var subdata = new Object();
|
||||||
|
subdata["name"] = config[0];
|
||||||
|
subdata["id"] = parseInt(config[1]);
|
||||||
|
data.push(subdata);
|
||||||
|
index_file_cmdid++;
|
||||||
|
});
|
||||||
|
lineReadercmdid.on("close", function () {
|
||||||
|
console.log("found cmd id " + index_file_cmdid);
|
||||||
|
var strNotes = JSON.stringify(data, null, 4);
|
||||||
|
fs.writeFile(read_cmdid_output, strNotes, "utf8", function (err) {
|
||||||
|
if (err) {
|
||||||
|
console.log("An error occured while writing JSON Object to File.");
|
||||||
|
return console.log(err);
|
||||||
|
}
|
||||||
|
console.log("JSON file has been saved.");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function get_cmdid_gc() {
|
||||||
|
const inputStreamcmdid = fs.createReadStream(read_cmdid_gc);
|
||||||
|
var lineReadercmdid = readline.createInterface({
|
||||||
|
input: inputStreamcmdid,
|
||||||
|
terminal: false,
|
||||||
|
});
|
||||||
|
lineReadercmdid.on("line", function (line) {
|
||||||
|
var config = line.split(" = ");
|
||||||
|
var name = config[0];
|
||||||
|
var id = parseInt(config[1]);
|
||||||
|
if (name.includes("public static final int")) {
|
||||||
|
name = name.replace("\tpublic static final int", "");
|
||||||
|
// skip 0 ?
|
||||||
|
if(id == 0){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var subdata = new Object();
|
||||||
|
subdata["name"] = name;
|
||||||
|
subdata["id"] = id;
|
||||||
|
data_gc.push(subdata);
|
||||||
|
//console.log(name);
|
||||||
|
index_cmdid_gc++;
|
||||||
|
} else {
|
||||||
|
index_cmdid_gc_out++;
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
var subdata = new Object();
|
||||||
|
subdata["name"] = config[0];
|
||||||
|
subdata["id"] = parseInt(config[1]);
|
||||||
|
data.push(subdata);
|
||||||
|
*/
|
||||||
|
});
|
||||||
|
lineReadercmdid.on("close", function () {
|
||||||
|
console.log(
|
||||||
|
"found cmd id " + index_cmdid_gc + " | no need " + index_cmdid_gc_out
|
||||||
|
);
|
||||||
|
var strNotes = JSON.stringify(data_gc, null, 4);
|
||||||
|
fs.writeFile(read_cmdid_output_gc, strNotes, "utf8", function (err) {
|
||||||
|
if (err) {
|
||||||
|
console.log("An error occured while writing JSON Object to File.");
|
||||||
|
return console.log(err);
|
||||||
|
}
|
||||||
|
console.log("JSON file has been saved.");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
get_cmdid_gc();
|
||||||
|
//get_cmdid_json();
|
||||||
|
//check_gen();
|
Loading…
Reference in New Issue
Block a user