From 7ec470766134d507543381975b16a2d620f3325c Mon Sep 17 00:00:00 2001 From: Henrique Gemignani Passos Lima Date: Tue, 11 Oct 2022 21:35:41 +0300 Subject: [PATCH] Use COutputStream::Put Former-commit-id: a02037e26608ee6be3288a5f75790fd102331e2e --- asm/MetroidPrime/CMemoryCardDriver.s | 14 +++++++------- asm/MetroidPrime/Player/CGameState.s | 6 +++--- include/Kyoto/Streams/COutputStream.hpp | 10 +++++++--- include/MetroidPrime/CMemoryCardDriver.hpp | 4 ++-- include/MetroidPrime/Player/CGameState.hpp | 3 +-- include/MetroidPrime/Player/CSystemOptions.hpp | 2 +- src/MetroidPrime/CMemoryCardDriver.cpp | 12 ++++++------ 7 files changed, 27 insertions(+), 24 deletions(-) diff --git a/asm/MetroidPrime/CMemoryCardDriver.s b/asm/MetroidPrime/CMemoryCardDriver.s index fb64d66d..7d299908 100644 --- a/asm/MetroidPrime/CMemoryCardDriver.s +++ b/asm/MetroidPrime/CMemoryCardDriver.s @@ -152,7 +152,7 @@ InitializeFromGameState__13SGameFileSlotFv: /* 8024C394 002492F4 48 0F 2F A9 */ bl __ct__16CMemoryStreamOutFPvUlQ216CMemoryStreamOut10EOwnerShipi /* 8024C398 002492F8 80 6D A0 80 */ lwz r3, gpGameState@sda21(r13) /* 8024C39C 002492FC 38 81 00 30 */ addi r4, r1, 0x30 -/* 8024C3A0 00249300 4B F8 7C E9 */ bl PutTo__10CGameStateFR16CMemoryStreamOut +/* 8024C3A0 00249300 4B F8 7C E9 */ bl PutTo__10CGameStateCFR13COutputStream /* 8024C3A4 00249304 38 61 00 30 */ addi r3, r1, 0x30 /* 8024C3A8 00249308 38 80 FF FF */ li r4, -1 /* 8024C3AC 0024930C 48 0F 2F 15 */ bl __dt__16CMemoryStreamOutFv @@ -181,8 +181,8 @@ InitializeFromGameState__13SGameFileSlotFv: /* 8024C408 00249368 38 21 00 D0 */ addi r1, r1, 0xd0 /* 8024C40C 0024936C 4E 80 00 20 */ blr -.global DoPut__13SGameFileSlotCFR16CMemoryStreamOut -DoPut__13SGameFileSlotCFR16CMemoryStreamOut: +.global PutTo__13SGameFileSlotCFR13COutputStream +PutTo__13SGameFileSlotCFR13COutputStream: /* 8024C410 00249370 94 21 FF F0 */ stwu r1, -0x10(r1) /* 8024C414 00249374 7C 08 02 A6 */ mflr r0 /* 8024C418 00249378 90 01 00 14 */ stw r0, 0x14(r1) @@ -376,8 +376,8 @@ lbl_8024C674: /* 8024C698 002495F8 38 21 00 10 */ addi r1, r1, 0x10 /* 8024C69C 002495FC 4E 80 00 20 */ blr -.global DoPut__11SSaveHeaderCFR16CMemoryStreamOut -DoPut__11SSaveHeaderCFR16CMemoryStreamOut: +.global PutTo__11SSaveHeaderCFR13COutputStream +PutTo__11SSaveHeaderCFR13COutputStream: /* 8024C6A0 00249600 94 21 FF E0 */ stwu r1, -0x20(r1) /* 8024C6A4 00249604 7C 08 02 A6 */ mflr r0 /* 8024C6A8 00249608 90 01 00 24 */ stw r0, 0x24(r1) @@ -1299,7 +1299,7 @@ InitializeFileInfo__17CMemoryCardDriverFv: /* 8024D35C 0024A2BC 7C 00 2B 78 */ or r0, r0, r5 /* 8024D360 0024A2C0 54 00 0F FE */ srwi r0, r0, 0x1f /* 8024D364 0024A2C4 98 01 00 0E */ stb r0, 0xe(r1) -/* 8024D368 0024A2C8 4B FF F3 39 */ bl DoPut__11SSaveHeaderCFR16CMemoryStreamOut +/* 8024D368 0024A2C8 4B FF F3 39 */ bl PutTo__11SSaveHeaderCFR13COutputStream /* 8024D36C 0024A2CC 38 61 00 A0 */ addi r3, r1, 0xa0 /* 8024D370 0024A2D0 48 0F 21 49 */ bl FlushShiftRegister__13COutputStreamFv /* 8024D374 0024A2D4 38 61 00 A0 */ addi r3, r1, 0xa0 @@ -1313,7 +1313,7 @@ lbl_8024D38C: /* 8024D390 0024A2F0 28 03 00 00 */ cmplwi r3, 0 /* 8024D394 0024A2F4 41 82 00 0C */ beq lbl_8024D3A0 /* 8024D398 0024A2F8 38 81 00 A0 */ addi r4, r1, 0xa0 -/* 8024D39C 0024A2FC 4B FF F0 75 */ bl DoPut__13SGameFileSlotCFR16CMemoryStreamOut +/* 8024D39C 0024A2FC 4B FF F0 75 */ bl PutTo__13SGameFileSlotCFR13COutputStream lbl_8024D3A0: /* 8024D3A0 0024A300 3B BD 00 08 */ addi r29, r29, 8 lbl_8024D3A4: diff --git a/asm/MetroidPrime/Player/CGameState.s b/asm/MetroidPrime/Player/CGameState.s index cbebff77..fe954758 100644 --- a/asm/MetroidPrime/Player/CGameState.s +++ b/asm/MetroidPrime/Player/CGameState.s @@ -336,7 +336,7 @@ WriteBackupBuf__10CGameStateFv: /* 801D3BEC 001D0B4C 48 16 B7 51 */ bl __ct__16CMemoryStreamOutFPvUlQ216CMemoryStreamOut10EOwnerShipi /* 801D3BF0 001D0B50 7F E3 FB 78 */ mr r3, r31 /* 801D3BF4 001D0B54 38 81 00 08 */ addi r4, r1, 8 -/* 801D3BF8 001D0B58 48 00 04 91 */ bl PutTo__10CGameStateFR16CMemoryStreamOut +/* 801D3BF8 001D0B58 48 00 04 91 */ bl PutTo__10CGameStateCFR13COutputStream /* 801D3BFC 001D0B5C 38 61 00 08 */ addi r3, r1, 8 /* 801D3C00 001D0B60 38 80 FF FF */ li r4, -1 /* 801D3C04 001D0B64 48 16 B6 BD */ bl __dt__16CMemoryStreamOutFv @@ -679,8 +679,8 @@ ReadSystemOptions__10CGameStateFR12CInputStream: /* 801D4080 001D0FE0 38 21 00 F0 */ addi r1, r1, 0xf0 /* 801D4084 001D0FE4 4E 80 00 20 */ blr -.global PutTo__10CGameStateFR16CMemoryStreamOut -PutTo__10CGameStateFR16CMemoryStreamOut: +.global PutTo__10CGameStateCFR13COutputStream +PutTo__10CGameStateCFR13COutputStream: /* 801D4088 001D0FE8 94 21 FF B0 */ stwu r1, -0x50(r1) /* 801D408C 001D0FEC 7C 08 02 A6 */ mflr r0 /* 801D4090 001D0FF0 90 01 00 54 */ stw r0, 0x54(r1) diff --git a/include/Kyoto/Streams/COutputStream.hpp b/include/Kyoto/Streams/COutputStream.hpp index 8351ee53..2a63137a 100644 --- a/include/Kyoto/Streams/COutputStream.hpp +++ b/include/Kyoto/Streams/COutputStream.hpp @@ -4,10 +4,9 @@ #include "types.h" class COutputStream; + template < typename T > -void coutput_stream_helper(const T& t, COutputStream& out) { - t.PutTo(out); -} +void coutput_stream_helper(const T& t, COutputStream& out); class COutputStream { void DoPut(const void* ptr, size_t len); @@ -57,6 +56,11 @@ private: uchar mScratch[96]; }; +template < typename T > +inline void coutput_stream_helper(const T& t, COutputStream& out) { + t.PutTo(out); +} + template <> inline void coutput_stream_helper(const float& t, COutputStream& out) { int tmp = *(int*)&t; diff --git a/include/MetroidPrime/CMemoryCardDriver.hpp b/include/MetroidPrime/CMemoryCardDriver.hpp index c60e1f6e..279d7539 100644 --- a/include/MetroidPrime/CMemoryCardDriver.hpp +++ b/include/MetroidPrime/CMemoryCardDriver.hpp @@ -44,7 +44,7 @@ struct SSaveHeader { explicit SSaveHeader(int); explicit SSaveHeader(CMemoryInStream& in); - void DoPut(CMemoryStreamOut& out) const; + void PutTo(COutputStream& out) const; }; struct SGameFileSlot { @@ -56,7 +56,7 @@ struct SGameFileSlot { void InitializeFromGameState(); void LoadGameState(int idx); - void DoPut(CMemoryStreamOut& w) const; + void PutTo(COutputStream& w) const; }; CHECK_SIZEOF(SGameFileSlot, 0x3d8) diff --git a/include/MetroidPrime/Player/CGameState.hpp b/include/MetroidPrime/Player/CGameState.hpp index c74a752c..8e0d5adb 100644 --- a/include/MetroidPrime/Player/CGameState.hpp +++ b/include/MetroidPrime/Player/CGameState.hpp @@ -15,14 +15,13 @@ #include "rstl/reserved_vector.hpp" #include "rstl/vector.hpp" -class CMemoryStreamOut; class CGameState { public: CGameState(); CGameState(CInputStream& in, int saveIdx); void ReadSystemOptions(CInputStream& in); - void PutTo(CMemoryStreamOut& out); + void PutTo(COutputStream& out) const; void WriteSystemOptions(COutputStream& out); rstl::rc_ptr< CPlayerState >& PlayerState(); diff --git a/include/MetroidPrime/Player/CSystemOptions.hpp b/include/MetroidPrime/Player/CSystemOptions.hpp index 77cc0379..3df3c6d8 100644 --- a/include/MetroidPrime/Player/CSystemOptions.hpp +++ b/include/MetroidPrime/Player/CSystemOptions.hpp @@ -14,7 +14,7 @@ public: CSystemOptions(); explicit CSystemOptions(CInputStream&); ~CSystemOptions(); - void PutTo(COutputStream&); + void PutTo(COutputStream&) const; void SetHasFusion(bool v); bool GetHasFusion() const { return xd0_28_fusionSuitActive; } diff --git a/src/MetroidPrime/CMemoryCardDriver.cpp b/src/MetroidPrime/CMemoryCardDriver.cpp index 96b2a5e0..9ae04ce9 100644 --- a/src/MetroidPrime/CMemoryCardDriver.cpp +++ b/src/MetroidPrime/CMemoryCardDriver.cpp @@ -672,7 +672,7 @@ void CMemoryCardDriver::InitializeFileInfo() { for (int i = 0; i < xe4_fileSlots.capacity(); ++i) { header.x4_savePresent[i] = !xe4_fileSlots[i].null(); } - header.DoPut(w); + w.Put(header); w.Put(x30_systemData.data(), x30_systemData.capacity()); @@ -680,7 +680,7 @@ void CMemoryCardDriver::InitializeFileInfo() { xe4_fileSlots.begin(); it != xe4_fileSlots.end(); ++it) { if (!it->null()) { - (*it)->DoPut(w); + w.Put(**it); } } } @@ -761,7 +761,7 @@ void CMemoryCardDriver::ExportPersistentOptions() { gpGameState->ExportPersistentOptions(opts); CMemoryStreamOut w(data, x30_systemData.capacity()); - opts.PutTo(w); + w.Put(opts); } SSaveHeader::SSaveHeader(int i) : x0_version(i) {} @@ -773,7 +773,7 @@ SSaveHeader::SSaveHeader(CMemoryInStream& in) { } } -void SSaveHeader::DoPut(CMemoryStreamOut& out) const { +void SSaveHeader::PutTo(COutputStream& out) const { out.WriteLong(x0_version); for (int i = 0; i < 3; ++i) { out.Put(x4_savePresent[i]); @@ -787,14 +787,14 @@ SGameFileSlot::SGameFileSlot(CMemoryInStream& in) : x0_saveBuffer('\x00') { x944_fileInfo = gpGameState->LoadGameFileState(x0_saveBuffer.data()); } -void SGameFileSlot::DoPut(CMemoryStreamOut& w) const { +void SGameFileSlot::PutTo(COutputStream& w) const { w.Put(x0_saveBuffer.data(), x0_saveBuffer.capacity()); } void SGameFileSlot::InitializeFromGameState() { { CMemoryStreamOut w(x0_saveBuffer.data(), x0_saveBuffer.capacity()); - gpGameState->PutTo(w); + w.Put(*gpGameState); } x944_fileInfo = CGameState::LoadGameFileState(x0_saveBuffer.data()); }