Skip to content
This repository was archived by the owner on Sep 30, 2019. It is now read-only.

Commit 8f3c590

Browse files
committed
Fixed for Beat Saber 0.11.2.
1 parent 494bdd4 commit 8f3c590

9 files changed

Lines changed: 205 additions & 90 deletions
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
using System;
2+
3+
namespace PracticePlugin
4+
{
5+
public class CustomEffectPoolsInstaller : EffectPoolsInstaller
6+
{
7+
private void Awake()
8+
{
9+
Console.WriteLine("Custom Awake!");
10+
}
11+
12+
public override void InstallBindings()
13+
{
14+
Console.WriteLine("Custom install bindings!");
15+
Container.BindMemoryPool<FlyingTextEffect, FlyingTextEffect.Pool>().WithInitialSize(20).FromComponentInNewPrefab(_flyingTextEffectPrefab);
16+
Container.BindMemoryPool<FlyingScoreTextEffect, FlyingScoreTextEffect.Pool>().WithInitialSize(20)
17+
.FromComponentInNewPrefab(_flyingScoreTextEffectPrefab);
18+
Container.BindMemoryPool<FlyingSpriteEffect, FlyingSpriteEffect.Pool>().WithInitialSize(20)
19+
.FromComponentInNewPrefab(_flyingSpriteEffectPrefab);
20+
Container.BindMemoryPool<NoteDebris, NoteDebris.Pool>().WithInitialSize(30).FromComponentInNewPrefab(_noteDebrisPrefab);
21+
Container.BindMemoryPool<BeatEffect, BeatEffect.Pool>().WithInitialSize(20).FromComponentInNewPrefab(_beatEffectPrefab);
22+
Container.BindMemoryPool<BombCutSoundEffect, BombCutSoundEffect.Pool>().WithInitialSize(20)
23+
.FromComponentInNewPrefab(_bombCutSoundEffectPrefab);;
24+
25+
Container.BindMemoryPool<NoteCutSoundEffect, NoteCutSoundEffect.Pool>().WithInitialSize(10)
26+
.FromComponentInNewPrefab(ReplacePrefab());
27+
}
28+
29+
private CustomNoteCutSoundEffect ReplacePrefab()
30+
{
31+
return CustomNoteCutSoundEffect.CopyOriginal(_noteCutSoundEffectPrefab);
32+
}
33+
}
34+
}

PracticePlugin/CustomNoteCutSoundEffect.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,11 @@ public override void LateUpdate()
3030
base.LateUpdate();
3131
}
3232

33-
public override void Init(AudioClip audioClip, float volumeScale, double noteDSPTime, float aheadTime, float missedTimeOffset,
33+
public override void Init(AudioClip audioClip, double noteDSPTime, float aheadTime, float missedTimeOffset,
3434
Saber saber, NoteData noteData, bool handleWrongSaberTypeAsGood)
3535
{
36-
base.Init(audioClip, volumeScale, noteDSPTime, aheadTime, missedTimeOffset, saber, noteData, handleWrongSaberTypeAsGood);
36+
Console.WriteLine("Custom Init!");
37+
base.Init(audioClip, noteDSPTime, aheadTime, missedTimeOffset, saber, noteData, handleWrongSaberTypeAsGood);
3738
_audioSource.Stop();
3839
var dspTime = AudioSettings.dspTime;
3940
var timeDiff = noteDSPTime - dspTime;

PracticePlugin/NoteCutSoundReplacer.cs

Lines changed: 0 additions & 30 deletions
This file was deleted.

PracticePlugin/Plugin.cs

Lines changed: 97 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
using System;
2+
using System.Collections.Generic;
23
using System.Linq;
4+
using System.Reflection;
35
using IllusionPlugin;
46
using TMPro;
57
using UnityEngine;
68
using UnityEngine.SceneManagement;
79
using UnityEngine.UI;
10+
using Zenject;
811
using Object = UnityEngine.Object;
912

1013
namespace PracticePlugin
@@ -18,12 +21,16 @@ public string Name
1821

1922
public string Version
2023
{
21-
get { return "v3.0"; }
24+
get { return "v3.2"; }
2225
}
23-
26+
2427
public const float MaxSize = 5.05f;
2528
public const float StepSize = 0.05f;
2629

30+
public const string MenuSceneName = "Menu";
31+
public const string GameSceneName = "GameCore";
32+
public const string ContextSceneName = "StandardLevel";
33+
2734
public static GameObject SettingsObject { get; private set; }
2835

2936
public static float TimeScale
@@ -76,17 +83,55 @@ public void OnApplicationStart()
7683
{
7784
if (_init) return;
7885
_init = true;
79-
SceneManager.activeSceneChanged += SceneManagerOnActiveSceneChanged;
86+
SceneManager.sceneLoaded += SceneManagerOnSceneLoaded;
87+
}
88+
89+
private void SceneManagerOnActiveSceneChanged(Scene oldScene, Scene newScene)
90+
{
91+
Console.WriteLine("Active scene changed: " + newScene.name);
92+
for (var i = 0; i < SceneManager.sceneCount; i++)
93+
{
94+
var scene = SceneManager.GetSceneAt(i);
95+
Console.WriteLine("Scene loaded!!: " + scene.name);
96+
}
97+
98+
var gameScene = new Scene();
99+
if (!gameScene.isLoaded) return;
100+
101+
Console.WriteLine("It's loaded!");
102+
103+
var effectPoolsInstaller = Resources.FindObjectsOfTypeAll<EffectPoolsInstaller>().FirstOrDefault();
104+
if (effectPoolsInstaller != null)
105+
{
106+
ReflectionUtil.CopyComponent(effectPoolsInstaller, typeof(EffectPoolsInstaller), typeof(CustomEffectPoolsInstaller),
107+
effectPoolsInstaller.gameObject);
108+
Object.DestroyImmediate(effectPoolsInstaller);
109+
110+
Console.WriteLine("Trying to find scene context");
111+
SceneContext sceneContext = null;
112+
foreach (var gameObject in gameScene.GetRootGameObjects())
113+
{
114+
sceneContext = gameObject.GetComponentInChildren<SceneContext>();
115+
if (sceneContext != null)
116+
{
117+
break;
118+
}
119+
}
120+
121+
if (sceneContext == null) return;
122+
Console.WriteLine("Found it");
123+
sceneContext.enabled = false;
124+
}
80125
}
81126

82127
public void OnApplicationQuit()
83128
{
84-
SceneManager.activeSceneChanged -= SceneManagerOnActiveSceneChanged;
129+
SceneManager.sceneLoaded -= SceneManagerOnSceneLoaded;
85130
}
86131

87-
private void SceneManagerOnActiveSceneChanged(Scene arg0, Scene scene)
132+
private void SceneManagerOnSceneLoaded(Scene scene, LoadSceneMode mode)
88133
{
89-
if (scene.buildIndex == 1)
134+
if (scene.name == MenuSceneName)
90135
{
91136
if (_resetNoFail)
92137
{
@@ -118,20 +163,60 @@ private void SceneManagerOnActiveSceneChanged(Scene arg0, Scene scene)
118163
SettingsObject.GetComponentInChildren<TMP_Text>().text = "SPEED";
119164
Object.DontDestroyOnLoad(SettingsObject);
120165
}
121-
else
166+
else if (scene.name == GameSceneName)
122167
{
168+
CustomEffectPoolsInstaller customEffectPoolsInstaller = null;
169+
var effectPoolsInstaller = Resources.FindObjectsOfTypeAll<EffectPoolsInstaller>().FirstOrDefault();
170+
if (effectPoolsInstaller != null)
171+
{
172+
customEffectPoolsInstaller = (CustomEffectPoolsInstaller) ReflectionUtil.CopyComponent(effectPoolsInstaller,
173+
typeof(EffectPoolsInstaller), typeof(CustomEffectPoolsInstaller), effectPoolsInstaller.gameObject);
174+
}
175+
176+
SceneContext sceneContext = null;
177+
SceneDecoratorContext sceneDecoratorContext = null;
178+
179+
foreach (var gameObject in scene.GetRootGameObjects())
180+
{
181+
if (sceneContext == null)
182+
{
183+
sceneContext = gameObject.GetComponentInChildren<SceneContext>(true);
184+
}
185+
}
186+
187+
foreach (var gameObject in SceneManager.GetSceneByName(ContextSceneName).GetRootGameObjects())
188+
{
189+
if (sceneDecoratorContext == null)
190+
{
191+
sceneDecoratorContext = gameObject.GetComponentInChildren<SceneDecoratorContext>(true);
192+
193+
if (sceneDecoratorContext != null)
194+
{
195+
Console.WriteLine("Found one in " + gameObject.name);
196+
}
197+
}
198+
}
199+
200+
201+
if (sceneContext != null && sceneDecoratorContext != null)
202+
{
203+
Console.WriteLine("We're live!");
204+
var prop = typeof(Context).GetField("_installers", BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance);
205+
var installersList = (List<MonoInstaller>) prop.GetValue(sceneDecoratorContext);
206+
Console.WriteLine("There are " + installersList.Count + " installers!");
207+
installersList.Remove(effectPoolsInstaller);
208+
Object.DestroyImmediate(effectPoolsInstaller);
209+
installersList.Add(customEffectPoolsInstaller);
210+
Console.WriteLine("Done!");
211+
}
212+
123213
if (_mainGameSceneSetupData == null)
124214
{
125215
_mainGameSceneSetupData = Resources.FindObjectsOfTypeAll<MainGameSceneSetupData>().FirstOrDefault();
126216
if (_mainGameSceneSetupData == null) return;
127217
_mainGameSceneSetupData.didFinishEvent += MainGameSceneSetupDataOnDidFinishEvent;
128218
}
129219

130-
if (scene.buildIndex != 5)
131-
{
132-
return;
133-
}
134-
135220
if (_lastLevelId != _mainGameSceneSetupData.difficultyLevel.level.levelID &&
136221
!string.IsNullOrEmpty(_lastLevelId))
137222
{
@@ -161,8 +246,6 @@ private void SceneManagerOnActiveSceneChanged(Scene arg0, Scene scene)
161246
TimeScale = Mathf.Clamp(TimeScale, 1, MaxSize);
162247
}
163248

164-
NoteCutSoundReplacer.ReplacePrefab();
165-
166249
var canvas = Resources.FindObjectsOfTypeAll<HorizontalLayoutGroup>()
167250
.FirstOrDefault(x => x.name == "Buttons")
168251
?.transform.parent;

PracticePlugin/PoolExtensions.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using System.Linq;
2+
using UnityEngine;
3+
4+
namespace PracticePlugin
5+
{
6+
public static class PoolExtensions
7+
{
8+
public static void DespawnAll<T> (this MemoryPoolWithActiveItems<T> memoryPool) where T : Component
9+
{
10+
var activeItems = memoryPool.activeItems.ToList();
11+
foreach (var activeItem in activeItems)
12+
{
13+
memoryPool.Despawn(activeItem);
14+
}
15+
}
16+
}
17+
}

PracticePlugin/PracticePlugin.csproj

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,21 @@
6565
<Reference Include="UnityEngine.UIModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
6666
<HintPath>..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Beat Saber\Beat Saber_Data\Managed\UnityEngine.UIModule.dll</HintPath>
6767
</Reference>
68+
<Reference Include="Zenject, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
69+
<HintPath>..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Beat Saber\Beat Saber_Data\Managed\Zenject.dll</HintPath>
70+
</Reference>
71+
<Reference Include="Zenject-usage, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
72+
<HintPath>..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Beat Saber\Beat Saber_Data\Managed\Zenject-usage.dll</HintPath>
73+
</Reference>
6874
</ItemGroup>
6975
<ItemGroup>
76+
<Compile Include="CustomEffectPoolsInstaller.cs" />
7077
<Compile Include="CustomNoteCutSoundEffect.cs" />
7178
<Compile Include="LooperCursor.cs" />
7279
<Compile Include="LooperUI.cs" />
7380
<Compile Include="NoFailGameEnergy.cs" />
74-
<Compile Include="NoteCutSoundReplacer.cs" />
7581
<Compile Include="Plugin.cs" />
82+
<Compile Include="PoolExtensions.cs" />
7683
<Compile Include="Properties\AssemblyInfo.cs" />
7784
<Compile Include="ReflectionUtil.cs" />
7885
<Compile Include="SongSeeker.cs" />

PracticePlugin/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,5 @@
3131
// You can specify all the values or you can default the Build and Revision Numbers
3232
// by using the '*' as shown below:
3333
// [assembly: AssemblyVersion("1.0.*")]
34-
[assembly: AssemblyVersion("3.0")]
35-
[assembly: AssemblyFileVersion("3.0")]
34+
[assembly: AssemblyVersion("3.2.0.0")]
35+
[assembly: AssemblyFileVersion("3.2.0.0")]

PracticePlugin/SongSeekBeatmapHandler.cs

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ private static List<BeatmapObjectCallbackController.BeatmapObjectCallbackData> C
2323
.GetPrivateField<List<BeatmapObjectCallbackController.BeatmapObjectCallbackData>>(
2424
"_beatmapObjectCallbackData");
2525

26-
_beatmapObjectCallbackController.GetBeatmapDataModelFromProvider();
2726
_beatmapData = _beatmapObjectCallbackController
2827
.GetPrivateField<BeatmapDataModel>("_beatmapDataModel").beatmapData;
2928
}
@@ -34,15 +33,12 @@ private static List<BeatmapObjectCallbackController.BeatmapObjectCallbackData> C
3433
.FirstOrDefault();
3534
if (_beatmapObjectSpawnController != null)
3635
{
37-
_gameNotePrefab =
38-
_beatmapObjectSpawnController.GetPrivateField<NoteController>("_gameNotePrefab");
39-
_bombNotePrefab =
40-
_beatmapObjectSpawnController.GetPrivateField<BombNoteController>("_bombNotePrefab");
41-
_obstacleFullHeightPrefab =
42-
_beatmapObjectSpawnController.GetPrivateField<ObstacleController>(
43-
"_obstacleFullHeightPrefab");
44-
_obstacleTopPrefab =
45-
_beatmapObjectSpawnController.GetPrivateField<ObstacleController>("_obstacleTopPrefab");
36+
_noteAPool = _beatmapObjectSpawnController.GetPrivateField<NoteController.Pool>("_noteAPool");
37+
_noteBPool = _beatmapObjectSpawnController.GetPrivateField<NoteController.Pool>("_noteBPool");
38+
_bombNotePool = _beatmapObjectSpawnController.GetPrivateField<NoteController.Pool>("_bombNotePool");
39+
_fullHeightObstaclePool =
40+
_beatmapObjectSpawnController.GetPrivateField<ObstacleController.Pool>("_fullHeightObstaclePool");
41+
_topObstaclePool = _beatmapObjectSpawnController.GetPrivateField<ObstacleController.Pool>("_topObstaclePool");
4642
}
4743
}
4844

@@ -62,10 +58,11 @@ private static List<BeatmapObjectCallbackController.BeatmapObjectCallbackData> C
6258
private static BeatmapObjectSpawnController _beatmapObjectSpawnController;
6359
private static NoteCutSoundEffectManager _noteCutSoundEffectManager;
6460

65-
private static NoteController _gameNotePrefab;
66-
private static BombNoteController _bombNotePrefab;
67-
private static ObstacleController _obstacleFullHeightPrefab;
68-
private static ObstacleController _obstacleTopPrefab;
61+
private static NoteController.Pool _noteAPool;
62+
private static NoteController.Pool _noteBPool;
63+
private static NoteController.Pool _bombNotePool;
64+
private static ObstacleController.Pool _fullHeightObstaclePool;
65+
private static ObstacleController.Pool _topObstaclePool;
6966

7067
private static BeatmapData _beatmapData;
7168

@@ -106,13 +103,13 @@ public static void OnSongTimeChanged(float newSongTime, float aheadTime)
106103

107104
_beatmapObjectCallbackController.SetPrivateField("_nextEventIndex", newNextEventIndex);
108105

109-
_gameNotePrefab.gameObject.RecycleAll();
110-
_bombNotePrefab.gameObject.RecycleAll();
111-
_obstacleFullHeightPrefab.RecycleAll();
112-
_obstacleTopPrefab.RecycleAll();
106+
_noteAPool.DespawnAll();
107+
_bombNotePool.DespawnAll();
108+
_fullHeightObstaclePool.DespawnAll();
109+
_topObstaclePool.DespawnAll();
113110

114111
Plugin.AudioTimeSync.SetPrivateField("_prevAudioSamplePos", -1);
115-
Plugin.AudioTimeSync.GetPrivateField<FloatVariableSetter>("_songTime").SetValue(newSongTime);
112+
Plugin.AudioTimeSync.GetPrivateField<FloatSO>("_songTime").value = newSongTime;
116113
_noteCutSoundEffectManager.SetPrivateField("_prevNoteATime", -1);
117114
_noteCutSoundEffectManager.SetPrivateField("_prevNoteBTime", -1);
118115
}

0 commit comments

Comments
 (0)