Optimizations (#2649)

* fix(Respawn): fix respawn in SP
* fix: re-enable bigobj
* fix: update creator's stack size
* fix: use BOOLs instead of bools
* fix(gitignore): hide .pyc files
This commit is contained in:
maybegreat48 2023-12-29 16:07:00 +00:00 committed by GitHub
parent 5312960e22
commit 22e15e95d6
132 changed files with 140632 additions and 14651 deletions

1
.gitignore vendored
View File

@ -13,6 +13,7 @@ __pycache__/
*.ipch
*.gch
*.pch
*.pyc
# generated by CMAKE
version.cpp

View File

@ -14,7 +14,6 @@ include(scripts/async-logger.cmake)
include(scripts/pugixml.cmake)
include(scripts/json.cmake)
include(scripts/cpr.cmake)
include(scripts/zydis.cmake)
include(scripts/lua.cmake)
include(scripts/imgui.cmake)
message("\nFetching custom modules")
@ -52,10 +51,11 @@ target_include_directories(YimMenu PRIVATE
"${json_SOURCE_DIR}/single_include"
"${gtav_classes_SOURCE_DIR}"
"${imgui_SOURCE_DIR}"
"${minhook_SOURCE_DIR}/src/hde"
)
target_precompile_headers(YimMenu PRIVATE "${SRC_DIR}/common.hpp")
target_link_libraries(YimMenu PRIVATE pugixml minhook AsyncLogger dbghelp imgui cpr Zydis lua_static)
target_link_libraries(YimMenu PRIVATE pugixml minhook AsyncLogger dbghelp imgui cpr lua_static)
# Warnings as errors
set_property(TARGET YimMenu PROPERTY COMPILE_WARNING_AS_ERROR ON)
@ -65,3 +65,13 @@ add_compile_definitions(YimMenu
"NOMINMAX"
"WIN32_LEAN_AND_MEAN"
)
# Optimizations
if(MSVC)
set(CMAKE_MODULE_LINKER_FLAGS
"${CMAKE_MODULE_LINKER_FLAGS} /LTCG /OPT:REF,ICF /GUARD:NO")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO
"${CMAKE_CXX_FLAGS_RELWITHDEBINFO} /O2 /Ox /Oi /Ot /Oy /Ob3 /sdl- /GL /GF /GS- /Gw")
string(REPLACE "/Ob1" "/Ob3" CMAKE_CXX_FLAGS_RELWITHDEBINFO ${CMAKE_CXX_FLAGS_RELWITHDEBINFO})
endif()

View File

@ -1,16 +1,5 @@
{
"configurations": [
{
"name": "x64-Debug",
"generator": "Ninja",
"configurationType": "Debug",
"inheritEnvironments": [ "msvc_x64_x64" ],
"buildRoot": "${projectDir}\\out\\build\\${name}",
"installRoot": "${projectDir}\\out\\install\\${name}",
"cmakeCommandArgs": "",
"buildCommandArgs": "",
"ctestCommandArgs": ""
},
{
"name": "x64-Release",
"generator": "Ninja",
@ -21,6 +10,18 @@
"cmakeCommandArgs": "",
"buildCommandArgs": "",
"ctestCommandArgs": ""
},
{
"name": "x64-Debug",
"generator": "Ninja",
"configurationType": "Debug",
"buildRoot": "${projectDir}\\out\\build\\${name}",
"installRoot": "${projectDir}\\out\\install\\${name}",
"cmakeCommandArgs": "",
"buildCommandArgs": "",
"ctestCommandArgs": "",
"inheritEnvironments": [ "msvc_x64_x64" ],
"variables": []
}
]
}

View File

@ -3,7 +3,7 @@ include(FetchContent)
FetchContent_Declare(
gtav_classes
GIT_REPOSITORY https://github.com/Yimura/GTAV-Classes.git
GIT_TAG eab95fba6d19ceeee0442158b6f5de6824ff7349
GIT_TAG e8d8bdd2b3152253f6e1fde48720e4caeab19f83
GIT_PROGRESS TRUE
CONFIGURE_COMMAND ""
BUILD_COMMAND ""

View File

@ -1,15 +0,0 @@
include(FetchContent)
message("zydis")
set(ZYDIS_BUILD_DOXYGEN OFF CACHE BOOL "Zydis Build Doxygen")
set(ZYDIS_FEATURE_ENCODER OFF CACHE BOOL "Zydis Feature Encoder")
FetchContent_Declare(
zydis
GIT_REPOSITORY https://github.com/zyantific/zydis.git
GIT_TAG 8948d9a8f493330d27a0e7bbebf40f0391e45f1b
GIT_PROGRESS TRUE
)
FetchContent_MakeAvailable(zydis)
set_property(TARGET Zydis PROPERTY CXX_STANDARD 23)

View File

@ -1,13 +1,8 @@
#include "backend/player_command.hpp"
#include "core/scr_globals.hpp"
#include "fiber_pool.hpp"
#include "gta/net_object_mgr.hpp"
#include "gta/script_handler.hpp"
#include "hooking.hpp"
#include "natives.hpp"
#include "pointers.hpp"
#include "services/script_connection/script_connection_service.hpp"
#include "util/scripts.hpp"
#include <script/globals/GPBD_FM.hpp>
#include <script/globals/GlobalPlayerBD.hpp>

View File

@ -1,7 +1,7 @@
#include "chat_command_context.hpp"
#include "fiber_pool.hpp"
#include "hooking.hpp"
#include "hooking/hooking.hpp"
#include "util/notify.hpp"
namespace big

View File

@ -1,5 +1,4 @@
#include "backend/looped/looped.hpp"
#include "hooking.hpp"
#include "natives.hpp"
#include "script_function.hpp"
#include "services/script_patcher/script_patcher_service.hpp"

View File

@ -43,7 +43,7 @@ namespace big
-1,
0,
7);
int did_raycast_hit = 0;
BOOL did_raycast_hit{FALSE};
Vector3 raycast_hit_position{};
Vector3 raycast_surface_normal_hit_position{};
Entity raycast_hit_entity{};

View File

@ -30,7 +30,7 @@ namespace big
}
Hash current_weapon, current_vehicle_weapon;
WEAPON::GET_CURRENT_PED_WEAPON(player_ped, &current_weapon, -1);
WEAPON::GET_CURRENT_PED_WEAPON(player_ped, &current_weapon, false);
WEAPON::GET_CURRENT_PED_VEHICLE_WEAPON(player_ped, &current_vehicle_weapon);
for (int iterator_keys = 0; iterator_keys < 6; iterator_keys++)
{

View File

@ -2,7 +2,7 @@
#include "backend/player_command.hpp"
#include "fiber_pool.hpp"
#include "hooking.hpp"
#include "hooking/hooking.hpp"
#include "pointers.hpp"
#include "script.hpp"
#include "util/notify.hpp"

View File

@ -2,7 +2,7 @@
#include "backend/player_command.hpp"
#include "fiber_pool.hpp"
#include "hooking.hpp"
#include "hooking/hooking.hpp"
#include "pointers.hpp"
#include "script.hpp"
#include "services/player_database/player_database_service.hpp"

View File

@ -1,7 +1,7 @@
#include "byte_patch_manager.hpp"
#include "gta/net_array.hpp"
#include "hooking.hpp"
#include "hooking/hooking.hpp"
#include "memory/byte_patch.hpp"
#include "pointers.hpp"
#include "util/explosion_anti_cheat_bypass.hpp"

View File

@ -56,7 +56,6 @@
#include "logger/logger.hpp"
#include "core/settings.hpp"
#include "gta/natives.hpp"
#include "ped/CPed.hpp"
#include "services/notifications/notification_service.hpp"
@ -65,6 +64,8 @@
#define SOL_ALL_SAFETIES_ON 1
#include "lua/sol.hpp"
#include <script/types.hpp>
// clang-format on
namespace big

View File

@ -2,6 +2,7 @@
namespace big
{
// Get new values from gameconfig.xml
constexpr inline static const std::pair<const char*, int> stack_sizes[] = {
{"MICRO", 128},
{"MINI", 512},
@ -10,26 +11,26 @@ namespace big
{"FRIEND", 2050},
{"SHOP", 2324},
{"CELLPHONE", 2552},
{"VEHICLE_SPAWN", 3568},
{"CAR_MOD_SHOP", 3650},
{"VEHICLE_SPAWN", 3868},
{"CAR_MOD_SHOP", 3750},
{"PAUSE_MENU_SCRIPT", 3076},
{"APP_INTERNET", 4592},
{"MULTIPLAYER_MISSION", 5050},
{"CONTACTS_APP", 4000},
{"INTERACTION_MENU", 9800},
{"SCRIPT_XML", 8344},
{"SCRIPT_XML", 8500},
{"PROPERTY_INT", 19400},
{"ACTIVITY_CREATOR_INT", 15900},
{"SMPL_INTERIOR", 2512},
{"SMPL_INTERIOR", 6500},
{"WAREHOUSE", 14100},
{"IE_DELIVERY", 2324},
{"SHOP_CONTROLLER", 3800},
{"AM_MP_YACHT", 5000},
{"INGAMEHUD", 4600},
{"TRANSITION", 8032},
{"FMMC_LAUNCHER", 24000},
{"MULTIPLAYER_FREEMODE", 72500},
{"MISSION", 54000},
{"MP_LAUNCH_SCRIPT", 33750},
{"FMMC_LAUNCHER", 26000},
{"MULTIPLAYER_FREEMODE", 82500},
{"MISSION", 60500},
{"MP_LAUNCH_SCRIPT", 37500},
};
}

File diff suppressed because it is too large Load Diff

View File

@ -1,9 +0,0 @@
#pragma once
#include "gta/natives.hpp"
namespace big
{
constexpr auto NATIVE_COUNT = 6568;
using crossmap = std::array<std::pair<rage::scrNativeHash, rage::scrNativeHash>, NATIVE_COUNT>;
extern const crossmap g_crossmap;
}

View File

@ -1,5 +1,6 @@
#pragma once
#include <rage/rlTaskStatus.hpp>
#include <script/scrNativeHandler.hpp>
class CMsgJoinResponse;
class NetworkGameFilterMatchmakingComponent;
@ -12,6 +13,9 @@ class GenericPool;
class CGetPedSeatReturnClass;
enum eVehicleGadgetType : uint32_t;
enum class PedBones : uint16_t;
class CNetComplaintMgr;
class Network;
class CNetworkObjectMgr;
namespace rage
{
@ -36,6 +40,10 @@ namespace rage
class fwEntity;
class netGameEvent;
class netEventMgr;
class fiDevice;
class fiPackfile;
class scrNativeRegistrationTable;
class rlSessionByGamerTaskResult;
struct rlScTaskStatus
{
void* pad = 0;

View File

@ -1,6 +1,6 @@
#include "fidevice.hpp"
#include "hooking.hpp"
#include "hooking/hooking.hpp"
#include "pointers.hpp"
namespace rage

View File

@ -1,119 +0,0 @@
#pragma once
#include "fwddec.hpp"
#include <cstdint>
#include <script/types.hpp>
#include <utility>
namespace rage
{
class scrNativeCallContext
{
public:
constexpr void reset()
{
m_arg_count = 0;
m_data_count = 0;
}
template<typename T>
constexpr void push_arg(T&& value)
{
static_assert(sizeof(T) <= sizeof(uint64_t));
*reinterpret_cast<std::remove_cv_t<std::remove_reference_t<T>>*>(reinterpret_cast<uint64_t*>(m_args) + (m_arg_count++)) = std::forward<T>(value);
}
template<typename T>
constexpr T& get_arg(std::size_t index)
{
static_assert(sizeof(T) <= sizeof(uint64_t));
return *reinterpret_cast<T*>(reinterpret_cast<uint64_t*>(m_args) + index);
}
template<typename T>
constexpr void set_arg(std::size_t index, T&& value)
{
static_assert(sizeof(T) <= sizeof(uint64_t));
*reinterpret_cast<std::remove_cv_t<std::remove_reference_t<T>>*>(reinterpret_cast<uint64_t*>(m_args) + index) = std::forward<T>(value);
}
template<typename T>
constexpr T* get_return_value()
{
return reinterpret_cast<T*>(m_return_value);
}
template<typename T>
constexpr void set_return_value(T&& value)
{
*reinterpret_cast<std::remove_cv_t<std::remove_reference_t<T>>*>(m_return_value) = std::forward<T>(value);
}
template<typename T>
constexpr void set_return_value(T& value)
{
*reinterpret_cast<std::remove_cv_t<std::remove_reference_t<T>>*>(m_return_value) = std::forward<T>(value);
}
protected:
void* m_return_value;
uint32_t m_arg_count;
void* m_args;
std::int32_t m_data_count;
uint32_t m_data[48];
};
static_assert(sizeof(scrNativeCallContext) == 0xE0);
using scrNativeHash = uint64_t;
using scrNativeMapping = std::pair<scrNativeHash, scrNativeHash>;
using scrNativeHandler = void (*)(scrNativeCallContext*);
class scrNativeRegistration
{
public:
uint64_t m_nextRegistration1;
uint64_t m_nextRegistration2;
void* m_handlers[7];
uint32_t m_numEntries1;
uint32_t m_numEntries2;
uint64_t m_hashes;
scrNativeRegistration* get_next_registration()
{
std::uintptr_t result;
auto nextReg = uintptr_t(&m_nextRegistration1);
auto newReg = nextReg ^ m_nextRegistration2;
auto charTableOfRegs = (char*)&result - nextReg;
for (auto i = 0; i < 3; i++)
{
*(DWORD*)&charTableOfRegs[nextReg] = static_cast<DWORD>(newReg) ^ *(DWORD*)nextReg;
nextReg += 4;
}
return reinterpret_cast<scrNativeRegistration*>(result);
}
uint32_t get_num_entries()
{
return static_cast<uint32_t>(((std::uintptr_t)&m_numEntries1) ^ m_numEntries1 ^ m_numEntries2);
}
uint64_t get_hash(uint32_t index)
{
auto nativeAddress = 16 * index + std::uintptr_t(&m_nextRegistration1) + 0x54;
uint64_t result;
auto charTableOfRegs = (char*)&result - nativeAddress;
auto addressIndex = nativeAddress ^ *(DWORD*)(nativeAddress + 8);
for (auto i = 0; i < 3; i++)
{
*(DWORD*)&charTableOfRegs[nativeAddress] = static_cast<DWORD>(addressIndex ^ *(DWORD*)(nativeAddress));
nativeAddress += 4;
}
return result;
}
};
#pragma pack(push, 1)
class scrNativeRegistrationTable
{
scrNativeRegistration* m_entries[0xFF];
uint32_t m_unk;
bool m_initialized;
};
#pragma pack(pop)
}

View File

@ -14,6 +14,7 @@ class CNetGamePlayer;
namespace rage
{
class netArrayHandlerBase;
class netPlayer;
}
class CGameArrayMgr

View File

@ -1,6 +1,5 @@
#include "detour_hook.hpp"
#include "common.hpp"
#include "memory/handle.hpp"
#include <MinHook.h>

View File

@ -1,17 +1,6 @@
#include "hooking.hpp"
#include "hooking/hooking.hpp"
#include "common.hpp"
#include "function_types.hpp"
#include "gta/script_thread.hpp"
#include "gui.hpp"
#include "memory/module.hpp"
#include "natives.hpp"
#include "pointers.hpp"
#include "renderer.hpp"
#include "script_mgr.hpp"
#include <MinHook.h>
#include <vehicle/CVehicle.hpp>
namespace big
{
@ -211,14 +200,4 @@ namespace big
MH_ApplyQueued();
}
}
bool hooks::run_script_threads(uint32_t ops_to_execute)
{
if (g_running)
{
g_script_mgr.tick();
}
return g_hooking->get_original<run_script_threads>()(ops_to_execute);
}
}

View File

@ -1,16 +1,11 @@
#pragma once
#include "MinHook.h"
#include "call_hook.hpp"
#include "common.hpp"
#include "detour_hook.hpp"
#include "gta/enums.hpp"
#include "gta/fwddec.hpp"
#include "gta/json_serializer.hpp"
#include "gta/script_thread.hpp"
#include "vmt_hook.hpp"
#include "vtable_hook.hpp"
#include <network/netConnection.hpp>
#include <network/netConnection.hpp> // cannot stub this
class CPlayerGamerDataNode;
class CPlayerGameStateDataNode;
@ -39,6 +34,12 @@ class CNonPhysicalPlayerData;
class TimecycleKeyframeData;
class CPedTaskSpecificDataNode;
class CPedTaskSequenceDataNode;
class Network;
class GtaThread;
class CNetworkPlayerMgr;
class CNetworkObjectMgr;
enum class eAckCode : uint32_t;
namespace rage
{
@ -52,6 +53,9 @@ namespace rage
class datBitBuffer;
class rlMetric;
class rlTaskStatus;
class netEventMgr;
class json_serializer;
class netGameEvent;
}
namespace big
@ -183,8 +187,6 @@ namespace big
static bool sync_reader_serialize_vec3(void* _this, rage::fvector3* vec, float divisor, int size);
static bool sync_reader_serialize_vec3_signed(void* _this, rage::fvector3* vec, float divisor, int size);
static bool sync_reader_serialize_array(void* _this, void* array, int size);
static bool remove_player_from_sender_list(void* list, uint64_t rockstar_id);
};
class minhook_keepalive

View File

@ -1,5 +1,4 @@
#pragma once
#include "common.hpp"
namespace big
{

View File

@ -1,5 +1,4 @@
#pragma once
#include "common.hpp"
namespace big
{

View File

@ -1,4 +1,4 @@
#include "hooking.hpp"
#include "hooking/hooking.hpp"
#include "natives.hpp"
#include "util/fuzzer.hpp"

View File

@ -1,4 +1,4 @@
#include "hooking.hpp"
#include "hooking/hooking.hpp"
#include "util/fuzzer.hpp"
namespace big

View File

@ -1,4 +1,4 @@
#include "hooking.hpp"
#include "hooking/hooking.hpp"
#include "renderer.hpp"
#include "script.hpp"

View File

@ -1,4 +1,4 @@
#include "hooking.hpp"
#include "hooking/hooking.hpp"
#include "renderer.hpp"
#include "script.hpp"

View File

@ -1,4 +1,4 @@
#include "hooking.hpp"
#include "hooking/hooking.hpp"
#include "renderer.hpp"
#include "script.hpp"

View File

@ -1,5 +1,5 @@
#include "gta/net_game_event.hpp"
#include "hooking.hpp"
#include "hooking/hooking.hpp"
#include "services/players/player_service.hpp"
#include "util/globals.hpp"
#include "util/misc.hpp"

View File

@ -1,5 +1,6 @@
#include "hooking.hpp"
#include "hooking/hooking.hpp"
#include "rage/rlMetric.hpp"
#include "gta/json_serializer.hpp"
namespace big
{

View File

@ -1,4 +1,4 @@
#include "hooking.hpp"
#include "hooking/hooking.hpp"
#include "services/custom_text/custom_text_service.hpp"
namespace big

View File

@ -1,4 +1,4 @@
#include "hooking.hpp"
#include "hooking/hooking.hpp"
#include "util/model_info.hpp"
namespace big

View File

@ -1,4 +1,4 @@
#include "hooking.hpp"
#include "hooking/hooking.hpp"
#include "logger/stack_trace.hpp"
#include "pointers.hpp"
#include "util/string_conversions.hpp"

View File

@ -1,4 +1,4 @@
#include "hooking.hpp"
#include "hooking/hooking.hpp"
#include "logger/stack_trace.hpp"
#include "pointers.hpp"
#include "util/string_conversions.hpp"

View File

@ -1,4 +1,4 @@
#include "hooking.hpp"
#include "hooking/hooking.hpp"
namespace big
{

View File

@ -1,4 +1,4 @@
#include "hooking.hpp"
#include "hooking/hooking.hpp"
namespace big
{

View File

@ -1,4 +1,4 @@
#include "hooking.hpp"
#include "hooking/hooking.hpp"
#include "services/matchmaking/matchmaking_service.hpp"
namespace rage

View File

@ -1,4 +1,4 @@
#include "hooking.hpp"
#include "hooking/hooking.hpp"
#include "pointers.hpp"
#include "security/ObfVar.hpp"
#include <Psapi.h>

View File

@ -2,7 +2,7 @@
#include "backend/context/chat_command_context.hpp"
#include "gta/net_game_event.hpp"
#include "gta_util.hpp"
#include "hooking.hpp"
#include "hooking/hooking.hpp"
#include "packet.hpp"
#include "services/players/player_service.hpp"
#include "util/spam.hpp"

View File

@ -1,5 +1,5 @@
#include "gta_util.hpp"
#include "hooking.hpp"
#include "hooking/hooking.hpp"
#include <network/Network.hpp>
#include <network/RemoteGamerInfoMsg.hpp>

View File

@ -1,5 +1,5 @@
#include "gta_util.hpp"
#include "hooking.hpp"
#include "hooking/hooking.hpp"
#include <network/CNetGamePlayerDataMsg.hpp>
#include <network/Network.hpp>

View File

@ -1,4 +1,4 @@
#include "hooking.hpp"
#include "hooking/hooking.hpp"
#include <network/Network.hpp>

View File

@ -1,6 +1,6 @@
#include "fiber_pool.hpp"
#include "function_types.hpp"
#include "hooking.hpp"
#include "hooking/hooking.hpp"
#include "services/matchmaking/matchmaking_service.hpp"
#include <network/Network.hpp>

View File

@ -1,4 +1,4 @@
#include "hooking.hpp"
#include "hooking/hooking.hpp"
namespace big
{

View File

@ -1,4 +1,4 @@
#include "hooking.hpp"
#include "hooking/hooking.hpp"
#include <misc/vfx/TimecycleKeyframeData.hpp>

View File

@ -2,7 +2,7 @@
#include "core/data/admin_rids.hpp"
#include "fiber_pool.hpp"
#include "gta_util.hpp"
#include "hooking.hpp"
#include "hooking/hooking.hpp"
#include "lua/lua_manager.hpp"
#include "packet.hpp"
#include "services/player_database/player_database_service.hpp"

View File

@ -1,5 +1,5 @@
#include "core/data/menu_event.hpp"
#include "hooking.hpp"
#include "hooking/hooking.hpp"
#include "lua/lua_manager.hpp"
#include "pointers.hpp"
#include "services/players/player_service.hpp"

View File

@ -1,5 +1,5 @@
#include "gta/net_game_event.hpp"
#include "hooking.hpp"
#include "hooking/hooking.hpp"
#include "pointers.hpp"
#include <rage/sysMemAllocator.hpp>

View File

@ -1,4 +1,4 @@
#include "hooking.hpp"
#include "hooking/hooking.hpp"
namespace big
{

View File

@ -1,4 +1,4 @@
#include "hooking.hpp"
#include "hooking/hooking.hpp"
#include "pointers.hpp"
#include "services/player_database/player_database_service.hpp"

View File

@ -1,5 +1,5 @@
#include "gta/net_game_event.hpp"
#include "hooking.hpp"
#include "hooking/hooking.hpp"
#include "services/players/player_service.hpp"
#include <network/CNetGamePlayer.hpp>

View File

@ -1,4 +1,4 @@
#include "hooking.hpp"
#include "hooking/hooking.hpp"
namespace big
{

View File

@ -1,4 +1,4 @@
#include "hooking.hpp"
#include "hooking/hooking.hpp"
namespace big
{

View File

@ -4,13 +4,14 @@
#include "core/data/packet_types.hpp"
#include "gta/net_game_event.hpp"
#include "gta_util.hpp"
#include "hooking.hpp"
#include "hooking/hooking.hpp"
#include "lua/lua_manager.hpp"
#include "natives.hpp"
#include "script/scriptIdBase.hpp"
#include "services/players/player_service.hpp"
#include "util/session.hpp"
#include "util/spam.hpp"
#include "gta/enums.hpp"
#include <network/Network.hpp>
#include <network/netTime.hpp>

View File

@ -1,4 +1,4 @@
#include "hooking.hpp"
#include "hooking/hooking.hpp"
namespace big
{

View File

@ -2,7 +2,7 @@
#include "gta/net_array.hpp"
#include "gta/script_handler.hpp"
#include "gta_util.hpp"
#include "hooking.hpp"
#include "hooking/hooking.hpp"
#include "script_local.hpp"
#include "services/players/player_service.hpp"
#include "util/misc.hpp"

View File

@ -1,4 +1,4 @@
#include "hooking.hpp"
#include "hooking/hooking.hpp"
#include "services/players/player_service.hpp"
#include "util/notify.hpp"

View File

@ -1,4 +1,4 @@
#include "hooking.hpp"
#include "hooking/hooking.hpp"
#include "services/players/player_service.hpp"
#include "util/notify.hpp"

View File

@ -1,7 +1,7 @@
#include "fiber_pool.hpp"
#include "gta/enums.hpp"
#include "gta/net_game_event.hpp"
#include "hooking.hpp"
#include "hooking/hooking.hpp"
#include "script/scriptIdBase.hpp"
#include "util/math.hpp"
#include "util/mobile.hpp"

View File

@ -1,4 +1,4 @@
#include "hooking.hpp"
#include "hooking/hooking.hpp"
#include "pointers.hpp"
namespace big

View File

@ -1,4 +1,4 @@
#include "hooking.hpp"
#include "hooking/hooking.hpp"
#include "pointers.hpp"
namespace big

View File

@ -1,4 +1,4 @@
#include "hooking.hpp"
#include "hooking/hooking.hpp"
#include "pointers.hpp"
namespace big

View File

@ -2,7 +2,7 @@
#include "gta/net_game_event.hpp"
#include "gta/script_handler.hpp"
#include "gta_util.hpp"
#include "hooking.hpp"
#include "hooking/hooking.hpp"
#include "lua/lua_manager.hpp"
#include "util/math.hpp"
#include "util/session.hpp"
@ -70,6 +70,7 @@ namespace big
{
std::vector<int32_t> script_event_args;
script_event_args.reserve(scripted_game_event->m_args_size);
for (int i = 0; i < scripted_game_event->m_args_size; i++)
script_event_args.push_back(args[i]);

View File

@ -1,4 +1,4 @@
#include "hooking.hpp"
#include "hooking/hooking.hpp"
#include "pointers.hpp"
#include "services/players/player_service.hpp"

View File

@ -1,4 +1,4 @@
#include "hooking.hpp"
#include "hooking/hooking.hpp"
#include "util/notify.hpp"
#include <entities/CDynamicEntity.hpp>

View File

@ -1,4 +1,4 @@
#include "hooking.hpp"
#include "hooking/hooking.hpp"
#include "util/notify.hpp"
#include <netsync/nodes/task/ClonedTakeOffPedVariationInfo.hpp>

View File

@ -1,4 +1,4 @@
#include "hooking.hpp"
#include "hooking/hooking.hpp"
namespace big
{

View File

@ -1,4 +1,4 @@
#include "hooking.hpp"
#include "hooking/hooking.hpp"
namespace big
{

View File

@ -1,4 +1,4 @@
#include "hooking.hpp"
#include "hooking/hooking.hpp"
#include "services/player_database/player_database_service.hpp"
namespace big

View File

@ -1,4 +1,4 @@
#include "hooking.hpp"
#include "hooking/hooking.hpp"
#include "native_hooks/native_hooks.hpp"
namespace big

View File

@ -1,4 +1,4 @@
#include "hooking.hpp"
#include "hooking/hooking.hpp"
#include "native_hooks/native_hooks.hpp"
namespace big

View File

@ -1,4 +1,4 @@
#include "hooking.hpp"
#include "hooking/hooking.hpp"
#include "native_hooks/native_hooks.hpp"
#include "services/script_patcher/script_patcher_service.hpp"

View File

@ -0,0 +1,15 @@
#include "hooking/hooking.hpp"
#include "script_mgr.hpp"
namespace big
{
bool hooks::run_script_threads(uint32_t ops_to_execute)
{
if (g_running)
{
g_script_mgr.tick();
}
return g_hooking->get_original<run_script_threads>()(ops_to_execute);
}
}

View File

@ -1,5 +1,5 @@
#include "core/scr_globals.hpp"
#include "hooking.hpp"
#include "hooking/hooking.hpp"
#include "pointers.hpp"
#include "services/script_patcher/script_patcher_service.hpp"

View File

@ -1,4 +1,4 @@
#include "hooking.hpp"
#include "hooking/hooking.hpp"
#include "network/Network.hpp"
#include <stats/CPlayerCardStats.hpp>

View File

@ -1,4 +1,4 @@
#include "hooking.hpp"
#include "hooking/hooking.hpp"
#include "network/Network.hpp"
namespace big

View File

@ -1,4 +1,4 @@
#include "hooking.hpp"
#include "hooking/hooking.hpp"
#include "network/Network.hpp"
#include <stats/CStatsSerializationContext.hpp>

View File

@ -1,4 +1,4 @@
#include "hooking.hpp"
#include "hooking/hooking.hpp"
#include "util/model_info.hpp"
#include <netsync/nodes/player/CPlayerAppearanceDataNode.hpp>

View File

@ -1,4 +1,4 @@
#include "hooking.hpp"
#include "hooking/hooking.hpp"
#include "services/players/player_service.hpp"
#include "util/globals.hpp"

View File

@ -1,4 +1,4 @@
#include "hooking.hpp"
#include "hooking/hooking.hpp"
#include <netsync/nodes/player/CPlayerCreationDataNode.hpp>

View File

@ -1,4 +1,4 @@
#include "hooking.hpp"
#include "hooking/hooking.hpp"
#include "services/players/player_service.hpp"
#include "util/globals.hpp"

View File

@ -1,4 +1,4 @@
#include "hooking.hpp"
#include "hooking/hooking.hpp"
#include <netsync/nodes/player/CPlayerGamerDataNode.hpp>

View File

@ -1,5 +1,5 @@
#include "gta/net_array.hpp"
#include "hooking.hpp"
#include "hooking/hooking.hpp"
#include "script_global.hpp"
#include "script_local.hpp"
#include "services/players/player_service.hpp"

View File

@ -1,5 +1,5 @@
#include "gta/net_array.hpp"
#include "hooking.hpp"
#include "hooking/hooking.hpp"
#include "script_global.hpp"
#include "script_local.hpp"

View File

@ -1,5 +1,5 @@
#include "gta/sound.hpp"
#include "hooking.hpp"
#include "hooking/hooking.hpp"
namespace big
{

View File

@ -1,5 +1,5 @@
#include "gta/sound.hpp"
#include "hooking.hpp"
#include "hooking/hooking.hpp"
class CFoundDevice
{

View File

@ -1,68 +0,0 @@
#include "invoker.hpp"
#include "common.hpp"
#include "crossmap.hpp"
#include "pointers.hpp"
extern "C" void _call_asm(void* context, void* function, void* ret);
namespace big
{
native_call_context::native_call_context()
{
m_return_value = &m_return_stack[0];
m_args = &m_arg_stack[0];
}
void native_invoker::cache_handlers()
{
if (m_handlers_cached)
return;
for (const rage::scrNativeMapping& mapping : g_crossmap)
{
rage::scrNativeHandler handler =
g_pointers->m_gta.m_get_native_handler(g_pointers->m_gta.m_native_registration_table, mapping.second);
m_handler_cache.emplace(mapping.first, handler);
}
m_handlers_cached = true;
}
void native_invoker::begin_call()
{
m_call_context.reset();
}
void native_invoker::end_call(rage::scrNativeHash hash)
{
if (!m_handlers_cached)
cache_handlers();
if (auto it = m_handler_cache.find(hash); it != m_handler_cache.end())
{
rage::scrNativeHandler handler = it->second;
[this, hash, handler] {
__try
{
// return address checks are no longer a thing
handler(&m_call_context);
g_pointers->m_gta.m_fix_vectors(&m_call_context);
}
__except (EXCEPTION_EXECUTE_HANDLER)
{
[hash]() {
LOG(WARNING) << "Exception caught while trying to call " << HEX_TO_UPPER(hash) << " native.";
}();
}
}();
}
else
{
[hash]() {
LOG(WARNING) << "Failed to find " << HEX_TO_UPPER(hash) << " native's handler.";
}();
}
}
}

View File

@ -1,47 +0,0 @@
#pragma once
#include "common.hpp"
#include "gta/natives.hpp"
namespace big
{
class native_call_context : public rage::scrNativeCallContext
{
public:
native_call_context();
private:
uint64_t m_return_stack[10];
uint64_t m_arg_stack[100];
};
class native_invoker
{
public:
explicit native_invoker() = default;
~native_invoker() = default;
void cache_handlers();
void begin_call();
void end_call(rage::scrNativeHash hash);
template<typename T>
void push_arg(T&& value)
{
m_call_context.push_arg(std::forward<T>(value));
}
template<typename T>
T& get_return_value()
{
return *m_call_context.get_return_value<T>();
}
public:
native_call_context m_call_context;
std::unordered_map<rage::scrNativeHash, rage::scrNativeHandler> m_handler_cache;
bool m_handlers_cached = false;
};
inline native_invoker g_native_invoker;
}

7
src/invoker/crossmap.hpp Normal file

File diff suppressed because one or more lines are too long

6568
src/invoker/crossmap.txt Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,123 @@
import json
crossmap = {}
natives = {}
current_idx = 0
crossmap_hash_list = []
class Arg:
def __init__(self, name: str, type: str):
self.name = name
self.type = type#.replace("BOOL", "bool")# .replace("Any*", "void*")
def __str__(self) -> str:
return str(self.type) + " " + str(self.name)
class NativeFunc:
def __init__(self, namespace: str, name: str, hash: int, args: list[dict], return_type: str):
self.namespace = namespace
self.name = name
self.hash = hash
self.args: list[Arg] = []
self.return_type = return_type#.replace("BOOL", "bool")# .replace("Any*", "void*")
self.native_index = -1
self.fix_vectors = "false"
for arg in args:
self.args.append(Arg(arg["name"], arg["type"]))
if arg["type"] == "Vector3*":
self.fix_vectors = "true"
def get_native_def_str(self) -> str:
assert self.native_index != -1
param_decl = ""
param_pass = ""
if len(self.args) > 0:
for arg in self.args:
param_decl += str(arg) + ", "
param_pass += arg.name + ", "
param_decl = param_decl[:-2]
param_pass = param_pass[:-2]
return f"FORCEINLINE constexpr {self.return_type} {self.name}({param_decl}) {{ return big::native_invoker::invoke<{self.native_index}, {self.fix_vectors}, {self.return_type}>({param_pass}); }}"
class CrossmapEntry:
def __init__(self, translated_hash: int):
self.hash = translated_hash
self.native_index = -1
def load_crossmap_data():
global crossmap
data = open("crossmap.txt").readlines()
for item in data:
translation = item.split(",")
crossmap[int(translation[0], 16)] = CrossmapEntry(int(translation[1], 16))
def load_natives_data():
global natives
data = json.load(open("natives.json"))
for ns, natives_list in data.items():
natives[ns] = []
for hash_str, native_data in natives_list.items():
natives[ns].append(NativeFunc(ns, native_data["name"], int(hash_str, 16), native_data["params"], native_data["return_type"]))
def allocate_indices():
global current_idx, crossmap_hash_list
for _, n in natives.items():
for native in n:
hash = native.hash
if hash in crossmap:
crossmap[hash].native_index = current_idx
native.native_index = current_idx
crossmap_hash_list.append(crossmap[hash].hash)
current_idx += 1
def write_crossmap_header():
open("crossmap.hpp", "w+").write(f"""#pragma once
#include <script/scrNativeHandler.hpp>
namespace big
{{
constexpr std::array<rage::scrNativeHash, {len(crossmap_hash_list)}> g_crossmap = {{{",".join([f"0x{x:X}" for x in crossmap_hash_list])}}};
}}
""")
def write_natives_header():
natives_buf = ""
natives_index_buf = ""
for ns, nvs in natives.items():
natives_buf += f"namespace {ns}\n{{\n"
for nat_data in nvs:
if nat_data.native_index == -1:
continue
natives_buf += f"\t{nat_data.get_native_def_str()}\n"
natives_index_buf += f"\t{nat_data.name} = {nat_data.native_index},\n"
natives_buf += "}\n\n"
natives_buf = natives_buf[:-2]
open("../natives.hpp", "w+").write(f"""#pragma once
#include "invoker/invoker.hpp"
// clang-format off
enum class NativeIndex
{{
{natives_index_buf}}};
{natives_buf}
// clang-format on
""")
if __name__ == "__main__":
load_crossmap_data()
load_natives_data()
allocate_indices()
write_crossmap_header()
write_natives_header()

24
src/invoker/invoker.cpp Normal file
View File

@ -0,0 +1,24 @@
#include "invoker.hpp"
#include "crossmap.hpp"
#include "pointers.hpp"
namespace big
{
void native_invoker::cache_handlers()
{
if (m_are_handlers_cached)
return;
for (int i = 0; i < g_crossmap.size(); i++)
{
m_handlers[i] = g_pointers->m_gta.m_get_native_handler(g_pointers->m_gta.m_native_registration_table, g_crossmap[i]);
}
m_are_handlers_cached = true;
}
void native_invoker::fix_vectors()
{
g_pointers->m_gta.m_fix_vectors(&m_call_context);
}
}

Some files were not shown because too many files have changed in this diff Show More