Skip to content

Commit

Permalink
Merge pull request #9 from hykilpikonna/tc21/fix-crash-slot-data-not-…
Browse files Browse the repository at this point in the history
…found

Fix crash during call to CommonMonitor.SetCharacterSlot
  • Loading branch information
hykilpikonna authored Feb 8, 2024
2 parents c10085b + f76a027 commit e1180a9
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions AquaMai/Fix/FixCharaCrash.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
using System;
using System.Collections.Generic;
using HarmonyLib;
using Process;
using Util;

namespace AquaMai.Fix
{
/**
* Fix character selection crashing because get map color returns null
* Fix character selection crashing due to missing character data
*/
public class FixCharaCrash
{
Expand All @@ -15,14 +17,28 @@ public class FixCharaCrash
public static void GetMapColorData(ref CharacterSelectProces __instance, ref CharacterMapColorData __result)
{
if (__result != null) return;

// 1 is a color that definitely exists
if (MapMaster.GetSlotData(1) == null)
{
MapMaster.GetSlotData(1).Load();
}
__result = MapMaster.GetSlotData(1);
}


// This is called when loading the music selection screen, to display characters on the top screen
[HarmonyPrefix]
[HarmonyPatch(typeof(Monitor.CommonMonitor), "SetCharacterSlot", new Type[] { typeof(MessageCharactorInfomationData) })]
public static bool SetCharacterSlot(ref MessageCharactorInfomationData data, Dictionary<int, CharacterSlotData> ____characterSlotData)
{
// Some characters are not found in this dictionary. We simply skip loading those characters
if (!____characterSlotData.ContainsKey(data.MapKey))
{
Console.Log($"Could not get CharacterSlotData for character [Index={data.Index}, MapKey={data.MapKey}], ignoring...");
return false;
}

return true;
}
}
}
}

0 comments on commit e1180a9

Please sign in to comment.