mirror of
https://github.com/Facepunch/sbox-public.git
synced 2026-04-27 01:39:03 -04:00
### Problem
NavMesh baking needed to store raw binary data in external files (`.navdata`) that should be tracked and packaged, but aren't native compiled resources.
### Solution
Reused the existing `RegisterAdditionalRelatedFile_Game` native infrastructure to track raw files similar to how `RegisterAdditionalRelatedFile_Content` is used to track content sources (.fbx, .tga...). `RegisterAdditionalRelatedFile_Game` was not used anywhere in the codebase, so it's safe to repurpose. This avoids changing the asset file format.
### Changes
**C# Asset System:**
- Split `GetAdditionalRelatedFiles()` into:
- `GetAdditionalContentFiles()` - content-side files (.fbx, .lxo, .rect, etc.) filtered by `ASSET_LOCATION_CONTENT`
- `GetAdditionalGameFiles()` - game-side data files (.navdata, etc.) filtered by `ASSET_LOCATION_GAME`
**Resource Compilation:**
- Added `FileReference` struct for JSON serialization with `{ "$reference_type: "filereference", "path": "..." }` pattern
- Added `AddGameFileReference()` to `ResourceCompileContext` which calls `RegisterAdditionalRelatedFile_Game()`
**Packaging:**
- `PackageManifest` now additionally collects game/rawfiles files for publishing (content files are still only included when publishing source)
Class Attributes: [Handles:Sandbox.ManagedTypeName] Set a class to use a handle system. A good example here is Sandbox.PhysicsBody. On creation we call a managed function to get a handle (an int) and we store that in the IPhysicsBody in native. Any time we pass a IPhysicsBody from native to managed, we pass the int and look up the real object. In the constructor of the physics object in native we call into native to destroy the handle. Which ensures that the pointer is cleared and can't try to be used.