feat(NativeHooks): Added basics for native hooking

This commit is contained in:
Yimura 2021-11-08 13:05:28 +01:00
parent 50eb335bd6
commit 007d905819
No known key found for this signature in database
GPG Key ID: 3D8FF4397E768682
8 changed files with 85 additions and 2 deletions

View File

@ -8,6 +8,7 @@
#include "hooking.hpp"
#include "memory/module.hpp"
#include "natives.hpp"
#include "native_hooks/native_hooks.hpp"
#include "pointers.hpp"
#include "renderer.hpp"
#include "script_mgr.hpp"

View File

@ -63,6 +63,8 @@ namespace big
void enable();
void disable();
std::list<script_hook*> m_native_hooks;
std::unordered_map<rage::scrNativeHash, rage::scrNativeHandler> m_natives;
private:
bool m_enabled{};
minhook_keepalive m_minhook_keepalive;

View File

@ -0,0 +1,16 @@
#pragma once
#include "natives.hpp"
namespace big::native_hook
{
inline void NETWORK_CAN_BAIL(rage::scrNativeCallContext* src);
inline void STAT_SET_INT(rage::scrNativeCallContext* src);
inline void TRIGGER_SCRIPT_EVENT(rage::scrNativeCallContext* src);
static std::unordered_map<rage::scrNativeHash, rage::scrNativeHandler> natives_replace =
{
{ 0x580CE4438479CC61, &NETWORK_CAN_BAIL },
{ 0xB3271D7AB655B441, &STAT_SET_INT },
{ 0x5AE99C571D5BBE5D, &TRIGGER_SCRIPT_EVENT }
};
}

View File

@ -0,0 +1,11 @@
#include "native_hooks.hpp"
namespace big::native_hook
{
void NETWORK_CAN_BAIL(rage::scrNativeCallContext* src)
{
LOG(INFO) << "NATIVE_HOOK => NETWORK_CAN_BAIL : TRIGGERED";
src->set_return_value<BOOL>(false);
}
}

View File

@ -0,0 +1,28 @@
#include "native_hooks.hpp"
#include "gta/joaat.hpp"
namespace big::native_hook
{
void STAT_SET_INT(rage::scrNativeCallContext* src)
{
Hash stat_hash = src->get_arg<Hash>(0);
int value = src->get_arg<int>(1);
BOOL save = src->get_arg<BOOL>(2);
switch (stat_hash)
{
case RAGE_JOAAT("MPPLY_GAME_EXPLOITS"):
case RAGE_JOAAT("MPPLY_VC_HATE"):
case RAGE_JOAAT("MPPLY_EXPLOITS"):
case RAGE_JOAAT("MPPLY_TC_ANNOYINGME"):
case RAGE_JOAAT("MPPLY_TC_HATE"):
src->set_return_value<BOOL>(true);
break;
default:
src->set_return_value<BOOL>(STATS::STAT_SET_INT(stat_hash, value, save));
break;
}
}
}

View File

@ -0,0 +1,24 @@
#include "native_hooks.hpp"
#include "pointers.hpp"
namespace big::native_hook
{
void TRIGGER_SCRIPT_EVENT(rage::scrNativeCallContext* src)
{
int event_group = src->get_arg<int>(0);
Any* event_data = src->get_arg<Any*>(1);
int event_size = src->get_arg<int>(3);
int player_bits = src->get_arg<int>(4);
if (event_group)
{
Hash event_hash = event_data[0];
LOG(INFO) << "Event hash: " << event_hash;
for (size_t i = 1; i < std::min(event_size, 200); i++)
LOG(INFO) << "Arg[#" << i << "] : " << event_data[i];
}
SCRIPT::TRIGGER_SCRIPT_EVENT(event_group, event_data, event_size, player_bits);
}
}

View File

@ -3,6 +3,7 @@
#include "gta/fwddec.hpp"
#include "gta/enums.hpp"
#include "gta/replay.hpp"
#include "gta/script_program.hpp"
#include "function_types.hpp"
namespace big

View File

@ -35,8 +35,8 @@ namespace big::toxic
inline void bounty_player(Player target, Player origin, int amount)
{
const size_t arg_count = 22;
int64_t args[22] = {
2388821078, // 0
int args[22] = {
(int)eRemoteEvent::Bounty, // 0
origin, // 1 Player in script self
target, // 2 Player in script self
0, // 3 unk