mirror of
https://github.com/XLabsProject/s1x-client.git
synced 2023-08-02 15:02:12 +02:00
Fix streamed textures being overriden
This commit is contained in:
parent
a04f166b15
commit
9620df5d4f
@ -2,6 +2,7 @@
|
||||
#include "loader/component_loader.hpp"
|
||||
#include "game/game.hpp"
|
||||
#include "images.hpp"
|
||||
#include "console.hpp"
|
||||
#include "scheduler.hpp"
|
||||
|
||||
#include <utils/hook.hpp>
|
||||
@ -15,12 +16,16 @@ namespace images
|
||||
namespace
|
||||
{
|
||||
utils::hook::detour load_texture_hook;
|
||||
utils::hook::detour setup_texture_hook;
|
||||
utils::concurrency::container<std::unordered_map<std::string, std::string>> overriden_textures;
|
||||
|
||||
static_assert(sizeof(game::GfxImage) == 104);
|
||||
static_assert(offsetof(game::GfxImage, name) == (sizeof(game::GfxImage) - sizeof(void*)));
|
||||
static_assert(offsetof(game::GfxImage, loadDef) == 56);
|
||||
static_assert(offsetof(game::GfxImage, pixelData) == 56);
|
||||
static_assert(offsetof(game::GfxImage, width) == 44);
|
||||
static_assert(offsetof(game::GfxImage, height) == 46);
|
||||
static_assert(offsetof(game::GfxImage, depth) == 48);
|
||||
static_assert(offsetof(game::GfxImage, numElements) == 50);
|
||||
|
||||
std::optional<std::string> load_image(game::GfxImage* image)
|
||||
{
|
||||
@ -60,8 +65,8 @@ namespace images
|
||||
return false;
|
||||
}
|
||||
|
||||
image->imageFormat |= 0x1000003;
|
||||
image->imageFormat &= ~0x2030000;
|
||||
image->imageFormat = 0x1000003;
|
||||
image->resourceSize = -1;
|
||||
|
||||
D3D11_SUBRESOURCE_DATA data{};
|
||||
data.SysMemPitch = raw_image->get_width() * 4;
|
||||
@ -87,12 +92,24 @@ namespace images
|
||||
return;
|
||||
}
|
||||
}
|
||||
catch(std::exception&)
|
||||
catch(std::exception& e)
|
||||
{
|
||||
console::error("Failed to load image %s: %s\n", image->name, e.what());
|
||||
}
|
||||
|
||||
load_texture_hook.invoke(load_def, image);
|
||||
}
|
||||
|
||||
int setup_texture_stub(game::GfxImage* image, void* a2, void* a3)
|
||||
{
|
||||
if(image->resourceSize == -1)
|
||||
{
|
||||
image->resourceSize = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
return setup_texture_hook.invoke<bool>(image, a2, a3);
|
||||
}
|
||||
}
|
||||
|
||||
void override_texture(std::string name, std::string data)
|
||||
@ -110,6 +127,7 @@ namespace images
|
||||
{
|
||||
if (game::environment::is_dedi()) return;
|
||||
|
||||
setup_texture_hook.create(SELECT_VALUE(0x14002A560, 0x140054370), setup_texture_stub);
|
||||
load_texture_hook.create(SELECT_VALUE(0x140484970, 0x1405A21F0), load_texture_stub);
|
||||
}
|
||||
};
|
||||
|
@ -1268,13 +1268,13 @@ namespace game
|
||||
struct GfxImage
|
||||
{
|
||||
GfxTexture textures;
|
||||
char pad5[4];
|
||||
int flags;
|
||||
int imageFormat;
|
||||
int pad4;
|
||||
int resourceSize;
|
||||
char mapType;
|
||||
char semantic;
|
||||
char category;
|
||||
char flags;
|
||||
char flags2;
|
||||
Picmip picmip;
|
||||
char track;
|
||||
//CardMemory cardMemory;
|
||||
@ -1282,8 +1282,10 @@ namespace game
|
||||
unsigned short height;
|
||||
unsigned short depth;
|
||||
unsigned short numElements;
|
||||
GfxImageLoadDef *loadDef;
|
||||
char pad2[32];
|
||||
char pad3[4];
|
||||
void* pixelData;
|
||||
//GfxImageLoadDef *loadDef;
|
||||
uint64_t streams[4];
|
||||
const char *name;
|
||||
};
|
||||
|
||||
|
@ -52,10 +52,12 @@ namespace game
|
||||
|
||||
WEAK symbol<void(XAssetType type, void (__cdecl* func)(XAssetHeader, void*), void* inData, bool includeOverride)>
|
||||
DB_EnumXAssets_FastFile{0x14017D7C0, 0x14026EC10};
|
||||
WEAK symbol<void(XAssetType type, void(__cdecl* func)(game::XAssetHeader, void*), const void* inData, bool includeOverride)>
|
||||
WEAK symbol<void(XAssetType type, void(__cdecl* func)(XAssetHeader, void*), const void* inData, bool includeOverride)>
|
||||
DB_EnumXAssets_Internal{0x14017D830, 0x14026EC80};
|
||||
WEAK symbol<game::XAssetEntry(game::XAssetType type, const char* name)>
|
||||
WEAK symbol<XAssetEntry(XAssetType type, const char* name)>
|
||||
DB_FindXAssetEntry{0x14017D830, 0x14026F020};
|
||||
WEAK symbol<XAssetEntry(XAssetType type, const char *name, int allowCreateDefault)>
|
||||
DB_FindXAssetHeader{0x14017DCA0, 0x14026F0F0};
|
||||
WEAK symbol<const char* (const XAsset* asset)> DB_GetXAssetName{0x140151C00, 0x140240DD0};
|
||||
WEAK symbol<int(XAssetType type)> DB_GetXAssetTypeSize{0x140151C20, 0x140240DF0};
|
||||
WEAK symbol<void(XZoneInfo* zoneInfo, unsigned int zoneCount, DBSyncMode syncMode)> DB_LoadXAssets{
|
||||
|
@ -15,7 +15,7 @@ namespace utils::nt
|
||||
library library::get_by_address(void* address)
|
||||
{
|
||||
HMODULE handle = nullptr;
|
||||
GetModuleHandleExA(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS, static_cast<LPCSTR>(address), &handle);
|
||||
GetModuleHandleExA(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, static_cast<LPCSTR>(address), &handle);
|
||||
return library(handle);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user