Skip to content

Commit

Permalink
Work in CGameOptions
Browse files Browse the repository at this point in the history
  • Loading branch information
henriquegemignani committed Sep 5, 2024
1 parent 7445e8c commit a96b245
Show file tree
Hide file tree
Showing 2 changed files with 108 additions and 51 deletions.
2 changes: 1 addition & 1 deletion include/MetroidPrime/Player/CGameOptions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class CGameOptions {
bool hintSystem : 1;
bool unk : 1;
rstl::vector<SObjectTag> vec;
char pad[0xc];
rstl::reserved_vector<rstl::pair<bool, bool>, 4> unk2;
};
CHECK_SIZEOF(CGameOptions, 0x44)

Expand Down
157 changes: 107 additions & 50 deletions src/MetroidPrime/Player/CGameOptions.cpp
Original file line number Diff line number Diff line change
@@ -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<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 iVar1;
Expand All @@ -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;
Expand All @@ -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)

: 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) {}
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() {
screenBrightness = 4;
Expand Down Expand Up @@ -89,7 +165,7 @@ void CGameOptions::ResetExtraFlagsToDefaults() {
}

void CGameOptions::ResetScreenToDefaults() {

screenBrightness = 4;
screenXOffset = 0;
screenYOffset = 0;
Expand Down Expand Up @@ -199,43 +275,27 @@ 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; }

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;
Expand All @@ -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); }

0 comments on commit a96b245

Please sign in to comment.