wip -- source mapping overrides in-game line error number

This commit is contained in:
2025-12-11 17:14:43 -07:00
parent 3edf0324c7
commit 098d689750
2 changed files with 60 additions and 0 deletions

View File

@@ -15,6 +15,9 @@ public static class GlobalCode
// so that save file data is smaller
private static Dictionary<Guid, string> 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<Guid, Dictionary<uint, List<Range>>> 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))

View File

@@ -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)