OpenRA / OpenRA/OpenRA

Refactor Shader loading to use the virtual FileSystem abstraction

Open
#22,509 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Refactor
Dominant language
C#
Stars
17.4k
Forks
3k
Avg merge
1d 12h
Merged PRs (30d)
14

Description

Motivation

Current implementation of shader loading in ShaderBindings.cs relies on direct disk access via File.ReadAllText and Path.Combine(Platform.EngineDir, "glsl", filename). This approach bypasses the engine's robust IReadOnlyFileSystem abstraction used everywhere else for maps, mods, and general assets. While not an immediate exploit path due to hardcoded names, this direct access prevents modders from supplying custom shaders within their mod packages and presents a potential path traversal risk if shader names were ever to be sourced dynamically in the future.

Proposed solution

Transitioning ShaderBindings.GetShaderCode to utilize the existing FileSystem service would align the graphics subsystem with the rest of the engine's asset management. After reviewing the current flow, I noticed that we could easily resolve shader code through the virtual filesystem, allowing mods to override or provide new .vert and .frag files. This change would involve injecting or accessing the mod's IReadOnlyFileSystem within the shader binding logic and replacing the manual file reads with a more secure and flexible stream-based approach.

Side effects

Minimal side effects are expected since the shaders are currently loaded during initialization. Performance impact would be negligible given the small size of shader files and the efficiency of the internal package loaders.

Alternatives

One alternative would be to simply add manual sanitization to the existing file path logic. However, I believe that moving towards the standard filesystem abstraction is a much cleaner architectural choice that yields long-term benefits for modding flexibility.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in ShaderBindings.cs at GetShaderCode and trace how shader loading currently uses File.ReadAllText and Path.Combine. Read the existing FileSystem and IReadOnlyFileSystem usage for maps, mods, or assets before deciding how the shader binding receives the filesystem. Done means shader code loads through the virtual filesystem and supports shader files supplied by mod packages without direct disk access.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
computer-graphics, game-dev
Issue type
Refactor
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.