diff --git a/src/API/APIClient.cpp b/src/API/APIClient.cpp index 6b10c01..e20031f 100644 --- a/src/API/APIClient.cpp +++ b/src/API/APIClient.cpp @@ -22,7 +22,7 @@ APIClient::APIClient(std::string aBaseURL, bool aEnableSSL, std::filesystem::pat RefillAmount = aRefillAmount; RefillInterval = aRefillInterval; - LogDebug("APIClient", "APIClient(BaseURL: %s, EnableSSL: %s, CacheDirectory: %s, CacheLifetime: %d, BucketCapacity: %d, RefillAmount: %d, RefillInterval: %d)", + LogDebug(("APIClient::" + BaseURL).c_str(), "APIClient(BaseURL: %s, EnableSSL: %s, CacheDirectory: %s, CacheLifetime: %d, BucketCapacity: %d, RefillAmount: %d, RefillInterval: %d)", BaseURL.c_str(), aEnableSSL ? "true" : "false", CacheDirectory.string().c_str(), @@ -52,7 +52,7 @@ APIClient::~APIClient() delete Client; - LogDebug("APIClient", "~APIClient(%s)", BaseURL.c_str()); + LogDebug(("APIClient::" + BaseURL).c_str(), "~APIClient(%s)", BaseURL.c_str()); } json APIClient::Get(std::string aEndpoint, std::string aParameters) @@ -64,12 +64,17 @@ json APIClient::Get(std::string aEndpoint, std::string aParameters) if (cachedResponse != nullptr) { long long diff = Timestamp() - cachedResponse->Timestamp; - Log("APIClient", "diff: %d | curr: %d | cache: %d", diff, Timestamp(), cachedResponse->Timestamp); + Log(("APIClient::" + BaseURL).c_str(), "diff: %d | curr: %d | cache: %d", diff, Timestamp(), cachedResponse->Timestamp); if (diff < CacheLifetime && cachedResponse->Content != nullptr) { + LogDebug(("APIClient::" + BaseURL).c_str(), "Cached message %d seconds old. Reading from cache.", diff); return cachedResponse->Content; } + else + { + LogDebug(("APIClient::" + BaseURL).c_str(), "Cached message %d seconds old. CacheLifetime %d. Queueing request.", diff, CacheLifetime); + } } // Variables for synchronization @@ -119,7 +124,7 @@ void APIClient::Download(std::filesystem::path aOutPath, std::string aEndpoint, if (!downloadResult || downloadResult->status != 200 || bytesWritten == 0) { - LogWarning("APIClient", "Error fetching %s", query.c_str()); + LogWarning(("APIClient::" + BaseURL).c_str(), "Error fetching %s", query.c_str()); return; } } @@ -153,7 +158,7 @@ CachedResponse* APIClient::GetCachedResponse(const std::string& aQuery) } catch (json::parse_error& ex) { - Log("APIClient", "%s could not be parsed. Error: %s", path.string().c_str(), ex.what()); + Log(("APIClient::" + BaseURL).c_str(), "%s could not be parsed. Error: %s", path.string().c_str(), ex.what()); } } @@ -300,7 +305,7 @@ void APIClient::ProcessRequests() std::error_code err; if (!CreateDirectoryRecursive(normalizedPath.parent_path().string(), err)) { - LogWarning("APIClient", "CreateDirectoryRecursive FAILED, err: % s", err.message()); + LogWarning(("APIClient::" + BaseURL).c_str(), "CreateDirectoryRecursive FAILED, err: % s", err.message()); } std::ofstream file(normalizedPath); @@ -343,14 +348,14 @@ APIResponse APIClient::DoHttpReq(APIRequest aRequest) if (!result) { - LogWarning("APIClient", "Error fetching %s", aRequest.Query.c_str()); + LogWarning(("APIClient::" + BaseURL).c_str(), "Error fetching %s", aRequest.Query.c_str()); response.Status = 1; return response; } if (result->status != 200) // not HTTP_OK { - LogWarning("APIClient", "Status %d when fetching %s", result->status, aRequest.Query.c_str()); + LogWarning(("APIClient::" + BaseURL).c_str(), "Status %d when fetching %s", result->status, aRequest.Query.c_str()); response.Status = result->status; return response; } @@ -363,13 +368,13 @@ APIResponse APIClient::DoHttpReq(APIRequest aRequest) } catch (json::parse_error& ex) { - LogWarning("APIClient", "Response from %s could not be parsed. Error: %s", aRequest.Query.c_str(), ex.what()); + LogWarning(("APIClient::" + BaseURL).c_str(), "Response from %s could not be parsed. Error: %s", aRequest.Query.c_str(), ex.what()); return response; } if (jsonResult.is_null()) { - LogWarning("APIClient", "Error parsing API response from %s.", aRequest.Query.c_str()); + LogWarning(("APIClient::" + BaseURL).c_str(), "Error parsing API response from %s.", aRequest.Query.c_str()); return response; } diff --git a/src/GUI/Widgets/Addons/AddonsWindow.cpp b/src/GUI/Widgets/Addons/AddonsWindow.cpp index e1b9b31..bcfc2a0 100644 --- a/src/GUI/Widgets/Addons/AddonsWindow.cpp +++ b/src/GUI/Widgets/Addons/AddonsWindow.cpp @@ -77,6 +77,8 @@ namespace GUI ImGui::PushStyleVar(ImGuiStyleVar_ButtonTextAlign, ImVec2(0.5f, 0.5f)); ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 0); ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, 0); + ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(1, 1, 1, 1)); + ImGui::PushStyleColor(ImGuiCol_ChildBg, ImVec4(0, 0, 0, 0)); ImGui::SetNextWindowSize(ImVec2(windowWidth * Renderer::Scaling, windowHeight * Renderer::Scaling)); if (ImGui::Begin(Name.c_str(), &Visible, ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoBackground | ImGuiWindowFlags_NoTitleBar | @@ -249,6 +251,7 @@ namespace GUI } ImGui::End(); + ImGui::PopStyleColor(2); ImGui::PopStyleVar(6); ImGui::PopFont(); } diff --git a/src/GUI/Widgets/Menu/Menu.cpp b/src/GUI/Widgets/Menu/Menu.cpp index 442b2ea..b128eb0 100644 --- a/src/GUI/Widgets/Menu/Menu.cpp +++ b/src/GUI/Widgets/Menu/Menu.cpp @@ -74,58 +74,12 @@ namespace GUI void AddMenuItem(std::string aLabel, std::string aTextureIdentifier, bool* aToggle) { Texture* icon = TextureLoader::Get(aTextureIdentifier.c_str()); - MenuItem* mItem = new MenuItem{ aLabel, aToggle, icon, false }; + MenuItem* mItem = new MenuItem{ aLabel, aTextureIdentifier, aToggle, icon, false }; { const std::lock_guard lock(Menu::Mutex); MenuItems.push_back(mItem); } - - if (icon == nullptr) - { - std::thread([mItem, aLabel, aTextureIdentifier, aToggle]() - { - const std::lock_guard lock(Menu::Mutex); - { - // This code is copy pasted from quick access, bit of a clownfiesta not gonna lie - int tries = 0; - - LogDebug("CH_MENU", "Menu Item \"%s\" was promised 1 textures, but received 0.", aLabel.c_str()); - Sleep(100); // first retry after 100ms - - while (mItem->Icon == nullptr) - { - if (tries > 10) - { - LogWarning("CH_MENU", "Cancelled getting textures for menu item \"%s\" after 10 failed attempts.", aLabel.c_str()); - break; - } - - if (mItem->Icon == nullptr) { mItem->Icon = TextureLoader::Get(aTextureIdentifier.c_str()); } - - tries++; - Sleep(tries * 500); - } - - /* if not all tries were used, then the texture was loaded */ - if (tries <= 10) - { - LogDebug("CH_MENU", "Menu Item \"%s\" received promised texture after %d attempt(s).", aLabel.c_str(), tries); - return; - } - - /* fallback icons */ - mItem->Icon = TextureLoader::Get(ICON_GENERIC); - - /* absolute sanity check */ - if (mItem->Icon == nullptr) - { - LogWarning("CH_MENU", "Neither promised textures nor fallback textures could be loaded, removing menu item \"%s\".", aLabel.c_str()); - return; - } - } - }).detach(); - } } void ReceiveTextures(const char* aIdentifier, Texture* aTexture) diff --git a/src/GUI/Widgets/Menu/MenuItem.cpp b/src/GUI/Widgets/Menu/MenuItem.cpp index 0f27611..682cf5a 100644 --- a/src/GUI/Widgets/Menu/MenuItem.cpp +++ b/src/GUI/Widgets/Menu/MenuItem.cpp @@ -3,6 +3,7 @@ #include "Renderer.h" #include "Menu.h" +#include "Textures/TextureLoader.h" #include "Textures/Texture.h" #include "imgui.h" @@ -60,6 +61,10 @@ namespace GUI ImGui::Image(Icon->Resource, ImVec2(iconSize, iconSize)); ImGui::PopItemFlag(); } + else + { + Icon = TextureLoader::Get(TextureIdentifier.c_str()); + } ImGui::SetCursorPos(txtPos); ImGui::Text(Label.c_str()); diff --git a/src/GUI/Widgets/Menu/MenuItem.h b/src/GUI/Widgets/Menu/MenuItem.h index b3d6458..0c78673 100644 --- a/src/GUI/Widgets/Menu/MenuItem.h +++ b/src/GUI/Widgets/Menu/MenuItem.h @@ -11,6 +11,7 @@ namespace GUI struct MenuItem { std::string Label; + std::string TextureIdentifier; bool* Toggle; Texture* Icon; bool IsHovering; diff --git a/src/Hooks.cpp b/src/Hooks.cpp index 6b135c8..e2715a5 100644 --- a/src/Hooks.cpp +++ b/src/Hooks.cpp @@ -30,32 +30,35 @@ namespace Hooks LRESULT __stdcall WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { - // don't pass to game if loader - if (Loader::WndProc(hWnd, uMsg, wParam, lParam) == 0) { return 0; } + if (State::Nexus != ENexusState::SHUTDOWN) + { + // don't pass to game if loader + if (Loader::WndProc(hWnd, uMsg, wParam, lParam) == 0) { return 0; } - // don't pass to game if custom wndproc - if (WndProc::WndProc(hWnd, uMsg, wParam, lParam) == 0) { return 0; } + // don't pass to game if custom wndproc + if (WndProc::WndProc(hWnd, uMsg, wParam, lParam) == 0) { return 0; } - // don't pass to game if keybind - if (Keybinds::WndProc(hWnd, uMsg, wParam, lParam) == 0) { return 0; } + // don't pass to game if keybind + if (Keybinds::WndProc(hWnd, uMsg, wParam, lParam) == 0) { return 0; } - // don't pass to game if gui - if (GUI::WndProc(hWnd, uMsg, wParam, lParam) == 0) { return 0; } + // don't pass to game if gui + if (GUI::WndProc(hWnd, uMsg, wParam, lParam) == 0) { return 0; } - // don't pass keys to game if currently editing keybinds - if (Keybinds::IsSettingKeybind) - { - if (uMsg == WM_SYSKEYDOWN || uMsg == WM_KEYDOWN || uMsg == WM_SYSKEYUP || uMsg == WM_KEYUP) + // don't pass keys to game if currently editing keybinds + if (Keybinds::IsSettingKeybind) { - return 0; + if (uMsg == WM_SYSKEYDOWN || uMsg == WM_KEYDOWN || uMsg == WM_SYSKEYUP || uMsg == WM_KEYUP) + { + return 0; + } } - } - if (uMsg == WM_DESTROY || uMsg == WM_QUIT || uMsg == WM_CLOSE) - { - Main::Shutdown(uMsg); + if (uMsg == WM_DESTROY || uMsg == WM_QUIT || uMsg == WM_CLOSE) + { + Main::Shutdown(uMsg); + } } - + return CallWindowProcA(Hooks::GW2::WndProc, hWnd, uMsg, wParam, lParam); } HRESULT __stdcall DXGIPresent(IDXGISwapChain* pChain, UINT SyncInterval, UINT Flags) diff --git a/src/Keybinds/KeybindHandler.cpp b/src/Keybinds/KeybindHandler.cpp index 71c2974..fb09f17 100644 --- a/src/Keybinds/KeybindHandler.cpp +++ b/src/Keybinds/KeybindHandler.cpp @@ -76,6 +76,11 @@ namespace Keybinds kb.Key = 0; } + if (!kb.Alt && !kb.Ctrl && !kb.Shift && kb.Key == 0) + { + return uMsg; + } + if (keylp.PreviousKeyState) { return uMsg; diff --git a/src/Main.cpp b/src/Main.cpp index 452b2b8..e4a006e 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -134,7 +134,7 @@ namespace Main LogInfo(CH_CORE, "Shutdown performed."); - SetWindowLongPtr(Renderer::WindowHandle, GWLP_WNDPROC, (LONG_PTR)Hooks::GW2::WndProc); + //SetWindowLongPtr(Renderer::WindowHandle, GWLP_WNDPROC, (LONG_PTR)Hooks::GW2::WndProc); State::Nexus = ENexusState::SHUTDOWN; } diff --git a/src/Nexus.rc b/src/Nexus.rc index 75b17d6..6f6d24c 100644 --- a/src/Nexus.rc +++ b/src/Nexus.rc @@ -74,7 +74,7 @@ BEGIN VALUE "FileDescription", "Unofficial Guild Wars 2 Addon Host" VALUE "FileVersion", TOSTRING(V_MAJOR) "." TOSTRING(V_MINOR) "." TOSTRING(V_BUILD) "." TOSTRING(V_REVISION) VALUE "InternalName", "nexus.dll" - VALUE "LegalCopyright", "© 2023 Raidcore" + VALUE "LegalCopyright", "© 2023-2024 Raidcore" VALUE "ProductName", "Nexus" VALUE "ProductVersion", TOSTRING(V_MAJOR) "." TOSTRING(V_MINOR) "." TOSTRING(V_BUILD) "." TOSTRING(V_REVISION) END diff --git a/src/Textures/TextureLoader.cpp b/src/Textures/TextureLoader.cpp index 2bc62ac..94f6005 100644 --- a/src/Textures/TextureLoader.cpp +++ b/src/Textures/TextureLoader.cpp @@ -43,6 +43,8 @@ namespace TextureLoader void LoadFromFile(const char* aIdentifier, const char* aFilename, TEXTURES_RECEIVECALLBACK aCallback) { + LogInfo(CH_TEXTURES, "TextureLoader::LoadFromFile(aIdentifier: %s, aFilename: %s, aCallback: %p)", aIdentifier, aFilename, aCallback); + std::string str = aIdentifier; Texture* tex = Get(str.c_str()); @@ -70,6 +72,8 @@ namespace TextureLoader } void LoadFromResource(const char* aIdentifier, unsigned aResourceID, HMODULE aModule, TEXTURES_RECEIVECALLBACK aCallback) { + LogInfo(CH_TEXTURES, "TextureLoader::LoadFromResource(aIdentifier: %s, aResourceID: %u, aModule: %p, aCallback: %p)", aIdentifier, aResourceID, aModule, aCallback); + std::string str = aIdentifier; Texture* tex = Get(str.c_str()); @@ -119,6 +123,8 @@ namespace TextureLoader } void LoadFromURL(const char* aIdentifier, const char* aRemote, const char* aEndpoint, TEXTURES_RECEIVECALLBACK aCallback) { + LogInfo(CH_TEXTURES, "TextureLoader::LoadFromURL(aIdentifier: %s, aRemote: %s, aEndpoint: %s, aCallback: %p)", aIdentifier, aRemote, aEndpoint, aCallback); + std::string str = aIdentifier; Texture* tex = Get(str.c_str()); @@ -164,6 +170,8 @@ namespace TextureLoader } void LoadFromMemory(const char* aIdentifier, void* aData, size_t aSize, TEXTURES_RECEIVECALLBACK aCallback) { + LogInfo(CH_TEXTURES, "TextureLoader::LoadFromMemory(aIdentifier: %s, aData: %p, aSize: %u, aCallback: %p)", aIdentifier, aData, aSize, aCallback); + std::string str = aIdentifier; Texture* tex = Get(str.c_str()); @@ -199,7 +207,7 @@ namespace TextureLoader { std::string str = aIdentifier; - //LogDebug(CH_TEXTURES, "Queued %s", str.c_str()); + LogDebug(CH_TEXTURES, "Queued %s", str.c_str()); QueuedTexture raw{}; raw.Identifier = str; @@ -216,7 +224,7 @@ namespace TextureLoader } void CreateTexture(QueuedTexture aQueuedTexture) { - //LogDebug(CH_TEXTURES, "Create %s", aQueuedTexture.Identifier.c_str()); + LogDebug(CH_TEXTURES, "Create %s", aQueuedTexture.Identifier.c_str()); Texture* tex = new Texture{}; tex->Width = aQueuedTexture.Width; @@ -244,7 +252,7 @@ namespace TextureLoader if (!pTexture) { - //LogDebug(CH_TEXTURES, "pTexture was null"); + LogDebug(CH_TEXTURES, "pTexture was null"); stbi_image_free(aQueuedTexture.Data); return; }