summaryrefslogtreecommitdiff
path: root/source/main.cpp
blob: b26c24b54a9dae5b9e2810edfb89c82384f1c54c (plain)
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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
#include "main.h"

#include <data/stages.h>
#include <display/console.h>
#include <patch.h>
#include <tools.h>
#include <tp/JFWSystem.h>
#include <tp/d_a_alink.h>
#include <tp/d_com_inf_game.h>
#include <tp/f_ap_game.h>
#include <tp/f_op_actor_mng.h>
#include <tp/f_op_scene_req.h>
#include <tp/m_do_controller_pad.h>

#include <cstdint>
#include <cstdio>
#include <cstring>

namespace mod
{
    void main()
    {
        console = new libtp::display::Console("AECX", "Boss Rush", "Fast paced fighting action, beat boss after boss",
                                              "as quickly as possible. At the end of each fight",
                                              "you'll be teleported to the next one...", "Version: 0.2b");

        // Hook to a suitable function
        // This one runs every frame
        onFrameDraw_Return = libtp::patch::hookFunction(libtp::tp::f_ap_game::fapGm_Execute, onFrameDraw);

        onGanonFinish_Return = libtp::patch::hookFunction(libtp::tp::d_a_alink::procGanonFinish, onFinish);

        HUDbuttonCombo = libtp::tp::m_do_controller_pad::Button_R | libtp::tp::m_do_controller_pad::Button_Z;
        StartbuttonCombo = libtp::tp::m_do_controller_pad::Button_R | libtp::tp::m_do_controller_pad::Button_Start;

        return;
    }

    bool onFinish(void* d_a_alink)
    {
        if (gameActive)
        {
            gameActive = false;
            libtp::display::print(10, "gg & gz!");
        }
        return onGanonFinish_Return(d_a_alink);
    }

    void onFrameDraw()
    {
        // Clear console after 900 frames
        if (drawFrameCalls < 900)
        {
            drawFrameCalls++;
        }
        else if (drawFrameCalls == 900)
        {
            drawFrameCalls++;
            // Init console for our purpose(s)
            libtp::display::clearConsole(0, 25);

            // Fully transparent
            libtp::display::setConsoleColor(0xFF, 0xFF, 0xFF, 0x0);
            libtp::display::setConsole(true, 25);
        }
        else
        {
            // Check for button combo
            // TODO: create libtp wrapper function

            u32 cInput = libtp::tp::m_do_controller_pad::cpadInfo.buttonInput;

            if (cInput != lastInput)
            {
                if ((cInput & HUDbuttonCombo) == HUDbuttonCombo)
                {
                    // Toggle HUD
                    HUD = !HUD;
                    libtp::display::setConsole(HUD, 0);
                }

                if (!gameActive && (cInput & StartbuttonCombo) == StartbuttonCombo)
                {
                    // Start gamemode, reset timers etc.
                    frameTimer = 0;
                    totalFrames = 0;
                    hours = 0;
                    minutes = 0;
                    seconds = 0;
                    currentBossFight = 0;
                    itemWheelPos = 0;

                    libtp::display::clearConsole(0, 25);

                    gameActive = true;

                    // Make sure user has everything
                    for (u8 i = 0; i < currentBossFight; i++)
                    {
                        bossFights[i].preHook();
                    }

                    // Trigger first fight
                    bossFights[currentBossFight].preHook();
                    libtp::tools::triggerSaveLoad(bossFights[currentBossFight].stage, bossFights[currentBossFight].room,
                                                  bossFights[currentBossFight].spawnpoint, bossFights[currentBossFight].state);
                }
                else if ((cInput & StartbuttonCombo) == StartbuttonCombo)
                {
                    gameActive = false;
                }
            }  // End input check

            if (gameActive)
            {
                // Check for events if not loading
                bossFightInfo* boss = &bossFights[currentBossFight];
                if (!libtp::tp::f_op_scene_req::isLoading && boss->flagVar > 0 &&
                    ((libtp::tp::d_com_inf_game::dComIfG_gameInfo.localAreaNodes[boss->flagOffset] & boss->flagVar) ==
                     boss->flagVar))
                {
                    // Desired flag has been reached, load next one
                    currentBossFight++;
                    boss = &bossFights[currentBossFight];

                    boss->preHook();
                    libtp::tools::triggerSaveLoad(boss->stage, boss->room, boss->spawnpoint, boss->state);
                }

                frameTimer++;
                totalFrames++;
                // Update every second to save some processing power
                if (frameTimer == 30)
                {
                    frameTimer = 0;
                    seconds++;

                    if (seconds == 60)
                    {
                        seconds = 0;
                        minutes++;
                        if (minutes == 60)
                        {
                            minutes = 0;
                            hours++;
                        }
                    }
                }
            }

            // Print HUD if active
            if (HUD)
            {
                sprintf(libtp::tp::jfw_system::systemConsole->consoleLine[5].line, "Boss: %d", currentBossFight + 1);
                sprintf(libtp::tp::jfw_system::systemConsole->consoleLine[6].line, "%02d:%02d:%02d", hours, minutes, seconds);

                sprintf(libtp::tp::jfw_system::systemConsole->consoleLine[24].line, "Frames: %u", totalFrames);
            }
        }

        lastInput = libtp::tp::m_do_controller_pad::cpadInfo.buttonInput;
        return onFrameDraw_Return();
    }

    // Prehooks
    void ook()
    {
        // Give basic equip (heroe's cloths, za, ordon sword, shield)
        libtp::tp::d_com_inf_game::dComIfG_gameInfo.scratchPad.wQuestLogData[0xD1] |= 2;  // ZA
        libtp::tp::d_com_inf_game::dComIfG_gameInfo.scratchPad.wQuestLogData[0xD2] |=
            (128 | 16 | 4 | 1);  // hero cloth, hylian shield, ordon shield, ordon sword

        // Give bottles 2 * fairy tear
        libtp::tp::d_com_inf_game::dComIfG_gameInfo.scratchPad.wQuestLogData[0xA7] = 115;
        libtp::tp::d_com_inf_game::dComIfG_gameInfo.scratchPad.wQuestLogData[0xA8] = 115;

        // Item wheel bottles
        libtp::tp::d_com_inf_game::dComIfG_gameInfo.scratchPad.wQuestLogData[0xB4 + itemWheelPos] = 11;
        itemWheelPos++;
        libtp::tp::d_com_inf_game::dComIfG_gameInfo.scratchPad.wQuestLogData[0xB4 + itemWheelPos] = 12;
        itemWheelPos++;

        // Give ending blow only
        libtp::tp::d_com_inf_game::dComIfG_gameInfo.scratchPad.eventBits[0x29] = 0x24;
        libtp::tp::d_com_inf_game::dComIfG_gameInfo.scratchPad.eventBits[0x2A] = 0x00;
    }
    void diababa()
    {
        // Add gale
        libtp::tp::d_com_inf_game::dComIfG_gameInfo.scratchPad.wQuestLogData[0x9C] = 0x40;
        libtp::tp::d_com_inf_game::dComIfG_gameInfo.scratchPad.wQuestLogData[0xB4 + itemWheelPos] = 0;
        itemWheelPos++;
    }
    void dangoro()
    {
        // Iron boots
        libtp::tp::d_com_inf_game::dComIfG_gameInfo.scratchPad.wQuestLogData[0x9F] = 0x45;
        libtp::tp::d_com_inf_game::dComIfG_gameInfo.scratchPad.wQuestLogData[0xB4 + itemWheelPos] = 0x3;
        itemWheelPos++;
    }
    void fyrus()
    {
        // Add Heroe's Bow + ammo
        libtp::tp::d_com_inf_game::dComIfG_gameInfo.scratchPad.wQuestLogData[0xEC] = 30;
        libtp::tp::d_com_inf_game::dComIfG_gameInfo.scratchPad.wQuestLogData[0xA0] = 0x43;
        libtp::tp::d_com_inf_game::dComIfG_gameInfo.scratchPad.wQuestLogData[0xB4 + itemWheelPos] = 0x4;
        itemWheelPos++;
    }

    void dekutoad()
    {
        // Add Waterbombbag + ammo
        libtp::tp::d_com_inf_game::dComIfG_gameInfo.scratchPad.wQuestLogData[0xED] = 15;  // Ammo bomb bag 1
        // Bomb Bag + Waterbombs in bomb bag slot 1
        libtp::tp::d_com_inf_game::dComIfG_gameInfo.scratchPad.wQuestLogData[0xAB] = 0x71;
        // Reference id for bomb bag slot 1
        libtp::tp::d_com_inf_game::dComIfG_gameInfo.scratchPad.wQuestLogData[0xB4 + itemWheelPos] = 15;
        itemWheelPos++;
    }

    void morpheel()
    {
        // Add clawshot
        libtp::tp::d_com_inf_game::dComIfG_gameInfo.scratchPad.wQuestLogData[0xA5] = 0x44;
        libtp::tp::d_com_inf_game::dComIfG_gameInfo.scratchPad.wQuestLogData[0xB4 + itemWheelPos] = 0x9;

        clawshotItemWheelIndex = itemWheelPos;
        itemWheelPos++;
    }

    void deathsword()
    {
        // Set transform flag
        libtp::tp::d_com_inf_game::dComIfG_gameInfo.scratchPad.eventBits[0xD] |= 0x4;
        // Give midna
        libtp::tp::d_com_inf_game::dComIfG_gameInfo.scratchPad.eventBits[0xC] |= 0x10;
        // Give senses
        libtp::tp::d_com_inf_game::dComIfG_gameInfo.scratchPad.eventBits[0x43] |= 0x8;

        // MDH Flag (or white midna but that's sad)
        libtp::tp::d_com_inf_game::dComIfG_gameInfo.scratchPad.eventBits[0x1E] |= 0x8;

        // midna on back
        libtp::tp::d_com_inf_game::dComIfG_gameInfo.scratchPad.wQuestLogData[0x30] |= 0x8;

        // Midna Charge
        libtp::tp::d_com_inf_game::dComIfG_gameInfo.scratchPad.eventBits[0x5] |= 0x1;

        // Set Master sword inventory flag
        libtp::tp::d_com_inf_game::dComIfG_gameInfo.scratchPad.wQuestLogData[0xD2] |= 0x2;

        // Equip Master sword (0x49 / 73)
        libtp::tp::d_com_inf_game::dComIfG_gameInfo.scratchPad.wQuestLogData[0x014] = 0x49;
    }
    void stallord()
    {
        // Give spinner
        libtp::tp::d_com_inf_game::dComIfG_gameInfo.scratchPad.wQuestLogData[0x09E] = 0x41;
        libtp::tp::d_com_inf_game::dComIfG_gameInfo.scratchPad.wQuestLogData[0xB4 + itemWheelPos] = 0x2;
        itemWheelPos++;
    }

    void darkhammer()
    {
        // Nothing I guess
    }
    void blizetta()
    {
        // Give ball and chain
        libtp::tp::d_com_inf_game::dComIfG_gameInfo.scratchPad.wQuestLogData[0x0A2] = 0x42;
        libtp::tp::d_com_inf_game::dComIfG_gameInfo.scratchPad.wQuestLogData[0xB4 + itemWheelPos] = 0x6;
        itemWheelPos++;
    }
    void darknut()
    {
        // Nothing I guess
    }
    void armogohma()
    {
        // Dominion rod
        libtp::tp::d_com_inf_game::dComIfG_gameInfo.scratchPad.wQuestLogData[0x0A4] = 0x46;
        libtp::tp::d_com_inf_game::dComIfG_gameInfo.scratchPad.wQuestLogData[0xB4 + itemWheelPos] = 0x8;
        itemWheelPos++;
    }
    void arealfos()
    {
        // Nothing I guess
    }
    void argarok()
    {
        // 2nd clawshot
        libtp::tp::d_com_inf_game::dComIfG_gameInfo.scratchPad.wQuestLogData[0xA6] = 0x47;
        libtp::tp::d_com_inf_game::dComIfG_gameInfo.scratchPad.wQuestLogData[0xB4 + itemWheelPos] = 10;
        itemWheelPos++;
    }
    void phantomZant()
    {
        // Nothing I think
    }
    void zant()
    {
        // Light sword
        libtp::tp::d_com_inf_game::dComIfG_gameInfo.scratchPad.wQuestLogData[0xD6] = 0xFF;
    }
    void ganon()
    {
        // Nothing I guess
    }
}  // namespace mod