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)
This commit is contained in:
Lordmau5 2020-05-21 19:21:06 +02:00
parent 32156b09bb
commit 3993a25e4f
3 changed files with 58 additions and 24 deletions

View File

@ -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,
};

View File

@ -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);
}

View File

@ -2911,6 +2911,7 @@ for (let type in allModels) {
// ----------------------------------------
module.exports = {
_models,
allModels,
allTypes,
shuffledModels,