Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] CVar rework #2552

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions soh/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ set(Header_Files__include
"include/z64player.h"
"include/z64save.h"
"include/z64scene.h"
"include/z64settings.h"
"include/z64transition.h"
)
source_group("Header Files\\include" FILES ${Header_Files__include})
Expand Down Expand Up @@ -301,6 +302,8 @@ set(Source_Files__soh
"soh/UIWidgets.hpp"
"soh/UIWidgets.cpp"
"soh/CrashHandlerExt.cpp"
"soh/GlobalSettings.h"
"soh/GlobalSettings.cpp"
)
source_group("Source Files\\soh" FILES ${Source_Files__soh})

Expand Down
1 change: 1 addition & 0 deletions soh/include/variables.h
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ extern "C"
extern u64 gJpegUCodeData[];

extern SaveContext gSaveContext;
extern GlobalSettingsStruct gGlobalSettings;
extern GameInfo* gGameInfo;
extern u16 D_8015FCC0;
extern u16 D_8015FCC2;
Expand Down
1 change: 1 addition & 0 deletions soh/include/z64.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "z64skin.h"
#include "z64transition.h"
#include "z64interface.h"
#include "z64settings.h"
#include "alignment.h"
#include "sequence.h"
#include "sfx.h"
Expand Down
3 changes: 0 additions & 3 deletions soh/include/z64save.h
Original file line number Diff line number Diff line change
Expand Up @@ -226,10 +226,7 @@ typedef struct {
/* 0x1404 */ u16 minigameState;
/* 0x1406 */ u16 minigameScore; // "yabusame_total"
/* 0x1408 */ char unk_1408[0x0001];
/* 0x1409 */ u8 language; // NTSC 0: Japanese; 1: English | PAL 0: English; 1: German; 2: French
/* 0x140A */ u8 audioSetting;
/* 0x140B */ char unk_140B[0x0001];
/* 0x140C */ u8 zTargetSetting; // 0: Switch; 1: Hold
/* 0x140E */ u16 forcedSeqId; // immediately start playing the sequence if set
/* 0x1410 */ u8 cutsceneTransitionControl; // context dependent usage: can either trigger a delayed fade or control fill alpha
/* 0x1411 */ char unk_1411[0x0001];
Expand Down
17 changes: 17 additions & 0 deletions soh/include/z64settings.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#ifndef Z64SETTINGS_H
#define Z64SETTINGS_H

#include <libultraship/libultra.h>

typedef struct {
s32 matchKeyColor;
} RandomizerSettings;

typedef struct {
s32 language; // NTSC 0: Japanese; 1: English | PAL 0: English; 1: German; 2: French
s32 zTargetSetting;
s32 audioSetting;
RandomizerSettings rando;
} GlobalSettingsStruct;

#endif
16 changes: 8 additions & 8 deletions soh/soh/Enhancements/debugger/debugSaveEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ void DrawInfoTab() {
UIWidgets::InsertHelpHoverText("Time, in seconds");

const char* audioName;
switch (gSaveContext.audioSetting) {
switch (gGlobalSettings.audioSetting) {
case 0:
audioName = "Stereo";
break;
Expand All @@ -475,16 +475,16 @@ void DrawInfoTab() {
}
if (ImGui::BeginCombo("Audio", audioName)) {
if (ImGui::Selectable("Stereo")) {
gSaveContext.audioSetting = 0;
gGlobalSettings.audioSetting = 0;
}
if (ImGui::Selectable("Mono")) {
gSaveContext.audioSetting = 1;
gGlobalSettings.audioSetting = 1;
}
if (ImGui::Selectable("Headset")) {
gSaveContext.audioSetting = 2;
gGlobalSettings.audioSetting = 2;
}
if (ImGui::Selectable("Surround")) {
gSaveContext.audioSetting = 3;
gGlobalSettings.audioSetting = 3;
}

ImGui::EndCombo();
Expand All @@ -497,12 +497,12 @@ void DrawInfoTab() {
}
UIWidgets::InsertHelpHoverText("WARNING! If you save, your file may be locked! Use caution!");

if (ImGui::BeginCombo("Z Target Mode", gSaveContext.zTargetSetting ? "Hold" : "Switch")) {
if (ImGui::BeginCombo("Z Target Mode", gGlobalSettings.zTargetSetting ? "Hold" : "Switch")) {
if (ImGui::Selectable("Switch")) {
gSaveContext.zTargetSetting = 0;
gGlobalSettings.zTargetSetting = 0;
}
if (ImGui::Selectable("Hold")) {
gSaveContext.zTargetSetting = 1;
gGlobalSettings.zTargetSetting = 1;
}
ImGui::EndCombo();
}
Expand Down
6 changes: 3 additions & 3 deletions soh/soh/Enhancements/randomizer/3drando/spoiler_log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ static void WriteLocation(
ItemLocation* location = Location(locationKey);

// auto node = parentNode->InsertNewChildElement("location");
switch (gSaveContext.language) {
switch (gGlobalSettings.language) {
case LANGUAGE_ENG:
default:
jsonData["playthrough"][sphere][location->GetName()] = location->GetPlacedItemName().GetEnglish();
Expand Down Expand Up @@ -335,7 +335,7 @@ static void WriteShuffledEntrance(std::string sphereString, Entrance* entrance)
jsonData["entrances"].push_back(reverseEntranceJson);
}

switch (gSaveContext.language) {
switch (gGlobalSettings.language) {
case LANGUAGE_ENG:
case LANGUAGE_FRA:
default:
Expand Down Expand Up @@ -538,7 +538,7 @@ static void WriteRequiredTrials() {
for (const auto& trial : Trial::trialList) {
if (trial->IsRequired()) {
std::string trialName;
switch (gSaveContext.language) {
switch (gGlobalSettings.language) {
case LANGUAGE_FRA:
trialName = trial->GetName().GetFrench();
break;
Expand Down
15 changes: 7 additions & 8 deletions soh/soh/Enhancements/randomizer/draw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "z64.h"
#include "macros.h"
#include "functions.h"
#include "variables.h"
#include "randomizerTypes.h"
#include <array>
#include "objects/object_gi_key/object_gi_key.h"
Expand All @@ -12,7 +13,6 @@

extern "C" void Randomizer_DrawSmallKey(PlayState* play, GetItemEntry* getItemEntry) {
s32 pad;
s8 isColoredKeysEnabled = CVarGetInteger("gRandoMatchKeyColors", 0);
s16 color_slot = getItemEntry->getItemId - RG_FOREST_TEMPLE_SMALL_KEY;
s16 colors[9][3] = {
{ 4, 195, 46 }, // Forest Temple
Expand All @@ -33,14 +33,14 @@ extern "C" void Randomizer_DrawSmallKey(PlayState* play, GetItemEntry* getItemEn
gSPMatrix(POLY_OPA_DISP++, Matrix_NewMtx(play->state.gfxCtx, (char*)__FILE__, __LINE__),
G_MTX_MODELVIEW | G_MTX_LOAD);

if (isColoredKeysEnabled) {
if (gGlobalSettings.rando.matchKeyColor) {
gDPSetGrayscaleColor(POLY_OPA_DISP++, colors[color_slot][0], colors[color_slot][1], colors[color_slot][2], 255);
gSPGrayscale(POLY_OPA_DISP++, true);
}

gSPDisplayList(POLY_OPA_DISP++, (Gfx*)gGiSmallKeyDL);

if (isColoredKeysEnabled) {
if (gGlobalSettings.rando.matchKeyColor) {
gSPGrayscale(POLY_OPA_DISP++, false);
}

Expand All @@ -49,7 +49,6 @@ extern "C" void Randomizer_DrawSmallKey(PlayState* play, GetItemEntry* getItemEn

extern "C" void Randomizer_DrawBossKey(PlayState* play, GetItemEntry* getItemEntry) {
s32 pad;
s8 isColoredKeysEnabled = CVarGetInteger("gRandoMatchKeyColors", 0);
s16 color_slot;
color_slot = getItemEntry->getItemId - RG_FOREST_TEMPLE_BOSS_KEY;
s16 colors[6][3] = {
Expand All @@ -68,14 +67,14 @@ extern "C" void Randomizer_DrawBossKey(PlayState* play, GetItemEntry* getItemEnt
gSPMatrix(POLY_OPA_DISP++, Matrix_NewMtx(play->state.gfxCtx, (char*)__FILE__, __LINE__),
G_MTX_MODELVIEW | G_MTX_LOAD);

if (color_slot == 5 && isColoredKeysEnabled) { // Ganon's Boss Key
if (color_slot == 5 && gGlobalSettings.rando.matchKeyColor) { // Ganon's Boss Key
gDPSetGrayscaleColor(POLY_OPA_DISP++, 80, 80, 80, 255);
gSPGrayscale(POLY_OPA_DISP++, true);
}

gSPDisplayList(POLY_OPA_DISP++, (Gfx*)gGiBossKeyDL);

if (color_slot == 5 && isColoredKeysEnabled) { // Ganon's Boss Key
if (color_slot == 5 && gGlobalSettings.rando.matchKeyColor) { // Ganon's Boss Key
gSPGrayscale(POLY_OPA_DISP++, false);
}

Expand All @@ -84,14 +83,14 @@ extern "C" void Randomizer_DrawBossKey(PlayState* play, GetItemEntry* getItemEnt
gSPMatrix(POLY_XLU_DISP++, Matrix_NewMtx(play->state.gfxCtx, (char*)__FILE__, __LINE__),
G_MTX_MODELVIEW | G_MTX_LOAD);

if (isColoredKeysEnabled) {
if (gGlobalSettings.rando.matchKeyColor) {
gDPSetGrayscaleColor(POLY_XLU_DISP++, colors[color_slot][0], colors[color_slot][1], colors[color_slot][2], 255);
gSPGrayscale(POLY_XLU_DISP++, true);
}

gSPDisplayList(POLY_XLU_DISP++, (Gfx*)gGiBossKeyGemDL);

if (isColoredKeysEnabled) {
if (gGlobalSettings.rando.matchKeyColor) {
gSPGrayscale(POLY_XLU_DISP++, false);
}

Expand Down
14 changes: 8 additions & 6 deletions soh/soh/Enhancements/randomizer/randomizer_check_tracker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -845,10 +845,11 @@ void DrawLocation(RandomizerCheckObject rcObj, RandomizerCheckShow* thisCheckSta
case RCSHOW_SCUMMED:
if (gSaveContext.n64ddFlag)
txt = OTRGlobals::Instance->gRandomizer
->EnumToSpoilerfileGetName[gSaveContext.itemLocations[rcObj.rc].get.rgID][gSaveContext.language];
else if (gSaveContext.language == LANGUAGE_ENG)
->EnumToSpoilerfileGetName[gSaveContext.itemLocations[rcObj.rc].get.rgID]
[gGlobalSettings.language];
else if (gGlobalSettings.language == LANGUAGE_ENG)
txt = ItemFromGIID(rcObj.ogItemId).GetName().english;
else if (gSaveContext.language == LANGUAGE_FRA)
else if (gGlobalSettings.language == LANGUAGE_FRA)
txt = ItemFromGIID(rcObj.ogItemId).GetName().french;
break;
case RCSHOW_SKIPPED:
Expand All @@ -857,10 +858,11 @@ void DrawLocation(RandomizerCheckObject rcObj, RandomizerCheckShow* thisCheckSta
case RCSHOW_SEEN:
if (gSaveContext.n64ddFlag)
txt = OTRGlobals::Instance->gRandomizer
->EnumToSpoilerfileGetName[gSaveContext.itemLocations[rcObj.rc].get.fakeRgID][gSaveContext.language];
else if (gSaveContext.language == LANGUAGE_ENG)
->EnumToSpoilerfileGetName[gSaveContext.itemLocations[rcObj.rc].get.fakeRgID]
[gGlobalSettings.language];
else if (gGlobalSettings.language == LANGUAGE_ENG)
txt = ItemFromGIID(rcObj.ogItemId).GetName().english;
else if (gSaveContext.language == LANGUAGE_FRA)
else if (gGlobalSettings.language == LANGUAGE_FRA)
txt = ItemFromGIID(rcObj.ogItemId).GetName().french;
break;
case RCSHOW_HINTED:
Expand Down
27 changes: 27 additions & 0 deletions soh/soh/GlobalSettings.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include "GlobalSettings.h"
#include "z64.h"
#include "variables.h"
#include "core/bridge/consolevariablebridge.h"
#include "core/Window.h"

extern "C" GlobalSettingsStruct gGlobalSettings;

namespace GlobalSettings {

void Init() {
gGlobalSettings.language = LANGUAGE_ENG;
gGlobalSettings.zTargetSetting = 0;
gGlobalSettings.audioSetting = 0;
gGlobalSettings.rando.matchKeyColor = 0;
}

void RegisterCVars() {
std::shared_ptr<Ship::ConsoleVariable> cvar = Ship::Window::GetInstance()->GetConsoleVariables();

cvar->RegisterManaged("gLanguages", gGlobalSettings.language);
cvar->RegisterManaged("gZTargetSetting", gGlobalSettings.zTargetSetting);
cvar->RegisterManaged("gAudioSetting", gGlobalSettings.audioSetting);
cvar->RegisterManaged("gRandoMatchKeyColors", gGlobalSettings.rando.matchKeyColor);
}

} // namespace GlobalSettings
11 changes: 11 additions & 0 deletions soh/soh/GlobalSettings.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#pragma once

#include "z64settings.h"

namespace GlobalSettings {

void Init();

void RegisterCVars();

}
13 changes: 10 additions & 3 deletions soh/soh/OTRGlobals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
#include <Utils/StringHelper.h>
#include <Hooks.h>
#include "Enhancements/custom-message/CustomMessageManager.h"
#include "GlobalSettings.h"

#include <Fast3D/gfx_pc.h>
#include <Fast3D/gfx_rendering_api.h>
Expand Down Expand Up @@ -230,6 +231,10 @@ OTRGlobals::OTRGlobals() {
OOT_PAL_GC_DBG1,
OOT_PAL_GC_DBG2
};

GlobalSettings::Init();
Ship::RegisterHook<Ship::CVarInit>(GlobalSettings::RegisterCVars);

context = Ship::Window::CreateInstance("Ship of Harkinian", OTRFiles);

context->GetResourceManager()->GetResourceLoader()->RegisterResourceFactory(Ship::ResourceType::SOH_Animation, std::make_shared<Ship::AnimationFactory>());
Expand Down Expand Up @@ -565,6 +570,8 @@ extern "C" void InitOTR() {
SohImGui::AddSetupHooksDelegate(GameMenuBar::SetupHooks);
SohImGui::RegisterMenuDrawMethod(GameMenuBar::Draw);

//GlobalSettings_Init();

OTRGlobals::Instance = new OTRGlobals();
SaveManager::Instance = new SaveManager();
CustomMessageManager::Instance = new CustomMessageManager();
Expand Down Expand Up @@ -1414,11 +1421,11 @@ extern "C" void* getN64WeirdFrame(s32 i) {
extern "C" int GetEquipNowMessage(char* buffer, char* src, const int maxBufferSize) {
std::string postfix;

if (gSaveContext.language == LANGUAGE_FRA) {
if (gGlobalSettings.language == LANGUAGE_FRA) {
postfix = "\x04\x1A\x08" "D\x96sirez-vous l'\x96quiper maintenant?" "\x09&&"
"\x1B%g" "Oui" "&"
"Non" "%w\x02";
} else if (gSaveContext.language == LANGUAGE_GER) {
} else if (gGlobalSettings.language == LANGUAGE_GER) {
postfix = "\x04\x1A\x08" "M""\x9A""chtest Du es jetzt ausr\x9Esten?" "\x09&&"
"\x1B%g" "Ja!" "&"
"Nein!" "%w\x02";
Expand Down Expand Up @@ -1687,7 +1694,7 @@ extern "C" int CustomMessage_RetrieveIfExists(PlayState* play) {
}
if (messageEntry.textBoxType != -1) {
font->charTexBuf[0] = (messageEntry.textBoxType << 4) | messageEntry.textBoxPos;
switch (gSaveContext.language) {
switch (gGlobalSettings.language) {
case LANGUAGE_FRA:
return msgCtx->msgLength = font->msgLength =
CopyStringToCharBuffer(messageEntry.french, buffer, maxBufferSize);
Expand Down
Loading