General code and GUI cleanup (#1200)

* feat(native_hooks): removed useless bail kick hook
* feat(Translations): add button to force update languages
* refactor: reorganize GUI for world
* refactor: improve exception handler
Modified the exception handler to not catch C++ try/catch blocks before those could gracefully catch the error.

* chore: debug removed crash test button
* chore: removed script exception handler
* feat(OrbitalDrone): add translations
* feat(VehicleController): add translation keys
* feat: added player admin detected translation keys
* feat(Views): add cache sub menu
This commit is contained in:
Andreas Maerten 2023-04-07 23:08:34 +02:00 committed by GitHub
parent 60d8269d3b
commit 6df7be6f06
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
23 changed files with 1076 additions and 1079 deletions

View File

@ -5,8 +5,6 @@
namespace big
{
HRESULT hooks::swapchain_present(IDXGISwapChain* this_, UINT sync_interval, UINT flags)
{
TRY_CLAUSE
{
if (g_running)
{
@ -15,8 +13,4 @@ namespace big
return g_hooking->m_swapchain_hook.get_original<decltype(&swapchain_present)>(swapchain_present_index)(this_, sync_interval, flags);
}
EXCEPT_CLAUSE
return NULL;
}
}

View File

@ -5,8 +5,6 @@
namespace big
{
HRESULT hooks::swapchain_resizebuffers(IDXGISwapChain* this_, UINT buffer_count, UINT width, UINT height, DXGI_FORMAT new_format, UINT swapchain_flags)
{
TRY_CLAUSE
{
if (g_running)
{
@ -24,8 +22,4 @@ namespace big
return g_hooking->m_swapchain_hook.get_original<decltype(&swapchain_resizebuffers)>(swapchain_resizebuffers_index)(this_, buffer_count, width, height, new_format, swapchain_flags);
}
EXCEPT_CLAUSE
return NULL;
}
}

View File

@ -5,8 +5,6 @@
namespace big
{
LRESULT hooks::wndproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
{
TRY_CLAUSE
{
if (g_running)
{
@ -15,8 +13,4 @@ namespace big
return CallWindowProcW(g_hooking->m_og_wndproc, hwnd, msg, wparam, lparam);
}
EXCEPT_CLAUSE
return NULL;
}
}

View File

@ -51,8 +51,8 @@ namespace big
auto found = std::find(admin_rids.begin(), admin_rids.end(), net_player_data->m_gamer_handle.m_rockstar_id);
if (found != admin_rids.end())
{
g_notification_service->push_warning("Potential Admin Found!",
std::format("{} has been detected as admin", net_player_data->m_name));
g_notification_service->push_warning("POTENTIAL_ADMIN_FOUND"_T.data(),
std::vformat("PLAYER_DETECTED_AS_ADMIN"_T, std::make_format_args(net_player_data->m_name)));
LOG(WARNING) << net_player_data->m_name << " (" << net_player_data->m_gamer_handle.m_rockstar_id << ") has been detected as admin";
auto id = player->m_player_id;
if (auto plyr = g_player_service->get_by_id(id))

View File

@ -8,12 +8,14 @@ namespace big
{
exception_handler::exception_handler()
{
m_exception_handler = AddVectoredExceptionHandler(1, &vectored_exception_handler);
SetErrorMode(0);
SetUnhandledExceptionFilter(&vectored_exception_handler);
}
exception_handler::~exception_handler()
{
RemoveVectoredExceptionHandler(m_exception_handler);
// passing NULL / 0 will make it go back to normal exception handling
SetUnhandledExceptionFilter(0);
}
inline static stack_trace trace;

View File

@ -18,11 +18,6 @@ namespace big
src->set_return_value(STATS::STAT_GET_INT(src->get_arg<Hash>(0), src->get_arg<int*>(1), src->get_arg<int>(2)));
}
inline void NETWORK_BAIL(rage::scrNativeCallContext* src)
{
LOG(INFO) << "NETWORK_BAIL prevented";
}
inline void IS_PLAYER_PLAYING(rage::scrNativeCallContext* src)
{
// block undead OTR

View File

@ -121,7 +121,6 @@ namespace big
add_native_detour(RAGE_JOAAT("carmod_shop"), 0x5F4B6931816E599B, carmod_shop::DISABLE_ALL_CONTROL_ACTIONS);
add_native_detour(RAGE_JOAAT("freemode"), 0x767FBC2AC802EF3D, freemode::STAT_GET_INT);
add_native_detour(RAGE_JOAAT("freemode"), 0x95914459A87EBA28, freemode::NETWORK_BAIL);
add_native_detour(RAGE_JOAAT("freemode"), 0x5E9564D8246B909A, freemode::IS_PLAYER_PLAYING);
add_native_detour(RAGE_JOAAT("freemode"), 0xEA1C610A04DB6BBB, freemode::SET_ENTITY_VISIBLE);
add_native_detour(RAGE_JOAAT("freemode"), 0x231C8F89D0539D8F, freemode::SET_BIGMAP_ACTIVE);

View File

@ -5,19 +5,6 @@
namespace big
{
void script::script_exception_handler(PEXCEPTION_POINTERS exp)
{
HMODULE mod{};
DWORD64 offset{};
char buffer[MAX_PATH]{};
if (GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS, (LPCSTR)exp->ExceptionRecord->ExceptionAddress, &mod) == TRUE && mod != nullptr)
{
offset = ((DWORD64)exp->ExceptionRecord->ExceptionAddress - (DWORD64)mod);
GetModuleFileNameA(mod, buffer, MAX_PATH - 1);
}
LOG(FATAL) << "Exception Code: " << HEX_TO_UPPER(exp->ExceptionRecord->ExceptionCode) << " Exception Offset: " << HEX_TO_UPPER(offset) << " Fault Module Name: " << buffer;
}
script::script(const func_t func, const std::string_view name, const bool toggleable, const std::optional<std::size_t> stack_size) :
script(func, stack_size)
{
@ -102,15 +89,8 @@ namespace big
}
void script::fiber_func()
{
TRY_CLAUSE
{
m_func();
}
EXCEPT_CLAUSE
[]() {
LOG(INFO) << "Script finished!";
}();
while (true)
{

View File

@ -27,7 +27,6 @@ namespace big
void tick();
void yield(std::optional<std::chrono::high_resolution_clock::duration> time = std::nullopt);
static script* get_current();
static void script_exception_handler(PEXCEPTION_POINTERS exp);
private:
void fiber_func();
@ -38,17 +37,4 @@ namespace big
func_t m_func;
std::optional<std::chrono::high_resolution_clock::time_point> m_wake_time;
};
#define TRY_CLAUSE __try
#define EXCEPT_CLAUSE \
__except (script::script_exception_handler(GetExceptionInformation()), EXCEPTION_EXECUTE_HANDLER) \
{ \
}
#define QUEUE_JOB_BEGIN_CLAUSE(...) g_fiber_pool->queue_job([__VA_ARGS__] { __try
#define QUEUE_JOB_END_CLAUSE \
__except (script::script_exception_handler(GetExceptionInformation()), EXCEPTION_EXECUTE_HANDLER) \
{ \
} \
});
}

View File

@ -11,6 +11,8 @@ namespace big
WEAPONS,
TELEPORT,
MOBILE,
OUTFIT_EDITOR,
OUTFIT_SLOTS,
VEHICLE,
HANDLING,
@ -26,10 +28,8 @@ namespace big
WORLD,
SPAWN_PED,
TIME_AND_WEATHER,
CREATOR,
TRAIN,
WATER,
BLACKHOLE,
MODEL_SWAPPER,
NEARBY,
@ -41,13 +41,12 @@ namespace big
SPOOFING,
PLAYER_DATABASE,
SESSION_BROWSER,
STAT_EDITOR,
SETTINGS,
OUTFIT_EDITOR,
OUTFIT_SLOTS,
STAT_EDITOR,
CONTEXT_MENU_SETTINGS,
ESP_SETTINGS,
GTA_CACHE_SETTINGS,
GUI_SETTINGS,
HOTKEY_SETTINGS,
REACTION_SETTINGS,
@ -80,6 +79,8 @@ namespace big
{tabs::WEAPONS, {"GUI_TAB_WEAPONS", view::weapons}},
{tabs::MOBILE, {"GUI_TAB_MOBILE", view::mobile}},
{tabs::TELEPORT, {"GUI_TAB_TELEPORT", view::teleport}},
{tabs::OUTFIT_EDITOR, {"GUI_TAB_OUTFIT_EDITOR", view::outfit_editor}},
{tabs::OUTFIT_SLOTS, {"GUI_TAB_OUTFIT_SLOTS", view::outfit_slots}},
},
},
},
@ -112,17 +113,15 @@ namespace big
tabs::WORLD,
{
"GUI_TAB_WORLD",
nullptr,
view::world,
{
{tabs::SPAWN_PED, {"GUI_TAB_SPAWN_PED", view::spawn_ped}},
{tabs::TIME_AND_WEATHER, {"GUI_TAB_TIME_N_WEATHER", view::time_and_weather}},
{tabs::CREATOR, {"GUI_TAB_CREATOR", view::creator}},
{tabs::TRAIN, {"GUI_TAB_TRAIN", view::train}},
{tabs::WATER, {"GUI_TAB_WATER", view::water}},
{tabs::BLACKHOLE, {"GUI_TAB_BLACKHOLE", view::blackhole}},
{tabs::MODEL_SWAPPER, {"GUI_TAB_MODEL_SWAPPER", view::model_swapper}},
{tabs::NEARBY, {"GUI_TAB_NEARBY", view::nearby}},
{tabs::ORBITAL_DRONE, {"Orbital Drone", view::orbital_drone}},
{tabs::ORBITAL_DRONE, {"GUI_TAB_ORBITAL_DRONE", view::orbital_drone}},
},
},
},
@ -137,6 +136,7 @@ namespace big
{tabs::MISSIONS, {"GUI_TAB_MISSIONS", view::missions}},
{tabs::PLAYER_DATABASE, {"GUI_TAB_PLAYER_DB", view::player_database}},
{tabs::SESSION_BROWSER, {"GUI_TAB_SESSION_BROWSER", view::session_browser}},
{tabs::STAT_EDITOR, {"GUI_TAB_STAT_EDITOR", view::stat_editor}},
},
},
},
@ -146,11 +146,9 @@ namespace big
"GUI_TAB_SETTINGS",
view::settings,
{
{tabs::OUTFIT_EDITOR, {"GUI_TAB_OUTFIT_EDITOR", view::outfit_editor}},
{tabs::OUTFIT_SLOTS, {"GUI_TAB_OUTFIT_SLOTS", view::outfit_slots}},
{tabs::STAT_EDITOR, {"GUI_TAB_STAT_EDITOR", view::stat_editor}},
{tabs::CONTEXT_MENU_SETTINGS, {"GUI_TAB_CONTEXT_MENU", view::context_menu_settings}},
{tabs::ESP_SETTINGS, {"GUI_TAB_ESP", view::esp_settings}},
{tabs::GTA_CACHE_SETTINGS, {"GTA Cache", view::gta_cache}},
{tabs::GUI_SETTINGS, {"GUI_TAB_GUI", view::gui_settings}},
{tabs::HOTKEY_SETTINGS, {"GUI_TAB_HOTKEYS", view::hotkey_settings}},
{tabs::REACTION_SETTINGS, {"GUI_TAB_REACTIONS", view::reaction_settings}},

View File

@ -90,6 +90,22 @@ namespace big
});
}
void translation_service::update_language_packs()
{
for (auto item : std::filesystem::directory_iterator(m_translation_directory->get_path()))
{
const auto path = item.path();
const auto stem = path.stem().string();
if (stem == "index" || item.path().extension() != ".json")
continue;
if (!download_language_pack(stem))
{
LOG(WARNING) << "Failed to update '" << stem << "' language pack";
}
}
}
void translation_service::load_translations()
{
m_translations.clear();
@ -152,22 +168,6 @@ namespace big
return false;
}
void translation_service::update_language_packs()
{
for (auto item : std::filesystem::directory_iterator(m_translation_directory->get_path()))
{
const auto path = item.path();
const auto stem = path.stem().string();
if (stem == "index" || item.path().extension() != ".json")
continue;
if (!download_language_pack(stem))
{
LOG(WARNING) << "Failed to update '" << stem << "' language pack";
}
}
}
bool translation_service::download_index()
{
cpr::Response response = cpr::Get(cpr::Url{m_url + "/index.json"});

View File

@ -26,13 +26,13 @@ namespace big
std::map<std::string, translation_entry>& available_translations();
const std::string& current_language_pack();
void select_language_pack(const std::string& pack_id);
void update_language_packs();
private:
void load_translations();
nlohmann::json load_translation(const std::string_view pack_id);
bool download_language_pack(const std::string_view pack_id);
void update_language_packs();
/**
* @brief Downloads the remote index to compare with our local index

View File

@ -187,7 +187,7 @@ namespace big
4.f,
5.f);
//LOG(INFO) << "Navmesh probably failed, issiuing regular task ";
g_notification_service->push_warning("Vehicle controller", "Your vehicle could not assess an accurate path, it will try something else");
g_notification_service->push_warning("VEHICLE_CONTROLLER"_T.data(), "VEHICLE_CONTROLLER_TRY_ALT_PATHFINDING"_T.data());
script::get_current()->yield(500ms);
}
@ -331,12 +331,12 @@ namespace big
if (vehicle_control::find_suitable_destination_near_player(destination, heading))
{
//LOG(INFO) << "Suitable destination found";
g_notification_service->push_warning("Vehicle controller", "Found a nice spot, your vehicle is on its way");
g_notification_service->push_warning("VEHICLE_CONTROLLER"_T.data(), "VEHICLE_CONTROLLER_FOUND_LOCATION"_T.data());
}
else
{
//LOG(INFO) << "Couldn't find suitable destionation, defaulting to offset of player\nThis might go wrong";
g_notification_service->push_warning("Vehicle controller", "Couldn't locate an accurate spot, your vehicle is on its way regardless");
g_notification_service->push_warning("VEHICLE_CONTROLLER"_T.data(), "VEHICLE_CONTROLLER_FORCE_PATHFINDING"_T.data());
destination = behind_pos;
}
@ -359,7 +359,7 @@ namespace big
else
{
//LOG(INFO) << "Navmesh load failed";
g_notification_service->push_error("Nav mesh", "Failed loading the navmesh");
g_notification_service->push_error("VEHICLE_CONTROLLER"_T.data(), "VEHICLE_CONTROLLER_NAVMESH_FAILURE"_T.data());
m_driver_performing_task = false;
}
}

View File

@ -0,0 +1,33 @@
#include "natives.hpp"
#include "pointers.hpp"
#include "script.hpp"
#include "services/gta_data/gta_data_service.hpp"
#include "thread_pool.hpp"
#include "views/view.hpp"
namespace big
{
void view::gta_cache()
{
auto ped_count = g_gta_data_service->peds().size();
auto veh_count = g_gta_data_service->vehicles().size();
auto wep_count = g_gta_data_service->weapons().size();
components::sub_title("GTA cache stats:");
ImGui::Text("Peds Cached: %d\nVehicles Cached: %d\nWeapons Cached: %d", ped_count, veh_count, wep_count);
if (components::button("Rebuild Cache in Online"))
{
g_gta_data_service->set_state(eGtaDataUpdateState::NEEDS_UPDATE);
if (!*g_pointers->m_is_session_started)
{
g_gta_data_service->update_in_online();
}
else
{
g_gta_data_service->update_now();
}
}
}
}

View File

@ -1,5 +1,7 @@
#include "thread_pool.hpp"
#include "views/view.hpp"
namespace big
{
void view::translation_settings()
@ -22,5 +24,15 @@ namespace big
}
ImGui::EndCombo();
}
if (components::button("Force Update Languages"))
{
g_thread_pool->push([]
{
g_translation_service.update_language_packs();
g_notification_service->push("Translations", "Finished updating translations.");
});
}
}
}

View File

@ -57,10 +57,11 @@ namespace big
static void gta_data();
static void creator();
static void train();
static void water();
static void blackhole();
static void model_swapper();
static void nearby();
static void world();
static void gta_cache();
static void player_info();
static void player_troll();

View File

@ -37,7 +37,7 @@ namespace big
ImGui::BeginGroup();
ImGui::SetNextItemWidth(200);
if (ImGui::BeginCombo("##alldoorslock", "All doors"))
if (ImGui::BeginCombo("##alldoorslock", "VEHICLE_CONTROLLER_ALL_DOORS"_T.data()))
{
for (int lockindex = 0; lockindex < MAX_VEHICLE_LOCK_STATES; lockindex++)
{
@ -52,7 +52,7 @@ namespace big
}
ImGui::SameLine();
if (ImGui::Button("Open all"))
if (components::button("OPEN_ALL_DOORS"_T))
{
g_fiber_pool->queue_job([=] {
g_vehicle_control_service.operate_door(eDoorId::VEH_EXT_DOOR_INVALID_ID, true);
@ -60,7 +60,7 @@ namespace big
}
ImGui::SameLine();
if (ImGui::Button("Close all"))
if (components::button("CLOSE_ALL_DOORS"_T))
{
g_fiber_pool->queue_job([=] {
g_vehicle_control_service.operate_door(eDoorId::VEH_EXT_DOOR_INVALID_ID, false);
@ -75,6 +75,7 @@ namespace big
for (int i = 0; i < MAX_VEHICLE_DOORS; i++)
{
ImGui::PushID(i);
if (!g_vehicle_control_service.m_controlled_vehicle.doors[i].valid)
continue;
ImGui::SetNextItemWidth(200);
@ -94,15 +95,15 @@ namespace big
ImGui::SameLine(300);
std::string buttonlabel = g_vehicle_control_service.m_controlled_vehicle.doors[i].open ? "Close" : "Open";
buttonlabel.append("##").append(std::to_string(i));
if (ImGui::Button(buttonlabel.data()))
const auto button_label = g_vehicle_control_service.m_controlled_vehicle.doors[i].open ? "CLOSE"_T : "OPEN"_T;
if (components::button(button_label))
{
g_fiber_pool->queue_job([=] {
g_vehicle_control_service.operate_door((eDoorId)i,
!g_vehicle_control_service.m_controlled_vehicle.doors[i].open);
});
}
ImGui::PopID();
}
@ -118,21 +119,21 @@ namespace big
"Rear",
};
if (ImGui::Button("Toggle lights"))
if (components::button("VEHICLE_CONTROLLER_TOGGLE_LIGHTS"_T))
{
g_fiber_pool->queue_job([=] {
g_vehicle_control_service.operate_lights(!g_vehicle_control_service.m_controlled_vehicle.headlights, false);
});
}
ImGui::SameLine();
if (ImGui::Button("Toggle High beams"))
if (components::button("VEHICLE_CONTROLLER_TOGGLE_HIGH_BEAMS"_T))
{
g_fiber_pool->queue_job([=] {
g_vehicle_control_service.operate_lights(g_vehicle_control_service.m_controlled_vehicle.headlights,
!g_vehicle_control_service.m_controlled_vehicle.highbeams);
});
}
if (ImGui::Button("Interior lights on"))
if (components::button("VEHICLE_CONTROLLER_INTERIOR_LIGHTS_ON"_T))
{
g_fiber_pool->queue_job([=] {
if (g.window.vehicle_control.operation_animation)
@ -141,7 +142,7 @@ namespace big
});
}
ImGui::SameLine();
if (ImGui::Button("Interior lights off"))
if (components::button("VEHICLE_CONTROLLER_INTERIOR_LIGHTS_OFF"_T))
{
g_fiber_pool->queue_job([=] {
if (g.window.vehicle_control.operation_animation)
@ -150,7 +151,7 @@ namespace big
});
}
ImGui::Text("Neon lights");
ImGui::Text("VEHICLE_CONTROLLER_NEON_LIGHTS"_T.data());
ImGui::Separator();
for (int i = 0; i < 4; i++)
@ -180,18 +181,18 @@ namespace big
static int movespeed = 1;
if (ImGui::RadioButton("Walk", movespeed == 1))
if (ImGui::RadioButton("VEHICLE_CONTROLLER_ENTER_VEHICLE_SPEED_WALKING"_T.data(), movespeed == 1))
movespeed = 1;
ImGui::SameLine();
if (ImGui::RadioButton("Run", movespeed == 2))
if (ImGui::RadioButton("VEHICLE_CONTROLLER_ENTER_VEHICLE_SPEED_RUNNING"_T.data(), movespeed == 2))
movespeed = 2;
ImGui::SameLine();
if (ImGui::RadioButton("Sprint", movespeed == 3))
if (ImGui::RadioButton("VEHICLE_CONTROLLER_ENTER_VEHICLE_SPEED_SPRINTING"_T.data(), movespeed == 3))
movespeed = 3;
for (int i = 0; i < 6; i++)
{
if (ImGui::Button(seatnames[i]))
if (components::button(seatnames[i]))
{
g_fiber_pool->queue_job([=] {
if (g.window.vehicle_control.operation_animation)
@ -214,7 +215,7 @@ namespace big
if (g_vehicle_control_service.m_controlled_vehicle.isconvertible)
{
if (ImGui::Button(g_vehicle_control_service.m_controlled_vehicle.convertibelstate ? "Raise" : "Lower"))
if (components::button(g_vehicle_control_service.m_controlled_vehicle.convertibelstate ? "Raise" : "Lower"))
{
g_fiber_pool->queue_job([=] {
if (g.window.vehicle_control.operation_animation)

View File

@ -10,22 +10,21 @@ namespace big
{
ImGui::Separator();
ImGui::BeginGroup();
ImGui::Text("press 'Look behind' (C/R3 by default) to activate\npress WASD buttons or Left thumbstick to navigate\nUse scroll wheel/Mouse or Right thumbstick to zoom\npress E/Q or L1/R1 to modify speed\npress 'Jump' (Space/X/Square by default) to lock on an entity\npress 'Fire' (Mouse button 1/Right trigger by default) to Obliterate\npress Enter or A/X by default to teleport to target");
ImGui::Text("ORBITAL_DRONE_USAGE_DESCR"_T.data());
ImGui::EndGroup();
ImGui::Separator();
ImGui::BeginGroup();
ImGui::Checkbox("Detect player on lock", &g.world.orbital_drone.detect_player);
ImGui::Checkbox("ORBITAL_DRONE_AUTO_LOCK_ON_PLAYER"_T.data(), &g.world.orbital_drone.detect_player);
if (ImGui::IsItemHovered())
{
ImGui::BeginTooltip();
ImGui::Text("if enabled, changes the selected player to the one it detects upon locking on an entity");
ImGui::Text("All explosions will be blamed on the selected player, defaulting to the local player");
ImGui::TextWrapped("ORBITAL_DRONE_AUTO_LOCK_ON_PLAYER_TOOLTIP"_T.data());
ImGui::EndTooltip();
}
ImGui::Text("Adjust fast modifier");
ImGui::Text("ORBITAL_DRONE_HIGH_SPEED_MULTIPLIER"_T.data());
ImGui::SliderFloat("##fastspeed", &g.world.orbital_drone.nav_ovverride_fast, 1.f, 10.f);
ImGui::Text("Adjust slow modifier");
ImGui::Text("ORBITAL_DRONE_LOW_SPEED_MULTIPLIER"_T.data());
ImGui::SliderFloat("##slowspeed", &g.world.orbital_drone.nav_ovverride_slow, 0.f, 1.f);
ImGui::EndGroup();
}

View File

@ -1,10 +0,0 @@
#include "fiber_pool.hpp"
#include "views/view.hpp"
namespace big
{
void view::water()
{
components::command_checkbox<"partwater">();
}
}

View File

@ -0,0 +1,19 @@
#include "views/view.hpp"
namespace big
{
void view::world()
{
components::sub_title("GUI_TAB_TIME_N_WEATHER"_T);
{
view::time_and_weather();
}
ImGui::Separator();
components::sub_title("GUI_TAB_WATER"_T);
{
components::command_checkbox<"partwater">();
}
}
}