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

Commit

Permalink
Fixed negative note jump speed. Fixed cover image being mandatory. Ma…
Browse files Browse the repository at this point in the history
…de the custom level collections public for other plugins to use.
  • Loading branch information
PeturDarri committed Aug 21, 2018
1 parent 4068b15 commit 0553c47
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 21 deletions.
2 changes: 1 addition & 1 deletion SongLoaderPlugin/Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace SongLoaderPlugin
{
public class Plugin : IPlugin
{
public const string VersionNumber = "v4.3.1";
public const string VersionNumber = "v4.3.2";

public string Name
{
Expand Down
4 changes: 2 additions & 2 deletions SongLoaderPlugin/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@
// 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("4.3.1")]
[assembly: AssemblyFileVersion("4.3.1")]
[assembly: AssemblyVersion("4.3.2")]
[assembly: AssemblyFileVersion("4.3.2")]
51 changes: 33 additions & 18 deletions SongLoaderPlugin/SongLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,13 @@ public class SongLoader : MonoBehaviour
public static bool AreSongsLoaded { get; private set; }
public static bool AreSongsLoading { get; private set; }
public static float LoadingProgress { get; private set; }
public static CustomLevelCollectionsForGameplayModes CustomLevelCollectionsForGameplayModes
{
get { return _customLevelCollectionsForGameplayModes; }
}

public const string MenuSceneName = "Menu";
public const string GameSceneName = "StandardLevel";
public const string GameSceneName = "GameCore";

private static readonly Dictionary<string, Sprite> LoadedSprites = new Dictionary<string, Sprite>();
private static readonly Dictionary<string, AudioClip> LoadedAudioClips = new Dictionary<string, AudioClip>();
Expand All @@ -32,7 +36,7 @@ public class SongLoader : MonoBehaviour
private StandardLevelDetailViewController _standardLevelDetailViewController;
private MainGameSceneSetupData _mainGameSceneSetupData;

private CustomLevelCollectionsForGameplayModes _customLevelCollectionsForGameplayModes;
private static CustomLevelCollectionsForGameplayModes _customLevelCollectionsForGameplayModes;
private CustomLevelCollectionSO _standardLevelCollection;
private CustomLevelCollectionSO _oneSaberLevelCollection;
private CustomLevelCollectionSO _noArrowsLevelCollection;
Expand Down Expand Up @@ -97,7 +101,7 @@ private void SceneManagerOnSceneLoaded(Scene scene, LoadSceneMode mode)
}

StartCoroutine(WaitRemoveScores());

if (scene.name == MenuSceneName)
{
_currentLevelPlaying = null;
Expand All @@ -123,22 +127,9 @@ private void SceneManagerOnSceneLoaded(Scene scene, LoadSceneMode mode)
{
_currentLevelPlaying = beatmap;

//Beat Saber 0.11.1 introduced a check for if noteJumpMovementSpeed <= 0
//This breaks songs that have a negative noteJumpMovementSpeed and previously required a patcher to get working again
//I've added this to add support for that again, because why not.
if (_currentLevelPlaying.noteJumpMovementSpeed <= 0)
{
var beatmapObjectSpawnController =
Resources.FindObjectsOfTypeAll<BeatmapObjectSpawnController>().FirstOrDefault();
if (beatmapObjectSpawnController != null)
{
beatmapObjectSpawnController.Init(_currentLevelPlaying.level.beatsPerMinute,
_currentLevelPlaying.beatmapData.beatmapLinesData.Length,
_currentLevelPlaying.noteJumpMovementSpeed);
}
}
//The note jump movement speed now gets set in the Start method, so we're too early here. We have to wait a bit before overriding.
Invoke(nameof(DelayedNoteJumpMovementSpeedFix), 0.1f);
}


if (NoteHitVolumeChanger.PrefabFound) return;
var song = CustomLevels.FirstOrDefault(x => x.levelID == level.level.levelID);
Expand All @@ -147,6 +138,24 @@ private void SceneManagerOnSceneLoaded(Scene scene, LoadSceneMode mode)
}
}

private void DelayedNoteJumpMovementSpeedFix()
{
//Beat Saber 0.11.1 introduced a check for if noteJumpMovementSpeed <= 0
//This breaks songs that have a negative noteJumpMovementSpeed and previously required a patcher to get working again
//I've added this to add support for that again, because why not.
if (_currentLevelPlaying.noteJumpMovementSpeed <= 0)
{
var beatmapObjectSpawnController =
Resources.FindObjectsOfTypeAll<BeatmapObjectSpawnController>().FirstOrDefault();
if (beatmapObjectSpawnController != null)
{
beatmapObjectSpawnController.Init(_currentLevelPlaying.level.beatsPerMinute,
_currentLevelPlaying.beatmapData.beatmapLinesData.Length,
_currentLevelPlaying.noteJumpMovementSpeed);
}
}
}

private void StandardLevelListViewControllerOnDidSelectLevelEvent(StandardLevelListViewController arg1, IStandardLevel level)
{
var customLevel = level as CustomLevel;
Expand Down Expand Up @@ -322,6 +331,12 @@ private void LoadSprite(string spritePath, CustomLevel customLevel)
Sprite sprite;
if (!LoadedSprites.ContainsKey(spritePath))
{
if (!File.Exists(spritePath))
{
//Cover image doesn't exist, ignore it.
return;
}

var bytes = File.ReadAllBytes(spritePath);
var tex = new Texture2D(256, 256);
if (!tex.LoadImage(bytes, true))
Expand Down

0 comments on commit 0553c47

Please sign in to comment.