From 90d65a9ee34932c891878d3522f72be7408a14f4 Mon Sep 17 00:00:00 2001 From: Sheila Aman Date: Sat, 5 Jun 2021 13:44:31 -0500 Subject: [PATCH] Randomizer mode works, add magic fix. --- patches/rando/fixmagic.ips | Bin 0 -> 90 bytes src/exdeath.cc | 10 +++++-- src/randomizer.cc | 55 +++++++++++++++++++++++++------------ 3 files changed, 45 insertions(+), 20 deletions(-) create mode 100644 patches/rando/fixmagic.ips diff --git a/patches/rando/fixmagic.ips b/patches/rando/fixmagic.ips new file mode 100644 index 0000000000000000000000000000000000000000..23b83afba16bca881abec982965b4ebdfda4dbd5 GIT binary patch literal 90 zcmV-g0Hyy>K~zIX1ABx3Fds^)7!i0d90Bn9{RA8$92rS)7y)P*OUM`iXaqCK7zubC w@csG#U;roz&>$TD=L47W00sseB^(ss1DFf|0c``A8~_0U1DGTL0fj|RM${`A-v9sr literal 0 HcmV?d00001 diff --git a/src/exdeath.cc b/src/exdeath.cc index 7b0d105..927ddd8 100644 --- a/src/exdeath.cc +++ b/src/exdeath.cc @@ -78,7 +78,7 @@ void Exdeath::initMain(void) { selMode = new QComboBox(); selMode->addItem("Base"); - selMode->addItem("Randomizer"); + selMode->addItem("Randomizer", "rando/fixmagic.ips"); selMode->addItem("Unlocked Jobs", "unlock.ips"); selMode->addItem("Balance", "balance.ips"); selMode->addItem("Custom Classes", "custom_classes.ips"); @@ -268,7 +268,7 @@ void Exdeath::btnApply_clicked(bool trigger) { std::mt19937 rand(numSeed->value()); std::uniform_int_distribution<> dist(1, selNED->count() - 1); - if (mode > 1) { + if (mode > 0) { patches << ":/patches/" + selMode->itemData(mode).toString(); } if (chkPortraits->isChecked()) { @@ -321,10 +321,14 @@ void Exdeath::btnApply_clicked(bool trigger) { } bool global_innates = (chkPassages->isChecked() || chkPitfalls->isChecked() || chkLiteStep->isChecked() || chkDash->isChecked() || chkLearning->isChecked()); - // gyahahaha RANDOMIZER!! if (mode == 1) { Randomizer *rando = new Randomizer(rand); + QFile *pfile = new QFile(output + ".ips"); + pfile->open(QIODevice::WriteOnly); QBuffer *patch = rando->makeRandom(global_innates); + pfile->write(patch->readAll()); + patch->seek(0); + pfile->close(); applyPatch(target, patch); } if (global_innates) { diff --git a/src/randomizer.cc b/src/randomizer.cc index 6a1ee66..5788fbf 100644 --- a/src/randomizer.cc +++ b/src/randomizer.cc @@ -282,25 +282,36 @@ void Randomizer::randomizeSkills(void) { std::shuffle(l_tier6->begin(), l_tier6->end(), rng); std::shuffle(l_tier4->begin(), l_tier4->end(), rng); std::shuffle(l_tier2->begin(), l_tier2->end(), rng); + actions->append(*l_tier4); + actions->append(*l_tier2); for (int i = 0; i < 20; i++) { jobs[i] = new QVector(); costs[i] = new QVector(); } + QVector *job_list = new QVector(); + for (int i = 0; i < JOB_COUNT; i++) { + job_list->append(i); + } + std::shuffle(job_list->begin(), job_list->end(), rng); - while (tierpos < 6) { - if (skills[tierpos]->count() < 1) { - tierpos += 1; - } + while (tierpos < 5) { for (int i = 0; i < JOB_COUNT; i++) { - Skill temp = skills[i]->first(); + int job = job_list->at(i); + if (skills[tierpos]->count() < 1) { + tierpos += 1; + } + if (skills[tierpos]->isEmpty()) { + break; + } + Skill temp = skills[tierpos]->first(); int minimum = 0; - if (costs[i]->count() > 0) { + if (costs[job]->count() > 0) { minimum = costs[i]->last(); } - skills[i]->removeFirst(); - jobs[i]->append(temp); - costs[i]->append(tierCost(tierpos, minimum)); + skills[tierpos]->removeFirst(); + jobs[job]->append(temp); + costs[job]->append(tierCost(tierpos, minimum)); } } @@ -315,14 +326,12 @@ void Randomizer::randomizeSkills(void) { actions->removeFirst(); commands->insert(job, temp); } - actions->append(*l_tier4); for (int i = 0; i < jobs2->count(); i++) { int job = jobs2->at(i); Skill temp = actions->first(); actions->removeFirst(); commands->insert(job, temp); } - actions->append(*l_tier2); for (int i = 0; i < jobs3->count(); i++) { int job = jobs3->at(i); Skill temp = actions->first(); @@ -341,6 +350,8 @@ QByteArray be24(int num) { QBuffer *Randomizer::writePatch(void) { QBuffer *patch = new QBuffer(); + patch->open(QIODevice::ReadWrite); + patch->write("PATCH"); // job commands @@ -350,7 +361,7 @@ QBuffer *Randomizer::writePatch(void) { continue; } patch->write(be24(0x15616c + (i * 4) + 1)); - patch->write("\x00\x01"); + patch->write("\x00\x01", 2); QByteArray temp; temp.append(commands->at(i) & 0xFF); patch->write(temp); @@ -358,7 +369,7 @@ QBuffer *Randomizer::writePatch(void) { // ability counts patch->write(be24(0x14b1fc)); - patch->write("\x00\x14"); + patch->write("\x00\x14", 2); for (int i = 0; i < JOB_COUNT; i++) { char count = jobs[i]->count(); patch->putChar(count); @@ -366,14 +377,15 @@ QBuffer *Randomizer::writePatch(void) { // table offset patch->write(be24(0x155484)); - patch->write("\x00\x50"); + patch->write("\x00\x50", 2); for (int i = 0; i < JOB_COUNT; i++) { - patch->write("\xe8\x54\x15\x08"); + patch->write("\xe8\x54\x15\x08", 4); } // ability lists patch->write(be24(0x1554E8)); - patch->write("\x00\x50"); + QByteArray abilities; + for (int i = 0; i < JOB_COUNT; i++) { QVector *job = jobs[i]; char count = job->count(); @@ -387,9 +399,18 @@ QBuffer *Randomizer::writePatch(void) { // skill data.append(job->at(j) & 0xFF); data.append((char)0); - patch->write(data); + abilities.append(data); } } + unsigned short size = abilities.count(); + char csize[3]; + csize[0] = (size >> 8) & 0xFF; + csize[1] = size & 0xFF; + csize[2] = NULL; + patch->write(csize, 2); + patch->write(abilities); + patch->write("EOF"); + patch->seek(0); return patch; }