feat: added examples
This commit is contained in:
80
examples/native_invoker.cpp
Normal file
80
examples/native_invoker.cpp
Normal file
@@ -0,0 +1,80 @@
|
|||||||
|
#include <windows.h>
|
||||||
|
#include <fxn/invoker.hpp>
|
||||||
|
#include <fxn/utility.hpp>
|
||||||
|
|
||||||
|
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<int>(0);
|
||||||
|
auto weaponHash = context->GetArgument<unsigned int>(1);
|
||||||
|
auto ammoCount = context->GetArgument<int>(2);
|
||||||
|
auto isHidden = context->GetArgument<bool>(3);
|
||||||
|
auto bForceInHand = context->GetArgument<bool>(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;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user