diff --git a/CMakeLists.txt b/CMakeLists.txt index b278805..52da4df 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,7 +10,6 @@ set(GTA_SA_DIR F:/GTASanAndreas) # Can ignore the below paths if you got them in system paths set(PLUGIN_SDK_DIR $ENV{PLUGIN_SDK_DIR}) set(DIRECTX9_SDK_DIR $ENV{DIRECTX9_SDK_DIR}) -set(VULKAN_SDK_DIR $ENV{VK_SDK_PATH}) ################################################################################ ################################################################################ @@ -94,7 +93,6 @@ include_directories( "${PLUGIN_SDK_DIR}/shared" "${PLUGIN_SDK_DIR}/shared/game" "${DIRECTX9_SDK_DIR}/include" - # "${VULKAN_SDK_DIR}/Include" "deps" ) @@ -182,7 +180,6 @@ Depend target_link_directories(${PROJECT_NAME} PUBLIC "${PLUGIN_SDK_DIR}/output/lib/" "${DIRECTX9_SDK_DIR}/lib/x86/" - # "${VULKAN_SDK_DIR}/lib32" "$<$:" "deps/Release/" ">" diff --git a/deps/CMakeLists.txt b/deps/CMakeLists.txt index 5ba6c33..f5fefff 100644 --- a/deps/CMakeLists.txt +++ b/deps/CMakeLists.txt @@ -21,8 +21,6 @@ set(depend_files "imgui/imgui_impl_dx9.h" "imgui/imgui_impl_dx11.cpp" "imgui/imgui_impl_dx11.h" - # "imgui/imgui_impl_vulkan.cpp" - # "imgui/imgui_impl_vulkan.h" "imgui/imgui_impl_win32.cpp" "imgui/imgui_impl_win32.h" "imgui/imgui_internal.h" @@ -67,8 +65,6 @@ include_directories( "$ENV{PLUGIN_SDK_DIR}/shared" "$ENV{PLUGIN_SDK_DIR}/shared/game" "$ENV{DIRECTX9_SDK_DIR}/include" - # "${VULKAN_SDK_DIR}/Include" - # "${VULKAN_SDK_DIR}/lib32" ) target_compile_options(${PROJECT_NAME} PRIVATE diff --git a/deps/imgui/imgui_impl_vulkan.cpp b/deps/imgui/imgui_impl_vulkan.cpp deleted file mode 100644 index 44a555a..0000000 --- a/deps/imgui/imgui_impl_vulkan.cpp +++ /dev/null @@ -1,1414 +0,0 @@ -// dear imgui: Renderer Backend for Vulkan -// This needs to be used along with a Platform Backend (e.g. GLFW, SDL, Win32, custom..) - -// Implemented features: -// [X] Renderer: Support for large meshes (64k+ vertices) with 16-bit indices. -// Missing features: -// [ ] Renderer: User texture binding. Changes of ImTextureID aren't supported by this backend! See https://github.com/ocornut/imgui/pull/914 - -// You can copy and use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this. -// If you are new to Dear ImGui, read documentation from the docs/ folder + read the top of imgui.cpp. -// Read online: https://github.com/ocornut/imgui/tree/master/docs - -// The aim of imgui_impl_vulkan.h/.cpp is to be usable in your engine without any modification. -// IF YOU FEEL YOU NEED TO MAKE ANY CHANGE TO THIS CODE, please share them and your feedback at https://github.com/ocornut/imgui/ - -// Important note to the reader who wish to integrate imgui_impl_vulkan.cpp/.h in their own engine/app. -// - Common ImGui_ImplVulkan_XXX functions and structures are used to interface with imgui_impl_vulkan.cpp/.h. -// You will use those if you want to use this rendering backend in your engine/app. -// - Helper ImGui_ImplVulkanH_XXX functions and structures are only used by this example (main.cpp) and by -// the backend itself (imgui_impl_vulkan.cpp), but should PROBABLY NOT be used by your own engine/app code. -// Read comments in imgui_impl_vulkan.h. - -// CHANGELOG -// (minor and older changes stripped away, please see git history for details) -// 2021-01-27: Vulkan: Added support for custom function load and IMGUI_IMPL_VULKAN_NO_PROTOTYPES by using ImGui_ImplVulkan_LoadFunctions(). -// 2020-11-11: Vulkan: Added support for specifying which subpass to reference during VkPipeline creation. -// 2020-09-07: Vulkan: Added VkPipeline parameter to ImGui_ImplVulkan_RenderDrawData (default to one passed to ImGui_ImplVulkan_Init). -// 2020-05-04: Vulkan: Fixed crash if initial frame has no vertices. -// 2020-04-26: Vulkan: Fixed edge case where render callbacks wouldn't be called if the ImDrawData didn't have vertices. -// 2019-08-01: Vulkan: Added support for specifying multisample count. Set ImGui_ImplVulkan_InitInfo::MSAASamples to one of the VkSampleCountFlagBits values to use, default is non-multisampled as before. -// 2019-05-29: Vulkan: Added support for large mesh (64K+ vertices), enable ImGuiBackendFlags_RendererHasVtxOffset flag. -// 2019-04-30: Vulkan: Added support for special ImDrawCallback_ResetRenderState callback to reset render state. -// 2019-04-04: *BREAKING CHANGE*: Vulkan: Added ImageCount/MinImageCount fields in ImGui_ImplVulkan_InitInfo, required for initialization (was previously a hard #define IMGUI_VK_QUEUED_FRAMES 2). Added ImGui_ImplVulkan_SetMinImageCount(). -// 2019-04-04: Vulkan: Added VkInstance argument to ImGui_ImplVulkanH_CreateWindow() optional helper. -// 2019-04-04: Vulkan: Avoid passing negative coordinates to vkCmdSetScissor, which debug validation layers do not like. -// 2019-04-01: Vulkan: Support for 32-bit index buffer (#define ImDrawIdx unsigned int). -// 2019-02-16: Vulkan: Viewport and clipping rectangles correctly using draw_data->FramebufferScale to allow retina display. -// 2018-11-30: Misc: Setting up io.BackendRendererName so it can be displayed in the About Window. -// 2018-08-25: Vulkan: Fixed mishandled VkSurfaceCapabilitiesKHR::maxImageCount=0 case. -// 2018-06-22: Inverted the parameters to ImGui_ImplVulkan_RenderDrawData() to be consistent with other backends. -// 2018-06-08: Misc: Extracted imgui_impl_vulkan.cpp/.h away from the old combined GLFW+Vulkan example. -// 2018-06-08: Vulkan: Use draw_data->DisplayPos and draw_data->DisplaySize to setup projection matrix and clipping rectangle. -// 2018-03-03: Vulkan: Various refactor, created a couple of ImGui_ImplVulkanH_XXX helper that the example can use and that viewport support will use. -// 2018-03-01: Vulkan: Renamed ImGui_ImplVulkan_Init_Info to ImGui_ImplVulkan_InitInfo and fields to match more closely Vulkan terminology. -// 2018-02-16: Misc: Obsoleted the io.RenderDrawListsFn callback, ImGui_ImplVulkan_Render() calls ImGui_ImplVulkan_RenderDrawData() itself. -// 2018-02-06: Misc: Removed call to ImGui::Shutdown() which is not available from 1.60 WIP, user needs to call CreateContext/DestroyContext themselves. -// 2017-05-15: Vulkan: Fix scissor offset being negative. Fix new Vulkan validation warnings. Set required depth member for buffer image copy. -// 2016-11-13: Vulkan: Fix validation layer warnings and errors and redeclare gl_PerVertex. -// 2016-10-18: Vulkan: Add location decorators & change to use structs as in/out in glsl, update embedded spv (produced with glslangValidator -x). Null the released resources. -// 2016-08-27: Vulkan: Fix Vulkan example for use when a depth buffer is active. - -#include "imgui_impl_vulkan.h" -#include - -// Reusable buffers used for rendering 1 current in-flight frame, for ImGui_ImplVulkan_RenderDrawData() -// [Please zero-clear before use!] -struct ImGui_ImplVulkanH_FrameRenderBuffers -{ - VkDeviceMemory VertexBufferMemory; - VkDeviceMemory IndexBufferMemory; - VkDeviceSize VertexBufferSize; - VkDeviceSize IndexBufferSize; - VkBuffer VertexBuffer; - VkBuffer IndexBuffer; -}; - -// Each viewport will hold 1 ImGui_ImplVulkanH_WindowRenderBuffers -// [Please zero-clear before use!] -struct ImGui_ImplVulkanH_WindowRenderBuffers -{ - uint32_t Index; - uint32_t Count; - ImGui_ImplVulkanH_FrameRenderBuffers* FrameRenderBuffers; -}; - -// Vulkan data -static ImGui_ImplVulkan_InitInfo g_VulkanInitInfo = {}; -static VkRenderPass g_RenderPass = VK_NULL_HANDLE; -static VkDeviceSize g_BufferMemoryAlignment = 256; -static VkPipelineCreateFlags g_PipelineCreateFlags = 0x00; -static VkDescriptorSetLayout g_DescriptorSetLayout = VK_NULL_HANDLE; -static VkPipelineLayout g_PipelineLayout = VK_NULL_HANDLE; -static VkDescriptorSet g_DescriptorSet = VK_NULL_HANDLE; -static VkPipeline g_Pipeline = VK_NULL_HANDLE; -static uint32_t g_Subpass = 0; -static VkShaderModule g_ShaderModuleVert; -static VkShaderModule g_ShaderModuleFrag; -#ifdef VK_NO_PROTOTYPES -static bool g_FunctionsLoaded = false; -#else -static bool g_FunctionsLoaded = true; -#endif - -// Font data -static VkSampler g_FontSampler = VK_NULL_HANDLE; -static VkDeviceMemory g_FontMemory = VK_NULL_HANDLE; -static VkImage g_FontImage = VK_NULL_HANDLE; -static VkImageView g_FontView = VK_NULL_HANDLE; -static VkDeviceMemory g_UploadBufferMemory = VK_NULL_HANDLE; -static VkBuffer g_UploadBuffer = VK_NULL_HANDLE; - -// Render buffers -static ImGui_ImplVulkanH_WindowRenderBuffers g_MainWindowRenderBuffers; - -// Forward Declarations -bool ImGui_ImplVulkan_CreateDeviceObjects(); -void ImGui_ImplVulkan_DestroyDeviceObjects(); -void ImGui_ImplVulkanH_DestroyFrame(VkDevice device, ImGui_ImplVulkanH_Frame* fd, const VkAllocationCallbacks* allocator); -void ImGui_ImplVulkanH_DestroyFrameSemaphores(VkDevice device, ImGui_ImplVulkanH_FrameSemaphores* fsd, const VkAllocationCallbacks* allocator); -void ImGui_ImplVulkanH_DestroyFrameRenderBuffers(VkDevice device, ImGui_ImplVulkanH_FrameRenderBuffers* buffers, const VkAllocationCallbacks* allocator); -void ImGui_ImplVulkanH_DestroyWindowRenderBuffers(VkDevice device, ImGui_ImplVulkanH_WindowRenderBuffers* buffers, const VkAllocationCallbacks* allocator); -void ImGui_ImplVulkanH_CreateWindowSwapChain(VkPhysicalDevice physical_device, VkDevice device, ImGui_ImplVulkanH_Window* wd, const VkAllocationCallbacks* allocator, int w, int h, uint32_t min_image_count); -void ImGui_ImplVulkanH_CreateWindowCommandBuffers(VkPhysicalDevice physical_device, VkDevice device, ImGui_ImplVulkanH_Window* wd, uint32_t queue_family, const VkAllocationCallbacks* allocator); - -// Vulkan prototypes for use with custom loaders -// (see description of IMGUI_IMPL_VULKAN_NO_PROTOTYPES in imgui_impl_vulkan.h -#ifdef VK_NO_PROTOTYPES -#define IMGUI_VULKAN_FUNC_MAP(IMGUI_VULKAN_FUNC_MAP_MACRO) \ - IMGUI_VULKAN_FUNC_MAP_MACRO(vkAllocateCommandBuffers) \ - IMGUI_VULKAN_FUNC_MAP_MACRO(vkAllocateDescriptorSets) \ - IMGUI_VULKAN_FUNC_MAP_MACRO(vkAllocateMemory) \ - IMGUI_VULKAN_FUNC_MAP_MACRO(vkBindBufferMemory) \ - IMGUI_VULKAN_FUNC_MAP_MACRO(vkBindImageMemory) \ - IMGUI_VULKAN_FUNC_MAP_MACRO(vkCmdBindDescriptorSets) \ - IMGUI_VULKAN_FUNC_MAP_MACRO(vkCmdBindIndexBuffer) \ - IMGUI_VULKAN_FUNC_MAP_MACRO(vkCmdBindPipeline) \ - IMGUI_VULKAN_FUNC_MAP_MACRO(vkCmdBindVertexBuffers) \ - IMGUI_VULKAN_FUNC_MAP_MACRO(vkCmdCopyBufferToImage) \ - IMGUI_VULKAN_FUNC_MAP_MACRO(vkCmdDrawIndexed) \ - IMGUI_VULKAN_FUNC_MAP_MACRO(vkCmdPipelineBarrier) \ - IMGUI_VULKAN_FUNC_MAP_MACRO(vkCmdPushConstants) \ - IMGUI_VULKAN_FUNC_MAP_MACRO(vkCmdSetScissor) \ - IMGUI_VULKAN_FUNC_MAP_MACRO(vkCmdSetViewport) \ - IMGUI_VULKAN_FUNC_MAP_MACRO(vkCreateBuffer) \ - IMGUI_VULKAN_FUNC_MAP_MACRO(vkCreateCommandPool) \ - IMGUI_VULKAN_FUNC_MAP_MACRO(vkCreateDescriptorSetLayout) \ - IMGUI_VULKAN_FUNC_MAP_MACRO(vkCreateFence) \ - IMGUI_VULKAN_FUNC_MAP_MACRO(vkCreateFramebuffer) \ - IMGUI_VULKAN_FUNC_MAP_MACRO(vkCreateGraphicsPipelines) \ - IMGUI_VULKAN_FUNC_MAP_MACRO(vkCreateImage) \ - IMGUI_VULKAN_FUNC_MAP_MACRO(vkCreateImageView) \ - IMGUI_VULKAN_FUNC_MAP_MACRO(vkCreatePipelineLayout) \ - IMGUI_VULKAN_FUNC_MAP_MACRO(vkCreateRenderPass) \ - IMGUI_VULKAN_FUNC_MAP_MACRO(vkCreateSampler) \ - IMGUI_VULKAN_FUNC_MAP_MACRO(vkCreateSemaphore) \ - IMGUI_VULKAN_FUNC_MAP_MACRO(vkCreateShaderModule) \ - IMGUI_VULKAN_FUNC_MAP_MACRO(vkCreateSwapchainKHR) \ - IMGUI_VULKAN_FUNC_MAP_MACRO(vkDestroyBuffer) \ - IMGUI_VULKAN_FUNC_MAP_MACRO(vkDestroyCommandPool) \ - IMGUI_VULKAN_FUNC_MAP_MACRO(vkDestroyDescriptorSetLayout) \ - IMGUI_VULKAN_FUNC_MAP_MACRO(vkDestroyFence) \ - IMGUI_VULKAN_FUNC_MAP_MACRO(vkDestroyFramebuffer) \ - IMGUI_VULKAN_FUNC_MAP_MACRO(vkDestroyImage) \ - IMGUI_VULKAN_FUNC_MAP_MACRO(vkDestroyImageView) \ - IMGUI_VULKAN_FUNC_MAP_MACRO(vkDestroyPipeline) \ - IMGUI_VULKAN_FUNC_MAP_MACRO(vkDestroyPipelineLayout) \ - IMGUI_VULKAN_FUNC_MAP_MACRO(vkDestroyRenderPass) \ - IMGUI_VULKAN_FUNC_MAP_MACRO(vkDestroySampler) \ - IMGUI_VULKAN_FUNC_MAP_MACRO(vkDestroySemaphore) \ - IMGUI_VULKAN_FUNC_MAP_MACRO(vkDestroyShaderModule) \ - IMGUI_VULKAN_FUNC_MAP_MACRO(vkDestroySurfaceKHR) \ - IMGUI_VULKAN_FUNC_MAP_MACRO(vkDestroySwapchainKHR) \ - IMGUI_VULKAN_FUNC_MAP_MACRO(vkDeviceWaitIdle) \ - IMGUI_VULKAN_FUNC_MAP_MACRO(vkFlushMappedMemoryRanges) \ - IMGUI_VULKAN_FUNC_MAP_MACRO(vkFreeCommandBuffers) \ - IMGUI_VULKAN_FUNC_MAP_MACRO(vkFreeMemory) \ - IMGUI_VULKAN_FUNC_MAP_MACRO(vkGetBufferMemoryRequirements) \ - IMGUI_VULKAN_FUNC_MAP_MACRO(vkGetImageMemoryRequirements) \ - IMGUI_VULKAN_FUNC_MAP_MACRO(vkGetPhysicalDeviceMemoryProperties) \ - IMGUI_VULKAN_FUNC_MAP_MACRO(vkGetPhysicalDeviceSurfaceCapabilitiesKHR) \ - IMGUI_VULKAN_FUNC_MAP_MACRO(vkGetPhysicalDeviceSurfaceFormatsKHR) \ - IMGUI_VULKAN_FUNC_MAP_MACRO(vkGetPhysicalDeviceSurfacePresentModesKHR) \ - IMGUI_VULKAN_FUNC_MAP_MACRO(vkGetSwapchainImagesKHR) \ - IMGUI_VULKAN_FUNC_MAP_MACRO(vkMapMemory) \ - IMGUI_VULKAN_FUNC_MAP_MACRO(vkUnmapMemory) \ - IMGUI_VULKAN_FUNC_MAP_MACRO(vkUpdateDescriptorSets) - -// Define function pointers -#define IMGUI_VULKAN_FUNC_DEF(func) static PFN_##func func; -IMGUI_VULKAN_FUNC_MAP(IMGUI_VULKAN_FUNC_DEF) -#undef IMGUI_VULKAN_FUNC_DEF -#endif // VK_NO_PROTOTYPES - -//----------------------------------------------------------------------------- -// SHADERS -//----------------------------------------------------------------------------- - -// glsl_shader.vert, compiled with: -// # glslangValidator -V -x -o glsl_shader.vert.u32 glsl_shader.vert -/* -#version 450 core -layout(location = 0) in vec2 aPos; -layout(location = 1) in vec2 aUV; -layout(location = 2) in vec4 aColor; -layout(push_constant) uniform uPushConstant { vec2 uScale; vec2 uTranslate; } pc; - -out gl_PerVertex { vec4 gl_Position; }; -layout(location = 0) out struct { vec4 Color; vec2 UV; } Out; - -void main() -{ - Out.Color = aColor; - Out.UV = aUV; - gl_Position = vec4(aPos * pc.uScale + pc.uTranslate, 0, 1); -} -*/ -static uint32_t __glsl_shader_vert_spv[] = -{ - 0x07230203,0x00010000,0x00080001,0x0000002e,0x00000000,0x00020011,0x00000001,0x0006000b, - 0x00000001,0x4c534c47,0x6474732e,0x3035342e,0x00000000,0x0003000e,0x00000000,0x00000001, - 0x000a000f,0x00000000,0x00000004,0x6e69616d,0x00000000,0x0000000b,0x0000000f,0x00000015, - 0x0000001b,0x0000001c,0x00030003,0x00000002,0x000001c2,0x00040005,0x00000004,0x6e69616d, - 0x00000000,0x00030005,0x00000009,0x00000000,0x00050006,0x00000009,0x00000000,0x6f6c6f43, - 0x00000072,0x00040006,0x00000009,0x00000001,0x00005655,0x00030005,0x0000000b,0x0074754f, - 0x00040005,0x0000000f,0x6c6f4361,0x0000726f,0x00030005,0x00000015,0x00565561,0x00060005, - 0x00000019,0x505f6c67,0x65567265,0x78657472,0x00000000,0x00060006,0x00000019,0x00000000, - 0x505f6c67,0x7469736f,0x006e6f69,0x00030005,0x0000001b,0x00000000,0x00040005,0x0000001c, - 0x736f5061,0x00000000,0x00060005,0x0000001e,0x73755075,0x6e6f4368,0x6e617473,0x00000074, - 0x00050006,0x0000001e,0x00000000,0x61635375,0x0000656c,0x00060006,0x0000001e,0x00000001, - 0x61725475,0x616c736e,0x00006574,0x00030005,0x00000020,0x00006370,0x00040047,0x0000000b, - 0x0000001e,0x00000000,0x00040047,0x0000000f,0x0000001e,0x00000002,0x00040047,0x00000015, - 0x0000001e,0x00000001,0x00050048,0x00000019,0x00000000,0x0000000b,0x00000000,0x00030047, - 0x00000019,0x00000002,0x00040047,0x0000001c,0x0000001e,0x00000000,0x00050048,0x0000001e, - 0x00000000,0x00000023,0x00000000,0x00050048,0x0000001e,0x00000001,0x00000023,0x00000008, - 0x00030047,0x0000001e,0x00000002,0x00020013,0x00000002,0x00030021,0x00000003,0x00000002, - 0x00030016,0x00000006,0x00000020,0x00040017,0x00000007,0x00000006,0x00000004,0x00040017, - 0x00000008,0x00000006,0x00000002,0x0004001e,0x00000009,0x00000007,0x00000008,0x00040020, - 0x0000000a,0x00000003,0x00000009,0x0004003b,0x0000000a,0x0000000b,0x00000003,0x00040015, - 0x0000000c,0x00000020,0x00000001,0x0004002b,0x0000000c,0x0000000d,0x00000000,0x00040020, - 0x0000000e,0x00000001,0x00000007,0x0004003b,0x0000000e,0x0000000f,0x00000001,0x00040020, - 0x00000011,0x00000003,0x00000007,0x0004002b,0x0000000c,0x00000013,0x00000001,0x00040020, - 0x00000014,0x00000001,0x00000008,0x0004003b,0x00000014,0x00000015,0x00000001,0x00040020, - 0x00000017,0x00000003,0x00000008,0x0003001e,0x00000019,0x00000007,0x00040020,0x0000001a, - 0x00000003,0x00000019,0x0004003b,0x0000001a,0x0000001b,0x00000003,0x0004003b,0x00000014, - 0x0000001c,0x00000001,0x0004001e,0x0000001e,0x00000008,0x00000008,0x00040020,0x0000001f, - 0x00000009,0x0000001e,0x0004003b,0x0000001f,0x00000020,0x00000009,0x00040020,0x00000021, - 0x00000009,0x00000008,0x0004002b,0x00000006,0x00000028,0x00000000,0x0004002b,0x00000006, - 0x00000029,0x3f800000,0x00050036,0x00000002,0x00000004,0x00000000,0x00000003,0x000200f8, - 0x00000005,0x0004003d,0x00000007,0x00000010,0x0000000f,0x00050041,0x00000011,0x00000012, - 0x0000000b,0x0000000d,0x0003003e,0x00000012,0x00000010,0x0004003d,0x00000008,0x00000016, - 0x00000015,0x00050041,0x00000017,0x00000018,0x0000000b,0x00000013,0x0003003e,0x00000018, - 0x00000016,0x0004003d,0x00000008,0x0000001d,0x0000001c,0x00050041,0x00000021,0x00000022, - 0x00000020,0x0000000d,0x0004003d,0x00000008,0x00000023,0x00000022,0x00050085,0x00000008, - 0x00000024,0x0000001d,0x00000023,0x00050041,0x00000021,0x00000025,0x00000020,0x00000013, - 0x0004003d,0x00000008,0x00000026,0x00000025,0x00050081,0x00000008,0x00000027,0x00000024, - 0x00000026,0x00050051,0x00000006,0x0000002a,0x00000027,0x00000000,0x00050051,0x00000006, - 0x0000002b,0x00000027,0x00000001,0x00070050,0x00000007,0x0000002c,0x0000002a,0x0000002b, - 0x00000028,0x00000029,0x00050041,0x00000011,0x0000002d,0x0000001b,0x0000000d,0x0003003e, - 0x0000002d,0x0000002c,0x000100fd,0x00010038 -}; - -// glsl_shader.frag, compiled with: -// # glslangValidator -V -x -o glsl_shader.frag.u32 glsl_shader.frag -/* -#version 450 core -layout(location = 0) out vec4 fColor; -layout(set=0, binding=0) uniform sampler2D sTexture; -layout(location = 0) in struct { vec4 Color; vec2 UV; } In; -void main() -{ - fColor = In.Color * texture(sTexture, In.UV.st); -} -*/ -static uint32_t __glsl_shader_frag_spv[] = -{ - 0x07230203,0x00010000,0x00080001,0x0000001e,0x00000000,0x00020011,0x00000001,0x0006000b, - 0x00000001,0x4c534c47,0x6474732e,0x3035342e,0x00000000,0x0003000e,0x00000000,0x00000001, - 0x0007000f,0x00000004,0x00000004,0x6e69616d,0x00000000,0x00000009,0x0000000d,0x00030010, - 0x00000004,0x00000007,0x00030003,0x00000002,0x000001c2,0x00040005,0x00000004,0x6e69616d, - 0x00000000,0x00040005,0x00000009,0x6c6f4366,0x0000726f,0x00030005,0x0000000b,0x00000000, - 0x00050006,0x0000000b,0x00000000,0x6f6c6f43,0x00000072,0x00040006,0x0000000b,0x00000001, - 0x00005655,0x00030005,0x0000000d,0x00006e49,0x00050005,0x00000016,0x78655473,0x65727574, - 0x00000000,0x00040047,0x00000009,0x0000001e,0x00000000,0x00040047,0x0000000d,0x0000001e, - 0x00000000,0x00040047,0x00000016,0x00000022,0x00000000,0x00040047,0x00000016,0x00000021, - 0x00000000,0x00020013,0x00000002,0x00030021,0x00000003,0x00000002,0x00030016,0x00000006, - 0x00000020,0x00040017,0x00000007,0x00000006,0x00000004,0x00040020,0x00000008,0x00000003, - 0x00000007,0x0004003b,0x00000008,0x00000009,0x00000003,0x00040017,0x0000000a,0x00000006, - 0x00000002,0x0004001e,0x0000000b,0x00000007,0x0000000a,0x00040020,0x0000000c,0x00000001, - 0x0000000b,0x0004003b,0x0000000c,0x0000000d,0x00000001,0x00040015,0x0000000e,0x00000020, - 0x00000001,0x0004002b,0x0000000e,0x0000000f,0x00000000,0x00040020,0x00000010,0x00000001, - 0x00000007,0x00090019,0x00000013,0x00000006,0x00000001,0x00000000,0x00000000,0x00000000, - 0x00000001,0x00000000,0x0003001b,0x00000014,0x00000013,0x00040020,0x00000015,0x00000000, - 0x00000014,0x0004003b,0x00000015,0x00000016,0x00000000,0x0004002b,0x0000000e,0x00000018, - 0x00000001,0x00040020,0x00000019,0x00000001,0x0000000a,0x00050036,0x00000002,0x00000004, - 0x00000000,0x00000003,0x000200f8,0x00000005,0x00050041,0x00000010,0x00000011,0x0000000d, - 0x0000000f,0x0004003d,0x00000007,0x00000012,0x00000011,0x0004003d,0x00000014,0x00000017, - 0x00000016,0x00050041,0x00000019,0x0000001a,0x0000000d,0x00000018,0x0004003d,0x0000000a, - 0x0000001b,0x0000001a,0x00050057,0x00000007,0x0000001c,0x00000017,0x0000001b,0x00050085, - 0x00000007,0x0000001d,0x00000012,0x0000001c,0x0003003e,0x00000009,0x0000001d,0x000100fd, - 0x00010038 -}; - -//----------------------------------------------------------------------------- -// FUNCTIONS -//----------------------------------------------------------------------------- - -static uint32_t ImGui_ImplVulkan_MemoryType(VkMemoryPropertyFlags properties, uint32_t type_bits) -{ - ImGui_ImplVulkan_InitInfo* v = &g_VulkanInitInfo; - VkPhysicalDeviceMemoryProperties prop; - vkGetPhysicalDeviceMemoryProperties(v->PhysicalDevice, &prop); - for (uint32_t i = 0; i < prop.memoryTypeCount; i++) - if ((prop.memoryTypes[i].propertyFlags & properties) == properties && type_bits & (1 << i)) - return i; - return 0xFFFFFFFF; // Unable to find memoryType -} - -static void check_vk_result(VkResult err) -{ - ImGui_ImplVulkan_InitInfo* v = &g_VulkanInitInfo; - if (v->CheckVkResultFn) - v->CheckVkResultFn(err); -} - -static void CreateOrResizeBuffer(VkBuffer& buffer, VkDeviceMemory& buffer_memory, VkDeviceSize& p_buffer_size, size_t new_size, VkBufferUsageFlagBits usage) -{ - ImGui_ImplVulkan_InitInfo* v = &g_VulkanInitInfo; - VkResult err; - if (buffer != VK_NULL_HANDLE) - vkDestroyBuffer(v->Device, buffer, v->Allocator); - if (buffer_memory != VK_NULL_HANDLE) - vkFreeMemory(v->Device, buffer_memory, v->Allocator); - - VkDeviceSize vertex_buffer_size_aligned = ((new_size - 1) / g_BufferMemoryAlignment + 1) * g_BufferMemoryAlignment; - VkBufferCreateInfo buffer_info = {}; - buffer_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; - buffer_info.size = vertex_buffer_size_aligned; - buffer_info.usage = usage; - buffer_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE; - err = vkCreateBuffer(v->Device, &buffer_info, v->Allocator, &buffer); - check_vk_result(err); - - VkMemoryRequirements req; - vkGetBufferMemoryRequirements(v->Device, buffer, &req); - g_BufferMemoryAlignment = (g_BufferMemoryAlignment > req.alignment) ? g_BufferMemoryAlignment : req.alignment; - VkMemoryAllocateInfo alloc_info = {}; - alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; - alloc_info.allocationSize = req.size; - alloc_info.memoryTypeIndex = ImGui_ImplVulkan_MemoryType(VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT, req.memoryTypeBits); - err = vkAllocateMemory(v->Device, &alloc_info, v->Allocator, &buffer_memory); - check_vk_result(err); - - err = vkBindBufferMemory(v->Device, buffer, buffer_memory, 0); - check_vk_result(err); - p_buffer_size = new_size; -} - -static void ImGui_ImplVulkan_SetupRenderState(ImDrawData* draw_data, VkPipeline pipeline, VkCommandBuffer command_buffer, ImGui_ImplVulkanH_FrameRenderBuffers* rb, int fb_width, int fb_height) -{ - // Bind pipeline and descriptor sets: - { - vkCmdBindPipeline(command_buffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline); - VkDescriptorSet desc_set[1] = { g_DescriptorSet }; - vkCmdBindDescriptorSets(command_buffer, VK_PIPELINE_BIND_POINT_GRAPHICS, g_PipelineLayout, 0, 1, desc_set, 0, NULL); - } - - // Bind Vertex And Index Buffer: - if (draw_data->TotalVtxCount > 0) - { - VkBuffer vertex_buffers[1] = { rb->VertexBuffer }; - VkDeviceSize vertex_offset[1] = { 0 }; - vkCmdBindVertexBuffers(command_buffer, 0, 1, vertex_buffers, vertex_offset); - vkCmdBindIndexBuffer(command_buffer, rb->IndexBuffer, 0, sizeof(ImDrawIdx) == 2 ? VK_INDEX_TYPE_UINT16 : VK_INDEX_TYPE_UINT32); - } - - // Setup viewport: - { - VkViewport viewport; - viewport.x = 0; - viewport.y = 0; - viewport.width = (float)fb_width; - viewport.height = (float)fb_height; - viewport.minDepth = 0.0f; - viewport.maxDepth = 1.0f; - vkCmdSetViewport(command_buffer, 0, 1, &viewport); - } - - // Setup scale and translation: - // Our visible imgui space lies from draw_data->DisplayPps (top left) to draw_data->DisplayPos+data_data->DisplaySize (bottom right). DisplayPos is (0,0) for single viewport apps. - { - float scale[2]; - scale[0] = 2.0f / draw_data->DisplaySize.x; - scale[1] = 2.0f / draw_data->DisplaySize.y; - float translate[2]; - translate[0] = -1.0f - draw_data->DisplayPos.x * scale[0]; - translate[1] = -1.0f - draw_data->DisplayPos.y * scale[1]; - vkCmdPushConstants(command_buffer, g_PipelineLayout, VK_SHADER_STAGE_VERTEX_BIT, sizeof(float) * 0, sizeof(float) * 2, scale); - vkCmdPushConstants(command_buffer, g_PipelineLayout, VK_SHADER_STAGE_VERTEX_BIT, sizeof(float) * 2, sizeof(float) * 2, translate); - } -} - -// Render function -void ImGui_ImplVulkan_RenderDrawData(ImDrawData* draw_data, VkCommandBuffer command_buffer, VkPipeline pipeline) -{ - // Avoid rendering when minimized, scale coordinates for retina displays (screen coordinates != framebuffer coordinates) - int fb_width = (int)(draw_data->DisplaySize.x * draw_data->FramebufferScale.x); - int fb_height = (int)(draw_data->DisplaySize.y * draw_data->FramebufferScale.y); - if (fb_width <= 0 || fb_height <= 0) - return; - - ImGui_ImplVulkan_InitInfo* v = &g_VulkanInitInfo; - if (pipeline == VK_NULL_HANDLE) - pipeline = g_Pipeline; - - // Allocate array to store enough vertex/index buffers - ImGui_ImplVulkanH_WindowRenderBuffers* wrb = &g_MainWindowRenderBuffers; - if (wrb->FrameRenderBuffers == NULL) - { - wrb->Index = 0; - wrb->Count = v->ImageCount; - wrb->FrameRenderBuffers = (ImGui_ImplVulkanH_FrameRenderBuffers*)IM_ALLOC(sizeof(ImGui_ImplVulkanH_FrameRenderBuffers) * wrb->Count); - memset(wrb->FrameRenderBuffers, 0, sizeof(ImGui_ImplVulkanH_FrameRenderBuffers) * wrb->Count); - } - IM_ASSERT(wrb->Count == v->ImageCount); - wrb->Index = (wrb->Index + 1) % wrb->Count; - ImGui_ImplVulkanH_FrameRenderBuffers* rb = &wrb->FrameRenderBuffers[wrb->Index]; - - if (draw_data->TotalVtxCount > 0) - { - // Create or resize the vertex/index buffers - size_t vertex_size = draw_data->TotalVtxCount * sizeof(ImDrawVert); - size_t index_size = draw_data->TotalIdxCount * sizeof(ImDrawIdx); - if (rb->VertexBuffer == VK_NULL_HANDLE || rb->VertexBufferSize < vertex_size) - CreateOrResizeBuffer(rb->VertexBuffer, rb->VertexBufferMemory, rb->VertexBufferSize, vertex_size, VK_BUFFER_USAGE_VERTEX_BUFFER_BIT); - if (rb->IndexBuffer == VK_NULL_HANDLE || rb->IndexBufferSize < index_size) - CreateOrResizeBuffer(rb->IndexBuffer, rb->IndexBufferMemory, rb->IndexBufferSize, index_size, VK_BUFFER_USAGE_INDEX_BUFFER_BIT); - - // Upload vertex/index data into a single contiguous GPU buffer - ImDrawVert* vtx_dst = NULL; - ImDrawIdx* idx_dst = NULL; - VkResult err = vkMapMemory(v->Device, rb->VertexBufferMemory, 0, vertex_size, 0, (void**)(&vtx_dst)); - check_vk_result(err); - err = vkMapMemory(v->Device, rb->IndexBufferMemory, 0, index_size, 0, (void**)(&idx_dst)); - check_vk_result(err); - for (int n = 0; n < draw_data->CmdListsCount; n++) - { - const ImDrawList* cmd_list = draw_data->CmdLists[n]; - memcpy(vtx_dst, cmd_list->VtxBuffer.Data, cmd_list->VtxBuffer.Size * sizeof(ImDrawVert)); - memcpy(idx_dst, cmd_list->IdxBuffer.Data, cmd_list->IdxBuffer.Size * sizeof(ImDrawIdx)); - vtx_dst += cmd_list->VtxBuffer.Size; - idx_dst += cmd_list->IdxBuffer.Size; - } - VkMappedMemoryRange range[2] = {}; - range[0].sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE; - range[0].memory = rb->VertexBufferMemory; - range[0].size = VK_WHOLE_SIZE; - range[1].sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE; - range[1].memory = rb->IndexBufferMemory; - range[1].size = VK_WHOLE_SIZE; - err = vkFlushMappedMemoryRanges(v->Device, 2, range); - check_vk_result(err); - vkUnmapMemory(v->Device, rb->VertexBufferMemory); - vkUnmapMemory(v->Device, rb->IndexBufferMemory); - } - - // Setup desired Vulkan state - ImGui_ImplVulkan_SetupRenderState(draw_data, pipeline, command_buffer, rb, fb_width, fb_height); - - // Will project scissor/clipping rectangles into framebuffer space - ImVec2 clip_off = draw_data->DisplayPos; // (0,0) unless using multi-viewports - ImVec2 clip_scale = draw_data->FramebufferScale; // (1,1) unless using retina display which are often (2,2) - - // Render command lists - // (Because we merged all buffers into a single one, we maintain our own offset into them) - int global_vtx_offset = 0; - int global_idx_offset = 0; - for (int n = 0; n < draw_data->CmdListsCount; n++) - { - const ImDrawList* cmd_list = draw_data->CmdLists[n]; - for (int cmd_i = 0; cmd_i < cmd_list->CmdBuffer.Size; cmd_i++) - { - const ImDrawCmd* pcmd = &cmd_list->CmdBuffer[cmd_i]; - if (pcmd->UserCallback != NULL) - { - // User callback, registered via ImDrawList::AddCallback() - // (ImDrawCallback_ResetRenderState is a special callback value used by the user to request the renderer to reset render state.) - if (pcmd->UserCallback == ImDrawCallback_ResetRenderState) - ImGui_ImplVulkan_SetupRenderState(draw_data, pipeline, command_buffer, rb, fb_width, fb_height); - else - pcmd->UserCallback(cmd_list, pcmd); - } - else - { - // Project scissor/clipping rectangles into framebuffer space - ImVec4 clip_rect; - clip_rect.x = (pcmd->ClipRect.x - clip_off.x) * clip_scale.x; - clip_rect.y = (pcmd->ClipRect.y - clip_off.y) * clip_scale.y; - clip_rect.z = (pcmd->ClipRect.z - clip_off.x) * clip_scale.x; - clip_rect.w = (pcmd->ClipRect.w - clip_off.y) * clip_scale.y; - - if (clip_rect.x < fb_width && clip_rect.y < fb_height && clip_rect.z >= 0.0f && clip_rect.w >= 0.0f) - { - // Negative offsets are illegal for vkCmdSetScissor - if (clip_rect.x < 0.0f) - clip_rect.x = 0.0f; - if (clip_rect.y < 0.0f) - clip_rect.y = 0.0f; - - // Apply scissor/clipping rectangle - VkRect2D scissor; - scissor.offset.x = (int32_t)(clip_rect.x); - scissor.offset.y = (int32_t)(clip_rect.y); - scissor.extent.width = (uint32_t)(clip_rect.z - clip_rect.x); - scissor.extent.height = (uint32_t)(clip_rect.w - clip_rect.y); - vkCmdSetScissor(command_buffer, 0, 1, &scissor); - - // Draw - vkCmdDrawIndexed(command_buffer, pcmd->ElemCount, 1, pcmd->IdxOffset + global_idx_offset, pcmd->VtxOffset + global_vtx_offset, 0); - } - } - } - global_idx_offset += cmd_list->IdxBuffer.Size; - global_vtx_offset += cmd_list->VtxBuffer.Size; - } -} - -bool ImGui_ImplVulkan_CreateFontsTexture(VkCommandBuffer command_buffer) -{ - ImGui_ImplVulkan_InitInfo* v = &g_VulkanInitInfo; - ImGuiIO& io = ImGui::GetIO(); - - unsigned char* pixels; - int width, height; - io.Fonts->GetTexDataAsRGBA32(&pixels, &width, &height); - size_t upload_size = width * height * 4 * sizeof(char); - - VkResult err; - - // Create the Image: - { - VkImageCreateInfo info = {}; - info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; - info.imageType = VK_IMAGE_TYPE_2D; - info.format = VK_FORMAT_R8G8B8A8_UNORM; - info.extent.width = width; - info.extent.height = height; - info.extent.depth = 1; - info.mipLevels = 1; - info.arrayLayers = 1; - info.samples = VK_SAMPLE_COUNT_1_BIT; - info.tiling = VK_IMAGE_TILING_OPTIMAL; - info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT; - info.sharingMode = VK_SHARING_MODE_EXCLUSIVE; - info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED; - err = vkCreateImage(v->Device, &info, v->Allocator, &g_FontImage); - check_vk_result(err); - VkMemoryRequirements req; - vkGetImageMemoryRequirements(v->Device, g_FontImage, &req); - VkMemoryAllocateInfo alloc_info = {}; - alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; - alloc_info.allocationSize = req.size; - alloc_info.memoryTypeIndex = ImGui_ImplVulkan_MemoryType(VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, req.memoryTypeBits); - err = vkAllocateMemory(v->Device, &alloc_info, v->Allocator, &g_FontMemory); - check_vk_result(err); - err = vkBindImageMemory(v->Device, g_FontImage, g_FontMemory, 0); - check_vk_result(err); - } - - // Create the Image View: - { - VkImageViewCreateInfo info = {}; - info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; - info.image = g_FontImage; - info.viewType = VK_IMAGE_VIEW_TYPE_2D; - info.format = VK_FORMAT_R8G8B8A8_UNORM; - info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; - info.subresourceRange.levelCount = 1; - info.subresourceRange.layerCount = 1; - err = vkCreateImageView(v->Device, &info, v->Allocator, &g_FontView); - check_vk_result(err); - } - - // Update the Descriptor Set: - { - VkDescriptorImageInfo desc_image[1] = {}; - desc_image[0].sampler = g_FontSampler; - desc_image[0].imageView = g_FontView; - desc_image[0].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; - VkWriteDescriptorSet write_desc[1] = {}; - write_desc[0].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; - write_desc[0].dstSet = g_DescriptorSet; - write_desc[0].descriptorCount = 1; - write_desc[0].descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER; - write_desc[0].pImageInfo = desc_image; - vkUpdateDescriptorSets(v->Device, 1, write_desc, 0, NULL); - } - - // Create the Upload Buffer: - { - VkBufferCreateInfo buffer_info = {}; - buffer_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; - buffer_info.size = upload_size; - buffer_info.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT; - buffer_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE; - err = vkCreateBuffer(v->Device, &buffer_info, v->Allocator, &g_UploadBuffer); - check_vk_result(err); - VkMemoryRequirements req; - vkGetBufferMemoryRequirements(v->Device, g_UploadBuffer, &req); - g_BufferMemoryAlignment = (g_BufferMemoryAlignment > req.alignment) ? g_BufferMemoryAlignment : req.alignment; - VkMemoryAllocateInfo alloc_info = {}; - alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; - alloc_info.allocationSize = req.size; - alloc_info.memoryTypeIndex = ImGui_ImplVulkan_MemoryType(VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT, req.memoryTypeBits); - err = vkAllocateMemory(v->Device, &alloc_info, v->Allocator, &g_UploadBufferMemory); - check_vk_result(err); - err = vkBindBufferMemory(v->Device, g_UploadBuffer, g_UploadBufferMemory, 0); - check_vk_result(err); - } - - // Upload to Buffer: - { - char* map = NULL; - err = vkMapMemory(v->Device, g_UploadBufferMemory, 0, upload_size, 0, (void**)(&map)); - check_vk_result(err); - memcpy(map, pixels, upload_size); - VkMappedMemoryRange range[1] = {}; - range[0].sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE; - range[0].memory = g_UploadBufferMemory; - range[0].size = upload_size; - err = vkFlushMappedMemoryRanges(v->Device, 1, range); - check_vk_result(err); - vkUnmapMemory(v->Device, g_UploadBufferMemory); - } - - // Copy to Image: - { - VkImageMemoryBarrier copy_barrier[1] = {}; - copy_barrier[0].sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER; - copy_barrier[0].dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT; - copy_barrier[0].oldLayout = VK_IMAGE_LAYOUT_UNDEFINED; - copy_barrier[0].newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL; - copy_barrier[0].srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; - copy_barrier[0].dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; - copy_barrier[0].image = g_FontImage; - copy_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; - copy_barrier[0].subresourceRange.levelCount = 1; - copy_barrier[0].subresourceRange.layerCount = 1; - vkCmdPipelineBarrier(command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, 0, 0, NULL, 0, NULL, 1, copy_barrier); - - VkBufferImageCopy region = {}; - region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; - region.imageSubresource.layerCount = 1; - region.imageExtent.width = width; - region.imageExtent.height = height; - region.imageExtent.depth = 1; - vkCmdCopyBufferToImage(command_buffer, g_UploadBuffer, g_FontImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, ®ion); - - VkImageMemoryBarrier use_barrier[1] = {}; - use_barrier[0].sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER; - use_barrier[0].srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT; - use_barrier[0].dstAccessMask = VK_ACCESS_SHADER_READ_BIT; - use_barrier[0].oldLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL; - use_barrier[0].newLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; - use_barrier[0].srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; - use_barrier[0].dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; - use_barrier[0].image = g_FontImage; - use_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; - use_barrier[0].subresourceRange.levelCount = 1; - use_barrier[0].subresourceRange.layerCount = 1; - vkCmdPipelineBarrier(command_buffer, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT, 0, 0, NULL, 0, NULL, 1, use_barrier); - } - - // Store our identifier - io.Fonts->SetTexID((ImTextureID)(intptr_t)g_FontImage); - - return true; -} - -static void ImGui_ImplVulkan_CreateShaderModules(VkDevice device, const VkAllocationCallbacks* allocator) -{ - // Create the shader modules - if (g_ShaderModuleVert == NULL) - { - VkShaderModuleCreateInfo vert_info = {}; - vert_info.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO; - vert_info.codeSize = sizeof(__glsl_shader_vert_spv); - vert_info.pCode = (uint32_t*)__glsl_shader_vert_spv; - VkResult err = vkCreateShaderModule(device, &vert_info, allocator, &g_ShaderModuleVert); - check_vk_result(err); - } - if (g_ShaderModuleFrag == NULL) - { - VkShaderModuleCreateInfo frag_info = {}; - frag_info.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO; - frag_info.codeSize = sizeof(__glsl_shader_frag_spv); - frag_info.pCode = (uint32_t*)__glsl_shader_frag_spv; - VkResult err = vkCreateShaderModule(device, &frag_info, allocator, &g_ShaderModuleFrag); - check_vk_result(err); - } -} - -static void ImGui_ImplVulkan_CreateFontSampler(VkDevice device, const VkAllocationCallbacks* allocator) -{ - if (g_FontSampler) - return; - - VkSamplerCreateInfo info = {}; - info.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO; - info.magFilter = VK_FILTER_LINEAR; - info.minFilter = VK_FILTER_LINEAR; - info.mipmapMode = VK_SAMPLER_MIPMAP_MODE_LINEAR; - info.addressModeU = VK_SAMPLER_ADDRESS_MODE_REPEAT; - info.addressModeV = VK_SAMPLER_ADDRESS_MODE_REPEAT; - info.addressModeW = VK_SAMPLER_ADDRESS_MODE_REPEAT; - info.minLod = -1000; - info.maxLod = 1000; - info.maxAnisotropy = 1.0f; - VkResult err = vkCreateSampler(device, &info, allocator, &g_FontSampler); - check_vk_result(err); -} - -static void ImGui_ImplVulkan_CreateDescriptorSetLayout(VkDevice device, const VkAllocationCallbacks* allocator) -{ - if (g_DescriptorSetLayout) - return; - - ImGui_ImplVulkan_CreateFontSampler(device, allocator); - VkSampler sampler[1] = { g_FontSampler }; - VkDescriptorSetLayoutBinding binding[1] = {}; - binding[0].descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER; - binding[0].descriptorCount = 1; - binding[0].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT; - binding[0].pImmutableSamplers = sampler; - VkDescriptorSetLayoutCreateInfo info = {}; - info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; - info.bindingCount = 1; - info.pBindings = binding; - VkResult err = vkCreateDescriptorSetLayout(device, &info, allocator, &g_DescriptorSetLayout); - check_vk_result(err); -} - -static void ImGui_ImplVulkan_CreatePipelineLayout(VkDevice device, const VkAllocationCallbacks* allocator) -{ - if (g_PipelineLayout) - return; - - // Constants: we are using 'vec2 offset' and 'vec2 scale' instead of a full 3d projection matrix - ImGui_ImplVulkan_CreateDescriptorSetLayout(device, allocator); - VkPushConstantRange push_constants[1] = {}; - push_constants[0].stageFlags = VK_SHADER_STAGE_VERTEX_BIT; - push_constants[0].offset = sizeof(float) * 0; - push_constants[0].size = sizeof(float) * 4; - VkDescriptorSetLayout set_layout[1] = { g_DescriptorSetLayout }; - VkPipelineLayoutCreateInfo layout_info = {}; - layout_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; - layout_info.setLayoutCount = 1; - layout_info.pSetLayouts = set_layout; - layout_info.pushConstantRangeCount = 1; - layout_info.pPushConstantRanges = push_constants; - VkResult err = vkCreatePipelineLayout(device, &layout_info, allocator, &g_PipelineLayout); - check_vk_result(err); -} - -static void ImGui_ImplVulkan_CreatePipeline(VkDevice device, const VkAllocationCallbacks* allocator, VkPipelineCache pipelineCache, VkRenderPass renderPass, VkSampleCountFlagBits MSAASamples, VkPipeline* pipeline, uint32_t subpass) -{ - ImGui_ImplVulkan_CreateShaderModules(device, allocator); - - VkPipelineShaderStageCreateInfo stage[2] = {}; - stage[0].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; - stage[0].stage = VK_SHADER_STAGE_VERTEX_BIT; - stage[0].module = g_ShaderModuleVert; - stage[0].pName = "main"; - stage[1].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; - stage[1].stage = VK_SHADER_STAGE_FRAGMENT_BIT; - stage[1].module = g_ShaderModuleFrag; - stage[1].pName = "main"; - - VkVertexInputBindingDescription binding_desc[1] = {}; - binding_desc[0].stride = sizeof(ImDrawVert); - binding_desc[0].inputRate = VK_VERTEX_INPUT_RATE_VERTEX; - - VkVertexInputAttributeDescription attribute_desc[3] = {}; - attribute_desc[0].location = 0; - attribute_desc[0].binding = binding_desc[0].binding; - attribute_desc[0].format = VK_FORMAT_R32G32_SFLOAT; - attribute_desc[0].offset = IM_OFFSETOF(ImDrawVert, pos); - attribute_desc[1].location = 1; - attribute_desc[1].binding = binding_desc[0].binding; - attribute_desc[1].format = VK_FORMAT_R32G32_SFLOAT; - attribute_desc[1].offset = IM_OFFSETOF(ImDrawVert, uv); - attribute_desc[2].location = 2; - attribute_desc[2].binding = binding_desc[0].binding; - attribute_desc[2].format = VK_FORMAT_R8G8B8A8_UNORM; - attribute_desc[2].offset = IM_OFFSETOF(ImDrawVert, col); - - VkPipelineVertexInputStateCreateInfo vertex_info = {}; - vertex_info.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO; - vertex_info.vertexBindingDescriptionCount = 1; - vertex_info.pVertexBindingDescriptions = binding_desc; - vertex_info.vertexAttributeDescriptionCount = 3; - vertex_info.pVertexAttributeDescriptions = attribute_desc; - - VkPipelineInputAssemblyStateCreateInfo ia_info = {}; - ia_info.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO; - ia_info.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST; - - VkPipelineViewportStateCreateInfo viewport_info = {}; - viewport_info.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO; - viewport_info.viewportCount = 1; - viewport_info.scissorCount = 1; - - VkPipelineRasterizationStateCreateInfo raster_info = {}; - raster_info.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO; - raster_info.polygonMode = VK_POLYGON_MODE_FILL; - raster_info.cullMode = VK_CULL_MODE_NONE; - raster_info.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE; - raster_info.lineWidth = 1.0f; - - VkPipelineMultisampleStateCreateInfo ms_info = {}; - ms_info.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO; - ms_info.rasterizationSamples = (MSAASamples != 0) ? MSAASamples : VK_SAMPLE_COUNT_1_BIT; - - VkPipelineColorBlendAttachmentState color_attachment[1] = {}; - color_attachment[0].blendEnable = VK_TRUE; - color_attachment[0].srcColorBlendFactor = VK_BLEND_FACTOR_SRC_ALPHA; - color_attachment[0].dstColorBlendFactor = VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA; - color_attachment[0].colorBlendOp = VK_BLEND_OP_ADD; - color_attachment[0].srcAlphaBlendFactor = VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA; - color_attachment[0].dstAlphaBlendFactor = VK_BLEND_FACTOR_ZERO; - color_attachment[0].alphaBlendOp = VK_BLEND_OP_ADD; - color_attachment[0].colorWriteMask = VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT | VK_COLOR_COMPONENT_B_BIT | VK_COLOR_COMPONENT_A_BIT; - - VkPipelineDepthStencilStateCreateInfo depth_info = {}; - depth_info.sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO; - - VkPipelineColorBlendStateCreateInfo blend_info = {}; - blend_info.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO; - blend_info.attachmentCount = 1; - blend_info.pAttachments = color_attachment; - - VkDynamicState dynamic_states[2] = { VK_DYNAMIC_STATE_VIEWPORT, VK_DYNAMIC_STATE_SCISSOR }; - VkPipelineDynamicStateCreateInfo dynamic_state = {}; - dynamic_state.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO; - dynamic_state.dynamicStateCount = (uint32_t)IM_ARRAYSIZE(dynamic_states); - dynamic_state.pDynamicStates = dynamic_states; - - ImGui_ImplVulkan_CreatePipelineLayout(device, allocator); - - VkGraphicsPipelineCreateInfo info = {}; - info.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; - info.flags = g_PipelineCreateFlags; - info.stageCount = 2; - info.pStages = stage; - info.pVertexInputState = &vertex_info; - info.pInputAssemblyState = &ia_info; - info.pViewportState = &viewport_info; - info.pRasterizationState = &raster_info; - info.pMultisampleState = &ms_info; - info.pDepthStencilState = &depth_info; - info.pColorBlendState = &blend_info; - info.pDynamicState = &dynamic_state; - info.layout = g_PipelineLayout; - info.renderPass = renderPass; - info.subpass = subpass; - VkResult err = vkCreateGraphicsPipelines(device, pipelineCache, 1, &info, allocator, pipeline); - check_vk_result(err); -} - -bool ImGui_ImplVulkan_CreateDeviceObjects() -{ - ImGui_ImplVulkan_InitInfo* v = &g_VulkanInitInfo; - VkResult err; - - if (!g_FontSampler) - { - VkSamplerCreateInfo info = {}; - info.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO; - info.magFilter = VK_FILTER_LINEAR; - info.minFilter = VK_FILTER_LINEAR; - info.mipmapMode = VK_SAMPLER_MIPMAP_MODE_LINEAR; - info.addressModeU = VK_SAMPLER_ADDRESS_MODE_REPEAT; - info.addressModeV = VK_SAMPLER_ADDRESS_MODE_REPEAT; - info.addressModeW = VK_SAMPLER_ADDRESS_MODE_REPEAT; - info.minLod = -1000; - info.maxLod = 1000; - info.maxAnisotropy = 1.0f; - err = vkCreateSampler(v->Device, &info, v->Allocator, &g_FontSampler); - check_vk_result(err); - } - - if (!g_DescriptorSetLayout) - { - VkSampler sampler[1] = {g_FontSampler}; - VkDescriptorSetLayoutBinding binding[1] = {}; - binding[0].descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER; - binding[0].descriptorCount = 1; - binding[0].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT; - binding[0].pImmutableSamplers = sampler; - VkDescriptorSetLayoutCreateInfo info = {}; - info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; - info.bindingCount = 1; - info.pBindings = binding; - err = vkCreateDescriptorSetLayout(v->Device, &info, v->Allocator, &g_DescriptorSetLayout); - check_vk_result(err); - } - - // Create Descriptor Set: - { - VkDescriptorSetAllocateInfo alloc_info = {}; - alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; - alloc_info.descriptorPool = v->DescriptorPool; - alloc_info.descriptorSetCount = 1; - alloc_info.pSetLayouts = &g_DescriptorSetLayout; - err = vkAllocateDescriptorSets(v->Device, &alloc_info, &g_DescriptorSet); - check_vk_result(err); - } - - if (!g_PipelineLayout) - { - // Constants: we are using 'vec2 offset' and 'vec2 scale' instead of a full 3d projection matrix - VkPushConstantRange push_constants[1] = {}; - push_constants[0].stageFlags = VK_SHADER_STAGE_VERTEX_BIT; - push_constants[0].offset = sizeof(float) * 0; - push_constants[0].size = sizeof(float) * 4; - VkDescriptorSetLayout set_layout[1] = { g_DescriptorSetLayout }; - VkPipelineLayoutCreateInfo layout_info = {}; - layout_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; - layout_info.setLayoutCount = 1; - layout_info.pSetLayouts = set_layout; - layout_info.pushConstantRangeCount = 1; - layout_info.pPushConstantRanges = push_constants; - err = vkCreatePipelineLayout(v->Device, &layout_info, v->Allocator, &g_PipelineLayout); - check_vk_result(err); - } - - ImGui_ImplVulkan_CreatePipeline(v->Device, v->Allocator, v->PipelineCache, g_RenderPass, v->MSAASamples, &g_Pipeline, g_Subpass); - - return true; -} - -void ImGui_ImplVulkan_DestroyFontUploadObjects() -{ - ImGui_ImplVulkan_InitInfo* v = &g_VulkanInitInfo; - if (g_UploadBuffer) - { - vkDestroyBuffer(v->Device, g_UploadBuffer, v->Allocator); - g_UploadBuffer = VK_NULL_HANDLE; - } - if (g_UploadBufferMemory) - { - vkFreeMemory(v->Device, g_UploadBufferMemory, v->Allocator); - g_UploadBufferMemory = VK_NULL_HANDLE; - } -} - -void ImGui_ImplVulkan_DestroyDeviceObjects() -{ - ImGui_ImplVulkan_InitInfo* v = &g_VulkanInitInfo; - ImGui_ImplVulkanH_DestroyWindowRenderBuffers(v->Device, &g_MainWindowRenderBuffers, v->Allocator); - ImGui_ImplVulkan_DestroyFontUploadObjects(); - - if (g_ShaderModuleVert) { vkDestroyShaderModule(v->Device, g_ShaderModuleVert, v->Allocator); g_ShaderModuleVert = VK_NULL_HANDLE; } - if (g_ShaderModuleFrag) { vkDestroyShaderModule(v->Device, g_ShaderModuleFrag, v->Allocator); g_ShaderModuleFrag = VK_NULL_HANDLE; } - if (g_FontView) { vkDestroyImageView(v->Device, g_FontView, v->Allocator); g_FontView = VK_NULL_HANDLE; } - if (g_FontImage) { vkDestroyImage(v->Device, g_FontImage, v->Allocator); g_FontImage = VK_NULL_HANDLE; } - if (g_FontMemory) { vkFreeMemory(v->Device, g_FontMemory, v->Allocator); g_FontMemory = VK_NULL_HANDLE; } - if (g_FontSampler) { vkDestroySampler(v->Device, g_FontSampler, v->Allocator); g_FontSampler = VK_NULL_HANDLE; } - if (g_DescriptorSetLayout) { vkDestroyDescriptorSetLayout(v->Device, g_DescriptorSetLayout, v->Allocator); g_DescriptorSetLayout = VK_NULL_HANDLE; } - if (g_PipelineLayout) { vkDestroyPipelineLayout(v->Device, g_PipelineLayout, v->Allocator); g_PipelineLayout = VK_NULL_HANDLE; } - if (g_Pipeline) { vkDestroyPipeline(v->Device, g_Pipeline, v->Allocator); g_Pipeline = VK_NULL_HANDLE; } -} - -bool ImGui_ImplVulkan_LoadFunctions(PFN_vkVoidFunction(*loader_func)(const char* function_name, void* user_data), void* user_data) -{ - // Load function pointers - // You can use the default Vulkan loader using: - // ImGui_ImplVulkan_LoadFunctions([](const char* function_name, void*) { return vkGetInstanceProcAddr(your_vk_isntance, function_name); }); - // But this would be equivalent to not setting VK_NO_PROTOTYPES. -#ifdef VK_NO_PROTOTYPES -#define IMGUI_VULKAN_FUNC_LOAD(func) \ - func = reinterpret_cast(loader_func(#func, user_data)); \ - if (func == NULL) \ - return false; - IMGUI_VULKAN_FUNC_MAP(IMGUI_VULKAN_FUNC_LOAD) -#undef IMGUI_VULKAN_FUNC_LOAD -#else - IM_UNUSED(loader_func); - IM_UNUSED(user_data); -#endif - g_FunctionsLoaded = true; - return true; -} - -bool ImGui_ImplVulkan_Init(ImGui_ImplVulkan_InitInfo* info, VkRenderPass render_pass) -{ - IM_ASSERT(g_FunctionsLoaded && "Need to call ImGui_ImplVulkan_LoadFunctions() if IMGUI_IMPL_VULKAN_NO_PROTOTYPES or VK_NO_PROTOTYPES are set!"); - - // Setup backend capabilities flags - ImGuiIO& io = ImGui::GetIO(); - io.BackendRendererName = "imgui_impl_vulkan"; - io.BackendFlags |= ImGuiBackendFlags_RendererHasVtxOffset; // We can honor the ImDrawCmd::VtxOffset field, allowing for large meshes. - - IM_ASSERT(info->Instance != VK_NULL_HANDLE); - IM_ASSERT(info->PhysicalDevice != VK_NULL_HANDLE); - IM_ASSERT(info->Device != VK_NULL_HANDLE); - IM_ASSERT(info->Queue != VK_NULL_HANDLE); - IM_ASSERT(info->DescriptorPool != VK_NULL_HANDLE); - IM_ASSERT(info->MinImageCount >= 2); - IM_ASSERT(info->ImageCount >= info->MinImageCount); - IM_ASSERT(render_pass != VK_NULL_HANDLE); - - g_VulkanInitInfo = *info; - g_RenderPass = render_pass; - g_Subpass = info->Subpass; - - ImGui_ImplVulkan_CreateDeviceObjects(); - - return true; -} - -void ImGui_ImplVulkan_Shutdown() -{ - ImGui_ImplVulkan_DestroyDeviceObjects(); -} - -void ImGui_ImplVulkan_NewFrame() -{ -} - -void ImGui_ImplVulkan_SetMinImageCount(uint32_t min_image_count) -{ - IM_ASSERT(min_image_count >= 2); - if (g_VulkanInitInfo.MinImageCount == min_image_count) - return; - - ImGui_ImplVulkan_InitInfo* v = &g_VulkanInitInfo; - VkResult err = vkDeviceWaitIdle(v->Device); - check_vk_result(err); - ImGui_ImplVulkanH_DestroyWindowRenderBuffers(v->Device, &g_MainWindowRenderBuffers, v->Allocator); - g_VulkanInitInfo.MinImageCount = min_image_count; -} - - -//------------------------------------------------------------------------- -// Internal / Miscellaneous Vulkan Helpers -// (Used by example's main.cpp. Used by multi-viewport features. PROBABLY NOT used by your own app.) -//------------------------------------------------------------------------- -// You probably do NOT need to use or care about those functions. -// Those functions only exist because: -// 1) they facilitate the readability and maintenance of the multiple main.cpp examples files. -// 2) the upcoming multi-viewport feature will need them internally. -// Generally we avoid exposing any kind of superfluous high-level helpers in the backends, -// but it is too much code to duplicate everywhere so we exceptionally expose them. -// -// Your engine/app will likely _already_ have code to setup all that stuff (swap chain, render pass, frame buffers, etc.). -// You may read this code to learn about Vulkan, but it is recommended you use you own custom tailored code to do equivalent work. -// (The ImGui_ImplVulkanH_XXX functions do not interact with any of the state used by the regular ImGui_ImplVulkan_XXX functions) -//------------------------------------------------------------------------- - -VkSurfaceFormatKHR ImGui_ImplVulkanH_SelectSurfaceFormat(VkPhysicalDevice physical_device, VkSurfaceKHR surface, const VkFormat* request_formats, int request_formats_count, VkColorSpaceKHR request_color_space) -{ - IM_ASSERT(g_FunctionsLoaded && "Need to call ImGui_ImplVulkan_LoadFunctions() if IMGUI_IMPL_VULKAN_NO_PROTOTYPES or VK_NO_PROTOTYPES are set!"); - IM_ASSERT(request_formats != NULL); - IM_ASSERT(request_formats_count > 0); - - // Per Spec Format and View Format are expected to be the same unless VK_IMAGE_CREATE_MUTABLE_BIT was set at image creation - // Assuming that the default behavior is without setting this bit, there is no need for separate Swapchain image and image view format - // Additionally several new color spaces were introduced with Vulkan Spec v1.0.40, - // hence we must make sure that a format with the mostly available color space, VK_COLOR_SPACE_SRGB_NONLINEAR_KHR, is found and used. - uint32_t avail_count; - vkGetPhysicalDeviceSurfaceFormatsKHR(physical_device, surface, &avail_count, NULL); - ImVector avail_format; - avail_format.resize((int)avail_count); - vkGetPhysicalDeviceSurfaceFormatsKHR(physical_device, surface, &avail_count, avail_format.Data); - - // First check if only one format, VK_FORMAT_UNDEFINED, is available, which would imply that any format is available - if (avail_count == 1) - { - if (avail_format[0].format == VK_FORMAT_UNDEFINED) - { - VkSurfaceFormatKHR ret; - ret.format = request_formats[0]; - ret.colorSpace = request_color_space; - return ret; - } - else - { - // No point in searching another format - return avail_format[0]; - } - } - else - { - // Request several formats, the first found will be used - for (int request_i = 0; request_i < request_formats_count; request_i++) - for (uint32_t avail_i = 0; avail_i < avail_count; avail_i++) - if (avail_format[avail_i].format == request_formats[request_i] && avail_format[avail_i].colorSpace == request_color_space) - return avail_format[avail_i]; - - // If none of the requested image formats could be found, use the first available - return avail_format[0]; - } -} - -VkPresentModeKHR ImGui_ImplVulkanH_SelectPresentMode(VkPhysicalDevice physical_device, VkSurfaceKHR surface, const VkPresentModeKHR* request_modes, int request_modes_count) -{ - IM_ASSERT(g_FunctionsLoaded && "Need to call ImGui_ImplVulkan_LoadFunctions() if IMGUI_IMPL_VULKAN_NO_PROTOTYPES or VK_NO_PROTOTYPES are set!"); - IM_ASSERT(request_modes != NULL); - IM_ASSERT(request_modes_count > 0); - - // Request a certain mode and confirm that it is available. If not use VK_PRESENT_MODE_FIFO_KHR which is mandatory - uint32_t avail_count = 0; - vkGetPhysicalDeviceSurfacePresentModesKHR(physical_device, surface, &avail_count, NULL); - ImVector avail_modes; - avail_modes.resize((int)avail_count); - vkGetPhysicalDeviceSurfacePresentModesKHR(physical_device, surface, &avail_count, avail_modes.Data); - //for (uint32_t avail_i = 0; avail_i < avail_count; avail_i++) - // printf("[vulkan] avail_modes[%d] = %d\n", avail_i, avail_modes[avail_i]); - - for (int request_i = 0; request_i < request_modes_count; request_i++) - for (uint32_t avail_i = 0; avail_i < avail_count; avail_i++) - if (request_modes[request_i] == avail_modes[avail_i]) - return request_modes[request_i]; - - return VK_PRESENT_MODE_FIFO_KHR; // Always available -} - -void ImGui_ImplVulkanH_CreateWindowCommandBuffers(VkPhysicalDevice physical_device, VkDevice device, ImGui_ImplVulkanH_Window* wd, uint32_t queue_family, const VkAllocationCallbacks* allocator) -{ - IM_ASSERT(physical_device != VK_NULL_HANDLE && device != VK_NULL_HANDLE); - (void)physical_device; - (void)allocator; - - // Create Command Buffers - VkResult err; - for (uint32_t i = 0; i < wd->ImageCount; i++) - { - ImGui_ImplVulkanH_Frame* fd = &wd->Frames[i]; - ImGui_ImplVulkanH_FrameSemaphores* fsd = &wd->FrameSemaphores[i]; - { - VkCommandPoolCreateInfo info = {}; - info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; - info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; - info.queueFamilyIndex = queue_family; - err = vkCreateCommandPool(device, &info, allocator, &fd->CommandPool); - check_vk_result(err); - } - { - VkCommandBufferAllocateInfo info = {}; - info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; - info.commandPool = fd->CommandPool; - info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; - info.commandBufferCount = 1; - err = vkAllocateCommandBuffers(device, &info, &fd->CommandBuffer); - check_vk_result(err); - } - { - VkFenceCreateInfo info = {}; - info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; - info.flags = VK_FENCE_CREATE_SIGNALED_BIT; - err = vkCreateFence(device, &info, allocator, &fd->Fence); - check_vk_result(err); - } - { - VkSemaphoreCreateInfo info = {}; - info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO; - err = vkCreateSemaphore(device, &info, allocator, &fsd->ImageAcquiredSemaphore); - check_vk_result(err); - err = vkCreateSemaphore(device, &info, allocator, &fsd->RenderCompleteSemaphore); - check_vk_result(err); - } - } -} - -int ImGui_ImplVulkanH_GetMinImageCountFromPresentMode(VkPresentModeKHR present_mode) -{ - if (present_mode == VK_PRESENT_MODE_MAILBOX_KHR) - return 3; - if (present_mode == VK_PRESENT_MODE_FIFO_KHR || present_mode == VK_PRESENT_MODE_FIFO_RELAXED_KHR) - return 2; - if (present_mode == VK_PRESENT_MODE_IMMEDIATE_KHR) - return 1; - IM_ASSERT(0); - return 1; -} - -// Also destroy old swap chain and in-flight frames data, if any. -void ImGui_ImplVulkanH_CreateWindowSwapChain(VkPhysicalDevice physical_device, VkDevice device, ImGui_ImplVulkanH_Window* wd, const VkAllocationCallbacks* allocator, int w, int h, uint32_t min_image_count) -{ - VkResult err; - VkSwapchainKHR old_swapchain = wd->Swapchain; - wd->Swapchain = NULL; - err = vkDeviceWaitIdle(device); - check_vk_result(err); - - // We don't use ImGui_ImplVulkanH_DestroyWindow() because we want to preserve the old swapchain to create the new one. - // Destroy old Framebuffer - for (uint32_t i = 0; i < wd->ImageCount; i++) - { - ImGui_ImplVulkanH_DestroyFrame(device, &wd->Frames[i], allocator); - ImGui_ImplVulkanH_DestroyFrameSemaphores(device, &wd->FrameSemaphores[i], allocator); - } - IM_FREE(wd->Frames); - IM_FREE(wd->FrameSemaphores); - wd->Frames = NULL; - wd->FrameSemaphores = NULL; - wd->ImageCount = 0; - if (wd->RenderPass) - vkDestroyRenderPass(device, wd->RenderPass, allocator); - if (wd->Pipeline) - vkDestroyPipeline(device, wd->Pipeline, allocator); - - // If min image count was not specified, request different count of images dependent on selected present mode - if (min_image_count == 0) - min_image_count = ImGui_ImplVulkanH_GetMinImageCountFromPresentMode(wd->PresentMode); - - // Create Swapchain - { - VkSwapchainCreateInfoKHR info = {}; - info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR; - info.surface = wd->Surface; - info.minImageCount = min_image_count; - info.imageFormat = wd->SurfaceFormat.format; - info.imageColorSpace = wd->SurfaceFormat.colorSpace; - info.imageArrayLayers = 1; - info.imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; - info.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE; // Assume that graphics family == present family - info.preTransform = VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR; - info.compositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR; - info.presentMode = wd->PresentMode; - info.clipped = VK_TRUE; - info.oldSwapchain = old_swapchain; - VkSurfaceCapabilitiesKHR cap; - err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(physical_device, wd->Surface, &cap); - check_vk_result(err); - if (info.minImageCount < cap.minImageCount) - info.minImageCount = cap.minImageCount; - else if (cap.maxImageCount != 0 && info.minImageCount > cap.maxImageCount) - info.minImageCount = cap.maxImageCount; - - if (cap.currentExtent.width == 0xffffffff) - { - info.imageExtent.width = wd->Width = w; - info.imageExtent.height = wd->Height = h; - } - else - { - info.imageExtent.width = wd->Width = cap.currentExtent.width; - info.imageExtent.height = wd->Height = cap.currentExtent.height; - } - err = vkCreateSwapchainKHR(device, &info, allocator, &wd->Swapchain); - check_vk_result(err); - err = vkGetSwapchainImagesKHR(device, wd->Swapchain, &wd->ImageCount, NULL); - check_vk_result(err); - VkImage backbuffers[16] = {}; - IM_ASSERT(wd->ImageCount >= min_image_count); - IM_ASSERT(wd->ImageCount < IM_ARRAYSIZE(backbuffers)); - err = vkGetSwapchainImagesKHR(device, wd->Swapchain, &wd->ImageCount, backbuffers); - check_vk_result(err); - - IM_ASSERT(wd->Frames == NULL); - wd->Frames = (ImGui_ImplVulkanH_Frame*)IM_ALLOC(sizeof(ImGui_ImplVulkanH_Frame) * wd->ImageCount); - wd->FrameSemaphores = (ImGui_ImplVulkanH_FrameSemaphores*)IM_ALLOC(sizeof(ImGui_ImplVulkanH_FrameSemaphores) * wd->ImageCount); - memset(wd->Frames, 0, sizeof(wd->Frames[0]) * wd->ImageCount); - memset(wd->FrameSemaphores, 0, sizeof(wd->FrameSemaphores[0]) * wd->ImageCount); - for (uint32_t i = 0; i < wd->ImageCount; i++) - wd->Frames[i].Backbuffer = backbuffers[i]; - } - if (old_swapchain) - vkDestroySwapchainKHR(device, old_swapchain, allocator); - - // Create the Render Pass - { - VkAttachmentDescription attachment = {}; - attachment.format = wd->SurfaceFormat.format; - attachment.samples = VK_SAMPLE_COUNT_1_BIT; - attachment.loadOp = wd->ClearEnable ? VK_ATTACHMENT_LOAD_OP_CLEAR : VK_ATTACHMENT_LOAD_OP_DONT_CARE; - attachment.storeOp = VK_ATTACHMENT_STORE_OP_STORE; - attachment.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE; - attachment.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE; - attachment.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED; - attachment.finalLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR; - VkAttachmentReference color_attachment = {}; - color_attachment.attachment = 0; - color_attachment.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; - VkSubpassDescription subpass = {}; - subpass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS; - subpass.colorAttachmentCount = 1; - subpass.pColorAttachments = &color_attachment; - VkSubpassDependency dependency = {}; - dependency.srcSubpass = VK_SUBPASS_EXTERNAL; - dependency.dstSubpass = 0; - dependency.srcStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT; - dependency.dstStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT; - dependency.srcAccessMask = 0; - dependency.dstAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT; - VkRenderPassCreateInfo info = {}; - info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO; - info.attachmentCount = 1; - info.pAttachments = &attachment; - info.subpassCount = 1; - info.pSubpasses = &subpass; - info.dependencyCount = 1; - info.pDependencies = &dependency; - err = vkCreateRenderPass(device, &info, allocator, &wd->RenderPass); - check_vk_result(err); - - // We do not create a pipeline by default as this is also used by examples' main.cpp, - // but secondary viewport in multi-viewport mode may want to create one with: - //ImGui_ImplVulkan_CreatePipeline(device, allocator, VK_NULL_HANDLE, wd->RenderPass, VK_SAMPLE_COUNT_1_BIT, &wd->Pipeline, g_Subpass); - } - - // Create The Image Views - { - VkImageViewCreateInfo info = {}; - info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; - info.viewType = VK_IMAGE_VIEW_TYPE_2D; - info.format = wd->SurfaceFormat.format; - info.components.r = VK_COMPONENT_SWIZZLE_R; - info.components.g = VK_COMPONENT_SWIZZLE_G; - info.components.b = VK_COMPONENT_SWIZZLE_B; - info.components.a = VK_COMPONENT_SWIZZLE_A; - VkImageSubresourceRange image_range = { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 }; - info.subresourceRange = image_range; - for (uint32_t i = 0; i < wd->ImageCount; i++) - { - ImGui_ImplVulkanH_Frame* fd = &wd->Frames[i]; - info.image = fd->Backbuffer; - err = vkCreateImageView(device, &info, allocator, &fd->BackbufferView); - check_vk_result(err); - } - } - - // Create Framebuffer - { - VkImageView attachment[1]; - VkFramebufferCreateInfo info = {}; - info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO; - info.renderPass = wd->RenderPass; - info.attachmentCount = 1; - info.pAttachments = attachment; - info.width = wd->Width; - info.height = wd->Height; - info.layers = 1; - for (uint32_t i = 0; i < wd->ImageCount; i++) - { - ImGui_ImplVulkanH_Frame* fd = &wd->Frames[i]; - attachment[0] = fd->BackbufferView; - err = vkCreateFramebuffer(device, &info, allocator, &fd->Framebuffer); - check_vk_result(err); - } - } -} - -// Create or resize window -void ImGui_ImplVulkanH_CreateOrResizeWindow(VkInstance instance, VkPhysicalDevice physical_device, VkDevice device, ImGui_ImplVulkanH_Window* wd, uint32_t queue_family, const VkAllocationCallbacks* allocator, int width, int height, uint32_t min_image_count) -{ - IM_ASSERT(g_FunctionsLoaded && "Need to call ImGui_ImplVulkan_LoadFunctions() if IMGUI_IMPL_VULKAN_NO_PROTOTYPES or VK_NO_PROTOTYPES are set!"); - (void)instance; - ImGui_ImplVulkanH_CreateWindowSwapChain(physical_device, device, wd, allocator, width, height, min_image_count); - ImGui_ImplVulkanH_CreateWindowCommandBuffers(physical_device, device, wd, queue_family, allocator); -} - -void ImGui_ImplVulkanH_DestroyWindow(VkInstance instance, VkDevice device, ImGui_ImplVulkanH_Window* wd, const VkAllocationCallbacks* allocator) -{ - vkDeviceWaitIdle(device); // FIXME: We could wait on the Queue if we had the queue in wd-> (otherwise VulkanH functions can't use globals) - //vkQueueWaitIdle(g_Queue); - - for (uint32_t i = 0; i < wd->ImageCount; i++) - { - ImGui_ImplVulkanH_DestroyFrame(device, &wd->Frames[i], allocator); - ImGui_ImplVulkanH_DestroyFrameSemaphores(device, &wd->FrameSemaphores[i], allocator); - } - IM_FREE(wd->Frames); - IM_FREE(wd->FrameSemaphores); - wd->Frames = NULL; - wd->FrameSemaphores = NULL; - vkDestroyPipeline(device, wd->Pipeline, allocator); - vkDestroyRenderPass(device, wd->RenderPass, allocator); - vkDestroySwapchainKHR(device, wd->Swapchain, allocator); - vkDestroySurfaceKHR(instance, wd->Surface, allocator); - - *wd = ImGui_ImplVulkanH_Window(); -} - -void ImGui_ImplVulkanH_DestroyFrame(VkDevice device, ImGui_ImplVulkanH_Frame* fd, const VkAllocationCallbacks* allocator) -{ - vkDestroyFence(device, fd->Fence, allocator); - vkFreeCommandBuffers(device, fd->CommandPool, 1, &fd->CommandBuffer); - vkDestroyCommandPool(device, fd->CommandPool, allocator); - fd->Fence = VK_NULL_HANDLE; - fd->CommandBuffer = VK_NULL_HANDLE; - fd->CommandPool = VK_NULL_HANDLE; - - vkDestroyImageView(device, fd->BackbufferView, allocator); - vkDestroyFramebuffer(device, fd->Framebuffer, allocator); -} - -void ImGui_ImplVulkanH_DestroyFrameSemaphores(VkDevice device, ImGui_ImplVulkanH_FrameSemaphores* fsd, const VkAllocationCallbacks* allocator) -{ - vkDestroySemaphore(device, fsd->ImageAcquiredSemaphore, allocator); - vkDestroySemaphore(device, fsd->RenderCompleteSemaphore, allocator); - fsd->ImageAcquiredSemaphore = fsd->RenderCompleteSemaphore = VK_NULL_HANDLE; -} - -void ImGui_ImplVulkanH_DestroyFrameRenderBuffers(VkDevice device, ImGui_ImplVulkanH_FrameRenderBuffers* buffers, const VkAllocationCallbacks* allocator) -{ - if (buffers->VertexBuffer) { vkDestroyBuffer(device, buffers->VertexBuffer, allocator); buffers->VertexBuffer = VK_NULL_HANDLE; } - if (buffers->VertexBufferMemory) { vkFreeMemory(device, buffers->VertexBufferMemory, allocator); buffers->VertexBufferMemory = VK_NULL_HANDLE; } - if (buffers->IndexBuffer) { vkDestroyBuffer(device, buffers->IndexBuffer, allocator); buffers->IndexBuffer = VK_NULL_HANDLE; } - if (buffers->IndexBufferMemory) { vkFreeMemory(device, buffers->IndexBufferMemory, allocator); buffers->IndexBufferMemory = VK_NULL_HANDLE; } - buffers->VertexBufferSize = 0; - buffers->IndexBufferSize = 0; -} - -void ImGui_ImplVulkanH_DestroyWindowRenderBuffers(VkDevice device, ImGui_ImplVulkanH_WindowRenderBuffers* buffers, const VkAllocationCallbacks* allocator) -{ - for (uint32_t n = 0; n < buffers->Count; n++) - ImGui_ImplVulkanH_DestroyFrameRenderBuffers(device, &buffers->FrameRenderBuffers[n], allocator); - IM_FREE(buffers->FrameRenderBuffers); - buffers->FrameRenderBuffers = NULL; - buffers->Index = 0; - buffers->Count = 0; -} diff --git a/deps/imgui/imgui_impl_vulkan.h b/deps/imgui/imgui_impl_vulkan.h deleted file mode 100644 index 9f9010e..0000000 --- a/deps/imgui/imgui_impl_vulkan.h +++ /dev/null @@ -1,148 +0,0 @@ -// dear imgui: Renderer Backend for Vulkan -// This needs to be used along with a Platform Backend (e.g. GLFW, SDL, Win32, custom..) - -// Implemented features: -// [X] Renderer: Support for large meshes (64k+ vertices) with 16-bit indices. -// Missing features: -// [ ] Renderer: User texture binding. Changes of ImTextureID aren't supported by this backend! See https://github.com/ocornut/imgui/pull/914 - -// You can copy and use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this. -// If you are new to Dear ImGui, read documentation from the docs/ folder + read the top of imgui.cpp. -// Read online: https://github.com/ocornut/imgui/tree/master/docs - -// The aim of imgui_impl_vulkan.h/.cpp is to be usable in your engine without any modification. -// IF YOU FEEL YOU NEED TO MAKE ANY CHANGE TO THIS CODE, please share them and your feedback at https://github.com/ocornut/imgui/ - -// Important note to the reader who wish to integrate imgui_impl_vulkan.cpp/.h in their own engine/app. -// - Common ImGui_ImplVulkan_XXX functions and structures are used to interface with imgui_impl_vulkan.cpp/.h. -// You will use those if you want to use this rendering backend in your engine/app. -// - Helper ImGui_ImplVulkanH_XXX functions and structures are only used by this example (main.cpp) and by -// the backend itself (imgui_impl_vulkan.cpp), but should PROBABLY NOT be used by your own engine/app code. -// Read comments in imgui_impl_vulkan.h. - -#pragma once -#include "imgui.h" // IMGUI_IMPL_API - -// [Configuration] in order to use a custom Vulkan function loader: -// (1) You'll need to disable default Vulkan function prototypes. -// We provide a '#define IMGUI_IMPL_VULKAN_NO_PROTOTYPES' convenience configuration flag. -// In order to make sure this is visible from the imgui_impl_vulkan.cpp compilation unit: -// - Add '#define IMGUI_IMPL_VULKAN_NO_PROTOTYPES' in your imconfig.h file -// - Or as a compilation flag in your build system -// - Or uncomment here (not recommended because you'd be modifying imgui sources!) -// - Do not simply add it in a .cpp file! -// (2) Call ImGui_ImplVulkan_LoadFunctions() before ImGui_ImplVulkan_Init() with your custom function. -// If you have no idea what this is, leave it alone! -//#define IMGUI_IMPL_VULKAN_NO_PROTOTYPES - -// Vulkan includes -#if defined(IMGUI_IMPL_VULKAN_NO_PROTOTYPES) && !defined(VK_NO_PROTOTYPES) -#define VK_NO_PROTOTYPES -#endif -#include - -// Initialization data, for ImGui_ImplVulkan_Init() -// [Please zero-clear before use!] -struct ImGui_ImplVulkan_InitInfo -{ - VkInstance Instance; - VkPhysicalDevice PhysicalDevice; - VkDevice Device; - uint32_t QueueFamily; - VkQueue Queue; - VkPipelineCache PipelineCache; - VkDescriptorPool DescriptorPool; - uint32_t Subpass; - uint32_t MinImageCount; // >= 2 - uint32_t ImageCount; // >= MinImageCount - VkSampleCountFlagBits MSAASamples; // >= VK_SAMPLE_COUNT_1_BIT - const VkAllocationCallbacks* Allocator; - void (*CheckVkResultFn)(VkResult err); -}; - -// Called by user code -IMGUI_IMPL_API bool ImGui_ImplVulkan_Init(ImGui_ImplVulkan_InitInfo* info, VkRenderPass render_pass); -IMGUI_IMPL_API void ImGui_ImplVulkan_Shutdown(); -IMGUI_IMPL_API void ImGui_ImplVulkan_NewFrame(); -IMGUI_IMPL_API void ImGui_ImplVulkan_RenderDrawData(ImDrawData* draw_data, VkCommandBuffer command_buffer, VkPipeline pipeline = VK_NULL_HANDLE); -IMGUI_IMPL_API bool ImGui_ImplVulkan_CreateFontsTexture(VkCommandBuffer command_buffer); -IMGUI_IMPL_API void ImGui_ImplVulkan_DestroyFontUploadObjects(); -IMGUI_IMPL_API void ImGui_ImplVulkan_SetMinImageCount(uint32_t min_image_count); // To override MinImageCount after initialization (e.g. if swap chain is recreated) - -// Optional: load Vulkan functions with a custom function loader -// This is only useful with IMGUI_IMPL_VULKAN_NO_PROTOTYPES / VK_NO_PROTOTYPES -IMGUI_IMPL_API bool ImGui_ImplVulkan_LoadFunctions(PFN_vkVoidFunction(*loader_func)(const char* function_name, void* user_data), void* user_data = NULL); - -//------------------------------------------------------------------------- -// Internal / Miscellaneous Vulkan Helpers -// (Used by example's main.cpp. Used by multi-viewport features. PROBABLY NOT used by your own engine/app.) -//------------------------------------------------------------------------- -// You probably do NOT need to use or care about those functions. -// Those functions only exist because: -// 1) they facilitate the readability and maintenance of the multiple main.cpp examples files. -// 2) the upcoming multi-viewport feature will need them internally. -// Generally we avoid exposing any kind of superfluous high-level helpers in the backends, -// but it is too much code to duplicate everywhere so we exceptionally expose them. -// -// Your engine/app will likely _already_ have code to setup all that stuff (swap chain, render pass, frame buffers, etc.). -// You may read this code to learn about Vulkan, but it is recommended you use you own custom tailored code to do equivalent work. -// (The ImGui_ImplVulkanH_XXX functions do not interact with any of the state used by the regular ImGui_ImplVulkan_XXX functions) -//------------------------------------------------------------------------- - -struct ImGui_ImplVulkanH_Frame; -struct ImGui_ImplVulkanH_Window; - -// Helpers -IMGUI_IMPL_API void ImGui_ImplVulkanH_CreateOrResizeWindow(VkInstance instance, VkPhysicalDevice physical_device, VkDevice device, ImGui_ImplVulkanH_Window* wnd, uint32_t queue_family, const VkAllocationCallbacks* allocator, int w, int h, uint32_t min_image_count); -IMGUI_IMPL_API void ImGui_ImplVulkanH_DestroyWindow(VkInstance instance, VkDevice device, ImGui_ImplVulkanH_Window* wnd, const VkAllocationCallbacks* allocator); -IMGUI_IMPL_API VkSurfaceFormatKHR ImGui_ImplVulkanH_SelectSurfaceFormat(VkPhysicalDevice physical_device, VkSurfaceKHR surface, const VkFormat* request_formats, int request_formats_count, VkColorSpaceKHR request_color_space); -IMGUI_IMPL_API VkPresentModeKHR ImGui_ImplVulkanH_SelectPresentMode(VkPhysicalDevice physical_device, VkSurfaceKHR surface, const VkPresentModeKHR* request_modes, int request_modes_count); -IMGUI_IMPL_API int ImGui_ImplVulkanH_GetMinImageCountFromPresentMode(VkPresentModeKHR present_mode); - -// Helper structure to hold the data needed by one rendering frame -// (Used by example's main.cpp. Used by multi-viewport features. Probably NOT used by your own engine/app.) -// [Please zero-clear before use!] -struct ImGui_ImplVulkanH_Frame -{ - VkCommandPool CommandPool; - VkCommandBuffer CommandBuffer; - VkFence Fence; - VkImage Backbuffer; - VkImageView BackbufferView; - VkFramebuffer Framebuffer; -}; - -struct ImGui_ImplVulkanH_FrameSemaphores -{ - VkSemaphore ImageAcquiredSemaphore; - VkSemaphore RenderCompleteSemaphore; -}; - -// Helper structure to hold the data needed by one rendering context into one OS window -// (Used by example's main.cpp. Used by multi-viewport features. Probably NOT used by your own engine/app.) -struct ImGui_ImplVulkanH_Window -{ - int Width; - int Height; - VkSwapchainKHR Swapchain; - VkSurfaceKHR Surface; - VkSurfaceFormatKHR SurfaceFormat; - VkPresentModeKHR PresentMode; - VkRenderPass RenderPass; - VkPipeline Pipeline; // The window pipeline may uses a different VkRenderPass than the one passed in ImGui_ImplVulkan_InitInfo - bool ClearEnable; - VkClearValue ClearValue; - uint32_t FrameIndex; // Current frame being rendered to (0 <= FrameIndex < FrameInFlightCount) - uint32_t ImageCount; // Number of simultaneous in-flight frames (returned by vkGetSwapchainImagesKHR, usually derived from min_image_count) - uint32_t SemaphoreIndex; // Current set of swapchain wait semaphores we're using (needs to be distinct from per frame data) - ImGui_ImplVulkanH_Frame* Frames; - ImGui_ImplVulkanH_FrameSemaphores* FrameSemaphores; - - ImGui_ImplVulkanH_Window() - { - memset(this, 0, sizeof(*this)); - PresentMode = VK_PRESENT_MODE_MAX_ENUM_KHR; - ClearEnable = true; - } -}; - diff --git a/src/Animation.cpp b/src/Animation.cpp index 84b9ab4..7eb2cd9 100644 --- a/src/Animation.cpp +++ b/src/Animation.cpp @@ -17,8 +17,8 @@ CJson Animation::json = CJson("animation"); std::vector fighting_vec{ "Default","Boxing","Kung fu","Kick Boxing","Punch Kick" }; int fighting_selected = 0; -std::vector walking_vec{ "default", "man", "shuffle", "oldman", "gang1", "gang2", -"oldfatman", "fatman", "jogger", "drunkman", "blindman", "swat", "woman", "shopping", "busywoman", +std::vector walking_vec{ "default", "man", "shuffle", "oldman", "gang1", "gang2", +"oldfatman", "fatman", "jogger", "drunkman", "blindman", "swat", "woman", "shopping", "busywoman", "sexywoman", "pro", "oldwoman", "fatwoman", "jogwoman", "oldfatwoman", "skate" }; std::string walking_selected = "default"; @@ -28,7 +28,7 @@ Animation::Animation() json.LoadData(search_categories, selected_item); } -void Animation::Main() +void Animation::Draw() { if (ImGui::BeginTabBar("Animation", ImGuiTabBarFlags_NoTooltip + ImGuiTabBarFlags_FittingPolicyScroll)) { @@ -70,7 +70,7 @@ void Animation::Main() if (Ui::ListBox("Fighting", fighting_vec, fighting_selected)) { Command(hplayer, fighting_selected + 4, 6); - CHud::SetHelpMessage("Fighting anim set",false,false,false); + CHud::SetHelpMessage("Fighting anim set", false, false, false); } if (Ui::ListBoxStr("Walking", walking_vec, walking_selected)) { @@ -90,7 +90,7 @@ void Animation::Main() Command(); Command(hplayer, cwalking_selected); Command(cwalking_selected); - } + } CHud::SetHelpMessage("Walking anim set", false, false, false); } ImGui::EndTabItem(); @@ -127,7 +127,7 @@ void Animation::PlayAnimation(std::string& ifp, std::string& anim, std::string& Command(hplayer, anim.c_str(), ifp.c_str(), 4.0, loop, 0, 0, 0, -1); else Command(hplayer, anim.c_str(), ifp.c_str(), 4.0, loop, 0, 0, 0, -1); - + if (ifp != "PED") Command(ifp.c_str()); } @@ -140,7 +140,8 @@ void Animation::RemoveAnimation(std::string& ifp, std::string& anim, std::string json.data["Custom"].erase(anim); json.WriteToDisk(); CHud::SetHelpMessage("Animation removed", false, false, false); - }else CHud::SetHelpMessage("You can only remove custom anims", false, false, false); + } +else CHud::SetHelpMessage("You can only remove custom anims", false, false, false); } diff --git a/src/Animation.h b/src/Animation.h index d3ff851..cb128d8 100644 --- a/src/Animation.h +++ b/src/Animation.h @@ -18,7 +18,7 @@ protected: ~Animation() {}; public: - static void Main(); + static void Draw(); static void PlayAnimation(std::string& rootkey, std::string& anim, std::string& ifp); static void RemoveAnimation(std::string& rootkey, std::string& anim, std::string& ifp); }; diff --git a/src/CheatMenu.cpp b/src/CheatMenu.cpp index 465b872..3ef6722 100644 --- a/src/CheatMenu.cpp +++ b/src/CheatMenu.cpp @@ -4,12 +4,12 @@ #include "Ui.h" unsortedMap CheatMenu::header{ - { "Teleport", &Teleport::Main },{ "Player", &Player::Main },{ "Ped", &Ped::Main }, - { "Animation", &Animation::Main },{ "Vehicle", &Vehicle::Main },{ "Weapon", &Weapon::Main }, - { "Game", &Game::Main },{ "Visual", &Visual::Main },{ "Menu", &Menu::Main } + { "Teleport", &Teleport::Draw },{ "Player", &Player::Draw },{ "Ped", &Ped::Draw }, + { "Animation", &Animation::Draw },{ "Vehicle", &Vehicle::Draw },{ "Weapon", &Weapon::Draw }, + { "Game", &Game::Draw },{ "Visual", &Visual::Draw },{ "Menu", &Menu::Draw } }; -void CheatMenu::ProcessMenu() +void CheatMenu::DrawMenu() { ImGui::SetNextWindowSize(Globals::menu_size); if (ImGui::Begin(MENU_TITLE, &Globals::show_menu, ImGuiWindowFlags_NoCollapse)) @@ -32,32 +32,32 @@ void CheatMenu::ProcessWindow() { ImGuiIO& io = ImGui::GetIO(); - if (!FrontEndMenuManager.m_bMenuActive && (Globals::show_menu || Menu::commands::show_menu)) - { - if (Globals::show_menu) - ProcessMenu(); - else - Menu::ProcessShortcutsWindow(); - } + if (FrontEndMenuManager.m_bMenuActive) + Hook::show_mouse = false; + else + if (Globals::show_menu || Menu::commands::show_menu) + { + if (Globals::show_menu) + DrawMenu(); + else + Menu::DrawShortcutsWindow(); + } Menu::ProcessOverlay(); } CheatMenu::CheatMenu() { - ApplyImGuiStyle(); + ApplyStyle(); Hook::window_callback = std::bind(&ProcessWindow); - Events::initRwEvent += []() - { - // Load menu settings - Globals::header_id = config.GetValue("window.id",std::string("")); - Globals::menu_size.x = config.GetValue("window.sizeX", screen::GetScreenWidth() / 4.0f); - Globals::menu_size.y = config.GetValue("window.sizeY", screen::GetScreenHeight() / 1.2f); - srand(CTimer::m_snTimeInMilliseconds); - }; + // Load menu settings + Globals::header_id = config.GetValue("window.id", std::string("")); + Globals::menu_size.x = config.GetValue("window.sizeX", screen::GetScreenWidth() / 4.0f); + Globals::menu_size.y = config.GetValue("window.sizeY", screen::GetScreenHeight() / 1.2f); + srand(CTimer::m_snTimeInMilliseconds); - Events::processScriptsEvent += [this] + Events::processScriptsEvent += [] { if (Globals::init_done && !FrontEndMenuManager.m_bMenuActive) { @@ -69,7 +69,7 @@ CheatMenu::CheatMenu() if (Menu::commands::show_menu) { Menu::ProcessCommands(); - strcpy(commands::input_buffer,""); + strcpy(commands::input_buffer, ""); } Menu::commands::show_menu = !Menu::commands::show_menu; } @@ -78,32 +78,14 @@ CheatMenu::CheatMenu() { if (Hook::show_mouse) // Only write when the menu closes config.WriteToDisk(); - + Hook::show_mouse = Globals::show_menu; } } }; - - Events::drawMenuBackgroundEvent += [this] - { - if (Hook::show_mouse) - { - config.WriteToDisk(); - Hook::show_mouse = false; - } - }; - - Events::shutdownRwEvent += [] - { - flog << "Log Finished." << std::endl; - }; } -CheatMenu::~CheatMenu() -{ -} - -void CheatMenu::ApplyImGuiStyle() +void CheatMenu::ApplyStyle() { ImGuiStyle* style = &ImGui::GetStyle(); ImVec4* colors = style->Colors; @@ -175,4 +157,50 @@ void CheatMenu::ApplyImGuiStyle() colors[ImGuiCol_NavWindowingHighlight] = ImVec4(1.00f, 1.00f, 1.00f, 0.70f); colors[ImGuiCol_NavWindowingDimBg] = ImVec4(0.80f, 0.80f, 0.80f, 0.20f); colors[ImGuiCol_ModalWindowDimBg] = ImVec4(0.26f, 0.59f, 0.98f, 0.35f); +} + +void MenuThread(void* param) +{ + // Wait till the game is initiallized + Events::initGameEvent.after += []() + { + Globals::game_init = true; + }; + + while (!Globals::game_init) + Sleep(500); + + if (GetModuleHandle("SAMP.dll")) + { + MessageBox(RsGlobal.ps->window, "SAMP detected. Exiting CheatMenu.", "CheatMenu", MB_ICONERROR); + return; + } + + // SP fixes some mouse issues + if (!GetModuleHandle("SilentPatchSA.asi")) + { + MessageBox(RsGlobal.ps->window, "SilentPatch isn't installed. Exiting CheatMenu.", "CheatMenu", MB_ICONERROR); + return; + } + + flog << "Starting...\nVersion: " MENU_TITLE "\nAuthor: Grinch_\nDiscord: " DISCORD_INVITE "\nMore Info: " GITHUB_LINK "\n\n" << std::endl; + CFastman92limitAdjuster::Init(); + CheatMenu cheatmenu; + + while (true) + Sleep(5000); +} + +BOOL WINAPI DllMain(HINSTANCE hDllHandle, DWORD nReason, LPVOID Reserved) +{ + if (nReason == DLL_PROCESS_ATTACH) + { + uint gameVersion = GetGameVersion(); + if (gameVersion == GAME_10US_HOODLUM || gameVersion == GAME_10US_COMPACT) + CreateThread(NULL, NULL, (LPTHREAD_START_ROUTINE)&MenuThread, NULL, NULL, NULL); + else + MessageBox(HWND_DESKTOP, "Unknown game version. GTA SA v1.0 US is required.", "CheatMenu", MB_ICONERROR); + } + + return TRUE; } \ No newline at end of file diff --git a/src/CheatMenu.h b/src/CheatMenu.h index 7e567f7..4c3234b 100644 --- a/src/CheatMenu.h +++ b/src/CheatMenu.h @@ -22,51 +22,11 @@ class CheatMenu : Hook, Animation, Game, Menu, Ped, Player, Teleport, Vehicle, V { private: static unsortedMap header; - static void ProcessMenu(); + static void DrawMenu(); static void ProcessWindow(); - static void ApplyImGuiStyle(); + static void ApplyStyle(); public: CheatMenu(); - ~CheatMenu(); }; -class Launcher -{ -public: - Launcher() - { - Events::initRwEvent += []() - { - bool launch = true; - uint gameVersion = GetGameVersion(); - if (gameVersion != GAME_10US_HOODLUM && gameVersion != GAME_10US_COMPACT) { - MessageBox(HWND_DESKTOP, "CheatMenu requires v1.0 US of the game.", "CheatMenu", MB_ICONERROR); - launch = false; - } - - if (IsPluginInstalled("SAMP.dll")) { - MessageBox(HWND_DESKTOP, "SAMP detected. Exiting CheatMenu.", "CheatMenu", MB_ICONERROR); - launch = false; - } - - /* - Mouse is extremely buggy without SilentPatch - Should have a better fix for this but everyone should have - SilentPatch installed so mehh... - */ - if (!IsPluginInstalled("SilentPatchSA.asi")) { - MessageBox(HWND_DESKTOP, "SilentPatch isn't installed. Exiting CheatMenu.", "CheatMenu", MB_ICONERROR); - launch = false; - } - - if (launch) - { - flog << "Loading CheatMenu" << std::endl; - CFastman92limitAdjuster::Init(); - static CheatMenu cheatmenu; - } - }; - } -} launcher; - diff --git a/src/Events.cpp b/src/Events.cpp index e0d6f21..d815db0 100644 --- a/src/Events.cpp +++ b/src/Events.cpp @@ -1,12 +1,10 @@ #include "pch.h" #include "Events.h" - namespace plugin { namespace Events { decltype(vehicleResetAfterRender) vehicleResetAfterRender; - decltype(renderscence) renderscence; } } diff --git a/src/Events.h b/src/Events.h index 38f9784..4826382 100644 --- a/src/Events.h +++ b/src/Events.h @@ -5,6 +5,5 @@ namespace plugin namespace Events { extern ThiscallEvent, PRIORITY_BEFORE, ArgPickN, void(CVehicle*)> vehicleResetAfterRender; - extern ThiscallEvent, PRIORITY_BEFORE, ArgPickNone, void()> renderscence; } } diff --git a/src/Game.cpp b/src/Game.cpp index 195ae86..500698a 100644 --- a/src/Game.cpp +++ b/src/Game.cpp @@ -32,7 +32,7 @@ float Game::freecam::mouseX = 0; float Game::freecam::mouseY = 0; int Game::freecam::hped = -1; float Game::freecam::fov = -1; -CPed *Game::freecam::ped = nullptr; +CPed* Game::freecam::ped = nullptr; bool Game::hard_mode::state = false; float Game::hard_mode::prev_armour = 0.0f; @@ -60,18 +60,18 @@ static bool mission_warning_shown = false; // Thanks to aap void RealTimeClock(void) -{ +{ static int lastday; time_t tmp = time(NULL); - struct tm *now = localtime(&tmp); - - if(now->tm_yday != lastday) + struct tm* now = localtime(&tmp); + + if (now->tm_yday != lastday) CStats::SetStatValue(0x86, CStats::GetStatValue(0x86) + 1.0f); lastday = now->tm_yday; - CClock::ms_nGameClockMonth = now->tm_mon+1; + CClock::ms_nGameClockMonth = now->tm_mon + 1; CClock::ms_nGameClockDays = now->tm_mday; - CClock::CurrentDay = now->tm_wday+1; + CClock::CurrentDay = now->tm_wday + 1; CClock::ms_nGameClockHours = now->tm_hour; CClock::ms_nGameClockMinutes = now->tm_min; CClock::ms_nGameClockSeconds = now->tm_sec; @@ -79,29 +79,26 @@ void RealTimeClock(void) Game::Game() { - Events::initGameEvent += [] - { - json.LoadData(search_categories, selected_item); - stat::json.LoadData(stat::search_categories, stat::selected_item); - freecam::fov = TheCamera.FindCamFOV(); + json.LoadData(search_categories, selected_item); + stat::json.LoadData(stat::search_categories, stat::selected_item); + freecam::fov = TheCamera.FindCamFOV(); - // Generate enabled cheats vector - for (auto element : random_cheats::name_json.data.items()) - { - /* - [ - cheat_id = [ cheat_name, state (true/false) ] - ] - */ - random_cheats::enabled_cheats[std::stoi(element.key())][0] = element.value().get(); - random_cheats::enabled_cheats[std::stoi(element.key())][1] = "true"; - } - }; + // Generate enabled cheats vector + for (auto element : random_cheats::name_json.data.items()) + { + /* + [ + cheat_id = [ cheat_name, state (true/false) ] + ] + */ + random_cheats::enabled_cheats[std::stoi(element.key())][0] = element.value().get(); + random_cheats::enabled_cheats[std::stoi(element.key())][1] = "true"; + } Events::processScriptsEvent += [] { uint timer = CTimer::m_snTimeInMilliseconds; - static CPlayerPed *player = FindPlayerPed(); + static CPlayerPed* player = FindPlayerPed(); static int hplayer = CPools::GetPedRef(player); if (ss_shortcut) @@ -135,9 +132,9 @@ Game::Game() if (solid_water_object == 0) { Command(3095, pos.x, pos.y, water_height, &solid_water_object); - Command(solid_water_object,false); - if (pos.z < (water_height+1)) - player->SetPosn(pos.x,pos.y,water_height+1); + Command(solid_water_object, false); + if (pos.z < (water_height + 1)) + player->SetPosn(pos.x, pos.y, water_height + 1); } else Command(solid_water_object, pos.x, pos.y, water_height); @@ -155,19 +152,19 @@ Game::Game() // improve this later if (sync_time && timer - sync_time_timer > 50) { - std::time_t t = std::time(0); + std::time_t t = std::time(0); std::tm* now = std::localtime(&t); CClock::ms_nGameClockHours = now->tm_hour; CClock::ms_nGameClockMinutes = now->tm_min; - + sync_time_timer = timer; } - if (random_cheats::enable - && (timer - random_cheats::timer) > (uint(random_cheats::enable_wait_time)*1000)) + if (random_cheats::enable + && (timer - random_cheats::timer) > (uint(random_cheats::enable_wait_time) * 1000)) { - int id = Random(0,91); + int id = Random(0, 91); for (int i = 0; i < 92; i++) { @@ -183,7 +180,7 @@ Game::Game() } } } - + if (Ui::HotKeyPressed(Menu::hotkeys::freecam)) { if (freecam::enable) @@ -198,25 +195,21 @@ Game::Game() }; } -Game::~Game() -{ -} - void SetPlayerMission(std::string& rootkey, std::string& name, std::string& id) { - CPlayerPed *player = FindPlayerPed(); + CPlayerPed* player = FindPlayerPed(); uint hplayer = CPools::GetPedRef(player); int interior = 0; - Command<0x09E8>(hplayer,&interior); - - if ( Util::IsOnMission() && interior == 0) + Command<0x09E8>(hplayer, &interior); + + if (Util::IsOnMission() && interior == 0) { player->SetWantedLevel(0); Command(std::stoi(id)); } else CHud::SetHelpMessage("Can't start mission now", false, false, false); - + } void Game::FreeCam() @@ -225,18 +218,18 @@ void Game::FreeCam() if (!freecam::init_done) { - CPlayerPed *player = FindPlayerPed(-1); + CPlayerPed* player = FindPlayerPed(-1); Command(0, true); CHud::bScriptDontDisplayRadar = true; CHud::m_Wants_To_Draw_Hud = false; CVector player_pos = player->GetPosition(); CPad::GetPad(0)->DisablePlayerControls = true; - Command(player_pos.x,player_pos.y,player_pos.z, &freecam::hped); + Command(player_pos.x, player_pos.y, player_pos.z, &freecam::hped); freecam::ped = CPools::GetPed(freecam::hped); freecam::ped->m_bIsVisible = false; - - Command(freecam::hped,true); + + Command(freecam::hped, true); Command(freecam::hped, false); Command(freecam::hped, false); @@ -247,16 +240,16 @@ void Game::FreeCam() player_pos.z -= 20; freecam::ped->SetPosn(player_pos); - TheCamera.LerpFOV(TheCamera.FindCamFOV(),freecam::fov,1000,true); + TheCamera.LerpFOV(TheCamera.FindCamFOV(), freecam::fov, 1000, true); Command(true); } CVector pos = freecam::ped->GetPosition(); Command(&freecam::mouseX, &freecam::mouseY); - freecam::tmouseX = freecam::tmouseX - freecam::mouseX/250; - freecam::tmouseY = freecam::tmouseY + freecam::mouseY/3; - + freecam::tmouseX = freecam::tmouseX - freecam::mouseX / 250; + freecam::tmouseY = freecam::tmouseY + freecam::mouseY / 3; + if (freecam::tmouseY > 150) freecam::tmouseY = 150; @@ -265,18 +258,18 @@ void Game::FreeCam() if (Ui::HotKeyPressed(Menu::hotkeys::free_cam_tp_player)) { - CPlayerPed *player = FindPlayerPed(-1); + CPlayerPed* player = FindPlayerPed(-1); CVector pos = freecam::ped->GetPosition(); CEntity* player_entity = FindPlayerEntity(-1); pos.z = CWorld::FindGroundZFor3DCoord(pos.x, pos.y, 1000, 0, &player_entity) + 0.5f; - Command(CPools::GetPedRef(player),pos.x,pos.y,pos.z); + Command(CPools::GetPedRef(player), pos.x, pos.y, pos.z); // disble them again cause they get enabled CHud::bScriptDontDisplayRadar = true; CHud::m_Wants_To_Draw_Hud = false; - CHud::SetHelpMessage((char*)"Player telported",false,false,false); + CHud::SetHelpMessage((char*)"Player telported", false, false, false); } - + if (KeyPressed(VK_RCONTROL)) delta_speed /= 2; @@ -289,10 +282,10 @@ void Game::FreeCam() delta_speed *= -1; float angle; - Command(freecam::hped,&angle); - pos.x += delta_speed * cos(angle * 3.14159f/180.0f); - pos.y += delta_speed * sin(angle * 3.14159f/180.0f); - pos.z += delta_speed* 2 * sin(freecam::tmouseY/3* 3.14159f/180.0f); + Command(freecam::hped, &angle); + pos.x += delta_speed * cos(angle * 3.14159f / 180.0f); + pos.y += delta_speed * sin(angle * 3.14159f / 180.0f); + pos.z += delta_speed * 2 * sin(freecam::tmouseY / 3 * 3.14159f / 180.0f); } if (KeyPressed(VK_KEY_J) || KeyPressed(VK_KEY_L)) @@ -301,33 +294,33 @@ void Game::FreeCam() delta_speed *= -1; float angle; - Command(freecam::hped,&angle); + Command(freecam::hped, &angle); angle -= 90; - - pos.x += delta_speed * cos(angle * 3.14159f/180.0f); - pos.y += delta_speed * sin(angle * 3.14159f/180.0f); + + pos.x += delta_speed * cos(angle * 3.14159f / 180.0f); + pos.y += delta_speed * sin(angle * 3.14159f / 180.0f); } - if ( CPad::NewMouseControllerState.wheelUp) + if (CPad::NewMouseControllerState.wheelUp) { if (freecam::fov > 10.0f) freecam::fov -= 2.0f * delta_speed; - TheCamera.LerpFOV(TheCamera.FindCamFOV(),freecam::fov,250,true); + TheCamera.LerpFOV(TheCamera.FindCamFOV(), freecam::fov, 250, true); Command(true); } - if ( CPad::NewMouseControllerState.wheelDown) + if (CPad::NewMouseControllerState.wheelDown) { if (freecam::fov < 115.0f) freecam::fov += 2.0f * delta_speed; - - TheCamera.LerpFOV(TheCamera.FindCamFOV(),freecam::fov,250,true); + + TheCamera.LerpFOV(TheCamera.FindCamFOV(), freecam::fov, 250, true); Command(true); } freecam::ped->SetHeading(freecam::tmouseX); - Command(freecam::hped,0.0,0.0,20.0,90.0,180,freecam::tmouseY,0.0,2); + Command(freecam::hped, 0.0, 0.0, 20.0, 90.0, 180, freecam::tmouseY, 0.0, 2); freecam::ped->SetPosn(pos); CIplStore::AddIplsNeededAtPosn(pos); } @@ -346,10 +339,10 @@ void Game::ClearFreecamStuff() Command(); } -void Game::Main() +void Game::Draw() { ImGui::Spacing(); - static CPlayerPed *player = FindPlayerPed(); + static CPlayerPed* player = FindPlayerPed(); static int hplayer = CPools::GetPedRef(player); if (ImGui::BeginTabBar("Game", ImGuiTabBarFlags_NoTooltip + ImGuiTabBarFlags_FittingPolicyScroll)) @@ -402,7 +395,7 @@ of LS without completing missions")) if (Ui::CheckboxWithHint("Hard mode", &hard_mode::state, "Makes the game more challanging to play. \n\ Lowers armour, health, stamina etc.")) { - CPlayerPed *player = FindPlayerPed(); + CPlayerPed* player = FindPlayerPed(); if (hard_mode::state) { @@ -415,7 +408,7 @@ Lowers armour, health, stamina etc.")) else { player->m_fArmour = hard_mode::prev_armour; - CStats::SetStatValue(STAT_STAMINA,hard_mode::prev_stamina); + CStats::SetStatValue(STAT_STAMINA, hard_mode::prev_stamina); CStats::SetStatValue(STAT_MAX_HEALTH, hard_mode::prev_max_health); player->m_fHealth = hard_mode::prev_health; CWeaponInfo::LoadWeaponData(); @@ -428,7 +421,7 @@ Lowers armour, health, stamina etc.")) Command(keep_stuff); } Ui::CheckboxWithHint("Screenshot shortcut", &ss_shortcut, (("Take screenshot using ") + Ui::GetHotKeyNameString(Menu::hotkeys::quick_ss) - + "\nSaved inside 'GTA San Andreas User Files\\Gallery'").c_str()); + + "\nSaved inside 'GTA San Andreas User Files\\Gallery'").c_str()); if (Ui::CheckboxWithHint("Solid water", &solid_water, "Player can walk on water\nTurn this off if you want to swim.")) { if (!solid_water && solid_water_object != 0) @@ -452,9 +445,9 @@ Lowers armour, health, stamina etc.")) { if (ImGui::CollapsingHeader("Current day")) { - int day = CClock::CurrentDay-1; + int day = CClock::CurrentDay - 1; if (Ui::ListBox("Select day", day_names, day)) - CClock::CurrentDay = day+1; + CClock::CurrentDay = day + 1; ImGui::Spacing(); ImGui::Separator(); } @@ -469,10 +462,10 @@ Lowers armour, health, stamina etc.")) ClearFreecamStuff(); } ImGui::Spacing(); - + if (ImGui::SliderFloat("Field of view", &freecam::fov, 5.0f, 120.0f)) { - TheCamera.LerpFOV(TheCamera.FindCamFOV(),freecam::fov,250.0f,true); + TheCamera.LerpFOV(TheCamera.FindCamFOV(), freecam::fov, 250.0f, true); Command(true); } ImGui::SliderFloat("Movement Speed", &freecam::speed, 0.0f, 0.5f); @@ -481,7 +474,7 @@ Lowers armour, health, stamina etc.")) ImGui::Spacing(); ImGui::Separator(); } - Ui::EditReference("Game speed", CTimer::ms_fTimeScale,1, 1, 10); + Ui::EditReference("Game speed", CTimer::ms_fTimeScale, 1, 1, 10); Ui::EditFloat("Gravity", 0x863984, -1.0f, 0.008f, 1.0f); if (ImGui::CollapsingHeader("Set time")) @@ -507,13 +500,13 @@ Lowers armour, health, stamina etc.")) ImGui::Separator(); } - static std::vector themes { { "Beach", 0x969159 }, { "Country" ,0x96917D }, { "Fun house" ,0x969176 }, { "Ninja" ,0x96915C }}; + static std::vector themes{ { "Beach", 0x969159 }, { "Country" ,0x96917D }, { "Fun house" ,0x969176 }, { "Ninja" ,0x96915C } }; Ui::EditRadioButtonAddress("Themes", themes); - + if (ImGui::CollapsingHeader("Weather")) { typedef void func(void); - if (ImGui::Button("Foggy",Ui::GetSize(3))) + if (ImGui::Button("Foggy", Ui::GetSize(3))) ((func*)0x438F80)(); ImGui::SameLine(); @@ -570,7 +563,7 @@ It's recommanded not to save your game after using this. Use it at your own risk { // similat to Ui::DrawJSON() ImGui::Spacing(); - + ImGui::PushItemWidth(ImGui::GetContentRegionAvailWidth() / 2 - 5); Ui::ListBoxStr("##Categories", stat::search_categories, stat::selected_item); ImGui::SameLine(); diff --git a/src/Game.h b/src/Game.h index b126b44..8eb8fb2 100644 --- a/src/Game.h +++ b/src/Game.h @@ -25,7 +25,7 @@ public: static float speed; static float fov; static bool init_done; - static CPed *ped; + static CPed* ped; static int hped; static float mouseX, mouseY, tmouseX, tmouseY; }; @@ -60,8 +60,7 @@ public: }; Game(); - ~Game(); - static void Main(); + static void Draw(); static void FreeCam(); static void ClearFreecamStuff(); }; diff --git a/src/Hook.cpp b/src/Hook.cpp index 063a739..3fea2e2 100644 --- a/src/Hook.cpp +++ b/src/Hook.cpp @@ -6,7 +6,7 @@ WNDPROC Hook::oWndProc = NULL; f_Present11 Hook::oPresent11 = NULL; f_Present9 Hook::oPresent9 = NULL; -f_Reset Hook::oReset9 = NULL; +f_Reset Hook::oReset9 = NULL; bool Hook::mouse_visibility = false; bool Hook::show_mouse = false; @@ -31,20 +31,20 @@ LRESULT Hook::WndProc(const HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) if (ImGui::GetIO().WantTextInput) { Call<0x53F1E0>(); // CPad::ClearKeyboardHistory - return 1; + return 1; } - + return CallWindowProc(oWndProc, hWnd, uMsg, wParam, lParam); } -HRESULT Hook::Reset(IDirect3DDevice9 * pDevice, D3DPRESENT_PARAMETERS * pPresentationParameters) +HRESULT Hook::Reset(IDirect3DDevice9* pDevice, D3DPRESENT_PARAMETERS* pPresentationParameters) { ImGui_ImplDX9_InvalidateDeviceObjects(); return oReset9(pDevice, pPresentationParameters); } -void Hook::Present(void *ptr) +void Hook::Present(void* ptr) { ImGuiIO& io = ImGui::GetIO(); @@ -53,7 +53,7 @@ void Hook::Present(void *ptr) Hook::ShowMouse(show_mouse); // handle window scaling here - ImVec2 size(screen::GetScreenWidth(),screen::GetScreenHeight()); + ImVec2 size(screen::GetScreenWidth(), screen::GetScreenHeight()); if (Globals::screen_size.x != size.x && Globals::screen_size.y != size.y) { int font_size = int(size.y / 54.85f); // manually tested @@ -68,8 +68,8 @@ void Hook::Present(void *ptr) if (Globals::screen_size.x != -1 && Globals::screen_size.y != -1) { - Globals::menu_size.x += (size.x-Globals::screen_size.x) / 4.0f; - Globals::menu_size.y += (size.y-Globals::screen_size.y) / 1.2f; + Globals::menu_size.x += (size.x - Globals::screen_size.x) / 4.0f; + Globals::menu_size.y += (size.y - Globals::screen_size.y) / 1.2f; } ImGuiStyle* style = &ImGui::GetStyle(); @@ -80,7 +80,7 @@ void Hook::Present(void *ptr) style->ItemSpacing = ImVec2(8 * scale_x, 4 * scale_y); style->ScrollbarSize = 12 * scale_x; style->IndentSpacing = 20 * scale_x; - style->ItemInnerSpacing = ImVec2(4 * scale_x,4 * scale_y); + style->ItemInnerSpacing = ImVec2(4 * scale_x, 4 * scale_y); Globals::screen_size = size; } @@ -112,9 +112,9 @@ void Hook::Present(void *ptr) ImGuiStyle& style = ImGui::GetStyle(); ImGui_ImplWin32_Init(RsGlobal.ps->window); - + // shift trigger fix - patch::Nop(0x00531155,5); + patch::Nop(0x00531155, 5); if (Globals::renderer == Render_DirectX9) { @@ -143,7 +143,7 @@ void Hook::Present(void *ptr) } } -HRESULT Hook::PresentDx9Handler(IDirect3DDevice9 *pDevice, RECT* pSourceRect, RECT* pDestRect, HWND hDestWindowOverride, RGNDATA* pDirtyRegion) +HRESULT Hook::PresentDx9Handler(IDirect3DDevice9* pDevice, RECT* pSourceRect, RECT* pDestRect, HWND hDestWindowOverride, RGNDATA* pDirtyRegion) { Present(pDevice); return oPresent9(pDevice, pSourceRect, pDestRect, hDestWindowOverride, pDirtyRegion);; @@ -183,11 +183,10 @@ void Hook::ShowMouse(bool state) { if (mouse_visibility != show_mouse) { - patch::SetRaw(0x541DF5, (void*)"\xE8\x46\xF3\xFE\xFF", 5); // call CControllerConfigManager::AffectPadFromKeyBoard + patch::SetUChar(0x6194A0, 0xE9); // jmp setup patch::SetUChar(0x746ED0, 0xA1); patch::SetRaw(0x53F41F, (void*)"\x85\xC0\x0F\x8C", 4); // xor eax, eax -> test eax, eax , enable camera mouse movement // jz loc_53F526 -> jl loc_53F526 - patch::SetUChar(0x6194A0, 0xE9); // jmp setup } } @@ -196,7 +195,9 @@ void Hook::ShowMouse(bool state) CPad::ClearMouseHistory(); CPad::UpdatePads(); + // TODO: Replace this with windows cursor ImGui::GetIO().MouseDrawCursor = state; + CPad::NewMouseControllerState.X = 0; CPad::NewMouseControllerState.Y = 0; mouse_visibility = show_mouse; @@ -206,31 +207,22 @@ void Hook::ShowMouse(bool state) Hook::Hook() { ImGui::CreateContext(); - Events::initRwEvent += []() - { - if (kiero::init(kiero::RenderType::D3D9) == kiero::Status::Success) - { - Globals::renderer = Render_DirectX9; - kiero::bind(16, (void**)&oReset9, Reset); - kiero::bind(17, (void**)&oPresent9, PresentDx9Handler); - } - else - { - // gtaRenderHook - if (kiero::init(kiero::RenderType::D3D11) == kiero::Status::Success) - { - Globals::renderer = Render_DirectX11; - kiero::bind(8, (void**)&oPresent11, PresentDx11Handler); - } - // if (kiero::init(kiero::RenderType::Vulkan) == kiero::Status::Success) - // { - // Globals::renderer = Render_Vulkan; - // flog << "Vulkan detected!" << std::endl; - // kiero::bind(105, (void**)&hvkCmdDraw, PresentDx11Handler); - // } + if (kiero::init(kiero::RenderType::D3D9) == kiero::Status::Success) + { + Globals::renderer = Render_DirectX9; + kiero::bind(16, (void**)&oReset9, Reset); + kiero::bind(17, (void**)&oPresent9, PresentDx9Handler); + } + else + { + // gtaRenderHook + if (kiero::init(kiero::RenderType::D3D11) == kiero::Status::Success) + { + Globals::renderer = Render_DirectX11; + kiero::bind(8, (void**)&oPresent11, PresentDx11Handler); } - }; + } } Hook::~Hook() diff --git a/src/Hook.h b/src/Hook.h index 6dae06b..549b927 100644 --- a/src/Hook.h +++ b/src/Hook.h @@ -1,9 +1,9 @@ #pragma once #include "pch.h" -typedef HRESULT(CALLBACK *f_Present9)(IDirect3DDevice9*, RECT*, RECT*, HWND, RGNDATA*); -typedef HRESULT(CALLBACK *f_Present11)(IDXGISwapChain*, UINT, UINT); -typedef HRESULT(CALLBACK *f_Reset)(IDirect3DDevice9*, D3DPRESENT_PARAMETERS*); +typedef HRESULT(CALLBACK* f_Present9)(IDirect3DDevice9*, RECT*, RECT*, HWND, RGNDATA*); +typedef HRESULT(CALLBACK* f_Present11)(IDXGISwapChain*, UINT, UINT); +typedef HRESULT(CALLBACK* f_Reset)(IDirect3DDevice9*, D3DPRESENT_PARAMETERS*); extern IMGUI_IMPL_API LRESULT ImGui_ImplWin32_WndProcHandler(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam); @@ -16,10 +16,10 @@ private: static f_Reset oReset9; static bool mouse_visibility; - static void CALLBACK Present(void *ptr); - static HRESULT CALLBACK PresentDx9Handler(IDirect3DDevice9 *pDevice, RECT* pSourceRect, RECT* pDestRect, HWND hDestWindowOverride, RGNDATA* pDirtyRegion); + static void CALLBACK Present(void* ptr); + static HRESULT CALLBACK PresentDx9Handler(IDirect3DDevice9* pDevice, RECT* pSourceRect, RECT* pDestRect, HWND hDestWindowOverride, RGNDATA* pDirtyRegion); static HRESULT CALLBACK PresentDx11Handler(IDXGISwapChain* pSwapChain, UINT SyncInterval, UINT Flags); - static HRESULT CALLBACK Reset(IDirect3DDevice9 * pDevice, D3DPRESENT_PARAMETERS * pPresentationParameters); + static HRESULT CALLBACK Reset(IDirect3DDevice9* pDevice, D3DPRESENT_PARAMETERS* pPresentationParameters); static LRESULT CALLBACK WndProc(const HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam); static void ShowMouse(bool state); diff --git a/src/Json.cpp b/src/Json.cpp index 858a315..f089cd2 100644 --- a/src/Json.cpp +++ b/src/Json.cpp @@ -3,8 +3,8 @@ CJson::CJson(const char* name) { - file_path = "./CheatMenu/json/"+ std::string(name) +".json"; - + file_path = "./CheatMenu/json/" + std::string(name) + ".json"; + if (fs::exists(file_path)) { try @@ -29,7 +29,7 @@ CJson::CJson(const char* name) void CJson::WriteToDisk() { std::ofstream file(file_path); - file << data.dump(4,' ',false, nlohmann::json::error_handler_t::replace) << std::endl; + file << data.dump(4, ' ', false, nlohmann::json::error_handler_t::replace) << std::endl; file.close(); } diff --git a/src/Json.h b/src/Json.h index e41af97..36ce4ef 100644 --- a/src/Json.h +++ b/src/Json.h @@ -10,7 +10,7 @@ public: nlohmann::json data; /* - Returns a value from json structure hierarchy using '.' + Returns a value from json structure hierarchy using '.' Example: "Menu.Window.X" */ // specialize since typeid(std::string) doesn't work @@ -22,11 +22,11 @@ public: std::stringstream ss(key); std::string line; - nlohmann::json *json = &data; + nlohmann::json* json = &data; while (getline(ss, line, '.')) json = &((*json)[line]); - + // json library bugs with bool, using int instead if (typeid(T) == typeid(bool)) { @@ -39,7 +39,7 @@ public: return default_val; } } - + template<> std::string GetValue(std::string&& key, std::string&& default_val) { @@ -47,7 +47,7 @@ public: std::stringstream ss(key); std::string line; - nlohmann::json *json = &data; + nlohmann::json* json = &data; while (getline(ss, line, '.')) json = &((*json)[line]); @@ -60,7 +60,7 @@ public: } /* - Allows to save values in json hierarchy using '.' + Allows to save values in json hierarchy using '.' Example: "Menu.Window.X" */ @@ -70,7 +70,7 @@ public: std::stringstream ss(key); std::string line; - nlohmann::json *json = &data; + nlohmann::json* json = &data; while (getline(ss, line, '.')) json = &((*json)[line]); @@ -88,7 +88,7 @@ public: std::stringstream ss(key); std::string line; - nlohmann::json *json = &data; + nlohmann::json* json = &data; while (getline(ss, line, '.')) json = &((*json)[line]); @@ -96,7 +96,7 @@ public: *json = val; } /* - Loads the section names into a category vector. + Loads the section names into a category vector. Used to create drop down category menus */ void LoadData(std::vector& vec, std::string& selected); diff --git a/src/Menu.cpp b/src/Menu.cpp index d12d264..d6e69c0 100644 --- a/src/Menu.cpp +++ b/src/Menu.cpp @@ -23,7 +23,7 @@ HotKeyData Menu::hotkeys::freecam{}; HotKeyData Menu::hotkeys::command_window{}; HotKeyData Menu::hotkeys::flip_veh{}; HotKeyData Menu::hotkeys::fix_veh{}; -HotKeyData Menu::hotkeys::free_cam_tp_player{VK_RETURN,VK_RETURN}; +HotKeyData Menu::hotkeys::free_cam_tp_player{ VK_RETURN,VK_RETURN }; HotKeyData Menu::hotkeys::god_mode{}; HotKeyData Menu::hotkeys::menu_open{}; HotKeyData Menu::hotkeys::quick_ss{}; @@ -37,67 +37,60 @@ char Menu::commands::input_buffer[INPUT_BUFFER_SIZE] = ""; Menu::Menu() { - Events::initGameEvent += [] - { - // improve these later, use struct - // Load config data - overlay::coord = config.GetValue("overlay.coord", false); - overlay::fps = config.GetValue("overlay.fps", false); - overlay::loc_name = config.GetValue("overlay.loc_name", false); - overlay::transparent = config.GetValue("overlay.transparent", false); - overlay::veh_health = config.GetValue("overlay.veh_health", false); - overlay::veh_speed = config.GetValue("overlay.veh_speed", false); - overlay::selected_pos = config.GetValue("overlay.selected_pos", 4); - overlay::posX = config.GetValue("overlay.posX", 0); - overlay::posY = config.GetValue("overlay.posY", 0); + // TODO: use structs + // Load config data + overlay::coord = config.GetValue("overlay.coord", false); + overlay::fps = config.GetValue("overlay.fps", false); + overlay::loc_name = config.GetValue("overlay.loc_name", false); + overlay::transparent = config.GetValue("overlay.transparent", false); + overlay::veh_health = config.GetValue("overlay.veh_health", false); + overlay::veh_speed = config.GetValue("overlay.veh_speed", false); + overlay::selected_pos = config.GetValue("overlay.selected_pos", 4); + overlay::posX = config.GetValue("overlay.posX", 0); + overlay::posY = config.GetValue("overlay.posY", 0); - // Hotkeys - hotkeys::aim_skin_changer.key1 = config.GetValue("hotkey.aim_skin_changer.key1", VK_RETURN); - hotkeys::aim_skin_changer.key2 = config.GetValue("hotkey.aim_skin_changer.key2", VK_RETURN); + // Hotkeys + hotkeys::aim_skin_changer.key1 = config.GetValue("hotkey.aim_skin_changer.key1", VK_RETURN); + hotkeys::aim_skin_changer.key2 = config.GetValue("hotkey.aim_skin_changer.key2", VK_RETURN); - hotkeys::freecam.key1 = config.GetValue("hotkey.freecam.key1", VK_F6); - hotkeys::freecam.key2 = config.GetValue("hotkey.freecam.key2", VK_F6); + hotkeys::freecam.key1 = config.GetValue("hotkey.freecam.key1", VK_F6); + hotkeys::freecam.key2 = config.GetValue("hotkey.freecam.key2", VK_F6); - hotkeys::quick_ss.key1 = config.GetValue("hotkey.quick_screenshot.key1", VK_F5); - hotkeys::quick_ss.key2 = config.GetValue("hotkey.quick_screenshot.key2", VK_F5); + hotkeys::quick_ss.key1 = config.GetValue("hotkey.quick_screenshot.key1", VK_F5); + hotkeys::quick_ss.key2 = config.GetValue("hotkey.quick_screenshot.key2", VK_F5); - hotkeys::quick_tp.key1 = config.GetValue("hotkey.quick_tp.key1", VK_KEY_X); - hotkeys::quick_tp.key2 = config.GetValue("hotkey.quick_tp.key2", VK_KEY_Y); + hotkeys::quick_tp.key1 = config.GetValue("hotkey.quick_tp.key1", VK_KEY_X); + hotkeys::quick_tp.key2 = config.GetValue("hotkey.quick_tp.key2", VK_KEY_Y); - hotkeys::menu_open.key1 = config.GetValue("hotkey.menu_open.key1", VK_LCONTROL); - hotkeys::menu_open.key2 = config.GetValue("hotkey.menu_open.key2", VK_KEY_M); + hotkeys::menu_open.key1 = config.GetValue("hotkey.menu_open.key1", VK_LCONTROL); + hotkeys::menu_open.key2 = config.GetValue("hotkey.menu_open.key2", VK_KEY_M); - hotkeys::command_window.key1 = config.GetValue("hotkey.command_window.key1", VK_LMENU); - hotkeys::command_window.key2 = config.GetValue("hotkey.command_window.key2", VK_KEY_C); + hotkeys::command_window.key1 = config.GetValue("hotkey.command_window.key1", VK_LMENU); + hotkeys::command_window.key2 = config.GetValue("hotkey.command_window.key2", VK_KEY_C); - hotkeys::flip_veh.key1 = config.GetValue("hotkey.flip_veh.key1", VK_NONE); - hotkeys::flip_veh.key2 = config.GetValue("hotkey.flip_veh.key2", VK_NONE); + hotkeys::flip_veh.key1 = config.GetValue("hotkey.flip_veh.key1", VK_NONE); + hotkeys::flip_veh.key2 = config.GetValue("hotkey.flip_veh.key2", VK_NONE); - hotkeys::fix_veh.key1 = config.GetValue("hotkey.fix_veh.key1", VK_NONE); - hotkeys::fix_veh.key2 = config.GetValue("hotkey.fix_veh.key2", VK_NONE); + hotkeys::fix_veh.key1 = config.GetValue("hotkey.fix_veh.key1", VK_NONE); + hotkeys::fix_veh.key2 = config.GetValue("hotkey.fix_veh.key2", VK_NONE); - hotkeys::god_mode.key1 = config.GetValue("hotkey.god_mode.key1", VK_NONE); - hotkeys::god_mode.key2 = config.GetValue("hotkey.god_mode.key2", VK_NONE); + hotkeys::god_mode.key1 = config.GetValue("hotkey.god_mode.key1", VK_NONE); + hotkeys::god_mode.key2 = config.GetValue("hotkey.god_mode.key2", VK_NONE); - hotkeys::veh_engine.key1 = config.GetValue("hotkey.veh_engine.key1", VK_NONE); - hotkeys::veh_engine.key2 = config.GetValue("hotkey.veh_engine.key2", VK_NONE); + hotkeys::veh_engine.key1 = config.GetValue("hotkey.veh_engine.key1", VK_NONE); + hotkeys::veh_engine.key2 = config.GetValue("hotkey.veh_engine.key2", VK_NONE); - hotkeys::veh_instant_start.key1 = config.GetValue("hotkey.veh_instant_start.key1", VK_NONE); - hotkeys::veh_instant_start.key2 = config.GetValue("hotkey.veh_instant_start.key2", VK_NONE); + hotkeys::veh_instant_start.key1 = config.GetValue("hotkey.veh_instant_start.key1", VK_NONE); + hotkeys::veh_instant_start.key2 = config.GetValue("hotkey.veh_instant_start.key2", VK_NONE); - hotkeys::veh_instant_stop.key1 = config.GetValue("hotkey.veh_instant_stop.key1", VK_NONE); - hotkeys::veh_instant_stop.key2 = config.GetValue("hotkey.veh_instant_stop.key2", VK_NONE); - }; -} - -Menu::~Menu() -{ + hotkeys::veh_instant_stop.key1 = config.GetValue("hotkey.veh_instant_stop.key1", VK_NONE); + hotkeys::veh_instant_stop.key2 = config.GetValue("hotkey.veh_instant_stop.key2", VK_NONE); } void Menu::ProcessOverlay() { - CPlayerPed *player = FindPlayerPed(); - bool show_menu = overlay::coord || overlay::fps || overlay::loc_name || + CPlayerPed* player = FindPlayerPed(); + bool show_menu = overlay::coord || overlay::fps || overlay::loc_name || ((overlay::veh_health || overlay::veh_speed) && player->m_pVehicle && player->m_pVehicle->IsDriver(player)); int corner = overlay::selected_pos - 1; @@ -126,13 +119,13 @@ void Menu::ProcessOverlay() if (show_menu && ImGui::Begin("Overlay", NULL, window_flags)) { - CPlayerPed *player = FindPlayerPed(); - + CPlayerPed* player = FindPlayerPed(); + if (overlay::coord) { CVector pos = player->GetPosition(); - std::string text = "Coord: " + std::to_string(int(pos.x)) + ", " + std::to_string(int(pos.y)) + ", " + std::string text = "Coord: " + std::to_string(int(pos.x)) + ", " + std::to_string(int(pos.y)) + ", " + std::to_string(int(pos.z)); ImGui::Text(text.c_str()); @@ -151,7 +144,7 @@ void Menu::ProcessOverlay() if (overlay::veh_speed) { - int speed = player->m_pVehicle->m_vecMoveSpeed.Magnitude()*50; // 02E3 - GET_CAR_SPEED + int speed = player->m_pVehicle->m_vecMoveSpeed.Magnitude() * 50; // 02E3 - GET_CAR_SPEED ImGui::Text((std::string("Veh Speed: ") + std::to_string(speed)).c_str()); } } @@ -164,35 +157,35 @@ void Menu::ProcessOverlay() } } -void Menu::ProcessShortcutsWindow() +void Menu::DrawShortcutsWindow() { - int resX = int(screen::GetScreenWidth()); - int resY = int(screen::GetScreenHeight()); + int resX = int(screen::GetScreenWidth()); + int resY = int(screen::GetScreenHeight()); - ImGui::SetNextWindowPos(ImVec2(0, resY - 40), ImGuiCond_Always); - ImGui::SetNextWindowSize(ImVec2(resX, 40)); + ImGui::SetNextWindowPos(ImVec2(0, resY - 40), ImGuiCond_Always); + ImGui::SetNextWindowSize(ImVec2(resX, 40)); - ImGuiWindowFlags flags = ImGuiWindowFlags_NoDecoration + ImGuiWindowFlags_AlwaysAutoResize + ImGuiWindowFlags_NoSavedSettings - + ImGuiWindowFlags_NoMove; + ImGuiWindowFlags flags = ImGuiWindowFlags_NoDecoration + ImGuiWindowFlags_AlwaysAutoResize + ImGuiWindowFlags_NoSavedSettings + + ImGuiWindowFlags_NoMove; - if (ImGui::Begin("Shortcuts window", NULL, flags)) + if (ImGui::Begin("Shortcuts window", NULL, flags)) + { + ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(ImGui::GetStyle().FramePadding.x, resY / 130)); + ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(3, 3)); + + ImGui::SetNextItemWidth(resX); + ImGui::SetKeyboardFocusHere(-1); + + if (ImGui::InputTextWithHint("##TEXTFIELD", "Enter command", commands::input_buffer, INPUT_BUFFER_SIZE, ImGuiInputTextFlags_EnterReturnsTrue)) { - ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(ImGui::GetStyle().FramePadding.x, resY / 130)); - ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(3, 3)); - - ImGui::SetNextItemWidth(resX); - ImGui::SetKeyboardFocusHere(-1); - - if (ImGui::InputTextWithHint("##TEXTFIELD", "Enter command", commands::input_buffer, INPUT_BUFFER_SIZE, ImGuiInputTextFlags_EnterReturnsTrue)) - { - ProcessCommands(); - commands::show_menu = false; - strcpy(commands::input_buffer,""); - } - - ImGui::PopStyleVar(2); - ImGui::End(); + ProcessCommands(); + commands::show_menu = false; + strcpy(commands::input_buffer, ""); } + + ImGui::PopStyleVar(2); + ImGui::End(); + } } void Menu::ProcessCommands() @@ -217,7 +210,7 @@ void Menu::ProcessCommands() if (command == "time") { - try + try { std::string temp; ss >> temp; @@ -254,7 +247,7 @@ void Menu::ProcessCommands() } if (command == "wep") - { + { std::string wep_name; ss >> wep_name; @@ -278,14 +271,14 @@ void Menu::ProcessCommands() else CHud::SetHelpMessage("Invalid command", false, false, false); } - + return; } if (command == "veh") - { + { std::string veh_name; ss >> veh_name; - + int model = Vehicle::GetModelFromName(veh_name.c_str()); if (model != 0) { @@ -300,7 +293,7 @@ void Menu::ProcessCommands() } } -void Menu::Main() +void Menu::Draw() { if (ImGui::BeginTabBar("Menu", ImGuiTabBarFlags_NoTooltip + ImGuiTabBarFlags_FittingPolicyScroll)) { @@ -336,7 +329,7 @@ void Menu::Main() config.SetValue("overlay.veh_speed", overlay::veh_speed); ImGui::Columns(1); - + ImGui::EndTabItem(); } if (ImGui::BeginTabItem("Hotkeys")) @@ -358,7 +351,7 @@ void Menu::Main() config.SetValue("hotkey.command_window.key2", hotkeys::command_window.key2); } - ImGui::Dummy(ImVec2(0,10)); + ImGui::Dummy(ImVec2(0, 10)); if (Ui::HotKey("Activate aim skin changer", hotkeys::aim_skin_changer)) { @@ -381,7 +374,7 @@ void Menu::Main() config.SetValue("hotkey.quick_tp.key2", hotkeys::quick_tp.key2); } - ImGui::Dummy(ImVec2(0,10)); + ImGui::Dummy(ImVec2(0, 10)); if (Ui::HotKey("Fix current vehicle", hotkeys::fix_veh)) { @@ -475,7 +468,7 @@ void Menu::Main() if (ImGui::Button("GitHub repo", ImVec2(Ui::GetSize(2)))) ShellExecute(NULL, "open", GITHUB_LINK, NULL, NULL, SW_SHOWNORMAL); - + ImGui::Spacing(); if (ImGui::BeginChild("AboutChild")) @@ -490,14 +483,14 @@ void Menu::Main() ImGui::Text((std::string("Build: ") + BUILD_NUMBER).c_str()); ImGui::Columns(1); - + ImGui::Dummy(ImVec2(0, 10)); ImGui::TextWrapped("If you find bugs or have suggestions, let me know on discord."); ImGui::Dummy(ImVec2(0, 10)); ImGui::TextWrapped("Thanks to Junior-Djjr"); ImGui::Dummy(ImVec2(0, 10)); Ui::CenterdText("Copyright GPLv3 2019-2021 Grinch_"); - + ImGui::EndChild(); } diff --git a/src/Menu.h b/src/Menu.h index 094fbd9..a10f9f5 100644 --- a/src/Menu.h +++ b/src/Menu.h @@ -40,10 +40,9 @@ public: }; Menu(); - ~Menu(); - static void Main(); + static void Draw(); static void ProcessOverlay(); - static void ProcessShortcutsWindow(); + static void DrawShortcutsWindow(); static void ProcessCommands(); }; diff --git a/src/MenuInfo.h b/src/MenuInfo.h index d550cb7..272d013 100644 --- a/src/MenuInfo.h +++ b/src/MenuInfo.h @@ -1,5 +1,5 @@ #pragma once #define MENU_NAME "Cheat Menu" #define MENU_VERSION "2.6-beta" -#define BUILD_NUMBER "20210221" +#define BUILD_NUMBER "20210225" #define MENU_TITLE MENU_NAME " v" MENU_VERSION "(" BUILD_NUMBER ")" \ No newline at end of file diff --git a/src/Neon.cpp b/src/Neon.cpp index ab29ae1..ca5df31 100644 --- a/src/Neon.cpp +++ b/src/Neon.cpp @@ -7,24 +7,20 @@ RwTexture* Neon::neon_texture = nullptr; Neon::Neon() { - Events::initGameEvent += [this] - { - neon_texture = Util::LoadTextureFromPngFile(PLUGIN_PATH((char*)"CheatMenu\\vehicles\\neon_mask.png")); + neon_texture = Util::LoadTextureFromPngFile(PLUGIN_PATH((char*)"CheatMenu\\vehicles\\neon_mask.png")); + if (!neon_texture) + flog << "WARN: Failed to load neon mask" << std::endl; - if (!neon_texture) - flog << "Failed to load neon mask" << std::endl; - }; - - Events::vehicleRenderEvent += [](CVehicle *pVeh) + Events::vehicleRenderEvent += [](CVehicle* pVeh) { - NeonData *data = &VehNeon.Get(pVeh); + NeonData* data = &VehNeon.Get(pVeh); if (data->neon_installed && !pVeh->IsUpsideDown()) { CVector Pos = CModelInfo::GetModelInfo(pVeh->m_nModelIndex)->m_pColModel->m_boundBox.m_vecMin; - CVector center = pVeh->TransformFromObjectSpace(CVector(0.0f, 0.0f, 0.0f)); + CVector center = pVeh->TransformFromObjectSpace(CVector(0.0f, 0.0f, 0.0f)); CVector up = pVeh->TransformFromObjectSpace(CVector(0.0f, -Pos.y - data->val, 0.0f)) - center; - CVector right = pVeh->TransformFromObjectSpace(CVector(Pos.x + data->val, 0.0f, 0.0f)) - center; - CShadows::StoreShadowToBeRendered(5, neon_texture, ¢er, up.x, up.y, right.x, right.y, 180, data->color.r, data->color.g, data->color.b, 2.0f, false, 1.0f, 0, true); + CVector right = pVeh->TransformFromObjectSpace(CVector(Pos.x + data->val, 0.0f, 0.0f)) - center; + CShadows::StoreShadowToBeRendered(5, neon_texture, ¢er, up.x, up.y, right.x, right.y, 180, data->color.r, data->color.g, data->color.b, 2.0f, false, 1.0f, 0, true); if (CTimer::m_snTimeInMilliseconds - data->timer > 150) { @@ -33,7 +29,7 @@ Neon::Neon() if (data->pulsing) { if (data->val < 0.0f) - data->increment = true; + data->increment = true; if (data->val > 0.3f) data->increment = false; @@ -53,24 +49,24 @@ Neon::~Neon() delete neon_texture; } -bool Neon::IsNeonInstalled(CVehicle *pVeh) +bool Neon::IsNeonInstalled(CVehicle* pVeh) { return VehNeon.Get(pVeh).neon_installed; } -bool Neon::IsPulsingEnabled(CVehicle *pVeh) +bool Neon::IsPulsingEnabled(CVehicle* pVeh) { return VehNeon.Get(pVeh).pulsing; } -void Neon::SetPulsing(CVehicle *pVeh, bool state) +void Neon::SetPulsing(CVehicle* pVeh, bool state) { VehNeon.Get(pVeh).pulsing = state; } -void Neon::InstallNeon(CVehicle *pVeh, int red, int green, int blue) +void Neon::InstallNeon(CVehicle* pVeh, int red, int green, int blue) { - CRGBA &color = VehNeon.Get(pVeh).color; + CRGBA& color = VehNeon.Get(pVeh).color; color.r = red; color.g = green; @@ -80,7 +76,7 @@ void Neon::InstallNeon(CVehicle *pVeh, int red, int green, int blue) VehNeon.Get(pVeh).neon_installed = true; } -void Neon::RemoveNeon(CVehicle *pVeh) +void Neon::RemoveNeon(CVehicle* pVeh) { VehNeon.Get(pVeh).neon_installed = false; } diff --git a/src/Neon.h b/src/Neon.h index dfa0ce9..7801360 100644 --- a/src/Neon.h +++ b/src/Neon.h @@ -6,32 +6,32 @@ private: static RwTexture* neon_texture; class NeonData { - public: + public: CRGBA color; - bool neon_installed; + bool neon_installed; float val; uint timer; bool increment; - bool pulsing; + bool pulsing; - NeonData(CVehicle *pVeh) - { - neon_installed = false; + NeonData(CVehicle* pVeh) + { + neon_installed = false; val = 0.0; timer = 0; increment = true; } - }; + }; - static VehicleExtendedData VehNeon; + static VehicleExtendedData VehNeon; public: Neon(); ~Neon(); - static void InstallNeon(CVehicle *veh, int red, int green, int blue); - static bool IsNeonInstalled(CVehicle *veh); - static bool IsPulsingEnabled(CVehicle *veh); - static void SetPulsing(CVehicle *veh, bool state); - static void RemoveNeon(CVehicle *veh); + static void InstallNeon(CVehicle* veh, int red, int green, int blue); + static bool IsNeonInstalled(CVehicle* veh); + static bool IsPulsingEnabled(CVehicle* veh); + static void SetPulsing(CVehicle* veh, bool state); + static void RemoveNeon(CVehicle* veh); }; diff --git a/src/Paint.cpp b/src/Paint.cpp index b784fec..1cc4990 100644 --- a/src/Paint.cpp +++ b/src/Paint.cpp @@ -36,19 +36,16 @@ std::map> Paint::textures; Paint::Paint() { - Events::initGameEvent += [] + for (auto& p : fs::recursive_directory_iterator(PLUGIN_PATH((char*)"\\CheatMenu\\vehicles\\paintjobs\\"))) { - for (auto &p : fs::recursive_directory_iterator(PLUGIN_PATH((char*)"\\CheatMenu\\vehicles\\paintjobs\\"))) + if (p.path().extension() == ".png") { - if (p.path().extension() == ".png") - { - std::string file_name = p.path().stem().string(); - textures[file_name]= std::make_shared(*(Util::LoadTextureFromPngFile(p.path()))); - } + std::string file_name = p.path().stem().string(); + textures[file_name] = std::make_shared(*(Util::LoadTextureFromPngFile(p.path()))); } - }; - - Events::vehicleRenderEvent.before += [](CVehicle* veh) + } + + Events::vehicleRenderEvent.before += [](CVehicle* veh) { VehData& data = vehdata.Get(veh); @@ -104,16 +101,11 @@ Paint::Paint() }; } -Paint::~Paint() -{ -} - - void Paint::VehData::setMaterialColor(RpMaterial* material, RpGeometry* geometry, RwRGBA color, bool filter_mat) { auto& matProps = materialProperties[material]; - - if ( !filter_mat + + if (!filter_mat || (material->color.red == 0x3C && material->color.green == 0xFF && material->color.blue == 0x00) || (material->color.red == 0xFF && material->color.green == 0x00 && material->color.blue == 0xAF)) { @@ -140,7 +132,7 @@ void Paint::VehData::resetMaterialColor(RpMaterial* material) { auto& matProps = materialProperties[material]; matProps._recolor = false; - matProps._color = {0, 0, 0, 0}; + matProps._color = { 0, 0, 0, 0 }; } void Paint::VehData::resetMaterialTexture(RpMaterial* material) @@ -150,15 +142,15 @@ void Paint::VehData::resetMaterialTexture(RpMaterial* material) matProps._texture.reset(); } -void Paint::NodeWrapperRecursive(RwFrame *frame, CVehicle* pVeh, std::function func) +void Paint::NodeWrapperRecursive(RwFrame* frame, CVehicle* pVeh, std::function func) { if (frame) { func(frame); - if (RwFrame * newFrame = frame->child) + if (RwFrame* newFrame = frame->child) NodeWrapperRecursive(newFrame, pVeh, func); - if (RwFrame * newFrame = frame->next) + if (RwFrame* newFrame = frame->next) NodeWrapperRecursive(newFrame, pVeh, func); } return; @@ -166,9 +158,9 @@ void Paint::NodeWrapperRecursive(RwFrame *frame, CVehicle* pVeh, std::functionm_pRwClump->object.parent; + RwFrame* frame = (RwFrame*)pVeh->m_pRwClump->object.parent; - NodeWrapperRecursive(frame, pVeh, [](RwFrame *frame) + NodeWrapperRecursive(frame, pVeh, [](RwFrame* frame) { const std::string name = GetFrameNodeName(frame); @@ -179,9 +171,9 @@ void Paint::UpdateNodeListRecursive(CVehicle* pVeh) void Paint::SetNodeColor(CVehicle* pVeh, std::string node_name, CRGBA color, bool filter_mat) { - RwFrame *frame = (RwFrame *)pVeh->m_pRwClump->object.parent; + RwFrame* frame = (RwFrame*)pVeh->m_pRwClump->object.parent; - NodeWrapperRecursive(frame, pVeh, [&](RwFrame *frame) + NodeWrapperRecursive(frame, pVeh, [&](RwFrame* frame) { const std::string name = GetFrameNodeName(frame); @@ -199,7 +191,7 @@ void Paint::SetNodeColor(CVehicle* pVeh, std::string node_name, CRGBA color, boo RwFrameForAllObjects(frame, [](RwObject* object, void* data) -> RwObject* { if (object->type == rpATOMIC) { - RpAtomic *atomic = reinterpret_cast(object); + RpAtomic* atomic = reinterpret_cast(object); ST* st = reinterpret_cast(data); CRGBA* color = &st->_color; @@ -219,8 +211,8 @@ void Paint::SetNodeColor(CVehicle* pVeh, std::string node_name, CRGBA color, boo void Paint::SetNodeTexture(CVehicle* pVeh, std::string node_name, std::string texturename, bool filter_mat) { - RwFrame *frame = (RwFrame *)pVeh->m_pRwClump->object.parent; - NodeWrapperRecursive(frame, pVeh, [&](RwFrame *frame) + RwFrame* frame = (RwFrame*)pVeh->m_pRwClump->object.parent; + NodeWrapperRecursive(frame, pVeh, [&](RwFrame* frame) { const std::string name = GetFrameNodeName(frame); @@ -241,7 +233,7 @@ void Paint::SetNodeTexture(CVehicle* pVeh, std::string node_name, std::string te if (object->type == rpATOMIC) { - RpAtomic *atomic = reinterpret_cast(object); + RpAtomic* atomic = reinterpret_cast(object); ST* st = reinterpret_cast(data); VehData& data = vehdata.Get(FindPlayerPed()->m_pVehicle); @@ -255,11 +247,11 @@ void Paint::SetNodeTexture(CVehicle* pVeh, std::string node_name, std::string te }); } -void Paint::ResetNodeColor(CVehicle *pVeh, std::string node_name) +void Paint::ResetNodeColor(CVehicle* pVeh, std::string node_name) { - RwFrame *frame = (RwFrame *)pVeh->m_pRwClump->object.parent; + RwFrame* frame = (RwFrame*)pVeh->m_pRwClump->object.parent; - NodeWrapperRecursive(frame, pVeh, [&](RwFrame *frame) + NodeWrapperRecursive(frame, pVeh, [&](RwFrame* frame) { const std::string name = GetFrameNodeName(frame); @@ -268,7 +260,7 @@ void Paint::ResetNodeColor(CVehicle *pVeh, std::string node_name) RwFrameForAllObjects(frame, [](RwObject* object, void* data) -> RwObject* { if (object->type == rpATOMIC) { - RpAtomic *atomic = reinterpret_cast(object); + RpAtomic* atomic = reinterpret_cast(object); VehData& data = vehdata.Get(FindPlayerPed()->m_pVehicle); for (int i = 0; i < atomic->geometry->matList.numMaterials; ++i) @@ -280,11 +272,11 @@ void Paint::ResetNodeColor(CVehicle *pVeh, std::string node_name) }); } -void Paint::ResetNodeTexture(CVehicle *pVeh, std::string node_name) +void Paint::ResetNodeTexture(CVehicle* pVeh, std::string node_name) { - RwFrame *frame = (RwFrame *)pVeh->m_pRwClump->object.parent; + RwFrame* frame = (RwFrame*)pVeh->m_pRwClump->object.parent; - NodeWrapperRecursive(frame, pVeh, [&](RwFrame *frame) + NodeWrapperRecursive(frame, pVeh, [&](RwFrame* frame) { const std::string name = GetFrameNodeName(frame); @@ -294,7 +286,7 @@ void Paint::ResetNodeTexture(CVehicle *pVeh, std::string node_name) if (object->type == rpATOMIC) { - RpAtomic *atomic = reinterpret_cast(object); + RpAtomic* atomic = reinterpret_cast(object); VehData& data = vehdata.Get(FindPlayerPed()->m_pVehicle); diff --git a/src/Paint.h b/src/Paint.h index 5208f1e..eab4574 100644 --- a/src/Paint.h +++ b/src/Paint.h @@ -32,14 +32,14 @@ private: // store vehicle specific data struct VehData - { + { struct MaterialProperties { MaterialProperties() : - _color{0, 0, 0, 0}, + _color{ 0, 0, 0, 0 }, _recolor(false), _retexture(false), - _originalColor{0, 0, 0, 0}, + _originalColor{ 0, 0, 0, 0 }, _originalTexture(nullptr), _originalGeometryFlags(0), _geometry(nullptr) @@ -83,14 +83,13 @@ protected: static std::vector names_vec; static std::string selected; }; - + Paint(); - ~Paint(); static void UpdateNodeListRecursive(CVehicle* pVeh); - static void NodeWrapperRecursive(RwFrame * frame, CVehicle* pVeh, std::function func); + static void NodeWrapperRecursive(RwFrame* frame, CVehicle* pVeh, std::function func); static void SetNodeColor(CVehicle* pVeh, std::string node_name, CRGBA color, bool filter_mat = false); static void SetNodeTexture(CVehicle* pVeh, std::string node_name, std::string texturename, bool filter_mat = false); - static void ResetNodeColor(CVehicle *veh, std::string node_name); - static void ResetNodeTexture(CVehicle *pVeh, std::string node_name); + static void ResetNodeColor(CVehicle* veh, std::string node_name); + static void ResetNodeTexture(CVehicle* pVeh, std::string node_name); }; diff --git a/src/Ped.cpp b/src/Ped.cpp index 035f8cc..867ee52 100644 --- a/src/Ped.cpp +++ b/src/Ped.cpp @@ -7,6 +7,7 @@ ImGuiTextFilter Ped::filter = ""; std::string Ped::selected_item = "All"; std::vector Ped::search_categories; std::vector> Ped::peds_vec; +bool Ped::images_loaded = false; CJson Ped::ped_json = CJson("ped"); CJson Ped::pedspecial_json = CJson("ped special"); @@ -25,18 +26,21 @@ bool Ped::spawn_ped::dont_move = false; bool Ped::spawn_ped::ped_bleed = false; int Ped::spawn_ped::weapon_id = 0; -std::vector Ped::spawn_ped::ped_type = {"Civ male","Civ female","Cop","Ballas","Grove Street Families","Los Santos Vagos", +std::vector Ped::spawn_ped::ped_type = { "Civ male","Civ female","Cop","Ballas","Grove Street Families","Los Santos Vagos", "San Fierro Rifa","Da Nang Boys","Mafia","Mountain Cloud Triads","Varrio Los Aztecas", - "Gang 9","Medic","Dealer","Criminal","Fireman","Prostitute"}; + "Gang 9","Medic","Dealer","Criminal","Fireman","Prostitute" }; Ped::Ped() { - Events::initGameEvent += [] - { - Util::LoadTexturesInDirRecursive(PLUGIN_PATH((char*)"CheatMenu\\peds\\"), ".jpg", search_categories, peds_vec); + if (GetModuleHandle("ExGangWars.asi")) + exgangwars_installed = true; - if (LoadLibraryW(L"ExGangWars.asi")) - exgangwars_installed = true; - + Events::processScriptsEvent += [] + { + if (!images_loaded) + { + Util::LoadTexturesInDirRecursive(PLUGIN_PATH((char*)"CheatMenu\\peds\\"), ".jpg", search_categories, peds_vec); + images_loaded = true; + } }; } @@ -59,11 +63,11 @@ void Ped::SpawnPed(std::string& model) if (Ped::ped_json.data.contains(model)) { - CPlayerPed *player = FindPlayerPed(); + CPlayerPed* player = FindPlayerPed(); CVector pos = player->GetPosition(); pos.y += 1; - CPed *ped; + CPed* ped; int hplayer; if (Ped::pedspecial_json.data.contains(model)) @@ -81,12 +85,12 @@ void Ped::SpawnPed(std::string& model) CStreaming::SetSpecialCharIsDeletable(291); } else - { + { int imodel = std::stoi(model); CStreaming::RequestModel(imodel, eStreamingFlags::PRIORITY_REQUEST); CStreaming::LoadAllRequestedModels(false); - Command (spawn_ped::selected_ped_type + 4,imodel,pos.x,pos.y,pos.z+1,&hplayer); + Command (spawn_ped::selected_ped_type + 4, imodel, pos.x, pos.y, pos.z + 1, &hplayer); CStreaming::SetModelIsDeletable(imodel); } @@ -101,7 +105,7 @@ void Ped::SpawnPed(std::string& model) ped->m_nPedFlags.bPedIsBleeding = spawn_ped::ped_bleed; ped->m_nWeaponAccuracy = spawn_ped::accuracy; ped->m_fHealth = spawn_ped::health; - + if (spawn_ped::weapon_id != 0) { int model = 0; @@ -113,7 +117,7 @@ void Ped::SpawnPed(std::string& model) } } -void Ped::Main() +void Ped::Draw() { if (ImGui::BeginTabBar("Ped", ImGuiTabBarFlags_NoTooltip + ImGuiTabBarFlags_FittingPolicyScroll)) { @@ -154,9 +158,9 @@ void Ped::Main() CGangWars::StartDefensiveGangWar(); else CGangWars::StartOffensiveGangWar(); - + CGangWars::bGangWarsActive = true; - } + } ImGui::SameLine(); if (ImGui::Button("End gang war", ImVec2(Ui::GetSize(2)))) CGangWars::EndGangWar(true); @@ -170,9 +174,9 @@ void Ped::Main() { CVector pos = FindPlayerPed()->GetPosition(); CZone szone = CZone(); - CZone *pZone = &szone; + CZone* pZone = &szone; - CZoneExtraInfo *zone_info = CTheZones::GetZoneInfo(&pos, &pZone); + CZoneExtraInfo* zone_info = CTheZones::GetZoneInfo(&pos, &pZone); int density = zone_info->m_nGangDensity[i]; if (ImGui::SliderInt(Ped::gang_names[i].c_str(), &density, 0, 127)) @@ -201,7 +205,7 @@ void Ped::Main() if (ImGui::CollapsingHeader("Recruit anyone")) { - static std::vector select_weapon{ {"9mm", 0x96917C}, { "AK47", 0x96917D }, { "Rockets", 0x96917E }}; + static std::vector select_weapon{ {"9mm", 0x96917C}, { "AK47", 0x96917D }, { "Rockets", 0x96917E } }; Ui::RadioButtonAddress("Select weapon", select_weapon); ImGui::Spacing(); ImGui::Separator(); @@ -210,12 +214,12 @@ void Ped::Main() { ImGui::InputInt("Radius", &ped_remove_radius); ImGui::Spacing(); - if (ImGui::Button("Remove peds",Ui::GetSize(1))) + if (ImGui::Button("Remove peds", Ui::GetSize(1))) { - CPlayerPed *player = FindPlayerPed(); - for (CPed *ped : CPools::ms_pPedPool) + CPlayerPed* player = FindPlayerPed(); + for (CPed* ped : CPools::ms_pPedPool) { - if (DistanceBetweenPoints(ped->GetPosition(),player->GetPosition()) < ped_remove_radius + if (DistanceBetweenPoints(ped->GetPosition(), player->GetPosition()) < ped_remove_radius && ped->m_pVehicle == nullptr && ped != player) Command(CPools::GetPedRef(ped)); } diff --git a/src/Ped.h b/src/Ped.h index 4624b74..f71fe8b 100644 --- a/src/Ped.h +++ b/src/Ped.h @@ -9,6 +9,7 @@ private: static std::string selected_item; static std::vector search_categories; static std::vector> peds_vec; + static bool images_loaded; static CJson ped_json; static CJson pedspecial_json; @@ -34,7 +35,7 @@ private: public: Ped(); ~Ped(); - static void Main(); + static void Draw(); static void SpawnPed(std::string& model); }; diff --git a/src/Player.cpp b/src/Player.cpp index f0cb6a3..db37bbc 100644 --- a/src/Player.cpp +++ b/src/Player.cpp @@ -15,6 +15,7 @@ ImGuiTextFilter Player::filter = ""; std::vector Player::search_categories; std::vector> Player::clothes_vec; std::string Player::selected_item = "All"; +bool Player::images_loaded = false; std::string Player::custom_skins::dir = paths::GetGameDirPathA() + std::string("\\modloader\\Custom Skins\\"); std::vector Player::custom_skins::store_vec; @@ -24,51 +25,53 @@ bool Player::modloader_installed = false; static void PlayerModelBrokenFix() { - CPlayerPed *player = FindPlayerPed(); + CPlayerPed* player = FindPlayerPed(); if (player->m_nModelIndex == 0) - Call<0x5A81E0>(0, player->m_pPlayerData->m_pPedClothesDesc,0xBC1C78,false); + Call<0x5A81E0>(0, player->m_pPlayerData->m_pPedClothesDesc, 0xBC1C78, false); } Player::Player() { - Events::initGameEvent += [] + // Fix player model being broken after rebuild + patch::RedirectCall(0x5A834D, &PlayerModelBrokenFix); + + aim_skin_changer = config.GetValue("aim_skin_changer", false); + + // Custom skins setup + if (GetModuleHandle("modloader.asi")) { - // Fix player model being broken after rebuild - patch::RedirectCall(0x5A834D,&PlayerModelBrokenFix); - - aim_skin_changer = config.GetValue("aim_skin_changer", false); - Util::LoadTexturesInDirRecursive(PLUGIN_PATH((char*)"CheatMenu\\clothes\\"), ".jpg", search_categories, clothes_vec); - - // Custom skins setup - if (LoadLibraryW(L"modloader.asi")) + if (fs::is_directory(custom_skins::dir)) { - if (fs::is_directory(custom_skins::dir)) + for (auto& p : fs::recursive_directory_iterator(custom_skins::dir)) { - for (auto &p : fs::recursive_directory_iterator(custom_skins::dir)) + if (p.path().extension() == ".dff") { - if (p.path().extension() == ".dff") - { - std::string file_name = p.path().stem().string(); + std::string file_name = p.path().stem().string(); - if (file_name.size() < 9) - custom_skins::store_vec.push_back(file_name); - else - flog << "Custom Skin '" << file_name << "' longer than 8 characters" << std::endl; - } + if (file_name.size() < 9) + custom_skins::store_vec.push_back(file_name); + else + flog << "WARN: Custom Skin longer than 8 characters " << file_name << std::endl; } } - else fs::create_directory(custom_skins::dir); - - modloader_installed = true; } - }; + else fs::create_directory(custom_skins::dir); + + modloader_installed = true; + } Events::processScriptsEvent += [] { uint timer = CTimer::m_snTimeInMilliseconds; static CPlayerPed* player = FindPlayerPed(); + if (!images_loaded) + { + Util::LoadTexturesInDirRecursive(PLUGIN_PATH((char*)"CheatMenu\\clothes\\"), ".jpg", search_categories, clothes_vec); + images_loaded = true; + } + if (keep_position::state) { if (!player->IsAlive()) @@ -79,7 +82,7 @@ Player::Player() { CVector cur_pos = player->GetPosition(); - if (keep_position::pos.x != 0 && keep_position::pos.x != cur_pos.x + if (keep_position::pos.x != 0 && keep_position::pos.x != cur_pos.x && keep_position::pos.y != 0 && keep_position::pos.y != cur_pos.y) { player->Teleport(keep_position::pos, false); @@ -97,10 +100,10 @@ Player::Player() player->m_nPhysicalFlags.bFireProof = 1; player->m_nPhysicalFlags.bMeeleProof = 1; } - + if (aim_skin_changer && Ui::HotKeyPressed(Menu::hotkeys::aim_skin_changer)) { - CPed *target_ped = player->m_pPlayerTargettedPed; + CPed* target_ped = player->m_pPlayerTargettedPed; if (target_ped) { player->SetModelIndex(target_ped->m_nModelIndex); @@ -112,8 +115,8 @@ Player::Player() { if (god_mode) { - CHud::SetHelpMessage("God mode disabled",false,false,false); - + CHud::SetHelpMessage("God mode disabled", false, false, false); + patch::Set(0x96916D, god_mode, false); player->m_nPhysicalFlags.bBulletProof = false; player->m_nPhysicalFlags.bCollisionProof = false; @@ -124,19 +127,14 @@ Player::Player() } else { - CHud::SetHelpMessage("God mode enabled",false,false,false); + CHud::SetHelpMessage("God mode enabled", false, false, false); god_mode = true; } } }; } - -Player::~Player() -{ -} - -void Player::ChangePlayerCloth(std::string &name) +void Player::ChangePlayerCloth(std::string& name) { std::stringstream ss(name); std::string temp; @@ -150,7 +148,7 @@ void Player::ChangePlayerCloth(std::string &name) getline(ss, temp, '$'); std::string texture9 = temp.c_str(); - CPlayerPed *player = FindPlayerPed(); + CPlayerPed* player = FindPlayerPed(); if (texture9 == "cutoffchinosblue") { @@ -178,7 +176,7 @@ void Player::ChangePlayerModel(std::string& model) bool custom_skin = std::find(custom_skins::store_vec.begin(), custom_skins::store_vec.end(), model) != custom_skins::store_vec.end(); if (Ped::ped_json.data.contains(model) || custom_skin) { - CPlayerPed *player = FindPlayerPed(); + CPlayerPed* player = FindPlayerPed(); if (Ped::pedspecial_json.data.contains(model) || custom_skin) { std::string name; @@ -198,7 +196,7 @@ void Player::ChangePlayerModel(std::string& model) { int imodel = std::stoi(model); - CStreaming::RequestModel(imodel,eStreamingFlags::PRIORITY_REQUEST); + CStreaming::RequestModel(imodel, eStreamingFlags::PRIORITY_REQUEST); CStreaming::LoadAllRequestedModels(false); player->SetModelIndex(imodel); CStreaming::SetModelIsDeletable(imodel); @@ -206,7 +204,7 @@ void Player::ChangePlayerModel(std::string& model) } } -void Player::Main() +void Player::Draw() { static CPlayerPed* player = FindPlayerPed(); static int hplayer = CPools::GetPedRef(player); @@ -223,7 +221,7 @@ void Player::Main() ImGui::SameLine(); if (ImGui::Button("Suicide", ImVec2(Ui::GetSize(2)))) player->m_fHealth = 0.0; - + ImGui::Spacing(); if (ImGui::BeginTabBar("Player", ImGuiTabBarFlags_NoTooltip + ImGuiTabBarFlags_FittingPolicyScroll)) @@ -252,7 +250,7 @@ void Player::Main() Ui::CheckboxAddress("Infinite run", 0xB7CEE4); if (Ui::CheckboxBitFlag("Invisible player", player->m_nPedFlags.bDontRender)) player->m_nPedFlags.bDontRender = (player->m_nPedFlags.bDontRender == 1) ? 0 : 1; - + ImGui::NextColumn(); Ui::CheckboxWithHint("Keep position", &keep_position::state, "Teleport to the position you died from"); @@ -263,10 +261,10 @@ void Player::Main() Ui::CheckboxAddress("Mega punch", 0x969173); Ui::CheckboxAddress("Never get hungry", 0x969174); - bool never_wanted = patch::Get(0x969171, false); + bool never_wanted = patch::Get(0x969171, false); if (Ui::CheckboxWithHint("Never wanted", &never_wanted)) CCheat::NotWantedCheat(); - + ImGui::Columns(1); ImGui::EndChild(); @@ -317,7 +315,7 @@ void Player::Main() Ui::EditStat("Fat", STAT_FAT); Ui::EditReference("Health", player->m_fHealth, 0, 100, static_cast(player->m_fMaxHealth)); Ui::EditStat("Lung capacity", STAT_LUNG_CAPACITY); - Ui::EditStat("Max health", STAT_MAX_HEALTH,0,569,1450); + Ui::EditStat("Max health", STAT_MAX_HEALTH, 0, 569, 1450); Ui::EditAddress("Money", 0xB7CE50, -99999999, 0, 99999999); Ui::EditStat("Muscle", STAT_MUSCLE); Ui::EditStat("Respect", STAT_RESPECT); @@ -332,14 +330,14 @@ void Player::Main() ImGui::NextColumn(); ImGui::Text("Def: 0"); ImGui::NextColumn(); - ImGui::Text("Max: %d",max_wl); + ImGui::Text("Max: %d", max_wl); ImGui::Columns(1); ImGui::Spacing(); if (ImGui::InputInt("Set value##Wanted level", &val)) player->CheatWantedLevel(val); - + ImGui::Spacing(); if (ImGui::Button("Minimum##Wanted level", Ui::GetSize(3))) player->CheatWantedLevel(0); @@ -365,7 +363,7 @@ void Player::Main() if (ImGui::BeginTabItem("Appearance")) { ImGui::Spacing(); - if (Ui::CheckboxWithHint("Aim skin changer", &aim_skin_changer,(("Activate using Aim ped + ") + Ui::GetHotKeyNameString(Menu::hotkeys::aim_skin_changer)).c_str())) + if (Ui::CheckboxWithHint("Aim skin changer", &aim_skin_changer, (("Activate using Aim ped + ") + Ui::GetHotKeyNameString(Menu::hotkeys::aim_skin_changer)).c_str())) config.SetValue("aim_skin_changer", aim_skin_changer); if (ImGui::BeginTabBar("AppearanceTabBar")) @@ -378,7 +376,7 @@ void Player::Main() { if (ImGui::Button("Remove clothes", ImVec2(Ui::GetSize()))) { - CPlayerPed *player = FindPlayerPed(); + CPlayerPed* player = FindPlayerPed(); int temp = 0; for (uint i = 0; i < 18; i++) @@ -389,7 +387,7 @@ void Player::Main() ImGui::Spacing(); Ui::DrawImages(clothes_vec, ImVec2(70, 100), search_categories, selected_item, filter, ChangePlayerCloth, nullptr, - [](std::string str) + [](std::string str) { std::stringstream ss(str); std::string temp; @@ -422,9 +420,9 @@ void Player::Main() if (ImGui::BeginTabItem("Custom skins")) { ImGui::Spacing(); - + if (modloader_installed) - { + { Ui::FilterWithHint("Search", filter, std::string("Total skins: " + std::to_string(custom_skins::store_vec.size())).c_str()); Ui::ShowTooltip("Place your dff & txd files inside 'modloader/Custom Skins'"); ImGui::Spacing(); @@ -434,7 +432,7 @@ void Player::Main() { if (custom_skins::filter.PassFilter(name.c_str())) { - if (ImGui::MenuItem(name.c_str())) + if (ImGui::MenuItem(name.c_str())) { ChangePlayerModel(name); } diff --git a/src/Player.h b/src/Player.h index 6be2631..3fed33e 100644 --- a/src/Player.h +++ b/src/Player.h @@ -14,6 +14,7 @@ private: static std::string selected_item; static std::vector search_categories; static std::vector> clothes_vec; + static bool images_loaded; struct custom_skins { @@ -27,7 +28,6 @@ public: static void ChangePlayerCloth(std::string& model); static void ChangePlayerModel(std::string& model); Player(); - ~Player(); - static void Main(); + static void Draw(); }; diff --git a/src/Teleport.cpp b/src/Teleport.cpp index 7334964..1d50ce3 100644 --- a/src/Teleport.cpp +++ b/src/Teleport.cpp @@ -56,12 +56,7 @@ void Teleport::FetchRadarSpriteData() Teleport::Teleport() { json.LoadData(search_categories, selected_item); - - Events::initGameEvent += [] - { - // Load config data - quick_teleport = config.GetValue("quick_teleport", false); - }; + quick_teleport = config.GetValue("quick_teleport", false); Events::processScriptsEvent += [] { @@ -182,7 +177,7 @@ void Teleport::RemoveTeleportEntry(std::string& category, std::string& key, std: else CHud::SetHelpMessage("You can only remove custom location", false, false, false); } -void Teleport::Main() +void Teleport::Draw() { if (ImGui::BeginTabBar("Teleport",ImGuiTabBarFlags_NoTooltip+ImGuiTabBarFlags_FittingPolicyScroll)) { diff --git a/src/Teleport.h b/src/Teleport.h index 6f548bc..773e62a 100644 --- a/src/Teleport.h +++ b/src/Teleport.h @@ -33,8 +33,8 @@ protected: Teleport(); public: - static void Main(); - static void TeleportPlayer(bool get_marker = false, CVector pos = CVector(0,0,0), short interior_id = 0); + static void Draw(); + static void TeleportPlayer(bool get_marker = false, CVector pos = CVector(0, 0, 0), short interior_id = 0); static void TeleportToLocation(std::string& rootkey, std::string& loc_name, std::string& loc); static void RemoveTeleportEntry(std::string& rootkey, std::string& key, std::string& val); diff --git a/src/TimeCycle.h b/src/TimeCycle.h index e6ed491..86c2236 100644 --- a/src/TimeCycle.h +++ b/src/TimeCycle.h @@ -1,47 +1,47 @@ #include "plugin.h" uchar* m_nDirectionalMult = (uchar*)0x55F7C7; //m_nDirectionalMult[184] - + uchar* m_nWaterFogAlpha = (uchar*)0x55F7B8; //m_nWaterFogAlpha[184] - + uchar* m_nHighLightMinIntensity = (uchar*)0x55F7A9; //m_nHighLightMinIntensity[184] - + uchar* m_fCloudAlpha = (uchar*)0x55F793; //m_fCloudAlpha[184] - + uchar* m_fPostFx2Alpha = (uchar*)0x55F77D; //m_fPostFx2Alpha[184] - + uchar* m_fPostFx2Blue = (uchar*)0x55F767; //m_fPostFx2Blue[184] - + uchar* m_fPostFx2Green = (uchar*)0x55F751; //m_fPostFx2Green[184] - + uchar* m_fPostFx2Red = (uchar*)0x55F73B; //m_fPostFx2Red[184] - + uchar* m_fPostFx1Alpha = (uchar*)0x55F725; //m_fPostFx1Alpha[184] - + uchar* m_fPostFx1Blue = (uchar*)0x55F70F; //m_fPostFx1Blue[184] - + uchar* m_fPostFx1Green = (uchar*)0x55F6FC; //m_fPostFx1Green[184] - + uchar* m_fPostFx1Red = (uchar*)0x55F6E9; //m_fPostFx1Red[184] - + uchar* m_fWaterAlpha = (uchar*)0x55F6D6; //m_fWaterAlpha[184] - + uchar* m_fWaterBlue = (uchar*)0x55F6C3; //m_fWaterBlue[184] - + uchar* m_fWaterGreen = (uchar*)0x55F6B0; //m_fWaterGreen[184] - + uchar* m_fWaterRed = (uchar*)0x55F69C; //m_fWaterRed[184] - + uchar* m_nFluffyCloudsBottomBlue = (uchar*)0x55F690; //m_nFluffyCloudsBottomBlue[184] - + uchar* m_nFluffyCloudsBottomGreen = (uchar*)0x55F683;//m_nFluffyCloudsBottomGreen[184] - + uchar* m_nFluffyCloudsBottomRed = (uchar*)0x55F677; //m_nFluffyCloudsBottomRed[184] - + uchar* m_nLowCloudsBlue = (uchar*)0x55F66B; //m_nLowCloudsBlue[184] - + uchar* m_nLowCloudsGreen = (uchar*)0x55F65F; //m_nLowCloudsGreen[184] - + uchar* m_nLowCloudsRed = (uchar*)0x55F653; //m_nLowCloudsRed[184] uchar* m_fLightsOnGroundBrightness = (uchar*)0x55F640;//m_fLightsOnGroundBrightness[184] diff --git a/src/Ui.cpp b/src/Ui.cpp index 63d4d40..9a0f095 100644 --- a/src/Ui.cpp +++ b/src/Ui.cpp @@ -21,7 +21,7 @@ bool Ui::ListBox(const char* label, std::vector& all_items, int& se rtn = true; } } - } + } ImGui::EndCombo(); } return rtn; @@ -49,14 +49,14 @@ bool Ui::ListBoxStr(const char* label, std::vector& all_items, std: return rtn; } -ImVec2 Ui::GetSize(short count,bool spacing) +ImVec2 Ui::GetSize(short count, bool spacing) { if (count == 1) spacing = false; float factor = ImGui::GetStyle().ItemSpacing.x / 2.0f; float x; - + if (count == 3) factor = ImGui::GetStyle().ItemSpacing.x / 1.403f; @@ -65,14 +65,14 @@ ImVec2 Ui::GetSize(short count,bool spacing) else x = ImGui::GetWindowContentRegionWidth() / count; - return ImVec2(x, ImGui::GetFrameHeight()*1.3f); + return ImVec2(x, ImGui::GetFrameHeight() * 1.3f); } -void Ui::CenterdText(const std::string& text) +void Ui::CenterdText(const std::string& text) { float font_size = ImGui::GetFontSize() * text.size() / 2; ImGui::NewLine(); - ImGui::SameLine(ImGui::GetWindowSize().x / 2 -font_size + (font_size / 1.8)); + ImGui::SameLine(ImGui::GetWindowSize().x / 2 - font_size + (font_size / 1.8)); ImGui::Text(text.c_str()); } @@ -138,7 +138,7 @@ void Ui::DrawHeaders(unsortedMap& data) } else { - if ( func != nullptr && ImGui::BeginChild("TABSBAR")) + if (func != nullptr && ImGui::BeginChild("TABSBAR")) { ((void(*)(void))func)(); ImGui::EndChild(); @@ -159,14 +159,14 @@ void Ui::ShowTooltip(const char* text) } } -bool Ui::CheckboxWithHint(const char* label, bool *v, const char * hint, bool is_disabled) +bool Ui::CheckboxWithHint(const char* label, bool* v, const char* hint, bool is_disabled) { // set things up bool pressed = false; const ImGuiStyle& style = ImGui::GetStyle(); const ImVec2 text_size = ImGui::CalcTextSize(label, NULL, true); float square_sz = ImGui::GetFrameHeight(); - ImDrawList *drawlist = ImGui::GetWindowDrawList(); + ImDrawList* drawlist = ImGui::GetWindowDrawList(); ImU32 color = ImGui::GetColorU32(ImGuiCol_FrameBg); std::string slabel = "##InvCheckboxBtn" + std::string(label); @@ -241,14 +241,14 @@ bool Ui::CheckboxWithHint(const char* label, bool *v, const char * hint, bool is if (is_disabled) ImGui::PopStyleVar(); - + return pressed; } bool Ui::CheckboxAddress(const char* label, const int addr, const char* hint) { bool rtn = false; - bool state = patch::Get(addr,false); + bool state = patch::Get(addr, false); if (CheckboxWithHint(label, &state, hint) && addr != NULL) { @@ -312,7 +312,7 @@ bool Ui::CheckboxAddressVarEx(const char* label, bool val, int addr, int enabled return rtn; } -bool Ui::CheckboxBitFlag(const char* label,uint flag, const char* hint) +bool Ui::CheckboxBitFlag(const char* label, uint flag, const char* hint) { bool rtn = false; bool state = (flag == 1) ? true : false; @@ -325,16 +325,16 @@ bool Ui::CheckboxBitFlag(const char* label,uint flag, const char* hint) return rtn; } -void Ui::DrawJSON(CJson& json, std::vector& combo_items, std::string& selected_item, ImGuiTextFilter& filter , std::function func_left_click, std::function func_right_click) +void Ui::DrawJSON(CJson& json, std::vector& combo_items, std::string& selected_item, ImGuiTextFilter& filter, std::function func_left_click, std::function func_right_click) { - ImGui::PushItemWidth(ImGui::GetContentRegionAvailWidth()/2 - 5); + ImGui::PushItemWidth(ImGui::GetContentRegionAvailWidth() / 2 - 5); ListBoxStr("##Categories", combo_items, selected_item); ImGui::SameLine(); filter.Draw("##Filter"); if (strlen(filter.InputBuf) == 0) { - ImDrawList *drawlist = ImGui::GetWindowDrawList(); + ImDrawList* drawlist = ImGui::GetWindowDrawList(); ImVec2 min = ImGui::GetItemRectMin(); min.x += ImGui::GetStyle().FramePadding.x; @@ -342,7 +342,7 @@ void Ui::DrawJSON(CJson& json, std::vector& combo_items, std::strin drawlist->AddText(min, ImGui::GetColorU32(ImGuiCol_TextDisabled), "Search"); } - + ImGui::PopItemWidth(); ImGui::Spacing(); @@ -358,7 +358,7 @@ void Ui::DrawJSON(CJson& json, std::vector& combo_items, std::strin { for (auto _data : root.value().items()) { - + std::string name = _data.key(); if (filter.PassFilter(name.c_str())) { @@ -368,7 +368,7 @@ void Ui::DrawJSON(CJson& json, std::vector& combo_items, std::strin std::string data_key = _data.key(); std::string data_val = _data.value(); - func_left_click(root_key,data_key,data_val); + func_left_click(root_key, data_key, data_val); } if (ImGui::IsItemClicked(1) && func_right_click != nullptr) @@ -390,7 +390,7 @@ void Ui::DrawJSON(CJson& json, std::vector& combo_items, std::strin ImGui::Text(json_popup.key.c_str()); ImGui::Separator(); if (ImGui::MenuItem("Remove")) - json_popup.function(json_popup.root_key,json_popup.key,json_popup.value); + json_popup.function(json_popup.root_key, json_popup.key, json_popup.value); if (ImGui::MenuItem("Close")) @@ -403,7 +403,7 @@ void Ui::DrawJSON(CJson& json, std::vector& combo_items, std::strin } -void Ui::EditStat(const char *label, const int stat_id, const int min, const int def, const int max) +void Ui::EditStat(const char* label, const int stat_id, const int min, const int def, const int max) { if (ImGui::CollapsingHeader(label)) { @@ -448,7 +448,7 @@ void Ui::FilterWithHint(const char* label, ImGuiTextFilter& filter, const char* if (strlen(filter.InputBuf) == 0) { - ImDrawList *drawlist = ImGui::GetWindowDrawList(); + ImDrawList* drawlist = ImGui::GetWindowDrawList(); ImVec2 min = ImGui::GetItemRectMin(); min.x += ImGui::GetStyle().FramePadding.x; @@ -459,8 +459,8 @@ void Ui::FilterWithHint(const char* label, ImGuiTextFilter& filter, const char* } // clean up the code someday -void Ui::DrawImages(std::vector> &img_vec, ImVec2 image_size, - std::vector& category_vec,std::string& selected_item, ImGuiTextFilter& filter, +void Ui::DrawImages(std::vector>& img_vec, ImVec2 image_size, + std::vector& category_vec, std::string& selected_item, ImGuiTextFilter& filter, std::function on_left_click, std::function on_right_click, std::function get_name_func, std::function verify_func) { @@ -468,9 +468,9 @@ void Ui::DrawImages(std::vector> &img_vec, ImV // scale image size image_size.x *= screen::GetScreenWidth() / 1366.0f; image_size.y *= screen::GetScreenHeight() / 768.0f; - + int images_in_row = static_cast(ImGui::GetWindowContentRegionWidth() / image_size.x); - image_size.x = ImGui::GetWindowContentRegionWidth() / images_in_row - int(ImGuiStyleVar_ItemSpacing)*0.65f; + image_size.x = ImGui::GetWindowContentRegionWidth() / images_in_row - int(ImGuiStyleVar_ItemSpacing) * 0.65f; int images_count = 1; @@ -508,7 +508,7 @@ void Ui::DrawImages(std::vector> &img_vec, ImV if (ImGui::IsItemHovered()) { - ImDrawList *drawlist = ImGui::GetWindowDrawList(); + ImDrawList* drawlist = ImGui::GetWindowDrawList(); ImVec2 btn_min = ImGui::GetItemRectMin(); ImVec2 btn_max = ImGui::GetItemRectMax(); @@ -525,7 +525,7 @@ void Ui::DrawImages(std::vector> &img_vec, ImV { std::string buff = ""; - std::stringstream ss(model_name); + std::stringstream ss(model_name); short count = 1; while (ss >> buff) @@ -535,7 +535,7 @@ void Ui::DrawImages(std::vector> &img_vec, ImV drawlist->AddText(ImVec2(btn_min.x + offsetX, btn_min.y + 10 * count), ImGui::GetColorU32(ImGuiCol_Text), buff.c_str()); ++count; } - + } } @@ -565,9 +565,9 @@ void Ui::DrawImages(std::vector> &img_vec, ImV ImGui::EndChild(); } -void Ui::RadioButtonAddress(const char* label, std::vector &named_mem) +void Ui::RadioButtonAddress(const char* label, std::vector& named_mem) { - size_t btn_in_column = named_mem.size() / 2 -1; + size_t btn_in_column = named_mem.size() / 2 - 1; ImGui::Text(label); ImGui::Columns(2, 0, false); @@ -580,7 +580,7 @@ void Ui::RadioButtonAddress(const char* label, std::vector &named_m state = false; } - if (ImGui::RadioButton((std::string("None##") + label).c_str(), state)) + if (ImGui::RadioButton((std::string("None##") + label).c_str(), state)) { for (size_t i = 0; i < named_mem.size(); i++) patch::Set(named_mem[i].addr, false); @@ -604,7 +604,7 @@ void Ui::RadioButtonAddress(const char* label, std::vector &named_m ImGui::Columns(1); } -void Ui::RadioButtonAddressEx(const char* label, int addr, std::vector &named_val) +void Ui::RadioButtonAddressEx(const char* label, int addr, std::vector& named_val) { size_t btn_in_column = named_val.size() / 2; @@ -625,7 +625,7 @@ void Ui::RadioButtonAddressEx(const char* label, int addr, std::vector &named_mem) +void Ui::EditRadioButtonAddress(const char* label, std::vector& named_mem) { if (ImGui::CollapsingHeader(label)) { @@ -635,11 +635,11 @@ void Ui::EditRadioButtonAddress(const char* label, std::vector &nam } } -void Ui::EditRadioButtonAddressEx(const char* label, int addr, std::vector &named_val) +void Ui::EditRadioButtonAddressEx(const char* label, int addr, std::vector& named_val) { if (ImGui::CollapsingHeader(label)) { - RadioButtonAddressEx(label,addr,named_val); + RadioButtonAddressEx(label, addr, named_val); ImGui::Spacing(); ImGui::Separator(); } @@ -647,13 +647,13 @@ void Ui::EditRadioButtonAddressEx(const char* label, int addr, std::vector(base_addr, false); cur_color[1] = patch::Get(base_addr + 1, false); cur_color[2] = patch::Get(base_addr + 2, false); - cur_color[3] = patch::Get(base_addr + 3,false); + cur_color[3] = patch::Get(base_addr + 3, false); // 0-255 -> 0-1 cur_color[0] /= 255; @@ -670,9 +670,9 @@ void Ui::ColorPickerAddress(const char* label, int base_addr, ImVec4&& default_c cur_color[3] *= 255; patch::Set(base_addr, cur_color[0], false); - patch::Set(base_addr+1, cur_color[1], false); - patch::Set(base_addr+2, cur_color[2], false); - patch::Set(base_addr+3, cur_color[3], false); + patch::Set(base_addr + 1, cur_color[1], false); + patch::Set(base_addr + 2, cur_color[2], false); + patch::Set(base_addr + 3, cur_color[3], false); } ImGui::Spacing(); @@ -689,9 +689,9 @@ void Ui::ColorPickerAddress(const char* label, int base_addr, ImVec4&& default_c } } -void Ui::EditBits(const char *label, const int address, const std::vector& names) +void Ui::EditBits(const char* label, const int address, const std::vector& names) { - int *mem_val = (int*)address; + int* mem_val = (int*)address; if (ImGui::CollapsingHeader(label)) { @@ -715,12 +715,12 @@ void Ui::EditBits(const char *label, const int address, const std::vector(address, false)*mul; - + float val = patch::Get(address, false) * mul; + int items = 3; if (min == def) @@ -735,7 +735,7 @@ void Ui::EditFloat(const char *label, const int address, const float min, const ImGui::NextColumn(); ImGui::Text(("Def: " + std::to_string(def)).c_str()); } - + ImGui::NextColumn(); ImGui::Text(("Max: " + std::to_string(max)).c_str()); ImGui::Columns(1); @@ -746,15 +746,15 @@ void Ui::EditFloat(const char *label, const int address, const float min, const if (ImGui::InputFloat(("##" + std::string(label)).c_str(), &val)) patch::SetFloat(address, val / mul, false); - + ImGui::SameLine(0.0, 4.0); - if (ImGui::Button("-",ImVec2(size, size)) && val > min) + if (ImGui::Button("-", ImVec2(size, size)) && val > min) { val -= 1; patch::SetFloat(address, val / mul, false); } ImGui::SameLine(0.0, 4.0); - if (ImGui::Button("+",ImVec2(size, size)) && val < max) + if (ImGui::Button("+", ImVec2(size, size)) && val < max) { val += 1; patch::SetFloat(address, val / mul, false); @@ -766,20 +766,20 @@ void Ui::EditFloat(const char *label, const int address, const float min, const ImGui::Spacing(); if (ImGui::Button(("Minimum##" + std::string(label)).c_str(), Ui::GetSize(items))) - patch::Set(address, min/mul, false); + patch::Set(address, min / mul, false); if (items == 3) { ImGui::SameLine(); if (ImGui::Button(("Default##" + std::string(label)).c_str(), Ui::GetSize(items))) - patch::Set(address, def/mul, false); + patch::Set(address, def / mul, false); } ImGui::SameLine(); if (ImGui::Button(("Maximum##" + std::string(label)).c_str(), Ui::GetSize(items))) - patch::Set(address, max/mul, false); + patch::Set(address, max / mul, false); ImGui::Spacing(); ImGui::Separator(); @@ -814,18 +814,18 @@ bool Ui::HotKey(const char* label, HotKeyData& key_data) } } } - + std::string text; if (key_data.key1 != VK_NONE) - text = key_names[key_data.key1-1]; + text = key_names[key_data.key1 - 1]; else text = "None"; if (key_data.key1 != key_data.key2) - text += (" + " + key_names[key_data.key2-1]); - + text += (" + " + key_names[key_data.key2 - 1]); + if (ImGui::Button((text + std::string("##") + std::string(label)).c_str(), ImVec2(ImGui::GetWindowContentRegionWidth() / 3.5, ImGui::GetFrameHeight()))) if (!active) current_hotkey = label; @@ -845,16 +845,16 @@ bool Ui::HotKey(const char* label, HotKeyData& key_data) } else current_hotkey = ""; - + state = true; } - + ImGui::SameLine(); ImGui::Text(label); if (active) ImGui::PopStyleColor(2); - + return state; } @@ -878,7 +878,7 @@ std::string Ui::GetHotKeyNameString(HotKeyData& hotkey) std::string text; if (hotkey.key1 != VK_NONE) - text = key_names[hotkey.key1-1]; + text = key_names[hotkey.key1 - 1]; else text = "None"; @@ -888,7 +888,7 @@ std::string Ui::GetHotKeyNameString(HotKeyData& hotkey) return text; } -bool Ui::ColorButton(int color_id, std::vector &color, ImVec2 size) +bool Ui::ColorButton(int color_id, std::vector& color, ImVec2 size) { bool rtn = false; std::string label = "Color " + std::to_string(color_id); @@ -898,7 +898,7 @@ bool Ui::ColorButton(int color_id, std::vector &color, ImVec2 size) if (ImGui::IsItemHovered()) { - ImDrawList *drawlist = ImGui::GetWindowDrawList(); + ImDrawList* drawlist = ImGui::GetWindowDrawList(); drawlist->AddRectFilled(ImGui::GetItemRectMin(), ImGui::GetItemRectMax(), ImGui::GetColorU32(ImGuiCol_ModalWindowDimBg)); } diff --git a/src/Ui.h b/src/Ui.h index e8c3314..343e9c2 100644 --- a/src/Ui.h +++ b/src/Ui.h @@ -31,7 +31,7 @@ public: std::string value; }; static void CenterdText(const std::string& text); - static bool ColorButton(int color_id, std::vector &color, ImVec2 size); + static bool ColorButton(int color_id, std::vector& color, ImVec2 size); static bool CheckboxAddress(const char* label, const int addr = NULL, const char* hint = nullptr); static bool CheckboxAddressEx(const char* label, const int addr = NULL, int enabled_val = 1, int disabled_val = 0, const char* hint = nullptr); static bool CheckboxAddressVar(const char* label, bool val, int addr, const char* hint = nullptr); @@ -42,20 +42,20 @@ public: static void DrawJSON(CJson& json, std::vector& combo_items, std::string& selected_item, ImGuiTextFilter& filter, std::function func_left_click, std::function func_right_click); - static void DrawImages(std::vector> &img_vec, ImVec2 image_size, + static void DrawImages(std::vector>& img_vec, ImVec2 image_size, std::vector& category_vec, std::string& selected_item, ImGuiTextFilter& filter, std::function on_left_click, std::function on_right_click, std::function get_name_func, std::function verify_func = nullptr); template - static void EditAddress(const char *label,const int address, const int min = 0, const int def = 0, const int max = 100); - static void EditBits(const char *label, const int address, const std::vector& names); - static void EditFloat(const char *label, const int address, const float min, const float def, const float max, const float mul = 1); + static void EditAddress(const char* label, const int address, const int min = 0, const int def = 0, const int max = 100); + static void EditBits(const char* label, const int address, const std::vector& names); + static void EditFloat(const char* label, const int address, const float min, const float def, const float max, const float mul = 1); template - static void EditReference(const char *label,T &address, const int min = 0, const int def = 0, const int max = 100); - static void EditRadioButtonAddress(const char* label, std::vector &named_mem); - static void EditRadioButtonAddressEx(const char* label, int addr, std::vector &named_val); - static void EditStat(const char *label, const int stat_id, const int min = 0, const int def = 0, const int max = 1000); + static void EditReference(const char* label, T& address, const int min = 0, const int def = 0, const int max = 100); + static void EditRadioButtonAddress(const char* label, std::vector& named_mem); + static void EditRadioButtonAddressEx(const char* label, int addr, std::vector& named_val); + static void EditStat(const char* label, const int stat_id, const int min = 0, const int def = 0, const int max = 1000); static void FilterWithHint(const char* label, ImGuiTextFilter& filter, const char* hint); @@ -68,15 +68,15 @@ public: static bool ListBox(const char* label, std::vector& all_items, int& selected); static bool ListBoxStr(const char* label, std::vector& all_items, std::string& selected); - static void RadioButtonAddress(const char* label, std::vector &named_mem); - static void RadioButtonAddressEx(const char* label, int addr, std::vector &named_val); + static void RadioButtonAddress(const char* label, std::vector& named_mem); + static void RadioButtonAddressEx(const char* label, int addr, std::vector& named_val); static void ColorPickerAddress(const char* label, int base_addr, ImVec4&& default_color); static void ShowTooltip(const char* text); }; template -void Ui::EditAddress(const char *label, const int address, const int min, const int def, const int max) +void Ui::EditAddress(const char* label, const int address, const int min, const int def, const int max) { if (ImGui::CollapsingHeader(label)) { @@ -87,15 +87,15 @@ void Ui::EditAddress(const char *label, const int address, const int min, const if (min == def) items = 2; - ImGui::Columns(items,0,false); + ImGui::Columns(items, 0, false); ImGui::Text(("Min: " + std::to_string(min)).c_str()); - + if (items == 3) { ImGui::NextColumn(); ImGui::Text(("Def: " + std::to_string(def)).c_str()); } - + ImGui::NextColumn(); ImGui::Text(("Max: " + std::to_string(max)).c_str()); ImGui::Columns(1); @@ -109,7 +109,7 @@ void Ui::EditAddress(const char *label, const int address, const int min, const if (val < min) val = min; - + if (val > max) val = max; @@ -135,7 +135,7 @@ void Ui::EditAddress(const char *label, const int address, const int min, const } template -void Ui::EditReference(const char *label,T &address, const int min, const int def, const int max) +void Ui::EditReference(const char* label, T& address, const int min, const int def, const int max) { if (ImGui::CollapsingHeader(label)) { diff --git a/src/Util.cpp b/src/Util.cpp index db7074e..96789c1 100644 --- a/src/Util.cpp +++ b/src/Util.cpp @@ -23,10 +23,10 @@ void Util::ClearCharTasksVehCheck(CPed* ped) } } -void Util::LoadTexturesInDirRecursive(const char *path, const char *file_ext,std::vector& category_vec, std::vector> &store_vec) +void Util::LoadTexturesInDirRecursive(const char* path, const char* file_ext, std::vector& category_vec, std::vector>& store_vec) { std::string folder = ""; - for (auto &p : fs::recursive_directory_iterator(path)) + for (auto& p : fs::recursive_directory_iterator(path)) { if (p.path().extension() == file_ext) { @@ -41,7 +41,6 @@ void Util::LoadTexturesInDirRecursive(const char *path, const char *file_ext,std hr = S_OK; } - if (hr == S_OK) { store_vec.back().get()->file_name = p.path().stem().string(); @@ -49,7 +48,7 @@ void Util::LoadTexturesInDirRecursive(const char *path, const char *file_ext,std } else { - flog << "Couldn't load image " << p.path().stem().string() << std::endl; + flog << "WARN: Failed to load " << p.path().stem().string() << std::endl; store_vec.pop_back(); } } @@ -83,7 +82,7 @@ bool Util::LoadTextureFromFileDx11(const char* filename, ID3D11ShaderResourceVie desc.BindFlags = D3D11_BIND_SHADER_RESOURCE; desc.CPUAccessFlags = 0; - ID3D11Texture2D *pTexture = NULL; + ID3D11Texture2D* pTexture = NULL; D3D11_SUBRESOURCE_DATA subResource; subResource.pSysMem = image_data; subResource.SysMemPitch = desc.Width * 4; @@ -111,7 +110,7 @@ bool Util::IsOnMission() return FindPlayerPed()->CanPlayerStartMission() && !*(patch::Get(0x5D5380, false) + CTheScripts::OnAMissionFlag); } -std::string Util::GetLocationName(CVector *pos) +std::string Util::GetLocationName(CVector* pos) { int hplayer = CPools::GetPedRef(FindPlayerPed()); int interior = 0; @@ -123,18 +122,18 @@ std::string Util::GetLocationName(CVector *pos) switch (city) { - case 0: - town = "CS"; - break; - case 1: - town = "LS"; - break; - case 2: - town = "SF"; - break; - case 3: - town = "LV"; - break; + case 0: + town = "CS"; + break; + case 1: + town = "LS"; + break; + case 2: + town = "SF"; + break; + case 3: + town = "LV"; + break; } if (interior == 0) @@ -151,9 +150,9 @@ int Util::GetLargestGangInZone() for (int i = 0; i != 10; ++i) { CVector pos = FindPlayerPed()->GetPosition(); - CZone *zone = new CZone(); - - CZoneExtraInfo *zone_info = CTheZones::GetZoneInfo(&pos, &zone); + CZone* zone = new CZone(); + + CZoneExtraInfo* zone_info = CTheZones::GetZoneInfo(&pos, &zone); int density = zone_info->m_nGangDensity[i]; if (density > max_density) @@ -171,11 +170,11 @@ int Util::GetLargestGangInZone() // https://github.com/cleolibrary/CLEO4/blob/916d400f4a731ba1dd0ff16e52bdb056f42b7038/source/CCustomOpcodeSystem.cpp#L1671 CVehicle* Util::GetClosestVehicle() { - CPlayerPed *player = FindPlayerPed(); - CPedIntelligence *pedintel; + CPlayerPed* player = FindPlayerPed(); + CPedIntelligence* pedintel; if (player && (pedintel = player->m_pIntelligence)) { - CVehicle *veh = nullptr; + CVehicle* veh = nullptr; for (int i = 0; i < 16; i++) { veh = (CVehicle*)pedintel->m_vehicleScanner.m_apEntities[i]; @@ -191,11 +190,11 @@ CVehicle* Util::GetClosestVehicle() CPed* Util::GetClosestPed() { - CPlayerPed *player = FindPlayerPed(); - CPedIntelligence * pedintel; + CPlayerPed* player = FindPlayerPed(); + CPedIntelligence* pedintel; if (player && (pedintel = player->m_pIntelligence)) { - CPed *ped = nullptr; + CPed* ped = nullptr; for (int i = 0; i < 16; i++) { @@ -210,9 +209,9 @@ CPed* Util::GetClosestPed() return nullptr; } -void Util::RainbowValues(int &r, int&g, int &b, float speed) +void Util::RainbowValues(int& r, int& g, int& b, float speed) { - int timer = CTimer::m_snTimeInMilliseconds/150; + int timer = CTimer::m_snTimeInMilliseconds / 150; r = sin(timer * speed) * 127 + 128; g = sin(timer * speed + 2) * 127 + 128; b = sin(timer * speed + 4) * 127 + 128; diff --git a/src/Util.h b/src/Util.h index 76219d3..ace8d36 100644 --- a/src/Util.h +++ b/src/Util.h @@ -14,31 +14,6 @@ public: static bool IsOnMission(); static std::string GetLocationName(CVector *pos); static void RainbowValues(int &r, int&g, int &b, float speed); - - // This below source is taken from MoonAdditions https://github.com/THE-FYP/MoonAdditions - // MIT License - - // Copyright (c) 2012 DK22Pac - // Copyright (c) 2017 FYP - - // Permission is hereby granted, free of charge, to any person obtaining a copy - // of this software and associated documentation files (the "Software"), to deal - // in the Software without restriction, including without limitation the rights - // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - // copies of the Software, and to permit persons to whom the Software is - // furnished to do so, subject to the following conditions: - - // The above copyright notice and this permission notice shall be included in all - // copies or substantial portions of the Software. - - // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - // SOFTWARE. - static RwTexture* LoadTextureFromPngFile(fs::path path); static void UnloadTexture(RwTexture* texture9); }; diff --git a/src/VKeys.h b/src/VKeys.h index 33ced8f..128319c 100644 --- a/src/VKeys.h +++ b/src/VKeys.h @@ -206,5 +206,5 @@ static std::string key_names[] "LCtrl", "RCtrl", "LMenu", - "RMenu" + "RMenu" }; \ No newline at end of file diff --git a/src/Vehicle.cpp b/src/Vehicle.cpp index 17fd2ac..ba5557a 100644 --- a/src/Vehicle.cpp +++ b/src/Vehicle.cpp @@ -42,6 +42,7 @@ ImGuiTextFilter Vehicle::tune::filter = ""; std::vector Vehicle::tune::search_categories; std::vector> Vehicle::tune::image_vec; std::string Vehicle::tune::selected_item = "All"; +bool Vehicle::images_loaded = false; float Vehicle::neon::color_picker[3]{ 0,0,0 }; bool Vehicle::neon::rainbow = false; @@ -57,7 +58,7 @@ static std::vector(handling_flag_names) = // 32 flags "1G_BOOST","2G_BOOST","NPC_ANTI_ROLL","NPC_NEUTRAL_HANDL","NO_HANDBRAKE","STEER_REARWHEELS","HB_REARWHEEL_STEER","ALT_STEER_OPT", "WHEEL_F_NARROW2","WHEEL_F_NARROW","WHEEL_F_WIDE","WHEEL_F_WIDE2","WHEEL_R_NARROW2","WHEEL_R_NARROW","WHEEL_R_WIDE","WHEEL_R_WIDE2", "HYDRAULIC_GEOM","HYDRAULIC_INST","HYDRAULIC_NONE","NOS_INST","OFFROAD_ABILITY","OFFROAD_ABILITY2","HALOGEN_LIGHTS","PROC_REARWHEEL_1ST", - "USE_MAXSP_LIMIT","LOW_RIDER","STREET_RACER","SWINGING_CHASSIS","Unused 1","Unused 2","Unused 3","Unused 4" + "USE_MAXSP_LIMIT","LOW_RIDER","STREET_RACER","SWINGING_CHASSIS","Unused 1","Unused 2","Unused 3","Unused 4" }; static std::vector(model_flag_names) = // 32 flags @@ -70,27 +71,28 @@ static std::vector(model_flag_names) = // 32 flags Vehicle::Vehicle() { - Events::initGameEvent += [] - { - Util::LoadTexturesInDirRecursive(PLUGIN_PATH((char*)"CheatMenu\\vehicles\\images\\"), ".jpg", spawner::search_categories, spawner::image_vec); - Util::LoadTexturesInDirRecursive(PLUGIN_PATH((char*)"CheatMenu\\vehicles\\components\\"), ".jpg", tune::search_categories, tune::image_vec); - Util::LoadTexturesInDirRecursive(PLUGIN_PATH((char*)"CheatMenu\\vehicles\\paintjobs\\"), ".png", texture9::search_categories, texture9::image_vec); - - ParseVehiclesIDE(); - ParseCarcolsDAT(); - }; + ParseVehiclesIDE(); + ParseCarcolsDAT(); Events::processScriptsEvent += [this] { - uint timer = CTimer::m_snTimeInMilliseconds; + if (!images_loaded) + { + Util::LoadTexturesInDirRecursive(PLUGIN_PATH((char*)"CheatMenu\\vehicles\\images\\"), ".jpg", spawner::search_categories, spawner::image_vec); + Util::LoadTexturesInDirRecursive(PLUGIN_PATH((char*)"CheatMenu\\vehicles\\components\\"), ".jpg", tune::search_categories, tune::image_vec); + Util::LoadTexturesInDirRecursive(PLUGIN_PATH((char*)"CheatMenu\\vehicles\\paintjobs\\"), ".png", texture9::search_categories, texture9::image_vec); - CPlayerPed *player = FindPlayerPed(); - CVehicle *veh = player->m_pVehicle; + images_loaded = true; + } + + uint timer = CTimer::m_snTimeInMilliseconds; + CPlayerPed* player = FindPlayerPed(); + CVehicle* veh = player->m_pVehicle; if (player && veh) { int hveh = CPools::GetVehicleRef(veh); - + if (Ui::HotKeyPressed(Menu::hotkeys::flip_veh)) { float roll; @@ -104,7 +106,7 @@ Vehicle::Vehicle() { player->m_pVehicle->Fix(); player->m_pVehicle->m_fHealth = 1000.0f; - CHud::SetHelpMessage("Vehicle fixed",false,false,false); + CHud::SetHelpMessage("Vehicle fixed", false, false, false); } if (Ui::HotKeyPressed(Menu::hotkeys::veh_engine)) @@ -112,9 +114,9 @@ Vehicle::Vehicle() bool state = !veh->m_nVehicleFlags.bEngineBroken || veh->m_nVehicleFlags.bEngineOn; if (state) - CHud::SetHelpMessage("Vehicle engine off",false,false,false); + CHud::SetHelpMessage("Vehicle engine off", false, false, false); else - CHud::SetHelpMessage("Vehicle engine on",false,false,false); + CHud::SetHelpMessage("Vehicle engine on", false, false, false); veh->m_nVehicleFlags.bEngineBroken = state; veh->m_nVehicleFlags.bEngineOn = !state; @@ -125,7 +127,7 @@ Vehicle::Vehicle() if (Ui::HotKeyPressed(Menu::hotkeys::veh_instant_stop)) Command(hveh, 0); - + if (veh_nodmg) { veh->m_nPhysicalFlags.bBulletProof = true; @@ -133,10 +135,10 @@ Vehicle::Vehicle() veh->m_nPhysicalFlags.bFireProof = true; veh->m_nPhysicalFlags.bCollisionProof = true; veh->m_nPhysicalFlags.bMeeleProof = true; - veh->m_nVehicleFlags.bCanBeDamaged = true; + veh->m_nVehicleFlags.bCanBeDamaged = true; } - player->m_nPedFlags.CantBeKnockedOffBike = dont_fall_bike ? 1 : 2; + player->m_nPedFlags.CantBeKnockedOffBike = dont_fall_bike ? 1 : 2; Command(hveh, veh_heavy); Command(hveh, veh_watertight); @@ -179,34 +181,34 @@ Vehicle::Vehicle() // Traffic neons if (neon::traffic && timer - neon::traffic_timer > 1000) { - for (CVehicle *veh : CPools::ms_pVehiclePool) + for (CVehicle* veh : CPools::ms_pVehiclePool) { int chance = 0; if (veh->m_nVehicleClass == CLASS_NORMAL) // Normal - chance = Random(1,20); + chance = Random(1, 20); if (veh->m_nVehicleClass == CLASS_RICHFAMILY) // Rich family - chance = Random(1,4); + chance = Random(1, 4); if (veh->m_nVehicleClass == CLASS_EXECUTIVE) // Executive - chance = Random(1,3); + chance = Random(1, 3); if (chance == 1 && !IsNeonInstalled(veh) && veh->m_pDriver != player) - InstallNeon(veh, Random(0,255), Random(0,255), Random(0,255)); + InstallNeon(veh, Random(0, 255), Random(0, 255), Random(0, 255)); } neon::traffic_timer = timer; } - + if (bike_fly && veh && veh->IsDriver(player)) { if (veh->m_nVehicleSubClass == VEHICLE_BIKE || veh->m_nVehicleSubClass == VEHICLE_BMX) { - if (sqrt( veh->m_vecMoveSpeed.x * veh->m_vecMoveSpeed.x - + veh->m_vecMoveSpeed.y * veh->m_vecMoveSpeed.y - + veh->m_vecMoveSpeed.z * veh->m_vecMoveSpeed.z - ) > 0.0 - && CTimer::ms_fTimeStep > 0.0) + if (sqrt(veh->m_vecMoveSpeed.x * veh->m_vecMoveSpeed.x + + veh->m_vecMoveSpeed.y * veh->m_vecMoveSpeed.y + + veh->m_vecMoveSpeed.z * veh->m_vecMoveSpeed.z + ) > 0.0 + && CTimer::ms_fTimeStep > 0.0) { veh->FlyingControl(3, -9999.9902f, -9999.9902f, -9999.9902f, -9999.9902f); } @@ -218,11 +220,11 @@ Vehicle::Vehicle() void Vehicle::AddComponent(const std::string& component, const bool display_message) { try { - CPlayerPed *player = FindPlayerPed(); + CPlayerPed* player = FindPlayerPed(); int icomp = std::stoi(component); int hveh = CPools::GetVehicleRef(player->m_pVehicle); - CStreaming::RequestModel(icomp,eStreamingFlags::PRIORITY_REQUEST); + CStreaming::RequestModel(icomp, eStreamingFlags::PRIORITY_REQUEST); CStreaming::LoadAllRequestedModels(true); player->m_pVehicle->AddVehicleUpgrade(icomp); CStreaming::SetModelIsDeletable(icomp); @@ -240,7 +242,7 @@ void Vehicle::AddComponent(const std::string& component, const bool display_mess void Vehicle::RemoveComponent(const std::string& component, const bool display_message) { try { - CPlayerPed *player = FindPlayerPed(); + CPlayerPed* player = FindPlayerPed(); int icomp = std::stoi(component); int hveh = CPools::GetVehicleRef(player->m_pVehicle); @@ -267,23 +269,23 @@ int Vehicle::GetRandomTrainIdForModel(int model) switch (model) { - case 449: - _start = 0; - _end = 1; - break; - case 537: - _start = 2; - _end = 7; - break; - case 538: - _start = 8; - _end = 10; - break; - default: - CHud::SetHelpMessage("Invalid train model", false, false, false); - return -1; + case 449: + _start = 0; + _end = 1; + break; + case 537: + _start = 2; + _end = 7; + break; + case 538: + _start = 8; + _end = 10; + break; + default: + CHud::SetHelpMessage("Invalid train model", false, false, false); + return -1; } - int id = Random(_start,_end); + int id = Random(_start, _end); return train_ids[id]; } @@ -311,7 +313,7 @@ void Vehicle::ParseVehiclesIDE() getline(ss, temp, ','); int model = std::stoi(temp); - + // modelname, txd, type, handlingId getline(ss, temp, ','); getline(ss, temp, ','); @@ -406,11 +408,11 @@ void Vehicle::ParseCarcolsDAT() getline(ss, temp, ','); std::string name = temp; - while (getline(ss, temp, ',')) + while (getline(ss, temp, ',')) { try { - std::for_each(name.begin(), name.end(), [](char & c) { + std::for_each(name.begin(), name.end(), [](char& c) { c = ::toupper(c); }); @@ -431,16 +433,16 @@ void Vehicle::ParseCarcolsDAT() else flog << "Vehicle.ide file not found"; } -void Vehicle::SpawnVehicle(std::string &smodel) +void Vehicle::SpawnVehicle(std::string& smodel) { - CPlayerPed *player = FindPlayerPed(); + CPlayerPed* player = FindPlayerPed(); int hplayer = CPools::GetPedRef(player); int imodel = std::stoi(smodel); - CVehicle *veh = nullptr; + CVehicle* veh = nullptr; int interior = player->m_nAreaCode; - + if (Command(imodel)) { CVector pos = player->GetPosition(); @@ -450,7 +452,7 @@ void Vehicle::SpawnVehicle(std::string &smodel) { int hveh = 0; Command(hplayer, &hveh); - CVehicle *pveh = CPools::GetVehicle(hveh); + CVehicle* pveh = CPools::GetVehicle(hveh); pos = pveh->GetPosition(); Command(hveh, &speed); @@ -466,10 +468,10 @@ void Vehicle::SpawnVehicle(std::string &smodel) if (interior == 0) if (spawner::spawn_in_air && (CModelInfo::IsHeliModel(imodel) || CModelInfo::IsPlaneModel(imodel))) pos.z = 400; - else - pos.z -= 5; + else + pos.z -= 5; + - if (CModelInfo::IsTrainModel(imodel)) { int train_id = GetRandomTrainIdForModel(imodel); @@ -489,11 +491,11 @@ void Vehicle::SpawnVehicle(std::string &smodel) CStreaming::LoadAllRequestedModels(false); - CTrain *train = nullptr; - CTrain *carraige = nullptr; - int track = Random(0,1); - int node = CTrain::FindClosestTrackNode(pos,&track); - CTrain::CreateMissionTrain(pos,(Random(0,1)) == 1 ? true : false,train_id,&train,&carraige,node,track,false); + CTrain* train = nullptr; + CTrain* carraige = nullptr; + int track = Random(0, 1); + int node = CTrain::FindClosestTrackNode(pos, &track); + CTrain::CreateMissionTrain(pos, (Random(0, 1)) == 1 ? true : false, train_id, &train, &carraige, node, track, false); veh = (CVehicle*)train; hveh = CPools::GetVehicleRef(veh); @@ -532,12 +534,12 @@ void Vehicle::SpawnVehicle(std::string &smodel) Command(hveh, speed); } else - { + { player->TransformFromObjectSpace(pos, CVector(0, 10, 0)); Command(imodel, pos.x, pos.y, pos.z + 3.0f, &hveh); veh = CPools::GetVehicle(hveh); - veh->SetHeading(player->GetHeading()+55.0f); + veh->SetHeading(player->GetHeading() + 55.0f); } veh->m_nDoorLock = CARLOCK_UNLOCKED; veh->m_nAreaCode = interior; @@ -550,7 +552,7 @@ void Vehicle::SpawnVehicle(std::string &smodel) std::string Vehicle::GetNameFromModel(int model) { - CBaseModelInfo *info = CModelInfo::GetModelInfo(model); + CBaseModelInfo* info = CModelInfo::GetModelInfo(model); return (const char*)info + 0x32; } @@ -558,7 +560,7 @@ std::string Vehicle::GetNameFromModel(int model) int Vehicle::GetModelFromName(const char* name) { int model = 0; - CBaseModelInfo* model_info = CModelInfo::GetModelInfo((char*)name,&model); + CBaseModelInfo* model_info = CModelInfo::GetModelInfo((char*)name, &model); if (model > 0 && model < 1000000 && GetNameFromModel(model) != "") return model; @@ -573,7 +575,7 @@ Vehicle::~Vehicle() void Vehicle::GenerateHandlingDataFile(int phandling) { - FILE *fp = fopen("handling.txt", "w"); + FILE* fp = fopen("handling.txt", "w"); std::string handlingId = vehicle_ide[FindPlayerPed()->m_pVehicle->m_nModelIndex]; float fMass = patch::Get(phandling + 0x4); @@ -604,7 +606,7 @@ void Vehicle::GenerateHandlingDataFile(int phandling) float fCollisionDamageMultiplier = patch::Get(phandling + 0xC8) * 0.338; int nMonetaryValue = patch::Get(phandling + 0xD8); - int MaxVelocity = patch::Get(phandling + 0x84); + int MaxVelocity = patch::Get(phandling + 0x84); MaxVelocity = MaxVelocity * 206 + (MaxVelocity - 0.918668) * 1501; int modelFlags = patch::Get(phandling + 0xCC); @@ -626,10 +628,10 @@ void Vehicle::GenerateHandlingDataFile(int phandling) } -void Vehicle::Main() +void Vehicle::Draw() { ImGui::Spacing(); - static CPlayerPed *player = FindPlayerPed(); + static CPlayerPed* player = FindPlayerPed(); static int hplayer = CPools::GetPedRef(player); if (ImGui::Button("Blow up cars", ImVec2(Ui::GetSize(3)))) @@ -667,9 +669,9 @@ void Vehicle::Main() if (ImGui::BeginTabBar("Vehicle", ImGuiTabBarFlags_NoTooltip + ImGuiTabBarFlags_FittingPolicyScroll)) { - CVehicle *pVeh = player->m_pVehicle; + CVehicle* pVeh = player->m_pVehicle; bool is_driver = pVeh && player->m_pVehicle->IsDriver(player); - + ImGui::Spacing(); if (ImGui::BeginTabItem("Checkboxes")) @@ -699,7 +701,7 @@ void Vehicle::Main() } } Ui::CheckboxAddress("Decreased traffic", 0x96917A); - + ImGui::NextColumn(); Ui::CheckboxWithHint("Don't fall off bike", &dont_fall_bike); @@ -747,7 +749,7 @@ void Vehicle::Main() { pVeh->m_nVehicleFlags.bEngineBroken = !state; pVeh->m_nVehicleFlags.bEngineOn = state; - } + } state = pVeh->m_nPhysicalFlags.bExplosionProof; if (Ui::CheckboxWithHint("Explosion proof", &state, nullptr, veh_nodmg)) pVeh->m_nPhysicalFlags.bExplosionProof = state; @@ -755,7 +757,7 @@ void Vehicle::Main() state = pVeh->m_nPhysicalFlags.bFireProof; if (Ui::CheckboxWithHint("Fire proof", &state, nullptr, veh_nodmg)) pVeh->m_nPhysicalFlags.bFireProof = state; - + ImGui::NextColumn(); state = pVeh->m_nVehicleFlags.bVehicleCanBeTargettedByHS; @@ -787,14 +789,14 @@ void Vehicle::Main() if (Ui::CheckboxWithHint("Petrol tank blow", &state, "Vehicle will blow up if petrol tank is shot")) pVeh->m_nVehicleFlags.bPetrolTankIsWeakPoint = state; - state = pVeh->m_nVehicleFlags.bSirenOrAlarm; + state = pVeh->m_nVehicleFlags.bSirenOrAlarm; if (Ui::CheckboxWithHint("Siren", &state)) pVeh->m_nVehicleFlags.bSirenOrAlarm = state; state = pVeh->m_nVehicleFlags.bTakeLessDamage; if (Ui::CheckboxWithHint("Take less dmg", &state, nullptr)) pVeh->m_nVehicleFlags.bTakeLessDamage = state; - + ImGui::Columns(1); } @@ -808,9 +810,9 @@ void Vehicle::Main() Ui::EditFloat("Density multiplier", 0x8A5B20, 0, 1, 10); if (ImGui::CollapsingHeader("Enter nearest vehicle as")) { - CPlayerPed *player = FindPlayerPed(); + CPlayerPed* player = FindPlayerPed(); int hplayer = CPools::GetPedRef(player); - CVehicle *veh = Util::GetClosestVehicle(); + CVehicle* veh = Util::GetClosestVehicle(); if (veh) { @@ -832,7 +834,7 @@ void Vehicle::Main() { if (i % 2 != 1) ImGui::SameLine(); - + if (ImGui::Button((std::string("Passenger ") + std::to_string(i + 1)).c_str(), ImVec2(Ui::GetSize(2)))) Command(hplayer, veh, i); } @@ -847,12 +849,12 @@ void Vehicle::Main() { ImGui::InputInt("Radius", &veh_remove_radius); ImGui::Spacing(); - if (ImGui::Button("Remove vehicles",Ui::GetSize(1))) + if (ImGui::Button("Remove vehicles", Ui::GetSize(1))) { - CPlayerPed *player = FindPlayerPed(); - for (CVehicle *veh : CPools::ms_pVehiclePool) + CPlayerPed* player = FindPlayerPed(); + for (CVehicle* veh : CPools::ms_pVehiclePool) { - if (DistanceBetweenPoints(veh->GetPosition(),player->GetPosition()) < veh_remove_radius + if (DistanceBetweenPoints(veh->GetPosition(), player->GetPosition()) < veh_remove_radius && player->m_pVehicle != veh) Command(CPools::GetVehicleRef(veh)); } @@ -874,7 +876,7 @@ void Vehicle::Main() if (player && player->m_pVehicle) { - CVehicle *veh = player->m_pVehicle; + CVehicle* veh = player->m_pVehicle; int hveh = CPools::GetVehicleRef(veh); Ui::EditFloat("Dirt level", (int)veh + 0x4B0, 0, 7.5, 15); @@ -899,20 +901,20 @@ void Vehicle::Main() { switch (door_menu_button) { - case 0: - Command(hveh, i); - break; - case 1: - Command(hveh, i); - break; - case 2: - Command(hveh, i); - break; - case 3: - Command(hveh, i); - break; - default: - break; + case 0: + Command(hveh, i); + break; + case 1: + Command(hveh, i); + break; + case 2: + Command(hveh, i); + break; + case 3: + Command(hveh, i); + break; + default: + break; } } } @@ -923,20 +925,20 @@ void Vehicle::Main() { switch (door_menu_button) { - case 0: - Command(hveh, i); - break; - case 1: - Command(hveh, i); - break; - case 2: - Command(hveh, i); - break; - case 3: - Command(hveh, i); - break; - default: - break; + case 0: + Command(hveh, i); + break; + case 1: + Command(hveh, i); + break; + case 2: + Command(hveh, i); + break; + case 3: + Command(hveh, i); + break; + default: + break; } } @@ -978,7 +980,7 @@ void Vehicle::Main() ImGui::NextColumn(); Ui::CheckboxWithHint("Spawn aircraft in air", &spawner::spawn_in_air); ImGui::Columns(1); - + ImGui::Spacing(); ImGui::SetNextItemWidth(ImGui::GetWindowContentRegionWidth() - 2.5); @@ -994,7 +996,7 @@ void Vehicle::Main() } if (player->m_pVehicle && player->m_nPedFlags.bInVehicle) { - CVehicle *veh = FindPlayerPed()->m_pVehicle; + CVehicle* veh = FindPlayerPed()->m_pVehicle; int hveh = CPools::GetVehicleRef(veh); if (ImGui::BeginTabItem("Color")) { @@ -1036,15 +1038,15 @@ void Vehicle::Main() ImVec2 size = Ui::GetSize(); int btns_in_row = ImGui::GetWindowContentRegionWidth() / (size.y * 2); - int btn_size = (ImGui::GetWindowContentRegionWidth() - int(ImGuiStyleVar_ItemSpacing)*(btns_in_row - 0.6*btns_in_row)) / btns_in_row; + int btn_size = (ImGui::GetWindowContentRegionWidth() - int(ImGuiStyleVar_ItemSpacing) * (btns_in_row - 0.6 * btns_in_row)) / btns_in_row; ImGui::BeginChild("Colorss"); if (color::show_all) for (int color_id = 0; color_id < count; ++color_id) { - if (Ui::ColorButton(color_id, carcols_color_values[color_id], ImVec2(btn_size,btn_size))) - *(uint8_replacement *)(int(veh) + 0x433 + color::radio_btn) = color_id; + if (Ui::ColorButton(color_id, carcols_color_values[color_id], ImVec2(btn_size, btn_size))) + *(uint8_replacement*)(int(veh) + 0x433 + color::radio_btn) = color_id; if ((color_id + 1) % btns_in_row != 0) ImGui::SameLine(0.0, 4.0); @@ -1060,13 +1062,13 @@ void Vehicle::Main() for (int color_id : entry.second) { if (Ui::ColorButton(color_id, carcols_color_values[color_id], ImVec2(btn_size, btn_size))) - *(uint8_replacement *)(int(veh) + 0x433 + color::radio_btn) = color_id; + *(uint8_replacement*)(int(veh) + 0x433 + color::radio_btn) = color_id; if (count % btns_in_row != 0) ImGui::SameLine(0.0, 4.0); ++count; } - + break; } } @@ -1086,17 +1088,17 @@ void Vehicle::Main() ImGui::Spacing(); ImGui::Columns(2, NULL, false); - + bool pulsing = IsPulsingEnabled(veh); if (Ui::CheckboxWithHint("Pulsing neons", &pulsing)) - SetPulsing(veh,pulsing); + SetPulsing(veh, pulsing); Ui::CheckboxWithHint("Rainbow neons", &neon::rainbow, "Rainbow effect to neon lights"); ImGui::NextColumn(); Ui::CheckboxWithHint("Traffic neons", &neon::traffic, "Adds neon lights to traffic vehicles.\n\ Only some vehicles will have them."); ImGui::Columns(1); - + ImGui::Spacing(); if (ImGui::ColorEdit3("Color picker", neon::color_picker)) @@ -1108,7 +1110,7 @@ Only some vehicles will have them."); int count = (int)carcols_color_values.size(); ImVec2 size = Ui::GetSize(); int btns_in_row = ImGui::GetWindowContentRegionWidth() / (size.y * 2); - int btn_size = (ImGui::GetWindowContentRegionWidth() - int(ImGuiStyleVar_ItemSpacing)*(btns_in_row - 0.6*btns_in_row)) / btns_in_row; + int btn_size = (ImGui::GetWindowContentRegionWidth() - int(ImGuiStyleVar_ItemSpacing) * (btns_in_row - 0.6 * btns_in_row)) / btns_in_row; ImGui::BeginChild("Neonss"); @@ -1116,8 +1118,8 @@ Only some vehicles will have them."); { if (Ui::ColorButton(color_id, carcols_color_values[color_id], ImVec2(btn_size, btn_size))) { - std::vector &color = carcols_color_values[color_id]; - InstallNeon(veh, color[0]*255, color[1]*255, color[2]*255); + std::vector& color = carcols_color_values[color_id]; + InstallNeon(veh, color[0] * 255, color[1] * 255, color[2] * 255); } if ((color_id + 1) % btns_in_row != 0) @@ -1154,39 +1156,39 @@ Only some vehicles will have them."); if (curpjob > maxpjob) curpjob = -1; if (curpjob < -1) - curpjob = maxpjob-1; + curpjob = maxpjob - 1; Command(hveh, curpjob); } ImGui::Spacing(); } - + ImGui::Spacing(); ImGui::SameLine(); ImGui::Checkbox("Material filter", &color::material_filter); ImGui::Spacing(); Ui::DrawImages(texture9::image_vec, ImVec2(100, 80), texture9::search_categories, texture9::selected_item, texture9::filter, - [](std::string& str) + [](std::string& str) { Paint::SetNodeTexture(FindPlayerPed()->m_pVehicle, Paint::veh_nodes::selected, str, color::material_filter); }, nullptr, - [](std::string& str) {return str; - }); + [](std::string& str) {return str; + }); ImGui::EndTabItem(); } if (ImGui::BeginTabItem("Tune")) { ImGui::Spacing(); - Ui::DrawImages(tune::image_vec, ImVec2(100, 80), tune::search_categories, tune::selected_item, tune::filter, + Ui::DrawImages(tune::image_vec, ImVec2(100, 80), tune::search_categories, tune::selected_item, tune::filter, [](std::string& str) {AddComponent(str);}, [](std::string& str) {RemoveComponent(str); }, - [](std::string& str){return str;}, + [](std::string& str) {return str;}, [](std::string& str) { - return ((bool(*)(int,CVehicle*))0x49B010)(std::stoi(str), player->m_pVehicle); + return ((bool(*)(int, CVehicle*))0x49B010)(std::stoi(str), player->m_pVehicle); } ); @@ -1195,9 +1197,9 @@ Only some vehicles will have them."); if (ImGui::BeginTabItem("Handling")) { ImGui::Spacing(); - - CBaseModelInfo *info = CModelInfo::GetModelInfo(player->m_pVehicle->m_nModelIndex); - int phandling = patch::Get((int)info+0x4A,false); + + CBaseModelInfo* info = CModelInfo::GetModelInfo(player->m_pVehicle->m_nModelIndex); + int phandling = patch::Get((int)info + 0x4A, false); phandling *= 0xE0; phandling += 0xC2B9DC; @@ -1221,32 +1223,32 @@ Only some vehicles will have them."); ShellExecute(NULL, "open", "https://projectcerbera.com/gta/sa/tutorials/handling", NULL, NULL, SW_SHOWNORMAL); ImGui::Spacing(); - + ImGui::BeginChild("HandlingChild"); - static std::vector abs{{ "On", 1 }, { "Off", 0 }}; + static std::vector abs{ { "On", 1 }, { "Off", 0 } }; Ui::EditRadioButtonAddressEx("Abs", phandling + 0x9C, abs); Ui::EditFloat("Anti dive multiplier", phandling + 0xC4, 0.0f, 0.0f, 1.0f); Ui::EditFloat("Brake bias", phandling + 0x98, 0.0f, 0.0f, 1.0f); Ui::EditFloat("Brake deceleration", phandling + 0x94, 0.0f, 0.0f, 20.0f, 2500.0f); - Ui::EditFloat("Centre of mass X", phandling + 0x14,-10.0f,-10.0f, 10.0f); - Ui::EditFloat("Centre of mass Y", phandling + 0x18,-10.0f,-10.0f, 10.0f); - Ui::EditFloat("Centre of mass Z", phandling + 0x1C,-10.0f,-10.0f, 10.0f); + Ui::EditFloat("Centre of mass X", phandling + 0x14, -10.0f, -10.0f, 10.0f); + Ui::EditFloat("Centre of mass Y", phandling + 0x18, -10.0f, -10.0f, 10.0f); + Ui::EditFloat("Centre of mass Z", phandling + 0x1C, -10.0f, -10.0f, 10.0f); Ui::EditFloat("Collision damage multiplier", phandling + 0xC8, 0.0f, 0.0f, 1.0f, 0.3381f); Ui::EditFloat("Damping level", phandling + 0xB0, -10.0f, -10.0f, 10.0f); // test later Ui::EditFloat("Drag mult", phandling + 0x10, 0.0f, 0.0f, 30.0f); - static std::vector drive_type{ { "Front wheel drive", 70 }, { "Rear wheel drive", 82 }, { "Four wheel drive", 52 }}; + static std::vector drive_type{ { "Front wheel drive", 70 }, { "Rear wheel drive", 82 }, { "Four wheel drive", 52 } }; Ui::EditRadioButtonAddressEx("Drive type", phandling + 0x74, drive_type); Ui::EditFloat("Engine acceleration", phandling + 0x7C, 0.0f, 0.0f, 49.0f, 12500.0f); Ui::EditFloat("Engine inertia", phandling + 0x80, 0.0f, 0.0f, 400.0f); - static std::vector engine_type{ { "Petrol", 80 }, { "Diseal", 68 }, { "Electric", 69 }}; + static std::vector engine_type{ { "Petrol", 80 }, { "Diseal", 68 }, { "Electric", 69 } }; Ui::EditRadioButtonAddressEx("Engine type", phandling + 0x75, engine_type); - std::vector front_lights{ { "Long", 0 }, { "Small", 1 }, { "Big", 2 }, { "Tall", 3 }}; + std::vector front_lights{ { "Long", 0 }, { "Small", 1 }, { "Big", 2 }, { "Tall", 3 } }; Ui::EditRadioButtonAddressEx("Front lights", phandling + 0xDC, front_lights); Ui::EditFloat("Force level", phandling + 0xAC, -10.0f, -10.0f, 10.0f); // test later @@ -1265,7 +1267,7 @@ Only some vehicles will have them."); Ui::EditAddress("Number of gears", phandling + 0x76, 1, 1, 10); Ui::EditAddress("Percent submerged", phandling + 0x20, 10, 10, 120); - static std::vector rear_lights{ { "Long", 0 }, { "Small", 1 }, { "Big", 2 }, { "Tall", 3 }}; + static std::vector rear_lights{ { "Long", 0 }, { "Small", 1 }, { "Big", 2 }, { "Tall", 3 } }; Ui::EditRadioButtonAddressEx("Rear lights", phandling + 0xDD, rear_lights); Ui::EditFloat("Seat offset distance", phandling + 0xD4, 0.0f, 0.0f, 1.0f); @@ -1279,7 +1281,7 @@ Only some vehicles will have them."); Ui::EditAddress("Vehicle anim group", phandling + 0xDE, 0, 0, 20); ImGui::EndChild(); - + ImGui::EndTabItem(); } } diff --git a/src/Vehicle.h b/src/Vehicle.h index db13e9c..a115aa6 100644 --- a/src/Vehicle.h +++ b/src/Vehicle.h @@ -38,7 +38,7 @@ private: static uint traffic_timer; }; - struct spawner + struct spawner { static ImGuiTextFilter filter; static std::string selected_item; @@ -56,6 +56,7 @@ private: static std::vector search_categories; static std::vector> image_vec; }; + static bool images_loaded; struct tune { @@ -75,13 +76,13 @@ public: static void RemoveComponent(const std::string& component, const bool display_message = true); static std::string GetNameFromModel(int model); static int GetModelFromName(const char* name); - static void SpawnVehicle(std::string &name); + static void SpawnVehicle(std::string& name); static int GetRandomTrainIdForModel(int model); static void ParseVehiclesIDE(); static void ParseCarcolsDAT(); static void GenerateHandlingDataFile(int phandling); Vehicle(); ~Vehicle(); - static void Main(); + static void Draw(); }; diff --git a/src/Visual.cpp b/src/Visual.cpp index 83d2db8..7f6b55e 100644 --- a/src/Visual.cpp +++ b/src/Visual.cpp @@ -28,15 +28,12 @@ static bool init_patches = false; Visual::Visual() { - Events::initGameEvent += [] - { - if (LoadLibraryW(L"timecycle24.asi")) - timecyc_hour = 24; - }; + if (GetModuleHandle("timecycle24.asi")) + timecyc_hour = 24; Events::processScriptsEvent += [] { - // Improve this later + // TODO: Needs improvement if (lock_weather) { CWeather::OldWeatherType = weather_type_backup; @@ -190,7 +187,7 @@ void Visual::GenerateTimecycFile() } } -void Visual::Main() +void Visual::Draw() { if (ImGui::BeginTabBar("Visual", ImGuiTabBarFlags_NoTooltip + ImGuiTabBarFlags_FittingPolicyScroll)) { @@ -271,7 +268,7 @@ void Visual::Main() Ui::ColorPickerAddress("Armour bar", *(int*)0x5890FC, ImVec4(180,25,29,255)); Ui::ColorPickerAddress("Health bar", *(int*)0x589331, ImVec4(180,25,29,255)); - Ui::ColorPickerAddress("Main menu title border color", 0xBAB240, ImVec4(0,0,0,255)); + Ui::ColorPickerAddress("Draw menu title border color", 0xBAB240, ImVec4(0,0,0,255)); Ui::ColorPickerAddress("Money color", 0xBAB230, ImVec4(54,104,44,255)); static std::vector font_outline{{ "No outline", 0 }, { "Thin outline" ,1 }, { "Default outline" ,2 }}; Ui::EditRadioButtonAddressEx("Money font outline", 0x58F58D, font_outline); diff --git a/src/Visual.h b/src/Visual.h index e7fd7bb..15c8a08 100644 --- a/src/Visual.h +++ b/src/Visual.h @@ -11,21 +11,21 @@ private: static void GenerateTimecycFile(); static int GetCurrentHourTimeId(); - static bool TimeCycColorEdit3(const char* label, uchar *r, uchar *g, uchar *b, ImGuiColorEditFlags flags = 0); - static bool TimeCycColorEdit4(const char* label, uchar *r, uchar *g, uchar *b, uchar *a, ImGuiColorEditFlags flags = 0); + static bool TimeCycColorEdit3(const char* label, uchar* r, uchar* g, uchar* b, ImGuiColorEditFlags flags = 0); + static bool TimeCycColorEdit4(const char* label, uchar* r, uchar* g, uchar* b, uchar* a, ImGuiColorEditFlags flags = 0); template static void TimecycSlider(const char* label, T* data, int min, int max); public: Visual(); ~Visual(); - static void Main(); + static void Draw(); }; template void Visual::TimecycSlider(const char* label, T* ptr, int min, int max) { int val = 23 * GetCurrentHourTimeId() + CWeather::OldWeatherType; - T *arr = (T*)patch::GetPointer(int(ptr)); + T* arr = (T*)patch::GetPointer(int(ptr)); int a = arr[val]; if (ImGui::SliderInt(label, &a, min, max)) diff --git a/src/Weapon.cpp b/src/Weapon.cpp index ac8017d..2f4a985 100644 --- a/src/Weapon.cpp +++ b/src/Weapon.cpp @@ -7,6 +7,7 @@ ImGuiTextFilter Weapon::filter = ""; std::string Weapon::selected_item = "All"; std::vector Weapon::search_categories; std::vector> Weapon::weapon_vec; +bool Weapon::images_loaded = false; CJson Weapon::weapon_json = CJson("weapon"); bool Weapon::auto_aim = false; @@ -40,13 +41,14 @@ int Weapon::gang_weapons[10][3] = Weapon::Weapon() { - Events::initGameEvent += [] - { - Util::LoadTexturesInDirRecursive(PLUGIN_PATH((char*)"CheatMenu\\weapons\\"), ".jpg", Weapon::search_categories, Weapon::weapon_vec); - }; - Events::processScriptsEvent += [] { + if (!images_loaded) + { + Util::LoadTexturesInDirRecursive(PLUGIN_PATH((char*)"CheatMenu\\weapons\\"), ".jpg", Weapon::search_categories, Weapon::weapon_vec); + images_loaded = true; + } + CPlayerPed *player = FindPlayerPed(); if (auto_aim) { @@ -134,7 +136,7 @@ void Weapon::GiveWeaponToPlayer(std::string& weapon_type) } } -void Weapon::Main() +void Weapon::Draw() { CPlayerPed *player = FindPlayerPed(); uint hplayer = CPools::GetPedRef(player); diff --git a/src/Weapon.h b/src/Weapon.h index 162389c..41014b2 100644 --- a/src/Weapon.h +++ b/src/Weapon.h @@ -7,9 +7,10 @@ private: static std::string selected_item; static std::vector search_categories; static std::vector> weapon_vec; - - static CJson weapon_json; + static bool images_loaded; + static CJson weapon_json; + static bool auto_aim; static bool fast_reload; static bool huge_damage; @@ -32,7 +33,7 @@ public: Weapon(); ~Weapon(); - static void Main(); + static void Draw(); static void GiveWeaponToPlayer(std::string& weapon_type); static void SetGangWeapon(std::string& weapon_type); }; diff --git a/src/pch.cpp b/src/pch.cpp index 44d7943..dd3cf83 100644 --- a/src/pch.cpp +++ b/src/pch.cpp @@ -1,12 +1,13 @@ #include "pch.h" std::string Globals::header_id = ""; -ImVec2 Globals::menu_size = ImVec2(screen::GetScreenWidth()/4, screen::GetScreenHeight()/1.2); +ImVec2 Globals::menu_size = ImVec2(screen::GetScreenWidth() / 4, screen::GetScreenHeight() / 1.2); ImVec2 Globals::screen_size = ImVec2(-1, -1); bool Globals::show_menu = false; bool Globals::init_done = false; Renderer Globals::renderer = Render_Unknown; -void *Globals::device = nullptr; +void* Globals::device = nullptr; +bool Globals::game_init = false; std::ofstream flog = std::ofstream("CheatMenu.log"); CJson config = CJson("config"); diff --git a/src/pch.h b/src/pch.h index d4edc94..3485897 100644 --- a/src/pch.h +++ b/src/pch.h @@ -56,7 +56,6 @@ #include "imgui/imgui_internal.h" #include "imgui/imgui_impl_dx9.h" #include "imgui/imgui_impl_dx11.h" -// #include "imgui/imgui_impl_vulkan.h" #include "imgui/imgui_impl_win32.h" #include "Events.h" @@ -86,6 +85,7 @@ struct Globals static ImVec2 screen_size; static bool show_menu; static bool init_done; + static bool game_init; static Renderer renderer; static void* device; }; @@ -94,7 +94,7 @@ struct TextureStructure { std::string file_name; std::string category_name; - void *texture = nullptr; + void* texture = nullptr; }; struct HotKeyData