Skip to content

Commit

Permalink
Merge pull request #3 from XeTrinityz/Improvements
Browse files Browse the repository at this point in the history
Improvements
  • Loading branch information
TheSR007 authored Jul 8, 2024
2 parents 3bcb162 + 2ba99f0 commit 2cae22d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 20 deletions.
19 changes: 9 additions & 10 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
#include <xlocale>
#include "include/api.h"


#include "include/layer.h"
#include "include/menu.hpp"
#include "include/mod_loader.h"
Expand Down Expand Up @@ -82,6 +81,7 @@ void InitConsole(){
freopen_s(&inputStream, "CONIN$", "r", stdin);
}


void loadWrapper(){
dllHandle = LoadLibrary("C:\\Windows\\System32\\powrprof.dll");
if (dllHandle == NULL) {
Expand All @@ -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) {
Expand All @@ -125,7 +126,6 @@ static LRESULT WINAPI WndProc(const HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM
}



void terminateCrashpadHandler() {

PROCESSENTRY32 entry;
Expand Down Expand Up @@ -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;
Expand All @@ -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){
Expand All @@ -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;
}
Expand All @@ -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<WNDPROC>(SetWindowLongPtr(window, GWLP_WNDPROC, reinterpret_cast<LONG_PTR>(WndProc)));
InitConsole();
Sleep(3000);
clear_screen();
//clear_screen();
return EXIT_SUCCESS;
}

Expand Down Expand Up @@ -299,4 +298,4 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved){

return TRUE;

}
}
15 changes: 8 additions & 7 deletions src/menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ namespace Menu {
file.close();
}


void LoadFontsFromFolder(FontConfig& fontconfig) {
static const ImWchar ranges[] = {
static_cast<ImWchar>(fontconfig.unicodeRangeStart), static_cast<ImWchar>(fontconfig.unicodeRangeEnd), // Dynamic Unicode range from sml_config.json
Expand Down Expand Up @@ -79,6 +80,7 @@ namespace Menu {
}
}


void ShowFontSelector(){
ImGuiIO& io = ImGui::GetIO();
ImFont* font_current = ImGui::GetFont();
Expand All @@ -95,6 +97,7 @@ namespace Menu {
}
}


void InitializeContext(HWND hwnd) {
if (ig::GetCurrentContext( ))
return;
Expand All @@ -109,6 +112,7 @@ namespace Menu {
io.IniFilename = io.LogFilename = nullptr;
}


void HelpMarker(const char* description){
ImGui::TextDisabled("(?)");
if (ImGui::IsItemHovered())
Expand All @@ -121,6 +125,7 @@ namespace Menu {
}
}


void SMLMainMenu() {
char buf[64];
ig::SetNextWindowSize({200, 0}, ImGuiCond_Once);
Expand Down Expand Up @@ -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;
Expand All @@ -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();
}
}
}
5 changes: 2 additions & 3 deletions src/mod_loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down Expand Up @@ -56,7 +56,6 @@ size_t ModLoader::GetModCount() {
return mods.size();
}


const ModInfo& ModLoader::GetModInfo(int index) {
return mods[index].info;
}
Expand Down Expand Up @@ -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";
Expand Down

0 comments on commit 2cae22d

Please sign in to comment.