|
| 1 | +#include "gz_cheats.hpp" |
| 2 | +#include "gz_settings.hpp" |
| 3 | +#include "mem.hpp" |
| 4 | + |
| 5 | +#include <Unknown/UnkStruct_027e0ce0.hpp> |
| 6 | +#include <Unknown/UnkStruct_ov024_020d86b0.hpp> |
| 7 | + |
| 8 | +static bool CheckCheat(int itemIndex) { |
| 9 | + if (itemIndex < GZCheat_Max) { |
| 10 | + return gCheatManager.Check(itemIndex); |
| 11 | + } |
| 12 | + |
| 13 | + return false; |
| 14 | +} |
| 15 | + |
| 16 | +static void ToggleCheat(u32 params) { |
| 17 | + if (params < GZCheat_Max) { |
| 18 | + gCheatManager.Toggle(params); |
| 19 | + } |
| 20 | +} |
| 21 | + |
| 22 | +#define DEFINE_CHEAT(enum, name) {name, GZMenuItemType_Bool, CheckCheat, ToggleCheat, GZCheat_##enum, NULL, 0}, |
| 23 | +static GZMenuItem sCheatMenuItems[GZCheat_Max] = { |
| 24 | +#include "cheats.inl" |
| 25 | +}; |
| 26 | +#undef DEFINE_CHEAT |
| 27 | + |
| 28 | +GZCheatManager gCheatManager; |
| 29 | + |
| 30 | +GZCheatManager::GZCheatManager() { |
| 31 | + this->mMenu.title = "Cheats"; |
| 32 | + this->mMenu.parent = gMenuManager.GetMainMenu(); |
| 33 | + this->mMenu.entries = sCheatMenuItems; |
| 34 | + this->mMenu.mCount = ARRAY_LEN(sCheatMenuItems); |
| 35 | + this->mMenu.needSaveFile = true; |
| 36 | + gCheatManager.SetCheatBitfieldPtr(gSettings.mProfiles[gSettings.mProfileHeader.curProfileIndex].mCheatBitfield); |
| 37 | +} |
| 38 | + |
| 39 | +void GZCheatManager::SetCheatBitfieldPtr(u32* pBitfield) { this->mpCheatBitfield = pBitfield; } |
| 40 | + |
| 41 | +bool GZCheatManager::Check(GZCheat eCheat) { |
| 42 | + return this->mpCheatBitfield != NULL ? this->mpCheatBitfield[0] & (1 << eCheat) : false; |
| 43 | +} |
| 44 | + |
| 45 | +void GZCheatManager::Toggle(GZCheat eCheat) { |
| 46 | + u32 value = 1 << eCheat; |
| 47 | + |
| 48 | + if (this->mpCheatBitfield == NULL) { |
| 49 | + return; |
| 50 | + } |
| 51 | + |
| 52 | + if (this->mpCheatBitfield[0] & value) { |
| 53 | + this->mpCheatBitfield[0] &= ~value; |
| 54 | + } else { |
| 55 | + this->mpCheatBitfield[0] |= value; |
| 56 | + } |
| 57 | +} |
| 58 | + |
| 59 | +void GZCheatManager::Update() { |
| 60 | + if (data_027e0ce0 != NULL && data_027e0ce0->mUnk_28 != NULL) { |
| 61 | + if (this->Check(GZCheat_Health)) { |
| 62 | + //! TODO: find out what updates the hearts visually |
| 63 | + data_027e0ce0->mHealth = data_027e0ce0->mHealthMax; |
| 64 | + } |
| 65 | + |
| 66 | + if (this->Check(GZCheat_Rupees)) { |
| 67 | + data_027e0ce0->mUnk_28->mNumRupees = 9999; |
| 68 | + } |
| 69 | + |
| 70 | + if (this->Check(GZCheat_Arrows)) { |
| 71 | + data_027e0ce0->mUnk_28->mArrowAmount = data_027e0ce0->mUnk_28->func_ov000_020a8728(); |
| 72 | + } |
| 73 | + |
| 74 | + if (this->Check(GZCheat_Bombs)) { |
| 75 | + data_027e0ce0->mUnk_28->mBombAmount = data_027e0ce0->mUnk_28->func_ov000_020a8748(); |
| 76 | + } |
| 77 | + } |
| 78 | + |
| 79 | + if (data_ov024_020d86b0 != NULL) { |
| 80 | + if (this->Check(GZCheat_Postcards)) { |
| 81 | + data_ov024_020d86b0->mNumPostcards = 127; |
| 82 | + } |
| 83 | + } |
| 84 | +} |
0 commit comments