Work in CGameOptions

This commit is contained in:
Henrique Gemignani Passos Lima 2024-09-06 00:33:00 +03:00
parent 7445e8ccab
commit a96b24548e
No known key found for this signature in database
GPG Key ID: E224F951761145F8
2 changed files with 108 additions and 51 deletions

View File

@ -76,7 +76,7 @@ private:
bool hintSystem : 1; bool hintSystem : 1;
bool unk : 1; bool unk : 1;
rstl::vector<SObjectTag> vec; rstl::vector<SObjectTag> vec;
char pad[0xc]; rstl::reserved_vector<rstl::pair<bool, bool>, 4> unk2;
}; };
CHECK_SIZEOF(CGameOptions, 0x44) CHECK_SIZEOF(CGameOptions, 0x44)

View File

@ -1,16 +1,20 @@
#include "MetroidPrime/Player/CGameOptions.hpp" #include "MetroidPrime/Player/CGameOptions.hpp"
#include "Kyoto/Audio/CStreamAudioManager.hpp" #include "Kyoto/Audio/CStreamAudioManager.hpp"
#include "Kyoto/Graphics/CMoviePlayer.hpp"
#include "Kyoto/Graphics/CGraphics.hpp" #include "Kyoto/Graphics/CGraphics.hpp"
#include "Kyoto/Graphics/CMoviePlayer.hpp"
#include "Kyoto/Math/CMath.hpp" #include "Kyoto/Math/CMath.hpp"
#include "Kyoto/Streams/CMemoryStreamOut.hpp"
#include "Kyoto/Streams/CInputStream.hpp"
#include "dolphin/os.h" #include "dolphin/os.h"
extern "C" void fn_8029AF00(int, uchar); extern "C" void fn_8029AF00(int, uchar);
extern "C" rstl::pair<bool, bool> fn_80227694();
extern "C" void fn_802275B8(rstl::pair<bool, bool>&, CMemoryStreamOut& out);
extern "C" rstl::pair<bool, bool> fn_80227624(CInputStream& in);
bool lbl_804191E0; extern "C" bool lbl_804191E0;
int CGameOptions_CalculateBits(uint v) { int CGameOptions_CalculateBits(uint v) {
int iVar1; int iVar1;
@ -22,6 +26,10 @@ int CGameOptions_CalculateBits(uint v) {
return iVar1; return iVar1;
} }
inline void WritePackedBits(CMemoryStreamOut& out, uint val, uint m) {
out.WriteBits(val, CGameOptions_CalculateBits(m));
}
void CGameOptions::InitSoundMode() { void CGameOptions::InitSoundMode() {
if (OSGetSoundMode() == 0) { if (OSGetSoundMode() == 0) {
soundMode = CAudioSys::kSM_Mono; soundMode = CAudioSys::kSM_Mono;
@ -36,29 +44,97 @@ void CGameOptions::fn_80161C7C(bool x) { lbl_804191E0 = x; }
CGameOptions::CGameOptions() CGameOptions::CGameOptions()
: soundMode(CAudioSys::kSM_Stereo) : soundMode(CAudioSys::kSM_Stereo)
, screenBrightness(4) , screenBrightness(4)
, screenXOffset(0) , screenXOffset(0)
, screenYOffset(0) , screenYOffset(0)
, screenStretch(0) , screenStretch(0)
, sfxVol(0x69) , sfxVol(0x69)
, musicVol(0x4f) , musicVol(0x4f)
, hudAlpha(0xff) , hudAlpha(0xff)
, helmetAlpha(0xff) , helmetAlpha(0xff)
, hudLag(true) , hudLag(true)
, invertY(false) , invertY(false)
, rumble(true) , rumble(true)
, swapBeamsControls(false) , swapBeamsControls(false)
, hintSystem(true) , hintSystem(true)
, unk(false) , unk(false)
, unk2(fn_80227694())
{ {
InitSoundMode(); 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<bool, bool>* data = unk2.data();
for (; i < 4; ++i) {
fn_802275B8(*data, out);
++data;
}
}
void CGameOptions::ResetToDefaults() { void CGameOptions::ResetToDefaults() {
screenBrightness = 4; screenBrightness = 4;
@ -89,7 +165,7 @@ void CGameOptions::ResetExtraFlagsToDefaults() {
} }
void CGameOptions::ResetScreenToDefaults() { void CGameOptions::ResetScreenToDefaults() {
screenBrightness = 4; screenBrightness = 4;
screenXOffset = 0; screenXOffset = 0;
screenYOffset = 0; screenYOffset = 0;
@ -199,17 +275,11 @@ void CGameOptions::SetSurroundMode(CAudioSys::ESurroundModes mode, bool apply) {
} }
} }
int CGameOptions::GetHudAlphaRaw() const { int CGameOptions::GetHudAlphaRaw() const { return hudAlpha; }
return hudAlpha;
}
void CGameOptions::SetHudAlpha(int alpha) { void CGameOptions::SetHudAlpha(int alpha) { hudAlpha = alpha; }
hudAlpha = alpha;
}
float CGameOptions::GetHudAlpha() const { float CGameOptions::GetHudAlpha() const { return hudAlpha * 0.003921569f; }
return hudAlpha * 0.003921569f;
}
void CGameOptions::SetHelmetAlpha(int alpha) { helmetAlpha = alpha; } 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; } float CGameOptions::GetHelmetAlpha() const { return helmetAlpha * 0.003921569f; }
void CGameOptions::SetHUDLag(bool active) { void CGameOptions::SetHUDLag(bool active) { hudLag = active; }
hudLag = active;
}
void CGameOptions::SetIsHintSystemEnabled(bool active) { void CGameOptions::SetIsHintSystemEnabled(bool active) { hintSystem = active; }
hintSystem = active;
}
void CGameOptions::SetFlag3(bool active) { void CGameOptions::SetFlag3(bool active) { unk = active; }
unk = active;
}
void CGameOptions::SetInvertYAxis(bool active) { void CGameOptions::SetInvertYAxis(bool active) { invertY = active; }
invertY = active;
}
void CGameOptions::SetIsRumbleEnabled(bool active) { void CGameOptions::SetIsRumbleEnabled(bool active) { rumble = active; }
rumble = active;
}
void CGameOptions::ToggleControls(bool flag) { void CGameOptions::ToggleControls(bool flag) {
swapBeamsControls = 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) { void CGameOptions::SetControls(int controls) { ResetControllerAssets(controls); }
ResetControllerAssets(controls);
}