diff --git a/src/main.cpp b/src/main.cpp index 4696b6c..94dbde1 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -14,7 +14,6 @@ #include #include "include/api.h" - #include "include/layer.h" #include "include/menu.hpp" #include "include/mod_loader.h" @@ -82,6 +81,7 @@ void InitConsole(){ freopen_s(&inputStream, "CONIN$", "r", stdin); } + void loadWrapper(){ dllHandle = LoadLibrary("C:\\Windows\\System32\\powrprof.dll"); if (dllHandle == NULL) { @@ -102,6 +102,7 @@ void loadWrapper(){ } } + static WNDPROC oWndProc; static LRESULT WINAPI WndProc(const HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { if (uMsg == WM_KEYDOWN) { @@ -125,7 +126,6 @@ static LRESULT WINAPI WndProc(const HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM } - void terminateCrashpadHandler() { PROCESSENTRY32 entry; @@ -202,8 +202,6 @@ std::wstring GetKeyPathFromKKEY(HKEY key) #undef STATUS_BUFFER_TOO_SMALL #undef STATUS_SUCCESS - - void clear_screen(char fill = ' ') { COORD tl = {0,0}; CONSOLE_SCREEN_BUFFER_INFO s; @@ -215,6 +213,7 @@ void clear_screen(char fill = ' ') { SetConsoleCursorPosition(console, tl); } + typedef LSTATUS (__stdcall *PFN_RegEnumValueA)(HKEY hKey, DWORD dwIndex, LPSTR lpValueName, LPDWORD lpcchValueName, LPDWORD lpReserved, LPDWORD lpType, LPBYTE lpData, LPDWORD lpcbData); PFN_RegEnumValueA oRegEnumValueA; LSTATUS hkRegEnumValueA(HKEY hKey, DWORD dwIndex, LPSTR lpValueName, LPDWORD lpcchValueName, LPDWORD lpReserved, LPDWORD lpType, LPBYTE lpData, LPDWORD lpcbData){ @@ -230,7 +229,7 @@ LSTATUS hkRegEnumValueA(HKEY hKey, DWORD dwIndex, LPSTR lpValueName, LPDWORD lpc } lpValueName[name.size()] = '\0'; - *lpcchValueName = 2048; //max path + *lpcchValueName = 2048; // Max Path Length lpData = nullptr; *lpcbData = 4; } @@ -240,17 +239,17 @@ LSTATUS hkRegEnumValueA(HKEY hKey, DWORD dwIndex, LPSTR lpValueName, LPDWORD lpc DWORD WINAPI hook_thread(PVOID lParam){ HWND window = nullptr; - printf("Searching for window \n"); + printf("Searching for window...\n"); while(!window){ - std::this_thread::sleep_for(std::chrono::milliseconds(100)); //prone for a race condition (1 second crashes); + std::this_thread::sleep_for(std::chrono::milliseconds(100)); window = FindWindowA("TgcMainWindow", "Sky"); } - printf("found window: %p\n", window); + printf("Window Found: %p\n", window); layer::setup(window); oWndProc = reinterpret_cast(SetWindowLongPtr(window, GWLP_WNDPROC, reinterpret_cast(WndProc))); InitConsole(); Sleep(3000); - clear_screen(); + //clear_screen(); return EXIT_SUCCESS; } @@ -299,4 +298,4 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved){ return TRUE; -} +} \ No newline at end of file diff --git a/src/menu.cpp b/src/menu.cpp index d8459d4..a47eaff 100644 --- a/src/menu.cpp +++ b/src/menu.cpp @@ -47,6 +47,7 @@ namespace Menu { file.close(); } + void LoadFontsFromFolder(FontConfig& fontconfig) { static const ImWchar ranges[] = { static_cast(fontconfig.unicodeRangeStart), static_cast(fontconfig.unicodeRangeEnd), // Dynamic Unicode range from sml_config.json @@ -79,6 +80,7 @@ namespace Menu { } } + void ShowFontSelector(){ ImGuiIO& io = ImGui::GetIO(); ImFont* font_current = ImGui::GetFont(); @@ -95,6 +97,7 @@ namespace Menu { } } + void InitializeContext(HWND hwnd) { if (ig::GetCurrentContext( )) return; @@ -109,6 +112,7 @@ namespace Menu { io.IniFilename = io.LogFilename = nullptr; } + void HelpMarker(const char* description){ ImGui::TextDisabled("(?)"); if (ImGui::IsItemHovered()) @@ -121,6 +125,7 @@ namespace Menu { } } + void SMLMainMenu() { char buf[64]; ig::SetNextWindowSize({200, 0}, ImGuiCond_Once); @@ -148,7 +153,7 @@ namespace Menu { ImGuiIO& io = ImGui::GetIO(); ShowFontSelector(); ImGui::SameLine(); - HelpMarker(std::format("Total: {}\nPath: {}\nStart Range: {}\nEnd Range: {}\nSize: {}W / {}H\nchange sml_config.json as needed", io.Fonts->Fonts.Size, fontconfig.fontPath.c_str(), fontconfig.unicodeRangeStart, fontconfig.unicodeRangeEnd, io.Fonts->TexWidth, io.Fonts->TexHeight).c_str()); + 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; @@ -161,20 +166,16 @@ namespace Menu { ImGui::Separator(); ImGui::Spacing(); - ImGui::Text("Total Mods: %llu", ModLoader::GetModCount()); - ImGui::SameLine(); - ImGui::Text("|"); - ImGui::SameLine(); - ImGui::Text("Total Fonts: %d", io.Fonts->Fonts.Size); ImGui::Text("FPS: %.1f | %.3f ms/frame", io.Framerate, 1000.0f / io.Framerate); } ig::End(); } + void Render( ) { if (!bShowMenu) return; SMLMainMenu(); ModLoader::RenderAll(); } -} +} \ No newline at end of file diff --git a/src/mod_loader.cpp b/src/mod_loader.cpp index 1367e09..0da8653 100644 --- a/src/mod_loader.cpp +++ b/src/mod_loader.cpp @@ -21,7 +21,7 @@ void ModLoader::LoadMods() { DWORD ftyp = GetFileAttributesA(directory.c_str()); if(ftyp == INVALID_FILE_ATTRIBUTES){ - printf("Creating mods directory\n"); + printf("Creating mods directory...\n"); CreateDirectoryA((LPCSTR)directory.c_str(), NULL); } for (const auto& entry : std::filesystem::directory_iterator(directory)) { @@ -56,7 +56,6 @@ size_t ModLoader::GetModCount() { return mods.size(); } - const ModInfo& ModLoader::GetModInfo(int index) { return mods[index].info; } @@ -92,7 +91,7 @@ void ModLoader::RenderAll() { std::string ModLoader::toString(int index) { std::stringstream ss; - ss << "Mod Info " << "\n"; + ss << "Mod Information" << "\n"; ss << "Name: " << mods[index].info.name << "\n"; ss << "Version: " << mods[index].info.version << "\n"; ss << "Author: " << mods[index].info.author << "\n";