This repository has been archived on 2024-10-22. You can view files and clone it, but cannot push or open issues or pull requests.
YimMenu/BigBaseV2/src/main.cpp

177 lines
6.0 KiB
C++
Raw Normal View History

2019-03-21 20:18:31 +01:00
#include "common.hpp"
#include "core/globals.hpp"
2019-03-21 20:18:31 +01:00
#include "features.hpp"
#include "fiber_pool.hpp"
#include "gui.hpp"
#include "logger.hpp"
#include "hooking.hpp"
#include "pointers.hpp"
#include "renderer.hpp"
#include "script_mgr.hpp"
#include "thread_pool.hpp"
2019-03-21 20:18:31 +01:00
#include "native_hooks/native_hooks.hpp"
#include "services/context_menu_service.hpp"
#include "services/globals_service.hpp"
#include "services/gui_service.hpp"
#include "services/player_service.hpp"
#include "services/mobile_service.hpp"
#include "services/notification_service.hpp"
#include "services/vehicle_preview_service.hpp"
#include "services/vehicle_service.hpp"
2022-05-22 16:43:09 +02:00
#include "backend/backend.hpp"
2019-03-21 20:18:31 +01:00
BOOL APIENTRY DllMain(HMODULE hmod, DWORD reason, PVOID)
{
using namespace big;
if (reason == DLL_PROCESS_ATTACH)
{
DisableThreadLibraryCalls(hmod);
g_hmodule = hmod;
g_main_thread = CreateThread(nullptr, 0, [](PVOID) -> DWORD
{
while (!FindWindow(L"grcWindow", L"Grand Theft Auto V"))
std::this_thread::sleep_for(1s);
std::filesystem::path base_dir = std::getenv("appdata");
base_dir /= "BigBaseV2";
auto file_manager_instance = std::make_unique<file_manager>(base_dir);
auto globals_instance = std::make_unique<menu_settings>(
file_manager_instance->get_project_file("./settings.json")
);
auto logger_instance = std::make_unique<logger>(
"YimMenu",
file_manager_instance->get_project_file("./cout.log")
);
EnableMenuItem(GetSystemMenu(FindWindowA(NULL, "YimMenu"), 0), SC_CLOSE, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2019-03-21 20:18:31 +01:00
try
{
LOG(INFO) << "Yim's Menu Initializing";
2019-03-21 20:18:31 +01:00
auto pointers_instance = std::make_unique<pointers>();
LOG(INFO) << "Pointers initialized.";
2019-03-21 20:18:31 +01:00
auto renderer_instance = std::make_unique<renderer>();
LOG(INFO) << "Renderer initialized.";
2019-03-21 20:18:31 +01:00
auto fiber_pool_instance = std::make_unique<fiber_pool>(11);
LOG(INFO) << "Fiber pool initialized.";
2019-03-21 20:18:31 +01:00
auto hooking_instance = std::make_unique<hooking>();
LOG(INFO) << "Hooking initialized.";
g->load();
LOG(INFO) << "Settings Loaded.";
2019-03-21 20:18:31 +01:00
auto thread_pool_instance = std::make_unique<thread_pool>();
LOG(INFO) << "Thread pool initialized.";
auto context_menu_service_instance = std::make_unique<context_menu_service>();
auto globals_service_instace = std::make_unique<globals_service>();
auto mobile_service_instance = std::make_unique<mobile_service>();
auto notification_service_instance = std::make_unique<notification_service>();
auto player_service_instance = std::make_unique<player_service>();
auto vehicle_preview_service_instance = std::make_unique<vehicle_preview_service>();
2021-08-08 15:10:08 +02:00
auto vehicle_service_instance = std::make_unique<vehicle_service>();
auto gui_service_instance = std::make_unique<gui_service>();
LOG(INFO) << "Registered service instances...";
g_script_mgr.add_script(std::make_unique<script>(&features::script_func));
g_script_mgr.add_script(std::make_unique<script>(&gui::script_func));
2022-05-22 16:43:09 +02:00
g_script_mgr.add_script(std::make_unique<script>(&backend::self_loop));
g_script_mgr.add_script(std::make_unique<script>(&backend::weapons_loop));
g_script_mgr.add_script(std::make_unique<script>(&backend::vehicles_loop));
g_script_mgr.add_script(std::make_unique<script>(&backend::misc_loop));
g_script_mgr.add_script(std::make_unique<script>(&backend::remote_loop));
g_script_mgr.add_script(std::make_unique<script>(&backend::noclip_loop));
g_script_mgr.add_script(std::make_unique<script>(&backend::lscustoms_loop));
g_script_mgr.add_script(std::make_unique<script>(&backend::vehiclefly_loop));
g_script_mgr.add_script(std::make_unique<script>(&backend::rgbrandomizer_loop));
g_script_mgr.add_script(std::make_unique<script>(&backend::turnsignal_loop));
g_script_mgr.add_script(std::make_unique<script>(&backend::disable_control_action_loop));
2022-05-22 18:10:51 +02:00
g_script_mgr.add_script(std::make_unique<script>(&context_menu_service::context_menu));
LOG(INFO) << "Scripts registered.";
auto native_hooks_instance = std::make_unique<native_hooks>();
LOG(INFO) << "Dynamic native hooker initialized.";
2021-08-08 15:10:08 +02:00
g_hooking->enable();
LOG(INFO) << "Hooking enabled.";
g_running = true;
2019-03-21 20:18:31 +01:00
while (g_running)
std::this_thread::sleep_for(500ms);
2019-03-21 20:18:31 +01:00
g_hooking->disable();
LOG(INFO) << "Hooking disabled.";
native_hooks_instance.reset();
LOG(INFO) << "Dynamic native hooker uninitialized.";
g_script_mgr.remove_all_scripts();
LOG(INFO) << "Scripts unregistered.";
gui_service_instance.reset();
LOG(INFO) << "Gui Service reset.";
vehicle_service_instance.reset();
LOG(INFO) << "Vehicle Service reset.";
vehicle_preview_service_instance.reset();
LOG(INFO) << "Vehicle Preview Service reset.";
mobile_service_instance.reset();
LOG(INFO) << "Mobile Service reset.";
player_service_instance.reset();
LOG(INFO) << "Player Service reset.";
globals_service_instace.reset();
LOG(INFO) << "Globals Service reset.";
context_menu_service_instance.reset();
LOG(INFO) << "Context Service reset.";
LOG(INFO) << "Services uninitialized.";
// Make sure that all threads created don't have any blocking loops
// otherwise make sure that they have stopped executing
thread_pool_instance->destroy();
LOG(INFO) << "Destroyed thread pool.";
thread_pool_instance.reset();
LOG(INFO) << "Thread pool uninitialized.";
2019-03-21 20:18:31 +01:00
hooking_instance.reset();
LOG(INFO) << "Hooking uninitialized.";
2019-03-21 20:18:31 +01:00
fiber_pool_instance.reset();
LOG(INFO) << "Fiber pool uninitialized.";
2019-03-21 20:18:31 +01:00
renderer_instance.reset();
LOG(INFO) << "Renderer uninitialized.";
2019-03-21 20:18:31 +01:00
pointers_instance.reset();
LOG(INFO) << "Pointers uninitialized.";
2019-03-21 20:18:31 +01:00
}
catch (std::exception const &ex)
{
LOG(WARNING) << ex.what();
2019-03-21 20:18:31 +01:00
}
LOG(INFO) << "Farewell!";
logger_instance->destroy();
2019-03-21 20:18:31 +01:00
logger_instance.reset();
globals_instance.reset();
file_manager_instance.reset();
2019-03-21 20:18:31 +01:00
CloseHandle(g_main_thread);
FreeLibraryAndExitThread(g_hmodule, 0);
}, nullptr, 0, &g_main_thread_id);
}
return true;
}