├── immunity-gta5 ├── packages.config ├── fiber.hpp ├── immunity-gta5.vcxproj.user ├── tick.hpp ├── dllmain.cpp ├── secure.hpp ├── useful.h ├── imports.h ├── immunity-gta5.vcxproj.filters ├── xor.h ├── ui_extend.hpp ├── immunity-gta5.vcxproj ├── functions.h ├── config.hpp ├── features │ └── aimbot.hpp ├── pointers.hpp └── game.hpp ├── readme.md ├── includes ├── imgui │ ├── imgui_impl_dx11.h │ ├── imgui_impl_win32.h │ ├── imconfig.h │ ├── imgui_impl_win32.cpp │ └── imstb_rectpack.h ├── renderer │ ├── Renderer.h │ └── Renderer.cpp └── ini.h └── immunity-gta5.sln /immunity-gta5/packages.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /immunity-gta5/fiber.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #include "imports.h" 9 | -------------------------------------------------------------------------------- /immunity-gta5/immunity-gta5.vcxproj.user: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | false 5 | 6 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | COMPILATION NOTE BY "ABN": 2 | 3 | Download: 4 | -DXSDK ( https://download.microsoft.com/download/A/E/7/AE743F1F-632B-4809-87A9-AA1BB3458E31/DXSDK_Jun10.exe ) 5 | -Minhook( https://github.com/TsudaKageyu/minhook/releases/tag/v1.3.3 ) 6 | -Visual Studio + MSVC Compiler + C++ pack ( https://visualstudio.microsoft.com/de/downloads/ ) 7 | -Replace includes + libs with ur own path 8 | -Set to Release, x64 9 | -Compile 10 | 11 | (Google errors dont annoying everybody!!!) 12 | 13 | 14 | ps: idfk if it even fixed it lol aint no way iam downloading GTA to test 15 | -------------------------------------------------------------------------------- /immunity-gta5/tick.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | 6 | namespace tick 7 | { 8 | class thread_invoker 9 | { 10 | public: 11 | 12 | inline static void queue(std::function func) 13 | { 14 | funcs_to_invoke.emplace_back(std::make_pair(func, GetTickCount64())); 15 | } 16 | 17 | void on_tick() 18 | { 19 | auto current_tick = GetTickCount64(); 20 | for (auto& funcs : funcs_to_invoke) 21 | { 22 | if (current_tick - funcs.second < 1000) 23 | { 24 | funcs.first(); 25 | } 26 | } 27 | 28 | funcs_to_invoke.clear(); 29 | } 30 | private: 31 | inline static std::vector, uintptr_t>> funcs_to_invoke; 32 | }; 33 | 34 | inline thread_invoker pnative; 35 | } -------------------------------------------------------------------------------- /includes/imgui/imgui_impl_dx11.h: -------------------------------------------------------------------------------- 1 | // dear imgui: Renderer for DirectX11 2 | // This needs to be used along with a Platform Binding (e.g. Win32) 3 | 4 | // Implemented features: 5 | // [X] Renderer: User texture binding. Use 'ID3D11ShaderResourceView*' as ImTextureID. Read the FAQ about ImTextureID in imgui.cpp. 6 | // [X] Renderer: Support for large meshes (64k+ vertices) with 16-bits indices. 7 | 8 | // You can copy and use unmodified imgui_impl_* files in your project. See main.cpp for an example of using this. 9 | // If you are new to dear imgui, read examples/README.txt and read the documentation at the top of imgui.cpp. 10 | // https://github.com/ocornut/imgui 11 | 12 | #pragma once 13 | 14 | struct ID3D11Device; 15 | struct ID3D11DeviceContext; 16 | 17 | IMGUI_IMPL_API bool ImGui_ImplDX11_Init(ID3D11Device* device, ID3D11DeviceContext* device_context); 18 | IMGUI_IMPL_API void ImGui_ImplDX11_Shutdown(); 19 | IMGUI_IMPL_API void ImGui_ImplDX11_NewFrame(); 20 | IMGUI_IMPL_API void ImGui_ImplDX11_RenderDrawData(ImDrawData* draw_data); 21 | 22 | // Use if you want to reset your rendering device without losing ImGui state. 23 | IMGUI_IMPL_API void ImGui_ImplDX11_InvalidateDeviceObjects(); 24 | IMGUI_IMPL_API bool ImGui_ImplDX11_CreateDeviceObjects(); 25 | -------------------------------------------------------------------------------- /includes/imgui/imgui_impl_win32.h: -------------------------------------------------------------------------------- 1 | // dear imgui: Platform Binding for Windows (standard windows API for 32 and 64 bits applications) 2 | // This needs to be used along with a Renderer (e.g. DirectX11, OpenGL3, Vulkan..) 3 | 4 | // Implemented features: 5 | // [X] Platform: Clipboard support (for Win32 this is actually part of core imgui) 6 | // [X] Platform: Mouse cursor shape and visibility. Disable with 'io.ConfigFlags |= ImGuiConfigFlags_NoMouseCursorChange'. 7 | // [X] Platform: Keyboard arrays indexed using VK_* Virtual Key Codes, e.g. ImGui::IsKeyPressed(VK_SPACE). 8 | // [X] Platform: Gamepad support. Enabled with 'io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad'. 9 | 10 | #pragma once 11 | 12 | IMGUI_IMPL_API bool ImGui_ImplWin32_Init(void* hwnd); 13 | IMGUI_IMPL_API void ImGui_ImplWin32_Shutdown(); 14 | IMGUI_IMPL_API void ImGui_ImplWin32_NewFrame(); 15 | 16 | // Handler for Win32 messages, update mouse/keyboard data. 17 | // You may or not need this for your implementation, but it can serve as reference for handling inputs. 18 | // Intentionally commented out to avoid dragging dependencies on types. You can COPY this line into your .cpp code instead. 19 | /* 20 | IMGUI_IMPL_API LRESULT ImGui_ImplWin32_WndProcHandler(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam); 21 | */ 22 | -------------------------------------------------------------------------------- /immunity-gta5/dllmain.cpp: -------------------------------------------------------------------------------- 1 | #include "imports.h" 2 | #include "secure.hpp" 3 | 4 | DWORD __stdcall InitializeHook(PVOID) { 5 | 6 | config::load(); 7 | 8 | 9 | if (pointers::findAllPatterns()) { 10 | if (hook::enable()) { 11 | logs::add("enabled hooks"); 12 | Game.running = true; 13 | 14 | 15 | std::thread aimThread(aimbot::init); 16 | aimThread.detach(); 17 | 18 | std::thread hacksThread(hacks::init); 19 | hacksThread.detach(); 20 | } 21 | } 22 | 23 | tools::unlink_module_peb(Game.hModule); 24 | while (Game.running) { 25 | hook::patch_wndproc(); 26 | std::this_thread::sleep_for(500ms); 27 | } 28 | tools::relink_module_peb(Game.hModule); 29 | 30 | 31 | 32 | Game.running = false; 33 | 34 | Sleep(500); 35 | hook::disable(); 36 | 37 | FreeLibraryAndExitThread((HMODULE)Game.hModule, 0); 38 | return 1; 39 | } 40 | 41 | 42 | BOOL APIENTRY DllMain(HMODULE hModule, 43 | DWORD ul_reason_for_call, 44 | LPVOID lpReserved 45 | ) { 46 | if (ul_reason_for_call == DLL_PROCESS_ATTACH) { 47 | logs::clear(); 48 | Game.base = (uintptr_t)GetModuleHandleA(0); 49 | Game.hModule = hModule; 50 | logs::add("module entry"); 51 | Sleep(100); 52 | CreateThread(NULL, 0, InitializeHook, NULL, 0, NULL); 53 | } else if (ul_reason_for_call == DLL_PROCESS_DETACH) { 54 | 55 | } 56 | return TRUE; 57 | } 58 | 59 | -------------------------------------------------------------------------------- /immunity-gta5.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.29911.84 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "immunity-gta5", "immunity-gta5\immunity-gta5.vcxproj", "{05A41833-32B5-4898-AF98-6EBDAD66F1FD}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|x64 = Debug|x64 11 | Debug|x86 = Debug|x86 12 | Release|x64 = Release|x64 13 | Release|x86 = Release|x86 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {05A41833-32B5-4898-AF98-6EBDAD66F1FD}.Debug|x64.ActiveCfg = Debug|x64 17 | {05A41833-32B5-4898-AF98-6EBDAD66F1FD}.Debug|x64.Build.0 = Debug|x64 18 | {05A41833-32B5-4898-AF98-6EBDAD66F1FD}.Debug|x86.ActiveCfg = Debug|Win32 19 | {05A41833-32B5-4898-AF98-6EBDAD66F1FD}.Debug|x86.Build.0 = Debug|Win32 20 | {05A41833-32B5-4898-AF98-6EBDAD66F1FD}.Release|x64.ActiveCfg = Release|x64 21 | {05A41833-32B5-4898-AF98-6EBDAD66F1FD}.Release|x64.Build.0 = Release|x64 22 | {05A41833-32B5-4898-AF98-6EBDAD66F1FD}.Release|x86.ActiveCfg = Release|Win32 23 | {05A41833-32B5-4898-AF98-6EBDAD66F1FD}.Release|x86.Build.0 = Release|Win32 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | GlobalSection(ExtensibilityGlobals) = postSolution 29 | SolutionGuid = {ACEA898F-939B-4CF6-83DA-6CE9A1AC738A} 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /includes/renderer/Renderer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | 6 | #include 7 | #include 8 | #include 9 | #pragma comment(lib, "d3d11.lib") 10 | 11 | 12 | //#include 13 | //#pragma comment(lib, "d3dx11.lib") 14 | 15 | 16 | 17 | 18 | #include "../imgui/imgui.h" 19 | #include "../imgui/imgui_impl_dx11.h" 20 | #include "../imgui/imgui_impl_win32.h" 21 | #include "../imgui/imgui_internal.h" 22 | 23 | 24 | // Color Struct Storing rgba value 25 | struct RGBA { 26 | RGBA(int r, int g, int b, int a) : 27 | r(r), g(g), b(b), a(a) { } 28 | 29 | int r ; 30 | int g ; 31 | int b ; 32 | int a ; 33 | }; 34 | 35 | class imgui_render { 36 | public: 37 | ImGuiIO io; 38 | 39 | HRESULT hres; 40 | D3D11_VIEWPORT viewport; 41 | IDXGISwapChain* pSwapChain = nullptr; 42 | ID3D11Device* pDevice = nullptr; 43 | ID3D11DeviceContext* pContext = nullptr; 44 | ID3D11RenderTargetView* RenderTargetView = nullptr; 45 | typedef void (*vResourceLoadCall)(ID3D11Device*); 46 | 47 | 48 | vResourceLoadCall loadCall = nullptr; 49 | 50 | void SetResourceLoad(vResourceLoadCall funct2); 51 | 52 | void Initialize(HWND targetWindow, IDXGISwapChain* pSwapchain); 53 | 54 | void BeginScene(); 55 | void EndScene(); 56 | 57 | void Render(); 58 | 59 | bool ready(); 60 | void release(); 61 | void reset(UINT Width, UINT Height); 62 | 63 | 64 | float RenderText(const std::string& text, const ImVec2& position, float size, RGBA color, bool center,bool outine = false); 65 | void RenderLine(const ImVec2& from, const ImVec2& to, RGBA color, float thickness = 1.0f); 66 | void RenderCircle(const ImVec2& position, float radius, RGBA color, float thickness = 1.0f, uint32_t segments = 16); 67 | void RenderCircleFilled(const ImVec2& position, float radius, RGBA color, uint32_t segments = 16); 68 | void RenderRect(const ImVec2& from, const ImVec2& to, RGBA color, float rounding = 0.0f, uint32_t roundingCornersFlags = ImDrawCornerFlags_All, float thickness = 1.0f); 69 | void RenderDot(const ImVec2& from, const ImVec2& to, RGBA color, float thickness = 1.0f); 70 | void RenderRectFilled(const ImVec2& from, const ImVec2& to,RGBA color, float rounding = 0.0f, uint32_t roundingCornersFlags = ImDrawCornerFlags_All); 71 | 72 | 73 | 74 | ImVec2 RenderMenuRow(const ImVec2& from,float width); 75 | void RenderMenuSwitch(const ImVec2& from,std::string value); 76 | void RenderMenuValue(const ImVec2& from,float value); 77 | 78 | private: 79 | 80 | bool finishedInit = false; 81 | ImFont* imFont; 82 | }; -------------------------------------------------------------------------------- /immunity-gta5/secure.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | 6 | #include 7 | #include 8 | 9 | #ifdef _WIN64 10 | struct HookContext { 11 | BYTE original_code[64]; 12 | SIZE_T dst_ptr; 13 | BYTE far_jmp[6]; 14 | }; 15 | HookContext* presenthook64; 16 | 17 | #endif 18 | typedef struct _PEB_LDR_DATA { 19 | UINT8 _PADDING_[12]; 20 | LIST_ENTRY InLoadOrderModuleList; 21 | LIST_ENTRY InMemoryOrderModuleList; 22 | LIST_ENTRY InInitializationOrderModuleList; 23 | } PEB_LDR_DATA, * PPEB_LDR_DATA; 24 | 25 | typedef struct _PEB { 26 | #ifdef _WIN64 27 | UINT8 _PADDING_[24]; 28 | #else 29 | UINT8 _PADDING_[12]; 30 | #endif 31 | PEB_LDR_DATA* Ldr; 32 | } PEB, * PPEB; 33 | 34 | typedef struct _LDR_DATA_TABLE_ENTRY { 35 | LIST_ENTRY InLoadOrderLinks; 36 | LIST_ENTRY InMemoryOrderLinks; 37 | LIST_ENTRY InInitializationOrderLinks; 38 | VOID* DllBase; 39 | } LDR_DATA_TABLE_ENTRY, * PLDR_DATA_TABLE_ENTRY; 40 | 41 | typedef struct _UNLINKED_MODULE { 42 | HMODULE hModule; 43 | PLIST_ENTRY RealInLoadOrderLinks; 44 | PLIST_ENTRY RealInMemoryOrderLinks; 45 | PLIST_ENTRY RealInInitializationOrderLinks; 46 | PLDR_DATA_TABLE_ENTRY Entry; 47 | } UNLINKED_MODULE; 48 | 49 | #define UNLINK(x) \ 50 | (x).Flink->Blink = (x).Blink; \ 51 | (x).Blink->Flink = (x).Flink; 52 | 53 | #define RELINK(x, real) \ 54 | (x).Flink->Blink = (real); \ 55 | (x).Blink->Flink = (real); \ 56 | (real)->Blink = (x).Blink; \ 57 | (real)->Flink = (x).Flink; 58 | 59 | std::vector UnlinkedModules; 60 | 61 | struct FindModuleHandle { 62 | HMODULE m_hModule; 63 | FindModuleHandle(HMODULE hModule) : m_hModule(hModule) { 64 | } 65 | bool operator() (UNLINKED_MODULE const& Module) const { 66 | return (Module.hModule == m_hModule); 67 | } 68 | }; 69 | namespace tools { 70 | void relink_module_peb(HMODULE hModule) { 71 | std::vector::iterator it = std::find_if(UnlinkedModules.begin(), UnlinkedModules.end(), FindModuleHandle(hModule)); 72 | 73 | if (it == UnlinkedModules.end()) { 74 | //DBGOUT(TEXT("Module Not Unlinked Yet!")); 75 | return; 76 | } 77 | 78 | RELINK((*it).Entry->InLoadOrderLinks, (*it).RealInLoadOrderLinks); 79 | RELINK((*it).Entry->InInitializationOrderLinks, (*it).RealInInitializationOrderLinks); 80 | RELINK((*it).Entry->InMemoryOrderLinks, (*it).RealInMemoryOrderLinks); 81 | UnlinkedModules.erase(it); 82 | } 83 | 84 | 85 | 86 | 87 | void unlink_module_peb(HMODULE hModule) { 88 | std::vector::iterator it = std::find_if(UnlinkedModules.begin(), UnlinkedModules.end(), FindModuleHandle(hModule)); 89 | if (it != UnlinkedModules.end()) { 90 | return; 91 | } 92 | 93 | #ifdef _WIN64 94 | PPEB pPEB = (PPEB)__readgsqword(0x60); 95 | #else 96 | PPEB pPEB = (PPEB)__readfsdword(0x30); 97 | #endif 98 | 99 | PLIST_ENTRY CurrentEntry = pPEB->Ldr->InLoadOrderModuleList.Flink; 100 | PLDR_DATA_TABLE_ENTRY Current = NULL; 101 | 102 | while (CurrentEntry != &pPEB->Ldr->InLoadOrderModuleList && CurrentEntry != NULL) { 103 | Current = CONTAINING_RECORD(CurrentEntry, LDR_DATA_TABLE_ENTRY, InLoadOrderLinks); 104 | if (Current->DllBase == hModule) { 105 | UNLINKED_MODULE CurrentModule = { 0 }; 106 | CurrentModule.hModule = hModule; 107 | CurrentModule.RealInLoadOrderLinks = Current->InLoadOrderLinks.Blink->Flink; 108 | CurrentModule.RealInInitializationOrderLinks = Current->InInitializationOrderLinks.Blink->Flink; 109 | CurrentModule.RealInMemoryOrderLinks = Current->InMemoryOrderLinks.Blink->Flink; 110 | CurrentModule.Entry = Current; 111 | UnlinkedModules.push_back(CurrentModule); 112 | 113 | UNLINK(Current->InLoadOrderLinks); 114 | UNLINK(Current->InInitializationOrderLinks); 115 | UNLINK(Current->InMemoryOrderLinks); 116 | break; 117 | } 118 | 119 | CurrentEntry = CurrentEntry->Flink; 120 | } 121 | 122 | return; 123 | } 124 | } -------------------------------------------------------------------------------- /immunity-gta5/useful.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "imports.h" 3 | 4 | using namespace std; 5 | 6 | 7 | 8 | #include 9 | string GetFolderLocation(int csidl) { 10 | 11 | 12 | char buffer[_MAX_PATH]; 13 | LPITEMIDLIST pidl = 0; 14 | HRESULT result = SHGetSpecialFolderLocation(NULL, csidl, &pidl); 15 | *buffer = 0; 16 | 17 | if (result == 0) { 18 | SHGetPathFromIDList(pidl, buffer); 19 | CoTaskMemFree(pidl); 20 | return string(buffer); 21 | } 22 | return string(buffer); 23 | } 24 | 25 | 26 | 27 | namespace logs { 28 | string logFile = ""; 29 | inline bool exists() { 30 | string appdata = GetFolderLocation(CSIDL_LOCAL_APPDATA); 31 | logFile = appdata + "/immunity/logs/log.txt"; 32 | cout << "[!] appdata " << appdata << endl; 33 | 34 | if (CreateDirectory((appdata + "/immunity/logs/").c_str(), NULL) || 35 | ERROR_ALREADY_EXISTS == GetLastError()) { 36 | 37 | return true; 38 | } 39 | return false; 40 | } 41 | 42 | inline string getCurrentDateTime(string s) { 43 | time_t now = time(0); 44 | struct tm tstruct; 45 | char buf[80]; 46 | tstruct = *localtime(&now); 47 | if (s == "now") 48 | strftime(buf, sizeof(buf), "%Y-%m-%d %X", &tstruct); 49 | else if (s == "date") 50 | strftime(buf, sizeof(buf), "%Y-%m-%d", &tstruct); 51 | return string(buf); 52 | }; 53 | 54 | 55 | 56 | inline void clear() { 57 | if (exists()) { 58 | std::ofstream ofs; 59 | ofs.open(logFile.c_str(), std::ofstream::out | std::ofstream::trunc); 60 | ofs.close(); 61 | } 62 | } 63 | 64 | inline void addLog(string logMsg) { 65 | if (exists()) { 66 | string now = getCurrentDateTime("now"); 67 | ofstream ofs(logFile.c_str(), std::ios_base::out | std::ios_base::app); 68 | ofs << now << '\t' << logMsg << '\n'; 69 | ofs.close(); 70 | } 71 | } 72 | inline void add(string logMsg) { 73 | addLog(logMsg); 74 | } 75 | } 76 | 77 | 78 | 79 | namespace utils { 80 | 81 | using _RtlCreateUserThread = NTSTATUS(NTAPI*)( 82 | HANDLE ProcessHandle, 83 | PSECURITY_DESCRIPTOR SecurityDescriptor, 84 | BOOLEAN CreateSuspend, 85 | ULONG StackZeroBits, 86 | PULONG StackReserved, 87 | PULONG StackCommit, 88 | void* StartAddress, 89 | void* StartParameter, 90 | PHANDLE ThreadHandle, 91 | void* ClientID 92 | ); 93 | 94 | 95 | 96 | 97 | HANDLE spoof_thread(void* Thread, HMODULE& hModule) { 98 | HMODULE NT_DLL = LoadLibrary(xorstr_("ntdll")); 99 | uintptr_t SpoofedAddress = NULL; 100 | int DefaultThreadSize = 1000; 101 | srand(time(NULL)); // see random nums 102 | 103 | for (int i = 1; i < 4; i++) { 104 | SpoofedAddress |= (rand() & 0xFF) << i * 8; // we store it in the lowest bytes 105 | SpoofedAddress |= (rand() & 0xFF) << i * 8; 106 | SpoofedAddress |= (rand() & 0xFF) << i * 8; 107 | //returns spoofed address 108 | } 109 | while (SpoofedAddress > 0x7FFFFFFF) { 110 | SpoofedAddress -= 0x1000; 111 | } 112 | VirtualProtect((void*)SpoofedAddress, DefaultThreadSize, PAGE_EXECUTE_READWRITE, NULL); 113 | 114 | CONTEXT tContext; 115 | HANDLE pHandle = nullptr; 116 | 117 | _RtlCreateUserThread KeThread = (_RtlCreateUserThread)(GetProcAddress(GetModuleHandle(xorstr_("ntdll")), xorstr_("RtlCreateUserThread"))); 118 | KeThread(GetCurrentProcess(), nullptr, TRUE, NULL, NULL, NULL, (PTHREAD_START_ROUTINE)SpoofedAddress, hModule, &pHandle, NULL); //create a thread & stop init everything 119 | 120 | tContext.ContextFlags = CONTEXT_INTEGER | CONTEXT_CONTROL; 121 | GetThreadContext(pHandle, &tContext); 122 | 123 | #ifndef _WIN64 124 | tContext.Eax = (ULONG32)Thread; 125 | #else 126 | tContext.Rcx = (ULONG64)Thread; 127 | #endif 128 | 129 | tContext.ContextFlags = CONTEXT_INTEGER | CONTEXT_CONTROL; 130 | 131 | SetThreadContext(pHandle, &tContext); 132 | 133 | ResumeThread(pHandle); 134 | 135 | 136 | return pHandle; 137 | } 138 | } 139 | 140 | 141 | 142 | 143 | 144 | 145 | #define PI 3.14159265 146 | 147 | float EaseOut(float time, float start, float end, float current) { 148 | if (time == 0) return start; if ((time /= current) == 1) return start + end; 149 | float p = current * .3f; 150 | float a = end; 151 | float s = p / 4; 152 | return (a * pow(2, -10 * time) * sin((time * current - s) * (2 * PI) / p) + end + start); 153 | } 154 | 155 | double easeOutCubic(double t) { 156 | return 1 + (--t) * t * t; 157 | } 158 | 159 | double easeInSine(double t) { 160 | return sin(1.5707963 * t); 161 | } 162 | 163 | 164 | 165 | 166 | -------------------------------------------------------------------------------- /immunity-gta5/imports.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #define _CRT_SECURE_NO_WARNINGS 3 | 4 | #include 5 | #include 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | #include 29 | 30 | #define IM_MAX(_A,_B) (((_A) >= (_B)) ? (_A) : (_B)) 31 | 32 | #ifndef IsValidPtr 33 | #define IsValidPtr(x) (x && !IsBadReadPtr(&x, sizeof(void*) && x != nullptr && x > nullptr)) 34 | #endif 35 | 36 | 37 | // for convenience 38 | using json = nlohmann::json; 39 | bool debug = false; 40 | 41 | using namespace std; 42 | 43 | #include "MinHook.h" 44 | #if defined _M_X64 45 | #pragma comment(lib, "libMinHook.x64.lib") 46 | #elif defined _M_IX86 47 | #pragma comment(lib, "libMinHook.x86.lib") 48 | #endif 49 | 50 | #include "../includes/SimpleMath.h" 51 | 52 | using namespace DirectX::SimpleMath; 53 | 54 | 55 | #include "../includes/renderer/Renderer.h" 56 | #include "xor.h" 57 | #include "useful.h" 58 | #include 59 | 60 | #include "image.h" 61 | 62 | #define add_log(str) logs::add(enc(str)) 63 | 64 | imgui_render renderer; 65 | 66 | ID3D11ShaderResourceView* immunity_image = nullptr; 67 | 68 | void load_image_assets(ID3D11Device* device) 69 | { 70 | //All your other InitImGuiCode ... 71 | 72 | 73 | 74 | logs::add("load_image"); 75 | D3DX11_IMAGE_LOAD_INFO info; 76 | ID3DX11ThreadPump* pump{nullptr}; 77 | 78 | 79 | D3DX11CreateShaderResourceViewFromMemory(device, rawData, sizeof(rawData), &info, 80 | pump, &immunity_image, 0); 81 | 82 | return; 83 | }; 84 | 85 | 86 | #include "structs.h" 87 | 88 | typedef void(__fastcall* Game_tick) (); 89 | 90 | namespace fiber 91 | { 92 | using script_func_t = void(*)(); 93 | 94 | class fiber_task 95 | { 96 | public: 97 | explicit fiber_task(HMODULE hmod, script_func_t func) : 98 | m_hmodule(hmod), 99 | m_function(func) 100 | { } 101 | 102 | ~fiber_task() noexcept 103 | { 104 | if (m_script_fiber) 105 | { 106 | DeleteFiber(m_script_fiber); 107 | } 108 | } 109 | 110 | HMODULE get_hmodule() 111 | { 112 | return m_hmodule; 113 | } 114 | 115 | script_func_t get_function() 116 | { 117 | return m_function; 118 | } 119 | 120 | void on_tick() 121 | { 122 | if (GetTickCount64() < m_wake_at) 123 | return; 124 | 125 | if (!m_main_fiber) 126 | { 127 | m_main_fiber = IsThreadAFiber() ? GetCurrentFiber() : ConvertThreadToFiber(nullptr); 128 | } 129 | 130 | if (m_script_fiber) 131 | { 132 | current_fiber_script = this; 133 | SwitchToFiber(m_script_fiber); 134 | current_fiber_script = nullptr; 135 | } 136 | else 137 | { 138 | 139 | m_script_fiber = CreateFiber(0, [](PVOID param) 140 | { 141 | auto this_script = static_cast(param); 142 | while (true) 143 | { 144 | this_script->m_function(); 145 | } 146 | 147 | }, this); 148 | } 149 | } 150 | void wait(std::uint32_t time) 151 | { 152 | m_wake_at = GetTickCount64() + time; 153 | SwitchToFiber(m_main_fiber); 154 | } 155 | 156 | inline static fiber_task* get_current_script() 157 | { 158 | return current_fiber_script; 159 | } 160 | private: 161 | HMODULE m_hmodule{}; 162 | script_func_t m_function{}; 163 | 164 | std::uint32_t m_wake_at{}; 165 | void* m_script_fiber{}; 166 | void* m_main_fiber{}; 167 | 168 | inline static fiber_task* current_fiber_script{}; 169 | }; 170 | } 171 | std::unique_ptr game_fiber; 172 | 173 | 174 | struct HackBase { 175 | map keyStates; 176 | int renderMethod = -1; 177 | bool renderReady = false; 178 | bool running = false; 179 | 180 | bool menuOpen = true; 181 | 182 | ImVec2 screen = ImVec2(0, 0); 183 | HWND window = 0; 184 | HMODULE hModule = 0; 185 | WNDPROC originalWndProc = nullptr; 186 | 187 | uintptr_t base = 0; 188 | CReplayInterface* ReplayInterface = nullptr; 189 | CWorld* World = nullptr; 190 | 191 | CViewPort* viewPort = nullptr; 192 | game_state_t* gta_game_state = 0; 193 | 194 | uintptr_t CamAddr = 0; 195 | 196 | Game_tick tick; 197 | 198 | 199 | int game_mod_base = 0; 200 | 201 | vector messages; 202 | 203 | CPlayerAngles* getCam() { 204 | if (CamAddr){ 205 | return *(CPlayerAngles**)(CamAddr + 0x0); 206 | } 207 | return 0; 208 | } 209 | 210 | CGameCameraAngles* CGameCamera; 211 | 212 | bool allowClearTasks = false; 213 | } Game; 214 | 215 | //local player etc 216 | struct LocalData { 217 | CObject* player = nullptr; 218 | } local; 219 | 220 | 221 | 222 | 223 | #include "functions.h" 224 | 225 | #include "database.hpp" 226 | 227 | #include "config.hpp" 228 | #include "tick.hpp" 229 | 230 | #include "features/aimbot.hpp" 231 | #include "features/ui.hpp" 232 | #include "features/esp.hpp" 233 | #include "features/hacks.hpp" 234 | 235 | #include "game.hpp" 236 | 237 | #include "hooks.hpp" 238 | 239 | #include "pointers.hpp" 240 | -------------------------------------------------------------------------------- /immunity-gta5/immunity-gta5.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;c++;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | {5d293270-1fde-4d04-9b6f-c56d338969d8} 18 | 19 | 20 | {5707cdf9-7ce9-4daf-807a-a31d135aa2b6} 21 | 22 | 23 | {fd89b327-ea90-487f-9c58-00d7d30bd058} 24 | 25 | 26 | {84fd26c0-e490-453a-b935-dc991caf30ec} 27 | 28 | 29 | 30 | 31 | Headerdateien 32 | 33 | 34 | Headerdateien 35 | 36 | 37 | Headerdateien 38 | 39 | 40 | renderer 41 | 42 | 43 | imgui 44 | 45 | 46 | imgui 47 | 48 | 49 | imgui 50 | 51 | 52 | imgui 53 | 54 | 55 | imgui 56 | 57 | 58 | imgui 59 | 60 | 61 | imgui 62 | 63 | 64 | imgui 65 | 66 | 67 | Quelldateien 68 | 69 | 70 | Quelldateien 71 | 72 | 73 | Quelldateien 74 | 75 | 76 | Headerdateien 77 | 78 | 79 | Headerdateien 80 | 81 | 82 | Headerdateien 83 | 84 | 85 | Headerdateien 86 | 87 | 88 | native 89 | 90 | 91 | native 92 | 93 | 94 | native 95 | 96 | 97 | native 98 | 99 | 100 | Headerdateien 101 | 102 | 103 | Headerdateien 104 | 105 | 106 | features 107 | 108 | 109 | features 110 | 111 | 112 | features 113 | 114 | 115 | features 116 | 117 | 118 | 119 | 120 | Quelldateien 121 | 122 | 123 | renderer 124 | 125 | 126 | imgui 127 | 128 | 129 | imgui 130 | 131 | 132 | imgui 133 | 134 | 135 | imgui 136 | 137 | 138 | imgui 139 | 140 | 141 | imgui 142 | 143 | 144 | 145 | 146 | 147 | -------------------------------------------------------------------------------- /includes/imgui/imconfig.h: -------------------------------------------------------------------------------- 1 | //----------------------------------------------------------------------------- 2 | // COMPILE-TIME OPTIONS FOR DEAR IMGUI 3 | // Runtime options (clipboard callbacks, enabling various features, etc.) can generally be set via the ImGuiIO structure. 4 | // You can use ImGui::SetAllocatorFunctions() before calling ImGui::CreateContext() to rewire memory allocation functions. 5 | //----------------------------------------------------------------------------- 6 | // A) You may edit imconfig.h (and not overwrite it when updating Dear ImGui, or maintain a patch/branch with your modifications to imconfig.h) 7 | // B) or add configuration directives in your own file and compile with #define IMGUI_USER_CONFIG "myfilename.h" 8 | // If you do so you need to make sure that configuration settings are defined consistently _everywhere_ Dear ImGui is used, which include 9 | // the imgui*.cpp files but also _any_ of your code that uses Dear ImGui. This is because some compile-time options have an affect on data structures. 10 | // Defining those options in imconfig.h will ensure every compilation unit gets to see the same data structure layouts. 11 | // Call IMGUI_CHECKVERSION() from your .cpp files to verify that the data structures your files are using are matching the ones imgui.cpp is using. 12 | //----------------------------------------------------------------------------- 13 | 14 | #pragma once 15 | 16 | #define IMGUI_DEFINE_MATH_OPERATORS 17 | //---- Define assertion handler. Defaults to calling assert(). 18 | //#define IM_ASSERT(_EXPR) MyAssert(_EXPR) 19 | //#define IM_ASSERT(_EXPR) ((void)(_EXPR)) // Disable asserts 20 | 21 | //---- Define attributes of all API symbols declarations, e.g. for DLL under Windows 22 | // Using dear imgui via a shared library is not recommended, because of function call overhead and because we don't guarantee backward nor forward ABI compatibility. 23 | //#define IMGUI_API __declspec( dllexport ) 24 | //#define IMGUI_API __declspec( dllimport ) 25 | 26 | //---- Don't define obsolete functions/enums names. Consider enabling from time to time after updating to avoid using soon-to-be obsolete function/names. 27 | //#define IMGUI_DISABLE_OBSOLETE_FUNCTIONS 28 | 29 | //---- Don't implement demo windows functionality (ShowDemoWindow()/ShowStyleEditor()/ShowUserGuide() methods will be empty) 30 | // It is very strongly recommended to NOT disable the demo windows during development. Please read the comments in imgui_demo.cpp. 31 | //#define IMGUI_DISABLE_DEMO_WINDOWS 32 | 33 | //---- Don't implement some functions to reduce linkage requirements. 34 | //#define IMGUI_DISABLE_WIN32_DEFAULT_CLIPBOARD_FUNCTIONS // [Win32] Don't implement default clipboard handler. Won't use and link with OpenClipboard/GetClipboardData/CloseClipboard etc. 35 | //#define IMGUI_DISABLE_WIN32_DEFAULT_IME_FUNCTIONS // [Win32] Don't implement default IME handler. Won't use and link with ImmGetContext/ImmSetCompositionWindow. 36 | //#define IMGUI_DISABLE_WIN32_FUNCTIONS // [Win32] Won't use and link with any Win32 function (clipboard, ime). 37 | //#define IMGUI_DISABLE_OSX_FUNCTIONS // [OSX] Won't use and link with any OSX function (clipboard). 38 | //#define IMGUI_DISABLE_FORMAT_STRING_FUNCTIONS // Don't implement ImFormatString/ImFormatStringV so you can implement them yourself if you don't want to link with vsnprintf. 39 | //#define IMGUI_DISABLE_MATH_FUNCTIONS // Don't implement ImFabs/ImSqrt/ImPow/ImFmod/ImCos/ImSin/ImAcos/ImAtan2 wrapper so you can implement them yourself. Declare your prototypes in imconfig.h. 40 | //#define IMGUI_DISABLE_DEFAULT_ALLOCATORS // Don't implement default allocators calling malloc()/free() to avoid linking with them. You will need to call ImGui::SetAllocatorFunctions(). 41 | 42 | //---- Include imgui_user.h at the end of imgui.h as a convenience 43 | //#define IMGUI_INCLUDE_IMGUI_USER_H 44 | 45 | //---- Pack colors to BGRA8 instead of RGBA8 (to avoid converting from one to another) 46 | //#define IMGUI_USE_BGRA_PACKED_COLOR 47 | 48 | //---- Avoid multiple STB libraries implementations, or redefine path/filenames to prioritize another version 49 | // By default the embedded implementations are declared static and not available outside of imgui cpp files. 50 | //#define IMGUI_STB_TRUETYPE_FILENAME "my_folder/stb_truetype.h" 51 | //#define IMGUI_STB_RECT_PACK_FILENAME "my_folder/stb_rect_pack.h" 52 | //#define IMGUI_DISABLE_STB_TRUETYPE_IMPLEMENTATION 53 | //#define IMGUI_DISABLE_STB_RECT_PACK_IMPLEMENTATION 54 | 55 | //---- Define constructor and implicit cast operators to convert back<>forth between your math types and ImVec2/ImVec4. 56 | // This will be inlined as part of ImVec2 and ImVec4 class declarations. 57 | /* 58 | #define IM_VEC2_CLASS_EXTRA \ 59 | ImVec2(const MyVec2& f) { x = f.x; y = f.y; } \ 60 | operator MyVec2() const { return MyVec2(x,y); } 61 | 62 | #define IM_VEC4_CLASS_EXTRA \ 63 | ImVec4(const MyVec4& f) { x = f.x; y = f.y; z = f.z; w = f.w; } \ 64 | operator MyVec4() const { return MyVec4(x,y,z,w); } 65 | */ 66 | 67 | //---- Using 32-bits vertex indices (default is 16-bits) is one way to allow large meshes with more than 64K vertices. 68 | // Your renderer back-end will need to support it (most example renderer back-ends support both 16/32-bits indices). 69 | // Another way to allow large meshes while keeping 16-bits indices is to handle ImDrawCmd::VtxOffset in your renderer. 70 | // Read about ImGuiBackendFlags_RendererHasVtxOffset for details. 71 | //#define ImDrawIdx unsigned int 72 | 73 | //---- Override ImDrawCallback signature (will need to modify renderer back-ends accordingly) 74 | //struct ImDrawList; 75 | //struct ImDrawCmd; 76 | //typedef void (*MyImDrawCallback)(const ImDrawList* draw_list, const ImDrawCmd* cmd, void* my_renderer_user_data); 77 | //#define ImDrawCallback MyImDrawCallback 78 | 79 | //---- Tip: You can add extra functions within the ImGui:: namespace, here or in your own headers files. 80 | /* 81 | namespace ImGui 82 | { 83 | void MyFunction(const char* name, const MyMatrix44& v); 84 | } 85 | */ 86 | -------------------------------------------------------------------------------- /immunity-gta5/xor.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | /* 3 | * Copyright 2017 - 2018 Justas Masiulis 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | #define JM_XORSTR_DISABLE_AVX_INTRINSICS 1 19 | 20 | #ifndef JM_XORSTR_HPP 21 | #define JM_XORSTR_HPP 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | #define xorstr(str) \ 29 | ::jm::make_xorstr( \ 30 | []() { return str; }, \ 31 | std::make_index_sequence{}, \ 32 | std::make_index_sequence<::jm::detail::_buffer_size()>{}) 33 | #define xorstr_(str) xorstr(str).crypt_get() 34 | #define enc(str) xorstr(str).crypt_get() 35 | 36 | #ifdef _MSC_VER 37 | #define XORSTR_FORCEINLINE __forceinline 38 | #else 39 | #define XORSTR_FORCEINLINE __attribute__((always_inline)) 40 | #endif 41 | 42 | // you can define this macro to get possibly faster code on gcc/clang 43 | // at the expense of constants being put into data section. 44 | #if !defined(XORSTR_ALLOW_DATA) 45 | // MSVC - no volatile 46 | // GCC and clang - volatile everywhere 47 | #if defined(__clang__) || defined(__GNUC__) 48 | #define XORSTR_VOLATILE volatile 49 | #endif 50 | 51 | #endif 52 | #ifndef XORSTR_VOLATILE 53 | #define XORSTR_VOLATILE 54 | #endif 55 | 56 | namespace jm { 57 | 58 | namespace detail { 59 | 60 | template 61 | struct unsigned_; 62 | 63 | template<> 64 | struct unsigned_<1> { 65 | using type = std::uint8_t; 66 | }; 67 | template<> 68 | struct unsigned_<2> { 69 | using type = std::uint16_t; 70 | }; 71 | template<> 72 | struct unsigned_<4> { 73 | using type = std::uint32_t; 74 | }; 75 | 76 | template 77 | struct pack_value_type { 78 | using type = decltype(C); 79 | }; 80 | 81 | template 82 | constexpr std::size_t _buffer_size() 83 | { 84 | return ((Size / 16) + (Size % 16 != 0)) * 2; 85 | } 86 | 87 | template 88 | struct tstring_ { 89 | using value_type = typename pack_value_type::type; 90 | constexpr static std::size_t size = sizeof...(Cs); 91 | constexpr static value_type str[size] = { Cs... }; 92 | 93 | constexpr static std::size_t buffer_size = _buffer_size(); 94 | constexpr static std::size_t buffer_align = 95 | #ifndef JM_XORSTR_DISABLE_AVX_INTRINSICS 96 | ((sizeof(str) > 16) ? 32 : 16); 97 | #else 98 | 16; 99 | #endif 100 | }; 101 | 102 | template 103 | struct _ki { 104 | constexpr static std::size_t idx = I; 105 | constexpr static std::uint64_t key = K; 106 | }; 107 | 108 | template 109 | constexpr std::uint32_t key4() noexcept 110 | { 111 | std::uint32_t value = Seed; 112 | for (char c : __TIME__) 113 | value = static_cast((value ^ c) * 16777619ull); 114 | return value; 115 | } 116 | 117 | template 118 | constexpr std::uint64_t key8() 119 | { 120 | constexpr auto first_part = key4<2166136261 + S>(); 121 | constexpr auto second_part = key4(); 122 | return (static_cast(first_part) << 32) | second_part; 123 | } 124 | 125 | // clang and gcc try really hard to place the constants in data 126 | // sections. to counter that there was a need to create an intermediate 127 | // constexpr string and then copy it into a non constexpr container with 128 | // volatile storage so that the constants would be placed directly into 129 | // code. 130 | template 131 | struct string_storage { 132 | std::uint64_t storage[T::buffer_size]; 133 | 134 | XORSTR_FORCEINLINE constexpr string_storage() noexcept : storage{ Keys... } 135 | { 136 | using cast_type = 137 | typename unsigned_::type; 138 | constexpr auto value_size = sizeof(typename T::value_type); 139 | // puts the string into 64 bit integer blocks in a constexpr 140 | // fashion 141 | for (std::size_t i = 0; i < T::size; ++i) 142 | storage[i / (8 / value_size)] ^= 143 | (std::uint64_t{ static_cast(T::str[i]) } 144 | << ((i % (8 / value_size)) * 8 * value_size)); 145 | } 146 | }; 147 | 148 | } // namespace detail 149 | 150 | template 151 | class xor_string { 152 | alignas(T::buffer_align) std::uint64_t _storage[T::buffer_size]; 153 | 154 | // _single functions needed because MSVC crashes without them 155 | XORSTR_FORCEINLINE void _crypt_256_single(const std::uint64_t* keys, 156 | std::uint64_t* storage) noexcept 157 | 158 | { 159 | _mm256_store_si256( 160 | reinterpret_cast<__m256i*>(storage), 161 | _mm256_xor_si256( 162 | _mm256_load_si256(reinterpret_cast(storage)), 163 | _mm256_load_si256(reinterpret_cast(keys)))); 164 | } 165 | 166 | template 167 | XORSTR_FORCEINLINE void _crypt_256(const std::uint64_t* keys, 168 | std::index_sequence) noexcept 169 | { 170 | (_crypt_256_single(keys + Idxs * 4, _storage + Idxs * 4), ...); 171 | } 172 | 173 | XORSTR_FORCEINLINE void _crypt_128_single(const std::uint64_t* keys, 174 | std::uint64_t* storage) noexcept 175 | { 176 | _mm_store_si128( 177 | reinterpret_cast<__m128i*>(storage), 178 | _mm_xor_si128(_mm_load_si128(reinterpret_cast(storage)), 179 | _mm_load_si128(reinterpret_cast(keys)))); 180 | } 181 | 182 | template 183 | XORSTR_FORCEINLINE void _crypt_128(const std::uint64_t* keys, 184 | std::index_sequence) noexcept 185 | { 186 | (_crypt_128_single(keys + Idxs * 2, _storage + Idxs * 2), ...); 187 | } 188 | 189 | // loop generates vectorized code which places constants in data dir 190 | XORSTR_FORCEINLINE constexpr void _copy() noexcept 191 | { 192 | constexpr detail::string_storage storage; 193 | static_cast(std::initializer_list{ 194 | (const_cast(_storage))[Keys::idx] = 195 | storage.storage[Keys::idx]... }); 196 | } 197 | 198 | public: 199 | using value_type = typename T::value_type; 200 | using size_type = std::size_t; 201 | using pointer = value_type *; 202 | using const_pointer = const pointer; 203 | 204 | XORSTR_FORCEINLINE xor_string() noexcept { _copy(); } 205 | 206 | XORSTR_FORCEINLINE constexpr size_type size() const noexcept 207 | { 208 | return T::size - 1; 209 | } 210 | 211 | XORSTR_FORCEINLINE void crypt() noexcept 212 | { 213 | alignas(T::buffer_align) std::uint64_t keys[T::buffer_size]; 214 | static_cast(std::initializer_list{ 215 | (const_cast(keys))[Keys::idx] = 216 | Keys::key... }); 217 | 218 | _copy(); 219 | 220 | #ifndef JM_XORSTR_DISABLE_AVX_INTRINSICS 221 | _crypt_256(keys, std::make_index_sequence{}); 222 | if constexpr (T::buffer_size % 4 != 0) 223 | _crypt_128(keys, std::index_sequence{}); 224 | #else 225 | _crypt_128(keys, std::make_index_sequence{}); 226 | #endif 227 | } 228 | 229 | XORSTR_FORCEINLINE const_pointer get() const noexcept 230 | { 231 | return reinterpret_cast(_storage); 232 | } 233 | 234 | XORSTR_FORCEINLINE const_pointer crypt_get() noexcept 235 | { 236 | crypt(); 237 | return reinterpret_cast(_storage); 238 | } 239 | }; 240 | 241 | template 242 | XORSTR_FORCEINLINE constexpr auto 243 | make_xorstr(Tstr str_lambda, 244 | std::index_sequence, 245 | std::index_sequence) noexcept 246 | { 247 | return xor_string, 248 | detail::_ki()>...>{}; 249 | } 250 | 251 | } // namespace jm 252 | 253 | #endif // include guard -------------------------------------------------------------------------------- /immunity-gta5/ui_extend.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "imports.h" 3 | 4 | 5 | namespace ImmunityUI { 6 | 7 | // FIXME-LEGACY: Prior to 1.61 our DragInt() function internally used floats and because of this the compile-time default value for format was "%.0f". 8 | // Even though we changed the compile-time default, we expect users to have carried %f around, which would break the display of DragInt() calls. 9 | // To honor backward compatibility we are rewriting the format string, unless IMGUI_DISABLE_OBSOLETE_FUNCTIONS is enabled. What could possibly go wrong?! 10 | static const char* PatchFormatStringFloatToInt(const char* fmt) { 11 | if (fmt[0] == '%' && fmt[1] == '.' && fmt[2] == '0' && fmt[3] == 'f' && fmt[4] == 0) // Fast legacy path for "%.0f" which is expected to be the most common case. 12 | return "%d"; 13 | const char* fmt_start = ImParseFormatFindStart(fmt); // Find % (if any, and ignore %%) 14 | const char* fmt_end = ImParseFormatFindEnd(fmt_start); // Find end of format specifier, which itself is an exercise of confidence/recklessness (because snprintf is dependent on libc or user). 15 | if (fmt_end > fmt_start && fmt_end[-1] == 'f') { 16 | #ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS 17 | if (fmt_start == fmt && fmt_end[0] == 0) 18 | return "%d"; 19 | ImGuiContext& g = *GImGui; 20 | ImFormatString(g.TempBuffer, IM_ARRAYSIZE(g.TempBuffer), "%.*s%%d%s", (int)(fmt_start - fmt), fmt, fmt_end); // Honor leading and trailing decorations, but lose alignment/precision. 21 | return g.TempBuffer; 22 | #else 23 | IM_ASSERT(0 && "DragInt(): Invalid format string!"); // Old versions used a default parameter of "%.0f", please replace with e.g. "%d" 24 | #endif 25 | } 26 | return fmt; 27 | } 28 | 29 | 30 | bool SliderScalarCustom(const char* label, ImGuiDataType data_type, void* v, const void* v_min, const void* v_max, const char* format, float power) { 31 | ImGuiWindow* window = ImGui::GetCurrentWindow(); 32 | if (window->SkipItems) 33 | return false; 34 | 35 | 36 | 37 | ImGui::PushStyleVar(ImGuiStyleVar_GrabRounding, 0.0f); 38 | 39 | ImGuiContext& g = *GImGui; 40 | const ImGuiStyle& style = g.Style; 41 | const ImGuiID id = window->GetID(label); 42 | const float w = ImGui::CalcItemWidth(); 43 | 44 | const ImVec2 label_size = ImGui::CalcTextSize(label, NULL, true); 45 | //const ImRect frame_bb(window->DC.CursorPos, window->DC.CursorPos); 46 | //const ImRect total_bb(frame_bb.Min, frame_bb.Max); 47 | 48 | 49 | const ImRect frame_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(w, label_size.y + style.FramePadding.y * 2.0f)); 50 | const ImRect total_bb(frame_bb.Min, frame_bb.Max + ImVec2(label_size.x > 0.0f ? style.ItemInnerSpacing.x + label_size.x : 0.0f, 0.0f)); 51 | 52 | ImGui::ItemSize(total_bb, style.FramePadding.y); 53 | if (!ImGui::ItemAdd(total_bb, id, &frame_bb)) 54 | return false; 55 | 56 | // Default format string when passing NULL 57 | if (format == NULL) 58 | format = ImGui::DataTypeGetInfo(data_type)->PrintFmt; 59 | else if (data_type == ImGuiDataType_S32 && strcmp(format, "%d") != 0) // (FIXME-LEGACY: Patch old "%.0f" format string to use "%d", read function more details.) 60 | format = PatchFormatStringFloatToInt(format); 61 | 62 | // Tabbing or CTRL-clicking on Slider turns it into an input box 63 | const bool hovered = ImGui::ItemHoverable(frame_bb, id); 64 | bool temp_input_is_active = ImGui::TempInputTextIsActive(id); 65 | bool temp_input_start = false; 66 | if (!temp_input_is_active) { 67 | const bool focus_requested = ImGui::FocusableItemRegister(window, id); 68 | const bool clicked = (hovered && g.IO.MouseClicked[0]); 69 | if (focus_requested || clicked || g.NavActivateId == id || g.NavInputId == id) { 70 | ImGui::SetActiveID(id, window); 71 | ImGui::SetFocusID(id, window); 72 | ImGui::FocusWindow(window); 73 | g.ActiveIdAllowNavDirFlags = (1 << ImGuiDir_Up) | (1 << ImGuiDir_Down); 74 | if (focus_requested || (clicked && g.IO.KeyCtrl) || g.NavInputId == id) { 75 | temp_input_start = true; 76 | ImGui::FocusableItemUnregister(window); 77 | } 78 | } 79 | } 80 | if (temp_input_is_active || temp_input_start) 81 | return ImGui::TempInputTextScalar(frame_bb, id, label, data_type, v, format); 82 | 83 | // Draw frame 84 | const ImU32 frame_col = ImGui::GetColorU32(g.ActiveId == id ? ImGuiCol_FrameBgActive : g.HoveredId == id ? ImGuiCol_FrameBgHovered : ImGuiCol_FrameBg); 85 | ImGui::RenderNavHighlight(frame_bb, id); 86 | ImGui::RenderFrame(frame_bb.Min, frame_bb.Max, frame_col, true, g.Style.FrameRounding); 87 | 88 | // Slider behavior 89 | ImRect grab_bb; 90 | const bool value_changed = ImGui::SliderBehavior(frame_bb, id, data_type, v, v_min, v_max, format, power, ImGuiSliderFlags_None, &grab_bb); 91 | if (value_changed) 92 | ImGui::MarkItemEdited(id); 93 | 94 | // Render grab 95 | if (grab_bb.Max.x > grab_bb.Min.x) { 96 | //const ImRect frame_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(w, label_size.y + style.FramePadding.y * 2.0f)); 97 | window->DrawList->AddRectFilled(ImVec2(frame_bb.Min.x + 2.f, grab_bb.Min.y), grab_bb.Max, ImGui::GetColorU32(g.ActiveId == id ? ImGuiCol_SliderGrabActive : ImGuiCol_SliderGrab), style.GrabRounding); 98 | } 99 | 100 | // Display value using user-provided display format so user can add prefix/suffix/decorations to the value. 101 | char value_buf[64]; 102 | const char* value_buf_end = value_buf + ImGui::DataTypeFormatString(value_buf, IM_ARRAYSIZE(value_buf), data_type, v, format); 103 | ImGui::RenderTextClipped(frame_bb.Min, frame_bb.Max, value_buf, value_buf_end, NULL, ImVec2(0.5f, 0.5f)); 104 | 105 | if (label_size.x > 0.0f) 106 | ImGui::RenderText(ImVec2(frame_bb.Max.x + style.ItemInnerSpacing.x, frame_bb.Min.y + style.FramePadding.y), label); 107 | 108 | IMGUI_TEST_ENGINE_ITEM_INFO(id, label, window->DC.ItemFlags); 109 | 110 | 111 | ImGui::PopStyleVar(); 112 | return value_changed; 113 | } 114 | 115 | bool SliderFloatCustom(const char* label, float* v, float v_min, float v_max, const char* format, float power) { 116 | return SliderScalarCustom(label, ImGuiDataType_Float, v, &v_min, &v_max, format, power); 117 | } 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | bool ButtonEx(const char* label, const ImVec2& size_arg, ImGuiButtonFlags flags) { 127 | ImGuiWindow* window = ImGui::GetCurrentWindow(); 128 | if (window->SkipItems) 129 | return false; 130 | 131 | ImGuiContext& g = *GImGui; 132 | const ImGuiStyle& style = g.Style; 133 | const ImGuiID id = window->GetID(label); 134 | const ImVec2 label_size = ImGui::CalcTextSize(label, NULL, true); 135 | 136 | ImVec2 pos = window->DC.CursorPos; 137 | if ((flags & ImGuiButtonFlags_AlignTextBaseLine) && style.FramePadding.y < window->DC.CurrLineTextBaseOffset) // Try to vertically align buttons that are smaller/have no padding so that text baseline matches (bit hacky, since it shouldn't be a flag) 138 | pos.y += window->DC.CurrLineTextBaseOffset - style.FramePadding.y; 139 | ImVec2 size = ImGui::CalcItemSize(size_arg, label_size.x + style.FramePadding.x * 2.0f, label_size.y + style.FramePadding.y * 2.0f); 140 | 141 | const ImRect bb(pos, pos + size); 142 | ImGui::ItemSize(size, style.FramePadding.y); 143 | if (!ImGui::ItemAdd(bb, id)) 144 | return false; 145 | 146 | if (window->DC.ItemFlags & ImGuiItemFlags_ButtonRepeat) 147 | flags |= ImGuiButtonFlags_Repeat; 148 | bool hovered, held; 149 | bool pressed = ImGui::ButtonBehavior(bb, id, &hovered, &held, flags); 150 | if (pressed) 151 | ImGui::MarkItemEdited(id); 152 | 153 | // Render 154 | const ImU32 col = ImGui::GetColorU32((held && hovered) ? ImGuiCol_ButtonActive : hovered ? ImGuiCol_ButtonHovered : ImGuiCol_Button); 155 | ImGui::RenderNavHighlight(bb, id); 156 | 157 | 158 | //bb.Max 159 | ImGui::RenderFrame(bb.Min, bb.Max, 160 | col, true, style.FrameRounding 161 | ); 162 | 163 | //window->DrawList->AddImage(user_texture_id, bb.Min, bb.Min + image_size_arg, ImVec2(0,0), ImVec2(1, 1), ImGui::GetColorU32(ImVec4(1, 1, 1, 1))); 164 | 165 | ImGui::PushStyleVar(ImGuiStyleVar_ButtonTextAlign, ImVec2(0.5f, 0.5f)); 166 | 167 | ImGui::RenderTextClipped(bb.Min + style.FramePadding, bb.Max - style.FramePadding, label, NULL, &label_size, style.ButtonTextAlign, &bb); 168 | 169 | ImGui::PopStyleVar(); 170 | // Automatically close popups 171 | //if (pressed && !(flags & ImGuiButtonFlags_DontClosePopups) && (window->Flags & ImGuiWindowFlags_Popup)) 172 | // CloseCurrentPopup(); 173 | 174 | IMGUI_TEST_ENGINE_ITEM_INFO(id, label, window->DC.LastItemStatusFlags); 175 | return pressed; 176 | } 177 | 178 | 179 | 180 | bool Button(const char* label, const ImVec2& size_arg) { 181 | return ButtonEx(label, size_arg, 0); 182 | } 183 | 184 | 185 | bool Checkbox(const char* label, bool* v) { 186 | ImGuiWindow* window = ImGui::GetCurrentWindow(); 187 | if (window->SkipItems) 188 | return false; 189 | 190 | ImGuiContext& g = *GImGui; 191 | const ImGuiStyle& style = g.Style; 192 | const ImGuiID id = window->GetID(label); 193 | const ImVec2 label_size = ImGui::CalcTextSize(label, NULL, true); 194 | 195 | const float square_sz = ImGui::GetFrameHeight(); 196 | const ImVec2 pos = window->DC.CursorPos; 197 | const ImRect total_bb(pos, pos + ImVec2(square_sz + (label_size.x > 0.0f ? style.ItemInnerSpacing.x + label_size.x : 0.0f), label_size.y + style.FramePadding.y * 2.0f)); 198 | ImGui::ItemSize(total_bb, style.FramePadding.y); 199 | if (!ImGui::ItemAdd(total_bb, id)) 200 | return false; 201 | 202 | bool hovered, held; 203 | bool pressed = ImGui::ButtonBehavior(total_bb, id, &hovered, &held); 204 | if (pressed) { 205 | *v = !(*v); 206 | ImGui::MarkItemEdited(id); 207 | } 208 | 209 | const ImRect check_bb(pos, pos + ImVec2(square_sz, square_sz)); 210 | ImGui::RenderNavHighlight(total_bb, id); 211 | ImGui::RenderFrame(check_bb.Min, check_bb.Max, ImGui::GetColorU32((held && hovered) ? ImGuiCol_FrameBgActive : hovered ? ImGuiCol_FrameBgHovered : ImGuiCol_FrameBg), true, style.FrameRounding); 212 | if (*v) { 213 | const float pad = ImMax(1.0f, (float)(int)(square_sz / 6.0f)); 214 | 215 | ImVec2 gap = ImVec2(4, 4); 216 | ImGui::RenderFrame(check_bb.Min + gap, check_bb.Max - gap, ImGui::GetColorU32(ImGuiCol_CheckMark), true, style.FrameRounding); 217 | 218 | //ImGui::RenderCheckMark(check_bb.Min + ImVec2(pad, pad), ImGui::GetColorU32((held && hovered) ? ImGuiCol_FrameBgActive : hovered ? ImGuiCol_FrameBgHovered : ImGuiCol_FrameBg), square_sz - pad * 2.0f); 219 | } 220 | 221 | if (g.LogEnabled) 222 | ImGui::LogRenderedText(&total_bb.Min, *v ? "[x]" : "[ ]"); 223 | if (label_size.x > 0.0f) 224 | ImGui::RenderText(ImVec2(check_bb.Max.x + style.ItemInnerSpacing.x, check_bb.Min.y + style.FramePadding.y), label); 225 | 226 | IMGUI_TEST_ENGINE_ITEM_INFO(id, label, window->DC.ItemFlags | ImGuiItemStatusFlags_Checkable | (*v ? ImGuiItemStatusFlags_Checked : 0)); 227 | return pressed; 228 | } 229 | 230 | 231 | 232 | 233 | 234 | } -------------------------------------------------------------------------------- /immunity-gta5/immunity-gta5.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | Debug 14 | x64 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | 16.0 23 | {05A41833-32B5-4898-AF98-6EBDAD66F1FD} 24 | Win32Proj 25 | immunitygta5 26 | 10.0.19041.0 27 | 28 | 29 | 30 | DynamicLibrary 31 | true 32 | v142 33 | Unicode 34 | 35 | 36 | DynamicLibrary 37 | false 38 | v142 39 | true 40 | Unicode 41 | 42 | 43 | DynamicLibrary 44 | true 45 | v142 46 | Unicode 47 | 48 | 49 | DynamicLibrary 50 | false 51 | v142 52 | true 53 | MultiByte 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | true 75 | 76 | 77 | true 78 | 79 | 80 | false 81 | 82 | 83 | false 84 | C:\Microsoft DirectX SDK (June 2010)\Include;C:\C++\minhook\include;C:\C++;$(IncludePath) 85 | C:\Microsoft DirectX SDK (June 2010)\Lib\x64;C:\C++\minhook\build\VC16\lib\Release;C:\C++;$(LibraryPath) 86 | 87 | 88 | 89 | Use 90 | Level3 91 | true 92 | WIN32;_DEBUG;IMMUNITYGTA5_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) 93 | true 94 | pch.h 95 | 96 | 97 | Windows 98 | true 99 | false 100 | 101 | 102 | 103 | 104 | Use 105 | Level3 106 | true 107 | _DEBUG;IMMUNITYGTA5_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) 108 | true 109 | pch.h 110 | 111 | 112 | Windows 113 | true 114 | false 115 | 116 | 117 | 118 | 119 | Use 120 | Level3 121 | true 122 | true 123 | true 124 | WIN32;NDEBUG;IMMUNITYGTA5_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) 125 | true 126 | pch.h 127 | 128 | 129 | Windows 130 | true 131 | true 132 | true 133 | false 134 | 135 | 136 | 137 | 138 | NotUsing 139 | Level3 140 | true 141 | true 142 | true 143 | NDEBUG;IMMUNITYGTA5_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) 144 | true 145 | pch.h 146 | stdcpp17 147 | false 148 | 149 | 150 | Windows 151 | true 152 | true 153 | true 154 | false 155 | libcmt.lib 156 | D3DX11.lib;Dwmapi.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | Dieses Projekt verweist auf mindestens ein NuGet-Paket, das auf diesem Computer fehlt. Verwenden Sie die Wiederherstellung von NuGet-Paketen, um die fehlenden Dateien herunterzuladen. Weitere Informationen finden Sie unter "http://go.microsoft.com/fwlink/?LinkID=322105". Die fehlende Datei ist "{0}". 210 | 211 | 212 | 213 | -------------------------------------------------------------------------------- /immunity-gta5/functions.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "imports.h" 3 | 4 | 5 | 6 | 7 | 8 | typedef DWORD(__cdecl* start_shape_test_capsule_t)(Vector3 From, Vector3 To, float radius, IntersectOptions flags, DWORD entity, int p9); 9 | start_shape_test_capsule_t start_shape_test_capsule = nullptr; 10 | 11 | typedef int(__cdecl* get_raycast_result_t)(DWORD Handle, bool* hit, Vector3* endCoords, Vector3* surfaceNormal, DWORD* entityHit); 12 | get_raycast_result_t get_raycast_result = nullptr; 13 | 14 | typedef void(__cdecl* give_weapon_delayed_t)(int32_t ped, uintptr_t hash, int ammo, bool equip_now); 15 | give_weapon_delayed_t give_weapon_delayed = nullptr; 16 | typedef int32_t(__cdecl* pointer_to_handle_t)(intptr_t pointer); 17 | pointer_to_handle_t pointer_to_handle = nullptr; 18 | 19 | typedef void(__cdecl* disable_all_controlls_t)(unsigned int index); 20 | disable_all_controlls_t disable_all_controlls; 21 | 22 | typedef bool(__cdecl* clear_ped_task_t) (int32_t ped); 23 | clear_ped_task_t clear_ped_task; 24 | typedef bool(__fastcall* clear_ped_task_immediatly_t) (int32_t ped); 25 | clear_ped_task_immediatly_t clear_ped_task_immediatly; 26 | 27 | 28 | typedef void(__fastcall* set_ped_infinite_ammo_clip_t)(int32_t ped, BOOL toggle); 29 | set_ped_infinite_ammo_clip_t set_ped_infinite_ammo_clip = nullptr; 30 | 31 | float SquareRootFloat(float number) { 32 | long i; 33 | float x, y; 34 | const float f = 1.5F; 35 | 36 | x = number * 0.5F; 37 | y = number; 38 | i = *(long*)&y; 39 | i = 0x5f3759df - (i >> 1); 40 | y = *(float*)&i; 41 | y = y * (f - (x * y * y)); 42 | y = y * (f - (x * y * y)); 43 | return number * y; 44 | } 45 | 46 | float get_distance(Vector3 to, Vector3 from) { 47 | return (SquareRootFloat( 48 | ((to.x - from.x) * (to.x - from.x)) + 49 | ((to.y - from.y) * (to.y - from.y)) + 50 | ((to.z - from.z) * (to.z - from.z)) 51 | )); 52 | } 53 | 54 | 55 | float screen_distance(float Xx, float Yy, float xX, float yY) { 56 | return SquareRootFloat((yY - Yy) * (yY - Yy) + (xX - Xx) * (xX - Xx)); 57 | } 58 | 59 | /* 60 | auto screen_distance = [](double a, double b, double c, double d) { 61 | return sqrtf(pow(c - a, 2.0) + pow(d - b, 2.0)); 62 | };*/ 63 | 64 | 65 | 66 | static auto rage_joaat = [](const char* str) -> std::int32_t { 67 | static auto to_lowercase = [](char c) -> char { 68 | return (c >= 'A' && c <= 'Z') ? c + ('a' - 'A') : c; 69 | }; 70 | 71 | std::uint32_t hash = 0; 72 | while (*str) { 73 | hash += to_lowercase(*str++); 74 | hash += (hash << 10); 75 | hash ^= (hash >> 6); 76 | } 77 | 78 | hash += (hash << 3); 79 | hash ^= (hash >> 11); 80 | hash += (hash << 15); 81 | 82 | return (signed)hash; 83 | }; 84 | 85 | 86 | 87 | Vector3 PredictMovement(Vector3 TargetPos, Vector3 TargetSpeed, float mul) { 88 | Vector3 temp_pos = TargetPos; 89 | float d = screen_distance(temp_pos.x, temp_pos.y, temp_pos.x + TargetSpeed.x, temp_pos.y + TargetSpeed.y); 90 | Vector3 normalize_target_speed(0, 0, 0); 91 | if (d > 0) { 92 | normalize_target_speed = TargetSpeed / d; 93 | temp_pos.x += (normalize_target_speed.x * mul); 94 | temp_pos.y += (normalize_target_speed.y * mul); 95 | } 96 | 97 | return temp_pos; 98 | } 99 | 100 | 101 | 102 | typedef BOOLEAN(__cdecl* WorldToScreen_t)(Vector3* WorldPos, float* x, float* y); 103 | WorldToScreen_t WorldToScreenAddr = nullptr; 104 | 105 | bool WorldToScreen(Vector3 WorldPos, ImVec2* screen) { 106 | if (IsValidPtr(WorldToScreenAddr)) { 107 | ImVec2 pos; 108 | if (static_cast(WorldToScreenAddr(&WorldPos, &pos.x, &pos.y))) { 109 | screen->x = pos.x * ImGui::GetIO().DisplaySize.x; // or Game.screen.x 110 | screen->y = pos.y * ImGui::GetIO().DisplaySize.y; // or Game.screen.y 111 | 112 | return true; 113 | } 114 | } 115 | return false; 116 | } 117 | 118 | 119 | bool isW2SValid(ImVec2 coords) { 120 | return (coords.x > 1.0f && coords.y > 1.0f); 121 | } 122 | 123 | 124 | bool WorldToScreen2(Vector3 pos, ImVec2* out) { 125 | if (!IsValidPtr(Game.viewPort)) return false; 126 | Vector3 tmp; 127 | 128 | tmp.x = (Game.viewPort->fViewMatrix[1] * pos.x) + (Game.viewPort->fViewMatrix[5] * pos.y) + (Game.viewPort->fViewMatrix[9] * pos.z) + Game.viewPort->fViewMatrix[13]; //row 2 129 | tmp.y = (Game.viewPort->fViewMatrix[2] * pos.x) + (Game.viewPort->fViewMatrix[6] * pos.y) + (Game.viewPort->fViewMatrix[10] * pos.z) + Game.viewPort->fViewMatrix[14]; //row 3 130 | tmp.z = (Game.viewPort->fViewMatrix[3] * pos.x) + (Game.viewPort->fViewMatrix[7] * pos.y) + (Game.viewPort->fViewMatrix[11] * pos.z) + Game.viewPort->fViewMatrix[15]; //row 4 131 | 132 | if (tmp.z < 0.001f) 133 | return false; 134 | 135 | tmp.z = 1.0f / tmp.z; 136 | 137 | tmp.x *= tmp.z; 138 | tmp.y *= tmp.z; 139 | 140 | int w = ImGui::GetIO().DisplaySize.x; 141 | int h = ImGui::GetIO().DisplaySize.y; 142 | 143 | out->x = ((w / 2.f) + (.5f * tmp.x * w + 1.f)); /// ScreenWidth; 144 | out->y = ((h / 2.f) - (.5f * tmp.y * h + 1.f)); /// ScreenHeight; 145 | 146 | //if (!isW2SValid(*out)) return false; 147 | 148 | return true; 149 | } 150 | 151 | uint8_t* GetBone1 = 0; 152 | Vector3 FromM128(__m128 in) { 153 | return Vector3(in.m128_f32[0], in.m128_f32[1], in.m128_f32[2]); 154 | } 155 | 156 | 157 | 158 | 159 | 160 | 161 | typedef struct D3DXVECTOR4 { 162 | FLOAT x; 163 | FLOAT y; 164 | FLOAT z; 165 | FLOAT w; 166 | } D3DXVECTOR4; 167 | 168 | 169 | 170 | typedef void* (__fastcall* GetBoneFromMask2)(CObject* pThis, D3DXVECTOR4& vBonePos, WORD dwMask); 171 | GetBoneFromMask2 GetBoneFunc; 172 | Vector3 GetBonePosition(CObject* pThis, const int32_t wMask) { 173 | try { 174 | D3DXVECTOR4 tempVec4; 175 | GetBoneFunc(pThis, tempVec4, wMask); 176 | 177 | return Vector3(tempVec4.x, tempVec4.y, tempVec4.z); 178 | } catch (const std::exception& e) { 179 | 180 | printf("ERror BonePos %s\n", e.what()); 181 | } 182 | return Vector3(); 183 | } 184 | 185 | Vector3 GetBonePosition(CObject* pThis, Bones bone) { 186 | return GetBonePosition(pThis, (WORD)bone); 187 | } 188 | 189 | 190 | ImVec2 GetBoneScreenPosition(CObject* pThis, Bones bone) { 191 | ImVec2 bone2d; 192 | Vector3 bone3d = GetBonePosition(pThis, bone); 193 | if (WorldToScreen(bone3d, &bone2d)) { 194 | return bone2d; 195 | } 196 | return bone2d; 197 | } 198 | 199 | 200 | 201 | 202 | int GetPedDrawableVariation(CObject* ped, int group) { 203 | int res = -1; 204 | if (group > -1 && group < 13) { 205 | if (ped != nullptr && ped->pCPedStyle->propIndex[group] != 255) 206 | res = (int)ped->pCPedStyle->propIndex[group]; 207 | } 208 | return res; 209 | } 210 | 211 | int GetPedTextureVariation(CObject* ped, int group) { 212 | int res = -1; 213 | if (group > -1 && group < 13) { 214 | if (ped != nullptr && ped->pCPedStyle->textureIndex[group] != 255) 215 | res = (int)ped->pCPedStyle->textureIndex[group]; 216 | } 217 | return res; 218 | } 219 | 220 | int GetPedPaletteVariation(CObject* ped, int group) { 221 | int res = -1; 222 | if (group > -1 && group < 13) { 223 | if (ped != nullptr && ped->pCPedStyle->paletteIndex[group] != 255) 224 | res = (int)ped->pCPedStyle->paletteIndex[group]; 225 | } 226 | return res; 227 | } 228 | 229 | string GetPedComponentHash(CObject* ped) { 230 | string r = "\0"; 231 | 232 | for (int i = 0; i < 13; i++) { 233 | int c = GetPedTextureVariation(ped, i); 234 | if (c > -1) { 235 | r += to_string(c); 236 | } 237 | } 238 | for (int i = 0; i < 13; i++) { 239 | int c = GetPedPaletteVariation(ped, i); 240 | if (c > -1) { 241 | r += to_string(c); 242 | } 243 | } 244 | return r; 245 | } 246 | 247 | //========================================================================================================================== 248 | // Game Thread 249 | 250 | 251 | 252 | typedef DWORD(__cdecl* tSTART_SHAPE_TEST_CAPSULE)(PVector3 From, PVector3 To, float radius, IntersectOptions flags, DWORD entity, int p9); 253 | tSTART_SHAPE_TEST_CAPSULE _START_SHAPE_TEST_CAPSULE = nullptr; 254 | 255 | typedef int(__cdecl* t_GET_RAYCAST_RESULT)(DWORD Handle, bool* hit, PVector3* endCoords, PVector3* surfaceNormal, DWORD* entityHit); 256 | static t_GET_RAYCAST_RESULT _GET_RAYCAST_RESULT = nullptr; 257 | 258 | // game hooks 259 | typedef bool(__stdcall* Is_Dlc_Present_t) (std::uint64_t hash, bool a2); 260 | Is_Dlc_Present_t pIs_Dlc_Present = NULL; 261 | Is_Dlc_Present_t Is_Dlc_Present; 262 | 263 | typedef BOOL(__stdcall* sub_7FF766264E90_t) (DWORD hash, int* out, int unk0); 264 | sub_7FF766264E90_t sub_7FF766264E90 = NULL; 265 | sub_7FF766264E90_t psub_7FF766264E90 = NULL; 266 | 267 | 268 | 269 | 270 | 271 | typedef __int64(__stdcall* get_rendering_cam_t) (); 272 | get_rendering_cam_t get_rendering_cam = NULL; 273 | get_rendering_cam_t pget_rendering_cam = NULL; 274 | 275 | 276 | 277 | typedef __int64(__stdcall* stat_get_int_t) (__int64 a1, __int64 a2); 278 | stat_get_int_t stat_get_int = NULL; 279 | stat_get_int_t pstat_get_int = NULL; 280 | 281 | 282 | typedef bool(__stdcall* does_cam_exists_t) (__int64 a1); 283 | does_cam_exists_t does_cam_exists = NULL; 284 | does_cam_exists_t pdoes_cam_exists = NULL; 285 | 286 | 287 | typedef bool(__stdcall* is_cam_active_t) (__int64 a1); 288 | is_cam_active_t is_cam_active = NULL; 289 | is_cam_active_t pis_cam_active = NULL; 290 | 291 | typedef bool(__stdcall* is_aim_cam_active_t) (); 292 | is_aim_cam_active_t is_aim_cam_active = NULL; 293 | is_aim_cam_active_t pis_aim_cam_active = NULL; 294 | 295 | 296 | typedef float(__stdcall* get_gameplay_cam_zoom_t) (); 297 | get_gameplay_cam_zoom_t get_gameplay_cam_zoom = NULL; 298 | get_gameplay_cam_zoom_t pget_gameplay_cam_zoom = NULL; 299 | 300 | 301 | 302 | //void* HandleEventWrap(void* group, rage::fwEvent* event) { 303 | 304 | typedef void* (__stdcall* handle_event_t) (void* group, void* eventData); 305 | handle_event_t o_handle_event; 306 | handle_event_t handle_event; 307 | void* hk_handle_event(void* group, void* eventData) { 308 | const char* eventName = typeid(eventData).name(); 309 | cout << "eventName ->" << eventName << endl; 310 | 311 | return o_handle_event(group, eventData); 312 | } 313 | 314 | typedef bool (__stdcall* get_event_data_t) (std::int32_t eventGroup, std::int32_t eventIndex, std::int64_t* args, std::uint32_t argCount); 315 | get_event_data_t get_event_data; 316 | get_event_data_t o_get_event_data; 317 | 318 | bool hk_get_event_data(std::int32_t eventGroup, std::int32_t eventIndex, std::int64_t* args, std::uint32_t argCount) { 319 | 320 | cout << "eventGroup ->" << eventGroup << endl; 321 | cout << "eventIndex ->" << eventIndex << endl; 322 | cout << "argCount ->" << argCount << endl; 323 | 324 | return o_get_event_data(eventGroup, eventIndex, args, argCount); 325 | } 326 | 327 | 328 | 329 | void onGameTick() { 330 | //cout << "ontick" << endl; 331 | if (Game.running) { 332 | static uint64_t last = 0; 333 | uint64_t cur = *(uint64_t*)(FrameCount); 334 | if (last != cur) { 335 | last = cur; 336 | Game.tick(); 337 | } 338 | } 339 | } 340 | // stat_get_int 341 | float __stdcall hk_get_gameplay_cam_zoom() { 342 | cout << "hk_get_gameplay_cam_zoom" << endl; 343 | if (Game.running) { 344 | onGameTick(); 345 | } 346 | return pget_gameplay_cam_zoom(); 347 | } 348 | 349 | 350 | // stat_get_int 351 | bool __stdcall hk_stat_get_int(__int64 a1, __int64 a2) { 352 | cout << "stat_get_int" << endl; 353 | if (Game.running) { 354 | onGameTick(); 355 | } 356 | return pstat_get_int(a1, a2); 357 | } 358 | // does_cam_exists 359 | bool __fastcall hk_is_aim_cam_active() { 360 | cout << "hk_is_aim_cam_active" << endl; 361 | if (Game.running) { 362 | onGameTick(); 363 | } 364 | return pis_aim_cam_active(); 365 | } 366 | 367 | 368 | 369 | // does_cam_exists 370 | bool __fastcall hk_does_cam_exists(__int64 a1) { 371 | if (Game.running) { 372 | onGameTick(); 373 | } 374 | return pdoes_cam_exists(a1); 375 | } 376 | 377 | 378 | 379 | bool __stdcall hookIs_Dlc_Present(std::uint64_t hash, bool a2) { 380 | //cout << "hookIs_Dlc_Present" << endl; 381 | if (Game.running) { 382 | onGameTick(); 383 | } 384 | return pIs_Dlc_Present(hash, a2); 385 | } 386 | 387 | 388 | 389 | 390 | //========================================================================================================================== 391 | 392 | -------------------------------------------------------------------------------- /immunity-gta5/config.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "imports.h" 3 | #include "../includes/ini.h" 4 | #include 5 | namespace fs = std::filesystem; 6 | 7 | // Config Manager 8 | 9 | 10 | namespace config { 11 | 12 | mINI::INIFile settingsFile("ragemp.ini"); 13 | mINI::INIStructure ini; 14 | 15 | map config_list; 16 | 17 | string config_location = GetFolderLocation(CSIDL_LOCAL_APPDATA) + "/immunity/gta5/"; 18 | string active_config = config_location + "/active.ini"; 19 | 20 | 21 | void setup_folders() { 22 | if(fs::exists(config_location)) { 23 | settingsFile = mINI::INIFile(active_config); 24 | logs::add("config path " + active_config); 25 | } else { 26 | fs::create_directories(config_location); 27 | settingsFile = mINI::INIFile(active_config); 28 | logs::add("could not find config path, creating"); 29 | } 30 | } 31 | 32 | 33 | 34 | 35 | bool exists(string category, string key) { 36 | bool hasSection = ini.has(category); 37 | if(hasSection) { 38 | bool hasKey = ini[category].has(key); 39 | if(hasKey) { 40 | return true; 41 | } 42 | } 43 | return false; 44 | } 45 | //mape; 46 | 47 | map, map> string_cache; 48 | map get(string category, string key, map defaultValue) { 49 | map temp; 50 | try { 51 | json temp_map; 52 | 53 | 54 | if(string_cache[make_pair(category, key)].size()) { 55 | return string_cache[make_pair(category, key)]; 56 | } 57 | 58 | if(exists(category, key)) { 59 | string k = ini.get(category).get(key); 60 | if(k != "") { 61 | temp_map = json::parse(k); 62 | } 63 | } 64 | 65 | for(auto it = temp_map.begin(); it != temp_map.end(); ++it) { 66 | string first = it.key(); 67 | string second = it.value(); 68 | temp.insert(make_pair(first, second)); 69 | } 70 | 71 | 72 | string_cache[make_pair(category, key)] = temp; 73 | 74 | return temp; 75 | } catch(const std::exception& e) { 76 | printf("error %s", e.what()); 77 | } 78 | 79 | return temp; 80 | } 81 | bool set(string category, string key, map newValue) { 82 | json temp_data; 83 | map ::iterator it = newValue.begin(); 84 | while(it != newValue.end()) { 85 | string hash = it->first; 86 | string name = it->second; 87 | temp_data[hash] = name; 88 | it++; 89 | } 90 | 91 | string_cache[make_pair(category, key)] = newValue; 92 | 93 | ini[category][key] = temp_data.dump(); 94 | settingsFile.generate(ini, true); 95 | return true; 96 | } 97 | 98 | bool update(map newValue, string category, string key, map defaultValue) { 99 | if(newValue != config::get(category, key, defaultValue)) { 100 | return config::set(category, key, newValue); 101 | } 102 | return false; 103 | } 104 | 105 | map, map> dword_cache; 106 | map get(string category, string key, map defaultValue) { 107 | map temp; 108 | try { 109 | json temp_map; 110 | 111 | 112 | if(dword_cache[make_pair(category, key)].size()) { 113 | return dword_cache[make_pair(category, key)]; 114 | } 115 | 116 | if(exists(category, key)) { 117 | temp_map = json::parse(ini.get(category).get(key)); 118 | } 119 | 120 | for(auto it = temp_map.begin(); it != temp_map.end(); ++it) { 121 | int64_t hash = stoll(it.key().c_str()); 122 | string name = it.value(); 123 | temp.insert(make_pair(hash, name)); 124 | } 125 | 126 | dword_cache[make_pair(category, key)] = temp; 127 | 128 | return temp; 129 | } catch(const std::exception& e) { 130 | printf("error %s", e.what()); 131 | } 132 | return temp; 133 | } 134 | bool set(string category, string key, map newValue) { 135 | json temp_data; 136 | map ::iterator it = newValue.begin(); 137 | while(it != newValue.end()) { 138 | int64_t hash = it->first; 139 | string name = it->second; 140 | temp_data[std::to_string(hash)] = name.c_str(); 141 | it++; 142 | } 143 | dword_cache[make_pair(category, key)] = newValue; 144 | 145 | ini[category][key] = temp_data.dump(); 146 | settingsFile.generate(ini, true); 147 | return true; 148 | } 149 | 150 | 151 | bool update(map newValue, string category, string key, map defaultValue) { 152 | if(newValue != config::get(category, key, defaultValue)) { 153 | return config::set(category, key, newValue); 154 | } 155 | return false; 156 | } 157 | 158 | 159 | namespace fast { 160 | double pow10(int n) { 161 | double ret = 1.0; 162 | double r = 10.0; 163 | if(n < 0) { 164 | n = -n; 165 | r = 0.1; 166 | } 167 | 168 | while(n) { 169 | if(n & 1) { 170 | ret *= r; 171 | } 172 | r *= r; 173 | n >>= 1; 174 | } 175 | return ret; 176 | } 177 | 178 | int atoi(const char* str) { 179 | int val = 0; 180 | while(*str) { 181 | val = val * 10 + (*str++ - '0'); 182 | } 183 | return val; 184 | } 185 | 186 | double atof(const char* num) { 187 | if(!num || !*num) { 188 | return 0; 189 | } 190 | 191 | int sign = 1; 192 | double integerPart = 0.0; 193 | double fractionPart = 0.0; 194 | bool hasFraction = false; 195 | bool hasExpo = false; 196 | 197 | // Take care of +/- sign 198 | if(*num == '-') { 199 | ++num; 200 | sign = -1; 201 | } else if(*num == '+') { 202 | ++num; 203 | } 204 | 205 | while(*num != '\0') { 206 | if(*num >= '0' && *num <= '9') { 207 | integerPart = integerPart * 10 + (*num - '0'); 208 | } else if(*num == '.') { 209 | hasFraction = true; 210 | ++num; 211 | break; 212 | } else if(*num == 'e') { 213 | hasExpo = true; 214 | ++num; 215 | break; 216 | } else { 217 | return sign * integerPart; 218 | } 219 | ++num; 220 | } 221 | 222 | if(hasFraction) { 223 | double fractionExpo = 0.1; 224 | 225 | while(*num != '\0') { 226 | if(*num >= '0' && *num <= '9') { 227 | fractionPart += fractionExpo * (*num - '0'); 228 | fractionExpo *= 0.1; 229 | } else if(*num == 'e') { 230 | hasExpo = true; 231 | ++num; 232 | break; 233 | } else { 234 | return sign * (integerPart + fractionPart); 235 | } 236 | ++num; 237 | } 238 | } 239 | 240 | // parsing exponet part 241 | double expPart = 1.0; 242 | if(*num != '\0' && hasExpo) { 243 | int expSign = 1; 244 | if(*num == '-') { 245 | expSign = -1; 246 | ++num; 247 | } else if(*num == '+') { 248 | ++num; 249 | } 250 | 251 | int e = 0; 252 | while(*num != '\0' && *num >= '0' && *num <= '9') { 253 | e = e * 10 + *num - '0'; 254 | ++num; 255 | } 256 | 257 | expPart = pow10(expSign * e); 258 | } 259 | 260 | return sign * (integerPart + fractionPart) * expPart; 261 | } 262 | } 263 | 264 | 265 | //Vector3 266 | map, map> vector3_cache; 267 | 268 | 269 | map get(string category, string key, map defaultValue) { 270 | map temp; 271 | try { 272 | json temp_map; 273 | if(vector3_cache[make_pair(category, key)].size()) { 274 | return vector3_cache[make_pair(category, key)]; 275 | } 276 | if(exists(category, key)) { 277 | temp_map = json::parse(ini.get(category).get(key)); 278 | } 279 | for(auto it = temp_map.begin(); it != temp_map.end(); ++it) { 280 | string name = it.key().c_str(); 281 | 282 | 283 | string position_data = it.value(); 284 | 285 | 286 | float x = fast::atof(position_data.substr(0, position_data.find("|")).c_str()); // token is "scott" 287 | position_data.erase(0, position_data.find("|") + string("|").length()); 288 | float y = fast::atof(position_data.substr(0, position_data.find("|")).c_str()); 289 | position_data.erase(0, position_data.find("|") + string("|").length()); 290 | float z = fast::atof(position_data.substr(0, position_data.find("|")).c_str()); 291 | 292 | auto v = Vector3(x, y, z); 293 | temp.insert(make_pair(name, v)); 294 | } 295 | 296 | vector3_cache[make_pair(category, key)] = temp; 297 | 298 | return temp; 299 | } catch(const std::exception& e) { 300 | printf("error %s", e.what()); 301 | } 302 | return temp; 303 | } 304 | 305 | bool set(string category, string key, map newValue) { 306 | json temp_data; 307 | map ::iterator it = newValue.begin(); 308 | while(it != newValue.end()) { 309 | string name = it->first; 310 | Vector3 vec = it->second; 311 | 312 | temp_data[name] = to_string(vec.x) + "|" + to_string(vec.y) + "|" + to_string(vec.z); 313 | it++; 314 | } 315 | vector3_cache[make_pair(category, key)] = newValue; 316 | 317 | ini[category][key] = temp_data.dump(); 318 | settingsFile.generate(ini, true); 319 | return true; 320 | } 321 | 322 | 323 | bool update(map newValue, string category, string key, map defaultValue) { 324 | if(newValue != config::get(category, key, defaultValue)) { 325 | return config::set(category, key, newValue); 326 | } 327 | return false; 328 | } 329 | 330 | 331 | 332 | 333 | 334 | map, string> normal_cache; 335 | 336 | bool set(string category, string name, string setting) { 337 | ini[category][name] = setting; 338 | 339 | 340 | 341 | 342 | 343 | normal_cache[make_pair(category, name)] = setting; 344 | 345 | settingsFile.generate(ini, true); 346 | return true; 347 | } 348 | 349 | 350 | float get(string category, string key, float defaultVal) { 351 | 352 | if(normal_cache[make_pair(category, key)].length()) { 353 | return fast::atof((normal_cache[make_pair(category, key)]).c_str()); 354 | } 355 | 356 | if(exists(category, key)) { 357 | 358 | normal_cache[make_pair(category, key)] = ini.get(category).get(key).c_str(); 359 | 360 | 361 | return fast::atof((normal_cache[make_pair(category, key)]).c_str()); 362 | } 363 | 364 | return defaultVal; 365 | } 366 | int get(string category, string key, int defaultVal) { 367 | if(normal_cache[make_pair(category, key)].length()) { 368 | return fast::atoi((normal_cache[make_pair(category, key)]).c_str()); 369 | } 370 | if(exists(category, key)) { 371 | normal_cache[make_pair(category, key)] = ini.get(category).get(key).c_str(); 372 | 373 | 374 | return fast::atoi((normal_cache[make_pair(category, key)]).c_str()); 375 | } 376 | return defaultVal; 377 | } 378 | string get(string category, string key, string defaultVal) { 379 | if(normal_cache[make_pair(category, key)].length()) { 380 | return (normal_cache[make_pair(category, key)]); 381 | } 382 | if(exists(category, key)) { 383 | normal_cache[make_pair(category, key)] = ini.get(category).get(key).c_str(); 384 | 385 | return normal_cache[make_pair(category, key)]; 386 | } 387 | return defaultVal; 388 | } 389 | 390 | 391 | bool update(float newValue, string category, string key, float defaultVal) { 392 | if(newValue != config::get(category, key, defaultVal)) { 393 | return config::set(category, key, to_string(newValue)); 394 | } 395 | return false; 396 | } 397 | bool update(int newValue, string category, string key, int defaultVal) { 398 | if(newValue != config::get(category, key, defaultVal)) { 399 | return config::set(category, key, to_string(newValue)); 400 | } 401 | return false; 402 | } 403 | bool update(string newValue, string category, string key, string defaultVal) { 404 | if(newValue != config::get(category, key, defaultVal)) { 405 | return config::set(category, key, newValue); 406 | } 407 | return false; 408 | } 409 | 410 | void list_configs() { 411 | config_list.clear(); 412 | 413 | 414 | for(const auto& entry : fs::directory_iterator(config_location)) { 415 | config_list.insert(make_pair(entry.path().filename().string(), entry.path().string())); 416 | } 417 | } 418 | void refresh() { 419 | normal_cache.clear(); 420 | dword_cache.clear(); 421 | string_cache.clear(); 422 | } 423 | void load_config(string path) { 424 | 425 | settingsFile = mINI::INIFile(path); 426 | settingsFile.read(ini); 427 | active_config = path; 428 | logs::add("loaded config" + active_config); 429 | 430 | refresh(); 431 | } 432 | 433 | void new_config(string config_name) { 434 | 435 | settingsFile = mINI::INIFile(config_location + "/" + config_name + ".ini"); 436 | settingsFile.read(ini); 437 | active_config = config_location + "/" + config_name + ".ini"; 438 | logs::add("created new config " + active_config); 439 | 440 | refresh(); 441 | list_configs(); 442 | } 443 | void rename_config(string new_config_name, string old_config_name_path) { 444 | 445 | string new_config_name_path = config_location + "/" + new_config_name + ".ini"; 446 | 447 | int result = std::rename(old_config_name_path.c_str(), new_config_name_path.c_str()); 448 | if(result == 0) { 449 | 450 | settingsFile = mINI::INIFile(new_config_name_path); 451 | settingsFile.read(ini); 452 | active_config = new_config_name_path; 453 | logs::add("renamed config" + old_config_name_path + " -> " + new_config_name_path); 454 | } 455 | 456 | refresh(); 457 | list_configs(); 458 | } 459 | 460 | bool load() { 461 | setup_folders(); 462 | Sleep(10); 463 | list_configs(); 464 | logs::add("loaded config" + active_config); 465 | settingsFile.read(ini); 466 | 467 | 468 | 469 | 470 | 471 | 472 | 473 | refresh(); 474 | return true; 475 | } 476 | 477 | 478 | 479 | } -------------------------------------------------------------------------------- /immunity-gta5/features/aimbot.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "imports.h" 3 | 4 | 5 | namespace game { 6 | extern vector> ped_list; 7 | 8 | extern bool isValidPlayer(DWORD hash, CObject* player); 9 | } 10 | 11 | 12 | namespace aimbot { 13 | CObject* current_target; 14 | DataPed current_target_data; 15 | static Vector3 lastTargetVector = Vector3(0, 0, 0); 16 | static auto targetTimeout = std::chrono::high_resolution_clock::now(); 17 | static float aimTargetDist = 99999.0f; 18 | static Vector3 target_aim_angle; 19 | 20 | 21 | struct vehicleState { 22 | bool state; 23 | uint64_t ticksSinceChange; 24 | }; 25 | vehicleState vehicleAimbot; 26 | 27 | Vector3 get_aimbone_complex(Vector3 current, DataPed data) { 28 | Vector3 aim = current; 29 | PlayerBones bones = data.bones; 30 | Vector3 bone_positions[] = { 31 | bones.HEAD, 32 | bones.NECK, 33 | bones.RIGHT_HAND, 34 | bones.RIGHT_FOREARM, 35 | bones.RIGHT_UPPER_ARM, 36 | bones.RIGHT_CLAVICLE, 37 | bones.LEFT_HAND, 38 | bones.LEFT_FOREARM, 39 | bones.LEFT_UPPER_ARM, 40 | bones.LEFT_CLAVICLE, 41 | bones.PELVIS, 42 | bones.SPINE_ROOT, 43 | bones.SPINE0, 44 | bones.SPINE1, 45 | bones.SPINE2, 46 | bones.SPINE3, 47 | bones.RIGHT_TOE, 48 | bones.RIGHT_FOOT, 49 | bones.RIGHT_CALF, 50 | bones.RIGHT_THIGH, 51 | bones.LEFT_TOE, 52 | bones.LEFT_FOOT, 53 | bones.LEFT_CALF, 54 | bones.LEFT_THIGH 55 | }; 56 | float closest_distance = 999.f; 57 | int arrSize = sizeof(bone_positions) / sizeof(bone_positions[0]); 58 | 59 | 60 | for (size_t i = 0; i < arrSize; i++) { 61 | ImVec2 screen_point; 62 | if (!WorldToScreen(bone_positions[i], &screen_point)) continue; 63 | float dist = screen_distance(Game.screen.x / 2, Game.screen.y / 2, screen_point.x, screen_point.y); 64 | if (closest_distance > dist) { 65 | closest_distance = dist; 66 | aim = bone_positions[i]; 67 | } 68 | } 69 | 70 | 71 | return aim; 72 | } 73 | 74 | void get_new_target(CPlayerAngles* cam) { 75 | bool target_accquired = false; 76 | if (IsValidPtr(cam) && IsValidPtr(local.player)) { 77 | Vector3 CrosshairPos = cam->m_cam_pos; 78 | //float last_closest_dist = 9999.f; 79 | CObject* closest = nullptr; 80 | DataPed closest_data = {0}; 81 | 82 | for (pair& entity : game::ped_list) { 83 | CObject* ped = entity.first; 84 | DataPed data = entity.second; 85 | if (IsValidPtr(ped)) { 86 | if (local.player == ped) continue; 87 | if (ped->HP <= 0) continue; 88 | if (get_distance(local.player->fPosition, ped->fPosition) > config::get("hack", "max_range", 1000.f)) continue; 89 | DWORD hash = ped->ModelInfo()->GetHash(); 90 | if (!game::isValidPlayer(hash, ped)) continue; 91 | 92 | 93 | //Vector3 aimpos = GetBonePosition(ped, HEAD); 94 | 95 | Vector3 aimpos = config::get("aimbot", "aim_bone", 0) == 0 ? data.bones.HEAD : config::get("aimbot", "aim_bone", 0) == 1 ? data.bones.NECK : data.bones.SPINE2;//GetBonePosition(current_target, AssistBone == 0 ? BONETAG_HEAD : AssistBone == 1 ? BONETAG_NECK : BONETAG_STOMACH); // GetBonePosition1 96 | 97 | if (config::get("aimbot", "aim_bone", 0) == 3) { 98 | aimpos = get_aimbone_complex(aimpos, data); 99 | } 100 | 101 | //config::get("aimbot", "only_visible", 0) 102 | 103 | if (!data.visible && config::get("aimbot", "only_visible", 0)) continue; 104 | 105 | if (data.group.ally) continue; 106 | if ((data.group.inGroup == false) && config::get("aimbot", "aim_only_groups", 0) && config::get("aimbot", "group_check", 0)) continue; 107 | 108 | ImVec2 aim2d; 109 | if (!WorldToScreen2(aimpos, &aim2d)) continue; 110 | 111 | 112 | float Distance2d = screen_distance(Game.screen.x / 2, Game.screen.y / 2, aim2d.x, aim2d.y); 113 | 114 | if ( 115 | (Distance2d > config::get("aimbot", "aim_stop_radius", 0.f)) && 116 | (config::get("aimbot", "aim_radius", 50.f) > Distance2d) 117 | ) { 118 | if ((aimTargetDist > Distance2d) || (current_target == ped)) { 119 | aimTargetDist = Distance2d; 120 | target_accquired = true; 121 | closest = ped; 122 | closest_data = data; 123 | } 124 | } 125 | 126 | } 127 | } 128 | 129 | if (closest) { 130 | auto now = std::chrono::high_resolution_clock::now(); 131 | auto dur = std::chrono::duration_cast(now - targetTimeout).count(); 132 | 133 | if (closest != current_target) { 134 | if (dur > config::get("aimbot", "target_timeout", 0.f)) { 135 | //cout << "new targt " << dur << endl; 136 | current_target = closest; 137 | current_target_data = closest_data; 138 | targetTimeout = std::chrono::high_resolution_clock::now(); 139 | 140 | 141 | return; 142 | } 143 | } 144 | if (current_target == nullptr) { 145 | if (dur > config::get("aimbot", "target_timeout", 0.f)) { 146 | //cout << "new targt " << dur << endl; 147 | current_target = closest; 148 | current_target_data = closest_data; 149 | targetTimeout = std::chrono::high_resolution_clock::now(); 150 | return; 151 | } 152 | } 153 | } 154 | 155 | 156 | } 157 | if (!target_accquired) { 158 | current_target = nullptr; 159 | aimTargetDist = 9999.f; 160 | target_aim_angle = {0}; 161 | } 162 | } 163 | 164 | float RandomFloat(float a, float b) { 165 | float random = ((float)rand()) / (float)RAND_MAX; 166 | float diff = b - a; 167 | float r = random * diff; 168 | return a + r; 169 | } 170 | 171 | void do_silent_aim() { 172 | if (target_aim_angle.x != 0 && target_aim_angle.y != 0 && target_aim_angle.z != 0) { 173 | if (IsValidPtr(local.player)) { 174 | native::player::disable_player_firing(native::player::get_player_index(), true); 175 | if (native::controls::is_disabled_control_pressed(0, 24) || config::get("aimbot", "silent_aim_auto", 0)) { 176 | auto player = native::player::get_player_ped(-1); 177 | if (native::ped::is_ped_reloading(player)) return; 178 | 179 | native::ped::set_ped_shoots_at_coord(player, target_aim_angle.x, target_aim_angle.y, target_aim_angle.z, false); 180 | 181 | } 182 | } 183 | } 184 | } 185 | 186 | void setViewAnglesFix(Vector3 targetAngle) { 187 | 188 | 189 | } 190 | 191 | void tick() { 192 | float max_aim_radius = config::get("aimbot", "aim_radius", 50.f); 193 | float aim_stop_radius = config::get("aimbot", "aim_stop_radius", 50.f); 194 | float threshold = 0.5f / config::get("aimbot", "aim_strength", 500.f); 195 | CPlayerAngles* cam = Game.getCam(); 196 | 197 | if (!config::get("aimbot", "enable", 0)) return; 198 | if (IsValidPtr(cam) && IsValidPtr(local.player)) { 199 | if ( 200 | (GetAsyncKeyState(config::get("aimbot", "aim_key", 0)) & 0x8000) || 201 | (config::get("aimbot", "aim_mode", 0) == 3) 202 | ) { 203 | 204 | if ((local.player->IsInVehicle() == true) && !((config::get("aimbot", "aim_mode", 0) == 3))) return; 205 | 206 | 207 | CWeaponManager* wep = local.player->weapon(); 208 | if (IsValidPtr(wep)) { 209 | if (IsValidPtr(wep->_WeaponInfo)) { 210 | auto str = wep->_WeaponInfo->GetSzWeaponName(); 211 | string lstr(str, str + strlen(str)); 212 | if (lstr == "UNARMED") return; 213 | } 214 | } 215 | auto old_target = current_target; 216 | get_new_target(cam); 217 | 218 | if (IsValidPtr(current_target)) { 219 | //cout << "current_target" << endl; 220 | if (current_target != old_target) return; 221 | if (get_distance(local.player->fPosition, current_target->fPosition) > config::get("hack", "max_range", 1000.f)) return; 222 | 223 | //int b = config::get("aimbot", "aim_bone", 0) == 0 ? 0 : config::get("aimbot", "aim_bone", 0) == 1 ? 7 : 8; 224 | //Vector3 aim3d = current_target->get_bone(b);//GetBonePosition(current_target, AssistBone == 0 ? BONETAG_HEAD : AssistBone == 1 ? BONETAG_NECK : BONETAG_STOMACH); // GetBonePosition1 225 | 226 | //Vector3 aim3d = config::get("aimbot", "aim_bone", 0) == 0 ? data.bones.HEAD : config::get("aimbot", "aim_bone", 0) == 1 ? data.bones.NECK : data.bones.SPINE0; 227 | 228 | 229 | 230 | auto match = std::find_if(game::ped_list.begin(), game::ped_list.end(), [](const pair& v) {return v.first == current_target; }); 231 | if (match == game::ped_list.end()) return; 232 | int index = std::distance(game::ped_list.begin(), match); 233 | 234 | DataPed data = game::ped_list[index].second; 235 | Vector3 aim3d = config::get("aimbot", "aim_bone", 0) == 0 ? data.bones.HEAD : config::get("aimbot", "aim_bone", 0) == 1 ? data.bones.NECK : data.bones.SPINE2; 236 | if (config::get("aimbot", "aim_bone", 0) == 3) { 237 | aim3d = get_aimbone_complex(aim3d, data); 238 | } 239 | //current_target_data 240 | //} 241 | 242 | 243 | 244 | ImVec2 aim2d; 245 | if (!WorldToScreen(aim3d, &aim2d)) return; 246 | float Distance2d = screen_distance(Game.screen.x / 2, Game.screen.y / 2, aim2d.x, aim2d.y); 247 | if ( 248 | (Distance2d > config::get("aimbot", "aim_stop_radius", 0.f)) && 249 | (config::get("aimbot", "aim_radius", 50.f) > Distance2d) 250 | ) { 251 | 252 | Vector3 Crosshair3D = cam->m_cam_pos; 253 | if (config::get("aimbot", "aim_movement_prediction", 0)) { 254 | Vector3 EnemySpeed = current_target->v3Velocity; 255 | if (current_target->IsInVehicle()) { 256 | CVehicle* veh = current_target->vehicle(); 257 | if (IsValidPtr(veh)) { 258 | EnemySpeed = veh->v3Velocity; 259 | } 260 | } 261 | aim3d = PredictMovement(aim3d, EnemySpeed, config::get("aimbot", "aim_movement_prediction_distance", 0.f)); 262 | 263 | if (local.player->IsInVehicle()) { 264 | CVehicle* veh = local.player->vehicle(); 265 | if (IsValidPtr(veh)) { 266 | Crosshair3D = PredictMovement(Crosshair3D, veh->v3Velocity, 1.f); 267 | //Crosshair3D += veh->v3Velocity; 268 | } 269 | } 270 | } 271 | 272 | 273 | 274 | if (config::get("aimbot", "aim_offset", 0)) { 275 | lastTargetVector = Vector3(0, 0, 0); 276 | if ((old_target != current_target)) { 277 | // reset random vector cuz we renew it anyways 278 | 279 | if (config::get("aimbot", "aim_offset_range", 0)) { 280 | // if EnableAimOffsetRandomRange use random offset between x and y 281 | lastTargetVector.x = RandomFloat(config::get("aimbot", "aim_target_offset_range_x_min", 0.f), config::get("aimbot", "aim_target_offset_range_x_max", 0.f)); 282 | lastTargetVector.y = RandomFloat(config::get("aimbot", "aim_target_offset_range_y_min", 0.f), config::get("aimbot", "aim_target_offset_range_y_max", 0.f)); 283 | lastTargetVector.z = RandomFloat(config::get("aimbot", "aim_target_offset_range_z_min", 0.f), config::get("aimbot", "aim_target_offset_range_z_max", 0.f)); 284 | } 285 | } 286 | 287 | if (config::get("aimbot", "aim_offset_always_renew", 0)) { 288 | if (config::get("aimbot", "aim_offset_range", 0)) { 289 | lastTargetVector.x = RandomFloat(config::get("aimbot", "aim_target_offset_range_x_min", 0.f), config::get("aimbot", "aim_target_offset_range_x_max", 0.f)); 290 | lastTargetVector.y = RandomFloat(config::get("aimbot", "aim_target_offset_range_y_min", 0.f), config::get("aimbot", "aim_target_offset_range_y_max", 0.f)); 291 | lastTargetVector.z = RandomFloat(config::get("aimbot", "aim_target_offset_range_z_min", 0.f), config::get("aimbot", "aim_target_offset_range_z_max", 0.f)); 292 | } 293 | } 294 | 295 | 296 | if (!config::get("aimbot", "aim_offset_range", 0) && !config::get("aimbot", "aim_offset_always_renew", 0)) { 297 | lastTargetVector.x = config::get("aimbot", "aim_target_offset_static_x", 0.f); 298 | lastTargetVector.y = config::get("aimbot", "aim_target_offset_static_y", 0.f); 299 | lastTargetVector.z = config::get("aimbot", "aim_target_offset_static_z", 0.f); 300 | } 301 | 302 | aim3d += lastTargetVector; 303 | } 304 | 305 | //Vector3 Crosshair3D = cam->m_cam_pos2; 306 | 307 | float dist = get_distance(Crosshair3D, current_target->fPosition); 308 | 309 | Vector3 Out((aim3d.x - Crosshair3D.x) / dist, (aim3d.y - Crosshair3D.y) / dist, (aim3d.z - Crosshair3D.z) / dist); 310 | Vector3 viewAngles = cam->m_tps_angles; 311 | //Vector3 viewAngles = cam->m_fps_angles; 312 | 313 | 314 | if (config::get("aimbot", "aim_mode", 0) > 0) { 315 | Vector3 delta = Out - cam->m_tps_angles; 316 | float newX = 0;//ImLerp(viewAngles.x, Out.x, 1 / 1000.f * config::get("aimbot", "aim_strength", 500.f)); 317 | float newY = 0;//ImLerp(viewAngles.y, Out.y, 1 / 1000.f * config::get("aimbot", "aim_strength", 500.f)); 318 | float newZ = 0;//ImLerp(viewAngles.z, Out.z, 1 / 1000.f * config::get("aimbot", "aim_strength", 500.f)); 319 | 320 | if (config::get("aimbot", "aim_mode", 0) == 1) { 321 | newX = viewAngles.x + (delta.x / (1001.f - config::get("aimbot", "aim_strength", 500.f))); 322 | newY = viewAngles.y + (delta.y / (1001.f - config::get("aimbot", "aim_strength", 500.f))); 323 | newZ = viewAngles.z + (delta.z / (1001.f - config::get("aimbot", "aim_strength", 500.f))); 324 | } 325 | if (config::get("aimbot", "aim_mode", 0) == 2) { 326 | newX = viewAngles.x + (delta.x / (1001.f - config::get("aimbot", "aim_strength", 500.f))); 327 | newY = viewAngles.y + (delta.y / (1001.f - config::get("aimbot", "aim_strength", 500.f))); 328 | } 329 | 330 | if ((config::get("aimbot", "aim_mode", 0) == 3)) { 331 | target_aim_angle = aim3d; 332 | } else { 333 | if (newX != 0) { 334 | //cam->m_fps_angles.x = newX; 335 | cam->m_tps_angles.x = newX; 336 | } 337 | if (newY != 0) { 338 | //cam->m_fps_angles.y = newY; 339 | cam->m_tps_angles.y = newY; 340 | } 341 | if (newZ != 0) { 342 | //cam->m_fps_angles.z = newZ; 343 | cam->m_tps_angles.z = newZ; 344 | } 345 | } 346 | } else if (config::get("aimbot", "aim_mode", 0) == 0) { 347 | //cam->m_fps_angles = Out; 348 | cam->m_tps_angles = Out; 349 | 350 | 351 | //char address[100]; 352 | //std::snprintf(address, sizeof(address), "address %X\n", ); 353 | //logs::add(address); 354 | } 355 | } 356 | } 357 | } 358 | } 359 | } 360 | 361 | void init() { 362 | cout << "aimbot init" << endl; 363 | while (Game.running) { 364 | tick(); 365 | std::this_thread::sleep_for(1ms); 366 | } 367 | cout << "exit aimbot" << endl; 368 | } 369 | } -------------------------------------------------------------------------------- /includes/imgui/imgui_impl_win32.cpp: -------------------------------------------------------------------------------- 1 | // dear imgui: Platform Binding for Windows (standard windows API for 32 and 64 bits applications) 2 | // This needs to be used along with a Renderer (e.g. DirectX11, OpenGL3, Vulkan..) 3 | 4 | // Implemented features: 5 | // [X] Platform: Clipboard support (for Win32 this is actually part of core imgui) 6 | // [X] Platform: Mouse cursor shape and visibility. Disable with 'io.ConfigFlags |= ImGuiConfigFlags_NoMouseCursorChange'. 7 | // [X] Platform: Keyboard arrays indexed using VK_* Virtual Key Codes, e.g. ImGui::IsKeyPressed(VK_SPACE). 8 | // [X] Platform: Gamepad support. Enabled with 'io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad'. 9 | 10 | #include "imgui.h" 11 | #include "imgui_impl_win32.h" 12 | #ifndef WIN32_LEAN_AND_MEAN 13 | #define WIN32_LEAN_AND_MEAN 14 | #endif 15 | #include 16 | #include 17 | #include 18 | 19 | // CHANGELOG 20 | // (minor and older changes stripped away, please see git history for details) 21 | // 2019-05-11: Inputs: Don't filter value from WM_CHAR before calling AddInputCharacter(). 22 | // 2019-01-17: Misc: Using GetForegroundWindow()+IsChild() instead of GetActiveWindow() to be compatible with windows created in a different thread or parent. 23 | // 2019-01-17: Inputs: Added support for mouse buttons 4 and 5 via WM_XBUTTON* messages. 24 | // 2019-01-15: Inputs: Added support for XInput gamepads (if ImGuiConfigFlags_NavEnableGamepad is set by user application). 25 | // 2018-11-30: Misc: Setting up io.BackendPlatformName so it can be displayed in the About Window. 26 | // 2018-06-29: Inputs: Added support for the ImGuiMouseCursor_Hand cursor. 27 | // 2018-06-10: Inputs: Fixed handling of mouse wheel messages to support fine position messages (typically sent by track-pads). 28 | // 2018-06-08: Misc: Extracted imgui_impl_win32.cpp/.h away from the old combined DX9/DX10/DX11/DX12 examples. 29 | // 2018-03-20: Misc: Setup io.BackendFlags ImGuiBackendFlags_HasMouseCursors and ImGuiBackendFlags_HasSetMousePos flags + honor ImGuiConfigFlags_NoMouseCursorChange flag. 30 | // 2018-02-20: Inputs: Added support for mouse cursors (ImGui::GetMouseCursor() value and WM_SETCURSOR message handling). 31 | // 2018-02-06: Inputs: Added mapping for ImGuiKey_Space. 32 | // 2018-02-06: Inputs: Honoring the io.WantSetMousePos by repositioning the mouse (when using navigation and ImGuiConfigFlags_NavMoveMouse is set). 33 | // 2018-02-06: Misc: Removed call to ImGui::Shutdown() which is not available from 1.60 WIP, user needs to call CreateContext/DestroyContext themselves. 34 | // 2018-01-20: Inputs: Added Horizontal Mouse Wheel support. 35 | // 2018-01-08: Inputs: Added mapping for ImGuiKey_Insert. 36 | // 2018-01-05: Inputs: Added WM_LBUTTONDBLCLK double-click handlers for window classes with the CS_DBLCLKS flag. 37 | // 2017-10-23: Inputs: Added WM_SYSKEYDOWN / WM_SYSKEYUP handlers so e.g. the VK_MENU key can be read. 38 | // 2017-10-23: Inputs: Using Win32 ::SetCapture/::GetCapture() to retrieve mouse positions outside the client area when dragging. 39 | // 2016-11-12: Inputs: Only call Win32 ::SetCursor(NULL) when io.MouseDrawCursor is set. 40 | 41 | // Win32 Data 42 | static HWND g_hWnd = 0; 43 | static INT64 g_Time = 0; 44 | static INT64 g_TicksPerSecond = 0; 45 | static ImGuiMouseCursor g_LastMouseCursor = ImGuiMouseCursor_COUNT; 46 | static bool g_HasGamepad = false; 47 | static bool g_WantUpdateHasGamepad = true; 48 | 49 | // Functions 50 | bool ImGui_ImplWin32_Init(void* hwnd) 51 | { 52 | if (!::QueryPerformanceFrequency((LARGE_INTEGER *)&g_TicksPerSecond)) 53 | return false; 54 | if (!::QueryPerformanceCounter((LARGE_INTEGER *)&g_Time)) 55 | return false; 56 | 57 | // Setup back-end capabilities flags 58 | g_hWnd = (HWND)hwnd; 59 | ImGuiIO& io = ImGui::GetIO(); 60 | io.BackendFlags |= ImGuiBackendFlags_HasMouseCursors; // We can honor GetMouseCursor() values (optional) 61 | io.BackendFlags |= ImGuiBackendFlags_HasSetMousePos; // We can honor io.WantSetMousePos requests (optional, rarely used) 62 | io.BackendPlatformName = "imgui_impl_win32"; 63 | io.ImeWindowHandle = hwnd; 64 | 65 | // Keyboard mapping. ImGui will use those indices to peek into the io.KeysDown[] array that we will update during the application lifetime. 66 | io.KeyMap[ImGuiKey_Tab] = VK_TAB; 67 | io.KeyMap[ImGuiKey_LeftArrow] = VK_LEFT; 68 | io.KeyMap[ImGuiKey_RightArrow] = VK_RIGHT; 69 | io.KeyMap[ImGuiKey_UpArrow] = VK_UP; 70 | io.KeyMap[ImGuiKey_DownArrow] = VK_DOWN; 71 | io.KeyMap[ImGuiKey_PageUp] = VK_PRIOR; 72 | io.KeyMap[ImGuiKey_PageDown] = VK_NEXT; 73 | io.KeyMap[ImGuiKey_Home] = VK_HOME; 74 | io.KeyMap[ImGuiKey_End] = VK_END; 75 | io.KeyMap[ImGuiKey_Insert] = VK_INSERT; 76 | io.KeyMap[ImGuiKey_Delete] = VK_DELETE; 77 | io.KeyMap[ImGuiKey_Backspace] = VK_BACK; 78 | io.KeyMap[ImGuiKey_Space] = VK_SPACE; 79 | io.KeyMap[ImGuiKey_Enter] = VK_RETURN; 80 | io.KeyMap[ImGuiKey_Escape] = VK_ESCAPE; 81 | io.KeyMap[ImGuiKey_A] = 'A'; 82 | io.KeyMap[ImGuiKey_C] = 'C'; 83 | io.KeyMap[ImGuiKey_V] = 'V'; 84 | io.KeyMap[ImGuiKey_X] = 'X'; 85 | io.KeyMap[ImGuiKey_Y] = 'Y'; 86 | io.KeyMap[ImGuiKey_Z] = 'Z'; 87 | 88 | return true; 89 | } 90 | 91 | void ImGui_ImplWin32_Shutdown() 92 | { 93 | g_hWnd = (HWND)0; 94 | } 95 | 96 | static bool ImGui_ImplWin32_UpdateMouseCursor() 97 | { 98 | ImGuiIO& io = ImGui::GetIO(); 99 | if (io.ConfigFlags & ImGuiConfigFlags_NoMouseCursorChange) 100 | return false; 101 | 102 | ImGuiMouseCursor imgui_cursor = ImGui::GetMouseCursor(); 103 | if (imgui_cursor == ImGuiMouseCursor_None || io.MouseDrawCursor) 104 | { 105 | // Hide OS mouse cursor if imgui is drawing it or if it wants no cursor 106 | ::SetCursor(NULL); 107 | } 108 | else 109 | { 110 | // Show OS mouse cursor 111 | LPTSTR win32_cursor = IDC_ARROW; 112 | switch (imgui_cursor) 113 | { 114 | case ImGuiMouseCursor_Arrow: win32_cursor = IDC_ARROW; break; 115 | case ImGuiMouseCursor_TextInput: win32_cursor = IDC_IBEAM; break; 116 | case ImGuiMouseCursor_ResizeAll: win32_cursor = IDC_SIZEALL; break; 117 | case ImGuiMouseCursor_ResizeEW: win32_cursor = IDC_SIZEWE; break; 118 | case ImGuiMouseCursor_ResizeNS: win32_cursor = IDC_SIZENS; break; 119 | case ImGuiMouseCursor_ResizeNESW: win32_cursor = IDC_SIZENESW; break; 120 | case ImGuiMouseCursor_ResizeNWSE: win32_cursor = IDC_SIZENWSE; break; 121 | case ImGuiMouseCursor_Hand: win32_cursor = IDC_HAND; break; 122 | } 123 | ::SetCursor(::LoadCursor(NULL, win32_cursor)); 124 | } 125 | return true; 126 | } 127 | 128 | static void ImGui_ImplWin32_UpdateMousePos() 129 | { 130 | ImGuiIO& io = ImGui::GetIO(); 131 | 132 | // Set OS mouse position if requested (rarely used, only when ImGuiConfigFlags_NavEnableSetMousePos is enabled by user) 133 | if (io.WantSetMousePos) 134 | { 135 | POINT pos = { (int)io.MousePos.x, (int)io.MousePos.y }; 136 | ::ClientToScreen(g_hWnd, &pos); 137 | ::SetCursorPos(pos.x, pos.y); 138 | } 139 | 140 | // Set mouse position 141 | io.MousePos = ImVec2(-FLT_MAX, -FLT_MAX); 142 | POINT pos; 143 | if (HWND active_window = ::GetForegroundWindow()) 144 | if (active_window == g_hWnd || ::IsChild(active_window, g_hWnd)) 145 | if (::GetCursorPos(&pos) && ::ScreenToClient(g_hWnd, &pos)) 146 | io.MousePos = ImVec2((float)pos.x, (float)pos.y); 147 | } 148 | 149 | #ifdef _MSC_VER 150 | #pragma comment(lib, "xinput") 151 | #endif 152 | 153 | // Gamepad navigation mapping 154 | static void ImGui_ImplWin32_UpdateGamepads() 155 | { 156 | ImGuiIO& io = ImGui::GetIO(); 157 | memset(io.NavInputs, 0, sizeof(io.NavInputs)); 158 | if ((io.ConfigFlags & ImGuiConfigFlags_NavEnableGamepad) == 0) 159 | return; 160 | 161 | // Calling XInputGetState() every frame on disconnected gamepads is unfortunately too slow. 162 | // Instead we refresh gamepad availability by calling XInputGetCapabilities() _only_ after receiving WM_DEVICECHANGE. 163 | if (g_WantUpdateHasGamepad) 164 | { 165 | XINPUT_CAPABILITIES caps; 166 | g_HasGamepad = (XInputGetCapabilities(0, XINPUT_FLAG_GAMEPAD, &caps) == ERROR_SUCCESS); 167 | g_WantUpdateHasGamepad = false; 168 | } 169 | 170 | XINPUT_STATE xinput_state; 171 | io.BackendFlags &= ~ImGuiBackendFlags_HasGamepad; 172 | if (g_HasGamepad && XInputGetState(0, &xinput_state) == ERROR_SUCCESS) 173 | { 174 | const XINPUT_GAMEPAD& gamepad = xinput_state.Gamepad; 175 | io.BackendFlags |= ImGuiBackendFlags_HasGamepad; 176 | 177 | #define MAP_BUTTON(NAV_NO, BUTTON_ENUM) { io.NavInputs[NAV_NO] = (gamepad.wButtons & BUTTON_ENUM) ? 1.0f : 0.0f; } 178 | #define MAP_ANALOG(NAV_NO, VALUE, V0, V1) { float vn = (float)(VALUE - V0) / (float)(V1 - V0); if (vn > 1.0f) vn = 1.0f; if (vn > 0.0f && io.NavInputs[NAV_NO] < vn) io.NavInputs[NAV_NO] = vn; } 179 | MAP_BUTTON(ImGuiNavInput_Activate, XINPUT_GAMEPAD_A); // Cross / A 180 | MAP_BUTTON(ImGuiNavInput_Cancel, XINPUT_GAMEPAD_B); // Circle / B 181 | MAP_BUTTON(ImGuiNavInput_Menu, XINPUT_GAMEPAD_X); // Square / X 182 | MAP_BUTTON(ImGuiNavInput_Input, XINPUT_GAMEPAD_Y); // Triangle / Y 183 | MAP_BUTTON(ImGuiNavInput_DpadLeft, XINPUT_GAMEPAD_DPAD_LEFT); // D-Pad Left 184 | MAP_BUTTON(ImGuiNavInput_DpadRight, XINPUT_GAMEPAD_DPAD_RIGHT); // D-Pad Right 185 | MAP_BUTTON(ImGuiNavInput_DpadUp, XINPUT_GAMEPAD_DPAD_UP); // D-Pad Up 186 | MAP_BUTTON(ImGuiNavInput_DpadDown, XINPUT_GAMEPAD_DPAD_DOWN); // D-Pad Down 187 | MAP_BUTTON(ImGuiNavInput_FocusPrev, XINPUT_GAMEPAD_LEFT_SHOULDER); // L1 / LB 188 | MAP_BUTTON(ImGuiNavInput_FocusNext, XINPUT_GAMEPAD_RIGHT_SHOULDER); // R1 / RB 189 | MAP_BUTTON(ImGuiNavInput_TweakSlow, XINPUT_GAMEPAD_LEFT_SHOULDER); // L1 / LB 190 | MAP_BUTTON(ImGuiNavInput_TweakFast, XINPUT_GAMEPAD_RIGHT_SHOULDER); // R1 / RB 191 | MAP_ANALOG(ImGuiNavInput_LStickLeft, gamepad.sThumbLX, -XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE, -32768); 192 | MAP_ANALOG(ImGuiNavInput_LStickRight, gamepad.sThumbLX, +XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE, +32767); 193 | MAP_ANALOG(ImGuiNavInput_LStickUp, gamepad.sThumbLY, +XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE, +32767); 194 | MAP_ANALOG(ImGuiNavInput_LStickDown, gamepad.sThumbLY, -XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE, -32767); 195 | #undef MAP_BUTTON 196 | #undef MAP_ANALOG 197 | } 198 | } 199 | 200 | void ImGui_ImplWin32_NewFrame() 201 | { 202 | ImGuiIO& io = ImGui::GetIO(); 203 | IM_ASSERT(io.Fonts->IsBuilt() && "Font atlas not built! It is generally built by the renderer back-end. Missing call to renderer _NewFrame() function? e.g. ImGui_ImplOpenGL3_NewFrame()."); 204 | 205 | // Setup display size (every frame to accommodate for window resizing) 206 | RECT rect; 207 | ::GetClientRect(g_hWnd, &rect); 208 | io.DisplaySize = ImVec2((float)(rect.right - rect.left), (float)(rect.bottom - rect.top)); 209 | 210 | // Setup time step 211 | INT64 current_time; 212 | ::QueryPerformanceCounter((LARGE_INTEGER *)¤t_time); 213 | io.DeltaTime = (float)(current_time - g_Time) / g_TicksPerSecond; 214 | g_Time = current_time; 215 | 216 | // Read keyboard modifiers inputs 217 | io.KeyCtrl = (::GetKeyState(VK_CONTROL) & 0x8000) != 0; 218 | io.KeyShift = (::GetKeyState(VK_SHIFT) & 0x8000) != 0; 219 | io.KeyAlt = (::GetKeyState(VK_MENU) & 0x8000) != 0; 220 | io.KeySuper = false; 221 | // io.KeysDown[], io.MousePos, io.MouseDown[], io.MouseWheel: filled by the WndProc handler below. 222 | 223 | // Update OS mouse position 224 | ImGui_ImplWin32_UpdateMousePos(); 225 | 226 | // Update OS mouse cursor with the cursor requested by imgui 227 | ImGuiMouseCursor mouse_cursor = io.MouseDrawCursor ? ImGuiMouseCursor_None : ImGui::GetMouseCursor(); 228 | if (g_LastMouseCursor != mouse_cursor) 229 | { 230 | g_LastMouseCursor = mouse_cursor; 231 | ImGui_ImplWin32_UpdateMouseCursor(); 232 | } 233 | 234 | // Update game controllers (if enabled and available) 235 | ImGui_ImplWin32_UpdateGamepads(); 236 | } 237 | 238 | // Allow compilation with old Windows SDK. MinGW doesn't have default _WIN32_WINNT/WINVER versions. 239 | #ifndef WM_MOUSEHWHEEL 240 | #define WM_MOUSEHWHEEL 0x020E 241 | #endif 242 | #ifndef DBT_DEVNODES_CHANGED 243 | #define DBT_DEVNODES_CHANGED 0x0007 244 | #endif 245 | 246 | // Process Win32 mouse/keyboard inputs. 247 | // You can read the io.WantCaptureMouse, io.WantCaptureKeyboard flags to tell if dear imgui wants to use your inputs. 248 | // - When io.WantCaptureMouse is true, do not dispatch mouse input data to your main application. 249 | // - When io.WantCaptureKeyboard is true, do not dispatch keyboard input data to your main application. 250 | // Generally you may always pass all inputs to dear imgui, and hide them from your application based on those two flags. 251 | // PS: In this Win32 handler, we use the capture API (GetCapture/SetCapture/ReleaseCapture) to be able to read mouse coordinates when dragging mouse outside of our window bounds. 252 | // PS: We treat DBLCLK messages as regular mouse down messages, so this code will work on windows classes that have the CS_DBLCLKS flag set. Our own example app code doesn't set this flag. 253 | IMGUI_IMPL_API LRESULT ImGui_ImplWin32_WndProcHandler(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) 254 | { 255 | if (ImGui::GetCurrentContext() == NULL) 256 | return 0; 257 | 258 | ImGuiIO& io = ImGui::GetIO(); 259 | switch (msg) 260 | { 261 | case WM_LBUTTONDOWN: case WM_LBUTTONDBLCLK: 262 | case WM_RBUTTONDOWN: case WM_RBUTTONDBLCLK: 263 | case WM_MBUTTONDOWN: case WM_MBUTTONDBLCLK: 264 | case WM_XBUTTONDOWN: case WM_XBUTTONDBLCLK: 265 | { 266 | int button = 0; 267 | if (msg == WM_LBUTTONDOWN || msg == WM_LBUTTONDBLCLK) { button = 0; } 268 | if (msg == WM_RBUTTONDOWN || msg == WM_RBUTTONDBLCLK) { button = 1; } 269 | if (msg == WM_MBUTTONDOWN || msg == WM_MBUTTONDBLCLK) { button = 2; } 270 | if (msg == WM_XBUTTONDOWN || msg == WM_XBUTTONDBLCLK) { button = (GET_XBUTTON_WPARAM(wParam) == XBUTTON1) ? 3 : 4; } 271 | if (!ImGui::IsAnyMouseDown() && ::GetCapture() == NULL) 272 | ::SetCapture(hwnd); 273 | io.MouseDown[button] = true; 274 | return 0; 275 | } 276 | case WM_LBUTTONUP: 277 | case WM_RBUTTONUP: 278 | case WM_MBUTTONUP: 279 | case WM_XBUTTONUP: 280 | { 281 | int button = 0; 282 | if (msg == WM_LBUTTONUP) { button = 0; } 283 | if (msg == WM_RBUTTONUP) { button = 1; } 284 | if (msg == WM_MBUTTONUP) { button = 2; } 285 | if (msg == WM_XBUTTONUP) { button = (GET_XBUTTON_WPARAM(wParam) == XBUTTON1) ? 3 : 4; } 286 | io.MouseDown[button] = false; 287 | if (!ImGui::IsAnyMouseDown() && ::GetCapture() == hwnd) 288 | ::ReleaseCapture(); 289 | return 0; 290 | } 291 | case WM_MOUSEWHEEL: 292 | io.MouseWheel += (float)GET_WHEEL_DELTA_WPARAM(wParam) / (float)WHEEL_DELTA; 293 | return 0; 294 | case WM_MOUSEHWHEEL: 295 | io.MouseWheelH += (float)GET_WHEEL_DELTA_WPARAM(wParam) / (float)WHEEL_DELTA; 296 | return 0; 297 | case WM_KEYDOWN: 298 | case WM_SYSKEYDOWN: 299 | if (wParam < 256) 300 | io.KeysDown[wParam] = 1; 301 | return 0; 302 | case WM_KEYUP: 303 | case WM_SYSKEYUP: 304 | if (wParam < 256) 305 | io.KeysDown[wParam] = 0; 306 | return 0; 307 | case WM_CHAR: 308 | // You can also use ToAscii()+GetKeyboardState() to retrieve characters. 309 | io.AddInputCharacter((unsigned int)wParam); 310 | return 0; 311 | case WM_SETCURSOR: 312 | if (LOWORD(lParam) == HTCLIENT && ImGui_ImplWin32_UpdateMouseCursor()) 313 | return 1; 314 | return 0; 315 | case WM_DEVICECHANGE: 316 | if ((UINT)wParam == DBT_DEVNODES_CHANGED) 317 | g_WantUpdateHasGamepad = true; 318 | return 0; 319 | } 320 | return 0; 321 | } 322 | 323 | -------------------------------------------------------------------------------- /immunity-gta5/pointers.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #pragma once 4 | #include "imports.h" 5 | #include 6 | #include 7 | #include 8 | 9 | //#include "classes.h" 10 | extern bool isFiveM; 11 | 12 | 13 | 14 | #define INRANGE(x,a,b) (x >= a && x <= b) 15 | #define getBits( x ) (INRANGE((x&(~0x20)),'A','F') ? ((x&(~0x20)) - 'A' + 0xa) : (INRANGE(x,'0','9') ? x - '0' : 0)) 16 | #define getByte( x ) (getBits(x[0]) << 4 | getBits(x[1])) 17 | #define FIND_NT_HEADER(x) reinterpret_cast( uint64_t(x) + ((PIMAGE_DOS_HEADER)(x))->e_lfanew ) 18 | namespace pointers { 19 | 20 | vector listIAT(string moduleName) { 21 | vector t; 22 | HMODULE mp = GetModuleHandleA(moduleName.c_str()); 23 | PIMAGE_DOS_HEADER img_dos_headers = (PIMAGE_DOS_HEADER)mp; 24 | PIMAGE_NT_HEADERS img_nt_headers = (PIMAGE_NT_HEADERS)((BYTE*)img_dos_headers + img_dos_headers->e_lfanew); 25 | PIMAGE_IMPORT_DESCRIPTOR img_import_desc = (PIMAGE_IMPORT_DESCRIPTOR)((BYTE*)img_dos_headers + img_nt_headers->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT].VirtualAddress); 26 | if (img_dos_headers->e_magic != IMAGE_DOS_SIGNATURE) 27 | add_log("ERROR: e_magic is no valid DOS signature\n"); 28 | 29 | for (IMAGE_IMPORT_DESCRIPTOR* iid = img_import_desc; iid->Name != 0; iid++) { 30 | for (int func_idx = 0; *(func_idx + (void**)(iid->FirstThunk + (size_t)mp)) != nullptr; func_idx++) { 31 | char* mod_func_name = (char*)(*(func_idx + (size_t*)(iid->OriginalFirstThunk + (size_t)mp)) + (size_t)mp + 2); 32 | const intptr_t nmod_func_name = (intptr_t)mod_func_name; 33 | if (nmod_func_name >= 0) { 34 | t.push_back((string)moduleName + " -> " + (string)mod_func_name); 35 | } 36 | } 37 | } 38 | return t; 39 | } 40 | 41 | 42 | void** find_iat(string moduleName, string targetFunc) { 43 | HMODULE mp = GetModuleHandleA(moduleName.c_str()); 44 | PIMAGE_DOS_HEADER img_dos_headers = (PIMAGE_DOS_HEADER)mp; 45 | PIMAGE_NT_HEADERS img_nt_headers = (PIMAGE_NT_HEADERS)((BYTE*)img_dos_headers + img_dos_headers->e_lfanew); 46 | PIMAGE_IMPORT_DESCRIPTOR img_import_desc = (PIMAGE_IMPORT_DESCRIPTOR)((BYTE*)img_dos_headers + img_nt_headers->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT].VirtualAddress); 47 | if (img_dos_headers->e_magic != IMAGE_DOS_SIGNATURE) 48 | add_log("ERROR: e_magic is no valid DOS signature\n"); 49 | 50 | for (IMAGE_IMPORT_DESCRIPTOR* iid = img_import_desc; iid->Name != 0; iid++) { 51 | for (int func_idx = 0; *(func_idx + (void**)(iid->FirstThunk + (size_t)mp)) != nullptr; func_idx++) { 52 | char* mod_func_name = (char*)(*(func_idx + (size_t*)(iid->OriginalFirstThunk + (size_t)mp)) + (size_t)mp + 2); 53 | const intptr_t nmod_func_name = (intptr_t)mod_func_name; 54 | if (nmod_func_name >= 0) { 55 | if (!strcmp(targetFunc.c_str(), mod_func_name)) { 56 | return func_idx + (void**)(iid->FirstThunk + (size_t)mp); 57 | } 58 | 59 | } 60 | } 61 | } 62 | return 0; 63 | } 64 | 65 | 66 | uintptr_t hook_iat_ptr(string moduleName, string targetFunc, void* newfunction) { 67 | auto&& func_ptr = find_iat(moduleName, targetFunc); 68 | if (*func_ptr == newfunction || *func_ptr == nullptr) 69 | return 0; 70 | 71 | DWORD old_rights, new_rights = PAGE_READWRITE; 72 | VirtualProtect(func_ptr, sizeof(uintptr_t), new_rights, &old_rights); 73 | uintptr_t ret = (uintptr_t)*func_ptr; 74 | *func_ptr = newfunction; 75 | VirtualProtect(func_ptr, sizeof(uintptr_t), old_rights, &new_rights); 76 | return ret; 77 | } 78 | 79 | 80 | 81 | template 82 | inline T fix_mov(uint8_t* patternMatch) { 83 | return reinterpret_cast(patternMatch + *reinterpret_cast(patternMatch + 3) + 7); 84 | } 85 | template 86 | inline T fix_call(uint8_t* address) { 87 | return reinterpret_cast(address + *reinterpret_cast(address + 1) + 5); 88 | } 89 | 90 | template 91 | inline T fix_custom(uint8_t* address, int offset) { 92 | return reinterpret_cast(address) - offset; 93 | } 94 | template 95 | inline T add(uint8_t* address, int offset) { 96 | return reinterpret_cast(address) + offset; 97 | } 98 | template 99 | inline T sub(uint8_t* address, int offset) { 100 | return reinterpret_cast(address) - offset; 101 | } 102 | 103 | template 104 | type as_relative(type address, int offset = 3) { 105 | return reinterpret_cast(reinterpret_cast(address) + *reinterpret_cast(reinterpret_cast(address) + offset) + (offset + 4i32)); 106 | } 107 | 108 | 109 | 110 | std::uint8_t* findPattern2(const char* module_name, const char* signature) { 111 | const auto module_handle = GetModuleHandleA(module_name); 112 | 113 | if (!module_handle) 114 | return nullptr; 115 | 116 | static auto pattern_to_byte = [](const char* pattern) { 117 | auto bytes = std::vector{}; 118 | auto start = const_cast(pattern); 119 | auto end = const_cast(pattern) + std::strlen(pattern); 120 | 121 | for (auto current = start; current < end; ++current) { 122 | if (*current == '?') { 123 | ++current; 124 | 125 | if (*current == '?') 126 | ++current; 127 | 128 | bytes.push_back(-1); 129 | } else { 130 | bytes.push_back(std::strtoul(current, ¤t, 16)); 131 | } 132 | } 133 | return bytes; 134 | }; 135 | 136 | auto dos_header = reinterpret_cast(module_handle); 137 | auto nt_headers = 138 | reinterpret_cast(reinterpret_cast(module_handle) + dos_header->e_lfanew); 139 | 140 | auto size_of_image = nt_headers->OptionalHeader.SizeOfImage; 141 | auto pattern_bytes = pattern_to_byte(signature); 142 | auto scan_bytes = reinterpret_cast(module_handle); 143 | 144 | auto s = pattern_bytes.size(); 145 | auto d = pattern_bytes.data(); 146 | 147 | for (auto i = 0ul; i < size_of_image - s; ++i) { 148 | bool found = true; 149 | 150 | for (auto j = 0ul; j < s; ++j) { 151 | if (scan_bytes[i + j] != d[j] && d[j] != -1) { 152 | found = false; 153 | break; 154 | } 155 | } 156 | if (found) 157 | return &scan_bytes[i]; 158 | } 159 | logs::add(enc("failed find pattern again in ") + string(module_name)); 160 | 161 | return nullptr; 162 | } 163 | 164 | 165 | uint8_t* findPattern(const std::string_view module, const std::string_view signature) { 166 | std::vector signature_bytes(signature.size() + 1); 167 | 168 | { 169 | std::vector signature_chunks{ }; 170 | std::string current_chunk{ }; 171 | 172 | std::istringstream string_stream{signature.data()}; 173 | 174 | while (std::getline(string_stream, current_chunk, ' ')) 175 | signature_chunks.push_back(current_chunk); 176 | 177 | std::transform(signature_chunks.cbegin(), signature_chunks.cend(), signature_bytes.begin(), [](const std::string& val) -> uint8_t { 178 | return val.find('?') != std::string::npos ? 0ui8 : static_cast(std::stoi(val, nullptr, 16)); 179 | }); 180 | } 181 | 182 | uint8_t* found_bytes = nullptr; 183 | 184 | { 185 | const auto image_start = reinterpret_cast(GetModuleHandleA(module.data())); 186 | const auto image_end = image_start + FIND_NT_HEADER(image_start)->OptionalHeader.SizeOfImage; 187 | 188 | const auto result = std::search(image_start, image_end, signature_bytes.cbegin(), signature_bytes.cend(), [](uint8_t left, uint8_t right) -> bool { 189 | return right == 0ui8 || left == right; 190 | }); 191 | 192 | found_bytes = (result != image_end) ? result : nullptr; 193 | } 194 | 195 | if (found_bytes == nullptr) { 196 | logs::add(enc("failed find pattern, fallback ") + string(module.data())); 197 | return findPattern2(module.data(), signature.data()); 198 | } 199 | return found_bytes; 200 | } 201 | 202 | 203 | 204 | bool findAllPatterns() { 205 | if (debug) return true; 206 | add_log("find signatures"); 207 | 208 | 209 | if (GetModuleHandleA("GameOverlayRenderer64.dll")) { 210 | hook::gameoverlay_presentd3d11 = (uintptr_t)findPattern("GameOverlayRenderer64.dll", enc("48 89 6C 24 ? 48 89 74 24 ? 41 56 48 83 EC 20 41 8B E8")); 211 | hook::gameoverlay_resized3d11 = (uintptr_t)findPattern("GameOverlayRenderer64.dll", enc("48 89 5C 24 ? 48 89 6C 24 ? 48 89 74 24 ? 57 41 56 41 57 48 83 EC 30 44 8B FA")); 212 | 213 | if (!hook::gameoverlay_presentd3d11 || !hook::gameoverlay_resized3d11) { 214 | add_log("cant find gameoverlay"); 215 | logs::add(enc("GameOverlayRenderer64 ") + to_string((uintptr_t)GetModuleHandleA("GameOverlayRenderer64.dll"))); 216 | 217 | } 218 | } 219 | std::cout << "GameOverlayRenderer64 " << std::endl; 220 | if (GetModuleHandleA("DiscordHook64.dll") && GetModuleHandleA("dxgi.dll")) { 221 | hook::discordoverlay_presentd3d11 = (uintptr_t)findPattern("DiscordHook64.dll", enc("56 57 53 48 83 EC 30 44 89 C6")); 222 | hook::discordoverlay_resized3d11 = (uintptr_t)findPattern("DiscordHook64.dll", enc("56 57 55 53 48 83 EC 28 44 89 CD 44 89 C7")); 223 | 224 | if (!hook::discordoverlay_presentd3d11 || !hook::discordoverlay_resized3d11) { 225 | add_log("cant find discordoverlay"); 226 | logs::add(enc("GameOverlayRenderer64 ") + to_string((uintptr_t)GetModuleHandleA("GameOverlayRenderer64.dll"))); 227 | 228 | } 229 | 230 | } 231 | string game_executable = "GTA5.exe"; 232 | 233 | 234 | logs::add(enc("game process:") + (string)game_executable); 235 | 236 | Game.ReplayInterface = *(CReplayInterface**)fix_mov(findPattern(game_executable, enc("48 8D 0D ? ? ? ? 48 8B D7 E8 ? ? ? ? 48 8D 0D ? ? ? ? 8A D8 E8 ? ? ? ? 84 DB 75 13 48 8D 0D"))); 237 | if (!IsValidPtr(Game.ReplayInterface)) { 238 | add_log("cant find ReplayInterface"); 239 | return false; 240 | } 241 | 242 | Game.World = *(CWorld**)fix_mov(findPattern(game_executable, enc("48 8B 05 ? ? ? ? 48 8B 58 08 48 85 DB 74 32"))); 243 | if (!IsValidPtr(Game.World)) { 244 | add_log("cant find World"); 245 | return false; 246 | } 247 | 248 | 249 | Game.viewPort = *(CViewPort**)fix_mov(findPattern(game_executable, enc("48 8B 15 ? ? ? ? 48 8D 2D ? ? ? ? 48 8B CD"))); 250 | 251 | 252 | Game.CamAddr = (uintptr_t)fix_mov(findPattern(game_executable, enc("48 8B 05 ? ? ? ? 48 8B 98 ? ? ? ? EB"))); 253 | 254 | 255 | 256 | if (!IsValidPtr(Game.viewPort)) { 257 | add_log("cant find viewport"); 258 | return false; 259 | } 260 | if (!Game.CamAddr) { 261 | add_log("cant find cam"); 262 | return false; 263 | } 264 | //printf("Replay Addr %p \n", Game.ReplayInterface); 265 | 266 | WorldToScreenAddr = reinterpret_cast(findPattern(game_executable, "48 89 5C 24 ?? 55 56 57 48 83 EC 70 65 4C 8B 0C 25 ?? 00 00 00 8B")); 267 | std::cout << "WorldToScreenAddr " << WorldToScreenAddr << std::endl; 268 | if (!IsValidPtr(WorldToScreenAddr)) { 269 | add_log("cant find w2s"); 270 | return false; 271 | } 272 | 273 | 274 | //GetBone = reinterpret_cast(findPattern(game_executable, enc("48 89 5C 24 ? 48 89 6C 24 ? 48 89 74 24 ? 57 48 83 EC 60 48 8B 01 41 8B E8 48 8B F2 48 8B F9 33 DB"))); 275 | GetBoneFunc = reinterpret_cast(findPattern(game_executable, enc("48 89 5C 24 ? 48 89 6C 24 ? 48 89 74 24 ? 57 48 83 EC 60 48 8B 01 41 8B E8 48 8B F2 48 8B F9 33 DB"))); 276 | if (!IsValidPtr(GetBoneFunc)) { 277 | add_log("cant find bone1"); 278 | return false; 279 | } 280 | 281 | DWORD64 FrameCount_pattern = (DWORD64)findPattern(game_executable, enc("8B 15 ? ? ? ? 41 FF CF")); 282 | //std::cout << "FrameCount_pattern " << FrameCount_pattern << std::endl; 283 | FrameCount = (FrameCount_pattern + *(DWORD*)(FrameCount_pattern + 0x2) + 0x6); 284 | //this_thread::sleep_for(chrono::milliseconds(100)); 285 | if (!FrameCount) { 286 | add_log("cant find FrameCount"); 287 | return false; 288 | } 289 | 290 | 291 | 292 | auto pattern = findPattern(game_executable, enc("83 3D ? ? ? ? ? 75 17 8B 43 20 25")); 293 | auto offset1 = add(pattern, 2); 294 | auto offset2 = as_relative(offset1, 0); 295 | auto offset3 = add(offset2, 1); 296 | Game.gta_game_state = reinterpret_cast(offset3); 297 | if (!IsValidPtr(Game.gta_game_state)) { 298 | add_log("cant find game_state"); 299 | 300 | return false; 301 | } 302 | 303 | 304 | Is_Dlc_Present = reinterpret_cast(sub(findPattern(game_executable, enc("57 48 83 EC 20 40 8A FA 8B 15 ? ? ? ? 48 8B F1")), 0xA)); 305 | 306 | if (!IsValidPtr(Is_Dlc_Present)) { 307 | add_log("cant find Dlc_Present"); 308 | return false; 309 | } 310 | 311 | //std::cout << "reinterpret_cast" << Is_Dlc_Present << std::endl; 312 | 313 | //std::cout << "Is_DLC_present" << std::endl; 314 | _START_SHAPE_TEST_CAPSULE = (tSTART_SHAPE_TEST_CAPSULE)(findPattern(game_executable, enc("41 8B CF C7 85 ? ? ? ? ? ? ? ? E8 ? ? ? ? B2 01")) - 0xBE); 315 | 316 | if (!IsValidPtr(_START_SHAPE_TEST_CAPSULE)) { 317 | add_log("cant find vis addr 1"); 318 | return false; 319 | //std::cout << "start_test not found" << std::endl; 320 | } 321 | 322 | _GET_RAYCAST_RESULT = (t_GET_RAYCAST_RESULT)(findPattern(game_executable, enc("48 89 5C 24 ? 48 89 74 24 ? 48 89 7C 24 ? 55 41 56 41 57 48 8B EC 48 83 EC 60 33 DB"))); 323 | 324 | 325 | if (!IsValidPtr(_GET_RAYCAST_RESULT)) { 326 | add_log("cant find raycast"); 327 | return false; 328 | //std::cout << "result not found" << std::endl; 329 | } 330 | 331 | 332 | 333 | pointer_to_handle = reinterpret_cast(findPattern(game_executable, enc("48 89 5c 24 ? 48 89 74 24 ? 57 48 83 ec 20 8b 15 ? ? ? ? 48 8b f9 48 83 c1 10 33 db"))); 334 | 335 | if (!IsValidPtr(pointer_to_handle)) { 336 | add_log("cant find pointer_to_handle"); 337 | return false; 338 | } 339 | 340 | //std::cout << "pointer_to_handle " << pointer_to_handle << std::endl; 341 | give_weapon_delayed = reinterpret_cast(findPattern(game_executable, enc("48 89 5c 24 ? 48 89 6c 24 ? 48 89 74 24 ? 57 48 83 ec ? 41 8a e9 41 8b f0 8b fa e8 ? ? ? ? 48 8b d8 48 85 c0 74"))); 342 | if (!IsValidPtr(give_weapon_delayed)) { 343 | add_log("cant find gwd"); 344 | 345 | return false; 346 | } 347 | 348 | 349 | 350 | //magic bullet?? 351 | //E8 ? ? ? ? 8B 75 D4 352 | gta_event_gun_shot = fix_call(findPattern(game_executable, enc("E8 ? ? ? ? 8B 75 D4"))); 353 | if (!IsValidPtr(gta_event_gun_shot)) { 354 | add_log("cant find gta_weapon_shot"); 355 | 356 | return false; 357 | } 358 | 359 | //thread hook JustNoScript 360 | //https://github.com/citizenfx/fivem/blob/6e1f04ed2739b3927a77fb437b4338a23d187efa/code/components/rage-scripting-five/src/scrEngine.cpp#L628 361 | 362 | gta_script_thread_tick = reinterpret_cast(sub(findPattern(game_executable, enc("48 83 EC 20 80 B9 4E 01 00 00 00")), 0xB)); // for 1.61 363 | if (!IsValidPtr(gta_script_thread_tick)) { 364 | add_log("cant find gta_script_thread_tick"); 365 | 366 | return false; 367 | } 368 | 369 | 370 | //native invoker 371 | 372 | // sig from https://github.com/Yimura/GTA5Base/blob/42454e20c67de80a01140fa85cbe2aadfad12728/src/Pointers.cpp#L41 373 | gta_get_native_handler = reinterpret_cast(as_relative(findPattern(game_executable, enc("48 8D 0D ? ? ? ? 48 8B 14 FA E8 ? ? ? ? 48 85 C0 75 0A")), 12)); 374 | if (!IsValidPtr(gta_get_native_handler)) { 375 | add_log("cant find gta_get_native_handler"); 376 | return false; 377 | } 378 | 379 | 380 | // sig from https://github.com/Yimura/GTA5Base/blob/42454e20c67de80a01140fa85cbe2aadfad12728/src/Pointers.cpp#L41 381 | gta_native_registration_table = reinterpret_cast(as_relative(findPattern(game_executable, enc("48 8D 0D ? ? ? ? 48 8B 14 FA E8 ? ? ? ? 48 85 C0 75 0A")), 3)); 382 | if (!IsValidPtr(gta_native_registration_table)) { 383 | add_log("cant find gta_native_registration_table"); 384 | return false; 385 | } 386 | 387 | 388 | 389 | //"Fix vectors" https://bitbucket.org/gir489/bigbasev2-fix/src/977bd803baa6a42e55523203f0b156d79ce69f8e/BigBaseV2/src/pointers.cpp?at=master#lines-38 390 | gta_fix_context_vector = reinterpret_cast(findPattern(game_executable, enc("83 79 18 00 48 8B D1 74 4A FF 4A 18 48 63 4A 18 48 8D 41 04 48 8B 4C CA"))); 391 | if (!IsValidPtr(gta_fix_context_vector)) { 392 | add_log("cant find gta_fix_context_vector"); 393 | return false; 394 | } 395 | 396 | if (GetModuleHandleA("multiplayerL.dll") || GetModuleHandleA("multiplayer.dll")) { 397 | add_log("detected ragemp"); 398 | Game.game_mod_base = 1; 399 | //string ragemp_exec = "multiplayerL.dll"; 400 | //if(!GetModuleHandleA("multiplayerL.dll")) { 401 | // ragemp_exec = "multiplayer.dll"; 402 | //} 403 | // 404 | //ragemp_fetch_handler = reinterpret_cast(as_relative(findPattern(ragemp_exec, enc("E8 ? ? ? ? 48 89 05 ? ? ? ? 48 8D 0D ? ? ? ? E8 ? ? ? ? E9 ? ? ? ?")), 1)); 405 | //if(!IsValidPtr(ragemp_fetch_handler)) { 406 | // add_log("cant find fetch_handler"); 407 | // return false; 408 | //} 409 | } 410 | if (GetModuleHandleA("altv-client.dll")) { 411 | add_log("detected altv"); 412 | Game.game_mod_base = 2; 413 | } 414 | 415 | 416 | 417 | add_log("found signatures"); 418 | return true; 419 | 420 | } 421 | } 422 | -------------------------------------------------------------------------------- /includes/renderer/Renderer.cpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | 8 | #include "../imgui/imgui.h" 9 | #include "../imgui/imgui_impl_dx11.h" 10 | #include "../imgui/imgui_impl_win32.h" 11 | #include "../imgui/imgui_internal.h" 12 | #include "./Renderer.h" 13 | //#include "../font.h" 14 | 15 | #define SAFE_RELEASE(pObject) { if(pObject) { (pObject)->Release(); (pObject) = NULL; } } 16 | 17 | 18 | 19 | bool imgui_render::ready() { 20 | return pDevice && pContext; 21 | } 22 | 23 | 24 | void imgui_render::SetResourceLoad(vResourceLoadCall funct2) { 25 | 26 | loadCall = funct2; 27 | } 28 | 29 | 30 | 31 | 32 | void imgui_render::Initialize(HWND targetWindow, IDXGISwapChain* pSwapchain) { 33 | IMGUI_CHECKVERSION(); 34 | ImGui::CreateContext(); 35 | io = ImGui::GetIO(); (void)io; 36 | pSwapChain = pSwapchain; 37 | 38 | 39 | io.IniFilename = NULL; 40 | ImGui::StyleColorsDark(); 41 | 42 | 43 | 44 | ImGuiStyle* style = &ImGui::GetStyle(); 45 | style->WindowPadding = ImVec2(8, 8); 46 | //style->WindowPadding = ImVec2(15, 15); 47 | style->WindowTitleAlign = ImVec2(0.5f, 0.5f); 48 | style->WindowRounding = 1.0f; 49 | style->FramePadding = ImVec2(4, 4); 50 | style->FrameRounding = 1.0f; 51 | style->ItemSpacing = ImVec2(2, 2); 52 | style->ItemInnerSpacing = ImVec2(8, 6); 53 | style->IndentSpacing = 25.0f; 54 | style->ScrollbarSize = 15.0f; 55 | style->ScrollbarRounding = 9.0f; 56 | style->GrabMinSize = 5.0f; 57 | style->GrabRounding = 3.0f; 58 | style->PopupRounding = 1.0f; 59 | 60 | 61 | 62 | ImColor mainColor = ImColor(4, 188, 0, 200); 63 | 64 | style->Colors[ImGuiCol_Text] = ImColor(255, 255, 255, 255); 65 | style->Colors[ImGuiCol_TextDisabled] = ImVec4(0.86f, 0.93f, 0.89f, 0.78f); 66 | 67 | style->Colors[ImGuiCol_TitleBg] = mainColor; 68 | style->Colors[ImGuiCol_TitleBgActive] = mainColor; 69 | style->Colors[ImGuiCol_TitleBgCollapsed] = mainColor; 70 | 71 | 72 | style->Colors[ImGuiCol_WindowBg] = ImColor(25, 25, 25, 220); 73 | //style->Colors[ImGuiCol_FrameBg] = ImVec4(0.10f, 0.09f, 0.12f, 1.00f); 74 | style->Colors[ImGuiCol_FrameBg] = ImColor(21, 21, 21, 255); 75 | style->Colors[ImGuiCol_FrameBgHovered] = ImColor(59, 59, 59, 200); 76 | style->Colors[ImGuiCol_FrameBgActive] = ImColor(59, 59, 59, 200); 77 | 78 | style->Colors[ImGuiCol_Button] = ImColor(51, 51, 51, 150); 79 | style->Colors[ImGuiCol_ButtonHovered] = ImColor(64, 62, 64, 180); 80 | style->Colors[ImGuiCol_ButtonActive] = ImColor(3, 159, 0, 200); 81 | 82 | style->Colors[ImGuiCol_CheckMark] = ImColor(4, 158, 0, 155); 83 | 84 | 85 | 86 | 87 | style->Colors[ImGuiCol_SliderGrab] = ImColor(4, 158, 0, 155); 88 | style->Colors[ImGuiCol_SliderGrabActive] = ImColor(4, 168, 0, 155); 89 | 90 | 91 | style->Colors[ImGuiCol_Tab] = ImColor(51, 51, 51, 255); 92 | style->Colors[ImGuiCol_TabHovered] = ImColor(4, 168, 0, 155); 93 | style->Colors[ImGuiCol_TabActive] = ImColor(4, 158, 0, 155); 94 | style->Colors[ImGuiCol_TabUnfocused] = ImColor(51, 51, 51, 255); 95 | style->Colors[ImGuiCol_TabUnfocusedActive] = ImColor(4, 158, 0, 155); 96 | 97 | 98 | 99 | 100 | 101 | style->Colors[ImGuiCol_Text] = ImVec4(0.80f, 0.80f, 0.83f, 1.00f); 102 | style->Colors[ImGuiCol_TextDisabled] = ImVec4(0.24f, 0.23f, 0.29f, 1.00f); 103 | 104 | style->Colors[ImGuiCol_ChildWindowBg] = ImColor(0, 0, 0, 0); 105 | style->Colors[ImGuiCol_ChildBg] = ImColor(0, 0, 0, 0); 106 | 107 | style->Colors[ImGuiCol_TitleBgCollapsed] = ImColor(25, 25, 25, 220); 108 | 109 | style->Colors[ImGuiCol_Header] = ImColor(51, 51, 51, 220); 110 | style->Colors[ImGuiCol_HeaderHovered] = ImColor(51, 100, 51, 220); 111 | style->Colors[ImGuiCol_HeaderActive] = ImColor(51, 61, 51, 220); 112 | 113 | 114 | 115 | 116 | style->Colors[ImGuiCol_ScrollbarBg] = ImColor(30, 30, 30, 220); 117 | 118 | style->Colors[ImGuiCol_ScrollbarGrab] = ImColor(30, 110, 30, 220); 119 | style->Colors[ImGuiCol_ScrollbarGrabHovered] = ImColor(30, 110, 30, 220); 120 | style->Colors[ImGuiCol_ScrollbarGrabActive] = ImColor(30, 110, 30, 220); 121 | 122 | 123 | 124 | style->Colors[ImGuiCol_PopupBg] = ImColor(25, 25, 25, 220); 125 | 126 | 127 | style->Colors[ImGuiCol_Border] = ImColor(255, 255, 255, 0); 128 | style->Colors[ImGuiCol_BorderShadow] = ImColor(255, 255, 255, 0); 129 | 130 | style->Colors[ImGuiCol_MenuBarBg] = ImVec4(0.10f, 0.09f, 0.12f, 1.00f); 131 | 132 | 133 | style->Colors[ImGuiCol_Column] = ImVec4(0.56f, 0.56f, 0.58f, 1.00f); 134 | style->Colors[ImGuiCol_ColumnHovered] = ImVec4(0.24f, 0.23f, 0.29f, 1.00f); 135 | style->Colors[ImGuiCol_ColumnActive] = ImVec4(0.56f, 0.56f, 0.58f, 1.00f); 136 | style->Colors[ImGuiCol_ResizeGrip] = ImVec4(0.00f, 0.00f, 0.00f, 0.00f); 137 | style->Colors[ImGuiCol_ResizeGripHovered] = ImVec4(0.56f, 0.56f, 0.58f, 1.00f); 138 | style->Colors[ImGuiCol_ResizeGripActive] = ImVec4(0.06f, 0.05f, 0.07f, 1.00f); 139 | style->Colors[ImGuiCol_PlotLines] = ImVec4(0.40f, 0.39f, 0.38f, 0.63f); 140 | style->Colors[ImGuiCol_PlotLinesHovered] = ImVec4(0.25f, 1.00f, 0.00f, 1.00f); 141 | style->Colors[ImGuiCol_PlotHistogram] = ImVec4(0.40f, 0.39f, 0.38f, 0.63f); 142 | style->Colors[ImGuiCol_PlotHistogramHovered] = ImVec4(0.25f, 1.00f, 0.00f, 1.00f); 143 | style->Colors[ImGuiCol_TextSelectedBg] = ImVec4(0.25f, 1.00f, 0.00f, 0.43f); 144 | style->Colors[ImGuiCol_ModalWindowDarkening] = ImVec4(1.00f, 0.98f, 0.95f, 0.73f); 145 | 146 | 147 | 148 | 149 | /* 150 | style->WindowPadding = ImVec2(15, 15); 151 | style->WindowRounding = 5.0f; 152 | style->FramePadding = ImVec2(5, 5); 153 | style->FrameRounding = 4.0f; 154 | style->ItemSpacing = ImVec2(12, 8); 155 | style->ItemInnerSpacing = ImVec2(8, 6); 156 | style->IndentSpacing = 25.0f; 157 | style->ScrollbarSize = 15.0f; 158 | style->ScrollbarRounding = 9.0f; 159 | style->GrabMinSize = 5.0f; 160 | style->GrabRounding = 3.0f; 161 | 162 | style->Colors[ImGuiCol_Text] = ImVec4(0.80f, 0.80f, 0.83f, 1.00f); 163 | style->Colors[ImGuiCol_TextDisabled] = ImVec4(0.24f, 0.23f, 0.29f, 1.00f); 164 | style->Colors[ImGuiCol_WindowBg] = ImVec4(0.06f, 0.05f, 0.07f, 1.00f); 165 | style->Colors[ImGuiCol_ChildWindowBg] = ImVec4(0.07f, 0.07f, 0.09f, 1.00f); 166 | style->Colors[ImGuiCol_PopupBg] = ImVec4(0.07f, 0.07f, 0.09f, 1.00f); 167 | style->Colors[ImGuiCol_Border] = ImVec4(0.80f, 0.80f, 0.83f, 0.88f); 168 | style->Colors[ImGuiCol_BorderShadow] = ImVec4(0.92f, 0.91f, 0.88f, 0.00f); 169 | style->Colors[ImGuiCol_FrameBg] = ImVec4(0.10f, 0.09f, 0.12f, 1.00f); 170 | style->Colors[ImGuiCol_FrameBgHovered] = ImVec4(0.24f, 0.23f, 0.29f, 1.00f); 171 | style->Colors[ImGuiCol_FrameBgActive] = ImVec4(0.56f, 0.56f, 0.58f, 1.00f); 172 | style->Colors[ImGuiCol_TitleBg] = ImVec4(0.10f, 0.09f, 0.12f, 1.00f); 173 | style->Colors[ImGuiCol_TitleBgCollapsed] = ImVec4(1.00f, 0.98f, 0.95f, 0.75f); 174 | style->Colors[ImGuiCol_TitleBgActive] = ImVec4(0.07f, 0.07f, 0.09f, 1.00f); 175 | style->Colors[ImGuiCol_MenuBarBg] = ImVec4(0.10f, 0.09f, 0.12f, 1.00f); 176 | style->Colors[ImGuiCol_ScrollbarBg] = ImVec4(0.10f, 0.09f, 0.12f, 1.00f); 177 | style->Colors[ImGuiCol_ScrollbarGrab] = ImVec4(0.80f, 0.80f, 0.83f, 0.31f); 178 | style->Colors[ImGuiCol_ScrollbarGrabHovered] = ImVec4(0.56f, 0.56f, 0.58f, 1.00f); 179 | style->Colors[ImGuiCol_ScrollbarGrabActive] = ImVec4(0.06f, 0.05f, 0.07f, 1.00f); 180 | style->Colors[ImGuiCol_CheckMark] = ImVec4(0.80f, 0.80f, 0.83f, 0.31f); 181 | style->Colors[ImGuiCol_SliderGrab] = ImVec4(0.80f, 0.80f, 0.83f, 0.31f); 182 | style->Colors[ImGuiCol_SliderGrabActive] = ImVec4(0.06f, 0.05f, 0.07f, 1.00f); 183 | style->Colors[ImGuiCol_Button] = ImVec4(0.10f, 0.09f, 0.12f, 1.00f); 184 | style->Colors[ImGuiCol_ButtonHovered] = ImVec4(0.24f, 0.23f, 0.29f, 1.00f); 185 | style->Colors[ImGuiCol_ButtonActive] = ImVec4(0.56f, 0.56f, 0.58f, 1.00f); 186 | style->Colors[ImGuiCol_Header] = ImVec4(0.10f, 0.09f, 0.12f, 1.00f); 187 | style->Colors[ImGuiCol_HeaderHovered] = ImVec4(0.56f, 0.56f, 0.58f, 1.00f); 188 | style->Colors[ImGuiCol_HeaderActive] = ImVec4(0.06f, 0.05f, 0.07f, 1.00f); 189 | style->Colors[ImGuiCol_Column] = ImVec4(0.56f, 0.56f, 0.58f, 1.00f); 190 | style->Colors[ImGuiCol_ColumnHovered] = ImVec4(0.24f, 0.23f, 0.29f, 1.00f); 191 | style->Colors[ImGuiCol_ColumnActive] = ImVec4(0.56f, 0.56f, 0.58f, 1.00f); 192 | style->Colors[ImGuiCol_ResizeGrip] = ImVec4(0.00f, 0.00f, 0.00f, 0.00f); 193 | style->Colors[ImGuiCol_ResizeGripHovered] = ImVec4(0.56f, 0.56f, 0.58f, 1.00f); 194 | style->Colors[ImGuiCol_ResizeGripActive] = ImVec4(0.06f, 0.05f, 0.07f, 1.00f); 195 | style->Colors[ImGuiCol_PlotLines] = ImVec4(0.40f, 0.39f, 0.38f, 0.63f); 196 | style->Colors[ImGuiCol_PlotLinesHovered] = ImVec4(0.25f, 1.00f, 0.00f, 1.00f); 197 | style->Colors[ImGuiCol_PlotHistogram] = ImVec4(0.40f, 0.39f, 0.38f, 0.63f); 198 | style->Colors[ImGuiCol_PlotHistogramHovered] = ImVec4(0.25f, 1.00f, 0.00f, 1.00f); 199 | style->Colors[ImGuiCol_TextSelectedBg] = ImVec4(0.25f, 1.00f, 0.00f, 0.43f); 200 | style->Colors[ImGuiCol_ModalWindowDarkening] = ImVec4(1.00f, 0.98f, 0.95f, 0.73f); 201 | 202 | 203 | 204 | */ 205 | 206 | 207 | if (SUCCEEDED(pSwapchain->GetDevice(__uuidof(ID3D11Device), (void**)&pDevice))) { 208 | pSwapchain->GetDevice(__uuidof(pDevice), (void**)&pDevice); 209 | pDevice->GetImmediateContext(&pContext); 210 | } 211 | 212 | 213 | loadCall(pDevice); 214 | 215 | ImGui_ImplWin32_Init(targetWindow); 216 | ImGui_ImplDX11_Init(pDevice, pContext); 217 | 218 | //ImGui_ImplDX11_CreateDeviceObjects(); 219 | //imFont = io.Fonts->AddFontFromMemoryCompressedTTF(font_compressed_data, font_compressed_size, 14.f); 220 | //imFont = io.Fonts->AddFontDefault(); 221 | // Arial C:\Windows\Fonts\arial.ttf 222 | imFont = io.Fonts->AddFontDefault(); 223 | 224 | return; 225 | } 226 | void imgui_render::release() { 227 | 228 | 229 | 230 | pContext->OMSetRenderTargets(0, 0, 0); 231 | RenderTargetView->Release(); 232 | 233 | 234 | ImGui_ImplDX11_InvalidateDeviceObjects(); 235 | ImGui_ImplWin32_Shutdown(); 236 | ImGui_ImplDX11_Shutdown(); 237 | 238 | pDevice = nullptr; 239 | pContext = nullptr; 240 | RenderTargetView = nullptr; 241 | pSwapChain = nullptr; 242 | 243 | 244 | finishedInit = false; 245 | 246 | } 247 | void imgui_render::reset(UINT Width, UINT Height) { 248 | ID3D11Texture2D* pBuffer; 249 | pSwapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), 250 | (void**)&pBuffer); 251 | pDevice->CreateRenderTargetView(pBuffer, NULL, 252 | &RenderTargetView); 253 | // Perform error handling here! 254 | pBuffer->Release(); 255 | 256 | pContext->OMSetRenderTargets(1, &RenderTargetView, NULL); 257 | 258 | // Set up the viewport. 259 | D3D11_VIEWPORT vp; 260 | vp.Width = Width; 261 | vp.Height = Height; 262 | vp.MinDepth = 0.0f; 263 | vp.MaxDepth = 1.0f; 264 | vp.TopLeftX = 0; 265 | vp.TopLeftY = 0; 266 | pContext->RSSetViewports(1, &vp); 267 | 268 | } 269 | 270 | void imgui_render::BeginScene() { 271 | ImGuiIO& io = ImGui::GetIO(); 272 | 273 | 274 | 275 | 276 | 277 | 278 | if (RenderTargetView == nullptr) { 279 | ID3D11Texture2D* backbuffer = NULL; 280 | //hres = pSwapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), (LPVOID*)&backbuffer); 281 | 282 | hres = pSwapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), (LPVOID*)&backbuffer);//pSwapChain->GetBuffer(0, IID_PPV_ARGS(&backbuffer)); 283 | 284 | if (FAILED(hres)) { 285 | pContext->OMGetRenderTargets(1, &RenderTargetView, NULL); 286 | return; 287 | } 288 | 289 | 290 | hres = pSwapChain->GetDevice(IID_PPV_ARGS(&pDevice)); 291 | 292 | if (FAILED(hres)) { 293 | pContext->OMGetRenderTargets(1, &RenderTargetView, NULL); 294 | 295 | return; 296 | } 297 | 298 | 299 | hres = pDevice->CreateRenderTargetView(backbuffer, NULL, &RenderTargetView); 300 | backbuffer->Release(); 301 | if (FAILED(hres)) { 302 | return; 303 | } 304 | } 305 | pContext->OMSetRenderTargets(1, &RenderTargetView, NULL); 306 | //else { 307 | // pContext->OMSetRenderTargets(1, &RenderTargetView, NULL); 308 | //} 309 | 310 | ImGui_ImplDX11_NewFrame(); 311 | ImGui_ImplWin32_NewFrame(); 312 | ImGui::NewFrame(); 313 | 314 | ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0.0f); 315 | ImGui::PushStyleVar(ImGuiStyleVar_Alpha, 1.0f); 316 | ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, { 0.0f, 0.0f }); 317 | ImGui::PushStyleColor(ImGuiCol_WindowBg, { 0.0f, 0.0f, 0.0f, 0.0f }); 318 | ImGui::Begin("##Backbuffer", nullptr, ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoInputs); 319 | 320 | ImGui::SetWindowPos(ImVec2(0, 0), ImGuiCond_Always); 321 | ImGui::SetWindowSize(ImVec2(io.DisplaySize.x, io.DisplaySize.y), ImGuiCond_Always); 322 | } 323 | 324 | void imgui_render::Render() { 325 | ImGui::Render(); 326 | ImGui_ImplDX11_RenderDrawData(ImGui::GetDrawData()); 327 | } 328 | void imgui_render::EndScene() { 329 | ImGuiWindow* window = ImGui::GetCurrentWindow(); 330 | window->DrawList->PushClipRectFullScreen(); 331 | 332 | ImGui::End(); 333 | ImGui::PopStyleColor(); 334 | ImGui::PopStyleVar(3); 335 | 336 | ImGui::EndFrame(); 337 | } 338 | 339 | bool inScreen(ImVec2 pos) { 340 | if (pos.x < 0 || pos.y < 0 || pos.x > ImGui::GetIO().DisplaySize.x || pos.y > ImGui::GetIO().DisplaySize.y) { 341 | return false; 342 | } 343 | 344 | return true; 345 | } 346 | 347 | float imgui_render::RenderText(const std::string& text, const ImVec2& position, float size, RGBA color, bool center, bool outine) { 348 | ImGuiWindow* window = ImGui::GetCurrentWindow(); 349 | 350 | 351 | std::stringstream stream(text); 352 | std::string line; 353 | 354 | float y = 0.0f; 355 | int i = 0; 356 | while (std::getline(stream, line)) { 357 | ImVec2 textSize = imFont->CalcTextSizeA(size, FLT_MAX, 0.0f, text.c_str()); 358 | 359 | if (center) { 360 | if (outine) { 361 | window->DrawList->AddText(imFont, size, { (position.x - textSize.x / 2.0f) + 1.0f, (position.y + textSize.y * i) + 1.0f }, IM_COL32(0, 0, 0, color.a), text.c_str()); 362 | window->DrawList->AddText(imFont, size, { (position.x - textSize.x / 2.0f) - 1.0f, (position.y + textSize.y * i) - 1.0f }, IM_COL32(0, 0, 0, color.a), text.c_str()); 363 | window->DrawList->AddText(imFont, size, { (position.x - textSize.x / 2.0f) + 1.0f, (position.y + textSize.y * i) - 1.0f }, IM_COL32(0, 0, 0, color.a), text.c_str()); 364 | window->DrawList->AddText(imFont, size, { (position.x - textSize.x / 2.0f) - 1.0f, (position.y + textSize.y * i) + 1.0f }, IM_COL32(0, 0, 0, color.a), text.c_str()); 365 | } 366 | window->DrawList->AddText(imFont, size, { position.x - textSize.x / 2.0f, position.y + textSize.y * i }, IM_COL32(color.r, color.g, color.b, color.a), text.c_str()); 367 | } else { 368 | if (outine) { 369 | window->DrawList->AddText(imFont, size, { (position.x) + 1.0f, (position.y + textSize.y * i) + 1.0f }, IM_COL32(0, 0, 0, color.a), text.c_str()); 370 | window->DrawList->AddText(imFont, size, { (position.x) - 1.0f, (position.y + textSize.y * i) - 1.0f }, IM_COL32(0, 0, 0, color.a), text.c_str()); 371 | window->DrawList->AddText(imFont, size, { (position.x) + 1.0f, (position.y + textSize.y * i) - 1.0f }, IM_COL32(0, 0, 0, color.a), text.c_str()); 372 | window->DrawList->AddText(imFont, size, { (position.x) - 1.0f, (position.y + textSize.y * i) + 1.0f }, IM_COL32(0, 0, 0, color.a), text.c_str()); 373 | } 374 | window->DrawList->AddText(imFont, size, { position.x, position.y + textSize.y * i }, IM_COL32(color.r, color.g, color.b, color.a), text.c_str()); 375 | } 376 | 377 | y = position.y + textSize.y * (i + 1); 378 | i++; 379 | } 380 | 381 | return y; 382 | } 383 | 384 | void imgui_render::RenderDot(const ImVec2& from, const ImVec2& to, RGBA color, float thickness) { 385 | 386 | //DrawRect(x - 1.0f, y - 1.0f, width + 2.0f, height + 2.0f, D3DCOLOR_RGBA(0, 0, 0, 1)); 387 | //DrawRect(x, y, width, height, dColor); 388 | 389 | //imgui_render::RenderRect(ImVec2(from.x - 1, from.y - 1), ImVec2(to.x + 2, to.y + 2), RGBA(0, 0, 0, 255), 1.0f, 0, thickness); 390 | if (inScreen(from) && inScreen(to)) 391 | imgui_render::RenderRect(from, to, color, 5.0f, 0, thickness); 392 | } 393 | 394 | void imgui_render::RenderLine(const ImVec2& from, const ImVec2& to, RGBA color, float thickness) { 395 | ImGuiWindow* window = ImGui::GetCurrentWindow(); 396 | 397 | if (inScreen(from) && inScreen(to)) 398 | window->DrawList->AddLine(from, to, IM_COL32(color.r, color.g, color.b, color.a), thickness); 399 | } 400 | 401 | void imgui_render::RenderCircle(const ImVec2& position, float radius, RGBA color, float thickness, uint32_t segments) { 402 | ImGuiWindow* window = ImGui::GetCurrentWindow(); 403 | 404 | 405 | if (inScreen(position)) 406 | window->DrawList->AddCircle(position, radius, IM_COL32(color.r, color.g, color.b, color.a), segments, thickness); 407 | } 408 | 409 | void imgui_render::RenderCircleFilled(const ImVec2& position, float radius, RGBA color, uint32_t segments) { 410 | ImGuiWindow* window = ImGui::GetCurrentWindow(); 411 | 412 | if (inScreen(position)) 413 | window->DrawList->AddCircleFilled(position, radius, IM_COL32(color.r, color.g, color.b, color.a), segments); 414 | } 415 | 416 | void imgui_render::RenderRect(const ImVec2& from, const ImVec2& to, RGBA color, float rounding, uint32_t roundingCornersFlags, float thickness) { 417 | ImGuiWindow* window = ImGui::GetCurrentWindow(); 418 | 419 | if (inScreen(from) && inScreen(to)) 420 | window->DrawList->AddRect(from, to, IM_COL32(color.r, color.g, color.b, color.a), rounding, roundingCornersFlags, thickness); 421 | } 422 | 423 | void imgui_render::RenderRectFilled(const ImVec2& from, const ImVec2& to, RGBA color, float rounding, uint32_t roundingCornersFlags) { 424 | ImGuiWindow* window = ImGui::GetCurrentWindow(); 425 | 426 | if (inScreen(from) && inScreen(to)) 427 | window->DrawList->AddRectFilled(from, to, IM_COL32(color.r, color.g, color.b, color.a), rounding, roundingCornersFlags); 428 | } 429 | 430 | 431 | -------------------------------------------------------------------------------- /immunity-gta5/game.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "imports.h" 3 | #include "database.hpp" 4 | 5 | 6 | namespace game { 7 | int menu_key = VK_END; 8 | int game_ticks = 0; 9 | float tick_ms = 0.f; 10 | bool visible_peds[1024] = {0}; 11 | 12 | 13 | 14 | DWORD freemode_f = 0x9C9EFFD8; 15 | DWORD freemode_m = 0x705E61F2; 16 | bool isValidPlayer(DWORD hash, CObject* player) { 17 | if(!config::get("misc", "misc_show_npcs", 0) && !config::get("misc", "misc_npc_only", 0)) { 18 | return hash == freemode_f || hash == freemode_m; 19 | } else if(config::get("misc", "misc_show_npcs", 0) && !config::get("misc", "misc_npc_only", 0)) { 20 | return true; 21 | } else if(config::get("misc", "misc_npc_only", 0)) { 22 | return hash != freemode_f && hash != freemode_m; 23 | } 24 | return false; 25 | } 26 | 27 | int update_calls = 0; 28 | 29 | void update_visiblity() { 30 | update_calls ++; 31 | if (update_calls < config::get("misc", "visibility_update_time", 0) && config::get("misc", "visibility_update_enable", 0)) return; 32 | 33 | if(IsValidPtr(Game.ReplayInterface) && IsValidPtr(Game.ReplayInterface->ped_interface)) { 34 | if(IsValidPtr(local.player)) { 35 | 36 | DWORD handle = pointer_to_handle((uintptr_t)local.player); 37 | 38 | auto localplayerHand = GetBonePosition(local.player, RIGHT_HAND); // right hand -> 6 39 | for(int i = 0; i < Game.ReplayInterface->ped_interface->max_peds; i++) { 40 | auto tmpEntity = reinterpret_cast(Game.ReplayInterface->ped_interface->get_ped(i)); 41 | if(IsValidPtr(tmpEntity)) { 42 | //cout << "tmpEntity" << endl; 43 | 44 | if(get_distance(local.player->fPosition, tmpEntity->fPosition) > config::get("hack", "max_range", 1000.f)) continue; 45 | 46 | DWORD hash = tmpEntity->ModelInfo()->GetHash(); 47 | if(!game::isValidPlayer(hash, tmpEntity)) continue; 48 | 49 | 50 | ImVec2 screen; 51 | if(!WorldToScreen2(tmpEntity->fPosition, &screen)) continue; 52 | if(!isW2SValid(screen)) continue; 53 | 54 | PVector3 EmtVecMap(0, 0, 0); 55 | RawRaycastResult RaycastResultMap; 56 | PVector3 HitCordMap(0, 0, 0); 57 | 58 | 59 | auto tmpEntityHead = GetBonePosition(tmpEntity, HEAD); //HEAD 60 | 61 | DWORD flags = IntersectMap; 62 | 63 | if (config::get("misc", "misc_include_vegetation", 1)) { 64 | flags |= IntersectVegetation; 65 | } 66 | if (config::get("misc", "misc_include_vehicles", 1)) { 67 | flags |= IntersectVehicles; 68 | } 69 | if (config::get("misc", "misc_include_objects", 0)) { 70 | flags |= IntersectObjects; 71 | } 72 | 73 | DWORD Raycast = _START_SHAPE_TEST_CAPSULE(PVector3(localplayerHand.x, localplayerHand.y, localplayerHand.z), PVector3(tmpEntityHead.x, tmpEntityHead.y, tmpEntityHead.z), 0.0f, (IntersectOptions)flags, (DWORD)0, 7); 74 | //DWORD Raycast = _START_SHAPE_TEST_CAPSULE(PVector3(tmpLocalRightHand.x, tmpLocalRightHand.y, tmpLocalRightHand.z), PVector3(tmpEntityHead.x, tmpEntityHead.y, tmpEntityHead.z), 0.0f, (IntersectOptions)flags, (DWORD)handle, 7); 75 | 76 | if (Raycast) { 77 | _GET_RAYCAST_RESULT(Raycast, &RaycastResultMap.DidHitAnything, &HitCordMap, &EmtVecMap, &RaycastResultMap.HitEntity); 78 | 79 | if (RaycastResultMap.DidHitAnything) { 80 | visible_peds[i] = false; 81 | } else { 82 | visible_peds[i] = true; 83 | } 84 | } 85 | 86 | 87 | } 88 | } 89 | } 90 | } 91 | return; 92 | } 93 | 94 | //std::atomic x = 0; 95 | //vector>> bone_position_list; 96 | map > bone_position_list; 97 | //map bone_positions[1000]; 98 | 99 | map> temp; 100 | void update_skeleton() { 101 | if(IsValidPtr(local.player)) { 102 | //cout << "update_skeleton" << endl; 103 | if(IsValidPtr(Game.ReplayInterface) && IsValidPtr(Game.ReplayInterface->ped_interface)) { 104 | temp.clear(); 105 | for(int i = 0; i < Game.ReplayInterface->ped_interface->max_peds; i++) { 106 | CObject* ped = reinterpret_cast(Game.ReplayInterface->ped_interface->get_ped(i)); 107 | if(IsValidPtr(ped)) { 108 | if(get_distance(local.player->fPosition, ped->fPosition) > config::get("hack", "max_range", 1000.f)) continue; 109 | 110 | //only update if onscreen 111 | 112 | 113 | try { 114 | ImVec2 screen; 115 | if(!WorldToScreen(ped->fPosition, &screen)) continue; 116 | if(isW2SValid(screen)) { 117 | map bone_map; 118 | 119 | bone_map[HEAD] = GetBonePosition(ped, HEAD); 120 | bone_map[NECK] = GetBonePosition(ped, NECK); 121 | 122 | 123 | bone_map[RIGHT_UPPER_ARM] = GetBonePosition(ped, RIGHT_UPPER_ARM); 124 | bone_map[RIGHT_FOREARM] = GetBonePosition(ped, RIGHT_FOREARM); 125 | bone_map[RIGHT_HAND] = GetBonePosition(ped, RIGHT_HAND); 126 | 127 | 128 | bone_map[LEFT_UPPER_ARM] = GetBonePosition(ped, LEFT_UPPER_ARM); 129 | bone_map[LEFT_FOREARM] = GetBonePosition(ped, LEFT_FOREARM); 130 | bone_map[LEFT_HAND] = GetBonePosition(ped, LEFT_HAND); 131 | 132 | 133 | bone_map[SPINE3] = GetBonePosition(ped, SPINE3); 134 | bone_map[SPINE2] = GetBonePosition(ped, SPINE2); 135 | bone_map[SPINE1] = GetBonePosition(ped, SPINE1); 136 | bone_map[SPINE_ROOT] = GetBonePosition(ped, SPINE_ROOT); 137 | 138 | 139 | bone_map[RIGHT_THIGH] = GetBonePosition(ped, RIGHT_THIGH); 140 | bone_map[RIGHT_CALF] = GetBonePosition(ped, RIGHT_CALF); 141 | bone_map[RIGHT_FOOT] = GetBonePosition(ped, RIGHT_FOOT); 142 | 143 | 144 | bone_map[LEFT_THIGH] = GetBonePosition(ped, LEFT_THIGH); 145 | bone_map[LEFT_CALF] = GetBonePosition(ped, LEFT_CALF); 146 | bone_map[LEFT_FOOT] = GetBonePosition(ped, LEFT_FOOT); 147 | 148 | temp[i] = bone_map; 149 | //temp.insert(make_pair(i, bone_map)); 150 | } 151 | } catch(const std::exception& e) { 152 | 153 | printf("err skeleton %s\n", e.what()); 154 | } 155 | } 156 | } 157 | bone_position_list.clear(); 158 | bone_position_list = temp; 159 | } 160 | } 161 | } 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | void crosshair() { 170 | 171 | RGBA CrosshairColorRGBA = RGBA( 172 | (float)config::get("visual", "crosshair_color_r", 1.f) * 255, 173 | (float)config::get("visual", "crosshair_color_g", 1.f) * 255, 174 | (float)config::get("visual", "crosshair_color_b", 1.f) * 255, 175 | (float)config::get("visual", "crosshair_color_a", 1.f) * 255 176 | ); 177 | 178 | int ScreenWidth = ImGui::GetIO().DisplaySize.x; 179 | int ScreenHeight = ImGui::GetIO().DisplaySize.y; 180 | 181 | ImVec2 Center = ImVec2(ScreenWidth / 2, ScreenHeight / 2); 182 | 183 | float gap = config::get("visual", "visual_crosshair_gap", 0.f); 184 | float thickness = config::get("visual", "visual_crosshair_thickness", 0.f); 185 | float width = config::get("visual", "visual_crosshair_width", 0.f); 186 | int border = config::get("visual", "visual_crosshair_border", 0); 187 | 188 | 189 | ImVec2 Center_Left = ImVec2(Center.x - gap, Center.y); 190 | ImVec2 Center_Left_End = ImVec2(Center.x - width, Center.y); 191 | if(border) { 192 | renderer.RenderLine(ImVec2(Center_Left.x + 1, Center_Left.y), ImVec2(Center_Left_End.x - 1, Center_Left_End.y), RGBA(0, 0, 0, 255), thickness + 2.0f); 193 | 194 | } 195 | renderer.RenderLine(Center_Left, Center_Left_End, CrosshairColorRGBA, thickness); 196 | 197 | 198 | ImVec2 Center_Right = ImVec2(Center.x + gap, Center.y); 199 | ImVec2 Center_Right_End = ImVec2(Center.x + width, Center.y); 200 | if(border) { 201 | renderer.RenderLine(ImVec2(Center_Right.x - 1, Center_Right.y), ImVec2(Center_Right_End.x + 1, Center_Right_End.y), RGBA(0, 0, 0, 255), thickness + 2.0f); 202 | } 203 | renderer.RenderLine(Center_Right, Center_Right_End, CrosshairColorRGBA, thickness); 204 | 205 | 206 | 207 | ImVec2 Center_Top = ImVec2(Center.x, Center.y - gap); 208 | ImVec2 Center_Top_End = ImVec2(Center.x, Center.y - width); 209 | if(border) { 210 | 211 | renderer.RenderLine(ImVec2(Center_Top.x, Center_Top.y + 1), ImVec2(Center_Top_End.x, Center_Top_End.y - 1), RGBA(0, 0, 0, 255), thickness + 2.0f); 212 | } 213 | renderer.RenderLine(Center_Top, Center_Top_End, CrosshairColorRGBA, thickness); 214 | 215 | 216 | 217 | 218 | ImVec2 Center_Bottom = ImVec2(Center.x, Center.y + gap); 219 | ImVec2 Center_Bottom_End = ImVec2(Center.x, Center.y + width); 220 | if(border) { 221 | renderer.RenderLine(ImVec2(Center_Bottom.x, Center_Bottom.y - 1), ImVec2(Center_Bottom_End.x, Center_Bottom_End.y + 1), RGBA(0, 0, 0, 255), thickness + 2.0f); 222 | } 223 | renderer.RenderLine(Center_Bottom, Center_Bottom_End, CrosshairColorRGBA, thickness); 224 | } 225 | 226 | 227 | void setFOV(float fov) { 228 | CPlayerAngles* cam = Game.getCam(); 229 | if(IsValidPtr(cam)) { 230 | cam->m_cam_data->Fov_Zoom = fov; 231 | } 232 | } 233 | 234 | 235 | 236 | vector> ped_list; 237 | vector object_list; 238 | vector vehicle_list; 239 | vector nearby_vehicle_list; 240 | 241 | 242 | map dummy_group; 243 | map dummy_group1; 244 | void update_vehicles() { 245 | if(IsValidPtr(Game.ReplayInterface) && IsValidPtr(Game.ReplayInterface->vehicle_interface)) { 246 | if(IsValidPtr(local.player)) { 247 | map veh_list_find = config::get("misc", "vehicle_esp_vehicle_list", dummy_group1); 248 | vector new_vehicle_list; 249 | vector new_nearby_vehicle_list; 250 | for(int i = 0; i < Game.ReplayInterface->vehicle_interface->max_vehicles; i++) { 251 | CVehicle* veh = reinterpret_cast(Game.ReplayInterface->vehicle_interface->get_vehicle(i)); 252 | 253 | if(IsValidPtr(veh)) { 254 | float dist = get_distance(local.player->fPosition, veh->fPosition); 255 | if(dist > config::get("hack", "max_range", 1000.f)) continue; 256 | 257 | 258 | if(dist < 50.f) { 259 | new_nearby_vehicle_list.push_back(veh); 260 | } 261 | 262 | 263 | 264 | DWORD hash = veh->ModelInfo()->GetHash(); 265 | //if (!game::isValidModel(hash)) continue; 266 | 267 | map::iterator it = veh_list_find.find(hash); 268 | if(config::get("misc", "vehicle_esp_all", 0) || (it != veh_list_find.end())) { 269 | new_vehicle_list.push_back(veh); 270 | } 271 | 272 | 273 | 274 | } 275 | } 276 | vehicle_list.clear(); 277 | vehicle_list = new_vehicle_list; 278 | 279 | 280 | nearby_vehicle_list.clear(); 281 | nearby_vehicle_list = new_nearby_vehicle_list; 282 | } 283 | } 284 | } 285 | void update_objects() { 286 | 287 | if(IsValidPtr(Game.ReplayInterface) && IsValidPtr(Game.ReplayInterface->object_interface)) { 288 | if(IsValidPtr(local.player)) { 289 | map object_findlist = config::get("misc", "object_esp_object_list", dummy_group1); 290 | vector new_obj_list; 291 | for(int i = 0; i < Game.ReplayInterface->object_interface->iMaxObjects; i++) { 292 | CObject* obj = reinterpret_cast(Game.ReplayInterface->object_interface->get_object(i)); 293 | 294 | 295 | if(IsValidPtr(obj)) { 296 | float dist = get_distance(local.player->fPosition, obj->fPosition); 297 | if(dist > config::get("hack", "max_range", 1000.f)) continue; 298 | 299 | DWORD hash = obj->ModelInfo()->GetHash(); 300 | //if (!game::isValidModel(hash)) continue; 301 | 302 | map::iterator it = object_findlist.find(hash); 303 | if(config::get("misc", "object_esp_all", 0) || 304 | (it != object_findlist.end()) 305 | ) { 306 | new_obj_list.push_back(obj); 307 | } 308 | } 309 | } 310 | object_list.clear(); 311 | object_list = new_obj_list; 312 | } 313 | } 314 | } 315 | using std::chrono::high_resolution_clock; 316 | using std::chrono::duration_cast; 317 | using std::chrono::duration; 318 | using std::chrono::milliseconds; 319 | void update_peds() { 320 | if(IsValidPtr(Game.ReplayInterface) && IsValidPtr(Game.ReplayInterface->ped_interface)) { 321 | if(IsValidPtr(local.player)) { 322 | map group_list = config::get("hack", "group_list", dummy_group); 323 | vector> new_list; 324 | for(int i = 0; i < Game.ReplayInterface->ped_interface->max_peds; i++) { 325 | CObject* ped = reinterpret_cast(Game.ReplayInterface->ped_interface->get_ped(i)); 326 | 327 | if(IsValidPtr(ped)) { 328 | if(ped->HP <= 0) continue; 329 | if(!config::get("visual", "esp_self", 0) && local.player == ped) continue; 330 | if(get_distance(local.player->fPosition, ped->fPosition) > config::get("hack", "max_range", 1000.f)) continue; 331 | DWORD hash = ped->ModelInfo()->GetHash(); 332 | if(!game::isValidPlayer(hash, ped)) continue; 333 | if(config::get("misc", "ignore_invisible", 0) && (ped->GetAlpha() < config::get("misc", "alpha_threshold", 0.f))) continue; 334 | if(config::get("misc", "force_visible", 0)) { 335 | if(ped->GetAlpha() < config::get("misc", "alpha_threshold", 0.f)) { 336 | ped->SetAlpha(config::get("misc", "alpha_threshold", 0.f)); 337 | } 338 | } 339 | 340 | 341 | if(config::get("misc", "hide_anticheat_npcs", 0)) { 342 | auto handle = pointer_to_handle((uintptr_t)ped); 343 | if (handle) { 344 | 345 | if (native::brain::get_is_task_active(handle, 221) || 346 | native::brain::get_is_task_active(handle, 222) || 347 | native::brain::get_is_task_active(handle, 241) || 348 | native::brain::get_is_task_active(handle, 151) || 349 | native::brain::get_is_task_active(handle, 138) || 350 | native::brain::get_is_task_active(handle, 100) || 351 | native::brain::get_is_task_active(handle, 218) || 352 | native::brain::get_is_task_active(handle, 220) || 353 | native::brain::get_is_task_active(handle, 34) || 354 | native::brain::get_is_task_active(handle, 101)) continue; 355 | } 356 | } 357 | 358 | 359 | 360 | DataPed PedData; 361 | PedData.index = i; 362 | PedData.visible = visible_peds[i] || false; 363 | 364 | 365 | //Fetch Group 366 | string group_name = "\0"; 367 | if((config::get("hack", "group_window", 0)) || config::get("visual", "display_groups", 0) || config::get("aimbot", "aim_only_groups", 0)) { 368 | string componentId = GetPedComponentHash(ped); 369 | map::iterator it = group_list.find(componentId); 370 | if(it != group_list.end()) { 371 | string cid = it->first; 372 | string dataString = it->second; 373 | if(cid == "") continue; 374 | if(cid.size() == 0) continue; 375 | if(dataString == "") continue; 376 | if(dataString.size() == 0) continue; 377 | json data = json::parse(dataString); 378 | string name = data["name"]; 379 | 380 | 381 | PedData.group.inGroup = true; 382 | PedData.group.name = name; 383 | 384 | PedData.group.ally = data["ally"]; 385 | 386 | if(PedData.visible) { 387 | PedData.group.color = RGBA( 388 | (float)data["visible_color_r"] * 255, 389 | (float)data["visible_color_g"] * 255, 390 | (float)data["visible_color_b"] * 255, 391 | (float)data["visible_color_a"] * 255 392 | ); 393 | } else { 394 | PedData.group.color = RGBA( 395 | (float)data["invisible_color_r"] * 255, 396 | (float)data["invisible_color_g"] * 255, 397 | (float)data["invisible_color_b"] * 255, 398 | (float)data["invisible_color_a"] * 255 399 | ); 400 | } 401 | } 402 | } 403 | 404 | if(config::get("aimbot", "enable", 0) || (config::get("visual", "enable", 0) && config::get("visual", "draw_skeleton", 0))) { 405 | 406 | 407 | ImVec2 screen; 408 | 409 | if(WorldToScreen2(ped->fPosition, &screen)) { 410 | if(isW2SValid(screen)) { 411 | PedData.bones.HEAD = GetBonePosition(ped, HEAD); 412 | PedData.bones.NECK = GetBonePosition(ped, NECK); 413 | 414 | 415 | PedData.bones.RIGHT_UPPER_ARM = GetBonePosition(ped, RIGHT_UPPER_ARM); 416 | PedData.bones.RIGHT_FOREARM = GetBonePosition(ped, RIGHT_FOREARM); 417 | PedData.bones.RIGHT_HAND = GetBonePosition(ped, RIGHT_HAND); 418 | 419 | 420 | PedData.bones.LEFT_UPPER_ARM = GetBonePosition(ped, LEFT_UPPER_ARM); 421 | PedData.bones.LEFT_FOREARM = GetBonePosition(ped, LEFT_FOREARM); 422 | PedData.bones.LEFT_HAND = GetBonePosition(ped, LEFT_HAND); 423 | 424 | 425 | PedData.bones.SPINE3 = GetBonePosition(ped, SPINE3); 426 | PedData.bones.SPINE2 = GetBonePosition(ped, SPINE2); 427 | PedData.bones.SPINE1 = GetBonePosition(ped, SPINE1); 428 | PedData.bones.SPINE_ROOT = GetBonePosition(ped, SPINE_ROOT); 429 | 430 | 431 | PedData.bones.RIGHT_THIGH = GetBonePosition(ped, RIGHT_THIGH); 432 | PedData.bones.RIGHT_CALF = GetBonePosition(ped, RIGHT_CALF); 433 | PedData.bones.RIGHT_FOOT = GetBonePosition(ped, RIGHT_FOOT); 434 | 435 | 436 | PedData.bones.LEFT_THIGH = GetBonePosition(ped, LEFT_THIGH); 437 | PedData.bones.LEFT_CALF = GetBonePosition(ped, LEFT_CALF); 438 | PedData.bones.LEFT_FOOT = GetBonePosition(ped, LEFT_FOOT); 439 | } 440 | } 441 | } 442 | 443 | new_list.push_back(pair(ped, PedData)); 444 | } 445 | } 446 | ped_list.clear(); 447 | ped_list = new_list; 448 | } 449 | } 450 | 451 | } 452 | 453 | 454 | void tick() { 455 | if(IsValidPtr(local.player)) { 456 | //GAME TICK!! 457 | if(config::get("visual", "enable", 0) || config::get("aimbot", "enable", 0)) { 458 | update_visiblity(); 459 | } 460 | if(config::get("visual", "enable", 0) || config::get("aimbot", "enable", 0)) { 461 | update_peds(); 462 | } 463 | 464 | hacks::game_tick(); 465 | 466 | if((config::get("aimbot", "aim_mode", 0) == 3) && config::get("aimbot", "enable", 0)) { 467 | aimbot::do_silent_aim(); 468 | } 469 | 470 | return; 471 | } 472 | } 473 | 474 | void render() { 475 | if(!Game.running) return; 476 | if(config::get("hack", "watermark", 1)) { 477 | renderer.RenderText("immunity gta5", ImVec2(0, 13), 13.f, RGBA(255, 255, 255, 255), false, true); 478 | } 479 | 480 | 481 | if(config::get("hack", "screenshot_warning", 1)) { 482 | if(Game.renderMethod == 2) { 483 | renderer.RenderText("The Cheat renders using its own renderer\nIngame screenshots might show it.\nThis warning can be disabled in settings ('Screen Warning')", ImVec2(Game.screen.x / 2, (Game.screen.y / 2) - 50.f), 13.f, RGBA(255, 0, 0, 255), true, true); 484 | Game.menuOpen = true; 485 | ui::changeTab(4); 486 | } 487 | } 488 | 489 | 490 | 491 | if(Game.World != nullptr) { 492 | local.player = Game.World->getLocalPlayer(); 493 | 494 | if(local.player) { 495 | if(config::get("misc", "object_esp", 0)) { 496 | update_objects(); 497 | } 498 | if(config::get("misc", "misc_vehicle_esp", 0) || config::get("hacks", "unlock_nearby", 0) || config::get("hacks", "no_collision_veh", 0)) { 499 | update_vehicles(); 500 | } 501 | esp::render(); 502 | } 503 | if(config::get("visual", "visual_crosshair", 0)) { 504 | crosshair(); 505 | } 506 | 507 | if(config::get("aimbot", "show_aim_radius", 0)) { 508 | int w = ImGui::GetIO().DisplaySize.x; 509 | int h = ImGui::GetIO().DisplaySize.y; 510 | renderer.RenderCircle(ImVec2(w / 2, h / 2), config::get("aimbot", "aim_radius", 50.f), RGBA(0, 255, 0, 150), 1.0f, 50); 511 | if(config::get("aimbot", "aim_stop_radius", 0.f) > 0.f) { 512 | renderer.RenderCircle(ImVec2(w / 2, h / 2), config::get("aimbot", "aim_stop_radius", 0.f), RGBA(255, 0, 0, 150), 1.0f, 50); 513 | } 514 | } 515 | 516 | if(config::get("hacks", "custom_fov", 0)) { 517 | setFOV(config::get("hacks", "custom_fov_value", 50.f)); 518 | } 519 | 520 | if(config::get("hacks", "freecam_steal", 0) && config::get("hacks", "freecam_enabled", 0)) { 521 | 522 | ImVec2 Center = ImVec2(ImGui::GetIO().DisplaySize.x / 2, ImGui::GetIO().DisplaySize.y / 2); 523 | renderer.RenderLine(ImVec2(Center.x - 25.f, Center.y), ImVec2(Center.x + 25.f, Center.y), RGBA(0, 255, 0, 255), 2.0f); 524 | renderer.RenderLine(ImVec2(Center.x, Center.y - 25.f), ImVec2(Center.x, Center.y + 25.f), RGBA(0, 255, 0, 255), 2.0f); 525 | 526 | if(hacks::freecam::target_entity != 0) { 527 | renderer.RenderText("[LMB] to Steal", ImVec2(Game.screen.x / 2, (Game.screen.y / 2) + 17), 13.f, RGBA(255, 255, 255, 255), true, true); 528 | } 529 | } 530 | 531 | 532 | 533 | } 534 | if(Game.menuOpen) { 535 | ui::render(); 536 | } 537 | } 538 | } -------------------------------------------------------------------------------- /includes/ini.h: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * Copyright (c) 2018 Danijel Durakovic 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | * this software and associated documentation files (the "Software"), to deal in 7 | * the Software without restriction, including without limitation the rights to 8 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 9 | * of the Software, and to permit persons to whom the Software is furnished to do 10 | * so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in all 13 | * copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | * 22 | */ 23 | 24 | /////////////////////////////////////////////////////////////////////////////// 25 | // 26 | // /mINI/ v0.9.7 27 | // An INI file reader and writer for the modern age. 28 | // 29 | /////////////////////////////////////////////////////////////////////////////// 30 | // 31 | // A tiny utility library for manipulating INI files with a straightforward 32 | // API and a minimal footprint. It conforms to the (somewhat) standard INI 33 | // format - sections and keys are case insensitive and all leading and 34 | // trailing whitespace is ignored. Comments are lines that begin with a 35 | // semicolon. Trailing comments are allowed on section lines. 36 | // 37 | // Files are read on demand, upon which data is kept in memory and the file 38 | // is closed. This utility supports lazy writing, which only writes changes 39 | // and updates to a file and preserves custom formatting and comments. A lazy 40 | // write invoked by a write() call will read the output file, find what 41 | // changes have been made and update the file accordingly. If you only need to 42 | // generate files, use generate() instead. Section and key order is preserved 43 | // on read, write and insert. 44 | // 45 | /////////////////////////////////////////////////////////////////////////////// 46 | // 47 | // /* BASIC USAGE EXAMPLE: */ 48 | // 49 | // /* read from file */ 50 | // mINI::INIFile file("myfile.ini"); 51 | // mINI::INIStructure ini; 52 | // file.read(ini); 53 | // 54 | // /* read value; gets a reference to actual value in the structure. 55 | // if key or section don't exist, a new empty value will be created */ 56 | // std::string& value = ini["section"]["key"]; 57 | // 58 | // /* read value safely; gets a copy of value in the structure. 59 | // does not alter the structure */ 60 | // std::string value = ini.get("section").get("key"); 61 | // 62 | // /* set or update values */ 63 | // ini["section"]["key"] = "value"; 64 | // 65 | // /* set multiple values */ 66 | // ini["section2"].set({ 67 | // {"key1", "value1"}, 68 | // {"key2", "value2"} 69 | // }); 70 | // 71 | // /* write updates back to file, preserving comments and formatting */ 72 | // file.write(ini); 73 | // 74 | // /* or generate a file (overwrites the original) */ 75 | // file.generate(ini); 76 | // 77 | /////////////////////////////////////////////////////////////////////////////// 78 | // 79 | // Long live the INI file!!! 80 | // 81 | /////////////////////////////////////////////////////////////////////////////// 82 | 83 | #ifndef MINI_INI_H_ 84 | #define MINI_INI_H_ 85 | 86 | #include 87 | #include 88 | #include 89 | #include 90 | #include 91 | #include 92 | #include 93 | #include 94 | #include 95 | 96 | namespace mINI 97 | { 98 | namespace INIStringUtil 99 | { 100 | const std::string whitespaceDelimiters = " \t\n\r\f\v"; 101 | inline void trim(std::string& str) 102 | { 103 | str.erase(str.find_last_not_of(whitespaceDelimiters) + 1); 104 | str.erase(0, str.find_first_not_of(whitespaceDelimiters)); 105 | } 106 | #ifndef MINI_CASE_SENSITIVE 107 | inline void toLower(std::string& str) 108 | { 109 | std::transform(str.begin(), str.end(), str.begin(), ::tolower); 110 | } 111 | #endif 112 | inline void replace(std::string& str, std::string const& a, std::string const& b) 113 | { 114 | if (!a.empty()) 115 | { 116 | std::size_t pos = 0; 117 | while ((pos = str.find(a, pos)) != std::string::npos) 118 | { 119 | str.replace(pos, a.size(), b); 120 | pos += b.size(); 121 | } 122 | } 123 | } 124 | #ifdef _WIN32 125 | const std::string endl = "\r\n"; 126 | #else 127 | const std::string endl = "\n"; 128 | #endif 129 | }; 130 | 131 | template 132 | class INIMap 133 | { 134 | private: 135 | using T_DataIndexMap = std::unordered_map; 136 | using T_DataItem = std::pair; 137 | using T_DataContainer = std::vector; 138 | using T_MultiArgs = typename std::vector>; 139 | 140 | T_DataIndexMap dataIndexMap; 141 | T_DataContainer data; 142 | 143 | inline std::size_t setEmpty(std::string& key) 144 | { 145 | std::size_t index = data.size(); 146 | dataIndexMap[key] = index; 147 | data.emplace_back(key, T()); 148 | return index; 149 | } 150 | 151 | public: 152 | using const_iterator = typename T_DataContainer::const_iterator; 153 | 154 | INIMap() { } 155 | 156 | INIMap(INIMap const& other) 157 | { 158 | std::size_t data_size = other.data.size(); 159 | for (std::size_t i = 0; i < data_size; ++i) 160 | { 161 | auto const& key = other.data[i].first; 162 | auto const& obj = other.data[i].second; 163 | data.emplace_back(key, obj); 164 | } 165 | dataIndexMap = T_DataIndexMap(other.dataIndexMap); 166 | } 167 | 168 | T& operator[](std::string key) 169 | { 170 | INIStringUtil::trim(key); 171 | #ifndef MINI_CASE_SENSITIVE 172 | INIStringUtil::toLower(key); 173 | #endif 174 | auto it = dataIndexMap.find(key); 175 | bool hasIt = (it != dataIndexMap.end()); 176 | std::size_t index = (hasIt) ? it->second : setEmpty(key); 177 | return data[index].second; 178 | } 179 | T get(std::string key) const 180 | { 181 | INIStringUtil::trim(key); 182 | #ifndef MINI_CASE_SENSITIVE 183 | INIStringUtil::toLower(key); 184 | #endif 185 | auto it = dataIndexMap.find(key); 186 | if (it == dataIndexMap.end()) 187 | { 188 | return T(); 189 | } 190 | return T(data[it->second].second); 191 | } 192 | bool has(std::string key) const 193 | { 194 | INIStringUtil::trim(key); 195 | #ifndef MINI_CASE_SENSITIVE 196 | INIStringUtil::toLower(key); 197 | #endif 198 | return (dataIndexMap.count(key) == 1); 199 | } 200 | void set(std::string key, T obj) 201 | { 202 | INIStringUtil::trim(key); 203 | #ifndef MINI_CASE_SENSITIVE 204 | INIStringUtil::toLower(key); 205 | #endif 206 | auto it = dataIndexMap.find(key); 207 | if (it != dataIndexMap.end()) 208 | { 209 | data[it->second].second = obj; 210 | } 211 | else 212 | { 213 | dataIndexMap[key] = data.size(); 214 | data.emplace_back(key, obj); 215 | } 216 | } 217 | void set(T_MultiArgs const& multiArgs) 218 | { 219 | for (auto const& it : multiArgs) 220 | { 221 | auto const& key = it.first; 222 | auto const& obj = it.second; 223 | set(key, obj); 224 | } 225 | } 226 | bool remove(std::string key) 227 | { 228 | INIStringUtil::trim(key); 229 | #ifndef MINI_CASE_SENSITIVE 230 | INIStringUtil::toLower(key); 231 | #endif 232 | auto it = dataIndexMap.find(key); 233 | if (it != dataIndexMap.end()) 234 | { 235 | std::size_t index = it->second; 236 | data.erase(data.begin() + index); 237 | dataIndexMap.erase(it); 238 | for (auto& it2 : dataIndexMap) 239 | { 240 | auto& vi = it2.second; 241 | if (vi > index) 242 | { 243 | vi--; 244 | } 245 | } 246 | return true; 247 | } 248 | return false; 249 | } 250 | void clear() 251 | { 252 | data.clear(); 253 | dataIndexMap.clear(); 254 | } 255 | std::size_t size() const 256 | { 257 | return data.size(); 258 | } 259 | const_iterator begin() const { return data.begin(); } 260 | const_iterator end() const { return data.end(); } 261 | }; 262 | 263 | using INIStructure = INIMap>; 264 | 265 | namespace INIParser 266 | { 267 | using T_ParseValues = std::pair; 268 | 269 | enum class PDataType : char 270 | { 271 | PDATA_NONE, 272 | PDATA_COMMENT, 273 | PDATA_SECTION, 274 | PDATA_KEYVALUE, 275 | PDATA_UNKNOWN 276 | }; 277 | 278 | inline PDataType parseLine(std::string line, T_ParseValues& parseData) 279 | { 280 | parseData.first.clear(); 281 | parseData.second.clear(); 282 | INIStringUtil::trim(line); 283 | if (line.empty()) 284 | { 285 | return PDataType::PDATA_NONE; 286 | } 287 | char firstCharacter = line[0]; 288 | if (firstCharacter == ';') 289 | { 290 | return PDataType::PDATA_COMMENT; 291 | } 292 | if (firstCharacter == '[') 293 | { 294 | auto commentAt = line.find_first_of(';'); 295 | if (commentAt != std::string::npos) 296 | { 297 | line = line.substr(0, commentAt); 298 | } 299 | auto closingBracketAt = line.find_last_of(']'); 300 | if (closingBracketAt != std::string::npos) 301 | { 302 | auto section = line.substr(1, closingBracketAt - 1); 303 | INIStringUtil::trim(section); 304 | parseData.first = section; 305 | return PDataType::PDATA_SECTION; 306 | } 307 | } 308 | auto lineNorm = line; 309 | INIStringUtil::replace(lineNorm, "\\=", " "); 310 | auto equalsAt = lineNorm.find_first_of('='); 311 | if (equalsAt != std::string::npos) 312 | { 313 | auto key = line.substr(0, equalsAt); 314 | INIStringUtil::trim(key); 315 | INIStringUtil::replace(key, "\\=", "="); 316 | auto value = line.substr(equalsAt + 1); 317 | INIStringUtil::trim(value); 318 | parseData.first = key; 319 | parseData.second = value; 320 | return PDataType::PDATA_KEYVALUE; 321 | } 322 | return PDataType::PDATA_UNKNOWN; 323 | } 324 | }; 325 | 326 | class INIReader 327 | { 328 | public: 329 | using T_LineData = std::vector; 330 | using T_LineDataPtr = std::shared_ptr; 331 | 332 | private: 333 | std::ifstream fileReadStream; 334 | T_LineDataPtr lineData; 335 | 336 | T_LineData readFile() 337 | { 338 | std::string fileContents; 339 | fileReadStream.seekg(0, std::ios::end); 340 | fileContents.resize(fileReadStream.tellg()); 341 | fileReadStream.seekg(0, std::ios::beg); 342 | std::size_t fileSize = fileContents.size(); 343 | fileReadStream.read(&fileContents[0], fileSize); 344 | fileReadStream.close(); 345 | T_LineData output; 346 | if (fileSize == 0) 347 | { 348 | return output; 349 | } 350 | std::string buffer; 351 | buffer.reserve(50); 352 | for (std::size_t i = 0; i < fileSize; ++i) 353 | { 354 | char& c = fileContents[i]; 355 | if (c == '\n') 356 | { 357 | output.emplace_back(buffer); 358 | buffer.clear(); 359 | continue; 360 | } 361 | if (c != '\0' && c != '\r') 362 | { 363 | buffer += c; 364 | } 365 | } 366 | output.emplace_back(buffer); 367 | return output; 368 | } 369 | 370 | public: 371 | INIReader(std::string const& filename, bool keepLineData = false) 372 | { 373 | fileReadStream.open(filename, std::ios::in | std::ios::binary); 374 | if (keepLineData) 375 | { 376 | lineData = std::make_shared(); 377 | } 378 | } 379 | ~INIReader() { } 380 | 381 | bool operator>>(INIStructure& data) 382 | { 383 | if (!fileReadStream.is_open()) 384 | { 385 | return false; 386 | } 387 | T_LineData fileLines = readFile(); 388 | std::string section; 389 | bool inSection = false; 390 | INIParser::T_ParseValues parseData; 391 | for (auto const& line : fileLines) 392 | { 393 | auto parseResult = INIParser::parseLine(line, parseData); 394 | if (parseResult == INIParser::PDataType::PDATA_SECTION) 395 | { 396 | inSection = true; 397 | data[section = parseData.first]; 398 | } 399 | else if (inSection && parseResult == INIParser::PDataType::PDATA_KEYVALUE) 400 | { 401 | auto const& key = parseData.first; 402 | auto const& value = parseData.second; 403 | data[section][key] = value; 404 | } 405 | if (lineData && parseResult != INIParser::PDataType::PDATA_UNKNOWN) 406 | { 407 | if (parseResult == INIParser::PDataType::PDATA_KEYVALUE && !inSection) 408 | { 409 | continue; 410 | } 411 | lineData->emplace_back(line); 412 | } 413 | } 414 | return true; 415 | } 416 | T_LineDataPtr getLines() 417 | { 418 | return lineData; 419 | } 420 | }; 421 | 422 | class INIGenerator 423 | { 424 | private: 425 | std::ofstream fileWriteStream; 426 | 427 | public: 428 | bool prettyPrint = false; 429 | 430 | INIGenerator(std::string const& filename) 431 | { 432 | fileWriteStream.open(filename, std::ios::out | std::ios::binary); 433 | } 434 | ~INIGenerator() { } 435 | 436 | bool operator<<(INIStructure const& data) 437 | { 438 | if (!fileWriteStream.is_open()) 439 | { 440 | return false; 441 | } 442 | if (!data.size()) 443 | { 444 | return true; 445 | } 446 | auto it = data.begin(); 447 | for (;;) 448 | { 449 | auto const& section = it->first; 450 | auto const& collection = it->second; 451 | fileWriteStream 452 | << "[" 453 | << section 454 | << "]"; 455 | if (collection.size()) 456 | { 457 | fileWriteStream << INIStringUtil::endl; 458 | auto it2 = collection.begin(); 459 | for (;;) 460 | { 461 | auto key = it2->first; 462 | INIStringUtil::replace(key, "=", "\\="); 463 | auto value = it2->second; 464 | INIStringUtil::trim(value); 465 | fileWriteStream 466 | << key 467 | << ((prettyPrint) ? " = " : "=") 468 | << value; 469 | if (++it2 == collection.end()) 470 | { 471 | break; 472 | } 473 | fileWriteStream << INIStringUtil::endl; 474 | } 475 | } 476 | if (++it == data.end()) 477 | { 478 | break; 479 | } 480 | fileWriteStream << INIStringUtil::endl; 481 | if (prettyPrint) 482 | { 483 | fileWriteStream << INIStringUtil::endl; 484 | } 485 | } 486 | return true; 487 | } 488 | }; 489 | 490 | class INIWriter 491 | { 492 | private: 493 | using T_LineData = std::vector; 494 | using T_LineDataPtr = std::shared_ptr; 495 | 496 | std::string filename; 497 | 498 | T_LineData getLazyOutput(T_LineDataPtr const& lineData, INIStructure& data, INIStructure& original) 499 | { 500 | T_LineData output; 501 | INIParser::T_ParseValues parseData; 502 | std::string sectionCurrent; 503 | bool parsingSection = false; 504 | bool continueToNextSection = false; 505 | bool discardNextEmpty = false; 506 | bool writeNewKeys = false; 507 | std::size_t lastKeyLine = 0; 508 | for (auto line = lineData->begin(); line != lineData->end(); ++line) 509 | { 510 | if (!writeNewKeys) 511 | { 512 | auto parseResult = INIParser::parseLine(*line, parseData); 513 | if (parseResult == INIParser::PDataType::PDATA_SECTION) 514 | { 515 | if (parsingSection) 516 | { 517 | writeNewKeys = true; 518 | parsingSection = false; 519 | --line; 520 | continue; 521 | } 522 | sectionCurrent = parseData.first; 523 | if (data.has(sectionCurrent)) 524 | { 525 | parsingSection = true; 526 | continueToNextSection = false; 527 | discardNextEmpty = false; 528 | output.emplace_back(*line); 529 | lastKeyLine = output.size(); 530 | } 531 | else 532 | { 533 | continueToNextSection = true; 534 | discardNextEmpty = true; 535 | continue; 536 | } 537 | } 538 | else if (parseResult == INIParser::PDataType::PDATA_KEYVALUE) 539 | { 540 | if (continueToNextSection) 541 | { 542 | continue; 543 | } 544 | if (data.has(sectionCurrent)) 545 | { 546 | auto& collection = data[sectionCurrent]; 547 | auto const& key = parseData.first; 548 | auto const& value = parseData.second; 549 | if (collection.has(key)) 550 | { 551 | auto outputValue = collection[key]; 552 | if (value == outputValue) 553 | { 554 | output.emplace_back(*line); 555 | } 556 | else 557 | { 558 | INIStringUtil::trim(outputValue); 559 | auto lineNorm = *line; 560 | INIStringUtil::replace(lineNorm, "\\=", " "); 561 | auto equalsAt = lineNorm.find_first_of('='); 562 | auto valueAt = lineNorm.find_first_not_of( 563 | INIStringUtil::whitespaceDelimiters, 564 | equalsAt + 1 565 | ); 566 | std::string outputLine = line->substr(0, valueAt); 567 | if (prettyPrint && equalsAt + 1 == valueAt) 568 | { 569 | outputLine += " "; 570 | } 571 | outputLine += outputValue; 572 | output.emplace_back(outputLine); 573 | } 574 | lastKeyLine = output.size(); 575 | } 576 | } 577 | } 578 | else 579 | { 580 | if (discardNextEmpty && line->empty()) 581 | { 582 | discardNextEmpty = false; 583 | } 584 | else if (parseResult != INIParser::PDataType::PDATA_UNKNOWN) 585 | { 586 | output.emplace_back(*line); 587 | } 588 | } 589 | } 590 | if (writeNewKeys || std::next(line) == lineData->end()) 591 | { 592 | T_LineData linesToAdd; 593 | if (data.has(sectionCurrent) && original.has(sectionCurrent)) 594 | { 595 | auto const& collection = data[sectionCurrent]; 596 | auto const& collectionOriginal = original[sectionCurrent]; 597 | for (auto const& it : collection) 598 | { 599 | auto key = it.first; 600 | if (collectionOriginal.has(key)) 601 | { 602 | continue; 603 | } 604 | auto value = it.second; 605 | INIStringUtil::replace(key, "=", "\\="); 606 | INIStringUtil::trim(value); 607 | linesToAdd.emplace_back( 608 | key + ((prettyPrint) ? " = " : "=") + value 609 | ); 610 | } 611 | } 612 | if (!linesToAdd.empty()) 613 | { 614 | output.insert( 615 | output.begin() + lastKeyLine, 616 | linesToAdd.begin(), 617 | linesToAdd.end() 618 | ); 619 | } 620 | if (writeNewKeys) 621 | { 622 | writeNewKeys = false; 623 | --line; 624 | } 625 | } 626 | } 627 | for (auto const& it : data) 628 | { 629 | auto const& section = it.first; 630 | if (original.has(section)) 631 | { 632 | continue; 633 | } 634 | if (prettyPrint && output.size() > 0 && !output.back().empty()) 635 | { 636 | output.emplace_back(); 637 | } 638 | output.emplace_back("[" + section + "]"); 639 | auto const& collection = it.second; 640 | for (auto const& it2 : collection) 641 | { 642 | auto key = it2.first; 643 | auto value = it2.second; 644 | INIStringUtil::replace(key, "=", "\\="); 645 | INIStringUtil::trim(value); 646 | output.emplace_back( 647 | key + ((prettyPrint) ? " = " : "=") + value 648 | ); 649 | } 650 | } 651 | return output; 652 | } 653 | 654 | public: 655 | bool prettyPrint = false; 656 | 657 | INIWriter(std::string const& filename) 658 | : filename(filename) 659 | { 660 | } 661 | ~INIWriter() { } 662 | 663 | bool operator<<(INIStructure& data) 664 | { 665 | struct stat buf; 666 | bool fileExists = (stat(filename.c_str(), &buf) == 0); 667 | if (!fileExists) 668 | { 669 | INIGenerator generator(filename); 670 | generator.prettyPrint = prettyPrint; 671 | return generator << data; 672 | } 673 | INIStructure originalData; 674 | T_LineDataPtr lineData; 675 | bool readSuccess = false; 676 | { 677 | INIReader reader(filename, true); 678 | if ((readSuccess = reader >> originalData)) 679 | { 680 | lineData = reader.getLines(); 681 | } 682 | } 683 | if (!readSuccess) 684 | { 685 | return false; 686 | } 687 | T_LineData output = getLazyOutput(lineData, data, originalData); 688 | std::ofstream fileWriteStream(filename, std::ios::out | std::ios::binary); 689 | if (fileWriteStream.is_open()) 690 | { 691 | if (output.size()) 692 | { 693 | auto line = output.begin(); 694 | for (;;) 695 | { 696 | fileWriteStream << *line; 697 | if (++line == output.end()) 698 | { 699 | break; 700 | } 701 | fileWriteStream << INIStringUtil::endl; 702 | } 703 | } 704 | return true; 705 | } 706 | return false; 707 | } 708 | }; 709 | 710 | class INIFile 711 | { 712 | private: 713 | std::string filename; 714 | 715 | public: 716 | INIFile(std::string const& filename) 717 | : filename(filename) 718 | { } 719 | 720 | ~INIFile() { } 721 | 722 | bool read(INIStructure& data) const 723 | { 724 | if (data.size()) 725 | { 726 | data.clear(); 727 | } 728 | if (filename.empty()) 729 | { 730 | return false; 731 | } 732 | INIReader reader(filename); 733 | return reader >> data; 734 | } 735 | bool generate(INIStructure const& data, bool pretty = false) const 736 | { 737 | if (filename.empty()) 738 | { 739 | return false; 740 | } 741 | INIGenerator generator(filename); 742 | generator.prettyPrint = pretty; 743 | return generator << data; 744 | } 745 | bool write(INIStructure& data, bool pretty = false) const 746 | { 747 | if (filename.empty()) 748 | { 749 | return false; 750 | } 751 | INIWriter writer(filename); 752 | writer.prettyPrint = pretty; 753 | return writer << data; 754 | } 755 | }; 756 | } 757 | 758 | #endif // MINI_INI_H_ 759 | -------------------------------------------------------------------------------- /includes/imgui/imstb_rectpack.h: -------------------------------------------------------------------------------- 1 | // [DEAR IMGUI] 2 | // This is a slightly modified version of stb_rect_pack.h 0.99. 3 | // Those changes would need to be pushed into nothings/stb: 4 | // - Added STBRP__CDECL 5 | // Grep for [DEAR IMGUI] to find the changes. 6 | 7 | // stb_rect_pack.h - v0.99 - public domain - rectangle packing 8 | // Sean Barrett 2014 9 | // 10 | // Useful for e.g. packing rectangular textures into an atlas. 11 | // Does not do rotation. 12 | // 13 | // Not necessarily the awesomest packing method, but better than 14 | // the totally naive one in stb_truetype (which is primarily what 15 | // this is meant to replace). 16 | // 17 | // Has only had a few tests run, may have issues. 18 | // 19 | // More docs to come. 20 | // 21 | // No memory allocations; uses qsort() and assert() from stdlib. 22 | // Can override those by defining STBRP_SORT and STBRP_ASSERT. 23 | // 24 | // This library currently uses the Skyline Bottom-Left algorithm. 25 | // 26 | // Please note: better rectangle packers are welcome! Please 27 | // implement them to the same API, but with a different init 28 | // function. 29 | // 30 | // Credits 31 | // 32 | // Library 33 | // Sean Barrett 34 | // Minor features 35 | // Martins Mozeiko 36 | // github:IntellectualKitty 37 | // 38 | // Bugfixes / warning fixes 39 | // Jeremy Jaussaud 40 | // 41 | // Version history: 42 | // 43 | // 0.99 (2019-02-07) warning fixes 44 | // 0.11 (2017-03-03) return packing success/fail result 45 | // 0.10 (2016-10-25) remove cast-away-const to avoid warnings 46 | // 0.09 (2016-08-27) fix compiler warnings 47 | // 0.08 (2015-09-13) really fix bug with empty rects (w=0 or h=0) 48 | // 0.07 (2015-09-13) fix bug with empty rects (w=0 or h=0) 49 | // 0.06 (2015-04-15) added STBRP_SORT to allow replacing qsort 50 | // 0.05: added STBRP_ASSERT to allow replacing assert 51 | // 0.04: fixed minor bug in STBRP_LARGE_RECTS support 52 | // 0.01: initial release 53 | // 54 | // LICENSE 55 | // 56 | // See end of file for license information. 57 | 58 | ////////////////////////////////////////////////////////////////////////////// 59 | // 60 | // INCLUDE SECTION 61 | // 62 | 63 | #ifndef STB_INCLUDE_STB_RECT_PACK_H 64 | #define STB_INCLUDE_STB_RECT_PACK_H 65 | 66 | #define STB_RECT_PACK_VERSION 1 67 | 68 | #ifdef STBRP_STATIC 69 | #define STBRP_DEF static 70 | #else 71 | #define STBRP_DEF extern 72 | #endif 73 | 74 | #ifdef __cplusplus 75 | extern "C" { 76 | #endif 77 | 78 | typedef struct stbrp_context stbrp_context; 79 | typedef struct stbrp_node stbrp_node; 80 | typedef struct stbrp_rect stbrp_rect; 81 | 82 | #ifdef STBRP_LARGE_RECTS 83 | typedef int stbrp_coord; 84 | #else 85 | typedef unsigned short stbrp_coord; 86 | #endif 87 | 88 | STBRP_DEF int stbrp_pack_rects (stbrp_context *context, stbrp_rect *rects, int num_rects); 89 | // Assign packed locations to rectangles. The rectangles are of type 90 | // 'stbrp_rect' defined below, stored in the array 'rects', and there 91 | // are 'num_rects' many of them. 92 | // 93 | // Rectangles which are successfully packed have the 'was_packed' flag 94 | // set to a non-zero value and 'x' and 'y' store the minimum location 95 | // on each axis (i.e. bottom-left in cartesian coordinates, top-left 96 | // if you imagine y increasing downwards). Rectangles which do not fit 97 | // have the 'was_packed' flag set to 0. 98 | // 99 | // You should not try to access the 'rects' array from another thread 100 | // while this function is running, as the function temporarily reorders 101 | // the array while it executes. 102 | // 103 | // To pack into another rectangle, you need to call stbrp_init_target 104 | // again. To continue packing into the same rectangle, you can call 105 | // this function again. Calling this multiple times with multiple rect 106 | // arrays will probably produce worse packing results than calling it 107 | // a single time with the full rectangle array, but the option is 108 | // available. 109 | // 110 | // The function returns 1 if all of the rectangles were successfully 111 | // packed and 0 otherwise. 112 | 113 | struct stbrp_rect 114 | { 115 | // reserved for your use: 116 | int id; 117 | 118 | // input: 119 | stbrp_coord w, h; 120 | 121 | // output: 122 | stbrp_coord x, y; 123 | int was_packed; // non-zero if valid packing 124 | 125 | }; // 16 bytes, nominally 126 | 127 | 128 | STBRP_DEF void stbrp_init_target (stbrp_context *context, int width, int height, stbrp_node *nodes, int num_nodes); 129 | // Initialize a rectangle packer to: 130 | // pack a rectangle that is 'width' by 'height' in dimensions 131 | // using temporary storage provided by the array 'nodes', which is 'num_nodes' long 132 | // 133 | // You must call this function every time you start packing into a new target. 134 | // 135 | // There is no "shutdown" function. The 'nodes' memory must stay valid for 136 | // the following stbrp_pack_rects() call (or calls), but can be freed after 137 | // the call (or calls) finish. 138 | // 139 | // Note: to guarantee best results, either: 140 | // 1. make sure 'num_nodes' >= 'width' 141 | // or 2. call stbrp_allow_out_of_mem() defined below with 'allow_out_of_mem = 1' 142 | // 143 | // If you don't do either of the above things, widths will be quantized to multiples 144 | // of small integers to guarantee the algorithm doesn't run out of temporary storage. 145 | // 146 | // If you do #2, then the non-quantized algorithm will be used, but the algorithm 147 | // may run out of temporary storage and be unable to pack some rectangles. 148 | 149 | STBRP_DEF void stbrp_setup_allow_out_of_mem (stbrp_context *context, int allow_out_of_mem); 150 | // Optionally call this function after init but before doing any packing to 151 | // change the handling of the out-of-temp-memory scenario, described above. 152 | // If you call init again, this will be reset to the default (false). 153 | 154 | 155 | STBRP_DEF void stbrp_setup_heuristic (stbrp_context *context, int heuristic); 156 | // Optionally select which packing heuristic the library should use. Different 157 | // heuristics will produce better/worse results for different data sets. 158 | // If you call init again, this will be reset to the default. 159 | 160 | enum 161 | { 162 | STBRP_HEURISTIC_Skyline_default=0, 163 | STBRP_HEURISTIC_Skyline_BL_sortHeight = STBRP_HEURISTIC_Skyline_default, 164 | STBRP_HEURISTIC_Skyline_BF_sortHeight 165 | }; 166 | 167 | 168 | ////////////////////////////////////////////////////////////////////////////// 169 | // 170 | // the details of the following structures don't matter to you, but they must 171 | // be visible so you can handle the memory allocations for them 172 | 173 | struct stbrp_node 174 | { 175 | stbrp_coord x,y; 176 | stbrp_node *next; 177 | }; 178 | 179 | struct stbrp_context 180 | { 181 | int width; 182 | int height; 183 | int align; 184 | int init_mode; 185 | int heuristic; 186 | int num_nodes; 187 | stbrp_node *active_head; 188 | stbrp_node *free_head; 189 | stbrp_node extra[2]; // we allocate two extra nodes so optimal user-node-count is 'width' not 'width+2' 190 | }; 191 | 192 | #ifdef __cplusplus 193 | } 194 | #endif 195 | 196 | #endif 197 | 198 | ////////////////////////////////////////////////////////////////////////////// 199 | // 200 | // IMPLEMENTATION SECTION 201 | // 202 | 203 | #ifdef STB_RECT_PACK_IMPLEMENTATION 204 | #ifndef STBRP_SORT 205 | #include 206 | #define STBRP_SORT qsort 207 | #endif 208 | 209 | #ifndef STBRP_ASSERT 210 | #include 211 | #define STBRP_ASSERT assert 212 | #endif 213 | 214 | // [DEAR IMGUI] Added STBRP__CDECL 215 | #ifdef _MSC_VER 216 | #define STBRP__NOTUSED(v) (void)(v) 217 | #define STBRP__CDECL __cdecl 218 | #else 219 | #define STBRP__NOTUSED(v) (void)sizeof(v) 220 | #define STBRP__CDECL 221 | #endif 222 | 223 | enum 224 | { 225 | STBRP__INIT_skyline = 1 226 | }; 227 | 228 | STBRP_DEF void stbrp_setup_heuristic(stbrp_context *context, int heuristic) 229 | { 230 | switch (context->init_mode) { 231 | case STBRP__INIT_skyline: 232 | STBRP_ASSERT(heuristic == STBRP_HEURISTIC_Skyline_BL_sortHeight || heuristic == STBRP_HEURISTIC_Skyline_BF_sortHeight); 233 | context->heuristic = heuristic; 234 | break; 235 | default: 236 | STBRP_ASSERT(0); 237 | } 238 | } 239 | 240 | STBRP_DEF void stbrp_setup_allow_out_of_mem(stbrp_context *context, int allow_out_of_mem) 241 | { 242 | if (allow_out_of_mem) 243 | // if it's ok to run out of memory, then don't bother aligning them; 244 | // this gives better packing, but may fail due to OOM (even though 245 | // the rectangles easily fit). @TODO a smarter approach would be to only 246 | // quantize once we've hit OOM, then we could get rid of this parameter. 247 | context->align = 1; 248 | else { 249 | // if it's not ok to run out of memory, then quantize the widths 250 | // so that num_nodes is always enough nodes. 251 | // 252 | // I.e. num_nodes * align >= width 253 | // align >= width / num_nodes 254 | // align = ceil(width/num_nodes) 255 | 256 | context->align = (context->width + context->num_nodes-1) / context->num_nodes; 257 | } 258 | } 259 | 260 | STBRP_DEF void stbrp_init_target(stbrp_context *context, int width, int height, stbrp_node *nodes, int num_nodes) 261 | { 262 | int i; 263 | #ifndef STBRP_LARGE_RECTS 264 | STBRP_ASSERT(width <= 0xffff && height <= 0xffff); 265 | #endif 266 | 267 | for (i=0; i < num_nodes-1; ++i) 268 | nodes[i].next = &nodes[i+1]; 269 | nodes[i].next = NULL; 270 | context->init_mode = STBRP__INIT_skyline; 271 | context->heuristic = STBRP_HEURISTIC_Skyline_default; 272 | context->free_head = &nodes[0]; 273 | context->active_head = &context->extra[0]; 274 | context->width = width; 275 | context->height = height; 276 | context->num_nodes = num_nodes; 277 | stbrp_setup_allow_out_of_mem(context, 0); 278 | 279 | // node 0 is the full width, node 1 is the sentinel (lets us not store width explicitly) 280 | context->extra[0].x = 0; 281 | context->extra[0].y = 0; 282 | context->extra[0].next = &context->extra[1]; 283 | context->extra[1].x = (stbrp_coord) width; 284 | #ifdef STBRP_LARGE_RECTS 285 | context->extra[1].y = (1<<30); 286 | #else 287 | context->extra[1].y = 65535; 288 | #endif 289 | context->extra[1].next = NULL; 290 | } 291 | 292 | // find minimum y position if it starts at x1 293 | static int stbrp__skyline_find_min_y(stbrp_context *c, stbrp_node *first, int x0, int width, int *pwaste) 294 | { 295 | stbrp_node *node = first; 296 | int x1 = x0 + width; 297 | int min_y, visited_width, waste_area; 298 | 299 | STBRP__NOTUSED(c); 300 | 301 | STBRP_ASSERT(first->x <= x0); 302 | 303 | #if 0 304 | // skip in case we're past the node 305 | while (node->next->x <= x0) 306 | ++node; 307 | #else 308 | STBRP_ASSERT(node->next->x > x0); // we ended up handling this in the caller for efficiency 309 | #endif 310 | 311 | STBRP_ASSERT(node->x <= x0); 312 | 313 | min_y = 0; 314 | waste_area = 0; 315 | visited_width = 0; 316 | while (node->x < x1) { 317 | if (node->y > min_y) { 318 | // raise min_y higher. 319 | // we've accounted for all waste up to min_y, 320 | // but we'll now add more waste for everything we've visted 321 | waste_area += visited_width * (node->y - min_y); 322 | min_y = node->y; 323 | // the first time through, visited_width might be reduced 324 | if (node->x < x0) 325 | visited_width += node->next->x - x0; 326 | else 327 | visited_width += node->next->x - node->x; 328 | } else { 329 | // add waste area 330 | int under_width = node->next->x - node->x; 331 | if (under_width + visited_width > width) 332 | under_width = width - visited_width; 333 | waste_area += under_width * (min_y - node->y); 334 | visited_width += under_width; 335 | } 336 | node = node->next; 337 | } 338 | 339 | *pwaste = waste_area; 340 | return min_y; 341 | } 342 | 343 | typedef struct 344 | { 345 | int x,y; 346 | stbrp_node **prev_link; 347 | } stbrp__findresult; 348 | 349 | static stbrp__findresult stbrp__skyline_find_best_pos(stbrp_context *c, int width, int height) 350 | { 351 | int best_waste = (1<<30), best_x, best_y = (1 << 30); 352 | stbrp__findresult fr; 353 | stbrp_node **prev, *node, *tail, **best = NULL; 354 | 355 | // align to multiple of c->align 356 | width = (width + c->align - 1); 357 | width -= width % c->align; 358 | STBRP_ASSERT(width % c->align == 0); 359 | 360 | node = c->active_head; 361 | prev = &c->active_head; 362 | while (node->x + width <= c->width) { 363 | int y,waste; 364 | y = stbrp__skyline_find_min_y(c, node, node->x, width, &waste); 365 | if (c->heuristic == STBRP_HEURISTIC_Skyline_BL_sortHeight) { // actually just want to test BL 366 | // bottom left 367 | if (y < best_y) { 368 | best_y = y; 369 | best = prev; 370 | } 371 | } else { 372 | // best-fit 373 | if (y + height <= c->height) { 374 | // can only use it if it first vertically 375 | if (y < best_y || (y == best_y && waste < best_waste)) { 376 | best_y = y; 377 | best_waste = waste; 378 | best = prev; 379 | } 380 | } 381 | } 382 | prev = &node->next; 383 | node = node->next; 384 | } 385 | 386 | best_x = (best == NULL) ? 0 : (*best)->x; 387 | 388 | // if doing best-fit (BF), we also have to try aligning right edge to each node position 389 | // 390 | // e.g, if fitting 391 | // 392 | // ____________________ 393 | // |____________________| 394 | // 395 | // into 396 | // 397 | // | | 398 | // | ____________| 399 | // |____________| 400 | // 401 | // then right-aligned reduces waste, but bottom-left BL is always chooses left-aligned 402 | // 403 | // This makes BF take about 2x the time 404 | 405 | if (c->heuristic == STBRP_HEURISTIC_Skyline_BF_sortHeight) { 406 | tail = c->active_head; 407 | node = c->active_head; 408 | prev = &c->active_head; 409 | // find first node that's admissible 410 | while (tail->x < width) 411 | tail = tail->next; 412 | while (tail) { 413 | int xpos = tail->x - width; 414 | int y,waste; 415 | STBRP_ASSERT(xpos >= 0); 416 | // find the left position that matches this 417 | while (node->next->x <= xpos) { 418 | prev = &node->next; 419 | node = node->next; 420 | } 421 | STBRP_ASSERT(node->next->x > xpos && node->x <= xpos); 422 | y = stbrp__skyline_find_min_y(c, node, xpos, width, &waste); 423 | if (y + height < c->height) { 424 | if (y <= best_y) { 425 | if (y < best_y || waste < best_waste || (waste==best_waste && xpos < best_x)) { 426 | best_x = xpos; 427 | STBRP_ASSERT(y <= best_y); 428 | best_y = y; 429 | best_waste = waste; 430 | best = prev; 431 | } 432 | } 433 | } 434 | tail = tail->next; 435 | } 436 | } 437 | 438 | fr.prev_link = best; 439 | fr.x = best_x; 440 | fr.y = best_y; 441 | return fr; 442 | } 443 | 444 | static stbrp__findresult stbrp__skyline_pack_rectangle(stbrp_context *context, int width, int height) 445 | { 446 | // find best position according to heuristic 447 | stbrp__findresult res = stbrp__skyline_find_best_pos(context, width, height); 448 | stbrp_node *node, *cur; 449 | 450 | // bail if: 451 | // 1. it failed 452 | // 2. the best node doesn't fit (we don't always check this) 453 | // 3. we're out of memory 454 | if (res.prev_link == NULL || res.y + height > context->height || context->free_head == NULL) { 455 | res.prev_link = NULL; 456 | return res; 457 | } 458 | 459 | // on success, create new node 460 | node = context->free_head; 461 | node->x = (stbrp_coord) res.x; 462 | node->y = (stbrp_coord) (res.y + height); 463 | 464 | context->free_head = node->next; 465 | 466 | // insert the new node into the right starting point, and 467 | // let 'cur' point to the remaining nodes needing to be 468 | // stiched back in 469 | 470 | cur = *res.prev_link; 471 | if (cur->x < res.x) { 472 | // preserve the existing one, so start testing with the next one 473 | stbrp_node *next = cur->next; 474 | cur->next = node; 475 | cur = next; 476 | } else { 477 | *res.prev_link = node; 478 | } 479 | 480 | // from here, traverse cur and free the nodes, until we get to one 481 | // that shouldn't be freed 482 | while (cur->next && cur->next->x <= res.x + width) { 483 | stbrp_node *next = cur->next; 484 | // move the current node to the free list 485 | cur->next = context->free_head; 486 | context->free_head = cur; 487 | cur = next; 488 | } 489 | 490 | // stitch the list back in 491 | node->next = cur; 492 | 493 | if (cur->x < res.x + width) 494 | cur->x = (stbrp_coord) (res.x + width); 495 | 496 | #ifdef _DEBUG 497 | cur = context->active_head; 498 | while (cur->x < context->width) { 499 | STBRP_ASSERT(cur->x < cur->next->x); 500 | cur = cur->next; 501 | } 502 | STBRP_ASSERT(cur->next == NULL); 503 | 504 | { 505 | int count=0; 506 | cur = context->active_head; 507 | while (cur) { 508 | cur = cur->next; 509 | ++count; 510 | } 511 | cur = context->free_head; 512 | while (cur) { 513 | cur = cur->next; 514 | ++count; 515 | } 516 | STBRP_ASSERT(count == context->num_nodes+2); 517 | } 518 | #endif 519 | 520 | return res; 521 | } 522 | 523 | // [DEAR IMGUI] Added STBRP__CDECL 524 | static int STBRP__CDECL rect_height_compare(const void *a, const void *b) 525 | { 526 | const stbrp_rect *p = (const stbrp_rect *) a; 527 | const stbrp_rect *q = (const stbrp_rect *) b; 528 | if (p->h > q->h) 529 | return -1; 530 | if (p->h < q->h) 531 | return 1; 532 | return (p->w > q->w) ? -1 : (p->w < q->w); 533 | } 534 | 535 | // [DEAR IMGUI] Added STBRP__CDECL 536 | static int STBRP__CDECL rect_original_order(const void *a, const void *b) 537 | { 538 | const stbrp_rect *p = (const stbrp_rect *) a; 539 | const stbrp_rect *q = (const stbrp_rect *) b; 540 | return (p->was_packed < q->was_packed) ? -1 : (p->was_packed > q->was_packed); 541 | } 542 | 543 | #ifdef STBRP_LARGE_RECTS 544 | #define STBRP__MAXVAL 0xffffffff 545 | #else 546 | #define STBRP__MAXVAL 0xffff 547 | #endif 548 | 549 | STBRP_DEF int stbrp_pack_rects(stbrp_context *context, stbrp_rect *rects, int num_rects) 550 | { 551 | int i, all_rects_packed = 1; 552 | 553 | // we use the 'was_packed' field internally to allow sorting/unsorting 554 | for (i=0; i < num_rects; ++i) { 555 | rects[i].was_packed = i; 556 | } 557 | 558 | // sort according to heuristic 559 | STBRP_SORT(rects, num_rects, sizeof(rects[0]), rect_height_compare); 560 | 561 | for (i=0; i < num_rects; ++i) { 562 | if (rects[i].w == 0 || rects[i].h == 0) { 563 | rects[i].x = rects[i].y = 0; // empty rect needs no space 564 | } else { 565 | stbrp__findresult fr = stbrp__skyline_pack_rectangle(context, rects[i].w, rects[i].h); 566 | if (fr.prev_link) { 567 | rects[i].x = (stbrp_coord) fr.x; 568 | rects[i].y = (stbrp_coord) fr.y; 569 | } else { 570 | rects[i].x = rects[i].y = STBRP__MAXVAL; 571 | } 572 | } 573 | } 574 | 575 | // unsort 576 | STBRP_SORT(rects, num_rects, sizeof(rects[0]), rect_original_order); 577 | 578 | // set was_packed flags and all_rects_packed status 579 | for (i=0; i < num_rects; ++i) { 580 | rects[i].was_packed = !(rects[i].x == STBRP__MAXVAL && rects[i].y == STBRP__MAXVAL); 581 | if (!rects[i].was_packed) 582 | all_rects_packed = 0; 583 | } 584 | 585 | // return the all_rects_packed status 586 | return all_rects_packed; 587 | } 588 | #endif 589 | 590 | /* 591 | ------------------------------------------------------------------------------ 592 | This software is available under 2 licenses -- choose whichever you prefer. 593 | ------------------------------------------------------------------------------ 594 | ALTERNATIVE A - MIT License 595 | Copyright (c) 2017 Sean Barrett 596 | Permission is hereby granted, free of charge, to any person obtaining a copy of 597 | this software and associated documentation files (the "Software"), to deal in 598 | the Software without restriction, including without limitation the rights to 599 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 600 | of the Software, and to permit persons to whom the Software is furnished to do 601 | so, subject to the following conditions: 602 | The above copyright notice and this permission notice shall be included in all 603 | copies or substantial portions of the Software. 604 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 605 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 606 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 607 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 608 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 609 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 610 | SOFTWARE. 611 | ------------------------------------------------------------------------------ 612 | ALTERNATIVE B - Public Domain (www.unlicense.org) 613 | This is free and unencumbered software released into the public domain. 614 | Anyone is free to copy, modify, publish, use, compile, sell, or distribute this 615 | software, either in source code form or as a compiled binary, for any purpose, 616 | commercial or non-commercial, and by any means. 617 | In jurisdictions that recognize copyright laws, the author or authors of this 618 | software dedicate any and all copyright interest in the software to the public 619 | domain. We make this dedication for the benefit of the public at large and to 620 | the detriment of our heirs and successors. We intend this dedication to be an 621 | overt act of relinquishment in perpetuity of all present and future rights to 622 | this software under copyright law. 623 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 624 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 625 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 626 | AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 627 | ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 628 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 629 | ------------------------------------------------------------------------------ 630 | */ 631 | --------------------------------------------------------------------------------