Skip to content

feat: Raw reading on zone load and scene tools#1910

Open
aronwk-aaron wants to merge 32 commits intomainfrom
raw-parsing-for-scene-data
Open

feat: Raw reading on zone load and scene tools#1910
aronwk-aaron wants to merge 32 commits intomainfrom
raw-parsing-for-scene-data

Conversation

@aronwk-aaron
Copy link
Copy Markdown
Member

@aronwk-aaron aronwk-aaron commented Oct 15, 2025

  • Add guard for chunk.scaleFactor <= 0, chunk.width <= 1, chunk.height <= 1, chunk.colorMapResolution == 0 in GetSceneIDFromPosition to prevent division by zero crashes from malformed raw files
  • Add overflow/OOM protection in Raw.cpp chunk parsing: validate resolutions, use size_t for multiplications, cap all blob sizes to 64 MiB
  • Fix BuildSceneGraph global scene: LWOSCENEID(m_ZoneID.GetMapID(), 0) → LWOSCENEID(0, 0)
  • Add explicit inline guards before sceneMapI/J and sceneI/J computation (chunk.width > 1, chunk.height > 1, chunk.colorMapResolution > 0)
  • Add bounds validation for outRaw.numChunks (kMaxChunks=1024), numFlairs (byte-size cap via kMaxBlobBytes), and chunk.vertSize (byte-size cap via kMaxBlobBytes) before resize() calls
  • Add width/height/scaleFactor guards in SpawnScenePoints command to prevent division by zero on malformed raw data
  • Change SceneColor::Get parameter from unsigned char to uint8_t, add #include
  • Add scaleFactor <= 0, width <= 1, height <= 1 guards in GenerateTerrainMesh to prevent division by zero; fix %u → %zu for size_t log format
  • Run code review
  • Run codeql checker

@aronwk-aaron aronwk-aaron changed the title Feat: Raw reading on zone load and scene tools feat: Raw reading on zone load and scene tools Oct 15, 2025
@aronwk-aaron aronwk-aaron marked this pull request as ready for review October 16, 2025 01:12
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR implements raw terrain file reading on zone load to enable scene identification from player positions. Key changes include parsing .raw terrain files, building a scene adjacency graph from scene transitions, and adding developer commands for scene debugging and visualization.

  • Adds comprehensive RAW terrain file parsing with scene map support
  • Implements scene ID lookup from world positions and scene adjacency graph construction
  • Adds developer commands for scene debugging and visualization with OBJ export capability

Reviewed Changes

Copilot reviewed 23 out of 23 changed files in this pull request and generated 17 comments.

Show a summary per file
File Description
resources/worldconfig.ini Adds config option to export terrain meshes to OBJ files for debugging
dZoneManager/dZoneManager.h Declares scene position lookup, adjacency list access, and scene graph building methods
dZoneManager/dZoneManager.cpp Implements scene position queries, scene graph construction from transitions, and global scene connectivity
dZoneManager/Zone.h Adds Raw terrain data storage and scene lookup methods
dZoneManager/Zone.cpp Implements zone file version checking, Raw file loading, and optional OBJ export
dZoneManager/Raw.h Defines complete terrain chunk structures, scene vertex data, and mesh generation/export functions
dZoneManager/Raw.cpp Implements RAW file parsing, terrain mesh generation with scene IDs, and OBJ export with scene colors
dZoneManager/CMakeLists.txt Adds Raw.cpp to build and includes SceneColor.h path
dNavigation/dTerrain/* Removes old unused terrain parsing code
dNavigation/dNavMesh.cpp Removes unused RawFile.h include
dNavigation/CMakeLists.txt Removes dTerrain subdirectory from build
dGame/dUtilities/SlashCommands/DEVGMCommands.h Declares four new scene debugging commands
dGame/dUtilities/SlashCommands/DEVGMCommands.cpp Implements GetScene, GetAdjacentScenes, SpawnScenePoints, and SpawnAllScenePoints commands
dGame/dUtilities/SlashCommandHandler.cpp Registers the four new scene debugging commands
dCommon/dClient/SceneColor.h Defines color palette for visualizing scene IDs in OBJ exports
dCommon/NiColor.h Adds RGB color structure with grayscale conversion
Comments suppressed due to low confidence (1)

dZoneManager/Raw.cpp:1

  • Potential division by zero in GetSceneIDFromPosition if chunk dimensions are 1. Similar to the issue in GenerateTerrainMesh, if chunk.width or chunk.height equals 1, this will cause division by zero. Add validation before these calculations.
#include "Raw.h"

aronwk-aaron and others added 7 commits March 20, 2026 13:03
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 23 out of 23 changed files in this pull request and generated 7 comments.

Comments suppressed due to low confidence (1)

dZoneManager/dZoneManager.cpp:18

  • This file uses std::clamp, std::min, and std::find but doesn’t include <algorithm> directly. Relying on transitive includes can break builds when include order changes; add the proper standard header and drop unused <cmath> if it’s no longer needed.
#include "WorldConfig.h"
#include "CDZoneTableTable.h"
#include <chrono>
#include <cmath>
#include "eObjectBits.h"
#include "CDZoneTableTable.h"
#include "AssetManager.h"
#include <ranges>

aronwk-aaron and others added 2 commits March 20, 2026 13:19
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
aronwk-aaron and others added 2 commits March 31, 2026 03:35
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…D in BuildSceneGraph

Agent-Logs-Url: https://github.com/DarkflameUniverse/DarkflameServer/sessions/5cf247c9-7028-4f94-9ab9-8dfd8e6101fa

Co-authored-by: aronwk-aaron <26027722+aronwk-aaron@users.noreply.github.com>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 23 out of 23 changed files in this pull request and generated 10 comments.

Comments suppressed due to low confidence (1)

dZoneManager/dZoneManager.cpp:18

  • This file now uses std::clamp/std::min/std::find and std::set, but the includes only add . Please add the required standard headers (at least for clamp/min/find and for std::set) to avoid relying on transitive includes and potential build breaks on other toolchains.
#include "WorldConfig.h"
#include "CDZoneTableTable.h"
#include <chrono>
#include <cmath>
#include "eObjectBits.h"
#include "CDZoneTableTable.h"
#include "AssetManager.h"
#include <ranges>

return; // No scene data available
}

LOG("GenerateTerrainMesh: Processing %u chunks", raw.chunks.size());
Copy link

Copilot AI Mar 31, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LOG uses printf-style formatting. raw.chunks.size() is size_t but is logged with %u here, which is undefined behavior on platforms where size_t isn't 32-bit. Use %zu (preferred) or cast to uint32_t after validating it fits.

Suggested change
LOG("GenerateTerrainMesh: Processing %u chunks", raw.chunks.size());
LOG("GenerateTerrainMesh: Processing %zu chunks", raw.chunks.size());

Copilot uses AI. Check for mistakes.
Comment on lines +20 to +28
struct FlairAttributes {
uint32_t id;
float scaleFactor;
NiPoint3 position;
NiPoint3 rotation;
uint8_t colorR;
uint8_t colorG;
uint8_t colorB;
uint8_t colorA;
Copy link

Copilot AI Mar 31, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These structs introduce many fundamental fields that are not default-initialized (e.g., FlairAttributes::id, MeshTri::meshTriListSize, Chunk::id/width/height/offsetX/offsetZ/shaderId/scaleFactor, Raw::version/dev). This is inconsistent with other structs in this module (which use {} initialization) and can lead to use of indeterminate values if a partial read fails or an instance is constructed before being fully populated. Prefer brace/"=" initialization for all scalar members.

Copilot uses AI. Check for mistakes.
aronwk-aaron and others added 3 commits March 31, 2026 04:44
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
… OOM from malformed raws

Agent-Logs-Url: https://github.com/DarkflameUniverse/DarkflameServer/sessions/39d7ce79-bc9a-4960-8259-f11bcb5947f8

Co-authored-by: aronwk-aaron <26027722+aronwk-aaron@users.noreply.github.com>
…nt division by zero

Agent-Logs-Url: https://github.com/DarkflameUniverse/DarkflameServer/sessions/386caefa-6a0f-4445-b3a5-3534ca2a5a93

Co-authored-by: aronwk-aaron <26027722+aronwk-aaron@users.noreply.github.com>
…%zu format specifier

Agent-Logs-Url: https://github.com/DarkflameUniverse/DarkflameServer/sessions/43d6190e-34b2-4d7f-8aaf-dd16bd77cc25

Co-authored-by: aronwk-aaron <26027722+aronwk-aaron@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants