From 1127e51a5214249ac2d6a0c04a2d261855ee636c Mon Sep 17 00:00:00 2001 From: maybegreat48 <96936658+maybegreat48@users.noreply.github.com> Date: Fri, 29 Dec 2023 16:07:00 +0000 Subject: [PATCH] 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 --- .gitignore | 1 + CMakeLists.txt | 14 +- CMakeSettings.json | 51 +- scripts/gtav-classes.cmake | 2 +- scripts/zydis.cmake | 15 - .../player/toxic/kick_from_interior.cpp | 5 - src/backend/context/chat_command_context.cpp | 2 +- src/backend/looped/self/dance_mode.cpp | 1 - src/backend/looped/weapons/rapid_fire.cpp | 2 +- src/backend/looped/weapons/weapon_hotkeys.cpp | 2 +- src/backend/reactions/interloper_reaction.cpp | 2 +- src/backend/reactions/reaction.cpp | 2 +- src/byte_patch_manager.cpp | 2 +- src/common.hpp | 3 +- src/core/data/stack_sizes.hpp | 69 +- src/crossmap.cpp | 6575 - src/crossmap.hpp | 9 - src/function_types.hpp | 8 + src/gta/fidevice.cpp | 2 +- src/gta/natives.hpp | 119 - src/gta/net_array.hpp | 1 + src/{ => hooking}/call_hook.cpp | 0 src/{ => hooking}/call_hook.hpp | 0 src/{ => hooking}/detour_hook.cpp | 1 - src/{ => hooking}/detour_hook.hpp | 0 src/{ => hooking}/hooking.cpp | 23 +- src/{ => hooking}/hooking.hpp | 20 +- src/{ => hooking}/vmt_hook.cpp | 80 +- src/{ => hooking}/vmt_hook.hpp | 77 +- src/{ => hooking}/vtable_hook.cpp | 0 src/{ => hooking}/vtable_hook.hpp | 1 - src/hooks/fuzzer/read_bits_single.cpp | 2 +- src/hooks/fuzzer/sync_data_reader.cpp | 2 +- src/hooks/gui/swap_chain_present.cpp | 2 +- src/hooks/gui/swap_chain_resizebuffers.cpp | 2 +- src/hooks/gui/wndproc.cpp | 2 +- src/hooks/info/get_network_event_data.cpp | 2 +- src/hooks/info/prepare_metric_for_sending.cpp | 3 +- src/hooks/misc/get_label_text.cpp | 26 +- src/hooks/misc/get_model_info.cpp | 76 +- src/hooks/misc/http_start_request.cpp | 2 +- src/hooks/misc/log_message_error_box.cpp | 2 +- src/hooks/misc/netfilter_handle_message.cpp | 2 +- src/hooks/misc/nt_query_virtual_memory.cpp | 20 +- .../process_matchmaking_find_response.cpp | 150 +- src/hooks/misc/queue_dependency.cpp | 2 +- src/hooks/misc/send_chat_message.cpp | 2 +- .../misc/serialize_join_request_message.cpp | 32 +- src/hooks/misc/serialize_player_data_msg.cpp | 38 +- src/hooks/misc/sort_session_details.cpp | 40 +- .../misc/start_matchmaking_find_sessions.cpp | 104 +- src/hooks/misc/task_jump_constructor.cpp | 2 +- .../misc/update_timecycle_keyframe_data.cpp | 2 +- .../assign_physical_index.cpp | 2 +- .../player_management/network_player_mgr.cpp | 2 +- .../protections/allocate_memory_reliable.cpp | 2 +- src/hooks/protections/can_apply_data.cpp | 2 +- .../protections/fragment_physics_crash.cpp | 2 +- src/hooks/protections/handle_join_request.cpp | 2 +- .../protections/increment_stat_event.cpp | 56 +- src/hooks/protections/invalid_decal.cpp | 2 +- .../protections/invalid_mods_crash_detour.cpp | 20 +- src/hooks/protections/receive_net_message.cpp | 3 +- src/hooks/protections/receive_pickup.cpp | 28 +- .../protections/received_array_update.cpp | 2 +- .../protections/received_clone_create.cpp | 2 +- src/hooks/protections/received_clone_sync.cpp | 2 +- src/hooks/protections/received_event.cpp | 2 +- src/hooks/protections/render_big_ped.cpp | 2 +- src/hooks/protections/render_entity.cpp | 2 +- src/hooks/protections/render_ped.cpp | 2 +- .../protections/script_event_handler.cpp | 3 +- .../send_non_physical_player_data.cpp | 2 +- .../protections/serialize_parachute_task.cpp | 2 +- .../serialize_take_off_ped_variation_task.cpp | 2 +- src/hooks/protections/task_ambient_clips.cpp | 2 +- .../protections/task_parachute_object.cpp | 2 +- .../protections/update_presence_attribute.cpp | 2 +- src/hooks/script/gta_thread_kill.cpp | 62 +- src/hooks/script/gta_thread_start.cpp | 40 +- src/hooks/script/init_native_tables.cpp | 2 +- src/hooks/script/run_script_threads.cpp | 15 + src/hooks/script/script_vm.cpp | 2 +- src/hooks/spoofing/send_player_card_stats.cpp | 54 +- .../send_session_matchmaking_attributes.cpp | 2 +- src/hooks/spoofing/serialize_stats.cpp | 2 +- .../write_player_appearance_data_node.cpp | 2 +- .../write_player_camera_data_node.cpp | 2 +- .../write_player_creation_data_node.cpp | 28 +- .../write_player_game_state_data_node.cpp | 2 +- .../spoofing/write_player_gamer_data_node.cpp | 2 +- src/hooks/toxic/broadcast_net_array.cpp | 2 +- ..._vehicle_proximity_migration_data_node.cpp | 2 +- .../voice/direct_sound_capture_create.cpp | 36 +- src/hooks/voice/enumerate_audio_devices.cpp | 84 +- src/invoker.cpp | 68 - src/invoker.hpp | 47 - src/invoker/crossmap.hpp | 7 + src/invoker/crossmap.txt | 6568 + src/invoker/generate_natives.py | 123 + src/invoker/invoker.cpp | 24 + src/invoker/invoker.hpp | 90 + src/invoker/natives.json | 119453 +++++++++++++++ src/logger/exception_handler.cpp | 87 +- src/lua/bindings/network.cpp | 2 +- src/lua/bindings/stats.cpp | 2 +- src/main.cpp | 2 +- src/native_hooks/all_scripts.hpp | 2 +- src/native_hooks/freemode.hpp | 4 +- src/native_hooks/native_hooks.cpp | 174 +- src/native_hooks/native_hooks.hpp | 121 +- src/native_hooks/tunables.hpp | 2 +- src/natives.hpp | 20114 ++- src/pointers.cpp | 6 +- src/sc_pointers.hpp | 1 + src/script_mgr.cpp | 1 - src/services/gta_data/yim_fipackfile.hpp | 1 + .../matchmaking/matchmaking_service.cpp | 230 +- .../player_database_service.cpp | 2 +- .../script_connection/script_connection.cpp | 1 - src/services/vehicle/persist_car_service.cpp | 2 +- .../vehicle/vehicle_control_service.cpp | 14 +- .../vehicle/vehicle_control_service.hpp | 13 +- src/util/notify.hpp | 2 +- src/util/scripts.hpp | 4 +- src/util/sync_trees.hpp | 1 + src/util/system.hpp | 4 +- src/util/vehicle.cpp | 2 +- src/views/debug/view_debug_misc.cpp | 2 +- src/views/network/view_network.cpp | 2 +- src/views/self/view_teleport.cpp | 2 +- src/views/settings/view_stat_editor.cpp | 2 +- src/views/view_vehicle_control.cpp | 10 +- 133 files changed, 140633 insertions(+), 14652 deletions(-) delete mode 100644 scripts/zydis.cmake delete mode 100644 src/crossmap.cpp delete mode 100644 src/crossmap.hpp delete mode 100644 src/gta/natives.hpp rename src/{ => hooking}/call_hook.cpp (100%) rename src/{ => hooking}/call_hook.hpp (100%) rename src/{ => hooking}/detour_hook.cpp (99%) rename src/{ => hooking}/detour_hook.hpp (100%) rename src/{ => hooking}/hooking.cpp (95%) rename src/{ => hooking}/hooking.hpp (97%) rename src/{ => hooking}/vmt_hook.cpp (94%) rename src/{ => hooking}/vmt_hook.hpp (95%) rename src/{ => hooking}/vtable_hook.cpp (100%) rename src/{ => hooking}/vtable_hook.hpp (97%) create mode 100644 src/hooks/script/run_script_threads.cpp delete mode 100644 src/invoker.cpp delete mode 100644 src/invoker.hpp create mode 100644 src/invoker/crossmap.hpp create mode 100644 src/invoker/crossmap.txt create mode 100644 src/invoker/generate_natives.py create mode 100644 src/invoker/invoker.cpp create mode 100644 src/invoker/invoker.hpp create mode 100644 src/invoker/natives.json diff --git a/.gitignore b/.gitignore index 8a829f67..de8c3647 100644 --- a/.gitignore +++ b/.gitignore @@ -13,6 +13,7 @@ __pycache__/ *.ipch *.gch *.pch +*.pyc # generated by CMAKE version.cpp \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 1edbbc5b..547bd7a7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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() diff --git a/CMakeSettings.json b/CMakeSettings.json index 68de1f1f..193e9988 100644 --- a/CMakeSettings.json +++ b/CMakeSettings.json @@ -1,26 +1,27 @@ -{ - "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", - "configurationType": "RelWithDebInfo", - "inheritEnvironments": [ "msvc_x64_x64" ], - "buildRoot": "${projectDir}\\out\\build\\${name}", - "installRoot": "${projectDir}\\out\\install\\${name}", - "cmakeCommandArgs": "", - "buildCommandArgs": "", - "ctestCommandArgs": "" - } - ] +{ + "configurations": [ + { + "name": "x64-Release", + "generator": "Ninja", + "configurationType": "RelWithDebInfo", + "inheritEnvironments": [ "msvc_x64_x64" ], + "buildRoot": "${projectDir}\\out\\build\\${name}", + "installRoot": "${projectDir}\\out\\install\\${name}", + "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": [] + } + ] } \ No newline at end of file diff --git a/scripts/gtav-classes.cmake b/scripts/gtav-classes.cmake index ab9a7def..e3fa9f1d 100644 --- a/scripts/gtav-classes.cmake +++ b/scripts/gtav-classes.cmake @@ -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 "" diff --git a/scripts/zydis.cmake b/scripts/zydis.cmake deleted file mode 100644 index 01150635..00000000 --- a/scripts/zydis.cmake +++ /dev/null @@ -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) diff --git a/src/backend/commands/player/toxic/kick_from_interior.cpp b/src/backend/commands/player/toxic/kick_from_interior.cpp index 0250b51e..5a18af47 100644 --- a/src/backend/commands/player/toxic/kick_from_interior.cpp +++ b/src/backend/commands/player/toxic/kick_from_interior.cpp @@ -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