whiteoutlib 0.1.4

Read and write Blizzard game assets from Rust: models (MDX, M2, M3), textures (BLP, DDS, PNG, JPEG, BMP, TGA, TIFF, GIF) and archives (CASC, MPQ).
Documentation
// SPDX-License-Identifier: BSD-3-Clause
// Copyright (c) 2026 Fernando Sahmkow
// AUTOGENERATED by tools/codegen/emit_c.py — do not edit.
// Regenerate via:  python -m tools.codegen.codegen host --backend c-source

#include "whiteout_host.h"

#include <cstring>
#include <new>
#include <span>
#include <string>
#include <vector>

#include <whiteout/interfaces.h>
#include <whiteout/utils/os_file_system.h>
#include <whiteout/utils/simple_thread_pool.h>
#include <whiteout/utils/simple_http_handler.h>
#include <whiteout/utils/job_group.h>
#include <whiteout/utils/blizzard_game_finder.h>

namespace { using namespace whiteout; }

namespace {

// `whiteout::u8` is `std::uint8_t`, so a single overload suffices. We use
// the project's type so the reinterpret_cast is a no-op everywhere the
// codegen runs.
inline whiteout_Bytes wrapBytes(std::vector<whiteout::u8>&& v) {
    auto* owned = new std::vector<whiteout::u8>(std::move(v));
    return { reinterpret_cast<const uint8_t*>(owned->data()), owned->size(), owned };
}

inline whiteout_Bytes emptyBytes() {
    return { nullptr, 0, nullptr };
}

inline whiteout_CString wrapCString(std::string&& s) {
    auto* owned = new std::string(std::move(s));
    return { owned->c_str(), owned->size(), owned };
}

inline whiteout_CString emptyCString() {
    return { nullptr, 0, nullptr };
}

} // anonymous
// ── WorkerPool ─────────────────────────────────────────────────

extern "C" {

void whiteout_host_WorkerPool_delete(whiteout_WorkerPool* self) {
    delete reinterpret_cast<whiteout::interfaces::WorkerPool*>(self);
}

void whiteout_host_WorkerPool_waitIdle(whiteout_WorkerPool* self) {
    reinterpret_cast<whiteout::interfaces::WorkerPool*>(self)->waitIdle();
}

uint64_t whiteout_host_WorkerPool_threadCount(const whiteout_WorkerPool* self) {
    return reinterpret_cast<const whiteout::interfaces::WorkerPool*>(self)->threadCount();
}

} // extern "C"

// ── CascFileSystem ─────────────────────────────────────────────────

extern "C" {

void whiteout_host_CascFileSystem_delete(whiteout_CascFileSystem* self) {
    delete reinterpret_cast<whiteout::interfaces::CascFileSystem*>(self);
}

whiteout_Bytes whiteout_host_CascFileSystem_readFile(const whiteout_CascFileSystem* self, uint32_t fileId) {
    return wrapBytes(reinterpret_cast<const whiteout::interfaces::CascFileSystem*>(self)->readFile(fileId));
}

int32_t whiteout_host_CascFileSystem_reserveFileId(whiteout_CascFileSystem* self, const char* path, uint32_t* out_value) {
    auto __r = reinterpret_cast<whiteout::interfaces::CascFileSystem*>(self)->reserveFileId(std::string(path ? path : ""));
    if (!__r) return 0;
    if (out_value) *out_value = static_cast<uint32_t>(*__r);
    return 1;
}

int32_t whiteout_host_CascFileSystem_writeFile(whiteout_CascFileSystem* self, uint32_t fileId, const uint8_t* data, size_t data_size) {
    return reinterpret_cast<whiteout::interfaces::CascFileSystem*>(self)->writeFile(fileId, std::vector<whiteout::u8>(data, data + data_size));
}

int32_t whiteout_host_CascFileSystem_fileExists(const whiteout_CascFileSystem* self, uint32_t fileId) {
    return reinterpret_cast<const whiteout::interfaces::CascFileSystem*>(self)->fileExists(fileId);
}

} // extern "C"

// ── VirtualPathFileSystem ─────────────────────────────────────────────────

extern "C" {

void whiteout_host_VirtualPathFileSystem_delete(whiteout_VirtualPathFileSystem* self) {
    delete reinterpret_cast<whiteout::interfaces::VirtualPathFileSystem*>(self);
}

whiteout_Bytes whiteout_host_VirtualPathFileSystem_readFile(const whiteout_VirtualPathFileSystem* self, const char* path) {
    return wrapBytes(reinterpret_cast<const whiteout::interfaces::VirtualPathFileSystem*>(self)->readFile(std::string(path ? path : "")));
}

int32_t whiteout_host_VirtualPathFileSystem_writeFile(whiteout_VirtualPathFileSystem* self, const char* path, const uint8_t* data, size_t data_size) {
    return reinterpret_cast<whiteout::interfaces::VirtualPathFileSystem*>(self)->writeFile(std::string(path ? path : ""), std::vector<whiteout::u8>(data, data + data_size));
}

int32_t whiteout_host_VirtualPathFileSystem_fileExists(const whiteout_VirtualPathFileSystem* self, const char* path) {
    return reinterpret_cast<const whiteout::interfaces::VirtualPathFileSystem*>(self)->fileExists(std::string(path ? path : ""));
}

} // extern "C"

// ── HttpResponse ─────────────────────────────────────────────────

extern "C" {

whiteout_HttpResponse* whiteout_host_HttpResponse_new(void) {
    return reinterpret_cast<whiteout_HttpResponse*>(new whiteout::interfaces::HttpResponse());
}

void whiteout_host_HttpResponse_delete(whiteout_HttpResponse* self) {
    delete reinterpret_cast<whiteout::interfaces::HttpResponse*>(self);
}

int32_t whiteout_host_HttpResponse_get_statusCode(const whiteout_HttpResponse* self) {
    return reinterpret_cast<const whiteout::interfaces::HttpResponse*>(self)->statusCode;
}

void whiteout_host_HttpResponse_set_statusCode(whiteout_HttpResponse* self, int32_t value) {
    reinterpret_cast<whiteout::interfaces::HttpResponse*>(self)->statusCode = value;
}

size_t whiteout_host_HttpResponse_get_body_count(const whiteout_HttpResponse* self) {
    return reinterpret_cast<const whiteout::interfaces::HttpResponse*>(self)->body.size();
}

void whiteout_host_HttpResponse_resize_body(whiteout_HttpResponse* self, size_t count) {
    reinterpret_cast<whiteout::interfaces::HttpResponse*>(self)->body.resize(count);
}

const uint8_t* whiteout_host_HttpResponse_get_body_data(const whiteout_HttpResponse* self) {
    const auto& __v = reinterpret_cast<const whiteout::interfaces::HttpResponse*>(self)->body;
    return __v.empty() ? nullptr : reinterpret_cast<const uint8_t*>(__v.data());
}

void whiteout_host_HttpResponse_assign_body(whiteout_HttpResponse* self, const uint8_t* data, size_t count) {
    auto& __v = reinterpret_cast<whiteout::interfaces::HttpResponse*>(self)->body;
    __v.resize(count);
    if (count) std::memcpy(__v.data(), data, count * sizeof(whiteout::u8));
}

whiteout_CString whiteout_host_HttpResponse_get_error(const whiteout_HttpResponse* self) {
    auto* __owned = new std::string(reinterpret_cast<const whiteout::interfaces::HttpResponse*>(self)->error);
    return whiteout_CString{ __owned->c_str(), __owned->size(), __owned };
}

void whiteout_host_HttpResponse_set_error(whiteout_HttpResponse* self, const char* value) {
    reinterpret_cast<whiteout::interfaces::HttpResponse*>(self)->error = (value ? value : "");
}

} // extern "C"

// ── HttpHandler ─────────────────────────────────────────────────

extern "C" {

void whiteout_host_HttpHandler_delete(whiteout_HttpHandler* self) {
    delete reinterpret_cast<whiteout::interfaces::HttpHandler*>(self);
}

uint32_t whiteout_host_HttpHandler_capabilities(const whiteout_HttpHandler* self) {
    return reinterpret_cast<const whiteout::interfaces::HttpHandler*>(self)->capabilities();
}

} // extern "C"

// ── OsFileSystem ─────────────────────────────────────────────────

extern "C" {

whiteout_OsFileSystem* whiteout_host_OsFileSystem_new_rootPath(const char* rootPath) {
    return reinterpret_cast<whiteout_OsFileSystem*>(new whiteout::utils::OsFileSystem(std::string(rootPath)));
}

void whiteout_host_OsFileSystem_delete(whiteout_OsFileSystem* self) {
    delete reinterpret_cast<whiteout::utils::OsFileSystem*>(self);
}

whiteout_Bytes whiteout_host_OsFileSystem_readFile(const whiteout_OsFileSystem* self, const char* path) {
    return wrapBytes(reinterpret_cast<const whiteout::utils::OsFileSystem*>(self)->readFile(std::string(path ? path : "")));
}

int32_t whiteout_host_OsFileSystem_writeFile(whiteout_OsFileSystem* self, const char* path, const uint8_t* data, size_t data_size) {
    return reinterpret_cast<whiteout::utils::OsFileSystem*>(self)->writeFile(std::string(path ? path : ""), std::vector<whiteout::u8>(data, data + data_size));
}

int32_t whiteout_host_OsFileSystem_fileExists(const whiteout_OsFileSystem* self, const char* path) {
    return reinterpret_cast<const whiteout::utils::OsFileSystem*>(self)->fileExists(std::string(path ? path : ""));
}

} // extern "C"

// ── SimpleThreadPool ─────────────────────────────────────────────────

extern "C" {

whiteout_SimpleThreadPool* whiteout_host_SimpleThreadPool_new_nThreads(uint64_t nThreads) {
    return reinterpret_cast<whiteout_SimpleThreadPool*>(new whiteout::utils::SimpleThreadPool(nThreads));
}

void whiteout_host_SimpleThreadPool_delete(whiteout_SimpleThreadPool* self) {
    delete reinterpret_cast<whiteout::utils::SimpleThreadPool*>(self);
}

void whiteout_host_SimpleThreadPool_waitIdle(whiteout_SimpleThreadPool* self) {
    reinterpret_cast<whiteout::utils::SimpleThreadPool*>(self)->waitIdle();
}

uint64_t whiteout_host_SimpleThreadPool_threadCount(const whiteout_SimpleThreadPool* self) {
    return reinterpret_cast<const whiteout::utils::SimpleThreadPool*>(self)->threadCount();
}

} // extern "C"

// ── SimpleHttpHandler ─────────────────────────────────────────────────

extern "C" {

whiteout_SimpleHttpHandler* whiteout_host_SimpleHttpHandler_new(void) {
    return reinterpret_cast<whiteout_SimpleHttpHandler*>(new whiteout::utils::SimpleHttpHandler());
}

whiteout_SimpleHttpHandler* whiteout_host_SimpleHttpHandler_new_nThreads(uint64_t nThreads) {
    return reinterpret_cast<whiteout_SimpleHttpHandler*>(new whiteout::utils::SimpleHttpHandler(nThreads));
}

void whiteout_host_SimpleHttpHandler_delete(whiteout_SimpleHttpHandler* self) {
    delete reinterpret_cast<whiteout::utils::SimpleHttpHandler*>(self);
}

uint32_t whiteout_host_SimpleHttpHandler_capabilities(const whiteout_SimpleHttpHandler* self) {
    return reinterpret_cast<const whiteout::utils::SimpleHttpHandler*>(self)->capabilities();
}

} // extern "C"

// ── JobGroup ─────────────────────────────────────────────────

extern "C" {

whiteout_JobGroup* whiteout_host_JobGroup_new(void) {
    return reinterpret_cast<whiteout_JobGroup*>(new whiteout::utils::JobGroup());
}

void whiteout_host_JobGroup_delete(whiteout_JobGroup* self) {
    delete reinterpret_cast<whiteout::utils::JobGroup*>(self);
}

void whiteout_host_JobGroup_add(whiteout_JobGroup* self, uint64_t n) {
    reinterpret_cast<whiteout::utils::JobGroup*>(self)->add(n);
}

void whiteout_host_JobGroup_done(whiteout_JobGroup* self) {
    reinterpret_cast<whiteout::utils::JobGroup*>(self)->done();
}

void whiteout_host_JobGroup_await(whiteout_JobGroup* self) {
    reinterpret_cast<whiteout::utils::JobGroup*>(self)->wait();
}

int32_t whiteout_host_JobGroup_isReady(const whiteout_JobGroup* self) {
    return reinterpret_cast<const whiteout::utils::JobGroup*>(self)->isReady();
}

} // extern "C"

// ── BlizzardGameInfo ─────────────────────────────────────────────────

extern "C" {

whiteout_BlizzardGameInfo* whiteout_host_BlizzardGameInfo_new(void) {
    return reinterpret_cast<whiteout_BlizzardGameInfo*>(new whiteout::utils::BlizzardGameInfo());
}

void whiteout_host_BlizzardGameInfo_delete(whiteout_BlizzardGameInfo* self) {
    delete reinterpret_cast<whiteout::utils::BlizzardGameInfo*>(self);
}

int32_t whiteout_host_BlizzardGameInfo_get_game(const whiteout_BlizzardGameInfo* self) {
    return static_cast<int32_t>(reinterpret_cast<const whiteout::utils::BlizzardGameInfo*>(self)->game);
}

void whiteout_host_BlizzardGameInfo_set_game(whiteout_BlizzardGameInfo* self, int32_t value) {
    reinterpret_cast<whiteout::utils::BlizzardGameInfo*>(self)->game = static_cast<whiteout::utils::BlizzardGame>(value);
}

whiteout_CString whiteout_host_BlizzardGameInfo_get_name(const whiteout_BlizzardGameInfo* self) {
    auto* __owned = new std::string(reinterpret_cast<const whiteout::utils::BlizzardGameInfo*>(self)->name);
    return whiteout_CString{ __owned->c_str(), __owned->size(), __owned };
}

void whiteout_host_BlizzardGameInfo_set_name(whiteout_BlizzardGameInfo* self, const char* value) {
    reinterpret_cast<whiteout::utils::BlizzardGameInfo*>(self)->name = (value ? value : "");
}

whiteout_CString whiteout_host_BlizzardGameInfo_get_path(const whiteout_BlizzardGameInfo* self) {
    auto* __owned = new std::string(reinterpret_cast<const whiteout::utils::BlizzardGameInfo*>(self)->path);
    return whiteout_CString{ __owned->c_str(), __owned->size(), __owned };
}

void whiteout_host_BlizzardGameInfo_set_path(whiteout_BlizzardGameInfo* self, const char* value) {
    reinterpret_cast<whiteout::utils::BlizzardGameInfo*>(self)->path = (value ? value : "");
}

} // extern "C"

// ── BlizzardGameInfoList ─────────────────────────────────────────────────

extern "C" {

void whiteout_host_BlizzardGameInfoList_delete(whiteout_BlizzardGameInfoList* self) {
    delete reinterpret_cast<whiteout::utils::BlizzardGameInfoList*>(self);
}

uint64_t whiteout_host_BlizzardGameInfoList_size(const whiteout_BlizzardGameInfoList* self) {
    return reinterpret_cast<const whiteout::utils::BlizzardGameInfoList*>(self)->size();
}

struct whiteout_BlizzardGameInfo* whiteout_host_BlizzardGameInfoList_at(const whiteout_BlizzardGameInfoList* self, uint64_t index) {
    auto& __r = reinterpret_cast<const whiteout::utils::BlizzardGameInfoList*>(self)->at(index);
    return const_cast<struct whiteout_BlizzardGameInfo*>(
        reinterpret_cast<const struct whiteout_BlizzardGameInfo*>(&__r));
}

} // extern "C"

// ── BlizzardGameFinder ─────────────────────────────────────────────────

extern "C" {

void whiteout_host_BlizzardGameFinder_delete(whiteout_BlizzardGameFinder* self) {
    delete reinterpret_cast<whiteout::utils::BlizzardGameFinder*>(self);
}

struct whiteout_BlizzardGameInfoList* whiteout_host_BlizzardGameFinder_findAll(void) {
    return reinterpret_cast<struct whiteout_BlizzardGameInfoList*>(
        new whiteout::utils::BlizzardGameInfoList(whiteout::utils::BlizzardGameFinder::findAll()));
}

int32_t whiteout_host_BlizzardGameFinder_fromName(const char* name) {
    return static_cast<int32_t>(whiteout::utils::BlizzardGameFinder::fromName(std::string(name ? name : "")));
}

whiteout_CString whiteout_host_BlizzardGameFinder_toName(int32_t game) {
    return wrapCString(whiteout::utils::BlizzardGameFinder::toName(static_cast<whiteout::utils::BlizzardGame>(game)));
}

} // extern "C"