5.8 KiB
ONI Mod API Reference (Confirmed via DLL Decompile)
Assembly: Assembly-CSharp.dll (D:\steam...\Managed)
BuildingDef (extends Def -> ScriptableObject)
FIELD string PrefabID # FROM BASE CLASS Def
FIELD int WidthInCells
FIELD int HeightInCells
FIELD float EnergyConsumptionWhenActive
FIELD float ExhaustKilowattsWhenActive
FIELD string[] MaterialCategory
FIELD float[] Mass
FIELD string Name # PROPERTY (Name getter)
PROPERTY string Desc, Flavor, Effect
Usage:
def.PrefabID(NOTdef?.PrefabID— fields cannot use null-conditional)
Building (base of BuildingComplete)
FIELD BuildingDef Def
PROPERTY Orientation Orientation
METHOD int GetCell()
METHOD int GetBottomLeftCell()
Usage:
((BuildingComplete)item).Def.PrefabID/building.Def.WidthInCellsIsOperationalis NOT on BuildingComplete — usego.GetComponent<Operational>()?.IsOperationalIsOperationalis a PROPERTY (bool), NOT a method: no()after it
Operational
PROPERTY bool IsOperational # getter
PROPERTY bool IsFunctional
PROPERTY bool IsActive
METHOD void SetFlag(Flag flag, bool value)
METHOD bool GetFlag(Flag flag)
METHOD void SetActive(bool value, bool force_ignore)
Generator
PROPERTY float WattageRating
PROPERTY ushort CircuitID
PROPERTY float JoulesAvailable
PROPERTY float Capacity
PROPERTY bool IsEmpty
NO
IsPoweredproperty. CheckJoulesAvailable > 0instead.
ConduitFlow.ConduitContents (STRUCT — value type!)
STRUCT ConduitContents {
SimHashes element # FIELD
float mass # FIELD
float temperature # FIELD
int diseaseHash
int diseaseCount
}
flow.GetContents(int cell)returnsConduitContents(always valid since it's a struct) Never null-check with!= null— usecontents.mass > 0instead
CircuitManager
METHOD ushort GetCircuitID(int cell)
METHOD float GetWattsUsedByCircuit(ushort circuitID)
METHOD float GetWattsGeneratedByCircuit(ushort circuitID)
METHOD float GetMaxSafeWattageForCircuit(ushort circuitID)
METHOD List<Generator> GetGeneratorsOnCircuit(ushort circuitID)
METHOD List<IEnergyConsumer> GetConsumersOnCircuit(ushort circuitID)
METHOD List<Battery> GetBatteriesOnCircuit(ushort circuitID)
NO
GetCircuits()method. Discover circuit IDs viaGetCircuitID(cell)for each building.
SaveLoader
PROPERTY static SaveLoader Instance # getter
METHOD string Save(string filename, bool isAutoSave, bool updateSavePointer)
METHOD bool Load(string filename)
METHOD string GetActiveSaveFilePath()
All are INSTANCE methods. Usage:
SaveLoader.Instance.Save(...)
Techs (ResourceSet)
METHOD Tech TryGetTechForTechItem(string itemId)
To enumerate: use the base class
ResourceSet<T>which hasresources/ implements IEnumerableDb.Get().Techsreturns the Techs collection. Iterate viaforeach (var tech in Db.Get().Techs.resources)or check if Techs implements IEnumerable directly
World
PROPERTY static World Instance
NO
worldNameproperty. Fallback: Use a hardcoded string like "ONI World"
Components quirks
Cmps<T>implementsIEnumerable(non-generic) → foreach givesobject, cast explicitlyCmpsByWorld<T>does NOT implement IEnumerable → CANNOT foreach. Access items through its internal API- Workaround: skip
Components.Geysersor use reflection to access items
- Workaround: skip
Components.CreatureIdentitiesNOT FOUND → useComponents.BrainsinsteadComponents.CropsgivesCropobjects → access.gameObjectnot cast to GameObject
Missing types in this ONI version
→ NOT FOUND, wrap in try-catchImmuneSystemMonitor→ NOT FOUND, useGlobalNotificationManagerNotifierif available→ NOT FOUNDAlertManager→ NOT FOUNDPriorityScreen.Instance→ NOT FOUNDAttributeLevels→ NOT FOUNDGameTags.RawPoultry/PreciousStone→ NOT FOUNDMoraleProvider/QualityOfLife/HappyMonitor
Grid (Stable — confirmed working)
STATIC Element[] Element # grid[cell]
STATIC float[] Mass
STATIC float[] Temperature
STATIC bool[] Solid
STATIC bool[] IsVisible
STATIC GameObject[,] Objects # [cell, ObjectLayer enum]
STATIC int XYToCell(int x, int y)
STATIC void CellToXY(int cell, out int x, out int y)
STATIC int CellCount (field)
STATIC int WidthInCells
STATIC int HeightInCells
ObjectLayer (enum values include)
- Building, Pickupables, Minion, Plants, Creatures, etc.
- NO
Creaturevalue → check the actual enum
Health
PROPERTY float hitPoints # NOT a method
PROPERTY float maxHitPoints
METHOD bool IsIncapacitated()
METHOD void Damage(float amount)
Verified correct patterns
// Buildings
foreach (var item in Components.BuildingCompletes) {
var b = (BuildingComplete)item;
var go = b.gameObject;
var def = b.Def; // FIELD on Building base
string id = def.PrefabID; // FIELD on Def base
int w = def.WidthInCells;
bool op = go.GetComponent<Operational>()?.IsOperational ?? false;
}
// Pipes (ConduitContents is struct!)
var contents = flow.GetContents(cell);
if (contents.mass > 0) { ... }
// Power
ushort cid = mgr.GetCircuitID(cell);
float used = mgr.GetWattsUsedByCircuit(cid);
// Save/Load
SaveLoader.Instance.Save("name", true, false);
SaveLoader.Instance.Load("path");
// Pause
SpeedControlScreen.Instance.Pause(false, true);
SpeedControlScreen.Instance.Unpause(true);
bool paused = SpeedControlScreen.Instance.IsPaused;
int speed = SpeedControlScreen.Instance.GetSpeed();
SpeedControlScreen.Instance.SetSpeed(3);
// Camera
CameraController.Instance.SnapTo(new Vector3(x, y, z));
// Duplicants
foreach (var item in Components.MinionIdentities) {
var m = (MinionIdentity)item;
string name = m.GetProperName();
var go = m.gameObject;
}