Skip to content

Commit

Permalink
Changes to UI, Internal updates, extra
Browse files Browse the repository at this point in the history
  • Loading branch information
fishnet-technologies committed Oct 17, 2024
1 parent 01d042d commit e4d699a
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 40 deletions.
26 changes: 22 additions & 4 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -154,7 +154,7 @@ void loadWrapper(){
}
}
else print("failed to load POWRPROF.dll");
}
}*/


static WNDPROC oWndProc;
Expand Down Expand Up @@ -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();
Expand All @@ -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();
Expand Down
90 changes: 54 additions & 36 deletions src/menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string>& names, const std::vector<std::string>& 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)) {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}
Expand Down

0 comments on commit e4d699a

Please sign in to comment.