build: C# 6 compatible port + build script + csproj

- Convert all C# 7/8 features to C# 6 for mono mcs compatibility:
  - Tuple switch → if-else chain
  - Switch expressions → if-else blocks
  - Expression-bodied switch → regular switch statement
- Verified compilation succeeds (only missing game DLL refs)
- Added mod/ONIAgentBridge.csproj for dotnet SDK builds
- Added scripts/build_mod.sh for mono-based builds
  - Auto-detects ONI installation path
  - References required game DLLs
  - Outputs to mod/bin/
This commit is contained in:
root
2026-05-22 10:39:17 +08:00
parent 6a71d42f78
commit 64e57b2c44
4 changed files with 721 additions and 231 deletions

69
scripts/build_mod.sh Executable file
View File

@ -0,0 +1,69 @@
#!/usr/bin/env bash
# Build the ONI Agent Bridge Mod
# Requires: mono-complete (for mcs compiler)
# Requires: ONI game installed to get reference DLLs
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
MOD_DIR="$SCRIPT_DIR/mod"
OUTPUT_DIR="$MOD_DIR/bin"
# Find ONI installation
ONI_PATH="${ONI_PATH:-}"
if [ -z "$ONI_PATH" ]; then
# Common paths
for candidate in \
"$HOME/.local/share/Steam/steamapps/common/OxygenNotIncluded" \
"$HOME/Library/Application Support/Steam/steamapps/common/OxygenNotIncluded" \
"/c/Program Files (x86)/Steam/steamapps/common/OxygenNotIncluded" \
"/mnt/c/Program Files (x86)/Steam/steamapps/common/OxygenNotIncluded"; do
if [ -d "$candidate" ]; then
ONI_PATH="$candidate"
break
fi
done
fi
if [ -z "$ONI_PATH" ]; then
echo "[!] ONI installation not found. Set ONI_PATH environment variable."
echo " export ONI_PATH=/path/to/OxygenNotIncluded"
exit 1
fi
echo "[Build] ONI path: $ONI_PATH"
# Check required DLLs
GAME_DLLS=(
"$ONI_PATH/Assembly-CSharp.dll"
"$ONI_PATH/Assembly-CSharp-firstpass.dll"
"$ONI_PATH/UnityEngine.dll"
"$ONI_PATH/UnityEngine.CoreModule.dll"
"$ONI_PATH/0Harmony.dll"
)
for dll in "${GAME_DLLS[@]}"; do
if [ ! -f "$dll" ]; then
echo "[!] Required DLL not found: $dll"
exit 1
fi
done
echo "[Build] Found all required DLLs"
mkdir -p "$OUTPUT_DIR"
# Compile
mcs -target:library \
-out:"$OUTPUT_DIR/ONIAgentBridge.dll" \
-reference:"$ONI_PATH/Assembly-CSharp.dll" \
-reference:"$ONI_PATH/Assembly-CSharp-firstpass.dll" \
-reference:"$ONI_PATH/UnityEngine.dll" \
-reference:"$ONI_PATH/UnityEngine.CoreModule.dll" \
-reference:"$ONI_PATH/0Harmony.dll" \
-recurse:"$MOD_DIR/*.cs"
echo "[Build] Compilation successful!"
echo "[Build] Output: $OUTPUT_DIR/ONIAgentBridge.dll"
echo ""
echo "To install: copy $OUTPUT_DIR/ONIAgentBridge.dll and $MOD_DIR/mod_info.yaml"
echo " to your ONI mods/local/ONIAgentBridge/ directory"