wip -- source mapping overrides in-game line error number
This commit is contained in:
@@ -15,6 +15,9 @@ public static class GlobalCode
|
|||||||
// so that save file data is smaller
|
// so that save file data is smaller
|
||||||
private static Dictionary<Guid, string> codeDict = new();
|
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();
|
private static Dictionary<Guid, Dictionary<uint, List<Range>>> sourceMaps = new();
|
||||||
|
|
||||||
public static void ClearCache()
|
public static void ClearCache()
|
||||||
@@ -38,6 +41,30 @@ public static class GlobalCode
|
|||||||
sourceMaps[reference] = builtDictionary;
|
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)
|
public static string GetSource(Guid reference)
|
||||||
{
|
{
|
||||||
if (!codeDict.ContainsKey(reference))
|
if (!codeDict.ContainsKey(reference))
|
||||||
|
|||||||
@@ -141,6 +141,39 @@ public static class SlangPatches
|
|||||||
chipData.SourceCode = code;
|
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(
|
[HarmonyPatch(
|
||||||
typeof(ProgrammableChipMotherboard),
|
typeof(ProgrammableChipMotherboard),
|
||||||
nameof(ProgrammableChipMotherboard.SerializeSave)
|
nameof(ProgrammableChipMotherboard.SerializeSave)
|
||||||
|
|||||||
Reference in New Issue
Block a user