Skip to content

Commit 2e2ceac

Browse files
committed
Add option to revert applied Battle modification(s)
1 parent 44026ff commit 2e2ceac

File tree

3 files changed

+79
-4
lines changed

3 files changed

+79
-4
lines changed

Includes/Folders/Battle.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ namespace Battle {
2020
void AlwaysShiny(MenuEntry *entry);
2121
void ExpMultiplierKB(MenuEntry *entry);
2222
void ExpMultiplier(MenuEntry *entry);
23+
void RevertDefault(MenuEntry *entry);
2324
void Shiny100(MenuEntry *entry);
2425
void DisableShinyLock(MenuEntry *entry);
2526
}

Sources/Folders/Battle.cpp

Lines changed: 75 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ namespace Battle {
99
static vector<u32> pointer(2);
1010
static u8 slot;
1111
int valid;
12+
static bool isRevert = false;
1213

1314
vector<string> Identifier(vector<string> party) {
1415
int location, data;
@@ -151,20 +152,79 @@ namespace Battle {
151152
}
152153

153154
void Statistics(MenuEntry *entry) {
155+
static vector<vector<u16>> originalBase(2, vector<u16>(sizeof(baseVal) / sizeof(baseVal[0]), 1000));
156+
static vector<vector<u8>> originalBoost(2, vector<u8>(sizeof(boostVal) / sizeof(boostVal[0]), 7));
157+
u16 value;
158+
159+
if (IsInBattle() && entry->WasJustActivated()) {
160+
getOriginal:
161+
if (pointer[0] != 0 && pointer[1] != 0) {
162+
for (int i = 0; i < pointer.size(); i++) {
163+
Process::Read32(pointer[i], data32);
164+
165+
for (int j = 0; j < sizeof(baseVal) / sizeof(baseVal[0]); j++) {
166+
Process::Read16(data32 + Helpers::AutoRegion(0xF6, 0x1DA) + (j * 2), value);
167+
originalBase[i][j] = value;
168+
}
169+
170+
for (int k = 0; k < sizeof(boostVal) / sizeof(boostVal[0]); k++) {
171+
Process::Read16(data32 + Helpers::AutoRegion(0x104, 0x1EA) + (k * 1), value);
172+
originalBoost[i][k] = value;
173+
}
174+
}
175+
}
176+
}
177+
178+
if (IsInBattle() && entry->IsActivated()) {
179+
if (pointer[0] != 0 && pointer[1] != 0) {
180+
for (int i = 0; i < pointer.size(); i++) {
181+
for (int j = 0; j < sizeof(baseVal) / sizeof(baseVal[0]); j++) {
182+
if (originalBase[i][j] == 1000)
183+
goto getOriginal;
184+
}
185+
186+
for (int k = 0; k < sizeof(boostVal) / sizeof(boostVal[0]); k++) {
187+
if (originalBoost[i][k] == 7)
188+
goto getOriginal;
189+
}
190+
}
191+
}
192+
}
193+
194+
if (!IsInBattle()) {
195+
if (pointer[0] != 0 && pointer[1] != 0) {
196+
for (int i = 0; i < pointer.size(); i++) {
197+
fill(originalBase[i].begin(), originalBase[i].end(), 1000);
198+
fill(originalBoost[i].begin(), originalBoost[i].end(), 7);
199+
}
200+
}
201+
}
202+
154203
if (IsInBattle()) {
155204
if (pointer[0] != 0 && pointer[1] != 0) {
156205
for (int i = 0; i < pointer.size(); i++) {
157206
for (int k = 0; k < sizeof(baseVal) / sizeof(baseVal[0]); k++) {
158-
if (baseVal[k] != 0)
159-
ProcessPlus::Write16(pointer[i], Helpers::AutoRegion(0xF6, 0x1DA) + (k * 2), baseVal[k]);
207+
if (isRevert)
208+
ProcessPlus::Write16(pointer[i], Helpers::AutoRegion(0xF6, 0x1DA) + (k * 2), originalBase[i][k]);
209+
210+
if (!isRevert && baseVal[k] != 0)
211+
ProcessPlus::Write16(pointer[i], Helpers::AutoRegion(0xF6, 0x1DA) + (k * 2), baseVal[k]);
160212
}
161213

162214
for (int l = 0; l < sizeof(boostVal) / sizeof(boostVal[0]); l++) {
163-
if (boostVal[l] != 0)
215+
if (isRevert)
216+
ProcessPlus::Write8(pointer[i], Helpers::AutoRegion(0x104, 0x1EA) + (l * 1), originalBoost[i][l]);
217+
218+
if (!isRevert && boostVal[l] != 0)
164219
ProcessPlus::Write8(pointer[i], Helpers::AutoRegion(0x104, 0x1EA) + (l * 1), boostVal[l]);
165220
}
166221
}
167222
}
223+
224+
if (isRevert) {
225+
entry->Disable();
226+
return;
227+
}
168228
}
169229
}
170230

@@ -306,6 +366,18 @@ namespace Battle {
306366
}
307367
}
308368

369+
void RevertDefault(MenuEntry *entry) {
370+
if (MessageBox(CenterAlign("Revert everything?"), DialogType::DialogYesNo, ClearScreen::Both)()) {
371+
isRevert = true;
372+
entry->Name() = "Revert to Default: " << Color::Green << "On";
373+
Message::Completed();
374+
return;
375+
}
376+
377+
entry->Name() = "Revert to Default: " << Color::Red << "Off";
378+
isRevert = false;
379+
}
380+
309381
bool IsValid(u32 pointer, PK6 *pkmn) {
310382
if (!GetPokemon(pointer, pkmn))
311383
return false;

Sources/Menu.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,9 @@ void InitMenu(PluginMenu &menu) {
6464
new MenuEntry("Invincibility", Battle::Universal::Invincibility, Battle::Universal::InvincibilityKB),
6565
new MenuEntry("Item", nullptr, Battle::Universal::Item),
6666
new MenuEntry("Attacks", nullptr, Battle::Universal::Attacks),
67-
new MenuEntry("Exp. Multiplier", Battle::Universal::ExpMultiplier, Battle::Universal::ExpMultiplierKB)
67+
new MenuEntry("Exp. Multiplier", Battle::Universal::ExpMultiplier, Battle::Universal::ExpMultiplierKB),
68+
new MenuEntry(Color::Gray << "Settings"),
69+
new MenuEntry("Revert to Default: " << Color::Red << "Off", nullptr, Battle::Universal::RevertDefault)
6870
}));
6971

7072
*primary += EntryWithHotkey(new MenuEntry("Poké View", nullptr, Battle::Universal::PokeView, note + "press the following hotkey(s) below to see the other information. Be aware that this is experiemental for now."), {Key::X, ""});

0 commit comments

Comments
 (0)