iw7-mod/src/client/component/resources.cpp

82 lines
1.6 KiB
C++
Raw Normal View History

2022-05-19 19:11:05 +03:00
#include <std_include.hpp>
#include "loader/component_loader.hpp"
#include <utils/nt.hpp>
namespace resources
{
namespace
{
HICON icon;
2022-05-25 14:48:49 +03:00
HANDLE splash;
2022-05-19 19:11:05 +03:00
HANDLE WINAPI load_image_a(const HINSTANCE handle, LPCSTR name, const UINT type, const int c_x, const int c_y,
const UINT load)
{
const utils::nt::library self;
if (self.get_handle() == handle && name == LPCSTR(0x64)) return splash;
return LoadImageA(handle, name, type, c_x, c_y, load);
}
HICON WINAPI load_icon_a(const HINSTANCE handle, const LPCSTR name)
{
const utils::nt::library self;
2022-05-25 14:48:49 +03:00
if (self.get_handle() == handle && name == LPCSTR(1)) return icon;
2022-05-19 19:11:05 +03:00
return LoadIconA(handle, name);
}
}
class component final : public component_interface
{
public:
2022-06-04 00:39:57 +03:00
~component()
2022-05-19 19:11:05 +03:00
{
2024-01-20 21:03:11 -06:00
if (utils::nt::is_wine())
{
return;
}
2022-05-19 19:11:05 +03:00
if (icon) DestroyIcon(icon);
if (splash) DeleteObject(splash);
}
void post_start() override
{
2024-01-20 21:03:11 -06:00
if (utils::nt::is_wine())
{
return;
}
2022-05-19 19:11:05 +03:00
2024-01-20 21:03:11 -06:00
const utils::nt::library self;
2022-05-19 19:11:05 +03:00
icon = LoadIconA(self.get_handle(), MAKEINTRESOURCEA(ID_ICON));
splash = LoadImageA(self.get_handle(), MAKEINTRESOURCEA(IMAGE_SPLASH), 0, 0, 0, LR_COPYFROMRESOURCE);
}
void* load_import(const std::string& library, const std::string& function) override
{
2024-01-20 21:03:11 -06:00
if (utils::nt::is_wine())
{
return nullptr;
}
2022-05-19 19:11:05 +03:00
if (library == "USER32.dll")
{
if (function == "LoadIconA")
{
return load_icon_a;
}
if (function == "LoadImageA")
{
return load_image_a;
}
}
return nullptr;
}
};
}
REGISTER_COMPONENT(resources::component)