diff --git a/src/Components/Modules/AssetInterfaces/IGfxWorld.cpp b/src/Components/Modules/AssetInterfaces/IGfxWorld.cpp index a3b0f918..c8445fea 100644 --- a/src/Components/Modules/AssetInterfaces/IGfxWorld.cpp +++ b/src/Components/Modules/AssetInterfaces/IGfxWorld.cpp @@ -18,6 +18,8 @@ namespace Assets asset->smodelInsts = reader->readArray(asset->smodelCount); } + std::vector surfs; + if (asset->surfaces) { asset->surfaces = reader->readArray(world->surfaceCount); @@ -25,6 +27,7 @@ namespace Assets for (unsigned int i = 0; i < world->surfaceCount; ++i) { Game::GfxSurface* surface = &asset->surfaces[i]; + surfs.push_back(&asset->surfaces[i]); if (surface->material) { @@ -33,6 +36,23 @@ namespace Assets } } + std::sort(surfs.begin(), surfs.end(), [](Game::GfxSurface* a, Game::GfxSurface* b) + { + if (a->material->name == nullptr && b->material->name == nullptr) return false; + if (a->material->name == nullptr && b->material->name != nullptr) return true; + if (a->material->name != nullptr && b->material->name == nullptr) return false; + return strcmp(a->material->name, b->material->name) == 0; + }); + + Game::GfxSurface* tmpBuffer = builder->getAllocator()->allocateArray(world->surfaceCount); + + for (unsigned int i = 0; i < world->surfaceCount; ++i) + { + std::memcpy(&tmpBuffer[i], surfs[i], sizeof(Game::GfxSurface)); + } + + asset->surfaces = tmpBuffer; + if (asset->surfacesBounds) { asset->surfacesBounds = reader->readArray(world->surfaceCount); diff --git a/src/Game/Structs.hpp b/src/Game/Structs.hpp index 032c0c2d..44ae2da1 100644 --- a/src/Game/Structs.hpp +++ b/src/Game/Structs.hpp @@ -545,7 +545,17 @@ namespace Game struct GfxDrawSurfFields { - __int64 _bf0; + unsigned __int64 objectId : 16; + unsigned __int64 reflectionProbeIndex : 8; + unsigned __int64 hasGfxEntIndex : 1; + unsigned __int64 customIndex : 5; + unsigned __int64 materialSortedIndex : 12; + unsigned __int64 prepass : 2; + unsigned __int64 useHeroLighting : 1; + unsigned __int64 sceneLightIndex : 8; + unsigned __int64 surfType : 4; + unsigned __int64 primarySortKey : 6; + unsigned __int64 unused : 1; }; union GfxDrawSurf @@ -559,6 +569,7 @@ namespace Game unsigned int loadBits[2]; }; + #pragma pack(push, 4) struct Material { @@ -3052,6 +3063,8 @@ namespace Game float scale; }; + + struct GfxStaticModelDrawInst { GfxPackedPlacement placement;