From 0b1f28bdaef2efd482268bfad14d0942b08cdfac Mon Sep 17 00:00:00 2001 From: TheApadayo Date: Mon, 27 Mar 2017 21:25:58 -0400 Subject: [PATCH] [IGfxWorld] More work, some possible fixes --- .../Modules/AssetInterfaces/IGfxWorld.cpp | 16 +--- src/Components/Modules/QuickPatch.cpp | 93 ++++++++++++++++++- src/Game/Functions.cpp | 37 ++++++++ src/Game/Functions.hpp | 2 + 4 files changed, 132 insertions(+), 16 deletions(-) diff --git a/src/Components/Modules/AssetInterfaces/IGfxWorld.cpp b/src/Components/Modules/AssetInterfaces/IGfxWorld.cpp index 881de499..a7ec9f7f 100644 --- a/src/Components/Modules/AssetInterfaces/IGfxWorld.cpp +++ b/src/Components/Modules/AssetInterfaces/IGfxWorld.cpp @@ -18,8 +18,6 @@ namespace Assets asset->smodelInsts = reader->readArray(asset->smodelCount); } - std::vector surfs; - if (asset->surfaces) { asset->surfaces = reader->readArray(world->surfaceCount); @@ -27,7 +25,6 @@ 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) { @@ -434,17 +431,6 @@ namespace Assets { asset->heroOnlyLights = reader.readArray(asset->heroOnlyLightCount); } - - // We need to temporarily allocate a runtime buffer - // It's not accessed during the building process, - // but as we're interacting with the runtime, we have to - // allocate a valid buffer for the time we're using it. - if (asset->dpvs.surfaceMaterials) - { - asset->dpvs.surfaceMaterials = builder->getAllocator()->allocateArray(asset->surfaceCount); - } - - Game::SortWorldSurfaces(asset); } } @@ -1174,7 +1160,7 @@ namespace Assets this->saveGfxLightGrid(&asset->lightGrid, &dest->lightGrid, builder); if (asset->models) - { + { AssertSize(Game::GfxBrushModel, 60); SaveLogEnter("GfxBrushModel"); diff --git a/src/Components/Modules/QuickPatch.cpp b/src/Components/Modules/QuickPatch.cpp index d3d042f1..8cf269a8 100644 --- a/src/Components/Modules/QuickPatch.cpp +++ b/src/Components/Modules/QuickPatch.cpp @@ -597,7 +597,6 @@ namespace Components } - if (pass->argumentDef) { buffer->align(Utils::Stream::ALIGN_4); @@ -645,6 +644,98 @@ namespace Components } }); + static Game::GfxWorld* storedWorld = nullptr; + + AssetHandler::OnLoad([](Game::XAssetType type, Game::XAssetHeader asset, std::string name, bool* /*restrict*/) + { + if (type == Game::XAssetType::ASSET_TYPE_GFXWORLD) + { + Game::GfxWorld* world = asset.gfxWorld; + Utils::Stream* buffer = new Utils::Stream(0x1000); + for (unsigned int i = 0; i < world->dpvs.staticSurfaceCount; ++i) + { + buffer->saveString(Utils::String::VA("%s\n", world->dpvs.surfaces[world->dpvs.sortedSurfIndex[i]].material->name)); + } + Utils::IO::WriteFile("userraw/logs/matlog.txt", buffer->toBuffer()); + + storedWorld = asset.gfxWorld; + } + }); + + Dvar::OnInit([]() + { + Dvar::Register("r_drawAabbTrees", false, Game::DVAR_FLAG_USERCREATED, "draw aabb trees"); + }); + + Renderer::OnFrame([]() + { + if (!Game::CL_IsCgameInitialized() || !Dvar::Var("r_drawAabbTrees").get()) return; + + float cyan[4] = { 0.0f, 0.5f, 0.5f, 1.0f }; + + Game::GfxWorld** gameWorld = reinterpret_cast(0x66DEE94); + + for (int i = 0; i < (*gameWorld)->dpvsPlanes.cellCount; ++i) + { + for (int j = 0; j < (*gameWorld)->aabbTreeCounts[i].aabbTreeCount; ++j) + { + Game::vec3_t v1, v2, v3, v4, v5, v6, v7, v8; + float* center = (*gameWorld)->aabbTrees[i].aabbTree[j].bounds.midPoint; + float* halfSize = (*gameWorld)->aabbTrees[i].aabbTree[j].bounds.halfSize; + v1[0] = center[0] - halfSize[0]; + v1[1] = center[1] - halfSize[1]; + v1[2] = center[2] - halfSize[2]; + + v2[0] = center[0] + halfSize[0]; + v2[1] = center[1] - halfSize[1]; + v2[2] = center[2] - halfSize[2]; + + v3[0] = center[0] - halfSize[0]; + v3[1] = center[1] + halfSize[1]; + v3[2] = center[2] - halfSize[2]; + + v4[0] = center[0] + halfSize[0]; + v4[1] = center[1] + halfSize[1]; + v4[2] = center[2] - halfSize[2]; + + v5[0] = center[0] - halfSize[0]; + v5[1] = center[1] - halfSize[1]; + v5[2] = center[2] + halfSize[2]; + + v6[0] = center[0] + halfSize[0]; + v6[1] = center[1] - halfSize[1]; + v6[2] = center[2] + halfSize[2]; + + v7[0] = center[0] - halfSize[0]; + v7[1] = center[1] + halfSize[1]; + v7[2] = center[2] + halfSize[2]; + + v8[0] = center[0] + halfSize[0]; + v8[1] = center[1] + halfSize[1]; + v8[2] = center[2] + halfSize[2]; + + // bottom + Game::R_AddDebugLine(cyan, v1, v2); + Game::R_AddDebugLine(cyan, v2, v4); + Game::R_AddDebugLine(cyan, v4, v3); + Game::R_AddDebugLine(cyan, v3, v1); + + // top + Game::R_AddDebugLine(cyan, v5, v6); + Game::R_AddDebugLine(cyan, v6, v8); + Game::R_AddDebugLine(cyan, v8, v7); + Game::R_AddDebugLine(cyan, v7, v5); + + // verticals + Game::R_AddDebugLine(cyan, v1, v5); + Game::R_AddDebugLine(cyan, v2, v6); + Game::R_AddDebugLine(cyan, v3, v7); + Game::R_AddDebugLine(cyan, v4, v8); + } + } + }); + + // Dvars Dvar::Register("ui_streamFriendly", false, Game::DVAR_FLAG_SAVED, "Stream friendly UI"); diff --git a/src/Game/Functions.cpp b/src/Game/Functions.cpp index e22d5417..09d06bf0 100644 --- a/src/Game/Functions.cpp +++ b/src/Game/Functions.cpp @@ -754,4 +754,41 @@ namespace Game *specular1 = saveSpecular1; *specular2 = saveSpecular2; } + + void R_AddDebugLine(float* color, float* v1, float* v2) + { + void* debugglobals = reinterpret_cast (Utils::Hook::Get(0x66DAD78) + 268772); + void* func = reinterpret_cast (0x51CEB0); + __asm + { + mov eax, v2 + push eax + mov eax, v1 + push eax + mov esi, debugglobals + mov edi, color + call func + add esp, 8 + } + } + + void R_AddDebugString(float *color, float *pos, float scale, char *string) + { + void* debugglobals = reinterpret_cast (Utils::Hook::Get(0x66DAD78) + 268772); + void* func = reinterpret_cast (0x51D0A0); + __asm + { + mov eax, string + push eax + mov eax, scale + push eax + mov eax, color + push eax + mov eax, pos + push eax + mov edi, debugglobals + call func + add esp, 16 + } + } } diff --git a/src/Game/Functions.hpp b/src/Game/Functions.hpp index a7b86e4f..a2b03a76 100644 --- a/src/Game/Functions.hpp +++ b/src/Game/Functions.hpp @@ -772,4 +772,6 @@ namespace Game int CL_GetMaxXP(); void SortWorldSurfaces(GfxWorld* world); + void R_AddDebugLine(float* color, float* v1, float* v2); + void R_AddDebugString(float *color, float *pos, float scale, char *str); }