From f1dda57847b01abb74481f022dca08c3306f3c83 Mon Sep 17 00:00:00 2001 From: CT5 Date: Thu, 6 Nov 2025 20:46:36 +1100 Subject: [PATCH] Added Config --- dlls/AcpHal/AcpHal.cpp | 6 -- dlls/common/Config.h | 2 + dlls/d3d11_x/overlay/overlay.cpp | 51 ----------------- .../Windows.Xbox.Input.Gamepad.cpp | 35 +++++++++--- .../Windows.Xbox.Input.Gamepad.h | 6 +- dlls/winrt_x/WinDurangoConfig.cpp | 55 +++++++++++++++---- dlls/winrt_x/WinDurangoConfig.h | 12 +++- 7 files changed, 88 insertions(+), 79 deletions(-) diff --git a/dlls/AcpHal/AcpHal.cpp b/dlls/AcpHal/AcpHal.cpp index 1751af6..204ae17 100644 --- a/dlls/AcpHal/AcpHal.cpp +++ b/dlls/AcpHal/AcpHal.cpp @@ -8,7 +8,6 @@ #include "contexts.h" #include #include -<<<<<<< Updated upstream //#include "../common/DebugLogger.h" static APU_HEAP g_ApuHeap = { 0 }; @@ -41,7 +40,6 @@ HRESULT AcpHalAllocateShapeContexts_X(SHAPE_CONTEXTS* ctx) { } -<<<<<<< Updated upstream HRESULT AcpHalReleaseShapeContexts_X() { //DEBUG_LOG(); @@ -138,7 +136,6 @@ HRESULT __stdcall ApuCreateHeap_X(UINT32 cachedSizeInBytes, UINT32 nonCachedSize HRESULT __stdcall ApuHeapGetState_X(ApuHeapState* apuHeapState, UINT32 flags) { -<<<<<<< Updated upstream //DEBUG_LOG(); if (!apuHeapState) @@ -158,7 +155,6 @@ bool ApuIsVirtualAddressValid_X( UINT32 physicalAlignmentInBytes ) { -<<<<<<< Updated upstream //DEBUG_LOG(); if (!virtualAddress || physicalAlignmentInBytes == 0) @@ -180,7 +176,6 @@ HRESULT ApuFree_X(void* virtualAddress) } APU_ADDRESS __stdcall ApuMapVirtualAddress_X(const void* virtualAddress) { -<<<<<<< Updated upstream //DEBUG_LOG(); return reinterpret_cast(virtualAddress); } @@ -189,7 +184,6 @@ void* ApuMapApuAddress_X( APU_ADDRESS apuPhysicalAddress ) { -<<<<<<< Updated upstream //DEBUG_LOG(); return reinterpret_cast(apuPhysicalAddress); } diff --git a/dlls/common/Config.h b/dlls/common/Config.h index a3da4ff..bda6268 100644 --- a/dlls/common/Config.h +++ b/dlls/common/Config.h @@ -164,6 +164,8 @@ public: } }; +extern Config cfg; + /* Usage Example: diff --git a/dlls/d3d11_x/overlay/overlay.cpp b/dlls/d3d11_x/overlay/overlay.cpp index 809ad96..49e9a4f 100644 --- a/dlls/d3d11_x/overlay/overlay.cpp +++ b/dlls/d3d11_x/overlay/overlay.cpp @@ -66,10 +66,6 @@ void wd::Overlay::Initialize() io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad; -<<<<<<< Updated upstream - io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\segoeui.ttf", 18.0f); - ImGui::StyleColorsDark(); -======= ImFont* mainFont = io.Fonts->AddFontFromFileTTF("C:\\Windows\\Fonts\\segoeui.ttf", 18.0f); ImFontConfig config; @@ -81,7 +77,6 @@ void wd::Overlay::Initialize() // 3️⃣ Build the font atlas io.Fonts->Build( ); ImGui::StyleColorsDark( ); ->>>>>>> Stashed changes ImGui_ImplUwp_InitForCurrentView(); ImGui_ImplDX11_Init(m_pDevice, m_pContext); @@ -253,13 +248,8 @@ void wd::Overlay::Present() ImGui_ImplDX11_RenderDrawData(ImGui::GetDrawData()); } -<<<<<<< Updated upstream -void wd::Overlay::RenderKeyboardWindow() -======= static int cursorPos = 0; - void wd::Overlay::RenderKeyboardWindow( ) ->>>>>>> Stashed changes { static bool isUppercase = false; static bool isSymbols = false; @@ -279,37 +269,11 @@ void wd::Overlay::RenderKeyboardWindow( ) const char** currentKeys = isSymbols ? symbols : keys; -<<<<<<< Updated upstream - ImGuiIO& io = ImGui::GetIO(); - ImGui::SetNextWindowSize(ImVec2(500, 330)); - ImGui::SetNextWindowPos(ImVec2(io.DisplaySize.x * 0.5f, io.DisplaySize.y * 0.5f), ImGuiCond_Always, ImVec2(0.5f, 0.5f)); - ImGui::Begin("WinDurango Keyboard", nullptr, ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoCollapse); -======= ImGuiIO& io = ImGui::GetIO( ); ImVec2 displaySize = ImGui::GetIO( ).DisplaySize; ->>>>>>> Stashed changes ImGui::SetNextWindowPos(ImVec2(displaySize.x / 2, displaySize.y / 2), ImGuiCond_Always); -<<<<<<< Updated upstream - if (ImGui::Button(isUppercase ? "Lowercase" : "Uppercase")) - isUppercase = !isUppercase; - ImGui::SameLine(); - if (ImGui::Button(isSymbols ? "Letters" : "Symbols")) - isSymbols = !isSymbols; - - ImGui::NewLine(); - RenderKeyboardRow(currentKeys, 0, 12, isUppercase); - RenderKeyboardRow(currentKeys, 12, 24, isUppercase); - if (!isSymbols) RenderKeyboardRow(currentKeys, 24, 35, isUppercase); - else RenderKeyboardRow(currentKeys, 24, 32, isUppercase); - if (!isSymbols) RenderKeyboardRow(currentKeys, 35, 44, isUppercase); - - ImGui::NewLine(); - HandleKeyboardSpecialKeys(); - - ImGui::End(); -======= ImGuiWindowFlags windowFlags = ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoScrollbar; ImGui::PushStyleColor(ImGuiCol_WindowBg, IM_COL32(0x05, 0x05, 0x05, 0xFF)); @@ -547,7 +511,6 @@ void wd::Overlay::RenderKeyboardWindow( ) ImGui::PopStyleColor( ); ImGui::End( ); ImGui::PopStyleColor( ); ->>>>>>> Stashed changes } void wd::Overlay::RenderKeyboardRow(const char** keys, int start, int end, bool isUppercase) @@ -584,23 +547,9 @@ void wd::Overlay::HandleKeyboardSpecialKeys() if (ImGui::Button("##space", ImVec2((ImGui::GetContentRegionAvail( ).x - 63), 30)) || ImGui::IsKeyPressed(ImGuiKey_GamepadFaceUp)) AddKeyToBuffer(' '); -<<<<<<< Updated upstream - ImGui::SameLine(); - - if (ImGui::Button("Backspace", ImVec2(90, 30)) || - ImGui::IsKeyPressed(ImGuiKey_Backspace) || - ImGui::IsKeyPressed(ImGuiKey_GamepadFaceLeft)) - { - size_t len = strlen(g_KeyboardText); - if (len > 0) - g_KeyboardText[ len - 1 ] = '\0'; - } - ImGui::SameLine(); -======= ImVec2 pos = ImGui::GetItemRectMin( ); ImVec2 size = ImGui::GetItemRectSize( ); ->>>>>>> Stashed changes ImVec2 bigTextSize = ImGui::CalcTextSize("\xEE\x9D\x9D"); ImGui::GetWindowDrawList( )->AddText( diff --git a/dlls/winrt_x/Implementation/Windows.Xbox.Input.Gamepad.cpp b/dlls/winrt_x/Implementation/Windows.Xbox.Input.Gamepad.cpp index d5545fa..ae51b94 100644 --- a/dlls/winrt_x/Implementation/Windows.Xbox.Input.Gamepad.cpp +++ b/dlls/winrt_x/Implementation/Windows.Xbox.Input.Gamepad.cpp @@ -9,6 +9,7 @@ #include #include #include "Windows.Xbox.System.User.h" +#include "../WinDurangoConfig.h" namespace winrt::Windows::Xbox::Input::implementation { @@ -185,6 +186,11 @@ namespace winrt::Windows::Xbox::Input::implementation if (GetAsyncKeyState(keyboardButtons[ i ].first)) { reading.Buttons |= keyboardButtons[ i ].second; + if (keyboardButtons[i].first == 'V') { + //menuOpened = true; + } else if (keyboardButtons[i].first == 'X') { + //menuOpened = false; + } } if (GetAsyncKeyState('W') & 0x8000) { ly = 1.0f; @@ -208,11 +214,21 @@ namespace winrt::Windows::Xbox::Input::implementation reading.LeftThumbstickY = ly; } - if (GetAsyncKeyState(VK_LBUTTON) & 0x8000) { - reading.RightTrigger = 1.0f; - } - if (GetAsyncKeyState(VK_RBUTTON) & 0x8000) { - reading.LeftTrigger = 1.0f; + if (menuOpened && wdcfg.GetData().game == WinDurangoConfigData::Game::Minecraft) { + if (GetAsyncKeyState(VK_LBUTTON) & 0x8000) { + reading.Buttons |= keyboardButtons[VK_SPACE].second; + + } + if (GetAsyncKeyState(VK_RBUTTON) & 0x8000) { + reading.Buttons |= keyboardButtons['V'].second; + } + } else { + if (GetAsyncKeyState(VK_LBUTTON) & 0x8000) { + reading.RightTrigger = 1.0f; + } + if (GetAsyncKeyState(VK_RBUTTON) & 0x8000) { + reading.LeftTrigger = 1.0f; + } } /* @@ -246,8 +262,13 @@ namespace winrt::Windows::Xbox::Input::implementation y *= -sign(deltasumY); if (x != 0 || y != 0) { - reading.RightThumbstickX = std::clamp(x, -1.0f, 1.0f); - reading.RightThumbstickY = std::clamp(y, -1.0f, 1.0f); + if (menuOpened && wdcfg.GetData().game == WinDurangoConfigData::Game::Minecraft) { + reading.LeftThumbstickX = std::clamp(x, -1.0f, 1.0f); + reading.LeftThumbstickY = std::clamp(y, -1.0f, 1.0f); + } else { + reading.RightThumbstickX = std::clamp(x, -1.0f, 1.0f); + reading.RightThumbstickY = std::clamp(y, -1.0f, 1.0f); + } } deltasumX = 0.0f; diff --git a/dlls/winrt_x/Implementation/Windows.Xbox.Input.Gamepad.h b/dlls/winrt_x/Implementation/Windows.Xbox.Input.Gamepad.h index 8e5b707..8060c43 100644 --- a/dlls/winrt_x/Implementation/Windows.Xbox.Input.Gamepad.h +++ b/dlls/winrt_x/Implementation/Windows.Xbox.Input.Gamepad.h @@ -10,7 +10,7 @@ namespace winrt::Windows::Xbox::Input::implementation struct Gamepad : GamepadT { Gamepad() = default; - Gamepad(uint64_t id) : m_id(id) {} + Gamepad(uint64_t id) : m_id(id), wdcfg(WinDurangoConfig::Instance()) {} static winrt::Windows::Foundation::Collections::IVectorView Gamepads(); static winrt::event_token GamepadAdded(winrt::Windows::Foundation::EventHandler const& handler); @@ -37,6 +37,8 @@ namespace winrt::Windows::Xbox::Input::implementation float deltasumX = 0.0f; float deltasumY = 0.0f; bool firstFrame = true; + bool menuOpened = false; + WinDurangoConfig& wdcfg; inline static std::pair const gamepadButtons[] = { @@ -70,7 +72,7 @@ namespace winrt::Windows::Xbox::Input::implementation { VK_RCONTROL, GamepadButtons::RightShoulder }, { VK_SPACE, GamepadButtons::A }, { 'X', GamepadButtons::B}, - { 'C', GamepadButtons::X }, + { 'C', GamepadButtons::X}, { 'V', GamepadButtons::Y}, }; }; diff --git a/dlls/winrt_x/WinDurangoConfig.cpp b/dlls/winrt_x/WinDurangoConfig.cpp index d494d00..bf5b38c 100644 --- a/dlls/winrt_x/WinDurangoConfig.cpp +++ b/dlls/winrt_x/WinDurangoConfig.cpp @@ -1,5 +1,7 @@ #include "pch.h" #include "WinDurangoConfig.h" +#include +using namespace winrt::Windows::Storage; WinDurangoConfig& WinDurangoConfig::Instance() { @@ -26,19 +28,39 @@ void WinDurangoConfig::ProcessConfigFile() Gamertag = "TheDurangler2" Gamerscore = 1500 Reputation = 5 + Game = "Unknown" AgeGroup = "Adult" )"sv; try { - // TODO: Try to read the config file from disk. If it doesn't exist, use the default data. + /* + * We need to use WinRT Storage APIs in UWP + */ + StorageFolder localFolder = ApplicationData::Current().LocalFolder(); + std::string pathStr(localFolder.Path().begin(), localFolder.Path().end()); + if (!std::filesystem::exists(pathStr + "/config.toml")) { + winrt::Windows::Storage::StorageFile file = localFolder + .CreateFileAsync(L"config.toml", winrt::Windows::Storage::CreationCollisionOption::ReplaceExisting) + .get(); - auto tbl = toml::parse(default_config_data); + std::wstring_convert> converter; + std::wstring wide = converter.from_bytes(std::string(default_config_data)); + winrt::Windows::Storage::FileIO::WriteTextAsync(file, wide).get(); + } - const auto gamertag_opt = tbl["WinDurango"]["Gamertag"].value(); - const auto gamerscore_opt = tbl["WinDurango"]["Gamerscore"].value(); - const auto reputation_opt = tbl["WinDurango"]["Reputation"].value(); - const auto agegroup_opt = tbl["WinDurango"]["AgeGroup"].value(); + StorageFile file = ApplicationData::Current().LocalFolder().GetFileAsync(L"config.toml").get(); + std::wstring cfdata = std::wstring(FileIO::ReadTextAsync(file).get()); + + std::string ConfigData(cfdata.begin(), cfdata.end()); + + auto tbl = toml::parse(ConfigData); + + auto gamertag_opt = tbl["WinDurango"]["Gamertag"].value(); + auto gamerscore_opt = tbl["WinDurango"]["Gamerscore"].value(); + auto reputation_opt = tbl["WinDurango"]["Reputation"].value(); + auto agegroup_opt = tbl["WinDurango"]["AgeGroup"].value(); + auto game_opt = tbl["WinDurango"]["Game"].value(); const WinDurangoConfigData data { @@ -51,16 +73,27 @@ void WinDurangoConfig::ProcessConfigFile() : agegroup_opt.value() == "Teen" ? WinDurangoConfigData::AgeGroup::Teen : agegroup_opt.value() == "Adult" ? WinDurangoConfigData::AgeGroup::Adult : WinDurangoConfigData::AgeGroup::Unknown) - : WinDurangoConfigData::AgeGroup::Unknown + : WinDurangoConfigData::AgeGroup::Unknown, + .game = + game_opt.has_value() + ? (game_opt.value() == "Minecraft" ? WinDurangoConfigData::Game::Minecraft + : game_opt.value() == "Forza Horizon 2" ? WinDurangoConfigData::Game::Forza_Horizon_2 + : WinDurangoConfigData::Game::Unknown) + : WinDurangoConfigData::Game::Unknown }; - Instance().SetData(data); - - // TODO: Save the config file, if the file didn't exist before. + SetData(data); } catch (const toml::parse_error& err) { - std::cerr << "Parsing failed:\n" << err << "\n"; + LOG_INFO("WinDurangoConfig || Parsing failed: %s\n", err); + const WinDurangoConfigData data + { + .gamertag = std::string("TheDurangler2"), + .gamerscore = 1500, + .reputation = 5, + .ageGroup = WinDurangoConfigData::AgeGroup::Unknown + }; } } diff --git a/dlls/winrt_x/WinDurangoConfig.h b/dlls/winrt_x/WinDurangoConfig.h index 5226e53..1748766 100644 --- a/dlls/winrt_x/WinDurangoConfig.h +++ b/dlls/winrt_x/WinDurangoConfig.h @@ -1,6 +1,8 @@ #pragma once - #include "toml.hpp" +#include +#include +#include struct WinDurangoConfigData { @@ -14,6 +16,12 @@ struct WinDurangoConfigData Adult, Unknown } ageGroup{ AgeGroup::Unknown }; + enum class Game + { + Minecraft, + Forza_Horizon_2, + Unknown + } game{ Game::Unknown }; }; class WinDurangoConfig @@ -33,7 +41,7 @@ private: WinDurangoConfig(); ~WinDurangoConfig() = default; - static void ProcessConfigFile(); + void ProcessConfigFile(); WinDurangoConfigData _data{};