From 1023dee2b785a7ecf2ef724aab3a35baa31eeff9 Mon Sep 17 00:00:00 2001 From: akanyan Date: Mon, 22 Jul 2024 21:58:17 +0900 Subject: [PATCH 1/3] chore: fix the branch --- AttractVideoPlayer/AttractVideoPlayer.csproj | 13 ++++ .../patch_OperationManager.cs | 54 +++++++++++++++ .../MU3.Sequence/patch_Advertise.cs | 28 ++++++++ AttractVideoPlayer/MU3/patch_AdvManager.cs | 66 +++++++++++++++++++ Mu3Mods.sln | 6 ++ 5 files changed, 167 insertions(+) create mode 100644 AttractVideoPlayer/AttractVideoPlayer.csproj create mode 100644 AttractVideoPlayer/MU3.OperationManager/patch_OperationManager.cs create mode 100644 AttractVideoPlayer/MU3.Sequence/patch_Advertise.cs create mode 100644 AttractVideoPlayer/MU3/patch_AdvManager.cs diff --git a/AttractVideoPlayer/AttractVideoPlayer.csproj b/AttractVideoPlayer/AttractVideoPlayer.csproj new file mode 100644 index 0000000..579a70e --- /dev/null +++ b/AttractVideoPlayer/AttractVideoPlayer.csproj @@ -0,0 +1,13 @@ + + + Assembly-CSharp.AttractVideoPlayer.mm + Control attract video + + + + + 2.0 + {6889330F-2E7E-4778-ADFF-70AF036F1BD5} + + + \ No newline at end of file diff --git a/AttractVideoPlayer/MU3.OperationManager/patch_OperationManager.cs b/AttractVideoPlayer/MU3.OperationManager/patch_OperationManager.cs new file mode 100644 index 0000000..4864ed1 --- /dev/null +++ b/AttractVideoPlayer/MU3.OperationManager/patch_OperationManager.cs @@ -0,0 +1,54 @@ +using MU3.Operation; +using MU3.SceneObject; +using MU3.Sequence; +using MU3.Util; +using System.Collections.ObjectModel; +using UnityEngine; + +namespace MU3.Operation; + +class patch_OperationManager: OperationManager +{ + private static readonly string CurrentSongIndexFilePath = "BepInEx/monomod/AttractVideoPlayer.currentSongIndex.txt"; + private ReadOnlyCollection _movieDataList; + public new MovieData movieData + { + get + { + if (_movieDataList.Count > 0) + { + int currentSongIndex = 0; + try + { + currentSongIndex = int.Parse(System.IO.File.ReadAllText(CurrentSongIndexFilePath)); + } + catch (System.Exception) + { + saveCurrentSongIndex(0); + } + + if (currentSongIndex < 0) + { + currentSongIndex = _movieDataList.Count - 1; + saveCurrentSongIndex(currentSongIndex); + } + + if (currentSongIndex >= _movieDataList.Count) + { + currentSongIndex = 0; + saveCurrentSongIndex(currentSongIndex); + } + + Debug.Log("currentSongIndex: " + currentSongIndex); + + return _movieDataList[currentSongIndex]; + } + return null; + } + } + + private void saveCurrentSongIndex(int currentSongIndex) + { + System.IO.File.WriteAllText(CurrentSongIndexFilePath, currentSongIndex.ToString()); + } +} \ No newline at end of file diff --git a/AttractVideoPlayer/MU3.Sequence/patch_Advertise.cs b/AttractVideoPlayer/MU3.Sequence/patch_Advertise.cs new file mode 100644 index 0000000..cdac034 --- /dev/null +++ b/AttractVideoPlayer/MU3.Sequence/patch_Advertise.cs @@ -0,0 +1,28 @@ +using Mono.Cecil; +using MU3.AM; +using MU3.Operation; +using MU3.SceneObject; +using MU3.Sequence; +using MU3.Util; +using UnityEngine; + +namespace MU3.Sequence; + +class patch_Advertise : Advertise +{ + private bool checkButtonOrAime() + { + if (SingletonStateMachine.instance.aimeReader.advCheck()) + { + Singleton.instance.loginType = OperationManager.LoginType.Aime; + return true; + } + UIInput instance = Singleton.instance; + if (instance.getTriggerOn(UIInput.Key.Decision) || instance.getTriggerOn(UIInput.Key.OptionBackward) || instance.getTriggerOn(UIInput.Key.OptionForward) || instance.getTriggerOn(UIInput.Key.SkipRight) || instance.getTriggerOn(UIInput.Key.MenuLeft) || instance.getTriggerOn(UIInput.Key.MenuRight)) + { + Singleton.instance.loginType = OperationManager.LoginType.Button; + return true; + } + return false; + } +} \ No newline at end of file diff --git a/AttractVideoPlayer/MU3/patch_AdvManager.cs b/AttractVideoPlayer/MU3/patch_AdvManager.cs new file mode 100644 index 0000000..c2a5fe6 --- /dev/null +++ b/AttractVideoPlayer/MU3/patch_AdvManager.cs @@ -0,0 +1,66 @@ +using Mono.Cecil; +using MU3.Operation; +using MU3.SceneObject; +using MU3.Sequence; +using MU3.Util; +using UnityEngine; + +namespace MU3; + +class patch_AdvManager : AdvManager +{ + private static readonly string CurrentSongIndexFilePath = "BepInEx/monomod/AttractVideoPlayer.currentSongIndex.txt"; + private static readonly float DelayBetweenButtonPress = 0.5f; + private float lastButtonPressedTime = 0f; + + private GameObject objMovie; + private CriManaMovieMaterial movieController; + private extern bool orig_initMovie(); + public new bool initMovie() + { + return orig_initMovie(); + } + + private extern bool orig_exec(); + public new bool exec() + { + if (Time.time - lastButtonPressedTime > DelayBetweenButtonPress) + { + if (Singleton.instance.getStateOn(UIInput.Key.Service)) + { + lastButtonPressedTime = Time.time; + + movieController?.player.Pause(!movieController.player.IsPaused()); + } + else if (Singleton.instance.getStateOn(UIInput.Key.L2)) + { + lastButtonPressedTime = Time.time; + + addOffsetToCurrentSongIndexAndPlayMovie(-1); + } + else if (Singleton.instance.getStateOn(UIInput.Key.L3)) + { + lastButtonPressedTime = Time.time; + + addOffsetToCurrentSongIndexAndPlayMovie(1); + } + } + + return orig_exec(); + } + public void addOffsetToCurrentSongIndexAndPlayMovie(int offset) + { + try + { + int currentSongIndex = int.Parse(System.IO.File.ReadAllText(CurrentSongIndexFilePath)) + offset; + System.IO.File.WriteAllText(CurrentSongIndexFilePath, currentSongIndex.ToString()); + } + catch (System.Exception) { } + + movieController?.Stop(); + Utility.destroyGameObject(ref movieController); + Utility.destroyGameObject(ref objMovie); + + initMovie(); + } +} \ No newline at end of file diff --git a/Mu3Mods.sln b/Mu3Mods.sln index 1e8bb06..9c71b3d 100644 --- a/Mu3Mods.sln +++ b/Mu3Mods.sln @@ -39,6 +39,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UnlockMemoryChapters", "Unl EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PlatinumTiming", "PlatinumTiming\PlatinumTiming.csproj", "{099AD6AF-181A-4745-88C4-1D0466BECCB1}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AttractVideoPlayer", "AttractVideoPlayer\AttractVideoPlayer.csproj", "{6889330F-2E7E-4778-ADFF-70AF036F1BD5}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|x64 = Debug|x64 @@ -117,6 +119,10 @@ Global {099AD6AF-181A-4745-88C4-1D0466BECCB1}.Debug|x64.Build.0 = Debug|x64 {099AD6AF-181A-4745-88C4-1D0466BECCB1}.Release|x64.ActiveCfg = Release|x64 {099AD6AF-181A-4745-88C4-1D0466BECCB1}.Release|x64.Build.0 = Release|x64 + {6889330F-2E7E-4778-ADFF-70AF036F1BD5}.Debug|x64.ActiveCfg = Debug|x64 + {6889330F-2E7E-4778-ADFF-70AF036F1BD5}.Debug|x64.Build.0 = Debug|x64 + {6889330F-2E7E-4778-ADFF-70AF036F1BD5}.Release|x64.ActiveCfg = Release|x64 + {6889330F-2E7E-4778-ADFF-70AF036F1BD5}.Release|x64.Build.0 = Release|x64 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE -- 2.39.2 From 0e244bc16bdb2e7d90cc11ef39f09448157a6d10 Mon Sep 17 00:00:00 2001 From: akanyan Date: Mon, 22 Jul 2024 22:03:11 +0900 Subject: [PATCH 2/3] chore: formatting --- AttractVideoPlayer/AttractVideoPlayer.csproj | 8 +--- .../patch_OperationManager.cs | 34 +++++------------ .../MU3.Sequence/patch_Advertise.cs | 18 +++------ AttractVideoPlayer/MU3/patch_AdvManager.cs | 38 ++++++------------- 4 files changed, 27 insertions(+), 71 deletions(-) diff --git a/AttractVideoPlayer/AttractVideoPlayer.csproj b/AttractVideoPlayer/AttractVideoPlayer.csproj index 579a70e..8343204 100644 --- a/AttractVideoPlayer/AttractVideoPlayer.csproj +++ b/AttractVideoPlayer/AttractVideoPlayer.csproj @@ -1,13 +1,7 @@ - + Assembly-CSharp.AttractVideoPlayer.mm Control attract video - - - - - 2.0 - {6889330F-2E7E-4778-ADFF-70AF036F1BD5} \ No newline at end of file diff --git a/AttractVideoPlayer/MU3.OperationManager/patch_OperationManager.cs b/AttractVideoPlayer/MU3.OperationManager/patch_OperationManager.cs index 4864ed1..4c1a075 100644 --- a/AttractVideoPlayer/MU3.OperationManager/patch_OperationManager.cs +++ b/AttractVideoPlayer/MU3.OperationManager/patch_OperationManager.cs @@ -1,40 +1,27 @@ -using MU3.Operation; -using MU3.SceneObject; -using MU3.Sequence; -using MU3.Util; -using System.Collections.ObjectModel; +using System.Collections.ObjectModel; using UnityEngine; namespace MU3.Operation; -class patch_OperationManager: OperationManager -{ +class patch_OperationManager: OperationManager { private static readonly string CurrentSongIndexFilePath = "BepInEx/monomod/AttractVideoPlayer.currentSongIndex.txt"; private ReadOnlyCollection _movieDataList; - public new MovieData movieData - { - get - { - if (_movieDataList.Count > 0) - { + public new MovieData movieData { + get { + if(_movieDataList.Count > 0) { int currentSongIndex = 0; - try - { + try { currentSongIndex = int.Parse(System.IO.File.ReadAllText(CurrentSongIndexFilePath)); - } - catch (System.Exception) - { + } catch(System.Exception) { saveCurrentSongIndex(0); } - if (currentSongIndex < 0) - { + if(currentSongIndex < 0) { currentSongIndex = _movieDataList.Count - 1; saveCurrentSongIndex(currentSongIndex); } - if (currentSongIndex >= _movieDataList.Count) - { + if(currentSongIndex >= _movieDataList.Count) { currentSongIndex = 0; saveCurrentSongIndex(currentSongIndex); } @@ -47,8 +34,7 @@ class patch_OperationManager: OperationManager } } - private void saveCurrentSongIndex(int currentSongIndex) - { + private void saveCurrentSongIndex(int currentSongIndex) { System.IO.File.WriteAllText(CurrentSongIndexFilePath, currentSongIndex.ToString()); } } \ No newline at end of file diff --git a/AttractVideoPlayer/MU3.Sequence/patch_Advertise.cs b/AttractVideoPlayer/MU3.Sequence/patch_Advertise.cs index cdac034..e01e722 100644 --- a/AttractVideoPlayer/MU3.Sequence/patch_Advertise.cs +++ b/AttractVideoPlayer/MU3.Sequence/patch_Advertise.cs @@ -1,25 +1,17 @@ -using Mono.Cecil; -using MU3.AM; +using MU3.AM; using MU3.Operation; -using MU3.SceneObject; -using MU3.Sequence; using MU3.Util; -using UnityEngine; namespace MU3.Sequence; -class patch_Advertise : Advertise -{ - private bool checkButtonOrAime() - { - if (SingletonStateMachine.instance.aimeReader.advCheck()) - { +class patch_Advertise: Advertise { + private bool checkButtonOrAime() { + if(SingletonStateMachine.instance.aimeReader.advCheck()) { Singleton.instance.loginType = OperationManager.LoginType.Aime; return true; } UIInput instance = Singleton.instance; - if (instance.getTriggerOn(UIInput.Key.Decision) || instance.getTriggerOn(UIInput.Key.OptionBackward) || instance.getTriggerOn(UIInput.Key.OptionForward) || instance.getTriggerOn(UIInput.Key.SkipRight) || instance.getTriggerOn(UIInput.Key.MenuLeft) || instance.getTriggerOn(UIInput.Key.MenuRight)) - { + if(instance.getTriggerOn(UIInput.Key.Decision) || instance.getTriggerOn(UIInput.Key.OptionBackward) || instance.getTriggerOn(UIInput.Key.OptionForward) || instance.getTriggerOn(UIInput.Key.SkipRight) || instance.getTriggerOn(UIInput.Key.MenuLeft) || instance.getTriggerOn(UIInput.Key.MenuRight)) { Singleton.instance.loginType = OperationManager.LoginType.Button; return true; } diff --git a/AttractVideoPlayer/MU3/patch_AdvManager.cs b/AttractVideoPlayer/MU3/patch_AdvManager.cs index c2a5fe6..0f30463 100644 --- a/AttractVideoPlayer/MU3/patch_AdvManager.cs +++ b/AttractVideoPlayer/MU3/patch_AdvManager.cs @@ -1,14 +1,9 @@ -using Mono.Cecil; -using MU3.Operation; -using MU3.SceneObject; -using MU3.Sequence; -using MU3.Util; +using MU3.Util; using UnityEngine; namespace MU3; -class patch_AdvManager : AdvManager -{ +class patch_AdvManager: AdvManager { private static readonly string CurrentSongIndexFilePath = "BepInEx/monomod/AttractVideoPlayer.currentSongIndex.txt"; private static readonly float DelayBetweenButtonPress = 0.5f; private float lastButtonPressedTime = 0f; @@ -16,30 +11,22 @@ class patch_AdvManager : AdvManager private GameObject objMovie; private CriManaMovieMaterial movieController; private extern bool orig_initMovie(); - public new bool initMovie() - { + public new bool initMovie() { return orig_initMovie(); } private extern bool orig_exec(); - public new bool exec() - { - if (Time.time - lastButtonPressedTime > DelayBetweenButtonPress) - { - if (Singleton.instance.getStateOn(UIInput.Key.Service)) - { + public new bool exec() { + if(Time.time - lastButtonPressedTime > DelayBetweenButtonPress) { + if(Singleton.instance.getStateOn(UIInput.Key.Service)) { lastButtonPressedTime = Time.time; movieController?.player.Pause(!movieController.player.IsPaused()); - } - else if (Singleton.instance.getStateOn(UIInput.Key.L2)) - { + } else if(Singleton.instance.getStateOn(UIInput.Key.L2)) { lastButtonPressedTime = Time.time; addOffsetToCurrentSongIndexAndPlayMovie(-1); - } - else if (Singleton.instance.getStateOn(UIInput.Key.L3)) - { + } else if(Singleton.instance.getStateOn(UIInput.Key.L3)) { lastButtonPressedTime = Time.time; addOffsetToCurrentSongIndexAndPlayMovie(1); @@ -48,14 +35,11 @@ class patch_AdvManager : AdvManager return orig_exec(); } - public void addOffsetToCurrentSongIndexAndPlayMovie(int offset) - { - try - { + public void addOffsetToCurrentSongIndexAndPlayMovie(int offset) { + try { int currentSongIndex = int.Parse(System.IO.File.ReadAllText(CurrentSongIndexFilePath)) + offset; System.IO.File.WriteAllText(CurrentSongIndexFilePath, currentSongIndex.ToString()); - } - catch (System.Exception) { } + } catch(System.Exception) { } movieController?.Stop(); Utility.destroyGameObject(ref movieController); -- 2.39.2 From 6738890408aa9140e0dcb7beb5eecaa27e6c2137 Mon Sep 17 00:00:00 2001 From: akanyan Date: Mon, 22 Jul 2024 23:51:35 +0900 Subject: [PATCH 3/3] rewrite basically --- .../patch_OperationManager.cs | 55 ++++++++++--------- .../MU3.Sequence/patch_Advertise.cs | 20 +++---- AttractVideoPlayer/MU3/patch_AdvManager.cs | 41 +++++--------- 3 files changed, 53 insertions(+), 63 deletions(-) diff --git a/AttractVideoPlayer/MU3.OperationManager/patch_OperationManager.cs b/AttractVideoPlayer/MU3.OperationManager/patch_OperationManager.cs index 4c1a075..96b64e1 100644 --- a/AttractVideoPlayer/MU3.OperationManager/patch_OperationManager.cs +++ b/AttractVideoPlayer/MU3.OperationManager/patch_OperationManager.cs @@ -1,40 +1,45 @@ -using System.Collections.ObjectModel; -using UnityEngine; +using System; +using System.Collections.ObjectModel; +using System.IO; namespace MU3.Operation; class patch_OperationManager: OperationManager { - private static readonly string CurrentSongIndexFilePath = "BepInEx/monomod/AttractVideoPlayer.currentSongIndex.txt"; + private static readonly string _fname = "data_advert_cache.txt"; private ReadOnlyCollection _movieDataList; + private int _movieIndex; + + ~patch_OperationManager() { + try { + File.WriteAllText(_fname, _movieIndex.ToString()); + } catch(Exception) {} + } + public int MovieIndex { + set { + _movieIndex = (value + _movieDataList.Count) % _movieDataList.Count; + } + get { + return _movieIndex; + } + } public new MovieData movieData { get { if(_movieDataList.Count > 0) { - int currentSongIndex = 0; - try { - currentSongIndex = int.Parse(System.IO.File.ReadAllText(CurrentSongIndexFilePath)); - } catch(System.Exception) { - saveCurrentSongIndex(0); - } - - if(currentSongIndex < 0) { - currentSongIndex = _movieDataList.Count - 1; - saveCurrentSongIndex(currentSongIndex); - } - - if(currentSongIndex >= _movieDataList.Count) { - currentSongIndex = 0; - saveCurrentSongIndex(currentSongIndex); - } - - Debug.Log("currentSongIndex: " + currentSongIndex); - - return _movieDataList[currentSongIndex]; + return _movieDataList[_movieIndex]; } return null; } } - private void saveCurrentSongIndex(int currentSongIndex) { - System.IO.File.WriteAllText(CurrentSongIndexFilePath, currentSongIndex.ToString()); + public extern void orig_initialize(); + + public new void initialize() { + orig_initialize(); + try { + _movieIndex = Math.Max(0, int.Parse(File.ReadAllText(_fname))); + } catch(Exception) { + _movieIndex = 0; + } + } } \ No newline at end of file diff --git a/AttractVideoPlayer/MU3.Sequence/patch_Advertise.cs b/AttractVideoPlayer/MU3.Sequence/patch_Advertise.cs index e01e722..ed96a89 100644 --- a/AttractVideoPlayer/MU3.Sequence/patch_Advertise.cs +++ b/AttractVideoPlayer/MU3.Sequence/patch_Advertise.cs @@ -1,18 +1,18 @@ -using MU3.AM; -using MU3.Operation; -using MU3.Util; +using MU3.Util; namespace MU3.Sequence; class patch_Advertise: Advertise { - private bool checkButtonOrAime() { - if(SingletonStateMachine.instance.aimeReader.advCheck()) { - Singleton.instance.loginType = OperationManager.LoginType.Aime; - return true; - } + // Exclude Back/Left/Right + private bool anyKeyDown() { UIInput instance = Singleton.instance; - if(instance.getTriggerOn(UIInput.Key.Decision) || instance.getTriggerOn(UIInput.Key.OptionBackward) || instance.getTriggerOn(UIInput.Key.OptionForward) || instance.getTriggerOn(UIInput.Key.SkipRight) || instance.getTriggerOn(UIInput.Key.MenuLeft) || instance.getTriggerOn(UIInput.Key.MenuRight)) { - Singleton.instance.loginType = OperationManager.LoginType.Button; + if(instance.getTriggerOn(UIInput.Key.Decision) + || instance.getTriggerOn(UIInput.Key.OptionBackward) + || instance.getTriggerOn(UIInput.Key.OptionForward) + || instance.getTriggerOn(UIInput.Key.SkipLeft) + || instance.getTriggerOn(UIInput.Key.SkipRight) + || instance.getTriggerOn(UIInput.Key.MenuLeft) + || instance.getTriggerOn(UIInput.Key.MenuRight)) { return true; } return false; diff --git a/AttractVideoPlayer/MU3/patch_AdvManager.cs b/AttractVideoPlayer/MU3/patch_AdvManager.cs index 0f30463..67708c5 100644 --- a/AttractVideoPlayer/MU3/patch_AdvManager.cs +++ b/AttractVideoPlayer/MU3/patch_AdvManager.cs @@ -1,47 +1,32 @@ -using MU3.Util; +using MU3.Operation; +using MU3.Util; using UnityEngine; namespace MU3; class patch_AdvManager: AdvManager { - private static readonly string CurrentSongIndexFilePath = "BepInEx/monomod/AttractVideoPlayer.currentSongIndex.txt"; - private static readonly float DelayBetweenButtonPress = 0.5f; - private float lastButtonPressedTime = 0f; - private GameObject objMovie; private CriManaMovieMaterial movieController; - private extern bool orig_initMovie(); - public new bool initMovie() { - return orig_initMovie(); - } private extern bool orig_exec(); public new bool exec() { - if(Time.time - lastButtonPressedTime > DelayBetweenButtonPress) { - if(Singleton.instance.getStateOn(UIInput.Key.Service)) { - lastButtonPressedTime = Time.time; - - movieController?.player.Pause(!movieController.player.IsPaused()); - } else if(Singleton.instance.getStateOn(UIInput.Key.L2)) { - lastButtonPressedTime = Time.time; - - addOffsetToCurrentSongIndexAndPlayMovie(-1); - } else if(Singleton.instance.getStateOn(UIInput.Key.L3)) { - lastButtonPressedTime = Time.time; - - addOffsetToCurrentSongIndexAndPlayMovie(1); + if(movieController?.player?.status == CriMana.Player.Status.Playing) { + if(Singleton.instance.getTriggerOn(UIInput.Key.Service)) { + movieController.player.Pause(!movieController.player.IsPaused()); + } else if(Singleton.instance.getTriggerOn(UIInput.Key.L2)) { + addMovieOffset(-1); + } else if(Singleton.instance.getTriggerOn(UIInput.Key.L3)) { + addMovieOffset(1); } } return orig_exec(); } - public void addOffsetToCurrentSongIndexAndPlayMovie(int offset) { - try { - int currentSongIndex = int.Parse(System.IO.File.ReadAllText(CurrentSongIndexFilePath)) + offset; - System.IO.File.WriteAllText(CurrentSongIndexFilePath, currentSongIndex.ToString()); - } catch(System.Exception) { } + public void addMovieOffset(int offset) { + var om = (patch_OperationManager)Singleton.instance; + om.MovieIndex += offset; - movieController?.Stop(); + movieController.Stop(); Utility.destroyGameObject(ref movieController); Utility.destroyGameObject(ref objMovie); -- 2.39.2