Introduction
Source 2 mods ship as VPK packs with compiled sources. A VPK hides what it edits. Two VPKs that replace one file clash, and the last load wins. A VPK holds full files, so it also hides later Valve edits to those files. After such a game update, the author must reissue the pack by hand.
A DiffMod holds plain diffs over decompiled sources. A diff shows what it edits. Builders merge DiffMods at build time and flag clashes with text conflicts. A DiffMod often still applies after a game update, since a rebuild runs it past fresh sources. If it fails, the diff marks the exact spot that needs care.
Most mods still ship as VPKs. A companion is a DiffMod that ships next to a VPK. Users with no builder load the VPK as it is. Builders use the companion to merge clashes and to repair stale files.
Terms
- A target is a cleartext path that a DiffMod changes.
- A builder is a tool that applies DiffMods and packs the result into a VPK. A mod manager that reads DiffMods is a builder.
- A mod VPK is a VPK that a mod ships.
- A mod VPK replaces a game file if it holds a file at the same path.
- A companion is a DiffMod that ships next to one mod VPK, see rule 12.
- A plain DiffMod is a DiffMod that is not a companion.
- A plain VPK is a mod VPK with no companion.
- The game copy of a target is the file from the game VPKs.
- A VPK copy of a target is the file from a mod VPK.
Specification
The key words "MUST" and "MUST NOT" mark strict rules. An imperative sentence in a numbered rule is also strict. The key word "RECOMMENDED" marks advice that a builder or an author can skip for a good reason.
- A DiffMod is a UTF-8 text file with LF line ends.
- Keep one DiffMod per file.
- The header holds zero or more lines at the top of the file. Each header line starts with
#. The header ends at the first line that starts without#. - A key line has the form
# <key>: <value>. Trim the spaces around the key and the value. The keys arespec,title, anddecompiler. Each key appears at most once. If one of those keys repeats, builders read the first line. Builders ignore unknown#lines. Builders treat them as comments. Compound values use thename/versionform. All header keys are optional. - The
speckey holds the spec name and version, for examplespec: diffmod/v1. A file without aspeckey defaults todiffmod/v1. If you add a header, placespecfirst. - The
titlekey holds a short human name. Thedecompilerkey is RECOMMENDED and holds a registry id plus a version, for examplesource2viewer-cli/20.1. Take ids from the registry. - The body is a unified diff. Use
diff -uform with---and+++lines. The body MUST apply clean withgit apply -p1to the decompiled game files that the author used. - Paths MUST use
a/andb/prefixes. Paths MUST stay relative to the VPK root. New files MUST use--- /dev/nullplus+++ b/<path>. Version 1 forbids renames. Version 1 forbids deletes. Use LF line ends in hunks. - Each target path MUST map to a compiled path through the game profile. Each profile lists its own map. The next table shows the Deadlock map. Files with a raw suffix such as
.cfgpass through with no compile step. If no map row fits a target, fail the build. Name the suffix in the error.Cleartext suffix Compiled suffix .css.vcss_c.xml.vxml_c.js.vjs_c - Decompile each target that the game VPKs hold. Apply DiffMods in the order the user gives. If a plain DiffMod does not apply after the earlier ones, fail the build. Name the DiffMod and the target in the error. Compile each result with the compiler that the game profile names. Pack compiled outputs plus raw files into one VPK.
- Each build MUST give a build record to the user. The record holds the game build id that the game profile defines. The record holds the decompiler id and version. The record holds the spec version. Show the record after each build, also after a failed build. Let the user copy the record into a bug report. Builders MUST NOT need the
decompilerkey to build. Warn on decompiler mismatch is RECOMMENDED. Fail on decompiler mismatch is allowed but not RECOMMENDED.
Companions
- A companion ships next to one mod VPK. The VPK holds the full mod and loads with no build. The companion holds the diffs for the game files that the VPK replaces. The companion file name MUST be the VPK file name plus
.patch. For example,pak50_dir.vpk.patchis the companion ofpak50_dir.vpk. The VPK MUST be a VPK that the mod ships, not a game VPK. Keep the companion in the same folder as its VPK. A file whose name ends in.vpk.patchis a companion. A plain DiffMod name MUST NOT end in.vpk.patch. To find its VPK, remove.patchfrom the name. For a pack with chunk files, use the name of the_dir.vpkfile. Each VPK has at most one companion. A mod with variants pairs each variant VPK with its own companion. A builder that renames a VPK MUST rename its companion to match. - A companion MUST cover each game file that its VPK replaces, if the profile lists the suffix. The body MUST reverse apply clean to the decompiled VPK copies with
git apply -R -p1. A companion MUST NOT add new files. New files stay in the VPK. Files with other suffixes stay outside the companion. For those files, the last load wins. - Builders MUST NOT apply a companion without its VPK. If the VPK is absent, skip the companion. Warn, and name the absent VPK.
- A companion pair needs no build by default. Load its VPK as it is. Rebuild a target only for a clash, see rule 16, or for a stale copy, see rule 19.
- A plain DiffMod changes each target in its body. A mod VPK changes each target whose game file it replaces. Two mods clash on a target if both change it. If mods clash on a target, rebuild that target.
- To rebuild a target, take the game copy as the base and decompile it. Apply each DiffMod that covers the target, in the order the user gives. If a companion does not apply, leave it out of that target. Warn, and name the mod and the target. Compile the result, and pack it into the one VPK from rule 10. That VPK MUST take priority over each mod VPK. New files still load from the mod VPKs.
- A plain VPK copy has no diff. If a plain VPK replaces the target, use its decompiled copy as the base in place of the game copy. If two plain VPKs replace the target, use the copy that the game loads, and warn. A VPK copy that its companion does not cover counts as a plain VPK copy.
- Check each companion pair on install and after each game update. Decompile each VPK copy that the companion covers. Reverse apply the companion to those copies. If the reverse apply fails, the pair does not match. Warn, and treat its VPK as a plain VPK. If it succeeds, the result is the base that the author used. Compare that base with the game copy. If they differ, the VPK copy is stale and hides Valve edits. Offer a rebuild of that target, and let the user decide. This check and this offer are RECOMMENDED.
Scope and versions
- Spec version 1 covers Deadlock. The core stays game neutral. New titles need a profile and a build test. Send profiles as spec pull requests.
- Spec versions use plain integers with a v prefix: v1, v2, v3. Builders warn on unknown spec versions and proceed. A new integer marks a break in form or build acts. Freeze each released version. Never edit a frozen version. If you fix a typo, add an erratum in the changelog.
Advisory
This section is advisory, not strict.
Keep hunks small. Small hunks survive game updates. Large ones clash. Prefer style edits over layout edits. Style rules clash less than moved panels. Put new panels, styles, and scripts in new files. Hook them in with small hunks, such as one include line. Place new files under a folder named after the mod.
A plain DiffMod needs a builder on the user machine. A VPK with a companion loads with no builder. Pick the form that fits your users. Never ship a VPK that replaces game files with no companion. Full game files hide Valve edits. Never ship a game file that you did not change. Make the companion with a tool, not by hand. Decompile the game copy and the VPK copy with one decompiler, then diff them. Set the decompiler key in each companion. If a game update edits a file that your VPK replaces, reissue the VPK and the companion.
Name titles plainly. The title key serves mod lists and managers. Name stored DiffMods with the .patch suffix. Keep three lines of context.
Example
A header looks like this:
# spec: diffmod/v1
# decompiler: source2viewer-cli/20.1
# title: Always show ability suggestions
A companion looks like this. Its file name is pak50_dir.vpk.patch, and it sits next to pak50_dir.vpk. The VPK ships compact_hud/main.css as a new file. The companion holds only the hook. Paths are illustrative.
# spec: diffmod/v1
# decompiler: source2viewer-cli/20.1
# title: Compact HUD
--- a/panorama/layout/hud.xml
+++ b/panorama/layout/hud.xml
@@ -2,6 +2,7 @@
<styles>
<include src="s2r://panorama/styles/hud.vcss_c" />
<include src="s2r://panorama/styles/hud_common.vcss_c" />
+ <include src="s2r://panorama/styles/compact_hud/main.vcss_c" />
</styles>
<scripts>
<include src="s2r://panorama/scripts/hud.vjs_c" />
Profiles
Each game needs a profile. The Deadlock profile is reference. Version 1 has no more profiles.
- Deadlock profile (reference)
A new profile needs VPK paths, a suffix map, and a green build test.
Decompilers
Each decompiler has a short id. The id maps to one tool and one release line. Same id plus same version MUST give byte-identical cleartext for same VPK input.
| id | tool | home |
|---|---|---|
source2viewer-cli | Source2Viewer-CLI | ValveResourceFormat/ValveResourceFormat |
Take the version from the upstream release tag, for example 20.1. Quote the tag verbatim. Source2Viewer-CLI reads all Source 2 games. The game list lives at s2v.app.
Send a pull request that adds one row. Take the first free slug. Never reuse a dead id. Add a SPEC-CHANGELOG.md line. Builders MUST NOT fail a build on an unknown id. Log a warning.
FAQ
Why diffs and not full files?
Full files hide Valve edits and clash on each shared file. Diffs show edits and merge.
Does one DiffMod cover many files?
Yes. One DiffMod holds edits to any count of targets.
What if a DiffMod fails to apply?
Re-derive it from fresh sources. The old diff shows the prior intent.
Why the .patch suffix?
Diff tools and builders read it with no extra setup.
Why ship a VPK and a companion?
Users with no builder drop in the VPK and play. Builders read the companion to merge clashes and to find stale files. Authors keep one release flow.
Do builders use the companion on each load?
No. A builder rebuilds a file only if two mods change it, or if the user accepts a repair.
What if two companions do not merge?
The builder leaves the later one out of that file and warns. Change the mod order to keep the other one.
How does a builder find a stale file?
It reverse applies the companion to the VPK copy. The result is the game file that the author used. If the current game file differs, the VPK copy is stale.
Does each game update make a VPK stale?
No. A VPK copy is stale only if Valve edited that same file.
Why does a companion need its VPK?
The diffs hook in new files that only the VPK holds. A build without the VPK points at absent files.
Why does the file name pair a companion with its VPK?
The name shows that the file is a companion, and it shows which VPK it belongs to. A builder that renames the VPK renames the companion too, so the pair stays correct. A mod with variants ships one companion next to each variant VPK.
Why may a companion not add new files?
The VPK already ships them. A second copy can drift from the first.
What about CS2 or Dota 2?
Version 1 covers Deadlock alone. The core fits more titles with Panorama sources in VPKs. Each new title needs a profile and a build test.
Why pin the decompiler?
Decompile output shifts with the decompiler release. A pinned version keeps builds repeatable. It also keeps the companion check exact.
How do new decompiler names get issued?
Send a pull request that adds one registry row. Take the first free slug. The id maps to one tool and one release line.
Does a new decompiler need a new spec version?
No. New rows extend the registry, not the form. Old files still validate, so the version stays.
Does a new file type need a new spec version?
No. New suffixes extend the profile, not the form. Prove a full round trip first: decompile, edit, compile, load. Send the map row as a profile pull request.
Do builders enforce the header?
Builders read what they need and skip the rest. Warn on unknown spec versions and proceed. Warn on decompiler mismatch is RECOMMENDED.