rodecomp/Source/Resource/BinkRuntime.h
ragnarok-clanker 5ec8920fd4 Maintenance: Add mandatory field offset markers /* XXXX */ and assertions to Resource headers
Batch #1067 by ragnarok-clanker: no function's compiled code changes; checked with 83 compiled unit(s), including every includer of Source/Resource/Audio/WaveResource.h, Source/Resource/BinkRuntime.h, Source/Resource/Bitmap/BitmapResource.h, Source/Resource/Bitmap/IJL15Runtime.h, Source/Resource/Models/ModelResource.h, Source/Resource/Resource.h, Source/Resource/ResourceAliases.h, Source/Resource/Sprites/ActionResource.h, Source/Resource/World/WorldResource.h.
2026-10-27 14:00:13 +00:00

70 lines
2.6 KiB
C++

#ifndef RAGNAROK_SOURCE_RESOURCE_BINKRUNTIME_H
#define RAGNAROK_SOURCE_RESOURCE_BINKRUNTIME_H
#include <cstddef>
#include <cstdint>
#include <system_error>
#include <windows.h>
struct BinkHandle {
std::uint32_t width;
std::uint32_t height;
/* 0008 */ std::uint32_t frames;
/* 000C */ std::uint32_t frame;
};
#if defined(_WIN32) && !defined(_WIN64)
static_assert(offsetof(BinkHandle, frames) == 0x08);
static_assert(offsetof(BinkHandle, frame) == 0x0C);
#endif
class BinkRuntime {
public:
BinkRuntime();
~BinkRuntime();
BinkRuntime(const BinkRuntime&) = delete;
BinkRuntime& operator=(const BinkRuntime&) = delete;
BinkHandle*(WINAPI* open)(const void*, unsigned);
void(WINAPI* close)(BinkHandle*);
const char*(WINAPI* error)();
int(WINAPI* wait)(BinkHandle*);
int(WINAPI* doFrame)(BinkHandle*);
int(WINAPI* shouldSkip)(BinkHandle*);
void(WINAPI* nextFrame)(BinkHandle*);
void(WINAPI* copyToBuffer)(BinkHandle*, void*, int, unsigned, unsigned, unsigned, unsigned);
void(WINAPI* setVolume)(BinkHandle*, unsigned, int);
private:
HMODULE m_module;
};
// INLINED
inline BinkRuntime::BinkRuntime() : m_module(LoadLibraryA("binkw32.dll")) {
if (!this->m_module) {
throw std::system_error(GetLastError(), std::system_category(), "binkw32.dll");
}
this->open = reinterpret_cast<decltype(this->open)>(GetProcAddress(this->m_module, "_BinkOpen@8"));
this->close = reinterpret_cast<decltype(this->close)>(GetProcAddress(this->m_module, "_BinkClose@4"));
this->error = reinterpret_cast<decltype(this->error)>(GetProcAddress(this->m_module, "_BinkGetError@0"));
this->wait = reinterpret_cast<decltype(this->wait)>(GetProcAddress(this->m_module, "_BinkWait@4"));
this->doFrame = reinterpret_cast<decltype(this->doFrame)>(GetProcAddress(this->m_module, "_BinkDoFrame@4"));
this->shouldSkip = reinterpret_cast<decltype(this->shouldSkip)>(GetProcAddress(this->m_module, "_BinkShouldSkip@4"));
this->nextFrame = reinterpret_cast<decltype(this->nextFrame)>(GetProcAddress(this->m_module, "_BinkNextFrame@4"));
this->copyToBuffer = reinterpret_cast<decltype(this->copyToBuffer)>(GetProcAddress(this->m_module, "_BinkCopyToBuffer@28"));
this->setVolume = reinterpret_cast<decltype(this->setVolume)>(GetProcAddress(this->m_module, "_BinkSetVolume@12"));
if (!this->open || !this->close || !this->error || !this->wait || !this->doFrame || !this->shouldSkip || !this->nextFrame || !this->copyToBuffer ||
!this->setVolume) {
FreeLibrary(this->m_module);
throw std::system_error(ERROR_PROC_NOT_FOUND, std::system_category(), "binkw32 exports");
}
}
// INLINED
inline BinkRuntime::~BinkRuntime() {
FreeLibrary(this->m_module);
}
#endif