🛡️ Working with Upstream code and minimizing conflicts
This skill describes the standards and patterns adopted in Space Station 14 forks with project-folder isolation (_Sunrise, _Scp, _Fish, _Lust) for working with code inherited from the upstream.
Main goal: Maintain the ability to easily receive updates from the upstream (merge), minimizing manual edits in case of conflicts.
Before making changes, first determine the active codebase prefix, project folder and edit markers using the ss14-codebase-prefix-detection rule.
After the active fork is determined, keep all new fork-owned code in that fork's project folder. Do not switch folders because the touched behavior is vanilla, inherited from another fork, or looks "not fork-specific". For Fire, the correct folder is _Scp; new code, prototypes and assets for Fire go there even when the hook or parent prototype lives in vanilla or in a Sunrise-looking repository mirror.
⚠️ Golden rule
[!IMPORTANT]
Minimizing changes to vanilla files is MORE IMPORTANT than "pretty" architecture.
It's better to leave the "dirty" hack in one line of the vanilla file than to rewrite half the system, creating hell when merging.
📁 Folder structure and Project Folder
To clearly separate vanilla code from our modifications, a special project folder is used, starting with the symbol _ (for example, _Sunrise, _Scp).
Why _?
- The folder is always at the top of the file list and is easy to find.
- Visually separates “our” code from “their” (vanilla) code.
What should I put in _ProjectName?
- New files: Completely new systems, components, prototypes.
- Partial classes: Extensions of vanilla classes (see below).
- Assets: New sprites, sounds, textures.
The selected project folder is a consequence of the active fork, not of the subsystem being touched. If the active fork is Fire, write new project code under _Scp. Do not move new files to _Sunrise just because the repository owner is makura-games, the original code came from Sunrise, or the change is a vanilla hook.
[!TIP]
Isolation principle:
Try to keep 99% of your unique code inside the
_ProjectNamefolder.
Only minimal edits (hooks, events) that connect vanilla code to yours should remain in vanilla folders.
🛠️ Modification of C# code
When modifying existing vanilla code (outside the project folder), use the following patterns.
1. Pattern `Edit Start` / `Edit End`
Used when you need to change existing logic inside a method or property.
Makes it easy to see your changes against the background of vanilla code.
Format:
// SERVERNAME edit start - краткая причина изменений
...your code...
// SERVERNAME edit end
Where SERVERNAME is the project name (for example, Fire, Sunrise).
Example (change value):
component.Field2 = 321;
component.Field = 123; // Fire edit - увеличиваем радиус для баланса
Example (changing logic):
// Sunrise edit start - исправляем двойные шлюзы
if (TryComp<AirlockComponent>(uid, out var airlock))
{
// ...новая логика...
}
// Sunrise edit end
2. Pattern `Added Start` / `Added End`
Used when you add a new block of code (eg calling an event, checking) that was not in the original.
Format:
// SERVERNAME added start - краткая причина добавления
...new code...
// SERVERNAME added end
Example:
_eventBus.RaiseLocalEvent(uid, new ProjectileHitEvent(projectile, entity)); // Fire added - чтобы знать, когда попали по Shy Guy
3. Partial Classes
If you need to add a new field, property or method to an existing class or system, DO NOT write it in a vanilla file.
Instead, create a partial class in your project folder (_Scp, _Sunrise, _Starlight).
Pattern:
- Find the upstream file that owns the behavior being extended.
- Mirror its name:
<UpstreamFile>.cs→<UpstreamFile>.<Fork>.cs;<UpstreamFile>.<Section>.cs→<UpstreamFile>.<Section>.<Fork>.cs.
- Declare the class as
partialwith the same namespace. - Important: Suppress the namespace mismatch warning if necessary.
Example:
Vanilla file (Content.Shared/Scp106/Systems/SharedScp106System.cs):
namespace Content.Shared.Scp106.Systems;
public abstract partial class SharedScp106System : EntitySystem
{
// Ванильный код...
}
Your file (Content.Shared/_Scp/Scp106/Systems/SharedScp106System.Fire.cs):
using Content.Shared.Scp106.Systems; // Используем ванильное пространство имён
// Подавляем предупреждение, так как файл физически находится в другой папке
// ReSharper disable once CheckNamespace
namespace Content.Shared.Scp106.Systems;
public abstract partial class SharedScp106System
{
// Ваша новая логика, доступная «как будто» внутри оригинального класса
public void MyNewMethod() { ... }
}
🧬 Modifying Prototypes (YAML)
Changing vanilla YAML files (Resources/Prototypes/Entities/...) is BAD PRACTICE. This is a guaranteed conflict with any change to this file in the upstream.
🌌 Ideal Prototype Change Pattern
Instead of editing the original, we create a replacement heir.
Algorithm:
- Find the vanilla entity ID (for example,
AirlockHatchSyndicate). - Create a new YAML file in your project folder (for example,
Resources/Prototypes/_Sunrise/.../access.yml). - Create a new entity:
id: Add a suffix or prefix (for example,AirlockHatchSyndicateLocked).parent: Specify a vanilla ID.- Make the necessary changes (add components, change fields).
- Migration Magic: Register the replacement in
Resources/migration.yml.
Implementation example:
1. New prototype (_Sunrise/Entities/Structures/Doors/Airlocks/access.yml):
- type: entity
parent: AirlockHatchSyndicate # Наследуемся от оригинала
id: AirlockHatchSyndicateLocked # Новый ID
suffix: Syndicate, Locked
categories: [ HideSpawnMenu ] # Fire added - скрываем из спавна, если это техническая сущность
components:
- type: AccessReader
access: [["SyndicateAgent"]] # Добавляем необходимые изменения
2. Migration file (Resources/migration.yml):
Add an entry to the end of the file or to the appropriate section.
# ... существующие миграции ...
# Sunrise edit
AirlockHatchSyndicate: AirlockHatchSyndicateLocked
Result:
When loading the map, the engine will automatically replace all AirlockHatchSyndicate with AirlockHatchSyndicateLocked.
When updating the upstream, if new components are added to AirlockHatchSyndicate, your AirlockHatchSyndicateLocked will automatically receive them through inheritance (parent). File conflicts - 0.
[!WARNING]
Migration DOES NOT update links in other prototypes!
The
migration.ymlfile tells the engine to replace the entity ONLY when spawning on the map and in saves.
If the old ID (
AirlockHatchSyndicate) is used in:
- Spawn Pools
- Crafting recipes
- Fields of other components (for example,
SpawnOnDeath)
...the old essence will remain there! You need to find all uses of the old ID and replace them with the new one manually (via the
editpattern or overriding).
🛠️ Minor changes in vanilla files
If migration is not possible (but try to use it!), use edit comments directly in YAML, but try to do it on one line.
- type: entity
id: VanillaEntity
components:
- type: Item
path: _FORKFOLDER/Objects/123.rsi # SERVERNAME edit - замена спрайта
🚫 Anti-patterns (What NOT to do)
❌ Direct code removal.
Instead of deleting, comment out the code and leave the mark edit.
// ПЛОХО:
// public void DeletedMethod() { }
// ХОРОШО:
// SERVERNAME edit start - удалено, потому что мешает механике X
// public void DeletedMethod() { ... }
// SERVERNAME edit end
❌ Rewriting entire files.
If you copy the entire file into your folder and disable the original, you lose all future updates to that file. DO this ONLY if the logic changes fundamentally and irreversibly.
❌ Replacement of entity ID without inheritance.
If you simply copy the YAML of an entity and change it, you will not receive updates to the parent components from upstream. Always use parent.