Decompile berry_powder.c

This commit is contained in:
Marcus Huderle
2019-03-24 14:45:09 -05:00
committed by huderlem
parent 456cc3a6f0
commit cf917a8733
13 changed files with 165 additions and 400 deletions
+128
View File
@@ -0,0 +1,128 @@
#include "global.h"
#include "berry_powder.h"
#include "bg.h"
#include "event_data.h"
#include "load_save.h"
#include "menu.h"
#include "string_util.h"
#include "strings.h"
#include "text.h"
#include "text_window.h"
#include "window.h"
#define MAX_BERRY_POWDER 99999
static EWRAM_DATA u8 sBerryPowderVendorWindowId = 0;
static u32 DecryptBerryPowder(u32 *powder)
{
return *powder ^ gSaveBlock2Ptr->encryptionKey;
}
void SetBerryPowder(u32 *powder, u32 amount)
{
*powder = amount ^ gSaveBlock2Ptr->encryptionKey;
}
void ApplyNewEncryptionKeyToBerryPowder(u32 encryptionKey)
{
u32 *powder = &gSaveBlock2Ptr->berryCrush.berryPowderAmount;
ApplyNewEncryptionKeyToWord(powder, encryptionKey);
}
static bool8 HasEnoughBerryPowder_(u32 cost)
{
u32 *powder = &gSaveBlock2Ptr->berryCrush.berryPowderAmount;
if (DecryptBerryPowder(powder) < cost)
return FALSE;
else
return TRUE;
}
bool8 HasEnoughBerryPowder(void)
{
u32 *powder = &gSaveBlock2Ptr->berryCrush.berryPowderAmount;
if (DecryptBerryPowder(powder) < gSpecialVar_0x8004)
return FALSE;
else
return TRUE;
}
bool8 GiveBerryPowder(u32 amountToAdd)
{
u32 *powder = &gSaveBlock2Ptr->berryCrush.berryPowderAmount;
u32 amount = DecryptBerryPowder(powder) + amountToAdd;
if (amount > MAX_BERRY_POWDER)
{
SetBerryPowder(powder, MAX_BERRY_POWDER);
return FALSE;
}
else
{
SetBerryPowder(powder, amount);
return TRUE;
}
}
static bool8 TakeBerryPowder_(u32 cost)
{
u32 *powder = &gSaveBlock2Ptr->berryCrush.berryPowderAmount;
if (!HasEnoughBerryPowder_(cost))
return FALSE;
SetBerryPowder(powder, DecryptBerryPowder(powder) - cost);
return TRUE;
}
bool8 TakeBerryPowder(void)
{
u32 *powder = &gSaveBlock2Ptr->berryCrush.berryPowderAmount;
if (!HasEnoughBerryPowder_(gSpecialVar_0x8004))
return FALSE;
SetBerryPowder(powder, DecryptBerryPowder(powder) - gSpecialVar_0x8004);
return TRUE;
}
u32 GetBerryPowder(void)
{
u32 *powder = &gSaveBlock2Ptr->berryCrush.berryPowderAmount;
return DecryptBerryPowder(powder);
}
static void PrintBerryPowderAmount(u8 windowId, int amount, u8 x, u8 y, u8 speed)
{
ConvertIntToDecimalStringN(gStringVar1, amount, STR_CONV_MODE_RIGHT_ALIGN, 5);
AddTextPrinterParameterized(windowId, 1, gStringVar1, x, y, speed, NULL);
}
static void DrawPlayerPowderAmount(u8 windowId, u16 baseTileOffset, u8 paletteNum, u32 amount)
{
DrawStdFrameWithCustomTileAndPalette(windowId, FALSE, baseTileOffset, paletteNum);
AddTextPrinterParameterized(windowId, 1, gText_Powder, 0, 1, TEXT_SPEED_FF, NULL);
PrintBerryPowderAmount(windowId, amount, 26, 17, 0);
}
void PrintPlayerBerryPowderAmount(void)
{
u32 amount = GetBerryPowder();
PrintBerryPowderAmount(sBerryPowderVendorWindowId, amount, 26, 17, 0);
}
void DisplayBerryPowderVendorMenu(void)
{
struct WindowTemplate template;
SetWindowTemplateFields(&template, 0, 1, 1, 7, 4, 15, 0x1C);
sBerryPowderVendorWindowId = AddWindow(&template);
FillWindowPixelBuffer(sBerryPowderVendorWindowId, PIXEL_FILL(0));
PutWindowTilemap(sBerryPowderVendorWindowId);
LoadUserWindowBorderGfx_(sBerryPowderVendorWindowId, 0x21D, 0xD0);
DrawPlayerPowderAmount(sBerryPowderVendorWindowId, 0x21D, 13, GetBerryPowder());
}
void RemoveBerryPowderVendorMenu(void)
{
ClearWindowTilemap(sBerryPowderVendorWindowId);
ClearStdWindowAndFrameToTransparent(sBerryPowderVendorWindowId, TRUE);
RemoveWindow(sBerryPowderVendorWindowId);
}
+2 -3
View File
@@ -4,6 +4,7 @@
#include "battle_pyramid.h"
#include "battle_pyramid_bag.h"
#include "berry.h"
#include "berry_powder.h"
#include "bike.h"
#include "coins.h"
#include "data2.h"
@@ -45,8 +46,6 @@ extern u8 Route102_EventScript_274482[];
extern u8 Route102_EventScript_2744C0[];
extern u8 BattleFrontier_OutsideEast_EventScript_242CFC[];
extern s32 sub_80247BC(void);
void SetUpItemUseCallback(u8 taskId);
void MapPostLoadHook_UseItem(void);
void sub_80AF6D4(void);
@@ -638,7 +637,7 @@ void ItemUseOutOfBattle_CoinCase(u8 taskId)
void ItemUseOutOfBattle_PowderJar(u8 taskId)
{
ConvertIntToDecimalStringN(gStringVar1, sub_80247BC(), 0, 5);
ConvertIntToDecimalStringN(gStringVar1, GetBerryPowder(), 0, 5);
StringExpandPlaceholders(gStringVar4, gText_PowderQty);
if (!gTasks[taskId].data[3])
+1 -2
View File
@@ -1,5 +1,6 @@
#include "global.h"
#include "alloc.h"
#include "berry_powder.h"
#include "item.h"
#include "load_save.h"
#include "main.h"
@@ -15,8 +16,6 @@
static void ApplyNewEncryptionKeyToAllEncryptedData(u32 encryptionKey);
extern void ApplyNewEncryptionKeyToBerryPowder(u32 key);
#define SAVEBLOCK_MOVE_RANGE 128
struct LoadedSaveData
+1 -1
View File
@@ -41,12 +41,12 @@
#include "secret_base.h"
#include "player_pc.h"
#include "field_specials.h"
#include "berry_powder.h"
extern void copy_strings_to_sav1(void);
extern void sub_801AFD8(void);
extern void ResetPokeJumpResults(void);
extern void SetBerryPowder(u32* powder, u32 newValue);
extern const u8 EventScript_ResetAllMapFlags[];