#include "pixmap.hpp" #include namespace t5de { namespace { using Getter = unsigned(__thiscall*)(const imvu::Pixmap*); using PixelsGetter = std::uint32_t*(__thiscall*)(const imvu::Pixmap*); struct Methods { Getter width = nullptr; Getter height = nullptr; Getter rowBytes = nullptr; PixelsGetter pixels = nullptr; }; const Methods& methods() { static const Methods methods = [] { Methods found; if (HMODULE module = GetModuleHandleW(L"pixmap.dll")) { found.width = reinterpret_cast(GetProcAddress(module, "?width@Pixmap@@QBEIXZ")); found.height = reinterpret_cast(GetProcAddress(module, "?height@Pixmap@@QBEIXZ")); found.rowBytes = reinterpret_cast(GetProcAddress(module, "?rowBytes@Pixmap@@QBEIXZ")); found.pixels = reinterpret_cast(GetProcAddress(module, "?pixels@Pixmap@@QBEPAIXZ")); } return found; }(); return methods; } } // namespace std::optional pixmap_pixels(const imvu::Pixmap& pixmap) { const Methods& m = methods(); if (m.width == nullptr || m.height == nullptr || m.rowBytes == nullptr || m.pixels == nullptr) { return std::nullopt; } return PixmapPixels{m.width(&pixmap), m.height(&pixmap), m.rowBytes(&pixmap), m.pixels(&pixmap)}; } } // namespace t5de