Skip to content

Commit

Permalink
CAM-42 Added selected album functionality, added failsafe application…
Browse files Browse the repository at this point in the history
… close on failed native hooks
  • Loading branch information
SB15-MD committed Jan 25, 2024
1 parent 0eb314a commit 403151f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
3 changes: 2 additions & 1 deletion Patches/AssetPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,8 @@ internal static unsafe void AttachHook()
if (loadFromNameMethod is null)
{
Logger.Error("FATAL ERROR: AssetPatch failed.");
return;
Thread.Sleep(1000);
Environment.Exit(1);
}

// AttachHook should only be run once; create the handler
Expand Down
24 changes: 16 additions & 8 deletions Patches/SavePatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ private static void Postfix(MusicInfo __instance, ref string __result)
// TODO: Find a way to inject hidden and favorite charts without using vanilla save -- below are workarounds for quick release.
private static void CleanCustomData()
{

DataHelper.hides.RemoveAll((Il2CppSystem.Predicate<string>)(uid => uid.StartsWith($"{AlbumManager.Uid}-")));
DataHelper.history.RemoveAll(
(Il2CppSystem.Predicate<string>)(uid => uid.StartsWith($"{AlbumManager.Uid}-")));
Expand All @@ -204,10 +205,6 @@ private static void CleanCustomData()
if (ModSettings.SavingEnabled) SaveData.SelectedAlbum = AlbumManager.GetAlbumNameFromUid(DataHelper.selectedMusicUidFromInfoList);
DataHelper.selectedMusicUidFromInfoList = "0-0";
}
else
{
if (ModSettings.SavingEnabled) SaveData.SelectedAlbum = string.Empty;
}

foreach (var task in DataHelper.tasks)
Singleton<DataManager>.instance["Task"][task].GetResult<Il2CppSystem.Collections.Generic.List<IData>>()
Expand All @@ -222,12 +219,12 @@ private static void InjectCustomData()
DataHelper.hides.AddManagedRange(SaveData.Hides.GetAlbumUidsFromNames());
DataHelper.history.AddManagedRange(SaveData.History.GetAlbumUidsFromNames());
DataHelper.collections.AddManagedRange(SaveData.Collections.GetAlbumUidsFromNames());
Logger.Msg("SelectedAlbum = " + SaveData.SelectedAlbum);

if (!SaveData.SelectedAlbum.StartsWith($"{AlbumManager.Uid}-")) return;

if (!SaveData.SelectedAlbum.StartsWith("album_")) return;
DataHelper.selectedAlbumUid = "music_package_999";
DataHelper.selectedAlbumTagIndex = 999;
DataHelper.selectedMusicUidFromInfoList = SaveData.SelectedAlbum ?? "0-0";
DataHelper.selectedMusicUidFromInfoList = AlbumManager.LoadedAlbums.TryGetValue(SaveData.SelectedAlbum, out var album) ? $"{AlbumManager.Uid}-{album.Index}" : "0-0";
}

[HarmonyPatch(typeof(PnlPreparation), nameof(PnlPreparation.OnEnable))]
Expand Down Expand Up @@ -350,7 +347,8 @@ internal static unsafe void AttachHook()
if (recordBattleArgsMethod is null)
{
Logger.Error("FATAL ERROR: SavePatch failed.");
return;
Thread.Sleep(1000);
Environment.Exit(1);
}

var recordBattleArgsPointer = *(IntPtr*)(IntPtr)Il2CppInteropUtils
Expand Down Expand Up @@ -427,6 +425,16 @@ private static void Postfix(PnlVictory __instance)
}
}

[HarmonyPatch(typeof(PnlPreparation), nameof(PnlPreparation.OnBattleStart))]
internal class OnBattleStartPatch
{
private static void Postfix()
{
if (ModSettings.SavingEnabled && !DataHelper.selectedMusicUidFromInfoList.StartsWith("album_"))
SaveData.SelectedAlbum = DataHelper.selectedMusicUidFromInfoList;
}
}

//
// HACKS SECTION - TODO: Remove all the methods below once we don't put data into the official game at all
//
Expand Down

0 comments on commit 403151f

Please sign in to comment.