From cf42625664a8bed75f0ab65307a355ad07f37e32 Mon Sep 17 00:00:00 2001 From: robojumper Date: Thu, 2 May 2024 13:48:08 +0200 Subject: [PATCH 1/4] Match the single-counter TUs --- config/SOUE01/splits.txt | 43 ++++++++++ config/SOUE01/symbols.txt | 84 +++++++++---------- configure.py | 7 ++ include/toBeSorted/counters/counter.h | 43 ++++++++++ src/toBeSorted/counters/arrow_counter.cpp | 15 ++++ src/toBeSorted/counters/bomb_counter.cpp | 15 ++++ .../counters/extra_wallet_counter.cpp | 16 ++++ src/toBeSorted/counters/key_piece_counter.cpp | 15 ++++ src/toBeSorted/counters/rupee_counter.cpp | 52 ++++++++++++ .../counters/slingshot_seed_counter.cpp | 15 ++++ src/toBeSorted/counters/tear_counter.cpp | 15 ++++ 11 files changed, 278 insertions(+), 42 deletions(-) create mode 100644 include/toBeSorted/counters/counter.h create mode 100644 src/toBeSorted/counters/arrow_counter.cpp create mode 100644 src/toBeSorted/counters/bomb_counter.cpp create mode 100644 src/toBeSorted/counters/extra_wallet_counter.cpp create mode 100644 src/toBeSorted/counters/key_piece_counter.cpp create mode 100644 src/toBeSorted/counters/rupee_counter.cpp create mode 100644 src/toBeSorted/counters/slingshot_seed_counter.cpp create mode 100644 src/toBeSorted/counters/tear_counter.cpp diff --git a/config/SOUE01/splits.txt b/config/SOUE01/splits.txt index f84fec00..ebd3baeb 100644 --- a/config/SOUE01/splits.txt +++ b/config/SOUE01/splits.txt @@ -127,6 +127,49 @@ toBeSorted/skipflag_manager.cpp: .sbss start:0x80575408 end:0x8057540C .bss start:0x805A9C68 end:0x805A9C88 +toBeSorted/counters/rupee_counter.cpp: + .text start:0x8016DE10 end:0x8016DF98 + .ctors start:0x804DB7BC end:0x804DB7C0 + .rodata start:0x804E91B0 end:0x804E91D0 + .data start:0x80527FF0 end:0x80528010 + .sbss start:0x80575610 end:0x80575618 + +toBeSorted/counters/arrow_counter.cpp: + .text start:0x8016DFA0 end:0x8016E018 + .ctors start:0x804DB7C0 end:0x804DB7C4 + .data start:0x80528010 end:0x80528030 + .sbss start:0x80575618 end:0x80575620 + +toBeSorted/counters/bomb_counter.cpp: + .text start:0x8016E020 end:0x8016E098 + .ctors start:0x804DB7C4 end:0x804DB7C8 + .data start:0x80528030 end:0x80528050 + .sbss start:0x80575620 end:0x80575628 + +toBeSorted/counters/tear_counter.cpp: + .text start:0x8016E0A0 end:0x8016E118 + .ctors start:0x804DB7C8 end:0x804DB7CC + .data start:0x80528050 end:0x80528070 + .sbss start:0x80575628 end:0x80575630 + +toBeSorted/counters/slingshot_seed_counter.cpp: + .text start:0x8016E120 end:0x8016E198 + .ctors start:0x804DB7CC end:0x804DB7D0 + .data start:0x80528070 end:0x80528090 + .sbss start:0x80575630 end:0x80575638 + +toBeSorted/counters/key_piece_counter.cpp: + .text start:0x8016E1A0 end:0x8016E218 + .ctors start:0x804DB7D0 end:0x804DB7D4 + .data start:0x80528090 end:0x805280B0 + .sbss start:0x80575638 end:0x80575640 + +toBeSorted/counters/extra_wallet_counter.cpp: + .text start:0x8016E220 end:0x8016E298 + .ctors start:0x804DB7D4 end:0x804DB7D8 + .data start:0x805280B0 end:0x805280D0 + .sbss start:0x80575640 end:0x80575648 + c/c_list.cpp: .text start:0x802E08C0 end:0x802E0A10 diff --git a/config/SOUE01/symbols.txt b/config/SOUE01/symbols.txt index 195dcdc3..73de0c19 100644 --- a/config/SOUE01/symbols.txt +++ b/config/SOUE01/symbols.txt @@ -9354,10 +9354,10 @@ fn_8016CB40 = .text:0x8016CB40; // type:function size:0x1C fn_8016CB60 = .text:0x8016CB60; // type:function size:0x78 fn_8016CBE0 = .text:0x8016CBE0; // type:function size:0x3C fn_8016CC20 = .text:0x8016CC20; // type:function size:0x14 -fn_8016CC40 = .text:0x8016CC40; // type:function size:0xF0 -fn_8016CD30 = .text:0x8016CD30; // type:function size:0x20 -fn_8016CD50 = .text:0x8016CD50; // type:function size:0x20 -fn_8016CD70 = .text:0x8016CD70; // type:function size:0x24 +checkedAdd__7CounterFi = .text:0x8016CC40; // type:function size:0xF0 +getCommittedValue__7CounterFv = .text:0x8016CD30; // type:function size:0x20 +getUncommittedValue__7CounterFv = .text:0x8016CD50; // type:function size:0x20 +setValue__7CounterFUs = .text:0x8016CD70; // type:function size:0x24 fn_8016CDA0 = .text:0x8016CDA0; // type:function size:0x64 fn_8016CE10 = .text:0x8016CE10; // type:function size:0x10 fn_8016CE20 = .text:0x8016CE20; // type:function size:0x14 @@ -9432,36 +9432,36 @@ fn_8016D990 = .text:0x8016D990; // type:function size:0x8 fn_8016D9A0 = .text:0x8016D9A0; // type:function size:0x8 fn_8016D9B0 = .text:0x8016D9B0; // type:function size:0x8 fn_8016D9C0 = .text:0x8016D9C0; // type:function size:0x448 -fn_8016DE10 = .text:0x8016DE10; // type:function size:0xAC -fn_8016DEC0 = .text:0x8016DEC0; // type:function size:0x2C -fn_8016DEF0 = .text:0x8016DEF0; // type:function size:0x40 -fn_8016DF30 = .text:0x8016DF30; // type:function size:0x18 -fn_8016DF50 = .text:0x8016DF50; // type:function size:0x38 -fn_8016DF90 = .text:0x8016DF90; // type:function size:0x8 -fn_8016DFA0 = .text:0x8016DFA0; // type:function size:0x40 -fn_8016DFE0 = .text:0x8016DFE0; // type:function size:0x18 -fn_8016E000 = .text:0x8016E000; // type:function size:0x8 -fn_8016E010 = .text:0x8016E010; // type:function size:0x8 -fn_8016E020 = .text:0x8016E020; // type:function size:0x40 -fn_8016E060 = .text:0x8016E060; // type:function size:0x18 -fn_8016E080 = .text:0x8016E080; // type:function size:0x8 -fn_8016E090 = .text:0x8016E090; // type:function size:0x8 -fn_8016E0A0 = .text:0x8016E0A0; // type:function size:0x40 -fn_8016E0E0 = .text:0x8016E0E0; // type:function size:0x18 -fn_8016E100 = .text:0x8016E100; // type:function size:0x8 -fn_8016E110 = .text:0x8016E110; // type:function size:0x8 -fn_8016E120 = .text:0x8016E120; // type:function size:0x40 -fn_8016E160 = .text:0x8016E160; // type:function size:0x18 -fn_8016E180 = .text:0x8016E180; // type:function size:0x8 -fn_8016E190 = .text:0x8016E190; // type:function size:0x8 -fn_8016E1A0 = .text:0x8016E1A0; // type:function size:0x40 -fn_8016E1E0 = .text:0x8016E1E0; // type:function size:0x18 -fn_8016E200 = .text:0x8016E200; // type:function size:0x8 -fn_8016E210 = .text:0x8016E210; // type:function size:0x8 -fn_8016E220 = .text:0x8016E220; // type:function size:0x40 -fn_8016E260 = .text:0x8016E260; // type:function size:0x18 -fn_8016E280 = .text:0x8016E280; // type:function size:0x8 -fn_8016E290 = .text:0x8016E290; // type:function size:0x8 +getBaseCapacity__Fv = .text:0x8016DE10; // type:function size:0xAC +getExtraWalletCapacity__Fv = .text:0x8016DEC0; // type:function size:0x2C +__dt__12RupeeCounterFv = .text:0x8016DEF0; // type:function size:0x40 +__ct__12RupeeCounterFv = .text:0x8016DF30; // type:function size:0x18 +getMax__12RupeeCounterFv = .text:0x8016DF50; // type:function size:0x38 +__sinit_\rupee_counter_cpp = .text:0x8016DF90; // type:function size:0x8 scope:local +__dt__12ArrowCounterFv = .text:0x8016DFA0; // type:function size:0x40 +__ct__12ArrowCounterFv = .text:0x8016DFE0; // type:function size:0x18 +getMax__12ArrowCounterFv = .text:0x8016E000; // type:function size:0x8 +__sinit_\arrow_counter_cpp = .text:0x8016E010; // type:function size:0x8 scope:local +__dt__11BombCounterFv = .text:0x8016E020; // type:function size:0x40 +__ct__11BombCounterFv = .text:0x8016E060; // type:function size:0x18 +getMax__11BombCounterFv = .text:0x8016E080; // type:function size:0x8 +__sinit_\bomb_counter_cpp = .text:0x8016E090; // type:function size:0x8 scope:local +__dt__11TearCounterFv = .text:0x8016E0A0; // type:function size:0x40 +__ct__11TearCounterFv = .text:0x8016E0E0; // type:function size:0x18 +getMax__11TearCounterFv = .text:0x8016E100; // type:function size:0x8 +__sinit_\tear_counter_cpp = .text:0x8016E110; // type:function size:0x8 scope:local +__dt__20SlingshotSeedCounterFv = .text:0x8016E120; // type:function size:0x40 +__ct__20SlingshotSeedCounterFv = .text:0x8016E160; // type:function size:0x18 +getMax__20SlingshotSeedCounterFv = .text:0x8016E180; // type:function size:0x8 +__sinit_\slingshot_seed_counter_cpp = .text:0x8016E190; // type:function size:0x8 scope:local +__dt__15KeyPieceCounterFv = .text:0x8016E1A0; // type:function size:0x40 +__ct__15KeyPieceCounterFv = .text:0x8016E1E0; // type:function size:0x18 +getMax__15KeyPieceCounterFv = .text:0x8016E200; // type:function size:0x8 +__sinit_\key_piece_counter_cpp = .text:0x8016E210; // type:function size:0x8 scope:local +__dt__18ExtraWalletCounterFv = .text:0x8016E220; // type:function size:0x40 +__ct__18ExtraWalletCounterFv = .text:0x8016E260; // type:function size:0x18 +getMax__18ExtraWalletCounterFv = .text:0x8016E280; // type:function size:0x8 +__sinit_\extra_wallet_counter_cpp = .text:0x8016E290; // type:function size:0x8 scope:local fn_8016E2A0 = .text:0x8016E2A0; // type:function size:0x6C fn_8016E310 = .text:0x8016E310; // type:function size:0x194 fn_8016E4B0 = .text:0x8016E4B0; // type:function size:0x1C @@ -28352,7 +28352,7 @@ lbl_804E8D18 = .rodata:0x804E8D18; // type:object size:0x10 lbl_804E8D28 = .rodata:0x804E8D28; // type:object size:0x48 data:4byte lbl_804E8D70 = .rodata:0x804E8D70; // type:object size:0x40 data:4byte lbl_804E8DB0 = .rodata:0x804E8DB0; // type:object size:0x400 -lbl_804E91B0 = .rodata:0x804E91B0; // type:object size:0x20 data:4byte +wallet_definitions = .rodata:0x804E91B0; // type:object size:0x20 scope:local data:4byte lbl_804E91D0 = .rodata:0x804E91D0; // type:object size:0xA8 lbl_804E9278 = .rodata:0x804E9278; // type:object size:0xA0 lbl_804E9318 = .rodata:0x804E9318; // type:object size:0xA8 @@ -33327,13 +33327,13 @@ lbl_80527F70 = .data:0x80527F70; // type:object size:0x20 lbl_80527F90 = .data:0x80527F90; // type:object size:0x20 lbl_80527FB0 = .data:0x80527FB0; // type:object size:0x20 lbl_80527FD0 = .data:0x80527FD0; // type:object size:0x20 -lbl_80527FF0 = .data:0x80527FF0; // type:object size:0x20 -lbl_80528010 = .data:0x80528010; // type:object size:0x20 -lbl_80528030 = .data:0x80528030; // type:object size:0x20 -lbl_80528050 = .data:0x80528050; // type:object size:0x20 -lbl_80528070 = .data:0x80528070; // type:object size:0x20 -lbl_80528090 = .data:0x80528090; // type:object size:0x20 -lbl_805280B0 = .data:0x805280B0; // type:object size:0x20 +__vt__12RupeeCounter = .data:0x80527FF0; // type:object size:0x20 +__vt__12ArrowCounter = .data:0x80528010; // type:object size:0x20 +__vt__11BombCounter = .data:0x80528030; // type:object size:0x20 +__vt__11TearCounter = .data:0x80528050; // type:object size:0x20 +__vt__20SlingshotSeedCounter = .data:0x80528070; // type:object size:0x20 +__vt__15KeyPieceCounter = .data:0x80528090; // type:object size:0x20 +__vt__18ExtraWalletCounter = .data:0x805280B0; // type:object size:0x20 lbl_805280D0 = .data:0x805280D0; // type:object size:0xC lbl_805280DC = .data:0x805280DC; // type:object size:0xC lbl_805280E8 = .data:0x805280E8; // type:object size:0x10 diff --git a/configure.py b/configure.py index c3cea48b..67462de3 100644 --- a/configure.py +++ b/configure.py @@ -285,6 +285,13 @@ config.libs = [ Object(NonMatching, "d/a/d_a_base.cpp"), Object(NonMatching, "d/a/obj/d_a_obj_base.cpp"), Object(Matching, "toBeSorted/save_file.cpp"), + Object(Matching, "toBeSorted/counters/rupee_counter.cpp"), + Object(Matching, "toBeSorted/counters/arrow_counter.cpp"), + Object(Matching, "toBeSorted/counters/bomb_counter.cpp"), + Object(Matching, "toBeSorted/counters/tear_counter.cpp"), + Object(Matching, "toBeSorted/counters/slingshot_seed_counter.cpp"), + Object(Matching, "toBeSorted/counters/key_piece_counter.cpp"), + Object(Matching, "toBeSorted/counters/extra_wallet_counter.cpp"), Object(NonMatching, "toBeSorted/file_manager.cpp"), Object(NonMatching, "toBeSorted/save_manager.cpp"), Object(NonMatching, "f/f_base.cpp"), diff --git a/include/toBeSorted/counters/counter.h b/include/toBeSorted/counters/counter.h new file mode 100644 index 00000000..9747dd49 --- /dev/null +++ b/include/toBeSorted/counters/counter.h @@ -0,0 +1,43 @@ +#ifndef COUNTER_H +#define COUNTER_H + +#include + +class Counter { +public: + Counter(u16 id): counterId(id) {} + // No vtable, this class appears to be header-only + virtual ~Counter() {}; + /* 8016cc40 */ virtual s32 checkedAdd(s32 num) { + s32 uncommitted = getUncommittedValue(); + s32 max = getMax(); + s32 result = uncommitted + num; + if (result < 0) { + setValue(0); + } else if (result < max) { + setValue(result); + } else { + setValue(max); + } + + if (result < 0) { + return result; + } + + return result <= max ? 0 : (result - max); + } + virtual u16 getCommittedValue() { + return 0; + } + virtual u16 getMax() = 0; + virtual u16 getUncommittedValue() { + return 0; + } + virtual void setValue(u16 num) { + return; + } + + u16 counterId; +}; + +#endif COUNTER_H diff --git a/src/toBeSorted/counters/arrow_counter.cpp b/src/toBeSorted/counters/arrow_counter.cpp new file mode 100644 index 00000000..a7837350 --- /dev/null +++ b/src/toBeSorted/counters/arrow_counter.cpp @@ -0,0 +1,15 @@ +#include + +class ArrowCounter : public Counter { +public: + ArrowCounter(); + /* 8016DFA0 */ ~ArrowCounter() {} + virtual u16 getMax() override; +}; + +/* 80575618 */ ArrowCounter lbl_80575618; + +/* 8016DFE0 */ ArrowCounter::ArrowCounter() : Counter(0x1f2) {} +/* 8016E000 */ u16 ArrowCounter::getMax() { + return 20; +} diff --git a/src/toBeSorted/counters/bomb_counter.cpp b/src/toBeSorted/counters/bomb_counter.cpp new file mode 100644 index 00000000..4511ea56 --- /dev/null +++ b/src/toBeSorted/counters/bomb_counter.cpp @@ -0,0 +1,15 @@ +#include + +class BombCounter : public Counter { +public: + BombCounter(); + /* 8016E020 */ ~BombCounter() {} + virtual u16 getMax() override; +}; + +/* 80575620 */ BombCounter lbl_80575620; + +/* 8016E060 */ BombCounter::BombCounter(): Counter(0x1f3) { } +/* 8016E080 */ u16 BombCounter::getMax() { + return 10; +} diff --git a/src/toBeSorted/counters/extra_wallet_counter.cpp b/src/toBeSorted/counters/extra_wallet_counter.cpp new file mode 100644 index 00000000..0d8a2f52 --- /dev/null +++ b/src/toBeSorted/counters/extra_wallet_counter.cpp @@ -0,0 +1,16 @@ +#include + +class ExtraWalletCounter : public Counter { +public: + ExtraWalletCounter(); + /* 8016E220 */ ~ExtraWalletCounter() {} + virtual u16 getMax() override; +}; + + +/* 80575640 */ ExtraWalletCounter lbl_80575640; + +/* 8016E260 */ ExtraWalletCounter::ExtraWalletCounter(): Counter(0x1fc) { } +/* 8016E280 */ u16 ExtraWalletCounter::getMax() { + return 3; +} diff --git a/src/toBeSorted/counters/key_piece_counter.cpp b/src/toBeSorted/counters/key_piece_counter.cpp new file mode 100644 index 00000000..8a3b6914 --- /dev/null +++ b/src/toBeSorted/counters/key_piece_counter.cpp @@ -0,0 +1,15 @@ +#include + +class KeyPieceCounter : public Counter { +public: + KeyPieceCounter(); + /* 8016E1A0 */ ~KeyPieceCounter() {} + virtual u16 getMax() override; +}; + +/* 80575638 */ KeyPieceCounter lbl_80575638; + +/* 8016E1E0 */ KeyPieceCounter::KeyPieceCounter() : Counter(0x1f9) {} +/* 8016E200 */ u16 KeyPieceCounter::getMax() { + return 5; +} diff --git a/src/toBeSorted/counters/rupee_counter.cpp b/src/toBeSorted/counters/rupee_counter.cpp new file mode 100644 index 00000000..d8b4920c --- /dev/null +++ b/src/toBeSorted/counters/rupee_counter.cpp @@ -0,0 +1,52 @@ +#include + +class RupeeCounter : public Counter { +public: + RupeeCounter(); + /* 8016DEF0 */ ~RupeeCounter() {} + virtual u16 getMax() override; +}; + +struct WalletStruct { + u32 flag; + u16 capacity; +}; + +/* 804E91B0 */ +const struct WalletStruct wallet_definitions[4] = { + {0x6c, 500}, + {0x6d, 1000}, + {0x6e, 5000}, + {0x6f, 9000}, +}; + +// TODO set up item flag manager +extern "C" void *lbl_80575400; +extern "C" u16 fn_800BF5E0(void *data, u16 flag); + +/* 8016DE10 */ u16 getBaseCapacity() { + int i = 0; + WalletStruct tmp[4] = {wallet_definitions[0], wallet_definitions[1], wallet_definitions[2], wallet_definitions[3]}; + const WalletStruct *wallet = &tmp[3]; + for (; i < 4; i++, wallet--) { + if (fn_800BF5E0(lbl_80575400, wallet->flag)) { + return wallet->capacity; + } + } + return 300; +} + +// TODO main counters class +extern "C" u16 fn_8016D730(u16); + +/* 8016DEC0 */ u16 getExtraWalletCapacity() { + return 300 * fn_8016D730(0x27); +} + +/* 80575610 */ RupeeCounter lbl_80575610; + +/* 8016DF30 */ RupeeCounter::RupeeCounter() : Counter(0x1f5) {} + +/* 8016DF50 */ u16 RupeeCounter::getMax() { + return (getBaseCapacity() + getExtraWalletCapacity()); +} diff --git a/src/toBeSorted/counters/slingshot_seed_counter.cpp b/src/toBeSorted/counters/slingshot_seed_counter.cpp new file mode 100644 index 00000000..1af7fb6c --- /dev/null +++ b/src/toBeSorted/counters/slingshot_seed_counter.cpp @@ -0,0 +1,15 @@ +#include + +class SlingshotSeedCounter : public Counter { +public: + SlingshotSeedCounter(); + /* 8016E120 */ ~SlingshotSeedCounter() {} + virtual u16 getMax() override; +}; + +/* 80575630 */ SlingshotSeedCounter lbl_80575630; + +/* 8016E160 */ SlingshotSeedCounter::SlingshotSeedCounter() : Counter(0x1ed) {} +/* 8016E180 */ u16 SlingshotSeedCounter::getMax() { + return 20; +} diff --git a/src/toBeSorted/counters/tear_counter.cpp b/src/toBeSorted/counters/tear_counter.cpp new file mode 100644 index 00000000..edb48276 --- /dev/null +++ b/src/toBeSorted/counters/tear_counter.cpp @@ -0,0 +1,15 @@ +#include + +class TearCounter : public Counter { +public: + TearCounter(); + /* 8016E0A0 */ ~TearCounter() {} + virtual u16 getMax() override; +}; + +/* 80575628 */ TearCounter lbl_80575628; + +/* 8016E0E0 */ TearCounter::TearCounter(): Counter(0x1f4) { } +/* 8016E100 */ u16 TearCounter::getMax() { + return 15; +} From 5f621162a254bd495e5d697451dc43f5c520d272 Mon Sep 17 00:00:00 2001 From: robojumper Date: Fri, 3 May 2024 09:50:23 +0200 Subject: [PATCH 2/4] Main counters file --- config/SOUE01/splits.txt | 3 ++ configure.py | 1 + include/toBeSorted/counters/counter.h | 32 ++-------------- src/toBeSorted/counters/counter.cpp | 55 +++++++++++++++++++++++++++ 4 files changed, 63 insertions(+), 28 deletions(-) create mode 100644 src/toBeSorted/counters/counter.cpp diff --git a/config/SOUE01/splits.txt b/config/SOUE01/splits.txt index ebd3baeb..523e8e25 100644 --- a/config/SOUE01/splits.txt +++ b/config/SOUE01/splits.txt @@ -127,6 +127,9 @@ toBeSorted/skipflag_manager.cpp: .sbss start:0x80575408 end:0x8057540C .bss start:0x805A9C68 end:0x805A9C88 +toBeSorted/counters/counter.cpp: + .text start:0x8016CC40 end:0x8016CD94 + toBeSorted/counters/rupee_counter.cpp: .text start:0x8016DE10 end:0x8016DF98 .ctors start:0x804DB7BC end:0x804DB7C0 diff --git a/configure.py b/configure.py index 67462de3..ae51b22b 100644 --- a/configure.py +++ b/configure.py @@ -285,6 +285,7 @@ config.libs = [ Object(NonMatching, "d/a/d_a_base.cpp"), Object(NonMatching, "d/a/obj/d_a_obj_base.cpp"), Object(Matching, "toBeSorted/save_file.cpp"), + Object(Matching, "toBeSorted/counters/counter.cpp"), Object(Matching, "toBeSorted/counters/rupee_counter.cpp"), Object(Matching, "toBeSorted/counters/arrow_counter.cpp"), Object(Matching, "toBeSorted/counters/bomb_counter.cpp"), diff --git a/include/toBeSorted/counters/counter.h b/include/toBeSorted/counters/counter.h index 9747dd49..0741b0d3 100644 --- a/include/toBeSorted/counters/counter.h +++ b/include/toBeSorted/counters/counter.h @@ -6,36 +6,12 @@ class Counter { public: Counter(u16 id): counterId(id) {} - // No vtable, this class appears to be header-only virtual ~Counter() {}; - /* 8016cc40 */ virtual s32 checkedAdd(s32 num) { - s32 uncommitted = getUncommittedValue(); - s32 max = getMax(); - s32 result = uncommitted + num; - if (result < 0) { - setValue(0); - } else if (result < max) { - setValue(result); - } else { - setValue(max); - } - - if (result < 0) { - return result; - } - - return result <= max ? 0 : (result - max); - } - virtual u16 getCommittedValue() { - return 0; - } + virtual s32 checkedAdd(s32 num); + virtual u16 getCommittedValue(); virtual u16 getMax() = 0; - virtual u16 getUncommittedValue() { - return 0; - } - virtual void setValue(u16 num) { - return; - } + virtual u16 getUncommittedValue(); + virtual void setValue(u16 num); u16 counterId; }; diff --git a/src/toBeSorted/counters/counter.cpp b/src/toBeSorted/counters/counter.cpp new file mode 100644 index 00000000..2c388e44 --- /dev/null +++ b/src/toBeSorted/counters/counter.cpp @@ -0,0 +1,55 @@ +#include + +// TODO use the item flag manager once it exists +class ItemFlagManager { +public: + ItemFlagManager() {} + /** 0x08 */ virtual ~ItemFlagManager(); + /** 0x0C */ virtual void setFlagszptr(); + /** 0x10 */ virtual void onDirty(); + /** 0x14 */ virtual void copyFlagsFromSave() = 0; + /** 0x18 */ virtual void setupUnkFlagsStuff() = 0; + /** 0x1C */ virtual bool doCommit() = 0; + /** 0x20 */ virtual void setFlag(u16 flag); + /** 0x24 */ virtual void unsetFlag(u16 flag); + /** 0x28 */ virtual void setFlagOrCounterToValue(u16 flag, u16 value); + /** 0x2C */ virtual u16 getCounterOrFlag(u16 flag); + /** 0x30 */ virtual u16 getUncommittedValue(u16 flag); + /** 0x34 */ virtual void unk3(); + /** 0x38 */ virtual u16 *getSaveFlagSpace() = 0; +}; + +// TODO set up item flag manager +extern "C" ItemFlagManager *lbl_80575400; + + +/* 8016cc40 */ s32 Counter::checkedAdd(s32 num) { + s32 uncommitted = getUncommittedValue(); + s32 max = getMax(); + s32 result = uncommitted + num; + if (result < 0) { + setValue(0); + } else if (result < max) { + setValue(result); + } else { + setValue(max); + } + + if (result < 0) { + return result; + } + + return result <= max ? 0 : (result - max); +} + +/* 8016cd30 */ u16 Counter::getCommittedValue() { + return lbl_80575400->getCounterOrFlag(counterId | 0x4000); +} + +/* 8016cd50 */ u16 Counter::getUncommittedValue() { + return lbl_80575400->getUncommittedValue(counterId | 0x4000); +} + +/* 8016cd70 */ void Counter::setValue(u16 num) { + lbl_80575400->setFlagOrCounterToValue(counterId | 0x4000, num); +} From d3e39ebc28e85751eaf03c2eca887194dabe6460 Mon Sep 17 00:00:00 2001 From: robojumper Date: Fri, 3 May 2024 10:01:24 +0200 Subject: [PATCH 3/4] Cleanup --- src/toBeSorted/counters/rupee_counter.cpp | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/src/toBeSorted/counters/rupee_counter.cpp b/src/toBeSorted/counters/rupee_counter.cpp index d8b4920c..cd754fc6 100644 --- a/src/toBeSorted/counters/rupee_counter.cpp +++ b/src/toBeSorted/counters/rupee_counter.cpp @@ -12,22 +12,19 @@ struct WalletStruct { u16 capacity; }; -/* 804E91B0 */ -const struct WalletStruct wallet_definitions[4] = { - {0x6c, 500}, - {0x6d, 1000}, - {0x6e, 5000}, - {0x6f, 9000}, -}; - // TODO set up item flag manager extern "C" void *lbl_80575400; extern "C" u16 fn_800BF5E0(void *data, u16 flag); /* 8016DE10 */ u16 getBaseCapacity() { int i = 0; - WalletStruct tmp[4] = {wallet_definitions[0], wallet_definitions[1], wallet_definitions[2], wallet_definitions[3]}; - const WalletStruct *wallet = &tmp[3]; + /* 804E91B0 */ WalletStruct wallet_definitions[4] = { + {0x6c, 500}, + {0x6d, 1000}, + {0x6e, 5000}, + {0x6f, 9000}, + }; + const WalletStruct *wallet = &wallet_definitions[3]; for (; i < 4; i++, wallet--) { if (fn_800BF5E0(lbl_80575400, wallet->flag)) { return wallet->capacity; From dcb2c48b588405ab01807516bb2ee920f734a1f2 Mon Sep 17 00:00:00 2001 From: robojumper Date: Sat, 4 May 2024 19:57:10 +0200 Subject: [PATCH 4/4] Update counters for ipa file --- src/toBeSorted/counters/arrow_counter.cpp | 7 +++---- src/toBeSorted/counters/bomb_counter.cpp | 7 +++---- src/toBeSorted/counters/extra_wallet_counter.cpp | 7 +++---- src/toBeSorted/counters/key_piece_counter.cpp | 7 +++---- src/toBeSorted/counters/rupee_counter.cpp | 15 ++++++++------- .../counters/slingshot_seed_counter.cpp | 7 +++---- src/toBeSorted/counters/tear_counter.cpp | 7 +++---- 7 files changed, 26 insertions(+), 31 deletions(-) diff --git a/src/toBeSorted/counters/arrow_counter.cpp b/src/toBeSorted/counters/arrow_counter.cpp index a7837350..a770d160 100644 --- a/src/toBeSorted/counters/arrow_counter.cpp +++ b/src/toBeSorted/counters/arrow_counter.cpp @@ -4,12 +4,11 @@ class ArrowCounter : public Counter { public: ArrowCounter(); /* 8016DFA0 */ ~ArrowCounter() {} - virtual u16 getMax() override; + /* 8016E000 */ virtual u16 getMax() override { + return 20; + }; }; /* 80575618 */ ArrowCounter lbl_80575618; /* 8016DFE0 */ ArrowCounter::ArrowCounter() : Counter(0x1f2) {} -/* 8016E000 */ u16 ArrowCounter::getMax() { - return 20; -} diff --git a/src/toBeSorted/counters/bomb_counter.cpp b/src/toBeSorted/counters/bomb_counter.cpp index 4511ea56..02d11af0 100644 --- a/src/toBeSorted/counters/bomb_counter.cpp +++ b/src/toBeSorted/counters/bomb_counter.cpp @@ -4,12 +4,11 @@ class BombCounter : public Counter { public: BombCounter(); /* 8016E020 */ ~BombCounter() {} - virtual u16 getMax() override; + /* 8016E080 */ virtual u16 getMax() override { + return 10; + } }; /* 80575620 */ BombCounter lbl_80575620; /* 8016E060 */ BombCounter::BombCounter(): Counter(0x1f3) { } -/* 8016E080 */ u16 BombCounter::getMax() { - return 10; -} diff --git a/src/toBeSorted/counters/extra_wallet_counter.cpp b/src/toBeSorted/counters/extra_wallet_counter.cpp index 0d8a2f52..342f2e81 100644 --- a/src/toBeSorted/counters/extra_wallet_counter.cpp +++ b/src/toBeSorted/counters/extra_wallet_counter.cpp @@ -4,13 +4,12 @@ class ExtraWalletCounter : public Counter { public: ExtraWalletCounter(); /* 8016E220 */ ~ExtraWalletCounter() {} - virtual u16 getMax() override; + /* 8016E280 */ virtual u16 getMax() override { + return 3; + } }; /* 80575640 */ ExtraWalletCounter lbl_80575640; /* 8016E260 */ ExtraWalletCounter::ExtraWalletCounter(): Counter(0x1fc) { } -/* 8016E280 */ u16 ExtraWalletCounter::getMax() { - return 3; -} diff --git a/src/toBeSorted/counters/key_piece_counter.cpp b/src/toBeSorted/counters/key_piece_counter.cpp index 8a3b6914..55ddded7 100644 --- a/src/toBeSorted/counters/key_piece_counter.cpp +++ b/src/toBeSorted/counters/key_piece_counter.cpp @@ -4,12 +4,11 @@ class KeyPieceCounter : public Counter { public: KeyPieceCounter(); /* 8016E1A0 */ ~KeyPieceCounter() {} - virtual u16 getMax() override; + /* 8016E200 */ virtual u16 getMax() override { + return 5; + } }; /* 80575638 */ KeyPieceCounter lbl_80575638; /* 8016E1E0 */ KeyPieceCounter::KeyPieceCounter() : Counter(0x1f9) {} -/* 8016E200 */ u16 KeyPieceCounter::getMax() { - return 5; -} diff --git a/src/toBeSorted/counters/rupee_counter.cpp b/src/toBeSorted/counters/rupee_counter.cpp index cd754fc6..d1264a74 100644 --- a/src/toBeSorted/counters/rupee_counter.cpp +++ b/src/toBeSorted/counters/rupee_counter.cpp @@ -1,10 +1,15 @@ #include +static u16 getBaseCapacity(); +static u16 getExtraWalletCapacity(); + class RupeeCounter : public Counter { public: RupeeCounter(); /* 8016DEF0 */ ~RupeeCounter() {} - virtual u16 getMax() override; + /* 8016DF50 */ virtual u16 getMax() override { + return (getBaseCapacity() + getExtraWalletCapacity()); + } }; struct WalletStruct { @@ -16,7 +21,7 @@ struct WalletStruct { extern "C" void *lbl_80575400; extern "C" u16 fn_800BF5E0(void *data, u16 flag); -/* 8016DE10 */ u16 getBaseCapacity() { +/* 8016DE10 */ static u16 getBaseCapacity() { int i = 0; /* 804E91B0 */ WalletStruct wallet_definitions[4] = { {0x6c, 500}, @@ -36,14 +41,10 @@ extern "C" u16 fn_800BF5E0(void *data, u16 flag); // TODO main counters class extern "C" u16 fn_8016D730(u16); -/* 8016DEC0 */ u16 getExtraWalletCapacity() { +/* 8016DEC0 */ static u16 getExtraWalletCapacity() { return 300 * fn_8016D730(0x27); } /* 80575610 */ RupeeCounter lbl_80575610; /* 8016DF30 */ RupeeCounter::RupeeCounter() : Counter(0x1f5) {} - -/* 8016DF50 */ u16 RupeeCounter::getMax() { - return (getBaseCapacity() + getExtraWalletCapacity()); -} diff --git a/src/toBeSorted/counters/slingshot_seed_counter.cpp b/src/toBeSorted/counters/slingshot_seed_counter.cpp index 1af7fb6c..797018d6 100644 --- a/src/toBeSorted/counters/slingshot_seed_counter.cpp +++ b/src/toBeSorted/counters/slingshot_seed_counter.cpp @@ -4,12 +4,11 @@ class SlingshotSeedCounter : public Counter { public: SlingshotSeedCounter(); /* 8016E120 */ ~SlingshotSeedCounter() {} - virtual u16 getMax() override; + /* 8016E180 */ virtual u16 getMax() override { + return 20; + }; }; /* 80575630 */ SlingshotSeedCounter lbl_80575630; /* 8016E160 */ SlingshotSeedCounter::SlingshotSeedCounter() : Counter(0x1ed) {} -/* 8016E180 */ u16 SlingshotSeedCounter::getMax() { - return 20; -} diff --git a/src/toBeSorted/counters/tear_counter.cpp b/src/toBeSorted/counters/tear_counter.cpp index edb48276..2a8503cd 100644 --- a/src/toBeSorted/counters/tear_counter.cpp +++ b/src/toBeSorted/counters/tear_counter.cpp @@ -4,12 +4,11 @@ class TearCounter : public Counter { public: TearCounter(); /* 8016E0A0 */ ~TearCounter() {} - virtual u16 getMax() override; + /* 8016E100 */ virtual u16 getMax() override { + return 15; + }; }; /* 80575628 */ TearCounter lbl_80575628; /* 8016E0E0 */ TearCounter::TearCounter(): Counter(0x1f4) { } -/* 8016E100 */ u16 TearCounter::getMax() { - return 15; -}