/
mod.cpp
215 lines (187 loc) · 5.11 KB
/
mod.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
#include "mod_ui_base/window.h"
#include "apwindow.h"
#include "chainloader.h"
#include "consolewindow.h"
#include "custompit.h"
#include "evtdebug.h"
#include "exception.h"
#include "gamesavemenu.h"
#include "hitboxmenu.h"
#include "hpwindow.h"
#include "inputwindow.h"
#include "mainmenu.h"
#include "mapdoorwindow.h"
#include "mapselectmenu.h"
#include "mod.h"
#include "nandsettings.h"
#include "patch.h"
#include "pyconsole.h"
#include "parsepatches.h"
#include "romfontexpand.h"
#include "scriptlog.h"
#include "scriptvarlog.h"
#include "titletextwindow.h"
#include "xyzwindow.h"
#include <types.h>
#include <spm/camdrv.h>
#include <spm/charpixlitemwin.h>
#include <spm/effdrv.h>
#include <spm/fadedrv.h>
#include <spm/homebuttondrv.h>
#include <spm/mario.h>
#include <spm/mario_motion.h>
#include <spm/relmgr.h>
#include <spm/seqdef.h>
#include <spm/seqdrv.h>
#include <spm/spmario.h>
#include <spm/spmario_snd.h>
#include <spm/system.h>
#include <spm/wpadmgr.h>
#include <wii/DVD_Broadway.h>
#include <wii/DVDFS.h>
#include <wii/ipc.h>
#include <wii/OSError.h>
#include <wii/wpad.h>
#include <wii/string.h>
namespace mod {
bool gIsDolphin;
bool gIsRiivolution;
bool gIsPatchedDisc;
bool gIs4_3;
/*
seq_game hooks
*/
static spm::seqdef::SeqDef seq_gameReal;
static void seq_gameInitOverride(spm::seqdrv::SeqWork * wp)
{
MapSelectMenu::onMapChanged();
seq_gameReal.init(wp);
}
static void seq_gameMainOverride(spm::seqdrv::SeqWork *wp)
{
// Check if a window could be opened
if (spm::wpadmgr::wpadGetButtonsPressed(0) & WPAD_BTN_B)
{
if (MenuWindow::sCurMenu == nullptr)
{
if (spm::fadedrv::fadeIsFinish() &&
!spm::mario::marioCtrlOffChk() &&
!spm::mario::marioKeyOffChk() &&
spm::mario_motion::func_80146f0c() &&
spm::effdrv::func_80061d78() == 0 &&
spm::charpixlitemwin::charPixlItemWinIsClosed() &&
spm::spmario::spmarioGetSystemLevel() == 0 &&
(spm::homebuttondrv::homebuttonWp->flags & HOMEBUTTON_FLAG_OPEN) == 0 &&
(spm::homebuttondrv::homebuttonWp->flags & HOMEBUTTON_FLAG_FORBIDDEN) == 0
)
MenuWindow::sCurMenu = new MainMenu();
}
else
{
MenuWindow::sCurMenu->fullClose();
}
}
seq_gameReal.main(wp);
}
static void seq_gamePatch()
{
seq_gameReal = spm::seqdef::seq_data[spm::seqdrv::SEQ_GAME];
spm::seqdef::seq_data[spm::seqdrv::SEQ_GAME] = {
seq_gameInitOverride, seq_gameMainOverride, seq_gameReal.exit
};
}
/*
spmarioMain hook
*/
static void (*spmarioMainReal)();
void spmarioMainPatch()
{
spmarioMainReal = patch::hookFunction(spm::spmario::spmarioMain,
[]()
{
#ifdef PYCONSOLE_PROTOTYPE
PyConsole::main();
#endif
Window::windowMain();
spmarioMainReal();
}
);
}
/*
Platform detection to adjust certain settings
*/
static void checkForDolphin()
{
// Thanks to TheLordScruffy for telling me about this
gIsDolphin = wii::IPC::IOS_Open("/sys", 1) == -106;
// If they ever fix that, it'll be in a version that's definitely new enough to have /dev/dolphin
if (!gIsDolphin)
{
int ret = wii::IPC::IOS_Open("/dev/dolphin", 0);
if (ret >= 0)
{
gIsDolphin = true;
wii::IPC::IOS_Close(ret);
}
}
}
static void checkForRiivolution()
{
// Thanks to TheLordScruffy for telling me about this
gIsRiivolution = wii::string::strcmp(wii::DVD_Broadway::devDiStr, "/dev/di") != 0;
}
static void checkForPatchedDisc()
{
gIsPatchedDisc = wii::DVDFS::DVDConvertPathToEntrynum("./mod/") != -1;
}
/*
Entrypoint
*/
void main()
{
wii::OSError::OSReport(MOD_VERSION": main running\n");
checkForDolphin();
checkForRiivolution();
checkForPatchedDisc();
#if !(defined SPM_JP0 || defined SPM_JP1 || defined SPM_US0)
// Fix dolphin hanging on game shutdown
if (gIsDolphin)
writeWord(spm::spmario_snd::spsndExit, 0, BLR);
#endif
romfontExpand();
exceptionPatch();
// Handle 4:3
spm::camdrv::CamEntry * cam = spm::camdrv::camGetPtr(spm::camdrv::CAM_DEBUG_3D);
gIs4_3 = (cam->flag & CAM_FLAG_16_9) == 0;
if (gIs4_3)
cam->pos.z = 1350.0f;
ConsoleWindow::init();
HPWindow::init();
MapDoorWindow::init();
XYZWindow::init();
TitleTextWindow::init();
spmarioMainPatch();
seq_gamePatch();
evtScriptLoggerPatch();
evtVarLogPatch();
evtDebugPatch();
nandSettingsPatch();
GameSaveMenu::pitSavePatch();
MapSelectMenu::scanEntrances();
customPitPatch();
parsePatch();
#ifdef PYCONSOLE_PROTOTYPE
PyConsole::init();
APWindow::init();
#endif
InputWindow::init();
HitboxMenu::hitboxPatch();
/*
Uncomment this if you'd like to load another mod alongside practice codes
(for example, to debug it). If you'd like to link against this mod, then
make sure to compile it with EXTRAFLAGS="-fno-function-sections -fno-data-sections"
to prevent anything you need being deadstripped
*/
// tryChainload();
}
}