1
0
mirror of synced 2024-11-27 23:40:48 +01:00

Fixed random exception on title launch

This commit is contained in:
Fluto 2022-08-20 14:24:20 +10:00
parent 4537f4bef9
commit 066998aa39

View File

@ -445,14 +445,17 @@ public class CustomMusicLoaderPatch
} }
[HarmonyPatch(typeof(DataManager), nameof(DataManager.ExchangeWordData))] [HarmonyPatch(typeof(DataManager), nameof(DataManager.ExchangeWordData))]
[HarmonyPostfix] [HarmonyPrefix]
[HarmonyWrapSafe] [HarmonyWrapSafe]
private static void ExchangeWordData_PostFix(DataManager __instance, string language) private static bool ExchangeWordData_Prefix(DataManager __instance, string language)
{ {
if (__instance.MusicData != null) if (__instance.MusicData != null)
{ {
WordDataInterface_Postfix(__instance.WordData, language); __instance.WordData = CreateWordDateInterface(language);
return false;
} }
return true;
} }
/// <summary> /// <summary>
@ -550,7 +553,6 @@ public class CustomMusicLoaderPatch
); );
musicInfoAccessors.Add(musicInfo); musicInfoAccessors.Add(musicInfo);
} }
#endregion #endregion
BubbleSort(musicInfoAccessors, (a, b) => a.Order - b.Order); BubbleSort(musicInfoAccessors, (a, b) => a.Order - b.Order);
@ -621,13 +623,14 @@ public class CustomMusicLoaderPatch
/// <summary> /// <summary>
/// This will handle loading the localisation of tracks /// This will handle loading the localisation of tracks
/// </summary> /// </summary>
private static void WordDataInterface_Postfix(WordDataInterface __instance, string language) private static WordDataInterface CreateWordDateInterface(string language)
{ {
var wordDataInterface = new WordDataInterface(Application.streamingAssetsPath + "/ReadAssets/newwordlist.bin", language);
// This is where the metadata for tracks are read in our attempt to allow custom tracks will be to add additional metadata to the list that is created // This is where the metadata for tracks are read in our attempt to allow custom tracks will be to add additional metadata to the list that is created
var customSongs = GetCustomSongs(); var customSongs = GetCustomSongs();
if (customSongs.Count == 0) if (customSongs.Count == 0)
return; return wordDataInterface;
var customLanguage = Plugin.Instance.ConfigOverrideDefaultSongLanguage.Value; var customLanguage = Plugin.Instance.ConfigOverrideDefaultSongLanguage.Value;
var languageValue = language; var languageValue = language;
@ -635,12 +638,12 @@ public class CustomMusicLoaderPatch
languageValue = customLanguage; languageValue = customLanguage;
// now that we have loaded this json, inject it into the existing `songInfoAccessers` // now that we have loaded this json, inject it into the existing `songInfoAccessers`
var musicInfoAccessors = __instance.wordListInfoAccessers; var musicInfoAccessors = wordDataInterface.wordListInfoAccessers;
// override the existing songs if we're using a custom language // override the existing songs if we're using a custom language
if (languageValue != language) if (languageValue != language)
{ {
var wordListInfoRead = (ReadData<WordListInfo>) AccessTools.Property(typeof(WordDataInterface), nameof(WordDataInterface.wordListInfoRead)).GetValue(__instance); var wordListInfoRead = wordDataInterface.wordListInfoRead;
var dictionary = wordListInfoRead.InfomationDatas.ToList(); var dictionary = wordListInfoRead.InfomationDatas.ToList();
for (int i = 0; i < musicInfoAccessors.Count; i++) for (int i = 0; i < musicInfoAccessors.Count; i++)
@ -704,7 +707,9 @@ public class CustomMusicLoaderPatch
} }
} }
__instance.wordListInfoAccessers = musicInfoAccessors; wordDataInterface.wordListInfoAccessers = musicInfoAccessors;
return wordDataInterface;
(string text, int font) GetValuesWordList(WordListInfo wordListInfo) (string text, int font) GetValuesWordList(WordListInfo wordListInfo)
{ {
@ -1014,6 +1019,7 @@ public class CustomMusicLoaderPatch
foreach (var song in unsortedSongList) foreach (var song in unsortedSongList)
__instance.SongList.Add(song); __instance.SongList.Add(song);
__instance.UnsortedSongList = unsortedSongList; __instance.UnsortedSongList = unsortedSongList;
updateSortCategoryInfo(DataConst.SongSortType.Genre); updateSortCategoryInfo(DataConst.SongSortType.Genre);
@ -1332,7 +1338,6 @@ public class CustomMusicLoaderPatch
[HarmonyWrapSafe] [HarmonyWrapSafe]
public static void UpdateDiffCourseAnim_Postfix(CourseSelect __instance) public static void UpdateDiffCourseAnim_Postfix(CourseSelect __instance)
{ {
Log.LogInfo(nameof(UpdateDiffCourseAnim_Postfix));
int num = __instance.selectedSongInfo.Stars[4] == 0 ? 4 : 5; int num = __instance.selectedSongInfo.Stars[4] == 0 ? 4 : 5;
for (int levelType = 0; levelType < num; ++levelType) for (int levelType = 0; levelType < num; ++levelType)
{ {
@ -1364,7 +1369,6 @@ public class CustomMusicLoaderPatch
[HarmonyWrapSafe] [HarmonyWrapSafe]
public static void SetMyInfo_Postfix(SongSelectRankingBestScoreDisplay __instance, int musicUniqueId, EnsoData.EnsoLevelType ensoLevel) public static void SetMyInfo_Postfix(SongSelectRankingBestScoreDisplay __instance, int musicUniqueId, EnsoData.EnsoLevelType ensoLevel)
{ {
Log.LogInfo(nameof(SetMyInfo_Postfix));
GetPlayerRecordInfo(TaikoSingletonMonoBehaviour<CommonObjects>.Instance.MyDataManager.PlayData, 0, musicUniqueId, ensoLevel, out var dst); GetPlayerRecordInfo(TaikoSingletonMonoBehaviour<CommonObjects>.Instance.MyDataManager.PlayData, 0, musicUniqueId, ensoLevel, out var dst);
__instance.UpdateScoreDisplay(dst.normalHiScore); __instance.UpdateScoreDisplay(dst.normalHiScore);
} }
@ -1374,7 +1378,6 @@ public class CustomMusicLoaderPatch
[HarmonyWrapSafe] [HarmonyWrapSafe]
public static void UpdateDisplay_Postfix(CourseSelectScoreDisplay __instance, int musicUniqueId, EnsoData.EnsoLevelType levelType) public static void UpdateDisplay_Postfix(CourseSelectScoreDisplay __instance, int musicUniqueId, EnsoData.EnsoLevelType levelType)
{ {
Log.LogInfo(nameof(UpdateDisplay_Postfix));
GetPlayerRecordInfo(TaikoSingletonMonoBehaviour<CommonObjects>.Instance.MyDataManager.PlayData, __instance.playerType == DataConst.PlayerType.Player_1 ? 0 : 1, musicUniqueId, levelType, out var dst); GetPlayerRecordInfo(TaikoSingletonMonoBehaviour<CommonObjects>.Instance.MyDataManager.PlayData, __instance.playerType == DataConst.PlayerType.Player_1 ? 0 : 1, musicUniqueId, levelType, out var dst);
var normalHiScore = dst.normalHiScore; var normalHiScore = dst.normalHiScore;
for (int index = 0; index < 6; ++index) for (int index = 0; index < 6; ++index)
@ -1411,7 +1414,6 @@ public class CustomMusicLoaderPatch
[HarmonyWrapSafe] [HarmonyWrapSafe]
public static void UpdateCrownNumDisplay_Postfix(SongSelectScoreDisplay __instance, int playerId) public static void UpdateCrownNumDisplay_Postfix(SongSelectScoreDisplay __instance, int playerId)
{ {
Log.LogInfo(nameof(UpdateCrownNumDisplay_Postfix));
PlayDataManager playData = TaikoSingletonMonoBehaviour<CommonObjects>.Instance.MyDataManager.PlayData; PlayDataManager playData = TaikoSingletonMonoBehaviour<CommonObjects>.Instance.MyDataManager.PlayData;
var musicInfoAccessers = TaikoSingletonMonoBehaviour<CommonObjects>.Instance.MyDataManager.MusicData.musicInfoAccessers; var musicInfoAccessers = TaikoSingletonMonoBehaviour<CommonObjects>.Instance.MyDataManager.MusicData.musicInfoAccessers;
int[,] numArray = new int[3, 5]; int[,] numArray = new int[3, 5];
@ -1449,7 +1451,6 @@ public class CustomMusicLoaderPatch
[HarmonyWrapSafe] [HarmonyWrapSafe]
public static void UpdateScoreDisplay_Postfix(SongSelectScoreDisplay __instance, int playerId, int musicUniqueId, bool enableUra) public static void UpdateScoreDisplay_Postfix(SongSelectScoreDisplay __instance, int playerId, int musicUniqueId, bool enableUra)
{ {
Log.LogInfo(nameof(UpdateScoreDisplay_Postfix));
var num = enableUra ? 5 : 4; var num = enableUra ? 5 : 4;
for (int levelType = 0; levelType < num; ++levelType) for (int levelType = 0; levelType < num; ++levelType)