mirror of
https://github.com/HarbourMasters/Shipwright.git
synced 2024-11-22 09:22:18 -05:00
LUS Cleanup: Removes GameSettings class. Moves code to Imgui. (#1036)
* LUS Cleanup: Removes GameSettings class. Moves code to Imgui. * Fixes more strdup problems and finalized removal of GameSetting. * Reverts changes to Directory.h * Update Directory.h * Fixes PR. * Update Directory.h * Update rando_main.cpp
This commit is contained in:
parent
c23457d666
commit
93d0d7443a
@ -1,8 +1,9 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <iostream>
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include "StringHelper.h"
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
#if __has_include(<filesystem>)
|
#if __has_include(<filesystem>)
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
@ -12,8 +13,6 @@ namespace fs = std::filesystem;
|
|||||||
namespace fs = std::experimental::filesystem;
|
namespace fs = std::experimental::filesystem;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "StringHelper.h"
|
|
||||||
|
|
||||||
#undef GetCurrentDirectory
|
#undef GetCurrentDirectory
|
||||||
#undef CreateDirectory
|
#undef CreateDirectory
|
||||||
|
|
||||||
@ -21,7 +20,7 @@ class Directory
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
#ifndef PATH_HACK
|
#ifndef PATH_HACK
|
||||||
static std::string GetCurrentDirectory() { return fs::current_path().u8string().c_str(); }
|
static std::string GetCurrentDirectory() { return fs::current_path().string(); }
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static bool Exists(const fs::path& path) { return fs::exists(path); }
|
static bool Exists(const fs::path& path) { return fs::exists(path); }
|
||||||
|
@ -4,6 +4,8 @@
|
|||||||
#include <functional>
|
#include <functional>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
#include <Utils/File.h>
|
||||||
|
#include "GlobalCtx2.h"
|
||||||
|
|
||||||
std::map<std::string, std::unique_ptr<CVar>, std::less<>> cvars;
|
std::map<std::string, std::unique_ptr<CVar>, std::less<>> cvars;
|
||||||
|
|
||||||
@ -135,3 +137,126 @@ extern "C" void CVar_RegisterString(const char* name, const char* defaultValue)
|
|||||||
if (!CVar_Get(name))
|
if (!CVar_Get(name))
|
||||||
CVar_SetString(name, defaultValue);
|
CVar_SetString(name, defaultValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename Numeric> bool is_number(const std::string& s) {
|
||||||
|
Numeric n;
|
||||||
|
return ((std::istringstream(s) >> n >> std::ws).eof());
|
||||||
|
}
|
||||||
|
|
||||||
|
void CVar_LoadLegacy() {
|
||||||
|
auto cvarsConfig = Ship::GlobalCtx2::GetPathRelativeToAppDirectory("cvars.cfg");
|
||||||
|
if (File::Exists(cvarsConfig)) {
|
||||||
|
const auto lines = File::ReadAllLines(cvarsConfig);
|
||||||
|
|
||||||
|
for (const std::string& line : lines) {
|
||||||
|
std::vector<std::string> cfg = StringHelper::Split(line, " = ");
|
||||||
|
if (line.empty()) continue;
|
||||||
|
if (cfg.size() < 2) continue;
|
||||||
|
|
||||||
|
if (cfg[1].find("\"") == std::string::npos && (cfg[1].find("#") != std::string::npos))
|
||||||
|
{
|
||||||
|
std::string value(cfg[1]);
|
||||||
|
value.erase(std::remove_if(value.begin(), value.end(), [](char c) { return c == '#'; }), value.end());
|
||||||
|
auto splitTest = StringHelper::Split(value, "\r")[0];
|
||||||
|
|
||||||
|
uint32_t val = std::stoul(splitTest, nullptr, 16);
|
||||||
|
Color_RGBA8 clr;
|
||||||
|
clr.r = val >> 24;
|
||||||
|
clr.g = val >> 16;
|
||||||
|
clr.b = val >> 8;
|
||||||
|
clr.a = val & 0xFF;
|
||||||
|
CVar_SetRGBA(cfg[0].c_str(), clr);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cfg[1].find("\"") != std::string::npos) {
|
||||||
|
std::string value(cfg[1]);
|
||||||
|
value.erase(std::remove(value.begin(), value.end(), '\"'), value.end());
|
||||||
|
#ifdef _MSC_VER
|
||||||
|
CVar_SetString(cfg[0].c_str(), _strdup(value.c_str()));
|
||||||
|
#else
|
||||||
|
CVar_SetString(cfg[0].c_str(), strdup(value.c_str()));
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
if (is_number<float>(cfg[1])) {
|
||||||
|
CVar_SetFloat(cfg[0].c_str(), std::stof(cfg[1]));
|
||||||
|
}
|
||||||
|
if (is_number<int>(cfg[1])) {
|
||||||
|
CVar_SetS32(cfg[0].c_str(), std::stoi(cfg[1]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fs::remove(cvarsConfig);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
extern "C" void CVar_Load() {
|
||||||
|
std::shared_ptr<Mercury> pConf = Ship::GlobalCtx2::GetInstance()->GetConfig();
|
||||||
|
pConf->reload();
|
||||||
|
|
||||||
|
for (const auto& item : pConf->rjson["CVars"].items()) {
|
||||||
|
auto value = item.value();
|
||||||
|
switch (value.type()) {
|
||||||
|
case nlohmann::detail::value_t::array:
|
||||||
|
break;
|
||||||
|
case nlohmann::detail::value_t::object:
|
||||||
|
if (value["Type"].get<std::string>() == mercuryRGBAObjectType) {
|
||||||
|
Color_RGBA8 clr;
|
||||||
|
clr.r = value["R"].get<uint8_t>();
|
||||||
|
clr.g = value["G"].get<uint8_t>();
|
||||||
|
clr.b = value["B"].get<uint8_t>();
|
||||||
|
clr.a = value["A"].get<uint8_t>();
|
||||||
|
CVar_SetRGBA(item.key().c_str(), clr);
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
case nlohmann::detail::value_t::string:
|
||||||
|
CVar_SetString(item.key().c_str(), value.get<std::string>().c_str());
|
||||||
|
break;
|
||||||
|
case nlohmann::detail::value_t::boolean:
|
||||||
|
CVar_SetS32(item.key().c_str(), value.get<bool>());
|
||||||
|
break;
|
||||||
|
case nlohmann::detail::value_t::number_unsigned:
|
||||||
|
case nlohmann::detail::value_t::number_integer:
|
||||||
|
CVar_SetS32(item.key().c_str(), value.get<int>());
|
||||||
|
break;
|
||||||
|
case nlohmann::detail::value_t::number_float:
|
||||||
|
CVar_SetFloat(item.key().c_str(), value.get<float>());
|
||||||
|
break;
|
||||||
|
default:;
|
||||||
|
}
|
||||||
|
if (item.key() == "gOpenMenuBar") {
|
||||||
|
int bp = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
CVar_LoadLegacy();
|
||||||
|
}
|
||||||
|
|
||||||
|
extern "C" void CVar_Save()
|
||||||
|
{
|
||||||
|
std::shared_ptr<Mercury> pConf = Ship::GlobalCtx2::GetInstance()->GetConfig();
|
||||||
|
|
||||||
|
for (const auto& cvar : cvars) {
|
||||||
|
const std::string key = StringHelper::Sprintf("CVars.%s", cvar.first.c_str());
|
||||||
|
|
||||||
|
if (cvar.second->type == CVarType::String && cvar.second->value.valueStr != nullptr)
|
||||||
|
pConf->setString(key, std::string(cvar.second->value.valueStr));
|
||||||
|
else if (cvar.second->type == CVarType::S32)
|
||||||
|
pConf->setInt(key, cvar.second->value.valueS32);
|
||||||
|
else if (cvar.second->type == CVarType::Float)
|
||||||
|
pConf->setFloat(key, cvar.second->value.valueFloat);
|
||||||
|
else if (cvar.second->type == CVarType::RGBA)
|
||||||
|
{
|
||||||
|
auto keyStr = key.c_str();
|
||||||
|
Color_RGBA8 clr = cvar.second->value.valueRGBA;
|
||||||
|
pConf->setUInt(StringHelper::Sprintf("%s.R", keyStr), clr.r);
|
||||||
|
pConf->setUInt(StringHelper::Sprintf("%s.G", keyStr), clr.r);
|
||||||
|
pConf->setUInt(StringHelper::Sprintf("%s.B", keyStr), clr.r);
|
||||||
|
pConf->setUInt(StringHelper::Sprintf("%s.A", keyStr), clr.r);
|
||||||
|
pConf->setString(StringHelper::Sprintf("%s.Type", keyStr), mercuryRGBAObjectType);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pConf->save();
|
||||||
|
}
|
||||||
|
@ -33,20 +33,23 @@ extern "C"
|
|||||||
{
|
{
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int32_t CVar_GetS32(const char* name, int32_t defaultValue);
|
float CVar_GetFloat(const char* name, float defaultValue);
|
||||||
float CVar_GetFloat(const char* name, float defaultValue);
|
void CVar_SetFloat(const char* name, float value);
|
||||||
void CVar_SetFloat(const char* name, float value);
|
int32_t CVar_GetS32(const char* name, int32_t defaultValue);
|
||||||
const char* CVar_GetString(const char* name, const char* defaultValue);
|
void CVar_SetS32(const char* name, int32_t value);
|
||||||
void CVar_SetS32(const char* name, int32_t value);
|
const char* CVar_GetString(const char* name, const char* defaultValue);
|
||||||
void CVar_SetString(const char* name, const char* value);
|
void CVar_SetString(const char* name, const char* value);
|
||||||
Color_RGB8 CVar_GetRGB(const char* name, Color_RGB8 defaultValue);
|
Color_RGB8 CVar_GetRGB(const char* name, Color_RGB8 defaultValue);
|
||||||
Color_RGBA8 CVar_GetRGBA(const char* name, Color_RGBA8 defaultValue);
|
Color_RGBA8 CVar_GetRGBA(const char* name, Color_RGBA8 defaultValue);
|
||||||
void CVar_SetRGBA(const char* name, Color_RGBA8 value);
|
void CVar_SetRGBA(const char* name, Color_RGBA8 value);
|
||||||
|
|
||||||
void CVar_RegisterS32(const char* name, int32_t defaultValue);
|
void CVar_RegisterS32(const char* name, int32_t defaultValue);
|
||||||
void CVar_RegisterFloat(const char* name, float defaultValue);
|
void CVar_RegisterFloat(const char* name, float defaultValue);
|
||||||
void CVar_RegisterString(const char* name, const char* defaultValue);
|
void CVar_RegisterString(const char* name, const char* defaultValue);
|
||||||
void CVar_RegisterRGBA(const char* name, Color_RGBA8 defaultValue);
|
void CVar_RegisterRGBA(const char* name, Color_RGBA8 defaultValue);
|
||||||
|
|
||||||
|
void CVar_Load();
|
||||||
|
void CVar_Save();
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
};
|
};
|
||||||
|
@ -1,56 +0,0 @@
|
|||||||
#include "GameSettings.h"
|
|
||||||
|
|
||||||
// Audio
|
|
||||||
#include <cstddef>
|
|
||||||
#include <PR/ultra64/types.h>
|
|
||||||
#include <PR/ultra64/sptask.h>
|
|
||||||
#include <PR/ultra64/pi.h>
|
|
||||||
#include <PR/ultra64/message.h>
|
|
||||||
|
|
||||||
#include "Cvar.h"
|
|
||||||
#include "GlobalCtx2.h"
|
|
||||||
#include "ImGuiImpl.h"
|
|
||||||
#include "../../soh/include/z64audio.h"
|
|
||||||
#include "Hooks.h"
|
|
||||||
#include "../../soh/soh/Enhancements/debugconsole.h"
|
|
||||||
|
|
||||||
#include "Window.h"
|
|
||||||
#include "Lib/Fast3D/gfx_rendering_api.h"
|
|
||||||
|
|
||||||
#define ABS(var) var < 0 ? -(var) : var
|
|
||||||
|
|
||||||
using namespace Ship;
|
|
||||||
|
|
||||||
namespace Game {
|
|
||||||
|
|
||||||
bool DeSyncAudio = false;
|
|
||||||
|
|
||||||
void UpdateAudio() {
|
|
||||||
Audio_SetGameVolume(SEQ_BGM_MAIN, CVar_GetFloat("gMainMusicVolume", 1));
|
|
||||||
Audio_SetGameVolume(SEQ_BGM_SUB, CVar_GetFloat("gSubMusicVolume", 1));
|
|
||||||
Audio_SetGameVolume(SEQ_FANFARE, CVar_GetFloat("gSFXMusicVolume", 1));
|
|
||||||
Audio_SetGameVolume(SEQ_SFX, CVar_GetFloat("gFanfareVolume", 1));
|
|
||||||
}
|
|
||||||
|
|
||||||
void LoadSettings() {
|
|
||||||
DebugConsole_LoadCVars();
|
|
||||||
}
|
|
||||||
|
|
||||||
void SaveSettings() {
|
|
||||||
DebugConsole_SaveCVars();
|
|
||||||
}
|
|
||||||
|
|
||||||
void InitSettings() {
|
|
||||||
Ship::RegisterHook<Ship::AudioInit>(UpdateAudio);
|
|
||||||
Ship::RegisterHook<Ship::GfxInit>([] {
|
|
||||||
gfx_get_current_rendering_api()->set_texture_filter((FilteringMode) CVar_GetS32("gTextureFilter", FILTER_THREE_POINT));
|
|
||||||
SohImGui::console->opened = CVar_GetS32("gConsoleEnabled", 0);
|
|
||||||
SohImGui::controller->Opened = CVar_GetS32("gControllerConfigurationEnabled", 0);
|
|
||||||
UpdateAudio();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
void SetSeqPlayerVolume(SeqPlayers playerId, float volume) {
|
|
||||||
Audio_SetGameVolume(playerId, volume);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,17 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
enum SeqPlayers {
|
|
||||||
/* 0 */ SEQ_BGM_MAIN,
|
|
||||||
/* 1 */ SEQ_FANFARE,
|
|
||||||
/* 2 */ SEQ_SFX,
|
|
||||||
/* 3 */ SEQ_BGM_SUB,
|
|
||||||
/* 4 */ SEQ_MAX
|
|
||||||
};
|
|
||||||
|
|
||||||
namespace Game {
|
|
||||||
void InitSettings();
|
|
||||||
void LoadSettings();
|
|
||||||
void LoadPadSettings();
|
|
||||||
void SaveSettings();
|
|
||||||
void SetSeqPlayerVolume(SeqPlayers playerId, float volume);
|
|
||||||
}
|
|
@ -7,8 +7,13 @@
|
|||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
#include <cstddef>
|
||||||
|
#include <PR/ultra64/types.h>
|
||||||
|
#include <PR/ultra64/sptask.h>
|
||||||
|
#include <PR/ultra64/pi.h>
|
||||||
|
#include <PR/ultra64/message.h>
|
||||||
|
#include "../../soh/include/z64audio.h"
|
||||||
#include "Archive.h"
|
#include "Archive.h"
|
||||||
#include "GameSettings.h"
|
|
||||||
#include "Console.h"
|
#include "Console.h"
|
||||||
#include "Hooks.h"
|
#include "Hooks.h"
|
||||||
#define IMGUI_DEFINE_MATH_OPERATORS
|
#define IMGUI_DEFINE_MATH_OPERATORS
|
||||||
@ -68,6 +73,14 @@ std::vector<std::string> emptyArgs;
|
|||||||
|
|
||||||
bool isBetaQuestEnabled = false;
|
bool isBetaQuestEnabled = false;
|
||||||
|
|
||||||
|
enum SeqPlayers {
|
||||||
|
/* 0 */ SEQ_BGM_MAIN,
|
||||||
|
/* 1 */ SEQ_FANFARE,
|
||||||
|
/* 2 */ SEQ_SFX,
|
||||||
|
/* 3 */ SEQ_BGM_SUB,
|
||||||
|
/* 4 */ SEQ_MAX
|
||||||
|
};
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
void enableBetaQuest() { isBetaQuestEnabled = true; }
|
void enableBetaQuest() { isBetaQuestEnabled = true; }
|
||||||
void disableBetaQuest() { isBetaQuestEnabled = false; }
|
void disableBetaQuest() { isBetaQuestEnabled = false; }
|
||||||
@ -115,6 +128,23 @@ namespace SohImGui {
|
|||||||
std::map<std::string, std::vector<std::string>> windowCategories;
|
std::map<std::string, std::vector<std::string>> windowCategories;
|
||||||
std::map<std::string, CustomWindow> customWindows;
|
std::map<std::string, CustomWindow> customWindows;
|
||||||
|
|
||||||
|
void UpdateAudio() {
|
||||||
|
Audio_SetGameVolume(SEQ_BGM_MAIN, CVar_GetFloat("gMainMusicVolume", 1));
|
||||||
|
Audio_SetGameVolume(SEQ_BGM_SUB, CVar_GetFloat("gSubMusicVolume", 1));
|
||||||
|
Audio_SetGameVolume(SEQ_FANFARE, CVar_GetFloat("gSFXMusicVolume", 1));
|
||||||
|
Audio_SetGameVolume(SEQ_SFX, CVar_GetFloat("gFanfareVolume", 1));
|
||||||
|
}
|
||||||
|
|
||||||
|
void InitSettings() {
|
||||||
|
Ship::RegisterHook<Ship::AudioInit>(UpdateAudio);
|
||||||
|
Ship::RegisterHook<Ship::GfxInit>([] {
|
||||||
|
gfx_get_current_rendering_api()->set_texture_filter((FilteringMode)CVar_GetS32("gTextureFilter", FILTER_THREE_POINT));
|
||||||
|
SohImGui::console->opened = CVar_GetS32("gConsoleEnabled", 0);
|
||||||
|
SohImGui::controller->Opened = CVar_GetS32("gControllerConfigurationEnabled", 0);
|
||||||
|
UpdateAudio();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
int GetBackendID(std::shared_ptr<Mercury> cfg) {
|
int GetBackendID(std::shared_ptr<Mercury> cfg) {
|
||||||
std::string backend = cfg->getString("Window.GfxBackend");
|
std::string backend = cfg->getString("Window.GfxBackend");
|
||||||
if (backend.empty()) {
|
if (backend.empty()) {
|
||||||
@ -347,7 +377,7 @@ namespace SohImGui {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Init(WindowImpl window_impl) {
|
void Init(WindowImpl window_impl) {
|
||||||
Game::LoadSettings();
|
CVar_Load();
|
||||||
impl = window_impl;
|
impl = window_impl;
|
||||||
ImGuiContext* ctx = ImGui::CreateContext();
|
ImGuiContext* ctx = ImGui::CreateContext();
|
||||||
ImGui::SetCurrentContext(ctx);
|
ImGui::SetCurrentContext(ctx);
|
||||||
@ -405,7 +435,7 @@ namespace SohImGui {
|
|||||||
pads = cont_pad;
|
pads = cont_pad;
|
||||||
});
|
});
|
||||||
|
|
||||||
Game::InitSettings();
|
InitSettings();
|
||||||
|
|
||||||
CVar_SetS32("gRandoGenerating", 0);
|
CVar_SetS32("gRandoGenerating", 0);
|
||||||
CVar_SetS32("gNewSeedGenerated", 0);
|
CVar_SetS32("gNewSeedGenerated", 0);
|
||||||
@ -419,7 +449,7 @@ namespace SohImGui {
|
|||||||
|
|
||||||
void Update(EventImpl event) {
|
void Update(EventImpl event) {
|
||||||
if (needs_save) {
|
if (needs_save) {
|
||||||
Game::SaveSettings();
|
CVar_Save();
|
||||||
needs_save = false;
|
needs_save = false;
|
||||||
}
|
}
|
||||||
ImGuiProcessEvent(event);
|
ImGuiProcessEvent(event);
|
||||||
@ -436,11 +466,10 @@ namespace SohImGui {
|
|||||||
const float volume = floorf(value * 100) / 100;
|
const float volume = floorf(value * 100) / 100;
|
||||||
CVar_SetFloat(key, volume);
|
CVar_SetFloat(key, volume);
|
||||||
needs_save = true;
|
needs_save = true;
|
||||||
Game::SetSeqPlayerVolume(playerId, volume);
|
Audio_SetGameVolume(playerId, volume);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void EnhancementCombobox(const char* name, const char* ComboArray[], size_t arraySize, uint8_t FirstTimeValue = 0) {
|
void EnhancementCombobox(const char* name, const char* ComboArray[], size_t arraySize, uint8_t FirstTimeValue = 0) {
|
||||||
if (FirstTimeValue <= 0) {
|
if (FirstTimeValue <= 0) {
|
||||||
FirstTimeValue = 0;
|
FirstTimeValue = 0;
|
||||||
|
@ -32,7 +32,6 @@
|
|||||||
|
|
||||||
#define DECLARE_GFX_DXGI_FUNCTIONS
|
#define DECLARE_GFX_DXGI_FUNCTIONS
|
||||||
#include "gfx_dxgi.h"
|
#include "gfx_dxgi.h"
|
||||||
#include "../../GameSettings.h"
|
|
||||||
|
|
||||||
#define WINCLASS_NAME L"N64GAME"
|
#define WINCLASS_NAME L"N64GAME"
|
||||||
#define GFX_API_NAME "DirectX"
|
#define GFX_API_NAME "DirectX"
|
||||||
@ -274,7 +273,7 @@ static LRESULT CALLBACK gfx_dxgi_wnd_proc(HWND h_wnd, UINT message, WPARAM w_par
|
|||||||
DragQueryFileA((HDROP)w_param, 0, fileName, 256);
|
DragQueryFileA((HDROP)w_param, 0, fileName, 256);
|
||||||
CVar_SetString("gDroppedFile", fileName);
|
CVar_SetString("gDroppedFile", fileName);
|
||||||
CVar_SetS32("gNewFileDropped", 1);
|
CVar_SetS32("gNewFileDropped", 1);
|
||||||
Game::SaveSettings();
|
CVar_Save();
|
||||||
break;
|
break;
|
||||||
case WM_SYSKEYDOWN:
|
case WM_SYSKEYDOWN:
|
||||||
if ((w_param == VK_RETURN) && ((l_param & 1 << 30) == 0)) {
|
if ((w_param == VK_RETURN) && ((l_param & 1 << 30) == 0)) {
|
||||||
|
@ -35,8 +35,6 @@
|
|||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
#include <WTypesbase.h>
|
#include <WTypesbase.h>
|
||||||
#endif
|
#endif
|
||||||
#include <time.h>
|
|
||||||
#include "../../GameSettings.h"
|
|
||||||
|
|
||||||
#define GFX_API_NAME "SDL2 - OpenGL"
|
#define GFX_API_NAME "SDL2 - OpenGL"
|
||||||
|
|
||||||
@ -306,7 +304,7 @@ static void gfx_sdl_handle_events(void) {
|
|||||||
case SDL_DROPFILE:
|
case SDL_DROPFILE:
|
||||||
CVar_SetString("gDroppedFile", event.drop.file);
|
CVar_SetString("gDroppedFile", event.drop.file);
|
||||||
CVar_SetS32("gNewFileDropped", 1);
|
CVar_SetS32("gNewFileDropped", 1);
|
||||||
Game::SaveSettings();
|
CVar_Save();
|
||||||
break;
|
break;
|
||||||
case SDL_QUIT:
|
case SDL_QUIT:
|
||||||
Ship::ExecuteHooks<Ship::ExitGame>();
|
Ship::ExecuteHooks<Ship::ExitGame>();
|
||||||
|
@ -9,7 +9,6 @@
|
|||||||
#include <spdlog/sinks/base_sink.h>
|
#include <spdlog/sinks/base_sink.h>
|
||||||
#include <spdlog/details/synchronous_factory.h>
|
#include <spdlog/details/synchronous_factory.h>
|
||||||
#include "ImGuiImpl.h"
|
#include "ImGuiImpl.h"
|
||||||
#include "GameSettings.h"
|
|
||||||
#include "Cvar.h"
|
#include "Cvar.h"
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
|
@ -261,7 +261,6 @@
|
|||||||
<ClCompile Include="Factories\AudioFactory.cpp" />
|
<ClCompile Include="Factories\AudioFactory.cpp" />
|
||||||
<ClCompile Include="InputEditor.cpp" />
|
<ClCompile Include="InputEditor.cpp" />
|
||||||
<ClCompile Include="GameOverlay.cpp" />
|
<ClCompile Include="GameOverlay.cpp" />
|
||||||
<ClCompile Include="GameSettings.cpp" />
|
|
||||||
<ClCompile Include="Lib\ImGui\backends\imgui_impl_dx11.cpp" />
|
<ClCompile Include="Lib\ImGui\backends\imgui_impl_dx11.cpp" />
|
||||||
<ClCompile Include="Lib\ImGui\backends\imgui_impl_win32.cpp" />
|
<ClCompile Include="Lib\ImGui\backends\imgui_impl_win32.cpp" />
|
||||||
<ClCompile Include="Lib\Mercury\Mercury.cpp" />
|
<ClCompile Include="Lib\Mercury\Mercury.cpp" />
|
||||||
@ -353,7 +352,6 @@
|
|||||||
<ClInclude Include="Factories\AudioFactory.h" />
|
<ClInclude Include="Factories\AudioFactory.h" />
|
||||||
<ClInclude Include="InputEditor.h" />
|
<ClInclude Include="InputEditor.h" />
|
||||||
<ClInclude Include="GameOverlay.h" />
|
<ClInclude Include="GameOverlay.h" />
|
||||||
<ClInclude Include="GameSettings.h" />
|
|
||||||
<ClInclude Include="GameVersions.h" />
|
<ClInclude Include="GameVersions.h" />
|
||||||
<ClInclude Include="Lib\dr_libs\mp3.h" />
|
<ClInclude Include="Lib\dr_libs\mp3.h" />
|
||||||
<ClInclude Include="Lib\dr_libs\wav.h" />
|
<ClInclude Include="Lib\dr_libs\wav.h" />
|
||||||
|
@ -318,9 +318,6 @@
|
|||||||
<ClCompile Include="luslog.cpp">
|
<ClCompile Include="luslog.cpp">
|
||||||
<Filter>Source Files\Logging</Filter>
|
<Filter>Source Files\Logging</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<ClCompile Include="GameSettings.cpp">
|
|
||||||
<Filter>Source Files\CustomImpl</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="Audio.cpp">
|
<ClCompile Include="Audio.cpp">
|
||||||
<Filter>Source Files\Resources\Files</Filter>
|
<Filter>Source Files\Resources\Files</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
@ -608,9 +605,6 @@
|
|||||||
<ClInclude Include="luslog.h">
|
<ClInclude Include="luslog.h">
|
||||||
<Filter>Source Files\Logging</Filter>
|
<Filter>Source Files\Logging</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="GameSettings.h">
|
|
||||||
<Filter>Source Files\CustomImpl</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="GameVersions.h">
|
<ClInclude Include="GameVersions.h">
|
||||||
<Filter>Source Files\Resources</Filter>
|
<Filter>Source Files\Resources</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
@ -1,11 +1,6 @@
|
|||||||
#include "CosmeticsEditor.h"
|
#include "CosmeticsEditor.h"
|
||||||
#include "../../util.h"
|
|
||||||
#include "../libultraship/ImGuiImpl.h"
|
#include "../libultraship/ImGuiImpl.h"
|
||||||
#include "GameSettings.h"
|
|
||||||
|
|
||||||
#include <array>
|
|
||||||
#include <bit>
|
|
||||||
#include <map>
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <Cvar.h>
|
#include <Cvar.h>
|
||||||
#include <PR/ultra64/types.h>
|
#include <PR/ultra64/types.h>
|
||||||
|
@ -14,7 +14,6 @@
|
|||||||
#define Path _Path
|
#define Path _Path
|
||||||
#define PATH_HACK
|
#define PATH_HACK
|
||||||
#include <Utils/StringHelper.h>
|
#include <Utils/StringHelper.h>
|
||||||
#include <Utils/File.h>
|
|
||||||
|
|
||||||
#include "Window.h"
|
#include "Window.h"
|
||||||
#include "Lib/ImGui/imgui_internal.h"
|
#include "Lib/ImGui/imgui_internal.h"
|
||||||
@ -426,7 +425,7 @@ static bool SetCVarHandler(const std::vector<std::string>& args) {
|
|||||||
else
|
else
|
||||||
CVar_SetS32(args[1].c_str(), std::stoi(args[2]));
|
CVar_SetS32(args[1].c_str(), std::stoi(args[2]));
|
||||||
|
|
||||||
DebugConsole_SaveCVars();
|
CVar_Save();
|
||||||
|
|
||||||
//INFO("[SOH] Updated player position to [ %.2f, %.2f, %.2f ]", pos.x, pos.y, pos.z);
|
//INFO("[SOH] Updated player position to [ %.2f, %.2f, %.2f ]", pos.x, pos.y, pos.z);
|
||||||
return CMD_SUCCESS;
|
return CMD_SUCCESS;
|
||||||
@ -507,123 +506,5 @@ void DebugConsole_Init(void) {
|
|||||||
Ship::ArgumentType::NUMBER,
|
Ship::ArgumentType::NUMBER,
|
||||||
}
|
}
|
||||||
} });
|
} });
|
||||||
DebugConsole_LoadCVars();
|
CVar_Load();
|
||||||
}
|
|
||||||
|
|
||||||
template <typename Numeric> bool is_number(const std::string& s) {
|
|
||||||
Numeric n;
|
|
||||||
return ((std::istringstream(s) >> n >> std::ws).eof());
|
|
||||||
}
|
|
||||||
|
|
||||||
void DebugConsole_LoadLegacyCVars() {
|
|
||||||
auto cvarsConfig = Ship::GlobalCtx2::GetPathRelativeToAppDirectory("cvars.cfg");
|
|
||||||
if (File::Exists(cvarsConfig)) {
|
|
||||||
const auto lines = File::ReadAllLines(cvarsConfig);
|
|
||||||
|
|
||||||
for (const std::string& line : lines) {
|
|
||||||
std::vector<std::string> cfg = StringHelper::Split(line, " = ");
|
|
||||||
if (line.empty()) continue;
|
|
||||||
if (cfg.size() < 2) continue;
|
|
||||||
|
|
||||||
if (cfg[1].find("\"") == std::string::npos && (cfg[1].find("#") != std::string::npos))
|
|
||||||
{
|
|
||||||
std::string value(cfg[1]);
|
|
||||||
value.erase(std::remove_if(value.begin(), value.end(), [](char c) { return c == '#'; }), value.end());
|
|
||||||
auto splitTest = StringHelper::Split(value, "\r")[0];
|
|
||||||
|
|
||||||
uint32_t val = std::stoul(splitTest, nullptr, 16);
|
|
||||||
Color_RGBA8 clr;
|
|
||||||
clr.r = val >> 24;
|
|
||||||
clr.g = val >> 16;
|
|
||||||
clr.b = val >> 8;
|
|
||||||
clr.a = val & 0xFF;
|
|
||||||
CVar_SetRGBA(cfg[0].c_str(), clr);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (cfg[1].find("\"") != std::string::npos) {
|
|
||||||
std::string value(cfg[1]);
|
|
||||||
value.erase(std::remove(value.begin(), value.end(), '\"'), value.end());
|
|
||||||
CVar_SetString(cfg[0].c_str(), ImStrdup(value.c_str()));
|
|
||||||
}
|
|
||||||
if (is_number<float>(cfg[1])) {
|
|
||||||
CVar_SetFloat(cfg[0].c_str(), std::stof(cfg[1]));
|
|
||||||
}
|
|
||||||
if (is_number<int>(cfg[1])) {
|
|
||||||
CVar_SetS32(cfg[0].c_str(), std::stoi(cfg[1]));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fs::remove(cvarsConfig);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void DebugConsole_LoadCVars() {
|
|
||||||
|
|
||||||
std::shared_ptr<Mercury> pConf = Ship::GlobalCtx2::GetInstance()->GetConfig();
|
|
||||||
pConf->reload();
|
|
||||||
|
|
||||||
for (const auto& item : pConf->rjson["CVars"].items()) {
|
|
||||||
auto value = item.value();
|
|
||||||
switch (value.type()) {
|
|
||||||
case nlohmann::detail::value_t::array:
|
|
||||||
break;
|
|
||||||
case nlohmann::detail::value_t::object:
|
|
||||||
if (value["Type"].get<std::string>() == mercuryRGBAObjectType) {
|
|
||||||
Color_RGBA8 clr;
|
|
||||||
clr.r = value["R"].get<uint8_t>();
|
|
||||||
clr.g = value["G"].get<uint8_t>();
|
|
||||||
clr.b = value["B"].get<uint8_t>();
|
|
||||||
clr.a = value["A"].get<uint8_t>();
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
|
||||||
case nlohmann::detail::value_t::string:
|
|
||||||
CVar_SetString(item.key().c_str(), value.get<std::string>().c_str());
|
|
||||||
break;
|
|
||||||
case nlohmann::detail::value_t::boolean:
|
|
||||||
CVar_SetS32(item.key().c_str(), value.get<bool>());
|
|
||||||
break;
|
|
||||||
case nlohmann::detail::value_t::number_unsigned:
|
|
||||||
case nlohmann::detail::value_t::number_integer:
|
|
||||||
CVar_SetS32(item.key().c_str(), value.get<int>());
|
|
||||||
break;
|
|
||||||
case nlohmann::detail::value_t::number_float:
|
|
||||||
CVar_SetFloat(item.key().c_str(), value.get<float>());
|
|
||||||
break;
|
|
||||||
default: ;
|
|
||||||
}
|
|
||||||
if (item.key() == "gOpenMenuBar") {
|
|
||||||
int bp = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
DebugConsole_LoadLegacyCVars();
|
|
||||||
}
|
|
||||||
|
|
||||||
void DebugConsole_SaveCVars()
|
|
||||||
{
|
|
||||||
std::shared_ptr<Mercury> pConf = Ship::GlobalCtx2::GetInstance()->GetConfig();
|
|
||||||
|
|
||||||
for (const auto &cvar : cvars) {
|
|
||||||
const std::string key = StringHelper::Sprintf("CVars.%s", cvar.first.c_str());
|
|
||||||
|
|
||||||
if (cvar.second->type == CVarType::String && cvar.second->value.valueStr != nullptr)
|
|
||||||
pConf->setString(key, std::string(cvar.second->value.valueStr));
|
|
||||||
else if (cvar.second->type == CVarType::S32)
|
|
||||||
pConf->setInt(key, cvar.second->value.valueS32);
|
|
||||||
else if (cvar.second->type == CVarType::Float)
|
|
||||||
pConf->setFloat(key, cvar.second->value.valueFloat);
|
|
||||||
else if (cvar.second->type == CVarType::RGBA)
|
|
||||||
{
|
|
||||||
auto keyStr = key.c_str();
|
|
||||||
Color_RGBA8 clr = cvar.second->value.valueRGBA;
|
|
||||||
pConf->setUInt(StringHelper::Sprintf("%s.R", keyStr), clr.r);
|
|
||||||
pConf->setUInt(StringHelper::Sprintf("%s.G", keyStr), clr.r);
|
|
||||||
pConf->setUInt(StringHelper::Sprintf("%s.B", keyStr), clr.r);
|
|
||||||
pConf->setUInt(StringHelper::Sprintf("%s.A", keyStr), clr.r);
|
|
||||||
pConf->setString(StringHelper::Sprintf("%s.Type", keyStr), mercuryRGBAObjectType);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pConf->save();
|
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
void DebugConsole_Init(void);
|
void DebugConsole_Init(void);
|
||||||
void DebugConsole_LoadCVars();
|
|
||||||
void DebugConsole_SaveCVars();
|
|
@ -6,7 +6,6 @@
|
|||||||
#include "rando_main.hpp"
|
#include "rando_main.hpp"
|
||||||
// #include <soh/Enhancements/randomizer.h>
|
// #include <soh/Enhancements/randomizer.h>
|
||||||
#include <Cvar.h>
|
#include <Cvar.h>
|
||||||
#include <GameSettings.h>
|
|
||||||
#define NOGDI
|
#define NOGDI
|
||||||
#define WIN32_LEAN_AND_MEAN
|
#define WIN32_LEAN_AND_MEAN
|
||||||
#include <GlobalCtx2.h>
|
#include <GlobalCtx2.h>
|
||||||
@ -25,7 +24,7 @@ void RandoMain::GenerateRando(std::unordered_map<RandomizerSettingKey, u8> cvarS
|
|||||||
std::string fileName = Ship::GlobalCtx2::GetPathRelativeToAppDirectory(GenerateRandomizer(cvarSettings).c_str());
|
std::string fileName = Ship::GlobalCtx2::GetPathRelativeToAppDirectory(GenerateRandomizer(cvarSettings).c_str());
|
||||||
CVar_SetString("gSpoilerLog", fileName.c_str());
|
CVar_SetString("gSpoilerLog", fileName.c_str());
|
||||||
|
|
||||||
Game::SaveSettings();
|
CVar_Save();
|
||||||
Game::LoadSettings();
|
CVar_Load();
|
||||||
CVar_SetS32("gNewSeedGenerated", 1);
|
CVar_SetS32("gNewSeedGenerated", 1);
|
||||||
}
|
}
|
@ -8,7 +8,6 @@
|
|||||||
#include <Cvar.h>
|
#include <Cvar.h>
|
||||||
#include <textures/icon_item_static/icon_item_static.h>
|
#include <textures/icon_item_static/icon_item_static.h>
|
||||||
#include <textures/icon_item_24_static/icon_item_24_static.h>
|
#include <textures/icon_item_24_static/icon_item_24_static.h>
|
||||||
#include <GameSettings.h>
|
|
||||||
#include "../libultraship/ImGuiImpl.h"
|
#include "../libultraship/ImGuiImpl.h"
|
||||||
#include <thread>
|
#include <thread>
|
||||||
#include "3drando/rando_main.hpp"
|
#include "3drando/rando_main.hpp"
|
||||||
@ -3192,7 +3191,7 @@ std::thread randoThread;
|
|||||||
|
|
||||||
void GenerateRandomizerImgui() {
|
void GenerateRandomizerImgui() {
|
||||||
CVar_SetS32("gRandoGenerating", 1);
|
CVar_SetS32("gRandoGenerating", 1);
|
||||||
Game::SaveSettings();
|
CVar_Save();
|
||||||
|
|
||||||
std::unordered_map<RandomizerSettingKey, u8> cvarSettings;
|
std::unordered_map<RandomizerSettingKey, u8> cvarSettings;
|
||||||
cvarSettings[RSK_FOREST] = CVar_GetS32("gRandomizeForest", 1);
|
cvarSettings[RSK_FOREST] = CVar_GetS32("gRandomizeForest", 1);
|
||||||
@ -3258,9 +3257,8 @@ void GenerateRandomizerImgui() {
|
|||||||
RandoMain::GenerateRando(cvarSettings);
|
RandoMain::GenerateRando(cvarSettings);
|
||||||
|
|
||||||
CVar_SetS32("gRandoGenerating", 0);
|
CVar_SetS32("gRandoGenerating", 0);
|
||||||
Game::SaveSettings();
|
CVar_Save();
|
||||||
|
CVar_Load();
|
||||||
Game::LoadSettings();
|
|
||||||
|
|
||||||
generated = 1;
|
generated = 1;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user