From e4d699ad9937d97267af6605ca5471a7e914a524 Mon Sep 17 00:00:00 2001 From: arol Date: Wed, 16 Oct 2024 20:36:40 -0600 Subject: [PATCH] Changes to UI, Internal updates, extra --- src/main.cpp | 26 ++++++++++++--- src/menu.cpp | 90 +++++++++++++++++++++++++++++++--------------------- 2 files changed, 76 insertions(+), 40 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index c940753..72fd7e7 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -135,8 +135,8 @@ void InitConsole(){ fflush(stderr); } - -void loadWrapper(){ +// Integrated into onAttach() +/*void loadWrapper() { dllHandle = LoadLibrary("C:\\Windows\\System32\\powrprof.dll"); if (dllHandle == NULL) @@ -154,7 +154,7 @@ void loadWrapper(){ } } else print("failed to load POWRPROF.dll"); -} +}*/ static WNDPROC oWndProc; @@ -294,7 +294,23 @@ DWORD WINAPI hook_thread(PVOID lParam) { } void onAttach() { - loadWrapper(); + //loadWrapper(); - Integrated into onAttach() + dllHandle = LoadLibrary("C:\\Windows\\System32\\powrprof.dll"); + + if (dllHandle == NULL) dllHandle = LoadLibrary("C:\\Windows\\System32\\POWRPROF.dll"); + print("Loading powrprof.dll symbols..."); + + if (dllHandle != NULL) { + o_GetPwrCapabilities = (BOOLEAN(*)(PSYSTEM_POWER_CAPABILITIES))GetProcAddress(dllHandle, "GetPwrCapabilities"); + o_CallNtPowerInformation = (NTSTATUS(*)(POWER_INFORMATION_LEVEL, PVOID, ULONG, PVOID, ULONG))GetProcAddress(dllHandle, "CallNtPowerInformation"); + o_PowerDeterminePlatformRole = (POWER_PLATFORM_ROLE(*)())GetProcAddress(dllHandle, "PowerDeterminePlatformRole"); + + if (o_GetPwrCapabilities == nullptr || o_CallNtPowerInformation == nullptr || o_PowerDeterminePlatformRole == nullptr) { + print("Could not locate symbols in powrprof.dll"); + } + } + else print("failed to load POWRPROF.dll"); + InitConsole(); std::remove("SML.log"); InitLogger(); @@ -307,6 +323,8 @@ void onAttach() { HMODULE handle = LoadLibrary("advapi32.dll"); if (handle != NULL) { lm_address_t fnRegEnumValue = (lm_address_t)GetProcAddress(handle, "RegEnumValueA"); + if (fnRegEnumValue == NULL) { std::cerr << "fnRegEnumValue address is null, possible corrupted file" << std::endl; return; } // this usually never happens, but still check just in case + if (LM_HookCode(fnRegEnumValue, (lm_address_t)&hkRegEnumValueA, (lm_address_t*)&oRegEnumValueA)) { terminateCrashpadHandler(); ModApi::Instance().InitSkyBase(); diff --git a/src/menu.cpp b/src/menu.cpp index 50b2375..b5c814b 100644 --- a/src/menu.cpp +++ b/src/menu.cpp @@ -63,14 +63,15 @@ namespace Menu { throw std::runtime_error("File does not have enough lines: " + filepath); } } - } catch (const std::exception& e) { + } + catch (const std::exception& e) { std::cerr << "Error reading default server URL: " << e.what() << std::endl; } return line; } void ShowServerUrlSelector(const std::vector& names, const std::vector& urls, std::string& selectedurl) { - if (ImGui::BeginCombo("Servers", selectedurl.c_str())) { + if (ImGui::BeginCombo("Server", selectedurl.c_str())) { for (size_t i = 0; i < names.size(); ++i) { bool isSelected = (urls[i] == selectedurl); if (ImGui::Selectable(names[i].c_str(), isSelected)) { @@ -219,7 +220,7 @@ namespace Menu { style->WindowBorderSize = 1; style->ChildBorderSize = 1; style->PopupBorderSize = 1; - style->FrameBorderSize = 0; // ?? + style->FrameBorderSize = 0; style->TabBorderSize = 1; style->TabBarBorderSize = 1; style->WindowRounding = 6; @@ -338,58 +339,75 @@ namespace Menu { HelpMarker(ModLoader::toString(i).c_str()); } ig::EndTable(); - ImGui::SeparatorText("Settings"); + ig::SeparatorText("Settings"); + + ShowFontSelector(); + ig::SameLine(); + HelpMarker(std::format("Total: {}\nPath: {}\nStart Range: {}\nEnd Range: {}\nSize: {}W / {}H\nConfig: sml_config.json", io.Fonts->Fonts.Size, fontconfig.fontPath.c_str(), fontconfig.unicodeRangeStart, fontconfig.unicodeRangeEnd, io.Fonts->TexWidth, io.Fonts->TexHeight).c_str()); + + const float MIN_SCALE = 0.3f; + const float MAX_SCALE = 3.0f; + static float window_scale = 1.0f; + if (ig::DragFloat("Window Scale", &window_scale, 0.005f, MIN_SCALE, MAX_SCALE, "%.2f", ImGuiSliderFlags_AlwaysClamp)) + ig::SetWindowFontScale(window_scale); + ig::DragFloat("Global Scale", &io.FontGlobalScale, 0.005f, MIN_SCALE, MAX_SCALE, "%.2f", ImGuiSliderFlags_AlwaysClamp); + + ig::Spacing(); + + ig::PushStyleVar(ImGuiStyleVar_SeparatorTextBorderSize, 1.f); + ig::SeparatorText("Custom Server"); + ig::PopStyleVar(); if (!Server_Urls_Initialized) { ReadServerUrls("sml_config.json", Server_Names, Server_Urls); Selected_Url = ReadDefaultServerUrl("data/AppInfo.tgc"); Server_Urls_Initialized = true; } - ShowServerUrlSelector(Server_Names, Server_Urls, Selected_Url); - ImGui::SameLine(); + ig::SameLine(); static bool Save_Server_URL = false; - if (ImGui::Button("Save")) { + if (ig::Button("Save")) { Save_Server_URL = true; - ImGui::OpenPopup("Confirmation"); - } + ig::OpenPopup("Confirmation"); + } if (Save_Server_URL) { - ImGui::SetNextWindowSize(ImVec2(365, 100)); - if (ImGui::BeginPopupModal("Confirmation", NULL, ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove)) { - ImGui::Text("Are you sure you want to save Server Url(requires Restart)?"); - ImGui::Spacing(); + ig::SetNextWindowSize(ImVec2(365, 120)); + if (ig::BeginPopupModal("Confirmation", NULL, ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove)) { + ig::TextWrapped("Are you sure you want to connect to this server? Your game will close to save changes."); + ig::Spacing(); - if (ImGui::Button("Yes", ImVec2(120, 30))) { + if (ig::Button("Yes", ImVec2(120, 30))) { SaveSelectedServerUrl("data/AppInfo.tgc", Selected_Url); exit(0); - ImGui::CloseCurrentPopup(); + ig::CloseCurrentPopup(); } - ImGui::SameLine(); - if (ImGui::Button("No", ImVec2(120, 30))) { - ImGui::CloseCurrentPopup(); + ig::SameLine(); + if (ig::Button("No", ImVec2(120, 30))) { + ig::CloseCurrentPopup(); } - ImGui::EndPopup(); + ig::EndPopup(); } - } - - ShowFontSelector(); - ImGui::SameLine(); - HelpMarker(std::format("Total: {}\nPath: {}\nStart Range: {}\nEnd Range: {}\nSize: {}W / {}H\nConfig: sml_config.json", io.Fonts->Fonts.Size, fontconfig.fontPath.c_str(), fontconfig.unicodeRangeStart, fontconfig.unicodeRangeEnd, io.Fonts->TexWidth, io.Fonts->TexHeight).c_str()); - - const float MIN_SCALE = 0.3f; - const float MAX_SCALE = 3.0f; - static float window_scale = 1.0f; - if (ImGui::DragFloat("Window Scale", &window_scale, 0.005f, MIN_SCALE, MAX_SCALE, "%.2f", ImGuiSliderFlags_AlwaysClamp)) - ImGui::SetWindowFontScale(window_scale); - ImGui::DragFloat("Global Scale", &io.FontGlobalScale, 0.005f, MIN_SCALE, MAX_SCALE, "%.2f", ImGuiSliderFlags_AlwaysClamp); - - ImGui::Spacing(); - ImGui::Separator(); - ImGui::Spacing(); + } - ImGui::Text("v0.1.3 | FPS: %.f | %.2f ms | DeltaTime: %.2f", io.Framerate, 1000.0f / io.Framerate, io.DeltaTime); + ig::Spacing(); + ig::Separator(); + ig::Spacing(); + + ig::Text("v0.1.4 | FPS: %.f | %.2f ms | DeltaTime: %.2f", io.Framerate, 1000.0f / io.Framerate, io.DeltaTime); + ig::SameLine(330); + if (ig::SmallButton("Credits")) { + std::cout << +R"text( +------------------------------------------------------------ + | SML Loader / Sky Mod Loader | + Developed by lukas0x1, TheSR, XeTrinityz, and yunkunsky! + +> Thank you for using SML Loader! [Build v0.1.4] +------------------------------------------------------------ +)text"; + } } ig::End(); }