Skip to content

Commit

Permalink
Merge branch 'develop-banker' of https://github.com/mckinlee/Shipwright
Browse files Browse the repository at this point in the history
… into develop-banker
  • Loading branch information
mckinlee committed Feb 17, 2024
2 parents d28afbc + 472c5ba commit accbcbd
Show file tree
Hide file tree
Showing 12 changed files with 319 additions and 268 deletions.
1 change: 1 addition & 0 deletions soh/include/functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -1117,6 +1117,7 @@ void func_8008EC70(Player* player);
void Player_SetEquipmentData(PlayState* play, Player* player);
void Player_UpdateBottleHeld(PlayState* play, Player* player, s32 item, s32 actionParam);
void func_80837C0C(PlayState* play, Player* this, s32 arg2, f32 arg3, f32 arg4, s16 arg5, s32 arg6);
void Player_StartTalking(PlayState* play, Actor* actor);
void func_8008EDF0(Player* player);
void func_8008EE08(Player* player);
void func_8008EEAC(PlayState* play, Actor* actor);
Expand Down
3 changes: 2 additions & 1 deletion soh/include/z64save.h
Original file line number Diff line number Diff line change
Expand Up @@ -326,9 +326,10 @@ typedef struct {
/* */ u8 triforcePiecesCollected;
/* */ s32 playerBalance;
/* */ u8 hasWarpTransfer;
/* */ u8 hasInterest;
/* */ u8 hasFee;
/* */ u8 hasPieceOfHeart;
/* */ u8 excessRupees;
/* */ u8 rupeesFee;
// #endregion
} SaveContext; // size = 0x1428

Expand Down
252 changes: 129 additions & 123 deletions soh/soh/Enhancements/banker.c

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions soh/soh/Enhancements/custom-message/CustomMessageTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ typedef enum {
TEXT_BANKER_ERROR_DEPOSIT_NOT_WORTHWHILE = 0x9404,
TEXT_BANKER_TRANSACTION_FEE = 0x9405,
TEXT_BANKER_EXCESS = 0x9406,
TEXT_BANKER_EXCESS_FULL = 0x9407,
TEXT_BANKER_EXCESS_FEE = 0x9408,
} TextIDs;

#ifdef __cplusplus
Expand Down
24 changes: 24 additions & 0 deletions soh/soh/Enhancements/debugger/debugSaveEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,30 @@ void DrawInfoTab() {
if (CVarGetInteger("gBanker", 0)) {
ImGui::InputScalar("Bank Balance", ImGuiDataType_S32, &gSaveContext.playerBalance);
UIWidgets::InsertHelpHoverText("Current bank balance");
if (gSaveContext.playerBalance > 5000) {
gSaveContext.playerBalance = 5000;
}
bool rewardsStatus[] = {
gSaveContext.hasWarpTransfer,
gSaveContext.hasFee,
gSaveContext.hasPieceOfHeart
};
const char* labels[] = {"Warp Transfer", "Transaction Fee", "Bank Heart Piece Reward"};
const char* helpTexts[] = {
"If checked, will have ability to warp transfer.",
"If checked, will not be charged a fee.",
"If checked, won't received Heart Piece reward."
};
for (int i = 0; i < sizeof(rewardsStatus)/sizeof(rewardsStatus[0]); ++i) {
if (ImGui::Checkbox(labels[i], &rewardsStatus[i])) {
switch (i) {
case 0: gSaveContext.hasWarpTransfer = rewardsStatus[i] ? 1 : 0; break;
case 1: gSaveContext.hasFee = rewardsStatus[i] ? 1 : 0; break;
case 2: gSaveContext.hasPieceOfHeart = rewardsStatus[i] ? 1 : 0; break;
}
}
UIWidgets::InsertHelpHoverText(helpTexts[i]);
}
}

const uint16_t dayTimeMin = 0;
Expand Down
28 changes: 17 additions & 11 deletions soh/soh/Enhancements/mods.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ extern PlayState* gPlayState;
extern void Overlay_DisplayText(float duration, const char* text);
uint32_t ResourceMgr_IsSceneMasterQuest(s16 sceneNum);

extern bool gBankBalanceUpdated;
extern int balanceUpdated;
extern int balanceMaxed;
extern int balanceWasMaxed;
extern bool prevTextboxCharm; //This will be removed later once TEXT_PIRATE_CHARM has been implemented
}

// GreyScaleEndDlist
Expand Down Expand Up @@ -1309,17 +1312,20 @@ void RegisterToTMedallions() {
}

void RegisterBankUpdate() {
GameInteractor::Instance->RegisterGameHook<GameInteractor::OnDialogMessage>([]() {
uint16_t messageIndex = gPlayState->msgCtx.textId;
if (gBankBalanceUpdated && CVarGetInteger("gBanker", 0) &&
(messageIndex == TEXT_BLUE_RUPEE || messageIndex == TEXT_RED_RUPEE ||
messageIndex == TEXT_PURPLE_RUPEE || messageIndex == TEXT_HUGE_RUPEE)) {
if (Message_ShouldAdvance(gPlayState)) {
Message_ContinueTextbox(gPlayState, TEXT_BANKER_EXCESS);
gBankBalanceUpdated = false;
}
auto handleBankUpdate = []() {
if (prevTextboxCharm) { //This will be removed when TEXT_PIRATE_CHARM has been implemented. TEXT_BLUE_RUPEE is being used as a placeholder in banker.c and conflicts with this logic.
return;
}
});
uint16_t messageIndex = gPlayState->msgCtx.textId;
bool isBankerActive = CVarGetInteger("gBanker", 0);
bool isRupeeMessage = (messageIndex == TEXT_BLUE_RUPEE) || (messageIndex == TEXT_RED_RUPEE) || (messageIndex == TEXT_PURPLE_RUPEE) || (messageIndex == TEXT_HUGE_RUPEE);
if (isBankerActive && isRupeeMessage && balanceUpdated && Message_ShouldAdvance(gPlayState)) {
uint16_t messageToShow = balanceWasMaxed ? TEXT_BANKER_EXCESS_FULL : TEXT_BANKER_EXCESS;
Message_ContinueTextbox(gPlayState, messageToShow);
balanceMaxed = balanceUpdated = balanceWasMaxed = 0;
}
};
GameInteractor::Instance->RegisterGameHook<GameInteractor::OnDialogMessage>(handleBankUpdate);
}

void InitMods() {
Expand Down
12 changes: 12 additions & 0 deletions soh/soh/OTRGlobals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2691,10 +2691,14 @@ extern "C" int CustomMessage_RetrieveIfExists(PlayState* play) {
messageEntry = CustomMessageManager::Instance->RetrieveMessage(customMessageTableID, TEXT_BANKER_ERROR_MAX_BALANCE);
}
if (textId == TEXT_BANKER_ERROR_DEPOSIT_NOT_WORTHWHILE && CVarGetInteger("gBanker", 0)) {
s32 rupeesFee = gSaveContext.rupeesFee;
messageEntry = CustomMessageManager::Instance->RetrieveMessage(customMessageTableID, TEXT_BANKER_ERROR_DEPOSIT_NOT_WORTHWHILE);
messageEntry.Replace("{{rupeesFee}}", std::to_string(rupeesFee));
}
if (textId == TEXT_BANKER_TRANSACTION_FEE && CVarGetInteger("gBanker", 0)) {
s32 rupeesFee = gSaveContext.rupeesFee;
messageEntry = CustomMessageManager::Instance->RetrieveMessage(customMessageTableID, TEXT_BANKER_TRANSACTION_FEE);
messageEntry.Replace("{{rupeesFee}}", std::to_string(rupeesFee));
}
if (textId == TEXT_BANKER_EXCESS && CVarGetInteger("gBanker", 0)) {
s32 playerBalance = gSaveContext.playerBalance;
Expand All @@ -2703,6 +2707,14 @@ extern "C" int CustomMessage_RetrieveIfExists(PlayState* play) {
messageEntry.Replace("{{playerBalance}}", std::to_string(playerBalance));
messageEntry.Replace("{{excessRupees}}", std::to_string(excessRupees));
}
if (textId == TEXT_BANKER_EXCESS_FULL && CVarGetInteger("gBanker", 0)) {
messageEntry = CustomMessageManager::Instance->RetrieveMessage(customMessageTableID, TEXT_BANKER_EXCESS_FULL);
}
if (textId == TEXT_BANKER_EXCESS_FEE && CVarGetInteger("gBanker", 0)) {
s32 rupeesFee = gSaveContext.rupeesFee;
messageEntry = CustomMessageManager::Instance->RetrieveMessage(customMessageTableID, TEXT_BANKER_EXCESS_FEE);
messageEntry.Replace("{{rupeesFee}}", std::to_string(rupeesFee));
}
font->charTexBuf[0] = (messageEntry.GetTextBoxType() << 4) | messageEntry.GetTextBoxPosition();
switch (gSaveContext.language) {
case LANGUAGE_FRA:
Expand Down
17 changes: 12 additions & 5 deletions soh/soh/SaveManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,7 @@ void SaveManager::InitFileNormal() {
gSaveContext.pendingIceTrapCount = 0;
gSaveContext.playerBalance = 0;
gSaveContext.excessRupees = 0;
gSaveContext.rupeesFee = 5;

// Init with normal quest unless only an MQ rom is provided
gSaveContext.questId = OTRGlobals::Instance->HasOriginal() ? QUEST_NORMAL : QUEST_MASTER;
Expand Down Expand Up @@ -739,6 +740,7 @@ void SaveManager::InitFileDebug() {
gSaveContext.sceneFlags[5].swch = 0x40000000;
gSaveContext.playerBalance = 999;
gSaveContext.excessRupees = 0;
gSaveContext.rupeesFee = 5;
}

void SaveManager::InitFileMaxed() {
Expand Down Expand Up @@ -1303,8 +1305,9 @@ void SaveManager::LoadBaseVersion1() {
});
SaveManager::Instance->LoadData("playerBalance", gSaveContext.playerBalance);
SaveManager::Instance->LoadData("hasWarpTransfer", gSaveContext.hasWarpTransfer);
SaveManager::Instance->LoadData("hasInterest", gSaveContext.hasInterest);
SaveManager::Instance->LoadData("hasFee", gSaveContext.hasFee);
SaveManager::Instance->LoadData("hasPieceOfHeart", gSaveContext.hasPieceOfHeart);
SaveManager::Instance->LoadData("rupeesFee", gSaveContext.rupeesFee);
}

void SaveManager::LoadBaseVersion2() {
Expand Down Expand Up @@ -1522,9 +1525,10 @@ void SaveManager::LoadBaseVersion2() {
}
SaveManager::Instance->LoadData("playerBalance", gSaveContext.playerBalance);
SaveManager::Instance->LoadData("hasWarpTransfer", gSaveContext.hasWarpTransfer);
SaveManager::Instance->LoadData("hasInterest", gSaveContext.hasInterest);
SaveManager::Instance->LoadData("hasFee", gSaveContext.hasFee);
SaveManager::Instance->LoadData("hasPieceOfHeart", gSaveContext.hasPieceOfHeart);
SaveManager::Instance->LoadData("excessRupees", gSaveContext.excessRupees);
SaveManager::Instance->LoadData("rupeesFee", gSaveContext.rupeesFee);
}
}

Expand Down Expand Up @@ -1749,9 +1753,10 @@ void SaveManager::LoadBaseVersion3() {
SaveManager::Instance->LoadData("dogParams", gSaveContext.dogParams);
SaveManager::Instance->LoadData("playerBalance", gSaveContext.playerBalance);
SaveManager::Instance->LoadData("hasWarpTransfer", gSaveContext.hasWarpTransfer);
SaveManager::Instance->LoadData("hasInterest", gSaveContext.hasInterest);
SaveManager::Instance->LoadData("hasFee", gSaveContext.hasFee);
SaveManager::Instance->LoadData("hasPieceOfHeart", gSaveContext.hasPieceOfHeart);
SaveManager::Instance->LoadData("excessRupees", gSaveContext.excessRupees);
SaveManager::Instance->LoadData("rupeesFee", gSaveContext.rupeesFee);
}

void SaveManager::LoadBaseVersion4() {
Expand Down Expand Up @@ -1935,9 +1940,10 @@ void SaveManager::LoadBaseVersion4() {
SaveManager::Instance->LoadData("dogParams", gSaveContext.dogParams);
SaveManager::Instance->LoadData("playerBalance", gSaveContext.playerBalance);
SaveManager::Instance->LoadData("hasWarpTransfer", gSaveContext.hasWarpTransfer);
SaveManager::Instance->LoadData("hasInterest", gSaveContext.hasInterest);
SaveManager::Instance->LoadData("hasFee", gSaveContext.hasFee);
SaveManager::Instance->LoadData("hasPieceOfHeart", gSaveContext.hasPieceOfHeart);
SaveManager::Instance->LoadData("excessRupees", gSaveContext.excessRupees);
SaveManager::Instance->LoadData("rupeesFee", gSaveContext.rupeesFee);
}

void SaveManager::SaveBase(SaveContext* saveContext, int sectionID, bool fullSave) {
Expand Down Expand Up @@ -2109,9 +2115,10 @@ void SaveManager::SaveBase(SaveContext* saveContext, int sectionID, bool fullSav
SaveManager::Instance->SaveData("dogParams", saveContext->dogParams);
SaveManager::Instance->SaveData("playerBalance", saveContext->playerBalance);
SaveManager::Instance->SaveData("hasWarpTransfer", saveContext->hasWarpTransfer);
SaveManager::Instance->SaveData("hasInterest", saveContext->hasInterest);
SaveManager::Instance->SaveData("hasFee", saveContext->hasFee);
SaveManager::Instance->SaveData("hasPieceOfHeart", saveContext->hasPieceOfHeart);
SaveManager::Instance->SaveData("excessRupees", saveContext->excessRupees);
SaveManager::Instance->SaveData("rupeesFee", saveContext->rupeesFee);
}

// Load a string into a char array based on size and ensuring it is null terminated when overflowed
Expand Down
Loading

0 comments on commit accbcbd

Please sign in to comment.