Skip to content

Commit 59ec337

Browse files
committed
Merge branch 'dev'
2 parents 871bc06 + e783b3f commit 59ec337

File tree

7 files changed

+144
-194
lines changed

7 files changed

+144
-194
lines changed

VS/EmoteRain/EmoteRain.csproj

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@
1010
<AppDesignerFolder>Properties</AppDesignerFolder>
1111
<RootNamespace>EmoteRain</RootNamespace>
1212
<AssemblyName>EmoteRain</AssemblyName>
13-
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
13+
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
1414
<FileAlignment>512</FileAlignment>
1515
<PathMap>$(SolutionDir)=C:\</PathMap>
1616
<DebugType>portable</DebugType>
1717
<BeatSaberDir>$(ProjectDir)References</BeatSaberDir>
18+
<TargetFrameworkProfile />
1819
</PropertyGroup>
1920
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
2021
<DebugSymbols>true</DebugSymbols>
@@ -33,40 +34,38 @@
3334
<WarningLevel>4</WarningLevel>
3435
</PropertyGroup>
3536
<ItemGroup>
36-
<Reference Include="BSML, Version=1.1.5.0, Culture=neutral, processorArchitecture=MSIL">
37+
<Reference Include="BSML, Version=1.2.2.0, Culture=neutral, processorArchitecture=MSIL">
3738
<SpecificVersion>False</SpecificVersion>
3839
<HintPath>..\..\..\..\..\SteamLibrary_SlowMode\steamapps\common\Beat Saber\Plugins\BSML.dll</HintPath>
3940
</Reference>
40-
<Reference Include="BS_Utils, Version=1.4.1.0, Culture=neutral, processorArchitecture=MSIL">
41+
<Reference Include="BS_Utils, Version=1.4.6.0, Culture=neutral, processorArchitecture=MSIL">
4142
<SpecificVersion>False</SpecificVersion>
4243
<HintPath>..\..\..\..\..\SteamLibrary_SlowMode\steamapps\common\Beat Saber\Plugins\BS_Utils.dll</HintPath>
4344
</Reference>
44-
<Reference Include="EnhancedStreamChat">
45-
<HintPath>D:\SteamLibrary_SlowMode\steamapps\common\Beat Saber\Plugins\EnhancedStreamChat.dll</HintPath>
46-
</Reference>
47-
<Reference Include="StreamCore">
48-
<HintPath>D:\SteamLibrary_SlowMode\steamapps\common\Beat Saber\Plugins\StreamCore.dll</HintPath>
45+
<Reference Include="ChatCore, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
46+
<SpecificVersion>False</SpecificVersion>
47+
<HintPath>..\..\..\..\..\SteamLibrary_SlowMode\steamapps\common\Beat Saber\Libs\ChatCore.dll</HintPath>
4948
</Reference>
50-
<Reference Include="System" />
51-
<Reference Include="MainAssembly">
52-
<HintPath>D:\SteamLibrary_SlowMode\steamapps\common\Beat Saber\Beat Saber_Data\Managed\MainAssembly.dll</HintPath>
53-
<Private>False</Private>
49+
<Reference Include="EnhancedStreamChat, Version=0.0.1.0, Culture=neutral, processorArchitecture=AMD64">
50+
<SpecificVersion>False</SpecificVersion>
51+
<HintPath>..\..\..\..\..\SteamLibrary_SlowMode\steamapps\common\Beat Saber\Plugins\EnhancedStreamChat.dll</HintPath>
5452
</Reference>
55-
<Reference Include="HMLib">
56-
<HintPath>D:\SteamLibrary_SlowMode\steamapps\common\Beat Saber\Beat Saber_Data\Managed\HMLib.dll</HintPath>
57-
<Private>False</Private>
53+
<Reference Include="HMLib, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
54+
<SpecificVersion>False</SpecificVersion>
55+
<HintPath>..\..\..\..\..\SteamLibrary_SlowMode\steamapps\common\Beat Saber\Beat Saber_Data\Managed\HMLib.dll</HintPath>
5856
</Reference>
59-
<Reference Include="HMUI">
60-
<HintPath>D:\SteamLibrary_SlowMode\steamapps\common\Beat Saber\Beat Saber_Data\Managed\HMUI.dll</HintPath>
61-
<Private>False</Private>
57+
<Reference Include="Main, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
58+
<SpecificVersion>False</SpecificVersion>
59+
<HintPath>..\..\..\..\..\SteamLibrary_SlowMode\steamapps\common\Beat Saber\Beat Saber_Data\Managed\Main.dll</HintPath>
6260
</Reference>
6361
<Reference Include="IPA.Loader">
6462
<HintPath>D:\SteamLibrary_SlowMode\steamapps\common\Beat Saber\Beat Saber_Data\Managed\IPA.Loader.dll</HintPath>
6563
<Private>False</Private>
6664
</Reference>
67-
<Reference Include="Unity.TextMeshPro">
68-
<HintPath>D:\SteamLibrary_SlowMode\steamapps\common\Beat Saber\Beat Saber_Data\Managed\Unity.TextMeshPro.dll</HintPath>
69-
<Private>False</Private>
65+
<Reference Include="System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL" />
66+
<Reference Include="Unity.TextMeshPro, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
67+
<SpecificVersion>False</SpecificVersion>
68+
<HintPath>..\..\..\..\..\SteamLibrary_SlowMode\steamapps\common\Beat Saber\Beat Saber_Data\Managed\Unity.TextMeshPro.dll</HintPath>
7069
</Reference>
7170
<Reference Include="UnityEngine">
7271
<HintPath>D:\SteamLibrary_SlowMode\steamapps\common\Beat Saber\Beat Saber_Data\Managed\UnityEngine.dll</HintPath>

VS/EmoteRain/Logger.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ internal static void Init(IPALogger IPAlogger)
1212
logger = IPAlogger;
1313
}
1414

15-
private static IPALogger logger { get; set; }
15+
public static IPALogger logger { get; set; }
1616

1717
internal static void Log(Exception e, Level level = Level.Notice) {
1818
Log("An error has been caught:\n" + e.GetType().Name + "\nAt:\n" + e.StackTrace + "\nWith message:\n" + e.Message, level);

VS/EmoteRain/Plugin.cs

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,20 @@
1212
using System.Reflection;
1313
using System.IO;
1414
using BS_Utils.Utilities;
15+
using UnityEngine.Events;
1516

1617
namespace EmoteRain
1718
{
1819

19-
internal class Plugin : IBeatSaberPlugin
20+
[Plugin(RuntimeOptions.SingleStartInit)]
21+
internal class Plugin
2022
{
2123
private static bool init;
2224
internal static Config config = new Config("EmoteRain");
2325

2426
internal static string Name => "EmoteRain";
2527

28+
[Init]
2629
public void Init(IPALogger logger)
2730
{
2831
Logger.Init(logger);
@@ -34,18 +37,6 @@ public void Init(IPALogger logger)
3437
/// </summary>
3538
/// <param name="scene"></param>
3639
/// <param name="sceneMode"></param>
37-
public void OnSceneLoaded(Scene scene, LoadSceneMode sceneMode)
38-
{
39-
if (!init)
40-
{
41-
init = true;
42-
SharedCoroutineStarter.instance.StartCoroutine(WaitForMenu());
43-
}
44-
if (scene.name.Contains("Environment"))
45-
{
46-
RequestCoordinator.EnvironmentSwitched(scene.name, SceneLoadMode.Load);
47-
}
48-
}
4940
private static IEnumerator<WaitUntil> WaitForMenu()
5041
{
5142
yield return new WaitUntil(() =>
@@ -66,17 +57,31 @@ private static IEnumerator<WaitUntil> WaitForMenu()
6657

6758
private static void Init()
6859
{
60+
TwitchMSGHandler.onLoad();
6961
RequestCoordinator.OnLoad();
7062
}
7163

64+
[OnStart]
7265
public void OnApplicationStart()
7366
{
7467
BSMLSettings.instance.AddSettingsMenu("EmoteRain", "EmoteRain.Views.settings.bsml", Settings.instance);
68+
SceneManager.sceneLoaded += OnSceneLoaded;
69+
SceneManager.sceneUnloaded += OnSceneUnloaded;
70+
}
71+
72+
public void OnSceneLoaded(Scene scene, LoadSceneMode sceneMode)
73+
{
74+
if (!init)
75+
{
76+
init = true;
77+
SharedCoroutineStarter.instance.StartCoroutine(WaitForMenu());
78+
}
79+
if (scene.name.Contains("Environment"))
80+
{
81+
RequestCoordinator.EnvironmentSwitched(scene.name, SceneLoadMode.Load);
82+
}
7583
}
76-
public void OnApplicationQuit() { }
77-
public void OnFixedUpdate() { }
78-
public void OnUpdate() { }
79-
public void OnActiveSceneChanged(Scene prevScene, Scene nextScene) { }
84+
8085
public void OnSceneUnloaded(Scene scene)
8186
{
8287
if (scene.name.Contains("Environment"))

VS/EmoteRain/Properties/AssemblyInfo.cs

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

VS/EmoteRain/RequestCoordinator.cs

Lines changed: 58 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
using EnhancedStreamChat.Textures;
1+
using ChatCore.Interfaces;
2+
using EnhancedStreamChat.Chat;
3+
using EnhancedStreamChat.Graphics;
24
using System;
35
using System.Collections.Generic;
46
using System.Reflection;
@@ -20,7 +22,7 @@ public static class RequestCoordinator
2022

2123
private static Mode mode;
2224

23-
internal static Action<string, byte> EmoteQueue;
25+
internal static Action<IChatEmote, byte> EmoteQueue;
2426

2527
private static Dictionary<Mode, PS_Prefab_Pair> particleSystems = new Dictionary<Mode, PS_Prefab_Pair>();
2628

@@ -30,10 +32,8 @@ internal static Scene myScene
3032
{
3133
if (!_myScene.HasValue)
3234
{
33-
Log("Creating Scene..");
3435
_myScene = SceneManager.CreateScene("EmoteRainScene");
3536
}
36-
Log("Returning Scene..");
3737
return _myScene.Value;
3838
}
3939
}
@@ -63,50 +63,87 @@ internal static void OnLoad()
6363
Log("Prefab at: " + (particleSystems[Mode.Play].Item2 ? particleSystems[Mode.Play].Item2.GetFullPath() : "null"));
6464
}
6565

66-
private static void MessageCallback(string id, byte count)
66+
private static void MessageCallback(IChatEmote emote, byte count)
6767
{
6868
if ((mode == Mode.Menu && Settings.menuRain) || (mode == Mode.Play && Settings.songRain))
6969
{
70-
SharedCoroutineStarter.instance.StartCoroutine(WaitForCollection(id, count));
70+
SharedCoroutineStarter.instance.StartCoroutine(WaitForCollection(emote, count));
7171
}
7272
}
7373

74-
private static IEnumerator<WaitUntil> WaitForCollection(string id, byte count)
74+
private static IEnumerator<WaitUntil> WaitForCollection(IChatEmote emote, byte count)
7575
{
7676
float time = Time.time;
77-
Log("Id: " + id);
77+
bool isAnimation = false; //doesn't do anything yet. look below.
7878

79-
CachedSpriteData cachedSpriteData = default;
80-
yield return new WaitUntil(() => ImageDownloader.CachedTextures.TryGetValue(id, out cachedSpriteData) && mode != Mode.None);
79+
EnhancedImageInfo enhancedImageInfo = default;
80+
yield return new WaitUntil(() => ChatImageProvider.instance.CachedImageInfo.TryGetValue(emote.Id, out enhancedImageInfo) && mode != Mode.None);
8181

82-
Log($"Continuing after {Time.time - time} seconds...");
82+
//Log($"Continuing after {Time.time - time} seconds...");
8383

8484
TimeoutScript cloneTimer;
8585
PS_Prefab_Pair ps_Prefab_Pair = particleSystems[mode];
8686

87-
if (!ps_Prefab_Pair.Item1.ContainsKey(id))
87+
if (!ps_Prefab_Pair.Item1.ContainsKey(emote.Id))
8888
{
89-
Log(ps_Prefab_Pair.Item2 ? ps_Prefab_Pair.Item2.GetFullPath() : "null");
9089
cloneTimer = UnityEngine.Object.Instantiate(ps_Prefab_Pair.Item2).GetComponent<TimeoutScript>();
9190
var main = cloneTimer.PS.main;
9291
if (mode == Mode.Menu) main.startSize = Settings.menuSize;
9392
if (mode == Mode.Play) main.startSize = Settings.songSize;
94-
cloneTimer.key = id;
93+
cloneTimer.key = emote.Id;
9594
cloneTimer.mode = mode;
9695
SceneManager.MoveGameObjectToScene(cloneTimer.gameObject, myScene);
97-
ps_Prefab_Pair.Item1.Add(id, cloneTimer);
96+
ps_Prefab_Pair.Item1.Add(emote.Id, cloneTimer);
9897
}
9998
else
10099
{
101-
cloneTimer = ps_Prefab_Pair.Item1[id];
100+
cloneTimer = ps_Prefab_Pair.Item1[emote.Id];
102101
}
103-
Log("Assigning...");
104-
cloneTimer.PSR.material.mainTexture = cachedSpriteData.sprite.texture;
105-
Log("Finished assigning!");
102+
103+
//not sure about this. Might not work at all, but is not yet in use. So it technically does work?
104+
if(isAnimation)
105+
{
106+
int numTilesX = (int)(enhancedImageInfo.Width / enhancedImageInfo.AnimControllerData.uvs[0].width);
107+
int numTilesY = (int)(enhancedImageInfo.Height / enhancedImageInfo.AnimControllerData.uvs[0].height);
108+
109+
var tex = cloneTimer.PS.textureSheetAnimation;
110+
tex.enabled = true;
111+
tex.animation = ParticleSystemAnimationType.WholeSheet;
112+
tex.numTilesX = numTilesX;
113+
tex.numTilesY = numTilesY;
114+
tex.timeMode = ParticleSystemAnimationTimeMode.Lifetime;
115+
116+
float lifeTime = cloneTimer.PS.main.startLifetime.constant;
117+
AnimationCurve curve = new AnimationCurve();
118+
float singleFramePercentage = 1 / enhancedImageInfo.AnimControllerData.uvs.Length;
119+
float maxFramePercentage = enhancedImageInfo.AnimControllerData.uvs.Length / (numTilesX * numTilesY);
120+
121+
List<float> timePercentages = new List<float>();
122+
float currentTimePercentage = 0;
123+
float currentFramePercentage = 0;
124+
for(int i = 0; currentTimePercentage < 1.0f; i++)
125+
{
126+
currentTimePercentage += (enhancedImageInfo.AnimControllerData.delays[i] / 1000) / lifeTime;
127+
if(currentFramePercentage < maxFramePercentage)
128+
{
129+
currentFramePercentage += singleFramePercentage;
130+
}
131+
else
132+
{
133+
currentFramePercentage = 0;
134+
}
135+
curve.AddKey(currentTimePercentage,currentFramePercentage);
136+
}
137+
tex.frameOverTime = new ParticleSystem.MinMaxCurve(1.0f, curve);
138+
}
139+
//end of "not-sure-about-this"
140+
141+
//Log("Assigning texture...");
142+
cloneTimer.PSR.material.mainTexture = enhancedImageInfo.Sprite.texture;
106143

107144
cloneTimer.Emit(count);
108145

109-
Log("ParticleSystems notified! " + cachedSpriteData.sprite.name);
146+
//Log("ParticleSystems notified! ");
110147

111148
}
112149
//Needs rework...
@@ -138,7 +175,7 @@ internal static void EnvironmentSwitched(string scene, SceneLoadMode sceneLoadMo
138175
internal static void UnregisterPS(string key, Mode mode)
139176
{
140177
UnityEngine.Object.Destroy(particleSystems[mode].Item1[key]);
141-
Log("Inactive ParticleSystem. Removing...");
178+
//Log("Inactive ParticleSystem. Removing...");
142179
particleSystems[mode].Item1.Remove(key);
143180
}
144181
}

0 commit comments

Comments
 (0)