From 098d689750f825733c8bd9ea202b197ef6515146 Mon Sep 17 00:00:00 2001 From: Devin Bidwell Date: Thu, 11 Dec 2025 17:14:43 -0700 Subject: [PATCH] wip -- source mapping overrides in-game line error number --- csharp_mod/GlobalCode.cs | 27 +++++++++++++++++++++++++++ csharp_mod/Patches.cs | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) diff --git a/csharp_mod/GlobalCode.cs b/csharp_mod/GlobalCode.cs index f472821..14f3c23 100644 --- a/csharp_mod/GlobalCode.cs +++ b/csharp_mod/GlobalCode.cs @@ -15,6 +15,9 @@ public static class GlobalCode // so that save file data is smaller private static Dictionary codeDict = new(); + // This Dictionary stores the source maps for the given SLANG_REF, where + // the key is the IC10 line, and the value is a List of Slang ranges where that + // line would have come from private static Dictionary>> sourceMaps = new(); public static void ClearCache() @@ -38,6 +41,30 @@ public static class GlobalCode sourceMaps[reference] = builtDictionary; } + public static bool GetSlangErrorLineFromICError( + Guid reference, + uint icErrorLine, + out uint slangSrc + ) + { + slangSrc = icErrorLine; + + if (!sourceMaps.ContainsKey(reference)) + { + return false; + } + + var foundRange = sourceMaps[reference][icErrorLine]; + + if (foundRange is null) + { + return false; + } + + slangSrc = foundRange[0].StartLine; + return true; + } + public static string GetSource(Guid reference) { if (!codeDict.ContainsKey(reference)) diff --git a/csharp_mod/Patches.cs b/csharp_mod/Patches.cs index d878f97..ea5169f 100644 --- a/csharp_mod/Patches.cs +++ b/csharp_mod/Patches.cs @@ -141,6 +141,39 @@ public static class SlangPatches chipData.SourceCode = code; } + [HarmonyPatch( + typeof(ProgrammableChip), + nameof(ProgrammableChip.ErrorLineNumberString), + MethodType.Getter + )] + [HarmonyPostfix] + public static void pgc_ErrorLineNumberString(ProgrammableChip __instance, ref string __result) + { + if ( + String.IsNullOrEmpty(__result) + || __result.LastIndexOf(GlobalCode.SLANG_REF) < 0 + || !Guid.TryParse( + __result + .Substring( + __result.LastIndexOf(GlobalCode.SLANG_REF) + GlobalCode.SLANG_REF.Length + ) + .Trim(), + out var slangGuid + ) + || !uint.TryParse(__result.Trim(), out var ic10ErrorLineNumber) + || !GlobalCode.GetSlangErrorLineFromICError( + slangGuid, + ic10ErrorLineNumber, + out var slangErrorLineNumber + ) + ) + { + return; + } + + __result = slangErrorLineNumber.ToString(); + } + [HarmonyPatch( typeof(ProgrammableChipMotherboard), nameof(ProgrammableChipMotherboard.SerializeSave)