From e4f349ad6be5408b64d2f38091d76d5c0c889bd4 Mon Sep 17 00:00:00 2001 From: dragonzkiller Date: Mon, 28 Oct 2024 20:49:05 -0400 Subject: [PATCH] Code Cleanup --- src/d3d12/D3D12.h | 2 - src/d3d12/D3D12_Functions.cpp | 2 +- src/imgui_impl/imgui_user_config.h | 2 + src/imgui_impl/win32.h | 6 --- src/overlay/widgets/Settings.cpp | 17 ++++---- src/sol_imgui/sol_imgui.h | 63 ++++++++++-------------------- xmake.lua | 2 +- 7 files changed, 35 insertions(+), 59 deletions(-) diff --git a/src/d3d12/D3D12.h b/src/d3d12/D3D12.h index 01f44a45..0c64197b 100644 --- a/src/d3d12/D3D12.h +++ b/src/d3d12/D3D12.h @@ -3,8 +3,6 @@ #include "common/D3D12Downlevel.h" #include "window/Window.h" -extern IMGUI_IMPL_API LRESULT ImGui_ImplWin32_WndProcHandler(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam); - using TPresentD3D12Downlevel = HRESULT(ID3D12CommandQueueDownlevel*, ID3D12GraphicsCommandList*, ID3D12Resource*, HWND, D3D12_DOWNLEVEL_PRESENT_FLAGS); using TCreateCommittedResource = HRESULT(ID3D12Device*, const D3D12_HEAP_PROPERTIES*, D3D12_HEAP_FLAGS, const D3D12_RESOURCE_DESC*, D3D12_RESOURCE_STATES, const D3D12_CLEAR_VALUE*, const IID*, void**); diff --git a/src/d3d12/D3D12_Functions.cpp b/src/d3d12/D3D12_Functions.cpp index 89894f39..ca23e2d6 100644 --- a/src/d3d12/D3D12_Functions.cpp +++ b/src/d3d12/D3D12_Functions.cpp @@ -504,7 +504,7 @@ void D3D12::PrepareUpdate() for (auto i = 0; i < drawData.CmdListsCount; ++i) copiedDrawLists[i] = drawData.CmdLists[i]->CloneOutput(); - drawData.CmdLists = copiedDrawLists; + drawData.CmdLists = std::move(copiedDrawLists); std::swap(m_imguiDrawDataBuffers[1], m_imguiDrawDataBuffers[2]); } diff --git a/src/imgui_impl/imgui_user_config.h b/src/imgui_impl/imgui_user_config.h index 6298b9c7..c020a6e8 100644 --- a/src/imgui_impl/imgui_user_config.h +++ b/src/imgui_impl/imgui_user_config.h @@ -3,6 +3,8 @@ // global declaration "Enable ImGui Assertions" extern bool g_ImGuiAssertionsEnabled; +#define IMGUI_IMPL_WIN32_DISABLE_GAMEPAD + // runtime assertions which can be enabled/disabled inside CET options void ImGuiAssert(wchar_t const* acpMessage, wchar_t const* acpFile, unsigned aLine); diff --git a/src/imgui_impl/win32.h b/src/imgui_impl/win32.h index 85e41262..ea25e954 100644 --- a/src/imgui_impl/win32.h +++ b/src/imgui_impl/win32.h @@ -28,13 +28,7 @@ IMGUI_IMPL_API void ImGui_ImplWin32_Shutdown(); IMGUI_IMPL_API void ImGui_ImplWin32_NewFrame(SIZE aOutSize); // Win32 message handler your application need to call. -// - Intentionally commented out in a '#if 0' block to avoid dragging dependencies on from this helper. -// - You should COPY the line below into your .cpp code to forward declare the function and then you can call it. -// - Call from your application's message handler. Keep calling your message handler unless this function returns TRUE. - -#if 0 extern IMGUI_IMPL_API LRESULT ImGui_ImplWin32_WndProcHandler(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam); -#endif // DPI-related helpers (optional) // - Use to enable DPI awareness without having to create an application manifest. diff --git a/src/overlay/widgets/Settings.cpp b/src/overlay/widgets/Settings.cpp index b9b81415..06d8335f 100644 --- a/src/overlay/widgets/Settings.cpp +++ b/src/overlay/widgets/Settings.cpp @@ -16,8 +16,7 @@ Settings::Settings(Options& aOptions, LuaVM& aVm) WidgetResult Settings::OnPopup() { - const auto ret = UnsavedChangesPopup( - "Settings", m_openChangesModal, m_madeChanges, [this] { Save(); }, [this] { Load(); }); + const auto ret = UnsavedChangesPopup("Settings", m_openChangesModal, m_madeChanges, [this] { Save(); }, [this] { Load(); }); m_madeChanges = ret == TChangedCBResult::CHANGED; m_popupResult = ret; @@ -54,7 +53,7 @@ void Settings::OnUpdate() m_madeChanges = false; if (ImGui::CollapsingHeader("Patches", ImGuiTreeNodeFlags_DefaultOpen)) { - ImGui::TreePush((void*)nullptr); + ImGui::TreePush("##PATCHES"); if (ImGui::BeginTable("##SETTINGS_PATCHES", 2, ImGuiTableFlags_Sortable | ImGuiTableFlags_SizingStretchSame, ImVec2(-ImGui::GetStyle().IndentSpacing, 0))) { const auto& patchesSettings = m_options.Patches; @@ -78,7 +77,9 @@ void Settings::OnUpdate() UpdateAndDrawSetting( "Disable Boundary Teleport", "Allows players to access out-of-bounds locations (requires restart to take effect).", m_patches.DisableBoundaryTeleport, patchesSettings.DisableBoundaryTeleport); - UpdateAndDrawSetting("Disable V-Sync (Windows 7 only)", "Disables VSync on Windows 7 to bypass the 60 FPS limit (requires restart to take effect).", m_patches.DisableWin7Vsync, patchesSettings.DisableWin7Vsync); + UpdateAndDrawSetting( + "Disable V-Sync (Windows 7 only)", "Disables VSync on Windows 7 to bypass the 60 FPS limit (requires restart to take effect).", m_patches.DisableWin7Vsync, + patchesSettings.DisableWin7Vsync); UpdateAndDrawSetting( "Fix Minimap Flicker", "Fixes Minimap flicker caused by some mods (requires restart to take effect).", m_patches.MinimapFlicker, patchesSettings.MinimapFlicker); @@ -89,7 +90,7 @@ void Settings::OnUpdate() } if (ImGui::CollapsingHeader("CET Development Settings", ImGuiTreeNodeFlags_DefaultOpen)) { - ImGui::TreePush((void*)nullptr); + ImGui::TreePush("##DEV"); if (ImGui::BeginTable("##SETTINGS_DEV", 2, ImGuiTableFlags_Sortable | ImGuiTableFlags_SizingStretchSame, ImVec2(-ImGui::GetStyle().IndentSpacing, 0))) { const auto& developerSettings = m_options.Developer; @@ -108,8 +109,10 @@ void Settings::OnUpdate() "Dump Game Options", "Dumps all game options into main log file (requires restart to take effect).", m_developer.DumpGameOptions, developerSettings.DumpGameOptions); UpdateAndDrawSetting( - "Enable JIT for Lua", "Enables JIT compiler for Lua VM, which may majorly speed up the mods. Disable it in case you experience issues as a troubleshooting step (requires restart to take effect).", m_developer.EnableJIT, - developerSettings.EnableJIT); + "Enable JIT for Lua", + "Enables JIT compiler for Lua VM, which may majorly speed up the mods. Disable it in case you experience issues as a troubleshooting step (requires restart to " + "take effect).", + m_developer.EnableJIT, developerSettings.EnableJIT); ImGui::EndTable(); } diff --git a/src/sol_imgui/sol_imgui.h b/src/sol_imgui/sol_imgui.h index 473e0cdd..f1dcbef9 100644 --- a/src/sol_imgui/sol_imgui.h +++ b/src/sol_imgui/sol_imgui.h @@ -2,13 +2,6 @@ namespace sol_ImGui { - -// Version -inline std::string GetVersion() -{ - return std::string(ImGui::GetVersion()); -} - // Windows inline bool Begin(const std::string& name) { @@ -50,6 +43,15 @@ inline bool BeginChild(const std::string& name, float sizeX, float sizeY) { return ImGui::BeginChild(name.c_str(), {sizeX, sizeY}); } +inline bool BeginChild(const std::string& name, float sizeX, float sizeY, int child_flags) +{ + return ImGui::BeginChild(name.c_str(), {sizeX, sizeY}, static_cast(child_flags)); +} + +inline bool BeginChild(const std::string& name, float sizeX, float sizeY, int child_flags, int window_flags) +{ + return ImGui::BeginChild(name.c_str(), {sizeX, sizeY}, static_cast(child_flags), static_cast(window_flags)); +} // DEPRECATED inline bool BeginChild(const std::string& name, float sizeX, float sizeY, bool border) @@ -61,17 +63,6 @@ inline bool BeginChild(const std::string& name, float sizeX, float sizeY, bool b return ImGui::BeginChild(name.c_str(), {sizeX, sizeY}, border, flags); } -// new -inline bool BeginChild(const std::string& name, float sizeX, float sizeY, int child_flags) -{ - return ImGui::BeginChild(name.c_str(), {sizeX, sizeY}, static_cast(child_flags)); -} - -inline bool BeginChild(const std::string& name, float sizeX, float sizeY, int child_flags, int window_flags) -{ - return ImGui::BeginChild(name.c_str(), {sizeX, sizeY}, static_cast(child_flags), static_cast(window_flags)); -} - inline void EndChild() { ImGui::EndChild(); @@ -2676,30 +2667,25 @@ inline int GetKeyPressedAmount(int key_index, float repeat_delay, float rate) { return ImGui::GetKeyPressedAmount(static_cast(key_index), repeat_delay, rate); } +inline void SetNextFrameWantCaptureKeyboard(bool want_capture_keyboard_value) +{ + ImGui::SetNextFrameWantCaptureKeyboard(want_capture_keyboard_value); +} // DEPRECATED inline int GetKeyIndex(int imgui_key) { return ImGui::GetKeyIndex(static_cast(imgui_key)); } - -// DEPRECATED inline void CaptureKeyboardFromApp() { ImGui::SetNextFrameWantCaptureKeyboard(true); } -// DEPRECTED inline void CaptureKeyboardFromApp(bool want_capture_keyboard_value) { ImGui::SetNextFrameWantCaptureKeyboard(want_capture_keyboard_value); } -// new -inline void SetNextFrameWantCaptureKeyboard(bool want_capture_keyboard_value) -{ - ImGui::SetNextFrameWantCaptureKeyboard(want_capture_keyboard_value); -} - // Inputs Utilities: Mouse inline bool IsMouseDown(int button) @@ -2784,23 +2770,21 @@ inline void SetMouseCursor(int cursor_type) { ImGui::SetMouseCursor(static_cast(cursor_type)); } +inline void SetNextFrameWantCaptureMouse(bool want_capture_mouse_value) +{ + ImGui::SetNextFrameWantCaptureMouse(want_capture_mouse_value); +} // DEPRECATED inline void CaptureMouseFromApp() { ImGui::SetNextFrameWantCaptureMouse(true); } -// DEPRECATED inline void CaptureMouseFromApp(bool want_capture_mouse_value) { ImGui::SetNextFrameWantCaptureMouse(want_capture_mouse_value); } -inline void SetNextFrameWantCaptureMouse(bool want_capture_mouse_value) -{ - ImGui::SetNextFrameWantCaptureMouse(want_capture_mouse_value); -} - // Clipboard Utilities inline std::string GetClipboardText() { @@ -3128,13 +3112,12 @@ inline void InitEnums(sol::table luaGlobals) #pragma region Selectable Flags luaGlobals.new_enum( - "ImGuiSelectableFlags", "None", ImGuiSelectableFlags_None, "NoAutoClosePopups", ImGuiSelectableFlags_NoAutoClosePopups, "SpanAllColumns", ImGuiSelectableFlags_SpanAllColumns, - "AllowDoubleClick", ImGuiSelectableFlags_AllowDoubleClick, "Disabled", ImGuiSelectableFlags_Disabled, "AllowOverlap", ImGuiSelectableFlags_AllowOverlap, + "ImGuiSelectableFlags", "None", ImGuiSelectableFlags_None, "NoAutoClosePopups", ImGuiSelectableFlags_NoAutoClosePopups, "SpanAllColumns", + ImGuiSelectableFlags_SpanAllColumns, "AllowDoubleClick", ImGuiSelectableFlags_AllowDoubleClick, "Disabled", ImGuiSelectableFlags_Disabled, "AllowOverlap", + ImGuiSelectableFlags_AllowOverlap, // DEPRECATED - "DontClosePopups", ImGuiSelectableFlags_DontClosePopups, - "AllowItemOverlap", ImGuiSelectableFlags_AllowItemOverlap - ); + "DontClosePopups", ImGuiSelectableFlags_DontClosePopups, "AllowItemOverlap", ImGuiSelectableFlags_AllowItemOverlap); #pragma endregion Selectable Flags #pragma region Popup Flags @@ -3269,10 +3252,6 @@ inline void InitBindings(sol::state& lua, sol::table luaGlobals) sol::table ImGui(lua, sol::create); -#pragma region Version - ImGui.set_function("GetVersion", GetVersion); -#pragma endregion Version - #pragma region Windows ImGui.set_function( "Begin", sol::overload( diff --git a/xmake.lua b/xmake.lua index f25a1605..576aee4a 100644 --- a/xmake.lua +++ b/xmake.lua @@ -64,7 +64,7 @@ target("RED4ext.SDK") on_install(function() end) target("cyber_engine_tweaks") - add_defines("WIN32_LEAN_AND_MEAN", "NOMINMAX", "WINVER=0x0601", "SOL_ALL_SAFETIES_ON", "SOL_LUAJIT=1", "SOL_EXCEPTIONS_SAFE_PROPAGATION", "SPDLOG_WCHAR_TO_UTF8_SUPPORT", "SPDLOG_WCHAR_FILENAMES", "SPDLOG_WCHAR_SUPPORT", "IMGUI_USER_CONFIG=\""..imguiUserConfig.."\", IMGUI_IMPL_WIN32_DISABLE_GAMEPAD") -- WINVER=0x0601 == Windows 7xmake + add_defines("WIN32_LEAN_AND_MEAN", "NOMINMAX", "WINVER=0x0601", "SOL_ALL_SAFETIES_ON", "SOL_LUAJIT=1", "SOL_EXCEPTIONS_SAFE_PROPAGATION", "SPDLOG_WCHAR_TO_UTF8_SUPPORT", "SPDLOG_WCHAR_FILENAMES", "SPDLOG_WCHAR_SUPPORT", "IMGUI_USER_CONFIG=\""..imguiUserConfig.."\"") -- WINVER=0x0601 == Windows 7xmake set_pcxxheader("src/stdafx.h") set_kind("shared") set_filename("cyber_engine_tweaks.asi")