unity debugging

This commit is contained in:
Aeth3r committed 2026-10-23 08:57:19 -04:00
1 parent 26085ed02b
commit e5f6d0d9a4
3 files changed
+105

No files matched your search

+29
View File
@@ -0,0 +1,29 @@
#!/usr/bin/env bash
# Installs Unity's MIT-licensed vscode-unity-debug adapter for nvim-dap and
# patches it to find editors however they were launched (see patch.cs).
# Re-runnable: always re-extracts and re-patches from the pristine .vsix.
set -euo pipefail
VERSION=3.0.1
HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
DEST="${1:-${XDG_DATA_HOME:-$HOME/.local/share}/nvim/unity-debug}"
BIN="$DEST/extension/bin"
for cmd in curl unzip mono mcs; do
command -v "$cmd" >/dev/null || { echo "unity-debug install: missing '$cmd'" >&2; exit 1; }
done
mkdir -p "$DEST"
VSIX="$DEST/unity-debug-$VERSION.vsix"
[ -f "$VSIX" ] || curl -fsSL -o "$VSIX" \
"https://github.com/Unity-Technologies/vscode-unity-debug/releases/download/Version-$VERSION/unity-debug-$VERSION.vsix"
rm -rf "$DEST/extension"
unzip -qo "$VSIX" -d "$DEST"
TMP="$(mktemp -d)"
trap 'rm -rf "$TMP"' EXIT
mcs "$HERE/patch.cs" -r:"$BIN/Mono.Cecil.dll" -out:"$TMP/patch.exe"
cp "$BIN/UnityDebug.exe" "$BIN/UnityDebug.exe.orig"
MONO_PATH="$BIN" mono "$TMP/patch.exe" "$BIN/UnityDebug.exe.orig" "$TMP/UnityDebug.exe"
cp "$TMP/UnityDebug.exe" "$BIN/UnityDebug.exe"
echo "unity-debug installed and patched in $DEST"
+20
View File
@@ -0,0 +1,20 @@
// Patches vscode-unity-debug's UnityProcessDiscovery.GetUnityEditorProcesses to
// prefix-match process names instead of requiring an exact "Unity"/"Unity Editor".
// The comparison is OrdinalIgnoreCase, so the "Unity" prefix then matches editors
// launched directly ("Unity") and via Unity Hub ("unityhub-unity-editor-<version>").
// Extra matches (UnityPackageManager etc.) are fine: with a config name containing
// "Editor", the adapter picks the editor by process_id from EditorInstance.json.
using System; using System.Linq; using Mono.Cecil;
class Patch {
static int Main(string[] a) {
var asm = AssemblyDefinition.ReadAssembly(a[0]);
var m = asm.MainModule.Types.SelectMany(t => t.Methods).Single(x => x.Name == "GetUnityEditorProcesses");
var startsWith = asm.MainModule.ImportReference(typeof(string).GetMethod("StartsWith", new[] { typeof(string), typeof(StringComparison) }));
int c = 0;
foreach (var i in m.Body.Instructions)
if (i.Operand is MethodReference r && r.DeclaringType.FullName == "System.String" && r.Name == "Equals" && r.Parameters.Count == 2) { i.Operand = startsWith; c++; }
if (c != 1) { Console.Error.WriteLine($"expected 1 string.Equals call in {m.Name}, found {c}"); return 1; }
asm.Write(a[1]);
return 0;
}
}