Skip to content

Commit

Permalink
Forced merge pull request #14 from MDMods/development
Browse files Browse the repository at this point in the history
v4.1.2 bump
  • Loading branch information
SB15-MD authored Aug 23, 2024
2 parents c2f9193 + 354af78 commit 9e44f69
Show file tree
Hide file tree
Showing 10 changed files with 186 additions and 111 deletions.
9 changes: 4 additions & 5 deletions BmsLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -655,16 +655,15 @@ private static float GetStartDelay(string prefab)

private static float GetAnimationDuration(string scene, string animation)
{
var resourceName =
Singleton<ConfigManager>.instance.GetConfigStringValue("boss", "scene_name", "boss_name", scene);
var controller = ResourcesManager.instance.LoadFromName<GameObject>(resourceName)
.GetComponent<SpineActionController>();
var controller = ResourcesManager.instance.LoadFromName<GameObject>(Boss.Instance.BossFestival($"{scene.Split("_")[1]}01_boss"))
.GetComponent<SpineActionController>();
var animations = controller.gameObject.GetComponent<SkeletonAnimation>().skeletonDataAsset
.GetSkeletonData(true).Animations;

var arr = new SkeletActionData[controller.actionData.Count];
controller.actionData.CopyTo(arr, 0);
var actionData = new List<SkeletActionData>(arr).Find(dd => dd.name == animation);

var animName = animation;
if (actionData is { actionIdx: not null } && actionData.actionIdx.Length != 0)
animName = actionData.actionIdx[0];
Expand Down
1 change: 0 additions & 1 deletion Data/Album.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System.IO.Compression;
using CustomAlbums.Managers;
using CustomAlbums.Utilities;
using Il2CppSystem.Runtime.Remoting.Messaging;
using UnityEngine;
using Logger = CustomAlbums.Utilities.Logger;

Expand Down
13 changes: 13 additions & 0 deletions Data/CustomAlbumsSave.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,24 @@
public class CustomAlbumsSave
{
public string SelectedAlbum { get; set; } = string.Empty;
public float Ability { get; set; } = 0;
public HashSet<string> UnlockedMasters { get; set; } = new();
public HashSet<string> Collections { get; set; } = new();
public HashSet<string> Hides { get; set; } = new();
public Queue<string> History { get; set; } = new();
public Dictionary<string, Dictionary<int, CustomChartSave>> Highest { get; set; } = new();
public Dictionary<string, List<int>> FullCombo { get; set; } = new();

internal bool IsEmpty()
{
return SelectedAlbum == string.Empty
&& Ability == 0
&& UnlockedMasters.Count == 0
&& Collections.Count == 0
&& Hides.Count == 0
&& History.Count == 0
&& Highest.Count == 0
&& FullCombo.Count == 0;
}
}
}
3 changes: 3 additions & 0 deletions Managers/SaveManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ private static void RestoreBackup()
{
continue;
}

// If our backup that we are trying to load is valid but empty, continue to try and find the last save with data in it
if (SaveData.IsEmpty()) continue;
Logger.Success($"Restored backup from {backup.LastWriteTime.DateTime}.");
return;
}
Expand Down
112 changes: 112 additions & 0 deletions Patches/AnalyticsPatch.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
using CustomAlbums.Managers;
using HarmonyLib;
using Il2CppAssets.Scripts.Database;
using Il2CppAssets.Scripts.Structs.Modules;
using Il2CppPeroPeroGames.DataStatistics;
using System.Reflection;
using UnityEngine;
using Logger = CustomAlbums.Utilities.Logger;

namespace CustomAlbums.Patches
{
internal class AnalyticsPatch
{
internal static readonly Logger Logger = new(nameof(AnalyticsPatch));

/// <summary>
/// Blocks tag analytics from being sent if tag is CustomAlbums.
/// </summary>
[HarmonyPatch(typeof(ThinkingDataPeripheralHelper), nameof(ThinkingDataPeripheralHelper.CommonSendString))]
internal class CommonSendStringPatch
{
private static bool Prefix(string eventName, string propertyName, string info)
{
var runCond = info != AlbumManager.Languages["ChineseS"];
if (!runCond) Logger.Msg("Blocked custom albums tag analytics.");
return runCond;
}
}

/// <summary>
/// Blocks chart analytics from being sent if the chart is custom.
/// </summary>
[HarmonyPatch(typeof(ThinkingDataBattleHelper))]
internal class SendMDPatch
{
private static IEnumerable<MethodBase> TargetMethods()
{
return typeof(ThinkingDataBattleHelper).GetMethods(BindingFlags.Instance | BindingFlags.Public)
.Where(method => method.Name.StartsWith("Send"));
}

private static bool Prefix()
{
var runCond = !BattleHelper.MusicInfo().uid.StartsWith($"{AlbumManager.Uid}-");
if (!runCond) Logger.Msg("Blocked sending analytics of custom chart.");
return runCond;
}
}


/// <summary>
/// Prevents the game from sending any analytics if the musicInfo is custom.
/// </summary>
[HarmonyPatch(typeof(ThinkingDataPeripheralHelper), nameof(ThinkingDataPeripheralHelper.PostToThinkingData))]
internal class PostToThinkingDataPatch
{
private static bool Prefix(string dataStatisticsEventDefinesName, MusicInfo musicInfo)
{
var runCond = !musicInfo.uid.StartsWith($"{AlbumManager.Uid}-");
if (!runCond) Logger.Msg("Blocked thinking data post of custom chart.");
return runCond;
}
}

/// <summary>
/// Prevents the game from sending any analytics if the favorited chart is custom.
/// </summary>
[HarmonyPatch(typeof(ThinkingDataPeripheralHelper),
nameof(ThinkingDataPeripheralHelper.SendFavoriteMusicBehavior))]
internal class SendFavoriteMusicBehaviorPatch
{
private static bool Prefix(string dataStatisticsEventDefinesNameMusicInfo, MusicInfo musicInfo)
{
var runCond = !musicInfo.uid.StartsWith($"{AlbumManager.Uid}-");
if (!runCond) Logger.Msg("Blocked sending favorite chart analytics of custom chart.");
return runCond;
}
}


/// <summary>
/// Prevents the game from sending any analytics if the musicInfo is custom.
/// </summary>
[HarmonyPatch(typeof(ThinkingDataPeripheralHelper), nameof(ThinkingDataPeripheralHelper.PostMusicChooseInfo))]
internal class PostMusicChooseInfoPatch
{
private static bool Prefix(Vector2Int diffValue, string chooseMusicType, string searchName, MusicInfo musicInfo)
{
var runCond = !musicInfo.uid.StartsWith($"{AlbumManager.Uid}-");
if (!runCond) Logger.Msg("Blocked sending chosen music from search analytics of custom chart.");
return runCond;
}
}

/// <summary>
/// Cleans search result analytics of custom charts.
/// </summary>
[HarmonyPatch(typeof(ThinkingDataPeripheralHelper), nameof(ThinkingDataPeripheralHelper.GetSearchResultInfo))]
internal class GetSearchResultInfoPatch
{

private static bool Prefix(MusicInfo musicInfo)
{
var runCond = !musicInfo.uid.StartsWith($"{AlbumManager.Uid}-");
if (runCond) return true;

Logger.Msg("Blocking custom album from being added to search analytics.");
return false;
}
}
}
}
89 changes: 38 additions & 51 deletions Patches/SavePatch.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text.Json.Nodes;
using CustomAlbums.Data;
using CustomAlbums.Managers;
using CustomAlbums.Utilities;
using HarmonyLib;
Expand All @@ -13,7 +13,6 @@
using Il2CppAssets.Scripts.PeroTools.Commons;
using Il2CppAssets.Scripts.PeroTools.Platforms.Steam;
using Il2CppAssets.Scripts.Structs;
using Il2CppAssets.Scripts.UI.Panels;
using Il2CppInterop.Common;
using Il2CppPeroPeroGames.DataStatistics;
using MelonLoader.NativeUtils;
Expand Down Expand Up @@ -53,7 +52,7 @@ internal static class SavePatch
/// <param name="panel">The PnlRecord instance to set.</param>
/// <param name="data">The custom chart data.</param>
/// <param name="isFullCombo">If the selected chart has been FCed.</param>
private static void SetPanelWithData(PnlRecord panel, JsonNode data, bool isFullCombo)
private static void SetPanelWithData(PnlRecord panel, CustomChartSave data, bool isFullCombo)
{
// Enables the FC icon if chart has been FCed
// Also sets the combo text to a gold color if it has been FCed
Expand All @@ -64,13 +63,13 @@ private static void SetPanelWithData(PnlRecord panel, JsonNode data, bool isFull
}

// Sets all the PnlRecord data to custom chart data.
var evaluate = data["Evaluate"]!.GetValue<int>();
panel.txtAccuracy.text = data["AccuracyStr"]!.GetValue<string>();
panel.txtClear.text = data["Clear"]!.GetValue<float>().ToStringInvariant();
panel.txtCombo.text = data["Combo"]!.GetValue<int>().ToStringInvariant();
var evaluate = data.Evaluate;
panel.txtAccuracy.text = data.AccuracyStr;
panel.txtClear.text = data.Clear.ToStringInvariant();
panel.txtCombo.text = data.Combo.ToStringInvariant();
panel.txtGrade.text = EvalToGrade[evaluate];
panel.txtGrade.color = panel.gradeColor[evaluate];
panel.txtScore.text = data["Score"]!.GetValue<int>().ToStringInvariant();
panel.txtScore.text = data.Score.ToStringInvariant();
}

/// <summary>
Expand Down Expand Up @@ -114,37 +113,30 @@ private static bool InjectPnlPreparation(PnlPreparation __instance, bool forceRe
{
var currentMusicInfo = GlobalDataBase.s_DbMusicTag.CurMusicInfo();

// If the chart is not custom, run the original method, otherwise continue and don't run the original method
// If the chart is not custom, run the original method; otherwise, run our modified one
if (currentMusicInfo.albumJsonIndex != AlbumManager.Uid + 1) return true;

// Reset the panel to its default
ClearAndRefreshPanels(__instance, forceReload);
__instance.designerLongNameController?.Refresh();

if (!ModSettings.SavingEnabled) return false;

var recordPanel = __instance.pnlRecord;
var currentChartData = SaveData.GetChartSaveDataFromUid(currentMusicInfo.uid);
var highestExists = currentChartData.TryGetPropertyValue("Highest", out var currentChartHighest);

// If no highest data exists then early return
if (!highestExists || currentChartHighest is null)
if ((currentChartData.Highest?.Count ?? 0) == 0)
{
Logger.Msg($"No save data found for {currentMusicInfo.uid}, nothing to inject");
return false;
}

var difficulty = GetDifficulty(currentMusicInfo.uid);

currentChartData.TryGetPropertyValue("FullCombo", out var currentChartFullCombo);

// LINQ query to see if difficulty is in the full combo list
// If currentChartFullCombo is null then there is no full combo so isFullCombo is false
var isFullCombo = currentChartFullCombo?.AsArray().Any(x => (int)x == difficulty) ?? false;

// Get the highest score for the difficulty that is selected
currentChartHighest = currentChartHighest[difficulty.ToString()];
var isFullCombo = currentChartData.FullCombo?.Contains(difficulty) ?? false;
var currentChartHighest = currentChartData.Highest.GetValueOrDefault(difficulty);

// If the current chart has no data for the selected difficulty then early return
if (currentChartHighest is null)
{
Logger.Msg($"Save data was found for the chart, but not for difficulty {difficulty}");
Expand Down Expand Up @@ -210,7 +202,6 @@ private static void CleanCustomData()

if (ModSettings.SavingEnabled) SaveData.SelectedAlbum = AlbumManager.GetAlbumNameFromUid(DataHelper.selectedMusicUidFromInfoList);
DataHelper.selectedMusicUidFromInfoList = "0-0";
DataHelper.unlockMasters.RemoveAll((Il2CppSystem.Predicate<string>)(uid => uid.StartsWith($"{AlbumManager.Uid}-")));
}

private static void InjectCustomData()
Expand All @@ -220,30 +211,44 @@ private static void InjectCustomData()
DataHelper.hides.AddManagedRange(SaveData.Hides.GetAlbumUidsFromNames());
DataHelper.history.AddManagedRange(SaveData.History.GetAlbumUidsFromNames());
DataHelper.collections.AddManagedRange(SaveData.Collections.GetAlbumUidsFromNames());
DataHelper.unlockMasters.AddManagedRange(SaveData.UnlockedMasters.GetAlbumUidsFromNames());

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

// Dumb hack that fixes the chart appearing locked on game start even if it is unlocked
[HarmonyPatch(typeof(PnlStage), nameof(PnlStage.Start))]
internal class StartPatch
[HarmonyPatch(typeof(DataHelper), nameof(DataHelper.CheckMusicUnlockMaster))]
internal class CheckUnlockMasterPatch
{
private static void Postfix(PnlStage __instance)
private static bool Prefix(MusicInfo musicInfo, ref bool __result)
{
var uid = DataHelper.selectedMusicUid;
if (!DataHelper.selectedMusicUid?.StartsWith($"{AlbumManager.Uid}-") ?? true) return;
SaveData.Ability = Math.Max(SaveData.Ability, GlobalDataBase.dbUi.ability);
var ability = GameAccountSystem.instance.IsLoggedIn() ? SaveData.Ability : 0;
var uid = musicInfo?.uid;

var album = AlbumManager.GetByUid(uid);
// If musicInfo or uid is null, run original
if (uid is null) return true;

if (album == null || (!DataHelper.isUnlockAllMaster && !SaveData.UnlockedMasters.Contains(album!.AlbumName))) return;
// Bugged vanilla state, do manual logic
if (GlobalDataBase.dbUi.ability == 0 && ability != 0)
{
Logger.Msg("Fixing bugged vanilla state for master lock");
var vanillaParse = Formatting.TryParseAsInt(musicInfo.difficulty3, out var difficulty);
var cond = !vanillaParse || ability >= difficulty;
__result = cond || DataHelper.unlockMasters.Contains(uid) || SaveData.UnlockedMasters.Contains(AlbumManager.GetAlbumNameFromUid(uid)) || (!AlbumManager.GetByUid(musicInfo.uid)?.IsPackaged ?? false);
return false;
}

__instance.difficulty3Lock.SetActive(false);
__instance.difficulty3Master.SetActive(true);
__instance.difficulty3.enabled = true;
// Non-bugged vanilla case
if (!uid.StartsWith($"{AlbumManager.Uid}-")) return true;

// Non-bugged custom case
var successParse = Formatting.TryParseAsInt(musicInfo.difficulty3, out var diffNum);
var abilityConditionOrGimmick = !successParse || ability >= diffNum;

__result = abilityConditionOrGimmick || SaveData.UnlockedMasters.Contains(AlbumManager.GetAlbumNameFromUid(uid)) || !AlbumManager.GetByUid(musicInfo.uid).IsPackaged;
return false;
}
}

Expand Down Expand Up @@ -395,24 +400,6 @@ private static void Postfix(string musicUid, int musicDifficulty, string charact
}
}

/// <summary>
/// Stops the game from sending analytics of custom charts.
/// </summary>
[HarmonyPatch(typeof(ThinkingDataBattleHelper))]
internal class SendMDPatch
{
private static MethodInfo[] TargetMethods()
{
return typeof(ThinkingDataBattleHelper).GetMethods(BindingFlags.Instance | BindingFlags.Public)
.Where(method => method.Name.StartsWith("Send")).ToArray();
}

private static bool Prefix()
{
return !BattleHelper.MusicInfo().uid.StartsWith($"{AlbumManager.Uid}-");
}
}

/// <summary>
/// Enables the PnlVictory screen logic when the chart is custom.
/// </summary>
Expand Down
16 changes: 0 additions & 16 deletions Patches/TreeItemPatch.cs
Original file line number Diff line number Diff line change
@@ -1,22 +1,6 @@
using Il2Cpp;
using Il2CppAssets.Scripts.UI.Panels.PnlMusicTag;
using Il2CppSuperScrollView;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using CustomAlbums.Utilities;
using HarmonyLib;
using MelonLoader.NativeUtils;
using System.Runtime.InteropServices;
using Il2CppInterop.Common;
using System.Runtime.CompilerServices;
using CustomAlbums.Managers;
using Il2CppInterop.Runtime;
using Il2CppAssets.Scripts.Database;
using static MelonLoader.MelonLogger;

namespace CustomAlbums.Patches
{
Expand Down
Loading

0 comments on commit 9e44f69

Please sign in to comment.