iw5-mod/src/main.cpp

47 lines
957 B
C++
Raw Normal View History

2018-12-01 09:42:29 -05:00
#include <std_include.hpp>
2018-12-23 07:17:08 -05:00
#include "launcher/launcher.hpp"
2018-12-23 16:15:32 -05:00
#include "loader/loader.hpp"
2018-12-24 13:54:44 -05:00
#include "loader/module_loader.hpp"
void exit_hook(const int code)
{
module_loader::pre_destroy();
exit(code);
}
2018-12-01 09:42:29 -05:00
2018-12-23 07:17:08 -05:00
int CALLBACK WinMain(HINSTANCE /*hInstance*/, HINSTANCE /*hPrevInstance*/, LPSTR /*lpCmdLine*/, int /*nCmdShow*/)
2018-12-01 09:42:29 -05:00
{
2018-12-23 16:15:32 -05:00
FARPROC entry_point = nullptr;
2018-12-23 12:25:22 -05:00
{
2018-12-23 16:15:32 -05:00
launcher launcher;
const auto mode = launcher.run();
2018-12-24 13:54:44 -05:00
module_loader::set_mode(mode);
2018-12-23 16:15:32 -05:00
if (mode == launcher::mode::NONE) return 0;
loader loader(mode);
loader.set_import_resolver([](const std::string& module, const std::string& function) -> FARPROC
{
if (module == "steam_api.dll")
{
return utils::nt::module().get_proc<FARPROC>(function);
}
else if (function == "ExitProcess")
{
2018-12-24 13:54:44 -05:00
return FARPROC(exit_hook);
2018-12-23 16:15:32 -05:00
}
return nullptr;
});
entry_point = loader.load({});
if (!entry_point) return 1;
2018-12-24 13:54:44 -05:00
module_loader::post_load();
2018-12-23 12:25:22 -05:00
}
2018-12-23 16:15:32 -05:00
return entry_point();
2018-12-01 09:42:29 -05:00
}