Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions include/common.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#pragma once

#include <types.h>

typedef void (*GZAction)(u32 params);
typedef bool (*GZCheckCallback)(int itemIndex);

// from oot-gc
extern "C" char* strcat(char* dst, const char* src);
2 changes: 2 additions & 0 deletions include/gz.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ class GZ {

bool IsOnLand() { return gOverlayManager.mLoadedOverlays[OverlaySlot_6] == OverlayIndex_Land; }

bool IsSceneInit() { return gOverlayManager.mLoadedOverlays[OverlaySlot_1] == OverlayIndex_SceneInit; }

// global init
void Init();

Expand Down
6 changes: 4 additions & 2 deletions include/gz_commands.hpp
Original file line number Diff line number Diff line change
@@ -1,25 +1,27 @@
#pragma once

#include "common.hpp"
#include "gz_controls.hpp"
#include "gz_menu.hpp"

#include <nitro/math.h>

typedef void (*GZCmdInit)(void);
typedef void (*GZCmdAction)(void);

struct GZCmdItem {
ButtonCombo btnCombo;
GZCmdAction actionCallback;
GZAction actionCallback;
};

class GZCommandManager {
public:
Input* mpButtons;
GZCmdItem* mpCommands;
GZMenu mMenu;

GZCommandManager();

void InitMenu();
void Update();
void Draw(Vec2b* pPos);
};
Expand Down
50 changes: 36 additions & 14 deletions include/gz_menu.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once

#include "common.hpp"
#include "gz_controls.hpp"

#include <Item/ItemManager.hpp>
Expand All @@ -8,10 +9,12 @@
#include <nitro/math.h>
#include <types.h>

typedef void (*GZMenuAction)(u32 params);
#define DRAW_TO_TOP_SCREEN 1

struct GZMenu;

typedef enum InventoryAmountType {
typedef u32 InventoryAmountType;
enum InventoryAmountType_ {
InventoryAmountType_Bow,
InventoryAmountType_Bombs,
InventoryAmountType_QuiverCapacity,
Expand All @@ -21,21 +24,36 @@ typedef enum InventoryAmountType {
InventoryAmountType_SmallKeys,
InventoryAmountType_LightTears,
InventoryAmountType_Max
} InventoryAmountType;
};

typedef u32 GZMenuItemType;
enum GZMenuItemType_ {
GZMenuItemType_Default,
GZMenuItemType_Bool,
GZMenuItemType_Increment,
};

struct GZMenuItem {
const char* mName; // menu item name
GZMenuAction mActionCallback; // associated action
u32 params; // parameters for the action callback
GZMenu* mSubMenu; // tied submenu
bool needSaveFile; // does it require the save data
s32 value; // misc value for internal use
const char* name;
GZMenuItemType eType;
GZCheckCallback checkCallback; // must be set when using `GZMenuItemType_Bool`
GZAction action;
u32 params;
GZMenu* submenu;

// internal
int value;
};

struct GZMenu {
GZMenuItem* mpItems;
const char* title;
GZMenu* parent;
GZMenuItem* entries;
s32 mCount;
GZMenu* mPrev;
bool needSaveFile;

// internal
s16 itemIndex;
};

struct GZMenuState {
Expand Down Expand Up @@ -90,16 +108,20 @@ class GZMenuManager {
this->mState.isOpened = false;
}

GZMenuItem* GetActiveMenuItem() { return &this->mpActiveMenu->mpItems[this->mState.itemIndex]; }
GZMenuItem* GetActiveMenuItem() {
return this->mState.itemIndex == 0 ? NULL : &this->mpActiveMenu->entries[this->mState.itemIndex - 1];
}

bool IsMainMenuActive();
bool IsInventoryMenuActive();
bool IsAmountsMenuActive();
bool IsCommandsMenuActive();
bool IsSettingsMenuActive();
bool IsAboutMenuActive();

void SetAmountString(s16 index, Vec2b* pPos, bool selected);
void ValidateNewIncrement();
GZMenu* GetMainMenu();
void SetAmountString(InventoryAmountType eType, Vec2b* pPos, bool selected);
void ValidateAmountIncrement();
void AssignPrevMenu();
void Update(); // update routine
void SetupScreen(); // creates the strings etc
Expand Down
17 changes: 9 additions & 8 deletions include/gz_settings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,27 @@ extern "C" void func_02030d58(u16 lockID); // CARD_UnlockBackup
#define MAX_POS_SLOTS 8
#define MAX_SAVE_PROFILES 8

//! TODO: make it one setting set per save file

extern "C" {
// IMPORTANT: do not reorder, retype or resize members!!! otherwise it will break older versions

typedef struct GZProfileHeader {
u8 curProfileIndex;
} GZProfileHeader __attribute__((aligned(32)));
} GZProfileHeader;

// the save file is large so we don't care about packing stuff to save space
typedef struct GZProfile {
u8 profileIndex;
bool mFasterTitleScreen; // goes into the "touch or start to exit" state immediately
bool mSkipTitleScreen; // same as above except it jump straight into the file select without requiring any input
s8 mPositionIndex;
s16 mPositionIndex;
Vec3p mLandPosSlots[MAX_POS_SLOTS];
Vec3p mTrainPosSlots[MAX_POS_SLOTS];
} GZProfile;

#define GZ_SAVE_OFFSET 0xF5000
#define GZ_PROFILE_HEADER_OFFSET (GZ_SAVE_OFFSET)
#define GZ_PROFILES_OFFSET (GZ_SAVE_OFFSET + sizeof(GZProfileHeader))
// profiles first because they might take a lot of space
#define GZ_PROFILES_OFFSET 0xF5000

// profile header at the end because the space it will take shouldn't be that large
#define GZ_PROFILE_HEADER_OFFSET 0xFFF00
}

class GZSettings {
Expand Down
22 changes: 22 additions & 0 deletions src/common.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include "common.hpp"

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wparentheses"

// from oot-gc
extern "C" char* strcat(char* dst, const char* src) {
const u8* p = (u8*)src - 1;
u8* q = (u8*)dst - 1;

while (*++q)
;

q--;

while (*++q = *++p)
;

return (dst);
}

#pragma GCC diagnostic pop
63 changes: 41 additions & 22 deletions src/gz_commands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@
extern "C" void DisplayDebugText(int, void*, int, int, const char*);
extern "C" void DisplayDebugTextF(int, void*, int, int, const char*, ...);

static void ExecuteLevitate();
static void ExecutePause();
static void ExecuteFrameAdvance();
static void ExecutePrevPosition();
static void ExecuteNextPosition();
static void ExecuteSavePosition();
static void ExecuteLoadPosition();
static void ExecuteVoidOut();
static void ExecuteTurbo();

// commands with default button combos
static void ExecuteLevitate(u32 params);
static void ExecutePause(u32 params);
static void ExecuteFrameAdvance(u32 params);
static void ExecutePrevPosition(u32 params);
static void ExecuteNextPosition(u32 params);
static void ExecuteSavePosition(u32 params);
static void ExecuteLoadPosition(u32 params);
static void ExecuteVoidOut(u32 params);
static void ExecuteTurbo(u32 params);

// commands with default button combos, assigning the held btn to none means it's not required (and vice versa)
static GZCmdItem sCommands[] = {
{ButtonCombo("Levitate", BTN_X, BTN_NONE), ExecuteLevitate},
{ButtonCombo("Pause/Unpause", BTN_NONE, BTN_DDOWN), ExecutePause},
Expand All @@ -35,19 +35,19 @@ static GZCmdItem sCommands[] = {
{ButtonCombo("Turbo", BTN_R, BTN_B), ExecuteTurbo},
};

static void ExecuteLevitate() { data_027e0478.mPlayer.mVel.y = FLOAT_TO_Q20(0.334375f); }
static void ExecuteLevitate(u32 params) { data_027e0478.mPlayer.mVel.y = FLOAT_TO_Q20(0.334375f); }

static void ExecutePause() {
static void ExecutePause(u32 params) {
if (!gGZ.mState.isPaused) {
gGZ.mState.isPaused = true;
} else {
gGZ.mState.isPaused = false;
}
}

static void ExecuteFrameAdvance() { gGZ.mState.requestedFrames++; }
static void ExecuteFrameAdvance(u32 params) { gGZ.mState.requestedFrames++; }

static void ExecutePrevPosition() {
static void ExecutePrevPosition(u32 params) {
GZProfile* pProfile = gSettings.GetProfile();

pProfile->mPositionIndex--;
Expand All @@ -57,7 +57,7 @@ static void ExecutePrevPosition() {
}
}

static void ExecuteNextPosition() {
static void ExecuteNextPosition(u32 params) {
GZProfile* pProfile = gSettings.GetProfile();

pProfile->mPositionIndex++;
Expand All @@ -67,31 +67,50 @@ static void ExecuteNextPosition() {
}
}

static void ExecuteSavePosition() {
static void ExecuteSavePosition(u32 params) {
GZProfile* pProfile = gSettings.GetProfile();
Vec3p* pPosArray = gSettings.GetPosArray();
pPosArray[pProfile->mPositionIndex] = data_027e0478.mPlayer.mPos;
}

static void ExecuteLoadPosition() {
static void ExecuteLoadPosition(u32 params) {
GZProfile* pProfile = gSettings.GetProfile();
Vec3p* pPosArray = gSettings.GetPosArray();
data_027e0478.mPlayer.mPos = pPosArray[pProfile->mPositionIndex];
}

static void ExecuteVoidOut() {
static void ExecuteVoidOut(u32 params) {
if (gGZ.IsOnLand()) {
data_027e0478.mPlayer.mPos.y = FLOAT_TO_Q20(-4000.0f);
}
}

static void ExecuteTurbo() {}
static void ExecuteTurbo(u32 params) {}

GZCommandManager gCommandManager;

GZCommandManager::GZCommandManager() {
this->mpButtons = &gGZ.mButtons;
this->mpCommands = sCommands;
this->InitMenu();
}

void GZCommandManager::InitMenu() {
this->mMenu.title = "Commands";
this->mMenu.parent = gMenuManager.GetMainMenu();
this->mMenu.mCount = ARRAY_LEN(sCommands);
this->mMenu.entries = new GZMenuItem[this->mMenu.mCount];
this->mMenu.needSaveFile = false;
this->mMenu.itemIndex = 0;

for (int i = 0; i < this->mMenu.mCount; i++) {
this->mMenu.entries[i].name = sCommands[i].btnCombo.name;
this->mMenu.entries[i].eType = GZMenuItemType_Default;
this->mMenu.entries[i].action = sCommands[i].actionCallback;
this->mMenu.entries[i].params = 0;
this->mMenu.entries[i].submenu = NULL;
this->mMenu.entries[i].value = 0;
}
}

void GZCommandManager::Update() {
Expand All @@ -104,7 +123,7 @@ void GZCommandManager::Update() {

if (pCmd->btnCombo.Executed(this->mpButtons)) {
if (pCmd->actionCallback != NULL) {
pCmd->actionCallback();
pCmd->actionCallback(0);
}
}
}
Expand All @@ -118,7 +137,7 @@ void GZCommandManager::Draw(Vec2b* pPos) {
bool selected = i + 1 == gMenuManager.mState.itemIndex;

pCmd->btnCombo.SetComboString();
DisplayDebugText(0, &elemPos, 0, selected, pCmd->btnCombo.fullName);
DisplayDebugText(DRAW_TO_TOP_SCREEN, &elemPos, 0, selected, pCmd->btnCombo.fullName);
elemPos.y++;
}
}
17 changes: 1 addition & 16 deletions src/gz_controls.cpp
Original file line number Diff line number Diff line change
@@ -1,24 +1,9 @@
#include "gz_controls.hpp"
#include "common.hpp"

#include <mem.h>
#include <string.h>

// from oot-gc
char* strcat(char* dst, const char* src) {
const u8* p = (u8*)src - 1;
u8* q = (u8*)dst - 1;

while (*++q)
;

q--;

while (*++q = *++p)
;

return (dst);
}

ButtonCombo::ButtonCombo() {
this->name = NULL;
this->Assign(BTN_NONE, BTN_NONE);
Expand Down
9 changes: 1 addition & 8 deletions src/gz_game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,7 @@ void CustomGame::Run() {

do {
gGZ.Update();

{
gMenuManager.Update();

if (gMenuManager.IsActive()) {
gMenuManager.Draw();
}
}
gMenuManager.Update();

// stgz: pause and frame advance block
{
Expand Down
Loading