Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

oni-save-parser

RoboPhred128MIT14.0.1TypeScript support: included

Parser for Oxygen Not Included save files.

ONI, Oxygen Not Included, save editor

readme

oni-save-parser

This library parses and writes save data from Oxygen Not Included. It is intended for both nodejs and web environments (through webpack or rollup).

This is a utility library for editing saves. If you are looking for a way to edit your save files, you can do so using Duplicity.

Game Compatibility

This library currently supports the Automation Innovation Update (save version 7.17).

This library intends to parse the most recent version of the save file as tracked by the stable (non-test) version of the game. Old versions will not be supported, and changes in test branches will not be integrated until the feature makes its way to the public stable version.

API

  • parseOniSave(ArrayBuffer): SaveGame Parses an ArrayBuffer of data into a save game object.

  • writeOniSave(SaveGame): ArrayBuffer Writes a save game object into an array buffer.

Typedefs

Typescript typedefs are included in this package, ready for use by typescript or any IDE that supports them.

Design Philosophy

Idempotent load-save cycle

This library intends to provide an idempotent load/save cycle: A save file that is loaded then written should generate a new file with identical content to the original. While the resulting file may differ due to implementation differences in the zlib compression library, the uncompressed content should be identical.

Due to this, the api uses arrays of key-value tuples rather than objects or Maps. This is required to guarantee the ordering of the elements remains the same.

The intent is to ensure as little data changes in the save as possible, to guard against potential cases where the ONI code makes assumptions or contains bugs regarding the ordering of data in data structures that might otherwise seem unordered.

A practical upshot of this is that the guaranteed order allows us to efficiently test the parser by round-trip loading and saving a file. By recording each parse instruction used when loading a file, we can ensure we receive the same write-equivalent instructions on saving. Any differences detected indicates that either the load or save operation is treating data differently than its counterpart, indicating a logic error. This check is made possible by the trampoline parser. See below for more information.

Instruction-based 'trampoline' parser

Parsing and unparsing is done through functions that generate and yield instructions to a top level parser. This buys us several advantages:

  • Ability to pause / delay / cancel / 'coroutine' the parse operation for environments that do not have threads.
  • Ability to replace the parser with a test implementation to ensure the expected operations are being performed.
  • Ability to inspect the parse progress, for use with progress reporting.
  • Ability to include extranious information such as the current parse target, for use with progress reporting and error handling.

Example usage

const { readFileSync } = require("fs");
const {
    parseSaveGame,
    writeSaveGame,
    AIAttributeLevelsBehavior
} = require("oni-save-parser");

function loadFile(fileName) {
  const fileData = readFileSync(`./test-data/${fileName}.sav`);
  return parseSaveGame(fileData.buffer);
}

function saveFile(fileName, save) {
  const fileData = writeSaveGame(save);
  writeFileSync(`./test-data/${fileName}.sav`, new Uint8Array(fileData));
}

const saveData = loadFile(fileName);

// Make all duplicants half-sized
const minions = saveData.gameObjects.find(x => x.name === "Minion")!;
for (const minion of minions.gameObjects) {
  minion.scale.x = 0.5;
  minion.scale.y = 0.5;
}

// Modify attributes of all duplicants
for (const minion of minions.gameObjects) {
  const skillBehavior = getBehavior(minion, AIAttributeLevelsBehavior);
  // Set each attribute to 10
  for (const attribute of skillBehavior.templateData.saveLoadLevels) {
    attribute.level = 10
  }
}

saveFile(`${fileName}-tweaked`, saveData);

Current Progress

Data can be loaded by parseOniSave(source: ArrayBuffer), and the data written out using writeOniSave(save: OniSave): ArrayBuffer. Brand new saves cannot be created, as the world data format is not understood. This data is preserved as-is when a save is parsed then re-written.

The save file and all templated data objects are loaded. This includes most of the interesting stuff, like duplicant stats, building attributes, and so on. Some information is still not parsed, such as the general world map and some specific data for a few of the more esoteric game objects.

changelog

14.0.0

  • Bump version lack to 7.31

13.0.2

  • Fix "no dlc" dlc marker.

13.0.1

  • Update types for dlc marker on header.

13.0.0

  • Bump version lock to 7.25 (Breath of Fresh Air update)
  • Export ParseError
  • Inherit error codes on ParseError
  • Fix save version lock bypass not functioning.

12.0.0

  • Bump version lock (dlc) to 7.23

11.1.0

  • Allow version 7.17 (non-dlc)

11.0.0

  • Bump version lock to 7.22

10.0.0

  • Bump version lock to 7.17
  • Handle new sim data section in save file.

9.0.0

  • Bump version lock to 7.16 for AP
  • Allow option to bypass version check.

8.1.2

  • Fix mistyped SpaceDestination.id.

8.1.1

  • Update SimHashes
  • Update SpacecraftManager types.
  • Greatly loosened strictness of .NET identifier validation. This should improve compatibility with mods, especially non-english ones.

8.1.0

  • Update traits for RP.

8.0.0

  • Bump version lock to 7.15 for RP.

7.2.0

  • Add Allergies and Archaeologist traits.

7.1.0

  • Update for save version 7.12

7.0.3

  • Add assignableProxy to MinionIdentity
  • Add various data structure default value helpers.

7.0.2

  • Fix parse validator throwing errors on generic fields.

7.0.1

  • Add salt water geyser to geyser names list.

7.0.0

  • Bump version lock to 7.11 for LU.

6.0.3

  • Return json-safe values for int64/uint64

6.0.2

  • Provide MinionSkillNames constant.

6.0.1

  • Update MinionResume for QOL3.

6.0.0

  • Fix parsing 7.8. Requires backwards-incompatible change; no longer able to parse 7.7 and below.

5.2.1

  • Enable loading versions 7.6 to 7.8.

5.2.0

  • Add typings for gameData.customGameSettings
  • Add SpacecraftManagerBehavior

5.1.5

  • Sync sim hashes with game for space update.

5.1.4

  • Add missing Foodie and SimpleTastes traits. Remove non-traits Caring and MedicalAid from traits list.

5.1.3

  • Fix crash in accessory utilities when encountering game-generated null guid.

5.1.2

  • Bump save file version to match rocketry update. No parser changes

5.1.1

  • Update header version check to match official release of Expressive Update.

5.1.0

  • Compatibility with Expressive Update.

5.0.0

  • Make ACCESSORY consts be CamelCase consistent with other consts.
  • Rename MinionRole to MinionRoleGroup to reflect its actual contents.
  • Fix incorrect HashedString hashes due to case sensitivity.

4.2.3

  • Fix crash on save from MinionModifierBehavior.

4.2.2

  • Fix MinionModifierBehavior types. Again.

4.2.1

  • Fix MinionModifierBehavior types.

4.2.0

  • Fix MinionModifiers not exported.
  • Add ACCESSORIES_BY_TYPE.

4.1.0

  • Basic progress reporting (game object start only).
  • Restore MinionModifiers.

4.0.0

  • Rework accessory type code to handle non-ordinal and prefix-clashing accessory names. -- prefix clash: "hair" vs "hair_always" -- non-ordinal: "hair_always_DEFAULT"

3.2.1

  • Fix AccessoryType.

3.2.0

  • Add missing accessory slots.
  • Added map tying minion identity bodyData slots to accessories.

3.1.1

  • Fix PrimaryElementBehavior interface name.

3.1.0

  • Add missing templateData typings to StorageBehavior.

3.0.1

  • Export StorageBehavior.

3.0.0

  • Include hard-coded enumeration and other constant data. -- SimHashes -- GeyserType -- HealthState

2.2.1

  • Fix getBehavior not exported.

2.2.0

  • Added support for parsing extra data of Storage behavior. Enables modifying the stored contents of all game objects that store items. This includes storage compactors, hydrogen and coal generators, and various other internal buffers used by buildings and creatures.
  • Export TypeTemplate and related typings
  • Export known GameObject types