// 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-"). // 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; } }