build: fix csproj (remove NuGet deps, add 0Harmony ref) + improved build script

csproj: removed Lib.Harmony and System.Text.Json NuGet packages (game bundles these),
added 0Harmony.dll reference from game directory, LangVersion=latest
build_mod.sh: auto-detect Managed/ subdirectory, support Linux/macOS/Windows paths,
better error messages, install instructions

C# code verification: 0 syntax errors, 8 missing-reference-only errors (expected)
This commit is contained in:
root
2026-05-22 10:45:40 +08:00
parent 64e57b2c44
commit bff8aea846
2 changed files with 37 additions and 61 deletions

View File

@ -5,65 +5,57 @@
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
MOD_DIR="$SCRIPT_DIR/mod"
PROJECT_DIR="$(cd "$SCRIPT_DIR/.." && pwd)"
MOD_DIR="$PROJECT_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/.steam/steam/steamapps/common/OxygenNotIncluded" \
"$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"
MANAGED="$candidate/OxygenNotIncluded_Data/Managed"
if [ -d "$MANAGED" ]; then
ONI_PATH="$MANAGED"
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"
echo "[!] ONI installation not found."
echo " Set ONI_PATH to the Managed directory:"
echo ' export ONI_PATH="/path/to/OxygenNotIncluded_Data/Managed"'
exit 1
fi
echo "[Build] ONI path: $ONI_PATH"
echo "[Build] ONI: $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
for dll in "$ONI_PATH/Assembly-CSharp.dll" "$ONI_PATH/UnityEngine.dll" \
"$ONI_PATH/UnityEngine.CoreModule.dll" "$ONI_PATH/0Harmony.dll"; do
if [ ! -f "$dll" ]; then echo "[!] Missing: $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"
REFS=""
for dll in "$ONI_PATH/Assembly-CSharp.dll" "$ONI_PATH/UnityEngine.dll" \
"$ONI_PATH/UnityEngine.CoreModule.dll" "$ONI_PATH/0Harmony.dll"; do
REFS="$REFS -reference:\"$dll\""
done
if [ -f "$ONI_PATH/Assembly-CSharp-firstpass.dll" ]; then
REFS="$REFS -reference:\"$ONI_PATH/Assembly-CSharp-firstpass.dll\""
fi
echo "[Build] Compilation successful!"
echo "[Build] Output: $OUTPUT_DIR/ONIAgentBridge.dll"
echo "[Build] Compiling..."
eval mcs -target:library -out:"$OUTPUT_DIR/ONIAgentBridge.dll" $REFS -recurse:"$MOD_DIR/*.cs"
echo "[Build] SUCCESS: $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"
echo "Install (Linux):"
echo " MOD_DIR=~/.config/unity3d/Klei/OxygenNot\\ Included/mods/local/ONIAgentBridge"
echo " mkdir -p \"\$MOD_DIR\""
echo " cp $OUTPUT_DIR/ONIAgentBridge.dll $MOD_DIR/mod_info.yaml \"\$MOD_DIR/\""
echo " # Then enable mod in ONI > Mods > ONI Agent Bridge"