From 45fd0de376f9390acaf93a10224172efe9e8b412 Mon Sep 17 00:00:00 2001 From: Delta <46466697+DeltaGW2@users.noreply.github.com> Date: Thu, 16 Nov 2023 15:21:09 +0100 Subject: [PATCH 1/2] loader fixes --- src/GUI/Widgets/Addons/AddonItem.cpp | 19 ++++++++++++------- src/GUI/Widgets/Debug/DebugWindow.cpp | 17 ++++++++++++----- src/Loader/Loader.cpp | 4 ++-- src/core.cpp | 2 +- 4 files changed, 27 insertions(+), 15 deletions(-) diff --git a/src/GUI/Widgets/Addons/AddonItem.cpp b/src/GUI/Widgets/Addons/AddonItem.cpp index 12c21be..6242fa9 100644 --- a/src/GUI/Widgets/Addons/AddonItem.cpp +++ b/src/GUI/Widgets/Addons/AddonItem.cpp @@ -5,7 +5,8 @@ namespace GUI void AddonItem(Addon* aAddon) { if (aAddon->State == EAddonState::NotLoadedDuplicate || - aAddon->State == EAddonState::Incompatible) + aAddon->State == EAddonState::Incompatible || + aAddon->Definitions == nullptr) { return; } @@ -34,7 +35,8 @@ namespace GUI ImGui::SetCursorPosX(ImGui::GetCursorPosX() + ImGui::GetColumnWidth() - 120.0f); { ImGui::BeginGroup(); - if (aAddon->State == EAddonState::Loaded) + if (aAddon->State == EAddonState::Loaded && + !(aAddon->Definitions->Unload == nullptr || aAddon->Definitions->HasFlag(EAddonFlags::DisableHotloading))) { if (ImGui::Button(("Disable##" + sig).c_str(), ImVec2(120.0f, 24.0f))) { @@ -62,14 +64,17 @@ namespace GUI } } } - if (ImGui::Button(("Uninstall##" + sig).c_str(), ImVec2(120.0f, 24.0f))) + if (!(aAddon->Definitions->Unload == nullptr || aAddon->Definitions->HasFlag(EAddonFlags::DisableHotloading))) { - for (auto& it : Loader::Addons) + if (ImGui::Button(("Uninstall##" + sig).c_str(), ImVec2(120.0f, 24.0f))) { - if (it.second->Definitions == aAddon->Definitions) + for (auto& it : Loader::Addons) { - LogDebug(CH_GUI, "Uninstall called: %s", it.second->Definitions->Name); - Loader::QueueAddon(ELoaderAction::Uninstall, it.first); + if (it.second->Definitions == aAddon->Definitions) + { + LogDebug(CH_GUI, "Uninstall called: %s", it.second->Definitions->Name); + Loader::QueueAddon(ELoaderAction::Uninstall, it.first); + } } } } diff --git a/src/GUI/Widgets/Debug/DebugWindow.cpp b/src/GUI/Widgets/Debug/DebugWindow.cpp index 60220b6..83836b1 100644 --- a/src/GUI/Widgets/Debug/DebugWindow.cpp +++ b/src/GUI/Widgets/Debug/DebugWindow.cpp @@ -249,12 +249,12 @@ namespace GUI std::string state = "State: "; switch (addon->State) { - case EAddonState::None: state.append("None"); break; - case EAddonState::Loaded: state.append("Loaded"); break; - case EAddonState::NotLoaded: state.append("NotLoaded"); break; + case EAddonState::None: state.append("None"); break; + case EAddonState::Loaded: state.append("Loaded"); break; + case EAddonState::NotLoaded: state.append("NotLoaded"); break; case EAddonState::NotLoadedDuplicate: state.append("NotLoadedDuplicate"); break; - case EAddonState::Incompatible: state.append("Incompatible"); break; - case EAddonState::IncompatibleAPI: state.append("IncompatibleAPI"); break; + case EAddonState::Incompatible: state.append("Incompatible"); break; + case EAddonState::IncompatibleAPI: state.append("IncompatibleAPI"); break; } ImGui::TextDisabled(state.c_str()); @@ -262,6 +262,13 @@ namespace GUI ImGui::TextDisabled("Module Size: %u", addon->ModuleSize); ImGui::TextDisabled("AddonDefs: %p", addon->Definitions); + if (ImGui::SmallButton("Memory Editor")) + { + memEditor.Open = true; + memPtr = addon->Definitions; + memSz = sizeof(AddonDefinition); + } + ImGui::TreePop(); } } diff --git a/src/Loader/Loader.cpp b/src/Loader/Loader.cpp index e35a191..65f6ceb 100644 --- a/src/Loader/Loader.cpp +++ b/src/Loader/Loader.cpp @@ -150,7 +150,7 @@ namespace Loader /* doesn't full fill min reqs */ if (hMod && !defs->HasMinimumRequirements()) { - LogWarning(CH_LOADER, "\"%s\" does not fulfill minimum requirements. At least define Name, Version, Author, Description as well as Load and Unload functions. Incompatible.", path); + LogWarning(CH_LOADER, "\"%s\" does not fulfill minimum requirements. At least define Name, Version, Author, Description as well as the Load function. Incompatible.", path); addon->State = EAddonState::Incompatible; FreeLibrary(hMod); return; @@ -162,7 +162,7 @@ namespace Loader // if defs defined && not the same path && signature the same though if (it.second->Definitions != nullptr && it.first != aPath && it.second->Definitions->Signature == defs->Signature) { - LogWarning(CH_LOADER, "\"%s\" or another addon with sig%d is already loaded. Added to blacklist.", path, defs->Signature); + LogWarning(CH_LOADER, "\"%s\" or another addon with this signature (%d) is already loaded. Added to blacklist.", path, defs->Signature); addon->State = EAddonState::NotLoadedDuplicate; FreeLibrary(hMod); return; diff --git a/src/core.cpp b/src/core.cpp index d13b9ad..74b07d5 100644 --- a/src/core.cpp +++ b/src/core.cpp @@ -25,7 +25,7 @@ bool FindFunction(HMODULE aModule, LPVOID aFunction, LPCSTR aName) { FARPROC* fp = (FARPROC*)aFunction; *fp = aModule ? GetProcAddress(aModule, aName) : 0; - return (fp != 0); + return (*fp != 0); } std::string WStrToStr(std::wstring& aWstring) From 9b013f864d0b08e05f24a44dddcb312eed5156a5 Mon Sep 17 00:00:00 2001 From: Delta <46466697+DeltaGW2@users.noreply.github.com> Date: Fri, 17 Nov 2023 00:43:57 +0100 Subject: [PATCH 2/2] fix nullptr, remove addon minreqs unload --- src/GUI/Widgets/Debug/DebugWindow.cpp | 11 +++++++---- src/Loader/AddonDefinition.cpp | 3 +-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/GUI/Widgets/Debug/DebugWindow.cpp b/src/GUI/Widgets/Debug/DebugWindow.cpp index 83836b1..680b435 100644 --- a/src/GUI/Widgets/Debug/DebugWindow.cpp +++ b/src/GUI/Widgets/Debug/DebugWindow.cpp @@ -262,11 +262,14 @@ namespace GUI ImGui::TextDisabled("Module Size: %u", addon->ModuleSize); ImGui::TextDisabled("AddonDefs: %p", addon->Definitions); - if (ImGui::SmallButton("Memory Editor")) + if (addon->Definitions != nullptr) { - memEditor.Open = true; - memPtr = addon->Definitions; - memSz = sizeof(AddonDefinition); + if (ImGui::SmallButton("Memory Editor")) + { + memEditor.Open = true; + memPtr = addon->Definitions; + memSz = sizeof(AddonDefinition); + } } ImGui::TreePop(); diff --git a/src/Loader/AddonDefinition.cpp b/src/Loader/AddonDefinition.cpp index 0c992ef..f9632a2 100644 --- a/src/Loader/AddonDefinition.cpp +++ b/src/Loader/AddonDefinition.cpp @@ -31,8 +31,7 @@ bool AddonDefinition::HasMinimumRequirements() Name && Author && Description && - Load && - (HasFlag(EAddonFlags::DisableHotloading) || Unload)) + Load) { return true; }