Prepare custom texture support #185

This commit is contained in:
Maurice Heumann 2021-05-15 12:33:21 +02:00
parent eaca589729
commit 43649ce612
3 changed files with 96 additions and 1 deletions

View File

@ -0,0 +1,37 @@
#include <std_include.hpp>
#include "loader/component_loader.hpp"
#include "game/game.hpp"
#include <utils/hook.hpp>
namespace images
{
namespace
{
utils::hook::detour load_texture_hook;
static_assert(sizeof(game::GfxImage) == 104);
static_assert(offsetof(game::GfxImage, name) == (sizeof(game::GfxImage) - sizeof(void*)));
static_assert(offsetof(game::GfxImage, texture) == 56);
void load_texture_stub(game::GfxImageLoadDef** load_def, game::GfxImage* image)
{
printf("Loading image: %s\n", image->name);
load_texture_hook.invoke(load_def, image);
}
}
class component final : public component_interface
{
public:
void post_unpack() override
{
if (!game::environment::is_mp()) return;
load_texture_hook.create(0x1405A21F0, load_texture_stub);
}
};
}
REGISTER_COMPONENT(images::component)

View File

@ -1,4 +1,5 @@
#pragma once
#include <d3d11.h>
#define PROTOCOL 1
@ -1225,6 +1226,62 @@ namespace game
const char* buffer;
};
struct GfxImageLoadDef
{
char levelCount;
char numElements;
char pad[2];
int flags;
int format;
int resourceSize;
char data[1];
};
union $3FA29451CE6F1FA138A5ABAB84BE9676
{
ID3D11Texture1D *linemap;
ID3D11Texture2D *map;
ID3D11Texture3D *volmap;
ID3D11Texture2D *cubemap;
GfxImageLoadDef *loadDef;
};
struct GfxTexture
{
$3FA29451CE6F1FA138A5ABAB84BE9676 ___u0;
ID3D11ShaderResourceView *shaderView;
ID3D11ShaderResourceView *shaderViewAlternate;
};
struct Picmip
{
char platform[2];
};
struct CardMemory
{
int platform[2];
};
struct GfxImage
{
char pad[36];
char mapType;
char semantic;
char category;
char flags;
Picmip picmip;
char track;
//CardMemory cardMemory;
unsigned short width;
unsigned short height;
unsigned short depth;
unsigned short numElements;
GfxTexture texture;
char pad2[16];
const char *name;
};
union XAssetHeader
{
void* data;
@ -1234,6 +1291,7 @@ namespace game
ScriptFile* scriptfile;
StringTable* stringTable;
LuaFile* luaFile;
GfxImage* image;
};
struct XAsset

View File

@ -78,7 +78,7 @@ namespace utils::hook
return static_cast<T*>(this->get_original());
}
template <typename T, typename... Args>
template <typename T = void, typename... Args>
T invoke(Args ... args)
{
return static_cast<T(*)(Args ...)>(this->get_original())(args...);