Skip to content

Commit bada1ed

Browse files
authored
Merge pull request #209 from RedShyGuy/hotfix/2.0.2
Hotfix/2.0.2
2 parents ed15b21 + bc567a1 commit bada1ed

File tree

13 files changed

+179
-45
lines changed

13 files changed

+179
-45
lines changed

Includes/Address/Addresses.hpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,13 @@
33
#include "types.h"
44

55
static const u32 ADDRESSES[][8] = {
6+
{ 0x6AF954, 0x6AEE7C, 0x6AE98C, 0x6AE98C, 0x6AE324, 0x6AE324, 0x6ADECC, 0x6ADECC }, //BADGE_AFTERWARDS
7+
{ 0x6AECA0, 0x6AE1C8, 0x6ADCD8, 0x6ADCD8, 0x6AD72C, 0x6AD72C, 0x6AD2D4, 0x6AD2D4 }, //BADGE_FIRST
8+
{ 0x19CE64, 0x19C8AC, 0x19CE84, 0x19CE84, 0x19CDC4, 0x19CDC4, 0x19CDC4, 0x19CDC4 }, //HOVERED_ITEM_NAME
69
{ 0x6BAC8C, 0x6BA13C, 0x6B9CC4, 0x6B9C9C, 0x6B95BC, 0x6B9594, 0x6B9164, 0x6B913C }, //SEED_ITEM_LEGIT
710
{ 0x4E1720, 0x4E1098, 0x4E0768, 0x4E0768, 0x4E0364, 0x4E0364, 0x4DFB3C, 0x4DFB3C }, //MOVING_FURNITURE
8-
{ 0x678AC0, 0x677FE8, 0x677AF8, 0x677AF8, 0x6775B8, 0x6775B8, 0x677160, 0x677160 }, //PICKING_UP_FURNITURE
9-
{ 0x76B880, 0x76A864, 0x76A888, 0x76A860, 0x76A020, 0x769FF8, 0x769BC8, 0x769BA0 }, //PLACING_FURNITURE1
11+
{ 0x678AC0, 0x677FE8, 0x677AF8, 0x677AF8, 0x6775B8, 0x6775B8, 0x677160, 0x677160 }, //PICKING_UP_FURNITURE
12+
{ 0x76B880, 0x76A864, 0x76A888, 0x76A860, 0x76A020, 0x769FF8, 0x769BC8, 0x769BA0 }, //PLACING_FURNITURE1
1013
{ 0x26FED8, 0x26F91C, 0x26FED4, 0x26FED4, 0x26FDE0, 0x26FDE0, 0x26FDAC, 0x26FDAC }, //PLACING_FURNITURE2
1114
{ 0x4E78A8, 0x4E7220, 0x4E68F0, 0x4E68F0, 0x4E64EC, 0x4E64EC, 0x4E5CC4, 0x4E5CC4 }, //PLACING_FURNITURE3
1215
{ 0x3279CC, 0x3273E0, 0x326D20, 0x326D20, 0x3269AC, 0x3269AC, 0x326864, 0x326864 }, //LIGHTSWITCH_VISIBLE
@@ -19,8 +22,6 @@ static const u32 ADDRESSES[][8] = {
1922
{ 0x2FEA78, 0x2FE7F4, 0x2FEA0C, 0x2FEA0C, 0x2FEAAC, 0x2FEAAC, 0x2FE9E4, 0x2FE9E4 }, //GET_ITEM_NAME
2023
{ 0x767028, 0x76600C, 0x766030, 0x766008, 0x7657C8, 0x7657A0, 0x765370, 0x765348 }, //DEVER5
2124
{ 0x2912B8, 0x290CFC, 0x2912B4, 0x2912B4, 0x2911B4, 0x2911B4, 0x29118C, 0x29118C }, //DISP
22-
{ 0xC, 0xC, 0xC, 0xC, 0, 0, 0, 0 }, //FIX
23-
{ 0x2C, 0x30, 0x2C, 0x30, 0x30, 0x30, 0x2C, 0x30 }, //CALC
2425
{ 0x2F7384, 0x2F74C8, 0x2F73AC, 0x2F73AC, 0x2F75CC, 0x2F75CC, 0x2F7488, 0x2F7488 }, //GETROOM
2526
{ 0x51C104, 0x51BA58, 0x51B14C, 0x51B14C, 0x51AA68, 0x51AA68, 0x51A3FC, 0x51A3FC }, //OFFSETPATCH
2627
{ 0x51BBDC, 0x51B530, 0x51AC24, 0x51AC24, 0x51A540, 0x51A540, 0x519ED4, 0x519ED4 }, //OFFSETHOOK

Includes/Helpers/Checks.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include "Helpers/GameStructs.hpp"
55

66
namespace CTRPluginFramework {
7+
void CheckInvalidBadge(u32 data, u32 badge, int badgeType, u32 r3, u32 r4);
78
void OnTitleScreen(u8 roomId, bool u0, bool u1, bool u2);
89
void InvalidGiveItem(bool var1, Item* item, u32 data);
910
u32 InvalidPickStop(u8 ID, Item *ItemToReplace, Item *ItemToPlace, Item *ItemToShow, u8 worldx, u8 worldy);
@@ -13,7 +14,8 @@ namespace CTRPluginFramework {
1314
bool InvalidItemStop(Item* item);
1415
bool ConvertFlower(Item *item);
1516
bool IsItemReplaceable(Item *item);
16-
void NameFunc(u32 u0, u32 u1, u32 u2);
17+
void SetHoveredItemName(u32 r0, u32 r1, u32 r2, u32 r3);
18+
void SetItemName(u32 u0, u32 u1, u32 u2);
1719
bool IsItemDroppable(u32 ItemData, Item *ItemID, int SecondaryItemFlag);
1820
bool IsItemPlantable(u32 ItemData, Item *ItemID);
1921
int CatalogPatch_Keyboard(u32 u0, u32 u1, u32 u2);

Includes/cheats.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@ namespace CTRPluginFramework {
233233
void DisableAllChecks(void);
234234
void DisableAllPatches(void);
235235

236+
void CheckInvalidBadgeEntry(MenuEntry *entry);
236237
void SeedItemLegitimacyEntry(MenuEntry *entry);
237238
void OnlineDropLagRemoverEntry(MenuEntry *entry);
238239
void ChangeRockbreakParticleEntry(MenuEntry *entry);

Sources/Folders/AnimationCodes.cpp

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -20,33 +20,34 @@ namespace CTRPluginFramework {
2020
//Speed
2121
bool speedmode = false;
2222

23-
static Address playerSelect(0x305EF0);
24-
static Address playerSelect2 = playerSelect.MoveOffset(4);
23+
bool IsPlayerSelectEnabled = false;
2524

26-
void PSelector_Set(u8 pIndex) {
27-
playerSelect.Patch(0xE3A00000 + pIndex);
28-
playerSelect2.Patch(0xE12FFF1E);
29-
}
30-
31-
void PSelector_OFF(void) {
32-
playerSelect.Unpatch();
33-
playerSelect2.Unpatch();
34-
}
25+
void TogglePlayerSelect(u8 pIndex) {
26+
static Address playerSelect(0x305EF0);
27+
static Address playerSelect2 = playerSelect.MoveOffset(4);
3528

36-
bool PSelector_ON(void) {
37-
return (*(u32 *)playerSelect.addr != playerSelect.origVal);
29+
if (pIndex < 4) {
30+
playerSelect.Patch(0xE3A00000 + pIndex);
31+
playerSelect2.Patch(0xE12FFF1E);
32+
IsPlayerSelectEnabled = true;
33+
}
34+
else {
35+
playerSelect.Unpatch();
36+
playerSelect2.Unpatch();
37+
IsPlayerSelectEnabled = false;
38+
}
3839
}
3940

4041
//check to make player selector better
4142
void PlayerSelectCheck(void) {
42-
if(!PSelector_ON()) {
43+
if(!IsPlayerSelectEnabled) {
4344
return;
4445
}
4546

4647
u8 pIndex = Game::GetOnlinePlayerIndex();
4748
//If player is not loaded or loading screen started, switch off the code
4849
if(!PlayerClass::GetInstance()->IsLoaded() || !PlayerClass::GetInstance(pIndex)->IsLoaded() || Game::IsRoomLoading()) {
49-
PSelector_OFF();
50+
TogglePlayerSelect(4);
5051
}
5152
}
5253

@@ -76,7 +77,7 @@ namespace CTRPluginFramework {
7677
int pChoice = pKB.Open();
7778
if(pChoice >= 0) {
7879
if(pV[pChoice] != Color::Silver << "-Empty-") {
79-
PSelector_Set(pChoice);
80+
TogglePlayerSelect(pChoice);
8081
OSD::Notify(Utils::Format("Controlling Player: %02X Enabled!", pChoice));
8182
}
8283
else {
@@ -86,16 +87,16 @@ namespace CTRPluginFramework {
8687
}
8788

8889
else if(entry->Hotkeys[1].IsPressed()) {
89-
if(PSelector_ON()) {
90+
if(IsPlayerSelectEnabled) {
9091
OSD::Notify(Utils::Format("Controlling Player: %02X Disabled!", *(u8 *)(Address(0x75F010).addr + 0x10)));
91-
PSelector_OFF();
92+
TogglePlayerSelect(4);
9293
return;
9394
}
9495
OSD::Notify("Error: No Player Is Selected!", Color::Red);
9596
}
9697

9798
if(!entry->IsActivated()) {
98-
PSelector_OFF();
99+
TogglePlayerSelect(4);
99100
PluginMenu *menu = PluginMenu::GetRunningInstance();
100101
*menu -= PlayerSelectCheck;
101102
}

Sources/Folders/DefaultCodes/DefaultChecks.cpp

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ namespace CTRPluginFramework {
2828
return optKb.Open();
2929
}
3030

31+
static Hook CheckInvalidBadgeHook1, CheckInvalidBadgeHook2;
3132
static Hook SaveButtonCheck;
3233
static Hook CatalogPHook1, CatalogPHook2;
3334
static Hook IPHook;
@@ -37,6 +38,7 @@ namespace CTRPluginFramework {
3738
static Hook IHHook;
3839
static Hook IIHook;
3940
static Hook CFHook;
41+
static Hook HoveredNameHook;
4042
static Hook NameHook;
4143
static Hook ReplaceHook;
4244
static Hook DropHook1, DropHook2, DropHook3, DropHook4;
@@ -45,6 +47,9 @@ namespace CTRPluginFramework {
4547
static Hook OnProDesignHook;
4648

4749
void EnableAllChecks() {
50+
SetHook(CheckInvalidBadgeHook1, Address(0x6AF954).addr, (u32)CheckInvalidBadge, USE_LR_TO_RETURN);
51+
SetHook(CheckInvalidBadgeHook2, Address(0x6AECA0).addr, (u32)CheckInvalidBadge, USE_LR_TO_RETURN);
52+
4853
SetHook(SaveButtonCheck, Address(0x1A0980).addr - 0x10, (u32)IsSTARTDown, USE_LR_TO_RETURN);
4954

5055
SetHook(CatalogPHook1, Address(0x21C408).addr, (u32)CatalogPatch_Keyboard, USE_LR_TO_RETURN);
@@ -65,7 +70,8 @@ namespace CTRPluginFramework {
6570

6671
SetHook(CFHook, Address(0x323514).addr, (u32)ConvertFlower, USE_LR_TO_RETURN);
6772

68-
SetHook(NameHook, Address(0x19C498).addr, (u32)NameFunc, USE_LR_TO_RETURN);
73+
SetHook(HoveredNameHook, Address(0x19CE64).addr, (u32)SetHoveredItemName, USE_LR_TO_RETURN);
74+
SetHook(NameHook, Address(0x19C498).addr, (u32)SetItemName, USE_LR_TO_RETURN);
6975

7076
SetHook(ReplaceHook, Address(0x165528).addr, (u32)IsItemReplaceable, USE_LR_TO_RETURN);
7177

@@ -86,6 +92,8 @@ namespace CTRPluginFramework {
8692
}
8793

8894
void DisableAllChecks() {
95+
CheckInvalidBadgeHook1.Disable();
96+
CheckInvalidBadgeHook2.Disable();
8997
SaveButtonCheck.Disable();
9098
CatalogPHook1.Disable();
9199
CatalogPHook2.Disable();
@@ -97,6 +105,7 @@ namespace CTRPluginFramework {
97105
IHHook.Disable();
98106
IIHook.Disable();
99107
CFHook.Disable();
108+
HoveredNameHook.Disable();
100109
NameHook.Disable();
101110
ReplaceHook.Disable();
102111
DropHook1.Disable();
@@ -112,6 +121,22 @@ namespace CTRPluginFramework {
112121
OnProDesignHook.Disable();
113122
}
114123

124+
void CheckInvalidBadgeEntry(MenuEntry *entry) {
125+
int res = OptionKeyboard();
126+
if(res < 0) {
127+
return;
128+
}
129+
130+
if (res == 0) {
131+
CheckInvalidBadgeHook1.Enable();
132+
CheckInvalidBadgeHook2.Enable();
133+
}
134+
else {
135+
CheckInvalidBadgeHook1.Disable();
136+
CheckInvalidBadgeHook2.Disable();
137+
}
138+
}
139+
115140
void DisableOpenSaveMenuWithStartButton(MenuEntry *entry) {
116141
int res = OptionKeyboard();
117142
if(res < 0) {
@@ -249,9 +274,11 @@ namespace CTRPluginFramework {
249274
}
250275

251276
if (res == 0) {
277+
HoveredNameHook.Enable();
252278
NameHook.Enable();
253279
}
254280
else {
281+
HoveredNameHook.Disable();
255282
NameHook.Disable();
256283
}
257284
}

Sources/Folders/InventoryCodes.cpp

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -348,10 +348,20 @@ namespace CTRPluginFramework {
348348
}
349349
}
350350

351-
void Hook_MenuPatch(void) {
352-
Game::OpenMenu(CurrentMenu);
353-
PluginMenu *menu = PluginMenu::GetRunningInstance();
354-
*menu += Callback_MenuPatch;
351+
void Hook_MenuPatch(u32 r0, u32 r1, u32 r3) {
352+
u8 roomId = Player::GetRoom(4);
353+
if (roomId == 0xA1 || roomId == 0xA2 || (roomId >= 0x92 && roomId <= 0x97)) {
354+
OSD::Notify("Custom Save Menu doesn't work in this room!", Color::Red);
355+
356+
const HookContext &curr = HookContext::GetCurrent();
357+
static Address func = Address::decodeARMBranch(curr.targetAddress, curr.overwrittenInstr);
358+
func.Call<void>(r0, r1, r3);
359+
}
360+
else {
361+
Game::OpenMenu(CurrentMenu);
362+
PluginMenu *menu = PluginMenu::GetRunningInstance();
363+
*menu += Callback_MenuPatch;
364+
}
355365
}
356366

357367
//Menu Changer

Sources/Folders/MiscCodes.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,30 @@ namespace CTRPluginFramework {
225225
}
226226

227227
u32 LightSwitchPatch(void) {
228+
static const u8 r_Array[14] = {
229+
0x02, //Train Station
230+
0x26, //Town Hall
231+
0x30, //Police Station
232+
0x31, //Police Station
233+
0x39, //T&T Mart
234+
0x3A, //Super T&T
235+
0x3B, //TIY
236+
0x3F, //Able Sisters Mable & Sable
237+
0x41, //Nooks Homes
238+
0x43, //Gardening Store
239+
0x44, //Gardening Store
240+
0x48, //Shampoodle
241+
0x5A, //Post Office
242+
0x67, //Island (Might freeze?)
243+
};
244+
245+
u8 stageID = CTRPluginFramework::Player::GetRoom(4);
246+
for (u8 i = 0; i < 14; ++i) {
247+
if(stageID == r_Array[i]) {
248+
return 0; //Disable lightswitch if invalid room
249+
}
250+
}
251+
228252
return Player::IsIndoors();
229253
}
230254

Sources/Helpers/Checks.cpp

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,17 @@ extern "C" bool __IsPlayerHouse() {
3636
}
3737

3838
namespace CTRPluginFramework {
39+
void CheckInvalidBadge(u32 data, u32 badge, int badgeType, u32 r3, u32 r4) {
40+
if (badgeType > 3) {
41+
OSD::Notify("Invalid Badge Type! Can't display badge properly.", Color::Red);
42+
return;
43+
}
44+
45+
const HookContext &curr = HookContext::GetCurrent();
46+
static Address func = Address::decodeARMBranch(curr.targetAddress, curr.overwrittenInstr);
47+
func.Call<void>(data, badge, badgeType, r3, r4);
48+
}
49+
3950
//Hook invalid pickup
4051
u32 InvalidPickStop(u8 ID, Item *ItemToReplace, Item *ItemToPlace, Item *ItemToShow, u8 worldx, u8 worldy) {
4152
if(ItemToReplace->isValid()) {
@@ -129,7 +140,30 @@ namespace CTRPluginFramework {
129140
return false;
130141
}
131142

132-
void NameFunc(u32 r0, u32 r1, u32 r2) {
143+
void SetHoveredItemName(u32 r0, u32 r1, u32 r2, u32 r3) {
144+
Item itemslotid = {0x7FFE, 0};
145+
u8 slot = 0;
146+
147+
if(Inventory::GetHoveredSlot(slot)) {
148+
if(Inventory::ReadSlot(slot, itemslotid)) {
149+
itemslotid.Flags = 0;
150+
if(Game::IsOutdoorItem(itemslotid) || itemslotid.ID == 0x3729) {
151+
std::string name = itemslotid.GetName();
152+
Process::Write32(r1 + 0x18, 0x000E000E);
153+
Process::Write32(r1 + 0x1C, 0x00040000);
154+
Process::Write32(r1 + 0x20, 0xCD030100);
155+
156+
Process::WriteString(r1 + 0x24, itemslotid.isValid(false) ? name : "Invalid Item", StringFormat::Utf16);
157+
}
158+
}
159+
}
160+
161+
const HookContext &curr = HookContext::GetCurrent();
162+
static Address func = Address::decodeARMBranch(curr.targetAddress, curr.overwrittenInstr);
163+
func.Call<void>(r0, r1, r2, r3);
164+
}
165+
166+
void SetItemName(u32 r0, u32 r1, u32 r2) {
133167
Item itemslotid = {0x7FFE, 0};
134168
u8 slot = 0;
135169

Sources/Helpers/Game.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -434,12 +434,14 @@ namespace CTRPluginFramework {
434434

435435
//get map boolen pointer
436436
bool Game::MapBoolCheck() {
437-
return *(bool *)Address(0x950C30).addr;
437+
static const Address mapBool(0x950C30);
438+
return *(bool *)mapBool.addr;
438439
}
439440

440441
//Get online index
441442
u8 Game::GetOnlinePlayerIndex() {
442-
return Address(0x305EF0).Call<u8>();
443+
static Address playerIndex(0x305EF0);
444+
return playerIndex.Call<u8>();
443445
}
444446

445447
//Get actual index

Sources/Helpers/KeepConnection.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,14 @@ namespace CTRPluginFramework {
111111

112112
void PatchThreadBegin(u32 threadfunc, u32 threadargs, u32 startFunc, u32 u0) {
113113
static Address point(0x953CA0);
114-
static Address calc(0x2C);
115114

116-
static u32 threadAddress = *(u32 *)(*(u32 *)(point.addr) + 0xA8 + 0x80) - calc.addr;
115+
u8 fixOffset = 0x30; //For USAWA, EURWA, JPN, JPNWA, KORWA
116+
if (Address::IsRegion(Address::Region::USA) || Address::IsRegion(Address::Region::EUR)
117+
|| Address::IsRegion(Address::Region::KOR)) {
118+
fixOffset = 0x2C;
119+
}
120+
121+
static u32 threadAddress = *(u32 *)(*(u32 *)(point.addr) + 0xA8 + 0x80) - fixOffset;
117122

118123
static u32 onlineThreadArgs[ONLINETHREADSAMOUNT] = {
119124
0x82C0FF8, //Region Free

0 commit comments

Comments
 (0)