iw4x-client/src/Main.cpp

85 lines
1.9 KiB
C++
Raw Normal View History

2017-01-19 16:23:59 -05:00
#include "STDInclude.hpp"
namespace Main
{
void Initialize()
{
2017-06-30 04:37:29 -04:00
Utils::SetEnvironment();
2017-01-19 16:23:59 -05:00
Utils::Cryptography::Initialize();
2017-01-30 15:13:30 -05:00
Components::Loader::Initialize();
2017-01-19 16:23:59 -05:00
2017-01-30 15:13:30 -05:00
#if defined(DEBUG) || defined(FORCE_UNIT_TESTS)
2017-07-03 09:40:32 -04:00
if (Components::Loader::IsPerformingUnitTests())
2017-01-19 16:23:59 -05:00
{
2017-01-30 15:13:30 -05:00
DWORD result = (Components::Loader::PerformUnitTests() ? 0 : -1);
Components::Loader::Uninitialize();
ExitProcess(result);
2017-01-19 16:23:59 -05:00
}
#else
2017-01-30 15:13:30 -05:00
if (Components::Flags::HasFlag("tests"))
{
Components::Logger::Print("Unit tests are disabled outside the debug environment!\n");
}
2017-01-30 15:13:30 -05:00
#endif
2017-01-19 16:23:59 -05:00
}
void Uninitialize()
{
2017-01-30 15:13:30 -05:00
Components::Loader::Uninitialize();
Utils::Cache::Uninitialize();
google::protobuf::ShutdownProtobufLibrary();
2017-01-19 16:23:59 -05:00
}
2017-05-30 17:34:52 -04:00
__declspec(naked) void EntryPoint()
{
__asm
{
pushad
call Main::Initialize
popad
push 6BAA2Fh // Continue init routine
2017-05-30 17:34:52 -04:00
push 6CA062h // ___security_init_cookie
retn
}
}
2017-01-19 16:23:59 -05:00
}
BOOL APIENTRY DllMain(HMODULE /*hModule*/, DWORD ul_reason_for_call, LPVOID /*lpReserved*/)
{
if (ul_reason_for_call == DLL_PROCESS_ATTACH)
{
// Not sure if it conflicts with our TLS variables
//DisableThreadLibraryCalls(hModule);
2017-02-16 21:27:38 -05:00
Steam::Proxy::RunMod();
#ifndef DISABLE_BINARY_CHECK
2017-01-19 16:23:59 -05:00
// Ensure we're working with our desired binary
2022-04-15 05:16:22 -04:00
auto* _module = reinterpret_cast<char*>(0x400000);
2020-12-19 18:00:07 -05:00
auto hash1 = Utils::Cryptography::JenkinsOneAtATime::Compute(_module + 0x1000, 0x2D531F); // .text
auto hash2 = Utils::Cryptography::JenkinsOneAtATime::Compute(_module + 0x2D75FC, 0xBDA04); // .rdata
if ((hash1 != 0x54684DBE
2018-11-04 14:10:27 -05:00
#ifdef DEBUG
&& hash1 != 0x8AADE716
2018-11-04 14:10:27 -05:00
#endif
) || hash2 != 0x8030ec53)
{
return FALSE;
}
2017-01-19 16:23:59 -05:00
DWORD oldProtect;
2020-12-19 18:00:07 -05:00
VirtualProtect(_module + 0x1000, 0x2D6000, PAGE_EXECUTE_READ, &oldProtect); // Protect the .text segment
#endif
2017-01-19 16:23:59 -05:00
2017-05-30 17:34:52 -04:00
// Install entry point hook
Utils::Hook(0x6BAC0F, Main::EntryPoint, HOOK_JUMP).install()->quick();
2017-01-19 16:23:59 -05:00
}
else if (ul_reason_for_call == DLL_PROCESS_DETACH)
{
Main::Uninitialize();
}
return TRUE;
}