diff --git a/src/Components/Modules/ModelSurfs.cpp b/src/Components/Modules/ModelSurfs.cpp index 9fac8e6f..0c53feef 100644 --- a/src/Components/Modules/ModelSurfs.cpp +++ b/src/Components/Modules/ModelSurfs.cpp @@ -129,13 +129,14 @@ namespace Components if (!surfs->surfaces) { + Assert_Offset(Game::XModelLodInfo, partBits, 12); Game::XModelSurfs* newSurfs = ModelSurfs::LoadXModelSurfaces(surfs->name); surfs->surfaces = newSurfs->surfaces; surfs->numSurfaces = newSurfs->numSurfaces; model->lods[i].surfs = newSurfs->surfaces; - std::memcpy(model->lods[i].pad3, newSurfs->pad, 24); + std::memcpy(model->lods[i].partBits, newSurfs->pad, 24); short numSurfs = static_cast(newSurfs->numSurfaces); model->lods[i].numSurfs = numSurfs; diff --git a/src/Components/Modules/Zones.cpp b/src/Components/Modules/Zones.cpp index 6d57f444..196a8a92 100644 --- a/src/Components/Modules/Zones.cpp +++ b/src/Components/Modules/Zones.cpp @@ -93,8 +93,10 @@ namespace Components for (int i = 0; i < 4; ++i) { + Assert_Offset(Game::XModelLodInfo, partBits, 12); + std::memcpy(&model->lods[i], &xmodel[72 + (i * 56)], 12); - std::memcpy(&model->lods[i].pad3, &xmodel[72 + (i * 56) + 16], 32); + std::memcpy(&model->lods[i].partBits, &xmodel[72 + (i * 56) + 16], 32); std::memcpy(reinterpret_cast(&model) + (size - 4) - (i * 4), &xmodel[72 + (i * 56) + 12], 4); } diff --git a/src/Game/Structs.hpp b/src/Game/Structs.hpp index 38558012..801f9aaf 100644 --- a/src/Game/Structs.hpp +++ b/src/Game/Structs.hpp @@ -1425,8 +1425,8 @@ namespace Game short numSurfs; // +4 short maxSurfs;// +6 XModelSurfs* surfaces; // +8 - int partBits[4]; - char pad3[8]; // +12 + int partBits[4]; // +12 + char pad3[8]; XSurface* surfs; char pad4[4]; }; diff --git a/src/STDInclude.hpp b/src/STDInclude.hpp index 20e6d452..17952024 100644 --- a/src/STDInclude.hpp +++ b/src/STDInclude.hpp @@ -141,6 +141,7 @@ using namespace std::literals; #define CLIENT_CONFIG "iw4x_config.cfg" #define Assert_Size(x, size) static_assert(sizeof(x) == size, STRINGIZE(x) " structure has an invalid size.") +#define Assert_Offset(x, y, offset) static_assert(offsetof(x, y) == offset, STRINGIZE(x) "::" STRINGIZE(y) " is not at the right offset.") // Resource stuff #ifdef APSTUDIO_INVOKED