From 58ced46d85ce9adac48a3e410ddf330714597974 Mon Sep 17 00:00:00 2001 From: Lordmau5 Date: Thu, 21 May 2020 21:28:50 +0200 Subject: [PATCH] Various changes - Rename original files - Allow exclusions and blacklist to be disabled completely - Add "valid locations" option - Add option to overwrite the files in the output folder ("chaining") - Add console output for how many models have been replaced, excluded, or are non valid --- config.default.js | 153 +++++++++++++++--- index.js | 58 ++++++- ....bin.orig => character_character_data.bin} | Bin ...in.orig => character_model_model_data.bin} | Bin 4 files changed, 182 insertions(+), 29 deletions(-) rename original/{character_character_data.bin.orig => character_character_data.bin} (100%) rename original/{character_model_model_data.bin.orig => character_model_model_data.bin} (100%) diff --git a/config.default.js b/config.default.js index ca9636c..98ce650 100644 --- a/config.default.js +++ b/config.default.js @@ -3,7 +3,10 @@ // 0 = Everyone is one model (singleModel) // 1 = Everyone has a random model from a list (randomModels) // 2 = Everyone is a completely random model -const mode = 2; +const mode = 0; + +// Whether or not the files should be modified from the output directory +const overwrite = false; // Should we try to make sure models are replaced // with another one of the same "type"? (2nd byte) @@ -15,28 +18,6 @@ const sameType = false; // const singleModel = [0x71, 0x08]; const singleModel = [0x71, 0x08]; -// List of models to choose randomly from when mode is 1 -const randomModels = [ - [0x71, 0x08], - [0x72, 0x08], - [0x81, 0x08], - [0x75, 0x08], - [0x7d, 0x08], - [0x77, 0x08], - [0x7b, 0x08], - [0x7a, 0x08], - [0x78, 0x08], - [0x79, 0x08], - [0x73, 0x08], - [0x7f, 0x08], - [0x7e, 0x08], - [0x7c, 0x08], - [0x82, 0x08], - [0x76, 0x08], - [0x80, 0x08], - [0x83, 0x08], -]; - // List of base models to exclude from modifications // Other models can still be replaced *with* that model // @@ -44,28 +25,154 @@ const randomModels = [ // That means Kiryu can't be set to Daigo, but Daigo can still be set to Kiryu // Can also work as a whitelist so only the models listed here will be replaced const exclusions = { + enabled: false, isWhitelist: false, models: [ [0x71, 0x08], [0x72, 0x08], + [0x81, 0x08], + [0x75, 0x08], + [0x7d, 0x08], + [0x77, 0x08], + [0x7b, 0x08], + [0x7a, 0x08], + [0x78, 0x08], + [0x79, 0x08], + [0x73, 0x08], + [0x7f, 0x08], + [0x7e, 0x08], + [0x7c, 0x08], + [0x82, 0x08], + [0x76, 0x08], + [0x80, 0x08], + [0x83, 0x08], ], }; // Blacklist to prevent models from appearing // Can also act as a whitelist so *only* those models will appear const blacklist = { + enabled: false, isWhitelist: false, models: [ + // Dummies [0x58, 0x08], [0x1e, 0x0a], + + // Sitting models + [0x03, 0x0b], + [0x90, 0x08], + [0xc7, 0x08], + [0x6b, 0x08], + [0xb9, 0x08], + [0x62, 0x08], + [0xa4, 0x08], + [0xa0, 0x08], + [0x82, 0x08], + [0x70, 0x05], + [0x72, 0x05], + [0x76, 0x05], + [0xb5, 0x08], + [0x8d, 0x08], + [0xc8, 0x08], + [0xb1, 0x02], + + // Sitting characters + [0x12, 0x07], + [0x13, 0x07], + [0x14, 0x07], + [0x15, 0x07], + [0x16, 0x07], + [0x17, 0x07], + [0x18, 0x07], + [0x19, 0x07], + [0x1a, 0x07], + [0x1b, 0x07], + [0x1c, 0x07], + [0xec, 0x0a], + [0xed, 0x0a], + [0xee, 0x0a], + [0xef, 0x0a], + [0xf0, 0x0a], + [0xf1, 0x0a], + [0xf2, 0x0a], + [0xf3, 0x0a], + [0xf4, 0x0a], + [0xf5, 0x0a], + [0xf6, 0x0a], + [0xf7, 0x0a], + [0xf8, 0x0a], + [0xf9, 0x0a], + [0xfa, 0x0a], + [0x1d, 0x07], + [0x1e, 0x07], + [0x1f, 0x07], + [0x20, 0x07], + [0x21, 0x07], + [0x22, 0x07], + [0x23, 0x07], + [0x24, 0x07], + [0x25, 0x07], + [0x26, 0x07], + [0x27, 0x07], + [0x28, 0x07], + [0x29, 0x07], + [0x2a, 0x07], + [0x2b, 0x07], + [0x2c, 0x07], + [0x2d, 0x07], + [0x2e, 0x07], + [0x2f, 0x07], + [0x30, 0x07], + [0x31, 0x07], + [0x32, 0x07], + [0x33, 0x07], + [0x34, 0x07], + [0x35, 0x07], + [0x36, 0x07], + [0x37, 0x07], + [0x38, 0x07], + [0x39, 0x07], + [0x3a, 0x07], + ], +}; + +// List of valid locations to replace +// +// Can also act as a blacklist so those locations will be excluded +const valid = { + enabled: false, + isWhitelist: true, + locations: [ + // All Kiryu model locations + 0x16194, + 0x181c0, + 0x18c28, + 0x17c14, + 0x18c24, + 0x18bb8, + 0x161b4, + 0x161b8, + 0x18bbc, + 0x18bc0, + 0x18310, + 0x161c0, + 0x161cc, + 0x161c4, + 0x18c20, + 0x189d4, + 0x18ae0, + 0x18e50, ], }; module.exports = { mode, + overwrite, sameType, singleModel, randomModels, exclusions, blacklist, + valid, }; diff --git a/index.js b/index.js index 6a3ead9..d04196a 100644 --- a/index.js +++ b/index.js @@ -2,7 +2,7 @@ const fs = require("fs"); const _ = require("underscore"); -const { _models, allTypes, shuffledModels } = require("./models"); +const { _models, shuffledModels } = require("./models"); if (!fs.existsSync("config.js")) { fs.writeFileSync("config.js", fs.readFileSync("config.default.js")); @@ -10,19 +10,31 @@ if (!fs.existsSync("config.js")) { if (!fs.existsSync("output")) { fs.mkdirSync("output"); + fs.writeFileSync( + "output/character_character_data.bin", + fs.readFileSync("original/character_character_data.bin") + ); + fs.writeFileSync( + "output/character_model_model_data.bin", + fs.readFileSync("original/character_model_model_data.bin") + ); } const { mode, + overwrite, sameType, singleModel, randomModels, exclusions, blacklist, + valid, } = require("./config"); // Check if a model is excluded from modification function isModelExcluded(fb, sb) { + if (!exclusions.enabled) return false; + for (let i = 0; i < exclusions.models.length; i++) { const model = exclusions.models[i]; @@ -40,6 +52,8 @@ function isModelExcluded(fb, sb) { // Check if a model is blacklisted function isModelBlacklisted(fb, sb) { + if (!blacklist.enabled) return false; + for (let i = 0; i < blacklist.models.length; i++) { const model = blacklist.models[i]; @@ -55,16 +69,34 @@ function isModelBlacklisted(fb, sb) { return blacklist.isWhitelist; } -function replaceModels(doReplace = true) { - const data = fs.readFileSync("original/character_character_data.bin.orig"); +function isValidLocation(loc) { + if (!valid.enabled) return true; + if (!valid.locations.length) return true; - let replaced = 0; + for (let i = 0; i < valid.locations.length; i++) { + if (valid.locations[i] === loc) return valid.isWhitelist; + } + return !valid.isWhitelist; +} + +function replaceModels(doReplace = true) { + const data = fs.readFileSync( + `${overwrite ? "output" : "original"}/character_character_data.bin` + ); + + let nonValid = 0; let excluded = 0; + let replaced = 0; if (doReplace) { // Magic if (mode === 0) { for (let i = 0x16194; i < 0x18ea8; i += 4) { + if (!isValidLocation(i)) { + nonValid++; + continue; + } + if (isModelExcluded(data[i], data[i + 1])) { excluded++; continue; @@ -76,6 +108,11 @@ function replaceModels(doReplace = true) { } } else if (mode === 1) { for (let i = 0x16194; i < 0x18ea8; i += 4) { + if (!isValidLocation(i)) { + nonValid++; + continue; + } + if (isModelExcluded(data[i], data[i + 1])) { excluded++; continue; @@ -89,6 +126,11 @@ function replaceModels(doReplace = true) { } } else if (mode === 2) { for (let i = 0x16194; i < 0x18ea8; i += 4) { + if (!isValidLocation(i)) { + nonValid++; + continue; + } + const id = data[i]; const type = data[i + 1]; @@ -125,7 +167,9 @@ function replaceModels(doReplace = true) { // ----- } - console.log(`Replaced ${replaced} models - Excluded ${excluded}`); + console.log( + `Replaced ${replaced} models - Excluded ${excluded} - Non-Valid ${nonValid}` + ); fs.writeFileSync("output/character_character_data.bin", data); } @@ -133,7 +177,9 @@ function replaceModels(doReplace = true) { // TODO: Create a reverse-lookup map of some sort to fit the proper model height with other models? // Only does scaling, so not that needed apparently... function replaceHeights(doReplace = true) { - const data = fs.readFileSync("original/character_model_model_data.bin.orig"); + const data = fs.readFileSync( + `${overwrite ? "output" : "original"}/character_model_model_data.bin` + ); if (doReplace) { // Magic diff --git a/original/character_character_data.bin.orig b/original/character_character_data.bin similarity index 100% rename from original/character_character_data.bin.orig rename to original/character_character_data.bin diff --git a/original/character_model_model_data.bin.orig b/original/character_model_model_data.bin similarity index 100% rename from original/character_model_model_data.bin.orig rename to original/character_model_model_data.bin