CheatMenuSA/src/dllmain.cpp

127 lines
4.1 KiB
C++
Raw Normal View History

2021-10-24 18:08:00 -04:00
#include "pch.h"
2021-10-25 10:03:27 -04:00
#include "cheatmenu.h"
2021-10-24 18:08:00 -04:00
#include "updater.h"
2022-03-09 17:23:08 -05:00
#include "rpc.h"
2021-09-20 08:41:40 -04:00
2021-10-25 10:03:27 -04:00
void MenuThread(void* param)
2021-09-20 08:41:40 -04:00
{
2022-02-20 12:00:35 -05:00
/*
Wait for game init
// Sleep(3000);
Doing it like this doesn't prevent from attaching a debugger
*/
static bool gameStarted = false;
Events::processScriptsEvent +=[]
{
2022-02-20 12:00:35 -05:00
gameStarted = true;
};
2022-02-20 12:00:35 -05:00
while (!gameStarted)
{
Sleep(500);
}
2022-01-07 03:18:00 -05:00
/*
Had to put this in place since some people put the folder in root
directory and the asi in modloader. Why??
*/
2022-06-16 14:44:33 -04:00
if (!std::filesystem::is_directory(PLUGIN_PATH((char*)FILE_NAME)))
2022-01-07 03:18:00 -05:00
{
2022-06-16 14:44:33 -04:00
std::string msg = std::format("{} folder not found. You need to put both '{}.asi' & '{}' folder in the same directory", FILE_NAME, FILE_NAME, FILE_NAME);
Log::Print<eLogLevel::Error>(msg.c_str());
MessageBox(NULL, msg.c_str(), FILE_NAME, MB_ICONERROR);
2022-01-07 03:18:00 -05:00
return;
}
2021-09-20 08:41:40 -04:00
2022-01-07 03:18:00 -05:00
/*
Need SilentPatch since all gta games have issues with mouse input
Implementing mouse fix is a headache anyway
*/
if (!GetModuleHandle(BY_GAME("SilentPatchSA.asi","SilentPatchVC.asi","SilentPatchIII.asi")))
{
2022-06-15 06:45:43 -04:00
Log::Print<eLogLevel::Error>("SilentPatch not found. Please install it from here https://gtaforums.com/topic/669045-silentpatch/");
2022-06-16 14:44:33 -04:00
int msgID = MessageBox(NULL, "SilentPatch not found. Do you want to install Silent Patch? (Game restart required)", FILE_NAME, MB_OKCANCEL | MB_DEFBUTTON1);
2021-09-20 08:41:40 -04:00
2022-01-07 03:18:00 -05:00
if (msgID == IDOK)
{
ShellExecute(nullptr, "open", "https://gtaforums.com/topic/669045-silentpatch/", nullptr, nullptr, SW_SHOWNORMAL);
};
return;
}
2021-09-20 08:41:40 -04:00
/*
TODO: Find a better way
Since you could still name it something else
*/
#ifdef GTASA
2022-01-07 03:18:00 -05:00
if (GetModuleHandle("SAMP.dll") || GetModuleHandle("SAMP.asi"))
{
2022-06-16 14:44:33 -04:00
Log::Print<eLogLevel::Error>(FILE_NAME " doesn't support SAMP");
MessageBox(NULL, "SAMP detected. Exiting " FILE_NAME, FILE_NAME, MB_ICONERROR);
2022-01-07 03:18:00 -05:00
return;
}
CFastman92limitAdjuster::Init();
#elif GTAVC
if (GetModuleHandle("vcmp-proxy.dll") || GetModuleHandle("vcmp-proxy.asi"))
{
2022-06-16 14:44:33 -04:00
Log::Print<eLogLevel::Error>(FILE_NAME " doesn't support VCMP");
MessageBox(NULL, "VCMP detected. Exiting " FILE_NAME, FILE_NAME, MB_ICONERROR);
return;
}
2021-10-21 18:23:02 -04:00
#endif
2021-09-20 08:41:40 -04:00
Log::Print<eLogLevel::None>("Starting " MENU_TITLE " (" BUILD_NUMBER ")\nAuthor: Grinch_\nDiscord: "
DISCORD_INVITE "\nMore Info: " GITHUB_LINK);
// date time
SYSTEMTIME st;
GetSystemTime(&st);
Log::Print<eLogLevel::None>("Date: {}-{}-{} Time: {}:{}\n", st.wYear, st.wMonth, st.wDay,
st.wHour, st.wMinute);
CheatMenu::Init();
2021-09-20 08:41:40 -04:00
2022-01-07 03:18:00 -05:00
// Checking for updates once a day
2022-06-16 06:51:22 -04:00
if (gConfig.Get("Menu.LastUpdateChecked", 0) != st.wDay)
2022-01-07 03:18:00 -05:00
{
Updater::CheckUpdate();
2022-03-14 02:04:58 -04:00
Updater::IncrementDailyUsageCounter();
2022-06-16 06:51:22 -04:00
gConfig.Set("Menu.LastUpdateChecked", st.wDay);
2022-01-07 03:18:00 -05:00
}
if (Updater::IsUpdateAvailable())
{
Updater::GetUpdateVersion();
Log::Print<eLogLevel::Info>("New update available: %s", Updater::GetUpdateVersion().c_str());
}
2021-09-20 08:41:40 -04:00
2022-01-07 03:18:00 -05:00
while (true)
{
Updater::Process();
2022-03-09 17:23:08 -05:00
RPC::Process();
Sleep(1000);
2022-01-07 03:18:00 -05:00
}
2021-09-20 08:41:40 -04:00
}
BOOL WINAPI DllMain(HINSTANCE hDllHandle, DWORD nReason, LPVOID Reserved)
{
2022-01-07 03:18:00 -05:00
if (nReason == DLL_PROCESS_ATTACH)
{
uint gameVer = GetGameVersion();
#ifdef GTASA
if (gameVer == GAME_10US_HOODLUM || gameVer == GAME_10US_COMPACT)
#else
if (gameVer == BY_GAME(NULL, GAME_10EN, GAME_10EN))
#endif
2022-01-07 03:18:00 -05:00
{
CreateThread(nullptr, NULL, (LPTHREAD_START_ROUTINE)&MenuThread, nullptr, NULL, nullptr);
}
else
{
2022-06-15 06:45:43 -04:00
Log::Print<eLogLevel::Error>("Unknown game version. GTA " BY_GAME("SA v1.0 US Hoodlum or Compact", "VC v1.0 EN", "III v1.0 EN") " is required.");
2022-06-16 14:44:33 -04:00
MessageBox(HWND_DESKTOP, "Unknown game version. GTA " BY_GAME("SA v1.0 US Hoodlum or Compact", "VC v1.0 EN", "III v1.0 EN") " is required.", FILE_NAME, MB_ICONERROR);
2022-01-07 03:18:00 -05:00
}
}
2021-09-20 08:41:40 -04:00
2022-01-07 03:18:00 -05:00
return TRUE;
2021-09-20 08:41:40 -04:00
}