Files
oniagent/scripts/annotate_apis.py
2026-05-30 11:00:36 +08:00

143 lines
6.7 KiB
Python

#!/usr/bin/env python3
"""
DEPRECATED: Annotate uncertain C# APIs in the Mod source with verification markers.
This script was used during the initial prototyping phase. The mod has since been
rewritten to use confirmed API signatures from the actual ONI DLL. Running this
script on the current source will add irrelevant annotations.
"""
import re
with open('mod/ONIAgentBridge.cs', 'r') as f:
content = f.read()
lines = content.split('\n')
annotations = {}
# Track by line number (1-indexed)
for i, line in enumerate(lines, 1):
s = line.strip()
# Skip comments and using directives
if s.startswith('//') or s.startswith('/*') or s.startswith('using ') or s.startswith('#') or s.startswith('*'):
continue
# === SpeedControlScreen ===
if 'SpeedControlScreen.Instance' in s and ('Pause(' in s or 'Unpause(' in s or 'SetSpeed(' in s):
annotations[i] = '🔶 UNVERIFIED: Pause/Unpause/SetSpeed method signatures on SpeedControlScreen'
# === Circuit Manager ===
if 'circuitManager' in s:
annotations[i] = '🔶 UNVERIFIED: Game.Instance.circuitManager — may be electricalManager'
if 'mgr.GetCircuits()' in s:
annotations[i] = '🔶 UNVERIFIED: circuitManager.GetCircuits() method may not exist'
if 'circuit.WattsUsed' in s or 'circuit.WattsGenerated' in s or 'circuit.MaxWatts' in s:
annotations[i] = '🔶 UNVERIFIED: Circuit property names may differ'
if 'gen.WattageRating' in s or 'gen.CircuitID' in s:
annotations[i] = '🔶 UNVERIFIED: Generator property names may differ'
# === Pipes ===
if 'Game.Instance?.liquidConduitFlow' in s:
annotations[i] = '🔶 UNVERIFIED: Game.Instance.liquidConduitFlow — may be different conduit system'
if 'Game.Instance?.gasConduitFlow' in s:
annotations[i] = '🔶 UNVERIFIED: Game.Instance.gasConduitFlow — may be different conduit system'
if 'flow.GetContents(' in s:
annotations[i] = '🔶 UNVERIFIED: ConduitFlow.GetContents() method and return type'
if 'contents.element' in s or 'contents.mass' in s or 'contents.temperature' in s:
annotations[i] = '🔶 UNVERIFIED: ConduitContents property names'
if 'Components.LiquidConduits' in s or 'Components.GasConduits' in s:
annotations[i] = '🔶 UNVERIFIED: Components.LiquidConduits / GasConduits may not exist'
if 'conduit.GetCell()' in s:
annotations[i] = '🔶 UNVERIFIED: Conduit.GetCell() method'
# === Printing Pod ===
if 'pod.IsReady()' in s or 'pod.CyclesUntilReady()' in s:
annotations[i] = '🔶 UNVERIFIED: PrintingPod methods IsReady/CyclesUntilReady — may differ'
if 'pod.GetCurrentOffers()' in s:
annotations[i] = '🔶 UNVERIFIED: PrintingPod.GetCurrentOffers() return type'
if 'offer.GetName()' in s:
annotations[i] = '🔶 UNVERIFIED: CarePackage/PrintingPodOffer.GetName() method'
if 'pod.SelectOffer(' in s:
annotations[i] = '🔶 UNVERIFIED: PrintingPod.SelectOffer(int) method'
if 'ImmuneSystemMonitor.Instance' in s and ('IsReadyToPrint' in s or 'GetCyclesUntilNextPrint' in s):
annotations[i] = '🔶 UNVERIFIED: ImmuneSystemMonitor methods may not exist'
# === Door ===
if 'door.Lock()' in s or 'door.Unlock()' in s:
annotations[i] = '🔶 UNVERIFIED: Door.Lock()/Unlock() methods may not exist'
# === Operational/Toggle ===
if 'oper.SetFlag(Operational.ActiveFlag,' in s:
annotations[i] = '🔶 UNVERIFIED: Operational.SetFlag signature — may need different approach'
# === Storage ===
if 'storage.DropAll(' in s:
annotations[i] = '🔶 UNVERIFIED: Storage.DropAll() parameters may differ'
# === Camera ===
if 'CameraController.Instance' in s and 'SetPosition' not in s:
annotations[i] = '🔶 UNVERIFIED: CameraController.Instance may not be the correct singleton'
if 'Camera.main?.orthographicSize' in s:
annotations[i] = '🔶 UNVERIFIED: Camera.main.orthographicSize setter may not work in ONI'
if 'cam.transform.position' in s and '= new Vector3' in s:
annotations[i] = '🔶 UNVERIFIED: Setting camera transform.position directly may not work'
# === Screenshot ===
if 'ScreenCapture.CaptureScreenshot' in s:
annotations[i] = '🔶 UNVERIFIED: ScreenCapture may not be available in ONI Unity version'
# === Save/Load ===
if 'SaveLoader.Save(' in s or 'SaveLoader.Load(' in s:
annotations[i] = '🔶 UNVERIFIED: SaveLoader.Save/Load method signatures'
if 'SaveLoader.GetActiveSaveFilePath()' in s:
annotations[i] = '🔶 UNVERIFIED: SaveLoader.GetActiveSaveFilePath() may not exist'
# === Research ===
if 'Research.Instance?.GetActiveResearchTechnologies' in s:
annotations[i] = '🔶 UNVERIFIED: Research.GetActiveResearchTechnologies() method'
if 'Research.Instance?.QueueResearch(' in s:
annotations[i] = '🔶 UNVERIFIED: Research.QueueResearch(Tech) method'
if 'Research.Instance?.CancelResearch(' in s:
annotations[i] = '🔶 UNVERIFIED: Research.CancelResearch(Tech) method'
if 'tech.pointsForCompletion' in s:
annotations[i] = '🔶 UNVERIFIED: Tech.pointsForCompletion property'
# === Overlay ===
if 'simOverlayManager' in s:
annotations[i] = '🔶 UNVERIFIED: Game.Instance.simOverlayManager may not exist'
if 'currentOverlay' in s:
annotations[i] = '🔶 UNVERIFIED: currentOverlay.ToString() may not yield expected overlay names'
# === Buildings ===
if 'Assets.BuildingDefs' in s and 'GetBuildingDef' not in s:
annotations[i] = '🔶 UNVERIFIED: Assets.BuildingDefs may not be a collection'
# === Grid ===
if 'Grid.Germs' in s:
annotations[i] = '🔶 UNVERIFIED: Grid.Germs API — may not exist or have different type'
# === DTO class ===
if 'public int? x2' in s or 'public int? y2' in s:
annotations[i] = '🔶 UNVERIFIED: Nullable parameters may not serialize correctly'
# === Buildings detail ===
if 'health?.GetHealth()' in s:
annotations[i] = '🔶 UNVERIFIED: Health component GetHealth()/GetMaxHealth() methods'
# === Sensor ===
if 'AtmoSensor' in s and '?.threshold' in s:
annotations[i] = '🔶 UNVERIFIED: AtmoSensor/ThermoSensor/HydroSensor threshold property'
# Apply annotations — add comment after the line
annotated = 0
for lineno in sorted(annotations.keys(), reverse=True):
idx = lineno - 1
comment = ' // ' + annotations[lineno]
lines[idx] = lines[idx] + comment
annotated += 1
with open('mod/ONIAgentBridge.cs', 'w') as f:
f.write('\n'.join(lines))
print(f"Annotated {annotated} lines with verification markers")