From ce6c64d39327d01af01997d2b9f221eff9470305 Mon Sep 17 00:00:00 2001 From: slayercio Date: Tue, 18 Nov 2025 22:01:09 +0100 Subject: [PATCH] feat: added examples --- examples/native_invoker.cpp | 80 +++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 examples/native_invoker.cpp diff --git a/examples/native_invoker.cpp b/examples/native_invoker.cpp new file mode 100644 index 0000000..86375c4 --- /dev/null +++ b/examples/native_invoker.cpp @@ -0,0 +1,80 @@ +#include +#include +#include + +void MainFunc() +{ + fxn::invoker_base::initialize("vcruntime140_1.dll"); + + constexpr auto GIVE_WEAPON_TO_PED = 0xB41DEC3AAC1AA107; + fxn::native_hooker<0xB41DEC3AAC1AA107> giveWeaponHook([](fxn::NativeContext* context, bool& callOriginal) -> bool + { + auto pedId = context->GetArgument(0); + auto weaponHash = context->GetArgument(1); + auto ammoCount = context->GetArgument(2); + auto isHidden = context->GetArgument(3); + auto bForceInHand = context->GetArgument(4); + + printf("GiveWeaponToPed Hooked! PedID: %d, WeaponHash: 0x%X, AmmoCount: %d, IsHidden: %d, ForceInHand: %d\n", + pedId, weaponHash, ammoCount, isHidden, bForceInHand); + + // Allow original function to be called + callOriginal = true; + return true; + }); + + while (!GetAsyncKeyState(VK_END)) + { + if (GetAsyncKeyState(VK_F1)) + { + auto playerPedId = fxn::invoker<0x4A8C381C258A124D, int>::invoke(); + printf("Player Ped ID: %d\n", playerPedId); + + auto weaponHash = fxn::HashString("WEAPON_PISTOL"); + fxn::invoker<0xB41DEC3AAC1AA107, void, int, unsigned int, int, bool, bool>::invoke( + playerPedId, + weaponHash, + 250, + true, true + ); + + Sleep(500); // Debounce + } + + Sleep(10); + } +} + +DWORD ThreadMain(LPVOID lpParam) +{ + FILE* fp; + AllocConsole(); + freopen_s(&fp, "CONOUT$", "w", stdout); + + HMODULE hModule = (HMODULE)lpParam; + + MainFunc(); + + FreeConsole(); + if (fp) + { + fclose(fp); + } + + FreeLibraryAndExitThread(hModule, 0); + return 0; +} + +BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) +{ + if (ul_reason_for_call == DLL_PROCESS_ATTACH) + { + HANDLE hThread = CreateThread(NULL, NULL, ThreadMain, hModule, NULL, NULL); + if (hThread) + { + CloseHandle(hThread); + } + } + + return TRUE; +} \ No newline at end of file