From 77a18c726436a0f1a31bf1d9fb835ed0c5d97953 Mon Sep 17 00:00:00 2001 From: NightFyre <80198020+xCENTx@users.noreply.github.com> Date: Sun, 28 Jan 2024 14:18:30 -0500 Subject: [PATCH] HUD Drawing - Initialize GObjects with Config initialization - GetDistanceToActor implementation - pointers to both imgui context & imgui viewport - watermark ~squish- - watermark - update toolset to v143 --- DX11-Base.vcxproj | 4 +-- DX11-Base.vcxproj.filters | 25 ++++++++------ config.cpp | 4 ++- dllmain.cpp | 3 +- feature.cpp | 35 ++++++++++++++----- feature.h | 4 ++- include/D3D11Window.hpp | 2 ++ include/helper.h | 2 +- initialize.hpp | 9 +++-- src/D3D11Window.cpp | 2 ++ src/Menu.cpp | 72 +++++++++++++++++++++++++++++++-------- 11 files changed, 119 insertions(+), 43 deletions(-) diff --git a/DX11-Base.vcxproj b/DX11-Base.vcxproj index dd57baa..af53949 100644 --- a/DX11-Base.vcxproj +++ b/DX11-Base.vcxproj @@ -43,13 +43,13 @@ DynamicLibrary true - v142 + v143 Unicode DynamicLibrary false - v142 + v143 true Unicode diff --git a/DX11-Base.vcxproj.filters b/DX11-Base.vcxproj.filters index 6dec8a5..1ed375c 100644 --- a/DX11-Base.vcxproj.filters +++ b/DX11-Base.vcxproj.filters @@ -25,6 +25,9 @@ {d55590e2-04e5-427a-a959-6dcc763f2f71} + + {26987ebc-44ae-4b58-be8f-b68ad7efa763} + @@ -108,9 +111,6 @@ Header Files\Class - - Header Files - Header Files @@ -120,6 +120,9 @@ Header Files\Class + + Resource Files\SDK + @@ -185,12 +188,6 @@ Source Files\Class - - Source Files - - - Source Files - Source Files @@ -198,10 +195,16 @@ Source Files - Source Files + Resource Files\SDK - Source Files + Resource Files\SDK + + + Resource Files\SDK + + + Resource Files\SDK diff --git a/config.cpp b/config.cpp index 8535898..c005ace 100644 --- a/config.cpp +++ b/config.cpp @@ -201,10 +201,12 @@ void config::Init() //register hook Config.ClientBase = (DWORD64)GetModuleHandleA("PalWorld-Win64-Shipping.exe"); - TickFunc = (Tick)(Config.ClientBase + Config.offset_Tick); + SDK::InitGObjects(); Config.gWorld = Config.GetUWorld(); + TickFunc = (Tick)(Config.ClientBase + Config.offset_Tick); + MH_CreateHook(TickFunc, DetourTick, reinterpret_cast(&OldTickFunc)); //init database diff --git a/dllmain.cpp b/dllmain.cpp index becc996..a035a7b 100644 --- a/dllmain.cpp +++ b/dllmain.cpp @@ -3,16 +3,15 @@ #include "initialize.hpp" using namespace SDK; +using namespace DX11_Base; extern DWORD WINAPI MainThread_Initialize(); BOOL APIENTRY DllMain(HMODULE hModule, DWORD dwCallReason, LPVOID lpReserved) { - using namespace DX11_Base; g_hModule = hModule; switch (dwCallReason) { case (DLL_PROCESS_ATTACH): { - InitGObjects(); DisableThreadLibraryCalls(hModule); CreateThread(NULL, NULL, (LPTHREAD_START_ROUTINE)MainThread_Initialize, g_hModule, NULL, NULL); break; diff --git a/feature.cpp b/feature.cpp index f7ed5d2..6b51bd8 100644 --- a/feature.cpp +++ b/feature.cpp @@ -52,8 +52,8 @@ void ESP_DEBUG(float mDist, ImVec4 color, UClass* mEntType) { FVector actorLocation = actor->K2_GetActorLocation(); FVector localPlayerLocation = pLocalPlayer->K2_GetActorLocation(); - float distantTo = pLocalPlayer->GetDistanceTo(actor); - if (distantTo > mDist) + float distanceTo = GetDistanceToActor(pLocalPlayer, actor); + if (distanceTo > mDist) continue; FVector2D outScreen; @@ -61,13 +61,13 @@ void ESP_DEBUG(float mDist, ImVec4 color, UClass* mEntType) continue; char data[0x256]; - const char* StringData = "OBJECT: [%s]\nCLASS: [%s]\nINDEX: [%d]\nPOSITION: { %0.0f, %0.0f, %0.0f }\nDISTANCE: [%.0fm]"; - if (distantTo >= 1000.f) + const char* StringData = "OBJECT: [%s]\nCLASS: [%s]\nPOSITION: { %0.0f, %0.0f, %0.0f }\nDISTANCE: [%.0fm]"; + if (distanceTo >= 1000.f) { - distantTo /= 1000.f; - StringData = "OBJECT: [%s]\nCLASS: [%s]\nINDEX: [%d]\nPOSITION: { %0.0f, %0.0f, %0.0f }\nDISTANCE: [%.0fkm]"; + distanceTo /= 1000.f; + StringData = "OBJECT: [%s]\nCLASS: [%s]\nPOSITION: { %0.0f, %0.0f, %0.0f }\nDISTANCE: [%.0fkm]"; } - sprintf_s(data, StringData, actor->GetName().c_str(), actor->Class->GetFullName().c_str(), actorLocation.X, actorLocation.Y, actorLocation.Z, distantTo); + sprintf_s(data, StringData, actor->GetName().c_str(), actor->Class->GetFullName().c_str(), actorLocation.X, actorLocation.Y, actorLocation.Z, distanceTo); ImVec2 screen = ImVec2(static_cast(outScreen.X), static_cast(outScreen.Y)); draw->AddText(screen, ImColor(color), data); @@ -242,11 +242,17 @@ void SpeedHack(float mSpeed) if (!pWorld) return; - AWorldSettings* pWorldSettings = pWorld->K2_GetWorldSettings(); + ULevel* pLevel = pWorld->PersistentLevel; + if (!pLevel) + return; + + AWorldSettings* pWorldSettings = pLevel->WorldSettings; if (!pWorldSettings) return; - pWorldSettings->TimeDilation = mSpeed; + pWorld->PersistentLevel->WorldSettings->TimeDilation = mSpeed; + + // pWorldSettings->TimeDilation = mSpeed; } // @@ -451,6 +457,17 @@ void RemoveAncientTechPoint(__int32 mPoints) pTechData->bossTechnologyPoint -= mPoints; } +float GetDistanceToActor(AActor* pLocal, AActor* pTarget) +{ + if (!pLocal || !pTarget) + return -1.f; + + FVector pLocation = pLocal->K2_GetActorLocation(); + FVector pTargetLocation = pTarget->K2_GetActorLocation(); + double distance = sqrt(pow(pTargetLocation.X - pLocation.X, 2.0) + pow(pTargetLocation.Y - pLocation.Y, 2.0) + pow(pTargetLocation.Z - pLocation.Z, 2.0)); + + return distance / 100.0f; +} /// OLDER METHODS //SDK::FPalDebugOtomoPalInfo palinfo = SDK::FPalDebugOtomoPalInfo(); diff --git a/feature.h b/feature.h index e10920c..fee1738 100644 --- a/feature.h +++ b/feature.h @@ -47,4 +47,6 @@ void AddAncientTechPoints(__int32 mPoints); void RemoveTechPoints(__int32 mPoints); -void RemoveAncientTechPoint(__int32 mPoints); \ No newline at end of file +void RemoveAncientTechPoint(__int32 mPoints); + +float GetDistanceToActor(SDK::AActor* pLocal, SDK::AActor* pTarget); \ No newline at end of file diff --git a/include/D3D11Window.hpp b/include/D3D11Window.hpp index 008ee07..1d40dbe 100644 --- a/include/D3D11Window.hpp +++ b/include/D3D11Window.hpp @@ -26,6 +26,8 @@ namespace DX11_Base { bool m_Init{}; bool b_ImGui_Initialized{}; WNDPROC m_OldWndProc{}; + ImGuiContext* pImGui; + ImGuiViewport* pViewport; // Forward Dx11 Hook Declarations bool Init(IDXGISwapChain* swapChain); diff --git a/include/helper.h b/include/helper.h index cb21236..ce627a5 100644 --- a/include/helper.h +++ b/include/helper.h @@ -1,5 +1,5 @@ #pragma once -#define DEBUG 0 +#define DEBUG 1 // External Libraries #include "../libs/ImGui/imgui.h" diff --git a/initialize.hpp b/initialize.hpp index b378574..0e587b1 100644 --- a/initialize.hpp +++ b/initialize.hpp @@ -11,7 +11,7 @@ void ClientBGThread() { while (g_Running) { g_Menu->Loops(); - std::this_thread::sleep_for(0ms); + std::this_thread::sleep_for(1ms); std::this_thread::yield(); } } @@ -42,7 +42,12 @@ DWORD WINAPI MainThread_Initialize() g_Running = TRUE; while (g_Running) { - if (GetAsyncKeyState(VK_INSERT) & 1) g_GameVariables->m_ShowMenu = !g_GameVariables->m_ShowMenu; + if (GetAsyncKeyState(VK_INSERT) & 1) + { + g_GameVariables->m_ShowMenu = !g_GameVariables->m_ShowMenu; + g_GameVariables->m_ShowHud = !g_GameVariables->m_ShowMenu; + + } } /// EXIT diff --git a/src/D3D11Window.cpp b/src/D3D11Window.cpp index c2d1eb0..4427d5a 100644 --- a/src/D3D11Window.cpp +++ b/src/D3D11Window.cpp @@ -208,6 +208,8 @@ namespace DX11_Base { ImGui::GetIO().ImeWindowHandle = g_GameVariables->g_GameWindow; m_OldWndProc = (WNDPROC)SetWindowLongPtr(g_GameVariables->g_GameWindow, GWLP_WNDPROC, (__int3264)(LONG_PTR)WndProc); b_ImGui_Initialized = TRUE; + pImGui = GImGui; + pViewport = pImGui->Viewports[0]; #if DEBUG g_Console->printdbg("D3D11Window::Swapchain Initialized\n", Console::Colors::pink); #endif diff --git a/src/Menu.cpp b/src/Menu.cpp index c85ef9d..5297e2a 100644 --- a/src/Menu.cpp +++ b/src/Menu.cpp @@ -271,15 +271,21 @@ namespace DX11_Base void TABDebug() { + ImGui::Checkbox("DEBUG ESP", &Config.isDebugESP); + if (Config.isDebugESP) + { + ImGui::SameLine(); + ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x); + ImGui::SliderFloat("##DISTANCE", &Config.mDebugESPDistance, 1.0f, 100.f, "%.0f", ImGuiSliderFlags_AlwaysClamp); + } // @TODO: print additional debug information if (ImGui::Button("PrintPlayerAddr", ImVec2(ImGui::GetContentRegionAvail().x - 3, 20))) { SDK::APalPlayerCharacter* p_appc = Config.GetPalPlayerCharacter(); - if (p_appc != NULL) - { - g_Console->printdbg("\n\n[+] APalPlayerCharacter: %x [+]\n\n", Console::Colors::green, p_appc); - } + if (p_appc) + g_Console->printdbg("\n\n[+] APalPlayerCharacter: 0x%llX\n", Console::Colors::green, p_appc); + } ImGui::InputTextWithHint("##INPUT", "INPUT GOBJECT fn NAME", inputBuffer_getFnAddr, 100); @@ -293,9 +299,11 @@ namespace DX11_Base static __int64 dwHandle = reinterpret_cast<__int64>(GetModuleHandle(0)); void* fnAddr = object->ExecFunction; unsigned __int64 fnOffset = (reinterpret_cast<__int64>(fnAddr) - dwHandle); - g_Console->printdbg("[+] Found %s @ 0x%llX\n", Console::Colors::yellow, input.c_str(), fnOffset); - + g_Console->printdbg("[+] Found [%s] -> 0x%llX\n", Console::Colors::yellow, input.c_str(), fnOffset); } + else + g_Console->printdbg("[!] OBJECT [%s] NOT FOUND!\n", Console::Colors::red, input.c_str()); + memset(inputBuffer_getFnAddr, 0, 100); } } @@ -303,23 +311,15 @@ namespace DX11_Base void Menu::Draw() { - if (Config.IsESP) - ESP(); if (g_GameVariables->m_ShowMenu) MainMenu(); - if (Config.bisOpenManager && g_GameVariables->m_ShowMenu) - ManagerMenu(); - if (g_GameVariables->m_ShowHud) HUD(&g_GameVariables->m_ShowHud); if (g_GameVariables->m_ShowDemo) ImGui::ShowDemoWindow(); - - if (Config.isDebugESP) - ESP_DEBUG(Config.mDebugESPDistance, ImVec4(0,1,0,1)); } void Menu::ManagerMenu() @@ -468,6 +468,8 @@ namespace DX11_Base ImGui::PopStyleColor(); } + ImGuiContext* pImGui = GImGui; + // Display Menu Content //Tabs::TABMain(); @@ -495,6 +497,13 @@ namespace DX11_Base Tabs::TABConfig(); ImGui::EndTabItem(); } +#if DEBUG + if (ImGui::BeginTabItem("DEBUG")) + { + Tabs::TABDebug(); + ImGui::EndTabItem(); + } +#endif if (Config.IsQuick && ImGui::BeginTabItem("Quick")) { Tabs::TABQuick(); @@ -508,10 +517,45 @@ namespace DX11_Base ImGui::EndTabBar(); } ImGui::End(); + + + + if (Config.bisOpenManager) + ManagerMenu(); } void Menu::HUD(bool* p_open) { + + ImGui::SetNextWindowPos(g_D3D11Window->pViewport->WorkPos); + ImGui::SetNextWindowSize(g_D3D11Window->pViewport->WorkSize); + ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, NULL); + ImGui::PushStyleColor(ImGuiCol_WindowBg, ImVec4(0.00f, 0.00f, 0.00f, 0.00f)); + if (!ImGui::Begin("##HUDWINDOW", (bool*)true, ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoInputs)) + { + ImGui::PopStyleColor(); + ImGui::PopStyleVar(); + ImGui::End(); + return; + } + ImGui::PopStyleColor(); + ImGui::PopStyleVar(); + + auto ImDraw = ImGui::GetWindowDrawList(); + auto draw_size = g_D3D11Window->pViewport->WorkSize; + auto center = ImVec2({ draw_size.x * .5f, draw_size.y * .5f }); + auto top_center = ImVec2({ draw_size.x * .5f, draw_size.y * 0.0f }); + + // Watermark + ImDraw->AddText(top_center, g_Menu->dbg_RAINBOW, "PalWorld-NetCrack"); + + if (Config.IsESP) + ESP(); + + if (Config.isDebugESP) + ESP_DEBUG(Config.mDebugESPDistance, ImVec4(0, 1, 0, 1)); + + ImGui::End(); } void Menu::Loops()