diff --git a/include/MetroidPrime/Player/CGameOptions.hpp b/include/MetroidPrime/Player/CGameOptions.hpp index 847af78..90d5326 100644 --- a/include/MetroidPrime/Player/CGameOptions.hpp +++ b/include/MetroidPrime/Player/CGameOptions.hpp @@ -76,7 +76,7 @@ private: bool hintSystem : 1; bool unk : 1; rstl::vector vec; - char pad[0xc]; + rstl::reserved_vector, 4> unk2; }; CHECK_SIZEOF(CGameOptions, 0x44) diff --git a/src/MetroidPrime/Player/CGameOptions.cpp b/src/MetroidPrime/Player/CGameOptions.cpp index 512b86e..1dba25b 100644 --- a/src/MetroidPrime/Player/CGameOptions.cpp +++ b/src/MetroidPrime/Player/CGameOptions.cpp @@ -1,16 +1,20 @@ #include "MetroidPrime/Player/CGameOptions.hpp" #include "Kyoto/Audio/CStreamAudioManager.hpp" -#include "Kyoto/Graphics/CMoviePlayer.hpp" #include "Kyoto/Graphics/CGraphics.hpp" +#include "Kyoto/Graphics/CMoviePlayer.hpp" #include "Kyoto/Math/CMath.hpp" +#include "Kyoto/Streams/CMemoryStreamOut.hpp" +#include "Kyoto/Streams/CInputStream.hpp" #include "dolphin/os.h" - extern "C" void fn_8029AF00(int, uchar); +extern "C" rstl::pair fn_80227694(); +extern "C" void fn_802275B8(rstl::pair&, CMemoryStreamOut& out); +extern "C" rstl::pair fn_80227624(CInputStream& in); -bool lbl_804191E0; +extern "C" bool lbl_804191E0; int CGameOptions_CalculateBits(uint v) { int iVar1; @@ -22,6 +26,10 @@ int CGameOptions_CalculateBits(uint v) { return iVar1; } +inline void WritePackedBits(CMemoryStreamOut& out, uint val, uint m) { + out.WriteBits(val, CGameOptions_CalculateBits(m)); +} + void CGameOptions::InitSoundMode() { if (OSGetSoundMode() == 0) { soundMode = CAudioSys::kSM_Mono; @@ -36,29 +44,97 @@ void CGameOptions::fn_80161C7C(bool x) { lbl_804191E0 = x; } CGameOptions::CGameOptions() - : soundMode(CAudioSys::kSM_Stereo) - , screenBrightness(4) - , screenXOffset(0) - , screenYOffset(0) - , screenStretch(0) - , sfxVol(0x69) - , musicVol(0x4f) - , hudAlpha(0xff) - , helmetAlpha(0xff) - , hudLag(true) - , invertY(false) - , rumble(true) - , swapBeamsControls(false) - , hintSystem(true) - , unk(false) +: soundMode(CAudioSys::kSM_Stereo) +, screenBrightness(4) +, screenXOffset(0) +, screenYOffset(0) +, screenStretch(0) +, sfxVol(0x69) +, musicVol(0x4f) +, hudAlpha(0xff) +, helmetAlpha(0xff) +, hudLag(true) +, invertY(false) +, rumble(true) +, swapBeamsControls(false) +, hintSystem(true) +, unk(false) +, unk2(fn_80227694()) { InitSoundMode(); } -CGameOptions::CGameOptions(CInputStream& in) {} +CGameOptions::CGameOptions(CInputStream& in) -void CGameOptions::PutTo(CMemoryStreamOut& out) {} +: soundMode(CAudioSys::kSM_Stereo) +, screenBrightness(4) +, screenXOffset(0) +, screenYOffset(0) +, screenStretch(0) +, sfxVol(0x69) +, musicVol(0x4f) +, hudAlpha(0xff) +, helmetAlpha(0xff) +, hudLag(true) +, invertY(false) +, rumble(true) +, swapBeamsControls(false) +, hintSystem(true) +, unk(false) +, vec() +{ + in.ReadBits(32); + soundMode = (CAudioSys::ESurroundModes) in.ReadBits(CGameOptions_CalculateBits(2)); + screenBrightness = in.ReadBits(CGameOptions_CalculateBits(8)); + screenXOffset = in.ReadBits(CGameOptions_CalculateBits(60)) - 30; + screenYOffset = in.ReadBits(CGameOptions_CalculateBits(60)) - 30; + screenYOffset = (screenYOffset < -19 ? -19 : (screenYOffset > 19 ? 19 : screenYOffset)); + screenStretch = in.ReadBits(CGameOptions_CalculateBits(20)) - 10; + sfxVol = in.ReadBits(CGameOptions_CalculateBits(0x69)); + musicVol = in.ReadBits(CGameOptions_CalculateBits(0x69)); + hudAlpha = in.ReadBits(CGameOptions_CalculateBits(0xff)); + helmetAlpha = in.ReadBits(CGameOptions_CalculateBits(0xff)); + + hudLag = in.ReadBits(1); + hintSystem = in.ReadBits(1); + invertY = in.ReadBits(1); + rumble = in.ReadBits(1); + swapBeamsControls = in.ReadBits(1); + unk = in.ReadBits(1); + + for (int i = 0; i < 4; ++i) { + unk2.push_back(fn_80227624(in)); + } + + InitSoundMode(); +} + +void CGameOptions::PutTo(CMemoryStreamOut& out) { + out.WriteBits(0x4f50544e, 32); + WritePackedBits(out, soundMode, 2); + WritePackedBits(out, screenBrightness, 8); + WritePackedBits(out, screenXOffset + 30, 60); + WritePackedBits(out, screenYOffset + 30, 60); + WritePackedBits(out, screenStretch + 10, 20); + WritePackedBits(out, sfxVol, 0x69); + WritePackedBits(out, musicVol, 0x69); + WritePackedBits(out, hudAlpha, 0xff); + WritePackedBits(out, helmetAlpha, 0xff); + out.WriteBits(hudLag != 0, 1); + out.WriteBits(hintSystem != 0, 1); + out.WriteBits(invertY != 0, 1); + out.WriteBits(rumble != 0, 1); + out.WriteBits(swapBeamsControls != 0, 1); + out.WriteBits(unk != 0, 1); + + int i = 0; + rstl::pair* data = unk2.data(); + for (; i < 4; ++i) { + fn_802275B8(*data, out); + ++data; + } +} void CGameOptions::ResetToDefaults() { screenBrightness = 4; @@ -89,7 +165,7 @@ void CGameOptions::ResetExtraFlagsToDefaults() { } void CGameOptions::ResetScreenToDefaults() { - + screenBrightness = 4; screenXOffset = 0; screenYOffset = 0; @@ -199,17 +275,11 @@ void CGameOptions::SetSurroundMode(CAudioSys::ESurroundModes mode, bool apply) { } } -int CGameOptions::GetHudAlphaRaw() const { - return hudAlpha; -} +int CGameOptions::GetHudAlphaRaw() const { return hudAlpha; } -void CGameOptions::SetHudAlpha(int alpha) { - hudAlpha = alpha; -} +void CGameOptions::SetHudAlpha(int alpha) { hudAlpha = alpha; } -float CGameOptions::GetHudAlpha() const { - return hudAlpha * 0.003921569f; -} +float CGameOptions::GetHudAlpha() const { return hudAlpha * 0.003921569f; } void CGameOptions::SetHelmetAlpha(int alpha) { helmetAlpha = alpha; } @@ -217,25 +287,15 @@ int CGameOptions::GetHelmetAlphaRaw() const { return helmetAlpha; } float CGameOptions::GetHelmetAlpha() const { return helmetAlpha * 0.003921569f; } -void CGameOptions::SetHUDLag(bool active) { - hudLag = active; -} +void CGameOptions::SetHUDLag(bool active) { hudLag = active; } -void CGameOptions::SetIsHintSystemEnabled(bool active) { - hintSystem = active; -} +void CGameOptions::SetIsHintSystemEnabled(bool active) { hintSystem = active; } -void CGameOptions::SetFlag3(bool active) { - unk = active; -} +void CGameOptions::SetFlag3(bool active) { unk = active; } -void CGameOptions::SetInvertYAxis(bool active) { - invertY = active; -} +void CGameOptions::SetInvertYAxis(bool active) { invertY = active; } -void CGameOptions::SetIsRumbleEnabled(bool active) { - rumble = active; -} +void CGameOptions::SetIsRumbleEnabled(bool active) { rumble = active; } void CGameOptions::ToggleControls(bool flag) { swapBeamsControls = flag; @@ -246,9 +306,6 @@ void CGameOptions::ToggleControls(bool flag) { } } -void CGameOptions::ResetControllerAssets(int controls) { -} +void CGameOptions::ResetControllerAssets(int controls) {} -void CGameOptions::SetControls(int controls) { - ResetControllerAssets(controls); -} +void CGameOptions::SetControls(int controls) { ResetControllerAssets(controls); }