// https://docs.google.com/spreadsheets/d/1-3E_t-KsFIw2rpM0hZIKOdNdGm5-GnQjvJb3cysOawE/edit#gid=1532331536 const fs = require("fs"); const _ = require("underscore"); const { allTypes, shuffledModels } = require("./models"); const { mode, sameType, singleModel, randomModels, excludedModels, 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]; if ( (model[0] === fb && model[1] === -1) || (model[0] === -1 && model[1] === sb) ) { return true; } else if (model[0] === fb && model[1] === sb) { return true; } } return false; } // Check if a model is blacklisted function isModelBlacklisted(fb, sb) { for (let i = 0; i < blacklistedModels.length; i++) { const model = blacklistedModels[i]; if ( (model[0] === fb && model[1] === -1) || (model[0] === -1 && model[1] === sb) ) { return blacklist.isWhitelist; } else if (model[0] === fb && model[1] === sb) { return blacklist.isWhitelist; } } return !blacklist.isWhitelist; } function replaceModels() { const data = fs.readFileSync("character_character_data.bin.orig"); // Magic if (mode === 0) { for (let i = 0x16194; i < 0x18ea8; i += 4) { if (isModelExcluded(data[i], data[i + 1])) continue; data[i] = singleModel[0]; data[i + 1] = singleModel[1]; } } else if (mode === 1) { for (let i = 0x16194; i < 0x18ea8; i += 4) { if (isModelExcluded(data[i], data[i + 1])) continue; const model = randomModels[_.random(randomModels.length - 1)]; data[i] = model[0]; data[i + 1] = model[1]; } } 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)]; } data[i] = modelId; data[i + 1] = type; } } // ----- fs.writeFileSync("character_character_data.bin", data); }