From fefc398f07fb341b0194d77686b0205326d882da Mon Sep 17 00:00:00 2001 From: beerpsi Date: Thu, 23 May 2024 16:13:19 +0700 Subject: [PATCH] Refactor and support BepInEx's native plugin format --- Rizu.BepInEx/PatchGameScoreList.cs | 38 ++++++++ Rizu.BepInEx/PatchUserDetail.cs | 27 ++++++ .../Properties/AssemblyInfo.cs | 10 +-- Rizu.BepInEx/Rizu.BepInEx.csproj | 86 ++++++++++++++++++ Rizu.BepInEx/RizuPlugin.cs | 34 +++++++ Rizu.Core/Config.cs | 13 +++ {Rizu => Rizu.Core}/Exporter.cs | 32 +++---- .../ForceAcceptAllCertificateHandler.cs | 2 +- {Rizu => Rizu.Core}/Logger.cs | 5 +- {Rizu => Rizu.Core}/Models/BatchManual.cs | 2 +- {Rizu => Rizu.Core}/Models/BatchManualDan.cs | 2 +- .../Models/BatchManualMatchingClass.cs | 2 +- {Rizu => Rizu.Core}/Models/BatchManualMeta.cs | 2 +- .../Models/BatchManualOptional.cs | 2 +- .../Models/BatchManualRankUp.cs | 2 +- .../Models/BatchManualResponseBody.cs | 2 +- .../Models/BatchManualScore.cs | 2 +- .../Models/BatchManualScoreJudgements.cs | 2 +- {Rizu => Rizu.Core}/Models/ImportDocument.cs | 2 +- .../Models/ImportErrContent.cs | 2 +- {Rizu => Rizu.Core}/Models/ImportProgress.cs | 2 +- .../Models/ImportStatusResponseBody.cs | 2 +- .../Models/SessionInfoReturn.cs | 2 +- {Rizu => Rizu.Core}/Models/TachiResponse.cs | 2 +- Rizu.Core/Properties/AssemblyInfo.cs | 35 ++++++++ .../Rizu.csproj => Rizu.Core/Rizu.Core.csproj | 42 +++------ {Rizu => Rizu.Core}/ScoreConversion.cs | 4 +- Rizu.MonoMod/ILRepack.targets | 23 +++++ Rizu.MonoMod/Properties/AssemblyInfo.cs | 35 ++++++++ {Rizu => Rizu.MonoMod}/Resources/Rizu.cfg | 0 Rizu.MonoMod/Rizu.MonoMod.csproj | 89 +++++++++++++++++++ Rizu.MonoMod/RizuMonoBehaviour.cs | 5 ++ {Rizu => Rizu.MonoMod}/patch_AmManager.cs | 7 +- Rizu.MonoMod/patch_GameScoreList.cs | 41 +++++++++ {Rizu => Rizu.MonoMod}/patch_UserDetail.cs | 21 ++--- Rizu.sln | 14 ++- Rizu/External/.gitkeep | 0 Rizu/patch_GameScoreList.cs | 30 ------- 38 files changed, 497 insertions(+), 126 deletions(-) create mode 100644 Rizu.BepInEx/PatchGameScoreList.cs create mode 100644 Rizu.BepInEx/PatchUserDetail.cs rename {Rizu => Rizu.BepInEx}/Properties/AssemblyInfo.cs (80%) create mode 100644 Rizu.BepInEx/Rizu.BepInEx.csproj create mode 100644 Rizu.BepInEx/RizuPlugin.cs create mode 100644 Rizu.Core/Config.cs rename {Rizu => Rizu.Core}/Exporter.cs (90%) rename {Rizu => Rizu.Core}/ForceAcceptAllCertificateHandler.cs (86%) rename {Rizu => Rizu.Core}/Logger.cs (94%) rename {Rizu => Rizu.Core}/Models/BatchManual.cs (82%) rename {Rizu => Rizu.Core}/Models/BatchManualDan.cs (70%) rename {Rizu => Rizu.Core}/Models/BatchManualMatchingClass.cs (74%) rename {Rizu => Rizu.Core}/Models/BatchManualMeta.cs (82%) rename {Rizu => Rizu.Core}/Models/BatchManualOptional.cs (78%) rename {Rizu => Rizu.Core}/Models/BatchManualRankUp.cs (82%) rename {Rizu => Rizu.Core}/Models/BatchManualResponseBody.cs (72%) rename {Rizu => Rizu.Core}/Models/BatchManualScore.cs (88%) rename {Rizu => Rizu.Core}/Models/BatchManualScoreJudgements.cs (82%) rename {Rizu => Rizu.Core}/Models/ImportDocument.cs (82%) rename {Rizu => Rizu.Core}/Models/ImportErrContent.cs (75%) rename {Rizu => Rizu.Core}/Models/ImportProgress.cs (75%) rename {Rizu => Rizu.Core}/Models/ImportStatusResponseBody.cs (82%) rename {Rizu => Rizu.Core}/Models/SessionInfoReturn.cs (75%) rename {Rizu => Rizu.Core}/Models/TachiResponse.cs (78%) create mode 100644 Rizu.Core/Properties/AssemblyInfo.cs rename Rizu/Rizu.csproj => Rizu.Core/Rizu.Core.csproj (70%) rename {Rizu => Rizu.Core}/ScoreConversion.cs (96%) create mode 100644 Rizu.MonoMod/ILRepack.targets create mode 100644 Rizu.MonoMod/Properties/AssemblyInfo.cs rename {Rizu => Rizu.MonoMod}/Resources/Rizu.cfg (100%) create mode 100644 Rizu.MonoMod/Rizu.MonoMod.csproj create mode 100644 Rizu.MonoMod/RizuMonoBehaviour.cs rename {Rizu => Rizu.MonoMod}/patch_AmManager.cs (71%) create mode 100644 Rizu.MonoMod/patch_GameScoreList.cs rename {Rizu => Rizu.MonoMod}/patch_UserDetail.cs (54%) delete mode 100644 Rizu/External/.gitkeep delete mode 100644 Rizu/patch_GameScoreList.cs diff --git a/Rizu.BepInEx/PatchGameScoreList.cs b/Rizu.BepInEx/PatchGameScoreList.cs new file mode 100644 index 0000000..f3bf43c --- /dev/null +++ b/Rizu.BepInEx/PatchGameScoreList.cs @@ -0,0 +1,38 @@ +using System.Reflection; +using Game; +using HarmonyLib; +using Manager; +using Rizu.Core; + +namespace Rizu.BepInEx; + +[HarmonyPatch(typeof(GameScoreList))] +public class PatchGameScoreList +{ + // New field introduced in SDEZ 1.40 (maimai DX BUDDiES) + private static readonly FieldInfo UtageKanjiTextField = typeof(SessionInfo) + .GetField("utageKanjiText", BindingFlags.Instance | BindingFlags.Public); + + // ReSharper disable once InconsistentNaming + [HarmonyPatch(nameof(GameScoreList.SetPlayAfterRate))] + [HarmonyPostfix] + private static void SetPlayAfterRatePostfix(GameScoreList __instance, int musicRate, int danRate, UdemaeID dan, int classValue) + { + if (!__instance.IsEnable) + { + return; + } + + if (__instance.SessionInfo.isAdvDemo || __instance.SessionInfo.isTutorial) + { + return; + } + + if (UtageKanjiTextField != null && !string.IsNullOrEmpty((string)UtageKanjiTextField.GetValue(__instance.SessionInfo))) + { + return; + } + + RizuPlugin.Instance.StartCoroutine(Exporter.Instance.ExportScore(__instance)); + } +} \ No newline at end of file diff --git a/Rizu.BepInEx/PatchUserDetail.cs b/Rizu.BepInEx/PatchUserDetail.cs new file mode 100644 index 0000000..73f0bdc --- /dev/null +++ b/Rizu.BepInEx/PatchUserDetail.cs @@ -0,0 +1,27 @@ +using HarmonyLib; +using Manager.UserDatas; +using Rizu.Core; + +namespace Rizu.BepInEx; + +[HarmonyPatch(typeof(UserDetail))] +public class PatchUserDetail +{ + // ReSharper disable once InconsistentNaming + [HarmonyPatch(nameof(UserDetail.CourseRank), MethodType.Setter)] + [HarmonyPrefix] + private static bool CourseRankPrefix(UserDetail __instance, ref uint value) + { + var previousValue = __instance.CourseRank; + + // Don't send an import if it's the same rank + if (value == previousValue || value == 0) + { + return true; + } + + RizuPlugin.Instance.StartCoroutine(Exporter.Instance.ExportDan(__instance)); + + return true; + } +} \ No newline at end of file diff --git a/Rizu/Properties/AssemblyInfo.cs b/Rizu.BepInEx/Properties/AssemblyInfo.cs similarity index 80% rename from Rizu/Properties/AssemblyInfo.cs rename to Rizu.BepInEx/Properties/AssemblyInfo.cs index 4ebea15..8ef4884 100644 --- a/Rizu/Properties/AssemblyInfo.cs +++ b/Rizu.BepInEx/Properties/AssemblyInfo.cs @@ -4,12 +4,12 @@ using System.Runtime.InteropServices; // General Information about an assembly is controlled through the following // set of attributes. Change these attribute values to modify the information // associated with an assembly. -[assembly: AssemblyTitle("Rizu")] -[assembly: AssemblyDescription("")] +[assembly: AssemblyTitle("Rizu.BepInEx")] +[assembly: AssemblyDescription("Tachi score hook for maimai DX")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("Rizu")] -[assembly: AssemblyCopyright("Copyright © 2024")] +[assembly: AssemblyCopyright("Copyright © beerpsi 2024")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] @@ -31,5 +31,5 @@ using System.Runtime.InteropServices; // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] \ No newline at end of file +[assembly: AssemblyVersion("0.1.1.0")] +[assembly: AssemblyFileVersion("0.1.1.0")] \ No newline at end of file diff --git a/Rizu.BepInEx/Rizu.BepInEx.csproj b/Rizu.BepInEx/Rizu.BepInEx.csproj new file mode 100644 index 0000000..bdb0969 --- /dev/null +++ b/Rizu.BepInEx/Rizu.BepInEx.csproj @@ -0,0 +1,86 @@ + + + + + Debug + AnyCPU + {4DDF918E-7A74-4266-B56A-028D66ED336F} + Library + Properties + Rizu.BepInEx + Rizu + Rizu + 0.1.1 + v4.6.2 + 512 + latest + + https://api.nuget.org/v3/index.json; + https://nuget.bepinex.dev/v3/index.json + + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + ..\External\Assembly-CSharp.dll + False + + + ..\External\UnityEngine.dll + False + + + ..\External\UnityEngine.CoreModule.dll + False + + + + + + + + + + + {4241a369-1619-4450-8182-cb66f447985f} + Rizu.Core + + + + + + diff --git a/Rizu.BepInEx/RizuPlugin.cs b/Rizu.BepInEx/RizuPlugin.cs new file mode 100644 index 0000000..743f00b --- /dev/null +++ b/Rizu.BepInEx/RizuPlugin.cs @@ -0,0 +1,34 @@ +using BepInEx; +using HarmonyLib; +using Rizu.Core; + +namespace Rizu.BepInEx; + +[BepInPlugin(MyPluginInfo.PLUGIN_GUID, MyPluginInfo.PLUGIN_NAME, MyPluginInfo.PLUGIN_VERSION)] +[BepInProcess("Sinmai.exe")] +public class RizuPlugin : BaseUnityPlugin +{ + public static RizuPlugin Instance { get; private set; } + + private Harmony _harmony; + + private void Awake() + { + Instance = this; + + Exporter.Instance.LoadConfig(); + + if (!Exporter.Instance.IsEnabled) + { + return; + } + + _harmony = new Harmony(MyPluginInfo.PLUGIN_GUID); + _harmony.PatchAll(); + } + + private void OnDestroy() + { + _harmony?.UnpatchSelf(); + } +} \ No newline at end of file diff --git a/Rizu.Core/Config.cs b/Rizu.Core/Config.cs new file mode 100644 index 0000000..42d5ba0 --- /dev/null +++ b/Rizu.Core/Config.cs @@ -0,0 +1,13 @@ +using System.Collections.Generic; + +namespace Rizu.Core; + +public class Config +{ + public bool Enabled; + public int NetworkTimeout; + public string FailedImportsFolder; + public string TachiBaseUrl; + public string TachiImportEndpoint; + public Dictionary AccessTokens = new(); +} diff --git a/Rizu/Exporter.cs b/Rizu.Core/Exporter.cs similarity index 90% rename from Rizu/Exporter.cs rename to Rizu.Core/Exporter.cs index 74133e3..cedb595 100644 --- a/Rizu/Exporter.cs +++ b/Rizu.Core/Exporter.cs @@ -1,6 +1,5 @@ using System; using System.Collections; -using System.Collections.Generic; using System.IO; using System.Text; using System.Threading; @@ -8,19 +7,20 @@ using MAI2.Util; using MAI2System; using Manager; using Manager.UserDatas; -using Rizu.Models; +using Rizu.Core.Models; using UnityEngine; using UnityEngine.Networking; using Path = System.IO.Path; -namespace Rizu; +namespace Rizu.Core; -public class Exporter : SingletonMonoBehaviour +public class Exporter { - protected Exporter() - { - _dontDestroyOnLoad = true; - } + public static readonly Exporter Instance = new(); + + private readonly Config _config = new(); + + public bool IsEnabled => _config.Enabled; // ReSharper disable Unity.PerformanceAnalysis public IEnumerator ExportScore(GameScoreList score) @@ -199,7 +199,7 @@ public class Exporter : SingletonMonoBehaviour } } - private void SaveFailedImport(string path, string import) + private static void SaveFailedImport(string path, string import) { var parent = Path.GetDirectoryName(path); @@ -210,7 +210,7 @@ public class Exporter : SingletonMonoBehaviour File.WriteAllText(path, import); } - + public void LoadConfig() { using var ini = new IniFile(".\\Rizu.cfg"); @@ -239,16 +239,4 @@ public class Exporter : SingletonMonoBehaviour Logger.Info("> Tachi import URL: {0}{1}", _config.TachiBaseUrl, _config.TachiImportEndpoint); Logger.Info("> {0} API key{1} loaded", _config.AccessTokens.Count, _config.AccessTokens.Count != 1 ? "s" : ""); } - - private readonly Config _config = new(); - - private class Config - { - public bool Enabled; - public int NetworkTimeout; - public string FailedImportsFolder; - public string TachiBaseUrl; - public string TachiImportEndpoint; - public Dictionary AccessTokens = new(); - } } diff --git a/Rizu/ForceAcceptAllCertificateHandler.cs b/Rizu.Core/ForceAcceptAllCertificateHandler.cs similarity index 86% rename from Rizu/ForceAcceptAllCertificateHandler.cs rename to Rizu.Core/ForceAcceptAllCertificateHandler.cs index 0b3031a..702bfb2 100644 --- a/Rizu/ForceAcceptAllCertificateHandler.cs +++ b/Rizu.Core/ForceAcceptAllCertificateHandler.cs @@ -1,6 +1,6 @@ using UnityEngine.Networking; -namespace Rizu; +namespace Rizu.Core; public class ForceAcceptAllCertificateHandler : CertificateHandler { diff --git a/Rizu/Logger.cs b/Rizu.Core/Logger.cs similarity index 94% rename from Rizu/Logger.cs rename to Rizu.Core/Logger.cs index 4e6bb66..67abb26 100644 --- a/Rizu/Logger.cs +++ b/Rizu.Core/Logger.cs @@ -1,7 +1,7 @@ using System.Diagnostics; using JetBrains.Annotations; -namespace Rizu; +namespace Rizu.Core; // UnityEngine.Debug logs don't show up in BepInEx logs for some reason public static class Logger @@ -54,5 +54,4 @@ public static class Logger { System.Console.WriteLine($"{LogPrefix} [{level}] {format}", args); } - -} \ No newline at end of file +} diff --git a/Rizu/Models/BatchManual.cs b/Rizu.Core/Models/BatchManual.cs similarity index 82% rename from Rizu/Models/BatchManual.cs rename to Rizu.Core/Models/BatchManual.cs index e0e18bf..cb8a20f 100644 --- a/Rizu/Models/BatchManual.cs +++ b/Rizu.Core/Models/BatchManual.cs @@ -1,6 +1,6 @@ using System; -namespace Rizu.Models; +namespace Rizu.Core.Models; [Serializable] public class BatchManual diff --git a/Rizu/Models/BatchManualDan.cs b/Rizu.Core/Models/BatchManualDan.cs similarity index 70% rename from Rizu/Models/BatchManualDan.cs rename to Rizu.Core/Models/BatchManualDan.cs index 46a09a1..c27d419 100644 --- a/Rizu/Models/BatchManualDan.cs +++ b/Rizu.Core/Models/BatchManualDan.cs @@ -1,6 +1,6 @@ using System; -namespace Rizu.Models; +namespace Rizu.Core.Models; [Serializable] public class BatchManualDan diff --git a/Rizu/Models/BatchManualMatchingClass.cs b/Rizu.Core/Models/BatchManualMatchingClass.cs similarity index 74% rename from Rizu/Models/BatchManualMatchingClass.cs rename to Rizu.Core/Models/BatchManualMatchingClass.cs index f5cc639..7095b3d 100644 --- a/Rizu/Models/BatchManualMatchingClass.cs +++ b/Rizu.Core/Models/BatchManualMatchingClass.cs @@ -1,6 +1,6 @@ using System; -namespace Rizu.Models; +namespace Rizu.Core.Models; [Serializable] public class BatchManualMatchingClass diff --git a/Rizu/Models/BatchManualMeta.cs b/Rizu.Core/Models/BatchManualMeta.cs similarity index 82% rename from Rizu/Models/BatchManualMeta.cs rename to Rizu.Core/Models/BatchManualMeta.cs index 4ff3c03..a1081b0 100644 --- a/Rizu/Models/BatchManualMeta.cs +++ b/Rizu.Core/Models/BatchManualMeta.cs @@ -1,6 +1,6 @@ using System; -namespace Rizu.Models; +namespace Rizu.Core.Models; [Serializable] public class BatchManualMeta diff --git a/Rizu/Models/BatchManualOptional.cs b/Rizu.Core/Models/BatchManualOptional.cs similarity index 78% rename from Rizu/Models/BatchManualOptional.cs rename to Rizu.Core/Models/BatchManualOptional.cs index 4b7d61b..17f1764 100644 --- a/Rizu/Models/BatchManualOptional.cs +++ b/Rizu.Core/Models/BatchManualOptional.cs @@ -1,6 +1,6 @@ using System; -namespace Rizu.Models; +namespace Rizu.Core.Models; [Serializable] public class BatchManualOptional diff --git a/Rizu/Models/BatchManualRankUp.cs b/Rizu.Core/Models/BatchManualRankUp.cs similarity index 82% rename from Rizu/Models/BatchManualRankUp.cs rename to Rizu.Core/Models/BatchManualRankUp.cs index 0ef0131..5c72557 100644 --- a/Rizu/Models/BatchManualRankUp.cs +++ b/Rizu.Core/Models/BatchManualRankUp.cs @@ -1,6 +1,6 @@ using System; -namespace Rizu.Models; +namespace Rizu.Core.Models; [Serializable] public class BatchManualRankUp diff --git a/Rizu/Models/BatchManualResponseBody.cs b/Rizu.Core/Models/BatchManualResponseBody.cs similarity index 72% rename from Rizu/Models/BatchManualResponseBody.cs rename to Rizu.Core/Models/BatchManualResponseBody.cs index 7fa7acd..b2cd261 100644 --- a/Rizu/Models/BatchManualResponseBody.cs +++ b/Rizu.Core/Models/BatchManualResponseBody.cs @@ -1,6 +1,6 @@ using System; -namespace Rizu.Models; +namespace Rizu.Core.Models; [Serializable] public class BatchManualResponseBody diff --git a/Rizu/Models/BatchManualScore.cs b/Rizu.Core/Models/BatchManualScore.cs similarity index 88% rename from Rizu/Models/BatchManualScore.cs rename to Rizu.Core/Models/BatchManualScore.cs index 6a6cbf4..a7c72ea 100644 --- a/Rizu/Models/BatchManualScore.cs +++ b/Rizu.Core/Models/BatchManualScore.cs @@ -1,6 +1,6 @@ using System; -namespace Rizu.Models; +namespace Rizu.Core.Models; [Serializable] public class BatchManualScore diff --git a/Rizu/Models/BatchManualScoreJudgements.cs b/Rizu.Core/Models/BatchManualScoreJudgements.cs similarity index 82% rename from Rizu/Models/BatchManualScoreJudgements.cs rename to Rizu.Core/Models/BatchManualScoreJudgements.cs index 127352a..7b61af2 100644 --- a/Rizu/Models/BatchManualScoreJudgements.cs +++ b/Rizu.Core/Models/BatchManualScoreJudgements.cs @@ -1,6 +1,6 @@ using System; -namespace Rizu.Models; +namespace Rizu.Core.Models; [Serializable] public class BatchManualScoreJudgements diff --git a/Rizu/Models/ImportDocument.cs b/Rizu.Core/Models/ImportDocument.cs similarity index 82% rename from Rizu/Models/ImportDocument.cs rename to Rizu.Core/Models/ImportDocument.cs index 13dbce1..bb1f382 100644 --- a/Rizu/Models/ImportDocument.cs +++ b/Rizu.Core/Models/ImportDocument.cs @@ -1,6 +1,6 @@ using System; -namespace Rizu.Models; +namespace Rizu.Core.Models; [Serializable] public class ImportDocument diff --git a/Rizu/Models/ImportErrContent.cs b/Rizu.Core/Models/ImportErrContent.cs similarity index 75% rename from Rizu/Models/ImportErrContent.cs rename to Rizu.Core/Models/ImportErrContent.cs index 98ff261..816db5c 100644 --- a/Rizu/Models/ImportErrContent.cs +++ b/Rizu.Core/Models/ImportErrContent.cs @@ -1,6 +1,6 @@ using System; -namespace Rizu.Models; +namespace Rizu.Core.Models; [Serializable] public class ImportErrContent diff --git a/Rizu/Models/ImportProgress.cs b/Rizu.Core/Models/ImportProgress.cs similarity index 75% rename from Rizu/Models/ImportProgress.cs rename to Rizu.Core/Models/ImportProgress.cs index 22f36ae..555b45a 100644 --- a/Rizu/Models/ImportProgress.cs +++ b/Rizu.Core/Models/ImportProgress.cs @@ -1,6 +1,6 @@ using System; -namespace Rizu.Models; +namespace Rizu.Core.Models; [Serializable] public class ImportProgress diff --git a/Rizu/Models/ImportStatusResponseBody.cs b/Rizu.Core/Models/ImportStatusResponseBody.cs similarity index 82% rename from Rizu/Models/ImportStatusResponseBody.cs rename to Rizu.Core/Models/ImportStatusResponseBody.cs index 9aae759..af6994b 100644 --- a/Rizu/Models/ImportStatusResponseBody.cs +++ b/Rizu.Core/Models/ImportStatusResponseBody.cs @@ -1,6 +1,6 @@ using System; -namespace Rizu.Models; +namespace Rizu.Core.Models; [Serializable] public class ImportStatusResponseBody diff --git a/Rizu/Models/SessionInfoReturn.cs b/Rizu.Core/Models/SessionInfoReturn.cs similarity index 75% rename from Rizu/Models/SessionInfoReturn.cs rename to Rizu.Core/Models/SessionInfoReturn.cs index a8e6a9b..d8fecd0 100644 --- a/Rizu/Models/SessionInfoReturn.cs +++ b/Rizu.Core/Models/SessionInfoReturn.cs @@ -1,6 +1,6 @@ using System; -namespace Rizu.Models; +namespace Rizu.Core.Models; [Serializable] public class SessionInfoReturn diff --git a/Rizu/Models/TachiResponse.cs b/Rizu.Core/Models/TachiResponse.cs similarity index 78% rename from Rizu/Models/TachiResponse.cs rename to Rizu.Core/Models/TachiResponse.cs index 8c3abbf..aa31dcd 100644 --- a/Rizu/Models/TachiResponse.cs +++ b/Rizu.Core/Models/TachiResponse.cs @@ -1,6 +1,6 @@ using System; -namespace Rizu.Models; +namespace Rizu.Core.Models; [Serializable] public class TachiResponse diff --git a/Rizu.Core/Properties/AssemblyInfo.cs b/Rizu.Core/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..57ef573 --- /dev/null +++ b/Rizu.Core/Properties/AssemblyInfo.cs @@ -0,0 +1,35 @@ +using System.Reflection; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("Rizu.Core")] +[assembly: AssemblyDescription("Tachi score hook for maimai DX")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("Rizu.Core")] +[assembly: AssemblyCopyright("Copyright © beerpsi 2024")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("4241A369-1619-4450-8182-CB66F447985F")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("0.1.1.0")] +[assembly: AssemblyFileVersion("0.1.1.0")] \ No newline at end of file diff --git a/Rizu/Rizu.csproj b/Rizu.Core/Rizu.Core.csproj similarity index 70% rename from Rizu/Rizu.csproj rename to Rizu.Core/Rizu.Core.csproj index 417271c..c6c17b2 100644 --- a/Rizu/Rizu.csproj +++ b/Rizu.Core/Rizu.Core.csproj @@ -5,20 +5,15 @@ Debug AnyCPU - {888E076C-8A77-453F-87DC-BC0186FDBB55} + {4241A369-1619-4450-8182-CB66F447985F} Library Properties - Rizu - Assembly-CSharp.Rizu.mm - net46 + Rizu.Core + Rizu.Core + 0.1.1 + v4.6.2 512 latest - - https://api.nuget.org/v3/index.json; - https://nuget.bepinex.dev/v3/index.json; - https://nuget.samboy.dev/v3/index.json - - true AnyCPU @@ -40,38 +35,30 @@ 4 - - - External\Assembly-CSharp.dll - False - - - External\MonoMod.exe - False - - - External\UnityEngine.dll + ..\External\Assembly-CSharp.dll False - External\UnityEngine.CoreModule.dll + ..\External\UnityEngine.CoreModule.dll False - External\UnityEngine.JSONSerializeModule.dll + ..\External\UnityEngine.JSONSerializeModule.dll False - External\UnityEngine.UnityWebRequestModule.dll + ..\External\UnityEngine.UnityWebRequestModule.dll False + + @@ -89,16 +76,9 @@ - - - - - - - + + + + + + + + + + + + + + diff --git a/Rizu.MonoMod/Properties/AssemblyInfo.cs b/Rizu.MonoMod/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..bf4f1db --- /dev/null +++ b/Rizu.MonoMod/Properties/AssemblyInfo.cs @@ -0,0 +1,35 @@ +using System.Reflection; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("Rizu.MonoMod")] +[assembly: AssemblyDescription("Tachi score hook for maimai DX")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("Rizu")] +[assembly: AssemblyCopyright("Copyright © beerpsi 2024")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("888E076C-8A77-453F-87DC-BC0186FDBB55")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("0.1.1.0")] +[assembly: AssemblyFileVersion("0.1.1.0")] \ No newline at end of file diff --git a/Rizu/Resources/Rizu.cfg b/Rizu.MonoMod/Resources/Rizu.cfg similarity index 100% rename from Rizu/Resources/Rizu.cfg rename to Rizu.MonoMod/Resources/Rizu.cfg diff --git a/Rizu.MonoMod/Rizu.MonoMod.csproj b/Rizu.MonoMod/Rizu.MonoMod.csproj new file mode 100644 index 0000000..bb459ed --- /dev/null +++ b/Rizu.MonoMod/Rizu.MonoMod.csproj @@ -0,0 +1,89 @@ + + + + + Debug + AnyCPU + {888E076C-8A77-453F-87DC-BC0186FDBB55} + Library + Properties + Rizu.MonoMod + Rizu.MonoMod + 0.1.1 + v4.6.2 + 512 + latest + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + ..\External\Assembly-CSharp.dll + False + + + ..\External\MonoMod.exe + False + + + ..\External\UnityEngine.dll + False + + + ..\External\UnityEngine.CoreModule.dll + False + + + + + + + + + + + + + + + + {4241a369-1619-4450-8182-cb66f447985f} + Rizu.Core + + + + + + + + diff --git a/Rizu.MonoMod/RizuMonoBehaviour.cs b/Rizu.MonoMod/RizuMonoBehaviour.cs new file mode 100644 index 0000000..b65785f --- /dev/null +++ b/Rizu.MonoMod/RizuMonoBehaviour.cs @@ -0,0 +1,5 @@ +using MAI2.Util; + +namespace Rizu.MonoMod; + +public class RizuMonoBehaviour : SingletonMonoBehaviour; diff --git a/Rizu/patch_AmManager.cs b/Rizu.MonoMod/patch_AmManager.cs similarity index 71% rename from Rizu/patch_AmManager.cs rename to Rizu.MonoMod/patch_AmManager.cs index 2c569bb..fa2c523 100644 --- a/Rizu/patch_AmManager.cs +++ b/Rizu.MonoMod/patch_AmManager.cs @@ -1,7 +1,7 @@ // ReSharper disable CheckNamespace // ReSharper disable InconsistentNaming -using MAI2.Util; +using Rizu.Core; using UnityEngine; namespace Manager; @@ -13,8 +13,9 @@ public class patch_AmManager : AmManager private void Execute_WaitAmDaemonReady() { var go = new GameObject { name = "Rizu" }; - go.AddComponent(); - SingletonMonoBehaviour.instance.LoadConfig(); + go.AddComponent(); + + Exporter.Instance.LoadConfig(); orig_Execute_WaitAmDaemonReady(); } diff --git a/Rizu.MonoMod/patch_GameScoreList.cs b/Rizu.MonoMod/patch_GameScoreList.cs new file mode 100644 index 0000000..862432a --- /dev/null +++ b/Rizu.MonoMod/patch_GameScoreList.cs @@ -0,0 +1,41 @@ +// ReSharper disable CheckNamespace +// ReSharper disable InconsistentNaming + +using System.Reflection; +using Game; +using MAI2.Util; +using Rizu.Core; +using Rizu.MonoMod; + +namespace Manager; + +public class patch_GameScoreList(int index) : GameScoreList(index) +{ + // New field introduced in SDEZ 1.40 (maimai DX BUDDiES) + private static readonly FieldInfo utageKanjiTextField = typeof(SessionInfo) + .GetField("utageKanjiText", BindingFlags.Instance | BindingFlags.Public); + + private extern void orig_SetPlayAfterRate(int musicRate, int danRate, UdemaeID dan, int classValue); + + public new void SetPlayAfterRate(int musicRate, int danRate, UdemaeID dan, int classValue) + { + orig_SetPlayAfterRate(musicRate, danRate, dan, classValue); + + if (!IsEnable) + { + return; + } + + if (SessionInfo.isAdvDemo || SessionInfo.isTutorial) + { + return; + } + + if (utageKanjiTextField != null && !string.IsNullOrEmpty((string)utageKanjiTextField.GetValue(SessionInfo))) + { + return; + } + + SingletonMonoBehaviour.instance.StartCoroutine(Exporter.Instance.ExportScore(this)); + } +} diff --git a/Rizu/patch_UserDetail.cs b/Rizu.MonoMod/patch_UserDetail.cs similarity index 54% rename from Rizu/patch_UserDetail.cs rename to Rizu.MonoMod/patch_UserDetail.cs index 5c98f99..836de17 100644 --- a/Rizu/patch_UserDetail.cs +++ b/Rizu.MonoMod/patch_UserDetail.cs @@ -2,6 +2,8 @@ // ReSharper disable InconsistentNaming using MAI2.Util; +using Rizu.Core; +using Rizu.MonoMod; namespace Manager.UserDatas; @@ -11,23 +13,16 @@ public class patch_UserDetail : UserDetail public void set_CourseRank(uint value) { - // Don't send an import if it's the same rank - if (value == CourseRank) - { - orig_set_CourseRank(value); - return; - } + var prevValue = CourseRank; orig_set_CourseRank(value); - - // Don't send an import if it's rank 0 (invalid) - if (value == 0) + + // Don't send an import if it's the same rank + if (value == prevValue || value == 0) { return; } - - var exporter = SingletonMonoBehaviour.instance; - - exporter.StartCoroutine(exporter.ExportDan(this)); + + SingletonMonoBehaviour.instance.StartCoroutine(Exporter.Instance.ExportDan(this)); } } diff --git a/Rizu.sln b/Rizu.sln index 7519b97..1738134 100644 --- a/Rizu.sln +++ b/Rizu.sln @@ -1,6 +1,10 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Rizu", "Rizu\Rizu.csproj", "{888E076C-8A77-453F-87DC-BC0186FDBB55}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Rizu.Core", "Rizu.Core\Rizu.Core.csproj", "{4241A369-1619-4450-8182-CB66F447985F}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Rizu.MonoMod", "Rizu.MonoMod\Rizu.MonoMod.csproj", "{888E076C-8A77-453F-87DC-BC0186FDBB55}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Rizu.BepInEx", "Rizu.BepInEx\Rizu.BepInEx.csproj", "{4DDF918E-7A74-4266-B56A-028D66ED336F}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -8,9 +12,17 @@ Global Release|Any CPU = Release|Any CPU EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution + {4241A369-1619-4450-8182-CB66F447985F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {4241A369-1619-4450-8182-CB66F447985F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {4241A369-1619-4450-8182-CB66F447985F}.Release|Any CPU.ActiveCfg = Release|Any CPU + {4241A369-1619-4450-8182-CB66F447985F}.Release|Any CPU.Build.0 = Release|Any CPU {888E076C-8A77-453F-87DC-BC0186FDBB55}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {888E076C-8A77-453F-87DC-BC0186FDBB55}.Debug|Any CPU.Build.0 = Debug|Any CPU {888E076C-8A77-453F-87DC-BC0186FDBB55}.Release|Any CPU.ActiveCfg = Release|Any CPU {888E076C-8A77-453F-87DC-BC0186FDBB55}.Release|Any CPU.Build.0 = Release|Any CPU + {4DDF918E-7A74-4266-B56A-028D66ED336F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {4DDF918E-7A74-4266-B56A-028D66ED336F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {4DDF918E-7A74-4266-B56A-028D66ED336F}.Release|Any CPU.ActiveCfg = Release|Any CPU + {4DDF918E-7A74-4266-B56A-028D66ED336F}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection EndGlobal diff --git a/Rizu/External/.gitkeep b/Rizu/External/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/Rizu/patch_GameScoreList.cs b/Rizu/patch_GameScoreList.cs deleted file mode 100644 index 7631fa2..0000000 --- a/Rizu/patch_GameScoreList.cs +++ /dev/null @@ -1,30 +0,0 @@ -// ReSharper disable CheckNamespace -// ReSharper disable InconsistentNaming - -using MAI2.Util; - -namespace Manager; - -public class patch_GameScoreList(int index) : GameScoreList(index) -{ - private extern void orig_SetPlayAfterRate(int musicRate, int danRate, UdemaeID dan, int classValue); - - public new void SetPlayAfterRate(int musicRate, int danRate, UdemaeID dan, int classValue) - { - orig_SetPlayAfterRate(musicRate, danRate, dan, classValue); - - if (!IsEnable) - { - return; - } - - if (SessionInfo.isAdvDemo || SessionInfo.isTutorial || !string.IsNullOrEmpty(SessionInfo.utageKanjiText)) - { - return; - } - - var exporter = SingletonMonoBehaviour.instance; - - exporter.StartCoroutine(exporter.ExportScore(this)); - } -}