Added Config

This commit is contained in:
CT5
2025-11-06 20:46:36 +11:00
parent a5c8ff1387
commit f1dda57847
7 changed files with 88 additions and 79 deletions
-6
View File
@@ -8,7 +8,6 @@
#include "contexts.h"
#include <intsafe.h>
#include <new>
<<<<<<< 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<APU_ADDRESS>(virtualAddress);
}
@@ -189,7 +184,6 @@ void* ApuMapApuAddress_X(
APU_ADDRESS apuPhysicalAddress
)
{
<<<<<<< Updated upstream
//DEBUG_LOG();
return reinterpret_cast<void*>(apuPhysicalAddress);
}
+2
View File
@@ -164,6 +164,8 @@ public:
}
};
extern Config cfg;
/*
Usage Example:
-51
View File
@@ -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(
@@ -9,6 +9,7 @@
#include <windowsx.h>
#include <Xinput.h>
#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;
@@ -10,7 +10,7 @@ namespace winrt::Windows::Xbox::Input::implementation
struct Gamepad : GamepadT<Gamepad>
{
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<winrt::Windows::Xbox::Input::IGamepad> Gamepads();
static winrt::event_token GamepadAdded(winrt::Windows::Foundation::EventHandler<winrt::Windows::Xbox::Input::GamepadAddedEventArgs> 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<WORD, GamepadButtons> 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},
};
};
+44 -11
View File
@@ -1,5 +1,7 @@
#include "pch.h"
#include "WinDurangoConfig.h"
#include <winrt/Windows.Storage.h>
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<std::codecvt_utf8_utf16<wchar_t>> 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<std::string_view>();
const auto gamerscore_opt = tbl["WinDurango"]["Gamerscore"].value<int>();
const auto reputation_opt = tbl["WinDurango"]["Reputation"].value<int>();
const auto agegroup_opt = tbl["WinDurango"]["AgeGroup"].value<std::string_view>();
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<std::string_view>();
auto gamerscore_opt = tbl["WinDurango"]["Gamerscore"].value<int>();
auto reputation_opt = tbl["WinDurango"]["Reputation"].value<int>();
auto agegroup_opt = tbl["WinDurango"]["AgeGroup"].value<std::string_view>();
auto game_opt = tbl["WinDurango"]["Game"].value<std::string_view>();
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
};
}
}
+10 -2
View File
@@ -1,6 +1,8 @@
#pragma once
#include "toml.hpp"
#include <locale>
#include <codecvt>
#include <filesystem>
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{};