Skip to content

Commit

Permalink
Merge pull request #1 from Pespiri/bsipa4-update
Browse files Browse the repository at this point in the history
Beat Saber 1.8.0 and BSIPA4 update
  • Loading branch information
Pespiri authored Mar 26, 2020
2 parents 5c7f934 + 96775ac commit 26a1741
Show file tree
Hide file tree
Showing 14 changed files with 107 additions and 77 deletions.
17 changes: 10 additions & 7 deletions CustomWalls/CustomWalls.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Reference Include="0Harmony.1.2.0.1">
<HintPath>$(BeatSaberDir)\Libs\0Harmony.1.2.0.1.dll</HintPath>
<Reference Include="0Harmony">
<HintPath>$(BeatSaberDir)\Libs\0Harmony.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="BSML">
Expand All @@ -48,20 +48,24 @@
<HintPath>$(BeatSaberDir)\Beat Saber_Data\Managed\HMLib.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="HMRendering">
<HintPath>$(BeatSaberDir)\Beat Saber_Data\Managed\HMRendering.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="HMUI">
<HintPath>$(BeatSaberDir)\Beat Saber_Data\Managed\HMUI.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="MainAssembly">
<HintPath>$(BeatSaberDir)\Beat Saber_Data\Managed\MainAssembly.dll</HintPath>
<Reference Include="Main">
<HintPath>$(BeatSaberDir)\Beat Saber_Data\Managed\Main.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="IPA.Loader">
<HintPath>$(BeatSaberDir)\Beat Saber_Data\Managed\IPA.Loader.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="SemVer.1.2.0.0">
<HintPath>$(BeatSaberDir)\Libs\SemVer.1.2.0.0.dll</HintPath>
<Reference Include="SemVer">
<HintPath>$(BeatSaberDir)\Libs\SemVer.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="System" />
Expand Down Expand Up @@ -127,5 +131,4 @@
<PropertyGroup>
<PostBuildEvent>copy "$(TargetPath)" "$(BeatSaberDir)\Plugins"</PostBuildEvent>
</PropertyGroup>
<ProjectExtensions />
</Project>
19 changes: 11 additions & 8 deletions CustomWalls/Data/CustomMaterial.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public class CustomMaterial
public MaterialDescriptor Descriptor { get; }
public GameObject GameObject { get; }
public Renderer MaterialRenderer { get; }
public string ErrorMessage { get; } = string.Empty;

public CustomMaterial(string fileName)
{
Expand All @@ -37,13 +38,14 @@ public CustomMaterial(string fileName)
{
MaterialName = "Invalid Wall (Delete it!)",
AuthorName = fileName,
Description = $"File: '{fileName}'" +
Icon = Utils.GetErrorIcon()
};

ErrorMessage = $"File: '{fileName}'" +
"\n\nThis file failed to load." +
"\n\nThis may have been caused by having duplicated files," +
" another wall with the same name already exists or that the custom wall is simply just broken." +
"\n\nThe best thing is probably just to delete it!",
Icon = Utils.GetErrorIcon()
};
"\n\nThe best thing is probably just to delete it!";

FileName = "DefaultMaterials";
}
Expand Down Expand Up @@ -82,13 +84,14 @@ public CustomMaterial(byte[] materialObject, string name)
{
MaterialName = "Internal Error (Report it!)",
AuthorName = $@"internalResource\{name}",
Description = $@"File: 'internalResource\\{name}'" +
Icon = Utils.GetErrorIcon()
};

ErrorMessage = $@"File: 'internalResource\\{name}'" +
"\n\nAn internal asset has failed to load." +
"\n\nThis shouldn't have happened and should be reported!" +
" Remember to include the log related to this incident." +
"\n\nDiscord: Pespiri#5919",
Icon = Utils.GetErrorIcon()
};
"\n\nDiscord: Pespiri#5919";

FileName = "DefaultMaterials";
}
Expand Down
6 changes: 3 additions & 3 deletions CustomWalls/HarmonyPatches/CustomMaterialsPatches.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Harmony;
using HarmonyLib;
using System.Reflection;

namespace CustomWalls.HarmonyPatches
Expand All @@ -8,7 +8,7 @@ namespace CustomWalls.HarmonyPatches
/// </summary>
public class CustomMaterialsPatches
{
private static HarmonyInstance instance;
private static Harmony instance;

public static bool IsPatched { get; private set; }
public const string InstanceId = "com.pespiri.beatsaber.pixiedust";
Expand All @@ -19,7 +19,7 @@ internal static void ApplyHarmonyPatches()
{
if (instance == null)
{
instance = HarmonyInstance.Create(InstanceId);
instance = new Harmony(InstanceId);
}

instance.PatchAll(Assembly.GetExecutingAssembly());
Expand Down
2 changes: 1 addition & 1 deletion CustomWalls/HarmonyPatches/Patches/WallPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using CustomWalls.Data;
using CustomWalls.Settings;
using CustomWalls.Utilities;
using Harmony;
using HarmonyLib;
using System;
using UnityEngine;

Expand Down
58 changes: 32 additions & 26 deletions CustomWalls/Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,63 +10,57 @@
using System.IO;
using System.Linq;
using UnityEngine;
using UnityEngine.SceneManagement;
using IPALogger = IPA.Logging.Logger;

namespace CustomWalls
{
public class Plugin : IBeatSaberPlugin, IDisablablePlugin
[Plugin(RuntimeOptions.DynamicInit)]
public class Plugin
{
public static string PluginName => "CustomWalls";
public static SemVer.Version PluginVersion { get; private set; } = new SemVer.Version("0.0.0");
public static string PluginAssetPath => Path.Combine(BeatSaber.InstallPath, "CustomWalls");
public static string PluginAssetPath => Path.Combine(UnityGame.InstallPath, "CustomWalls");

public void Init(IPALogger logger, [Config.Prefer("json")] IConfigProvider cfgProvider, PluginLoader.PluginMetadata metadata)
[Init]
public void Init(IPALogger logger, Config config, PluginMetadata metadata)
{
Logger.log = logger;
Configuration.Init(cfgProvider);
Configuration.Init(config);

if (metadata?.Version != null)
{
PluginVersion = metadata.Version;
}
}

[OnEnable]
public void OnEnable() => Load();
[OnDisable]
public void OnDisable() => Unload();
public void OnApplicationQuit() => Unload();

public void OnActiveSceneChanged(Scene prevScene, Scene nextScene)
private void OnGameSceneLoaded()
{
if (nextScene.name == "GameCore")
{
MaterialUtils.CurrentColorManager = Resources.FindObjectsOfTypeAll<ColorManager>().LastOrDefault();
MaterialUtils.CurrentColorManager = Resources.FindObjectsOfTypeAll<ColorManager>().LastOrDefault();

CustomMaterial customMaterial = MaterialAssetLoader.CustomMaterialObjects[MaterialAssetLoader.SelectedMaterial];
if (customMaterial.Descriptor.DisablesScore
|| Configuration.UserDisabledScores)
{
ScoreUtility.DisableScoreSubmission("Material");
}
else if (ScoreUtility.ScoreIsBlocked)
{
ScoreUtility.EnableScoreSubmission("Material");
}
CustomMaterial customMaterial = MaterialAssetLoader.CustomMaterialObjects[MaterialAssetLoader.SelectedMaterial];
if (customMaterial.Descriptor.DisablesScore
|| Configuration.UserDisabledScores)
{
ScoreUtility.DisableScoreSubmission("Material");
}
else if (ScoreUtility.ScoreIsBlocked)
{
ScoreUtility.EnableScoreSubmission("Material");
}
}

public void OnApplicationStart() { }
public void OnSceneLoaded(Scene scene, LoadSceneMode sceneMode) { }
public void OnSceneUnloaded(Scene scene) { }
public void OnUpdate() { }
public void OnFixedUpdate() { }

private void Load()
{
Configuration.Load();
MaterialAssetLoader.Load();
CustomMaterialsPatches.ApplyHarmonyPatches();
SettingsUI.CreateMenu();
AddEvents();

Logger.log.Info($"{PluginName} v.{PluginVersion} has started.");
}
Expand All @@ -77,6 +71,18 @@ private void Unload()
CustomMaterialsPatches.RemoveHarmonyPatches();
Configuration.Save();
MaterialAssetLoader.Clear();
RemoveEvents();
}

private void AddEvents()
{
RemoveEvents();
BS_Utils.Utilities.BSEvents.gameSceneLoaded += OnGameSceneLoaded;
}

private void RemoveEvents()
{
BS_Utils.Utilities.BSEvents.gameSceneLoaded -= OnGameSceneLoaded;
}
}
}
4 changes: 2 additions & 2 deletions CustomWalls/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@
// Build Number
// Revision
//
[assembly: AssemblyVersion("1.2.0.0")]
[assembly: AssemblyFileVersion("1.2.0.0")]
[assembly: AssemblyVersion("1.3.0.0")]
[assembly: AssemblyFileVersion("1.3.0.0")]
27 changes: 7 additions & 20 deletions CustomWalls/Settings/Configuration.cs
Original file line number Diff line number Diff line change
@@ -1,44 +1,31 @@
using CustomWalls.Settings.Utilities;
using IPA.Config;
using IPA.Utilities;
using IPA.Config.Stores;

namespace CustomWalls.Settings
{
public class Configuration
{
private static Ref<PluginConfig> config;
private static IConfigProvider configProvider;

public static string CurrentlySelectedMaterial { get; internal set; }
public static bool EnableObstacleFrame { get; internal set; }

public static bool UserDisabledScores { get; internal set; }

internal static void Init(IConfigProvider cfgProvider)
internal static void Init(Config config)
{
configProvider = cfgProvider;
config = cfgProvider.MakeLink<PluginConfig>((p, v) =>
{
if (v.Value == null || v.Value.RegenerateConfig)
{
p.Store(v.Value = new PluginConfig() { RegenerateConfig = false });
}
config = v;
});
PluginConfig.Instance = config.Generated<PluginConfig>();
}

internal static void Load()
{
CurrentlySelectedMaterial = config.Value.SelectedWallMaterial;
EnableObstacleFrame = config.Value.EnableObstacleFrame;
CurrentlySelectedMaterial = PluginConfig.Instance.SelectedWallMaterial;
EnableObstacleFrame = PluginConfig.Instance.EnableObstacleFrame;
}

internal static void Save()
{
config.Value.SelectedWallMaterial = CurrentlySelectedMaterial;
config.Value.EnableObstacleFrame = EnableObstacleFrame;

configProvider.Store(config.Value);
PluginConfig.Instance.SelectedWallMaterial = CurrentlySelectedMaterial;
PluginConfig.Instance.EnableObstacleFrame = EnableObstacleFrame;
}
}
}
1 change: 1 addition & 0 deletions CustomWalls/Settings/UI/MaterialDetailsViewController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using BeatSaberMarkupLanguage.ViewControllers;
using CustomWalls.Data;
using CustomWalls.Utilities;
using HMUI;
using TMPro;

namespace CustomWalls.Settings.UI
Expand Down
22 changes: 21 additions & 1 deletion CustomWalls/Settings/UI/MaterialPreviewViewController.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,29 @@
using BeatSaberMarkupLanguage.ViewControllers;
using BeatSaberMarkupLanguage.Attributes;
using BeatSaberMarkupLanguage.ViewControllers;
using CustomWalls.Data;
using CustomWalls.Utilities;
using HMUI;

namespace CustomWalls.Settings.UI
{
internal class MaterialPreviewViewController : BSMLResourceViewController
{
public override string ResourceName => "CustomWalls.Settings.UI.Views.materialPreview.bsml";

[UIComponent("error-description")]
public TextPageScrollView errorDescription;

public void OnMaterialWasChanged(CustomMaterial customMaterial)
{
if (!string.IsNullOrWhiteSpace(customMaterial?.ErrorMessage))
{
errorDescription.gameObject.SetActive(true);
errorDescription.SetText($"{customMaterial.Descriptor?.MaterialName}:\n\n{Utils.SafeUnescape(customMaterial.ErrorMessage)}");
}
else
{
errorDescription.gameObject.SetActive(false);
}
}
}
}
12 changes: 10 additions & 2 deletions CustomWalls/Settings/UI/MaterialsFlowCoordinator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,16 @@ public void Awake()
if (!materialsListView)
{
materialsListView = BeatSaberUI.CreateViewController<MaterialListViewController>();
materialsListView.customMaterialChanged += materialsDescriptionView.OnMaterialWasChanged;

if (materialsDescriptionView)
{
materialsListView.customMaterialChanged += materialsDescriptionView.OnMaterialWasChanged;
}

if (materialsPreviewView)
{
materialsListView.customMaterialChanged += materialsPreviewView.OnMaterialWasChanged;
}
}
}

Expand All @@ -48,7 +57,6 @@ protected override void DidActivate(bool firstActivation, ActivationType activat

protected override void BackButtonWasPressed(ViewController topViewController)
{
// Dismiss ourselves
BeatSaberUI.MainFlowCoordinator.DismissFlowCoordinator(this, null, false);
}
}
Expand Down
3 changes: 3 additions & 0 deletions CustomWalls/Settings/UI/Views/materialPreview.bsml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@
<horizontal bg='panel-top' pad-left='10' pad-right='10' horizontal-fit='PreferredSize'>
<text text='Wall Preview' align='Center' font-size='10' />
</horizontal>
<horizontal pref-width='100' pref-height='45'>
<text-page id='error-description' />
</horizontal>
</vertical>
2 changes: 1 addition & 1 deletion CustomWalls/Settings/Utilities/PluginConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{
public class PluginConfig
{
public bool RegenerateConfig = true;
public static PluginConfig Instance { get; set; }

public string SelectedWallMaterial;
public bool EnableObstacleFrame = true;
Expand Down
6 changes: 3 additions & 3 deletions CustomWalls/Utilities/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -172,10 +172,10 @@ public static bool IsPluginEnabled(string pluginName)
{
if (IsPluginPresent(pluginName))
{
PluginLoader.PluginInfo pluginInfo = PluginManager.GetPluginFromId(pluginName);
if (pluginInfo?.Metadata != null)
PluginMetadata metadata = PluginManager.GetPluginFromId(pluginName);
if (metadata != null)
{
return PluginManager.IsEnabled(pluginInfo.Metadata);
return PluginManager.IsEnabled(metadata);
}
}

Expand Down
Loading

0 comments on commit 26a1741

Please sign in to comment.