From 3993a25e4f4aedefcdbaedd10401b270859f0e72 Mon Sep 17 00:00:00 2001 From: Lordmau5 Date: Thu, 21 May 2020 19:21:06 +0200 Subject: [PATCH] Allow exclusion to work as a whitelist as well That way only the models listed in it will be replaced with other models (e.g. only Kiryu) --- config.default.js | 11 ++++++-- index.js | 70 ++++++++++++++++++++++++++++++++--------------- models.js | 1 + 3 files changed, 58 insertions(+), 24 deletions(-) diff --git a/config.default.js b/config.default.js index c152e83..ca9636c 100644 --- a/config.default.js +++ b/config.default.js @@ -42,7 +42,14 @@ const randomModels = [ // // Example: If Kiryu's base model is found it will never be changed // That means Kiryu can't be set to Daigo, but Daigo can still be set to Kiryu -const excludedModels = []; +// Can also work as a whitelist so only the models listed here will be replaced +const exclusions = { + isWhitelist: false, + models: [ + [0x71, 0x08], + [0x72, 0x08], + ], +}; // Blacklist to prevent models from appearing // Can also act as a whitelist so *only* those models will appear @@ -59,6 +66,6 @@ module.exports = { sameType, singleModel, randomModels, - excludedModels, + exclusions, blacklist, }; diff --git a/index.js b/index.js index 4db0757..6a3ead9 100644 --- a/index.js +++ b/index.js @@ -2,7 +2,7 @@ const fs = require("fs"); const _ = require("underscore"); -const { allTypes, shuffledModels } = require("./models"); +const { _models, allTypes, shuffledModels } = require("./models"); if (!fs.existsSync("config.js")) { fs.writeFileSync("config.js", fs.readFileSync("config.default.js")); @@ -17,25 +17,25 @@ const { sameType, singleModel, randomModels, - excludedModels, + exclusions, blacklist, } = require("./config"); // Check if a model is excluded from modification function isModelExcluded(fb, sb) { - for (let i = 0; i < excludedModels.length; i++) { - const model = excludedModels[i]; + for (let i = 0; i < exclusions.models.length; i++) { + const model = exclusions.models[i]; if ( (model[0] === fb && model[1] === -1) || (model[0] === -1 && model[1] === sb) ) { - return true; + return !exclusions.isWhitelist; } else if (model[0] === fb && model[1] === sb) { - return true; + return !exclusions.isWhitelist; } } - return false; + return exclusions.isWhitelist; } // Check if a model is blacklisted @@ -58,49 +58,75 @@ function isModelBlacklisted(fb, sb) { function replaceModels(doReplace = true) { const data = fs.readFileSync("original/character_character_data.bin.orig"); + let replaced = 0; + let excluded = 0; + if (doReplace) { // Magic if (mode === 0) { for (let i = 0x16194; i < 0x18ea8; i += 4) { - if (isModelExcluded(data[i], data[i + 1])) continue; + if (isModelExcluded(data[i], data[i + 1])) { + excluded++; + continue; + } data[i] = singleModel[0]; data[i + 1] = singleModel[1]; + replaced++; } } else if (mode === 1) { for (let i = 0x16194; i < 0x18ea8; i += 4) { - if (isModelExcluded(data[i], data[i + 1])) continue; + if (isModelExcluded(data[i], data[i + 1])) { + excluded++; + continue; + } const model = randomModels[_.random(randomModels.length - 1)]; data[i] = model[0]; data[i + 1] = model[1]; + replaced++; } } else if (mode === 2) { for (let i = 0x16194; i < 0x18ea8; i += 4) { const id = data[i]; const type = data[i + 1]; - if (isModelExcluded(id, type)) continue; - - const modelType = sameType - ? type - : allTypes[_.random(allTypes.length - 1)]; - const models = shuffledModels[modelType]; - - let modelId = models[_.random(models.length - 1)]; - - while (isModelBlacklisted(modelId, type)) { - modelId = models[_.random(models.length - 1)]; + if (isModelExcluded(id, type)) { + excluded++; + continue; } - data[i] = modelId; - data[i + 1] = type; + if (sameType) { + const models = shuffledModels[type]; + + let modelId = models[_.random(models.length - 1)]; + + while (isModelBlacklisted(modelId, type)) { + modelId = models[_.random(models.length - 1)]; + } + + data[i] = modelId; + data[i + 1] = type; + } else { + let [modelId, modelType] = _models[_.random(_models.length - 1)]; + + while (isModelBlacklisted(modelId, modelType)) { + [modelId, modelType] = _models[_.random(_models.length - 1)]; + } + + data[i] = modelId; + data[i + 1] = modelType; + } + + replaced++; } } // ----- } + console.log(`Replaced ${replaced} models - Excluded ${excluded}`); + fs.writeFileSync("output/character_character_data.bin", data); } diff --git a/models.js b/models.js index dba64e0..151029c 100644 --- a/models.js +++ b/models.js @@ -2911,6 +2911,7 @@ for (let type in allModels) { // ---------------------------------------- module.exports = { + _models, allModels, allTypes, shuffledModels,