Skip to content

Commit

Permalink
Merge pull request #167 from nicoco007/beat-saber-1.32.0
Browse files Browse the repository at this point in the history
Update for 1.32.0+
  • Loading branch information
ToniMacaroni authored Feb 15, 2024
2 parents 2669430 + ed35486 commit f374b9b
Show file tree
Hide file tree
Showing 17 changed files with 94 additions and 82 deletions.
9 changes: 6 additions & 3 deletions SaberFactory/Configuration/ConfigBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using System.Reflection;
using Newtonsoft.Json;
using SaberFactory.Helpers;
using UnityEngine;
using SiraUtil.Logging;
using Zenject;

namespace SaberFactory.Configuration
Expand All @@ -19,13 +19,16 @@ public abstract class ConfigBase : IInitializable, IDisposable

protected readonly FileInfo ConfigFile;

private readonly SiraLog _logger;

private readonly Dictionary<PropertyInfo, object> _originalValues = new Dictionary<PropertyInfo, object>();

private bool _didLoadingFail;

protected ConfigBase(PluginDirectories pluginDirs, string fileName)
protected ConfigBase(PluginDirectories pluginDirs, SiraLog logger, string fileName)
{
ConfigFile = pluginDirs.SaberFactoryDir.GetFile(fileName);
_logger = logger;
}

public void Dispose()
Expand Down Expand Up @@ -74,7 +77,7 @@ public void Load()
catch (Exception)
{
_didLoadingFail = true;
Debug.LogError($"[Saber Factory Configs] Failed to load config file {ConfigFile.Name}");
_logger.Error($"[Saber Factory Configs] Failed to load config file {ConfigFile.Name}");
}
}

Expand Down
12 changes: 1 addition & 11 deletions SaberFactory/Configuration/PluginConfig.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
using System.Collections.Generic;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using IPA.Config.Stores;
using IPA.Config.Stores.Attributes;
using IPA.Config.Stores.Converters;
using JetBrains.Annotations;
using UnityEngine;

[assembly: InternalsVisibleTo(GeneratedStore.AssemblyVisibilityTarget)]

namespace SaberFactory.Configuration
{
internal class PluginConfig : INotifyPropertyChanged
internal class PluginConfig
{
public bool Enabled { get; set; } = true;

Expand Down Expand Up @@ -122,13 +120,5 @@ public bool IsFavorite(string path)
{
return Favorites.Contains(path);
}

public event PropertyChangedEventHandler PropertyChanged;

[NotifyPropertyChangedInvocator]
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
}
6 changes: 4 additions & 2 deletions SaberFactory/Configuration/TrailConfig.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace SaberFactory.Configuration
using SiraUtil.Logging;

namespace SaberFactory.Configuration
{
public class TrailConfig : ConfigBase
{
Expand All @@ -8,7 +10,7 @@ public class TrailConfig : ConfigBase

public bool OnlyUseVertexColor { get; set; } = true;

public TrailConfig(PluginDirectories pluginDirs) : base(pluginDirs, "TrailConfig.json")
public TrailConfig(PluginDirectories pluginDirs, SiraLog logger) : base(pluginDirs, logger, "TrailConfig.json")
{ }
}
}
3 changes: 2 additions & 1 deletion SaberFactory/DataStore/MainAssetStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,15 @@ public class MainAssetStore : IDisposable, ILoadingTask
private MainAssetStore(
PluginConfig config,
SiraLog logger,
CustomSaberAssetLoader customSaberAssetLoader,
CustomSaberModelLoader customSaberModelLoader,
PluginDirectories pluginDirs)
{
_config = config;
_logger = logger;
_pluginDirs = pluginDirs;

_customSaberAssetLoader = new CustomSaberAssetLoader();
_customSaberAssetLoader = customSaberAssetLoader;
_customSaberModelLoader = customSaberModelLoader;

_modelCompositions = new Dictionary<string, ModelComposition>();
Expand Down
8 changes: 5 additions & 3 deletions SaberFactory/Game/GameSaberSetup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using SaberFactory.DataStore;
using SaberFactory.Helpers;
using SaberFactory.Models;
using UnityEngine;
using SiraUtil.Logging;
using Zenject;

namespace SaberFactory.Game
Expand All @@ -22,15 +22,17 @@ internal class GameSaberSetup : IInitializable, IDisposable
private readonly SaberModel _oldRightSaberModel;
private readonly RandomUtil _randomUtil;
private readonly SaberSet _saberSet;
private readonly SiraLog _logger;

private GameSaberSetup(PluginConfig config, SaberSet saberSet, MainAssetStore mainAssetStore,
IReadonlyBeatmapData beatmap, RandomUtil randomUtil)
IReadonlyBeatmapData beatmap, RandomUtil randomUtil, SiraLog logger)
{
_config = config;
_saberSet = saberSet;
_mainAssetStore = mainAssetStore;
_beatmapData = beatmap.CastChecked<BeatmapData>();
_randomUtil = randomUtil;
_logger = logger;

_oldLeftSaberModel = _saberSet.LeftSaber;
_oldRightSaberModel = _saberSet.RightSaber;
Expand Down Expand Up @@ -105,7 +107,7 @@ private async Task SetupSongSaber()
}
catch (Exception e)
{
Debug.LogError(e.ToString());
_logger.Error(e.ToString());
}
}
}
Expand Down
8 changes: 5 additions & 3 deletions SaberFactory/Game/SaberMovementTester.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@ internal class SaberMovementTester : IInitializable
private readonly AudioTimeSyncController _audioController;
private readonly InitData _initData;
private readonly SiraSaberFactory _saberFactory;
private readonly ICoroutineStarter _coroutineStarter;
private SiraSaber _saber;

private SaberMovementTester(InitData initData, SiraSaberFactory saberFactory, AudioTimeSyncController audioController)
private SaberMovementTester(InitData initData, SiraSaberFactory saberFactory, AudioTimeSyncController audioController, ICoroutineStarter coroutineStarter)
{
_initData = initData;
_saberFactory = saberFactory;
_audioController = audioController;
_coroutineStarter = coroutineStarter;
}

public async void Initialize()
Expand All @@ -37,8 +39,8 @@ public async void Initialize()
var saberA = CreateSaber(SaberType.SaberA, new Vector3(0, 0.6f, 0), Quaternion.Euler(90, 0, 0));
var saberB = CreateSaber(SaberType.SaberB, new Vector3(0, 0.6f, 0), Quaternion.Euler(90, 0, 0));

SharedCoroutineStarter.instance.StartCoroutine(GroundRoundAnimationCoroutine(-0.2f, saberA));
SharedCoroutineStarter.instance.StartCoroutine(GroundRoundAnimationCoroutine(0.2f, saberB));
_coroutineStarter.StartCoroutine(GroundRoundAnimationCoroutine(-0.2f, saberA));
_coroutineStarter.StartCoroutine(GroundRoundAnimationCoroutine(0.2f, saberB));

// Don't try this at home
var allLRs = Object.FindObjectsOfType<LineRenderer>()
Expand Down
41 changes: 13 additions & 28 deletions SaberFactory/Helpers/Readers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,15 +112,6 @@ public static async Task<Tuple<T, AssetBundle>> LoadAssetFromAssetBundleAsync<T>
return new Tuple<T, AssetBundle>(asset, assetBundle);
}

//public static async Task<Tuple<T, AssetBundle>> LoadAssetFromAssetBundleAsync<T>(string path,
// string assetName) where T : UnityEngine.Object
//{
// var fileData = await ReadFileAsync(path);
// if (fileData == null) return null;
// var asset = await LoadAssetFromAssetBundleAsync<T>(fileData, assetName);
// return asset;
//}

public static async Task<Tuple<T, AssetBundle>> LoadAssetFromAssetBundleAsync<T>(string path, string assetName) where T : Object
{
var tcs = new TaskCompletionSource<Tuple<T, AssetBundle>>();
Expand All @@ -135,28 +126,22 @@ public static async Task<Tuple<T, AssetBundle>> LoadAssetFromAssetBundleAsync<T>
}

var assetRequest = createRequest.assetBundle.LoadAssetAsync<T>(assetName);
assetRequest.completed += delegate { tcs.SetResult(new Tuple<T, AssetBundle>((T)assetRequest.asset, createRequest.assetBundle)); };
};
assetRequest.completed += delegate
{
Object asset = assetRequest.asset;

return await tcs.Task;
}

public static async Task<Tuple<T, AssetBundle>> LoadAssetFromAssetBundleSafeAsync<T>(string path, string assetName) where T : Object
{
var bundle = await AssetBundleExtensions.LoadFromFileAsync(path);
if (!bundle)
{
return null;
}
if (asset == null)
{
createRequest.assetBundle.Unload(true);
tcs.SetResult(null);
return;
}

var asset = await AssetBundleExtensions.LoadAssetAsync<T>(bundle, assetName);
if (!asset)
{
bundle.Unload(true);
return null;
}
tcs.SetResult(new Tuple<T, AssetBundle>((T)asset, createRequest.assetBundle));
};
};

return new Tuple<T, AssetBundle>(asset, bundle);
return await tcs.Task;
}
}
}
2 changes: 2 additions & 0 deletions SaberFactory/Installers/PluginAppInstaller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using SaberFactory.Instances;
using SaberFactory.Instances.PostProcessors;
using SaberFactory.Instances.Trail;
using SaberFactory.Loaders;
using SaberFactory.Misc;
using SaberFactory.Models;
using SaberFactory.Models.CustomSaber;
Expand Down Expand Up @@ -61,6 +62,7 @@ public override void InstallBindings()

Container.BindInterfacesAndSelfTo<EmbeddedAssetLoader>().AsSingle();

Container.Bind<CustomSaberAssetLoader>().AsSingle();
Container.Bind<CustomSaberModelLoader>().AsSingle();

Container.Bind<TextureStore>().AsSingle();
Expand Down
29 changes: 22 additions & 7 deletions SaberFactory/Loaders/CustomSaberAssetLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,23 @@
using IPA.Utilities;
using SaberFactory.DataStore;
using SaberFactory.Helpers;
using SiraUtil.Logging;
using UnityEngine;

namespace SaberFactory.Loaders
{
internal class CustomSaberAssetLoader : AssetBundleLoader
{
private readonly SiraLog _logger;
private readonly Material _defaultMaterial;

private CustomSaberAssetLoader(SiraLog logger)
{
_logger = logger;
_defaultMaterial = new Material(Shader.Find("Hidden/InternalErrorShader"));
}


public override string HandledExtension => ".saber";

public override ISet<AssetMetaPath> CollectFiles(PluginDirectories dirs)
Expand All @@ -35,23 +46,25 @@ public override async Task<StoreAsset> LoadStoreAssetAsync(string relativePath)
return null;
}

var result = await Readers.LoadAssetFromAssetBundleSafeAsync<GameObject>(fullPath, "_CustomSaber");
var result = await Readers.LoadAssetFromAssetBundleAsync<GameObject>(fullPath, "_CustomSaber");
if (result == null)
{
return null;
}

// GameScenesManager might call Resources.UnloadUnusedAssets while we're still working on this
result.Item1.hideFlags |= HideFlags.DontUnloadUnusedAsset;

var info = await ShaderRepair.FixShadersOnGameObjectAsync(result.Item1);
if (!info.AllShadersReplaced)
{
Debug.LogWarning($"Missing shader replacement data for {relativePath}:");
_logger.Warn($"Missing shader replacement data for {relativePath}:");
foreach (var shaderName in info.MissingShaderNames)
{
Debug.LogWarning($"\t- {shaderName}");
_logger.Warn($"\t- {shaderName}");
}
}


var trailsList = result.Item1.GetComponentsInChildren<CustomTrail>();
var matDict = new Dictionary<Material, List<CustomTrail>>();

Expand All @@ -76,11 +89,13 @@ public override async Task<StoreAsset> LoadStoreAssetAsync(string relativePath)

if (!trailInfo.AllShadersReplaced)
{
Debug.LogWarning("Missing trail shader replacement data. Using default trail");
trails.Do(x=>x.TrailMaterial = null);
_logger.Warn("Missing trail shader replacement data. Using default trail");
trails.Do(x => x.TrailMaterial = _defaultMaterial);
}
}


result.Item1.hideFlags &= ~HideFlags.DontUnloadUnusedAsset;

return new StoreAsset(relativePath, result.Item1, result.Item2);
}

Expand Down
6 changes: 2 additions & 4 deletions SaberFactory/Misc/RemotePartRetriever.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
using Newtonsoft.Json;
using SaberFactory.DataStore;
using SaberFactory.Models;
using SiraUtil.Logging;
using SiraUtil.Web;
using UnityEngine;
using Zenject;

namespace SaberFactory.Misc
Expand Down Expand Up @@ -39,7 +37,7 @@ public void Initialize()

public async Task Retrieve()
{
Debug.LogWarning("Loading remote sabers");
_logger.Warn("Loading remote sabers");

RemoteSabers.Clear();

Expand All @@ -63,7 +61,7 @@ public async Task Retrieve()
}
catch (Exception e)
{
Console.WriteLine(e);
_logger.Error(e);
RetrievingStatus = Status.Failed;
return;
}
Expand Down
10 changes: 10 additions & 0 deletions SaberFactory/SaberFactory.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,16 @@
<Reference Include="AssetBundleLoadingTools">
<HintPath>$(BeatSaberDir)\Plugins\AssetBundleLoadingTools.dll</HintPath>
</Reference>
<Reference Include="BGLib.AppFlow">
<HintPath>$(BeatSaberDir)\Beat Saber_Data\Managed\BGLib.AppFlow.dll</HintPath>
<Private>False</Private>
<SpecificVersion>False</SpecificVersion>
</Reference>
<Reference Include="BGLib.UnityExtension">
<HintPath>$(BeatSaberDir)\Beat Saber_Data\Managed\BGLib.UnityExtension.dll</HintPath>
<Private>False</Private>
<SpecificVersion>False</SpecificVersion>
</Reference>
<Reference Include="CameraUtils">
<HintPath>$(BeatSaberDir)\Plugins\CameraUtils.dll</HintPath>
<Private>False</Private>
Expand Down
6 changes: 4 additions & 2 deletions SaberFactory/SaberFileWatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ public class SaberFileWatcher

public bool IsWatching { get; private set; }
private readonly DirectoryInfo _dir;
private readonly ICoroutineStarter _coroutineStarter;

private FileSystemWatcher _watcher;

public SaberFileWatcher(PluginDirectories dirs)
public SaberFileWatcher(PluginDirectories dirs, ICoroutineStarter coroutineStarter)
{
_dir = dirs.CustomSaberDir;
_coroutineStarter = coroutineStarter;
}

public event Action<string> OnSaberUpdate;
Expand All @@ -42,7 +44,7 @@ public void Watch()

private void WatcherOnCreated(object sender, FileSystemEventArgs e)
{
HMMainThreadDispatcher.instance.Enqueue(Initiate(e.FullPath));
_coroutineStarter.StartCoroutine(Initiate(e.FullPath));
}

private IEnumerator Initiate(string filename)
Expand Down
2 changes: 1 addition & 1 deletion SaberFactory/UI/CustomSaber/Views/TrailSettingsView.bsml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
child-expand-height='false' child-control-height='false' spacing='2' pad='3'>

<vertical bg='panel-top' skew='0' bg-color='#00b6ff40' pad='2' vertical-fit='PreferredSize'>
<text text='You can modify the lenght and width using the thumbstick!' color='#ffffff80' font-size='3.5' align='Center'
<text text='You can modify the length and width using the thumbstick!' color='#ffffff80' font-size='3.5' align='Center'
active='~ShowThumbstickMessage'/>
<slider-setting text='Length' value='LengthValue' get-event='update-props,update-proportions' apply-on-change='true' increment="1"
min='0' max='30'/>
Expand Down
Loading

0 comments on commit f374b9b

Please sign in to comment.