From 2823a46b92ecf9bc6ff453309cbcbacc230d403b Mon Sep 17 00:00:00 2001 From: Jan Date: Thu, 21 Apr 2022 19:58:49 +0200 Subject: [PATCH] Add improvements from iw3 material dumping to iw4 --- src/Common/Game/IW4/IW4_Assets.h | 9 ++ src/ObjCommon/Game/IW4/MaterialConstantsIW4.h | 111 ++++++++++++++++++ .../IW4/AssetDumpers/AssetDumperMaterial.cpp | 35 +++++- 3 files changed, 152 insertions(+), 3 deletions(-) create mode 100644 src/ObjCommon/Game/IW4/MaterialConstantsIW4.h diff --git a/src/Common/Game/IW4/IW4_Assets.h b/src/Common/Game/IW4/IW4_Assets.h index 1f4b2a74..db4a5d8d 100644 --- a/src/Common/Game/IW4/IW4_Assets.h +++ b/src/Common/Game/IW4/IW4_Assets.h @@ -791,6 +791,15 @@ namespace IW4 unsigned int loadBits[2]; }; + struct infoParm_t + { + const char* name; + unsigned int clearSolid; + unsigned int surfaceFlags; + unsigned int contents; + unsigned int toolFlags; + }; + struct gcc_align(8) GfxDrawSurfFields { uint64_t objectId : 16; diff --git a/src/ObjCommon/Game/IW4/MaterialConstantsIW4.h b/src/ObjCommon/Game/IW4/MaterialConstantsIW4.h new file mode 100644 index 00000000..3b808120 --- /dev/null +++ b/src/ObjCommon/Game/IW4/MaterialConstantsIW4.h @@ -0,0 +1,111 @@ +#pragma once + +#include "Game/IW4/IW4.h" + +namespace IW4 +{ + inline infoParm_t infoParms[] + { + {"bark", 0x0, 0x100000, 0x0, 0x0}, + {"brick", 0x0, 0x200000, 0x0, 0x0}, + {"carpet", 0x0, 0x300000, 0x0, 0x0}, + {"cloth", 0x0, 0x400000, 0x0, 0x0}, + {"concrete", 0x0, 0x500000, 0x0, 0x0}, + {"dirt", 0x0, 0x600000, 0x0, 0x0}, + {"flesh", 0x0, 0x700000, 0x0, 0x0}, + {"foliage", 0x1, 0x800000, 0x2, 0x0}, + {"glass", 0x1, 0x900000, 0x10, 0x0}, + {"grass", 0x0, 0xa00000, 0x0, 0x0}, + {"gravel", 0x0, 0xb00000, 0x0, 0x0}, + {"ice", 0x0, 0xc00000, 0x0, 0x0}, + {"metal", 0x0, 0xd00000, 0x0, 0x0}, + {"mud", 0x0, 0xe00000, 0x0, 0x0}, + {"paper", 0x0, 0xf00000, 0x0, 0x0}, + {"plaster", 0x0, 0x1000000, 0x0, 0x0}, + {"rock", 0x0, 0x1100000, 0x0, 0x0}, + {"sand", 0x0, 0x1200000, 0x0, 0x0}, + {"snow", 0x0, 0x1300000, 0x0, 0x0}, + {"water", 0x1, 0x1400000, 0x20, 0x0}, + {"wood", 0x0, 0x1500000, 0x0, 0x0}, + {"asphalt", 0x0, 0x1600000, 0x0, 0x0}, + {"ceramic", 0x0, 0x1700000, 0x0, 0x0}, + {"plastic", 0x0, 0x1800000, 0x0, 0x0}, + {"rubber", 0x0, 0x1900000, 0x0, 0x0}, + {"cushion", 0x0, 0x1a00000, 0x0, 0x0}, + {"fruit", 0x0, 0x1b00000, 0x0, 0x0}, + {"paintedmetal", 0x0, 0x1c00000, 0x0, 0x0}, + {"riotshield", 0x0, 0x1d00000, 0x0, 0x0}, + {"slush", 0x0, 0x1e00000, 0x0, 0x0}, + {"opaqueglass", 0x0, 0x900000, 0x0, 0x0}, + {"clipmissile", 0x1, 0x0, 0x80, 0x0}, + {"ai_nosight", 0x1, 0x0, 0x1000, 0x0}, + {"clipshot", 0x1, 0x0, 0x2000, 0x0}, + {"playerclip", 0x1, 0x0, 0x10000, 0x0}, + {"monsterclip", 0x1, 0x0, 0x20000, 0x0}, + {"aiclipallowdeath", 0x1, 0x0, 0x4, 0x0}, + {"vehicleclip", 0x1, 0x0, 0x200, 0x0}, + {"itemclip", 0x1, 0x0, 0x400, 0x0}, + {"nodrop", 0x1, 0x0, 0x80000000, 0x0}, + {"nonsolid", 0x1, 0x4000, 0x0, 0x0}, + {"detail", 0x0, 0x0, 0x8000000, 0x0}, + {"structural", 0x0, 0x0, 0x10000000, 0x0}, + {"portal", 0x1, 0x80000000, 0x0, 0x0}, + {"canshootclip", 0x0, 0x0, 0x40, 0x0}, + {"origin", 0x1, 0x0, 0x0, 0x4}, + {"sky", 0x0, 0x4, 0x800, 0x0}, + {"nocastshadow", 0x0, 0x40000, 0x0, 0x0}, + {"physicsGeom", 0x0, 0x0, 0x0, 0x400}, + {"lightPortal", 0x0, 0x0, 0x0, 0x2000}, + {"outdoorBounds", 0x0, 0x0, 0x0, 0x8000}, + {"slick", 0x0, 0x2, 0x0, 0x0}, + {"noimpact", 0x0, 0x10, 0x0, 0x0}, + {"nomarks", 0x0, 0x20, 0x0, 0x0}, + {"nopenetrate", 0x0, 0x100, 0x0, 0x0}, + {"ladder", 0x0, 0x8, 0x0, 0x0}, + {"nodamage", 0x0, 0x1, 0x0, 0x0}, + {"mantleOn", 0x0, 0x2000000, 0x1000000, 0x0}, + {"mantleOver", 0x0, 0x4000000, 0x1000000, 0x0}, + {"stairs", 0x0, 0x200, 0x0, 0x0}, + {"soft", 0x0, 0x1000, 0x0, 0x0}, + {"nosteps", 0x0, 0x2000, 0x0, 0x0}, + {"nodraw", 0x0, 0x80, 0x0, 0x0}, + {"nolightmap", 0x0, 0x400, 0x0, 0x0}, + {"nodlight", 0x0, 0x20000, 0x0, 0x0} + }; + + inline const char* surfaceTypeNames[] + { + "default", + "bark", + "brick", + "carpet", + "cloth", + "concrete", + "dirt", + "flesh", + "foliage", + "glass", + "grass", + "gravel", + "ice", + "metal", + "mud", + "paper", + "plaster", + "rock", + "sand", + "snow", + "water", + "wood", + "asphalt", + "ceramic", + "plastic", + "rubber", + "cushion", + "fruit", + "paintedmetal", + "riotshield", + "slush" + }; + static_assert(std::extent_v == SURF_TYPE_NUM); +} diff --git a/src/ObjWriting/Game/IW4/AssetDumpers/AssetDumperMaterial.cpp b/src/ObjWriting/Game/IW4/AssetDumpers/AssetDumperMaterial.cpp index 4eabbba3..7b577c76 100644 --- a/src/ObjWriting/Game/IW4/AssetDumpers/AssetDumperMaterial.cpp +++ b/src/ObjWriting/Game/IW4/AssetDumpers/AssetDumperMaterial.cpp @@ -4,6 +4,7 @@ #include #include +#include "Game/IW4/MaterialConstantsIW4.h" #include "Game/IW4/TechsetConstantsIW4.h" using namespace IW4; @@ -28,7 +29,7 @@ namespace IW4 return json{}; } - json BuildComplexTableJson(complex_s* complexTable, const size_t count) + json BuildComplexTableJson(const complex_s* complexTable, const size_t count) { auto jArray = json::array(); @@ -325,6 +326,34 @@ namespace IW4 return jArray; } + + json BuildSurfaceTypeBitsJson(const unsigned surfaceTypeBits) + { + if (!surfaceTypeBits) + return json(surfaceTypeNames[SURF_TYPE_DEFAULT]); + + static constexpr auto NON_SURFACE_TYPE_BITS = ~(std::numeric_limits::max() >> ((sizeof(unsigned) * 8) - (static_cast(SURF_TYPE_NUM) - 1))); + assert((surfaceTypeBits & NON_SURFACE_TYPE_BITS) == 0); + + std::ostringstream ss; + auto firstSurfaceType = true; + for (auto surfaceTypeIndex = static_cast(SURF_TYPE_BARK); surfaceTypeIndex < SURF_TYPE_NUM; surfaceTypeIndex++) + { + if ((surfaceTypeBits & (1 << (surfaceTypeIndex - 1))) == 0) + continue; + + if (firstSurfaceType) + firstSurfaceType = false; + else + ss << ","; + ss << surfaceTypeNames[surfaceTypeIndex]; + } + + if (firstSurfaceType) + return json(surfaceTypeNames[SURF_TYPE_DEFAULT]); + + return json(ss.str()); + } } bool AssetDumperMaterial::ShouldDump(XAssetInfo* asset) @@ -357,7 +386,7 @@ void AssetDumperMaterial::DumpAsset(AssetDumpingContext& context, XAssetInfoinfo.gameFlags}, + {"gameFlags", material->info.gameFlags}, // TODO: Find out what gameflags mean {"sortKey", material->info.sortKey}, {"textureAtlasRowCount", material->info.textureAtlasRowCount}, {"textureAtlasColumnCount", material->info.textureAtlasColumnCount}, @@ -375,7 +404,7 @@ void AssetDumperMaterial::DumpAsset(AssetDumpingContext& context, XAssetInfo(material->info.drawSurf.fields.primarySortKey)} } }, - {"surfaceTypeBits", material->info.surfaceTypeBits}, + {"surfaceTypeBits", BuildSurfaceTypeBitsJson(material->info.surfaceTypeBits)}, {"hashIndex", material->info.hashIndex} } },