Skip to content

Commit

Permalink
Merge pull request #30 from legoandmars/note-layer
Browse files Browse the repository at this point in the history
2.2.0 update
  • Loading branch information
legoandmars authored Feb 8, 2021
2 parents 439e2d4 + d91c95e commit 19c24be
Show file tree
Hide file tree
Showing 25 changed files with 777 additions and 38 deletions.
25 changes: 25 additions & 0 deletions CustomNotes/CustomNotes.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Reference Include="0Harmony, Version=2.0.2.0, Culture=neutral, processorArchitecture=MSIL">
<Private>False</Private>
<HintPath>$(BeatSaberDir)\Libs\0Harmony.dll</HintPath>
<SpecificVersion>False</SpecificVersion>
</Reference>
<Reference Include="BeatmapCore">
<HintPath>$(BeatSaberDir)\Beat Saber_Data\Managed\BeatmapCore.dll</HintPath>
<Private>False</Private>
Expand Down Expand Up @@ -78,6 +83,10 @@
<HintPath>$(BeatSaberDir)\Plugins\SiraUtil.dll</HintPath>
<SpecificVersion>False</SpecificVersion>
</Reference>
<Reference Include="SongCore, Version=3.0.3.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>$(BeatSaberDir)\Plugins\SongCore.dll</HintPath>
</Reference>
<Reference Include="Unity.TextMeshPro">
<HintPath>$(BeatSaberDir)\Beat Saber_Data\Managed\Unity.TextMeshPro.dll</HintPath>
<Private>False</Private>
Expand All @@ -102,6 +111,10 @@
<HintPath>$(BeatSaberDir)\Beat Saber_Data\Managed\UnityEngine.UI.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="UnityEngine.UIModule, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>$(BeatSaberDir)\Beat Saber_Data\Managed\UnityEngine.UIModule.dll</HintPath>
</Reference>
<Reference Include="Zenject, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<Private>False</Private>
<HintPath>$(BeatSaberDir)\Beat Saber_Data\Managed\Zenject.dll</HintPath>
Expand All @@ -114,19 +127,25 @@
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="HarmonyPatches\CustomNotesPatches.cs" />
<Compile Include="HarmonyPatches\Patches\CameraPlusPatch.cs" />
<Compile Include="Installers\CustomNotesCoreInstaller.cs" />
<Compile Include="Installers\CustomNotesGameInstaller.cs" />
<Compile Include="Installers\CustomNotesMenuInstaller.cs" />
<Compile Include="Managers\CustomBombController.cs" />
<Compile Include="Managers\CustomNoteController.cs" />
<Compile Include="Managers\CustomNotesViewManager.cs" />
<Compile Include="Managers\GameCameraManager.cs" />
<Compile Include="Managers\MenuButtonManager.cs" />
<Compile Include="Managers\CustomNoteManager.cs" />
<Compile Include="Overrides\CustomNoteColorNoteVisuals.cs" />
<Compile Include="Providers\CustomBombNoteProvider.cs" />
<Compile Include="Providers\CustomGameNoteProvider.cs" />
<Compile Include="Settings\UI\NoteDetailsViewController.cs" />
<Compile Include="Settings\UI\NoteModifierViewController.cs" />
<Compile Include="Settings\UI\NotePreviewViewController.cs" />
<Compile Include="Settings\UI\NotesFlowCoordinator.cs" />
<Compile Include="Utilities\LayerUtils.cs" />
<Compile Include="Utilities\MaterialSwapper.cs" />
<Compile Include="Data\CustomNote.cs" />
<Compile Include="Data\NoteExtensions\DisableNoteColorOnGameobject.cs" />
Expand All @@ -151,6 +170,12 @@
<EmbeddedResource Include="Settings\UI\Views\noteList.bsml" />
<EmbeddedResource Include="Settings\UI\Views\notePreview.bsml" />
</ItemGroup>
<ItemGroup>
<Folder Include="Settings\UI\Watermark\" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Settings\UI\Views\noteModifier.bsml" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PostBuildEvent>copy "$(TargetPath)" "$(BeatSaberDir)\Plugins"</PostBuildEvent>
Expand Down
39 changes: 39 additions & 0 deletions CustomNotes/HarmonyPatches/CustomNotesPatches.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using HarmonyLib;
using System.Reflection;

namespace CustomNotes.HarmonyPatches
{
/// <summary>
/// Apply and remove all of our Harmony patches through this class
/// </summary>
public class CustomNotesPatches
{
private static Harmony instance;

public static bool IsPatched { get; private set; }
public const string InstanceId = "com.legoandmars.beatsaber.customnotes";

internal static void ApplyHarmonyPatches()
{
if (!IsPatched)
{
if (instance == null)
{
instance = new Harmony(InstanceId);
}

instance.PatchAll(Assembly.GetExecutingAssembly());
IsPatched = true;
}
}

internal static void RemoveHarmonyPatches()
{
if (instance != null && IsPatched)
{
instance.UnpatchAll(InstanceId);
IsPatched = false;
}
}
}
}
27 changes: 27 additions & 0 deletions CustomNotes/HarmonyPatches/Patches/CameraPlusPatch.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using CustomNotes.Utilities;
using HarmonyLib;
using IPA.Loader;
using System;
using System.Reflection;
using UnityEngine;

namespace CustomNotes.HarmonyPatches
{
[HarmonyPatch]
internal class CameraPlusPatch
{
private static MethodBase TargetMethod()
{
PluginMetadata cameraPlus = PluginManager.GetPluginFromId("CameraPlus");
// Patch should only trigger if CameraPlus is installed and a pre-layerfix version
if (cameraPlus != null && cameraPlus.Assembly.GetName().Version <= new Version("4.7.2")) {
return cameraPlus.Assembly.GetType("CameraPlus.CameraPlusBehaviour").GetMethod("SetCullingMask", BindingFlags.Instance | BindingFlags.NonPublic);
} else return null;
}

private static void Postfix(ref Camera ____cam)
{
LayerUtils.SetCamera(____cam, LayerUtils.CameraView.ThirdPerson);
}
}
}
2 changes: 2 additions & 0 deletions CustomNotes/Installers/CustomNotesCoreInstaller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using CustomNotes.Managers;
using CustomNotes.Providers;
using CustomNotes.Settings.Utilities;
using CustomNotes.Utilities;

namespace CustomNotes.Installers
{
Expand All @@ -13,6 +14,7 @@ internal class CustomNotesCoreInstaller : Installer<PluginConfig, CustomNotesCor
public CustomNotesCoreInstaller(PluginConfig pluginConfig)
{
_pluginConfig = pluginConfig;
LayerUtils.pluginConfig = pluginConfig;
}

public override void InstallBindings()
Expand Down
1 change: 1 addition & 0 deletions CustomNotes/Installers/CustomNotesGameInstaller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public override void InstallBindings()
{
if (_noteAssetLoader.SelectedNote != 0)
{
Container.BindInterfacesAndSelfTo<GameCameraManager>().AsSingle();
Container.Bind<IInitializable>().To<CustomNoteManager>().AsSingle();
}
}
Expand Down
2 changes: 2 additions & 0 deletions CustomNotes/Installers/CustomNotesMenuInstaller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ public override void InstallBindings()
Container.Bind<NotePreviewViewController>().FromNewComponentAsViewController().AsSingle();
Container.Bind<NoteDetailsViewController>().FromNewComponentAsViewController().AsSingle();
Container.Bind<NoteListViewController>().FromNewComponentAsViewController().AsSingle();
Container.BindInterfacesAndSelfTo<NoteModifierViewController>().AsSingle();
Container.BindFlowCoordinator<NotesFlowCoordinator>();

Container.BindInterfacesTo<MenuButtonManager>().AsSingle();
Container.BindInterfacesTo<CustomNotesViewManager>().AsSingle();
}
}
}
50 changes: 45 additions & 5 deletions CustomNotes/Managers/CustomBombController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using UnityEngine;
using CustomNotes.Data;
using CustomNotes.Settings.Utilities;
using CustomNotes.Utilities;
using SiraUtil.Objects;

namespace CustomNotes.Managers
Expand All @@ -15,26 +16,56 @@ internal class CustomBombController : MonoBehaviour
private BombNoteController _bombNoteController;

protected Transform bombMesh;
protected GameObject fakeFirstPersonBombMesh;

protected GameObject activeNote;
protected SiraPrefabContainer container;
protected SiraPrefabContainer.Pool bombPool;

[Inject]
internal void Init(PluginConfig pluginConfig, NoteAssetLoader noteAssetLoader, [Inject(Id = "cn.bomb")] SiraPrefabContainer.Pool bombContainerPool)
internal void Init(PluginConfig pluginConfig, NoteAssetLoader noteAssetLoader, [InjectOptional(Id = "cn.bomb")] SiraPrefabContainer.Pool bombContainerPool)
{
_pluginConfig = pluginConfig;

_customNote = noteAssetLoader.CustomNoteObjects[noteAssetLoader.SelectedNote];
bombPool = bombContainerPool;

_bombNoteController = GetComponent<BombNoteController>();
_noteMovement = GetComponent<NoteMovement>();
_bombNoteController.didInitEvent += Controller_Init;
_noteMovement.noteDidFinishJumpEvent += DidFinish;

if(bombPool != null)
{
_bombNoteController.didInitEvent += Controller_Init;
_noteMovement.noteDidFinishJumpEvent += DidFinish;
}

bombMesh = gameObject.transform.Find("Mesh");
bombPool = bombContainerPool;


MeshRenderer bm = GetComponentInChildren<MeshRenderer>();
bm.enabled = false;

if ((_pluginConfig.HMDOnly || LayerUtils.HMDOverride))
{
if(bombPool == null)
{
// create fake bombs for Custom Notes without Custom Bombs
fakeFirstPersonBombMesh = UnityEngine.Object.Instantiate(bombMesh.gameObject);
fakeFirstPersonBombMesh.name = "FakeFirstPersonBomb";
fakeFirstPersonBombMesh.transform.parent = bombMesh;

fakeFirstPersonBombMesh.transform.localScale = Vector3.one;
fakeFirstPersonBombMesh.transform.localPosition = Vector3.zero;
fakeFirstPersonBombMesh.transform.rotation = Quaternion.identity;
fakeFirstPersonBombMesh.layer = (int)LayerUtils.NoteLayer.FirstPerson;
}

}
else if (bombPool != null)
{
bm.enabled = false;
}


}

private void DidFinish()
Expand Down Expand Up @@ -63,6 +94,14 @@ private void SpawnThenParent(SiraPrefabContainer.Pool bombModelPool)
container = bombModelPool.Spawn();
activeNote = container.Prefab;
bombPool = bombModelPool;
if (_pluginConfig.HMDOnly == true || LayerUtils.HMDOverride == true)
{
LayerUtils.SetLayer(activeNote, LayerUtils.NoteLayer.FirstPerson);
}
else
{
LayerUtils.SetLayer(activeNote, LayerUtils.NoteLayer.Note);
}
ParentNote(activeNote);
}

Expand All @@ -72,6 +111,7 @@ protected void OnDestroy()
{
_bombNoteController.didInitEvent-= Controller_Init;
}
Destroy(fakeFirstPersonBombMesh);
}
}
}
48 changes: 43 additions & 5 deletions CustomNotes/Managers/CustomNoteController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,15 @@ internal void Init(PluginConfig pluginConfig,
noteCube = _gameNoteController.gameObject.transform.Find("NoteCube");

MeshRenderer noteMesh = GetComponentInChildren<MeshRenderer>();
noteMesh.forceRenderingOff = true;
if (_pluginConfig.HMDOnly == false && LayerUtils.HMDOverride == false)
{
// only disable if custom notes display on both hmd and display
noteMesh.forceRenderingOff = true;
}
else
{
noteMesh.gameObject.layer = (int) LayerUtils.NoteLayer.ThirdPerson;
}
}

private void DidFinish(NoteController nc)
Expand Down Expand Up @@ -105,6 +113,14 @@ private void SpawnThenParent(SiraPrefabContainer.Pool noteModelPool)
container = noteModelPool.Spawn();
activeNote = container.Prefab;
activePool = noteModelPool;
if (_pluginConfig.HMDOnly == true || LayerUtils.HMDOverride == true)
{
LayerUtils.SetLayer(activeNote, LayerUtils.NoteLayer.FirstPerson);
}
else
{
LayerUtils.SetLayer(activeNote, LayerUtils.NoteLayer.Note);
}
ParentNote(activeNote);
}

Expand All @@ -121,13 +137,35 @@ private void Visuals_DidInit(ColorNoteVisuals visuals, NoteController noteContro
{
SetActiveThenColor(activeNote, visuals.noteColor);
// Hide certain parts of the default note which is not required
if (_customNote.Descriptor.DisableBaseNoteArrows)
if(_pluginConfig.HMDOnly == false && LayerUtils.HMDOverride == false)
{
_customNoteColorNoteVisuals.TurnOffVisuals();
_customNoteColorNoteVisuals.SetBaseGameVisualsLayer((int) LayerUtils.NoteLayer.Note);
if (_customNote.Descriptor.DisableBaseNoteArrows)
{
_customNoteColorNoteVisuals.TurnOffVisuals();
}
else if (_pluginConfig.NoteSize != 1)
{
_customNoteColorNoteVisuals.ScaleVisuals(_pluginConfig.NoteSize);
}
}
else if(_pluginConfig.NoteSize != 1)
else
{
_customNoteColorNoteVisuals.ScaleVisuals(_pluginConfig.NoteSize);
// HMDOnly code
_customNoteColorNoteVisuals.SetBaseGameVisualsLayer((int) LayerUtils.NoteLayer.ThirdPerson);
if (!_customNote.Descriptor.DisableBaseNoteArrows)
{
if (_pluginConfig.NoteSize != 1)
{
// arrows should be enabled in both views, with fake arrows rescaled
_customNoteColorNoteVisuals.CreateAndScaleFakeVisuals((int)LayerUtils.NoteLayer.FirstPerson, _pluginConfig.NoteSize);
}
else
{
// arrows should be enabled in both views
_customNoteColorNoteVisuals.CreateFakeVisuals((int)LayerUtils.NoteLayer.FirstPerson);
}
}
}
}

Expand Down
17 changes: 14 additions & 3 deletions CustomNotes/Managers/CustomNoteManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
using CustomNotes.Data;
using SiraUtil.Services;
using CustomNotes.Utilities;
using System;
using CustomNotes.Settings.Utilities;
using IPA.Loader;
using System.Linq;

namespace CustomNotes.Managers
{
Expand All @@ -10,25 +14,28 @@ internal class CustomNoteManager : IInitializable
private readonly Submission _submission;
private readonly NoteAssetLoader _noteAssetLoader;
private readonly GameplayCoreSceneSetupData _gameplayCoreSceneSetupData;
private readonly PluginConfig _pluginConfig;
private readonly IDifficultyBeatmap _level;

internal CustomNoteManager([InjectOptional] Submission submission, NoteAssetLoader noteAssetLoader, GameplayCoreSceneSetupData gameplayCoreSceneSetupData)
internal CustomNoteManager([InjectOptional] Submission submission, NoteAssetLoader noteAssetLoader, GameplayCoreSceneSetupData gameplayCoreSceneSetupData, PluginConfig pluginConfig, IDifficultyBeatmap level)
{
_submission = submission;
_noteAssetLoader = noteAssetLoader;
_gameplayCoreSceneSetupData = gameplayCoreSceneSetupData;
_pluginConfig = pluginConfig;
_level = level;
}

public void Initialize()
{
if (_noteAssetLoader.SelectedNote != 0)
{
CustomNote activeNote = _noteAssetLoader.CustomNoteObjects[_noteAssetLoader.SelectedNote];


if (activeNote.NoteBomb != null)
{
MaterialSwapper.ReplaceMaterialsForGameObject(activeNote.NoteBomb);
}

if (_gameplayCoreSceneSetupData.gameplayModifiers.ghostNotes)
{
_submission?.DisableScoreSubmission("Custom Notes", "Ghost Notes");
Expand All @@ -37,6 +44,10 @@ public void Initialize()
{
_submission?.DisableScoreSubmission("Custom Notes", "Disappearing Arrows");
}
if (Utils.IsNoodleMap(_level))
{
_submission?.DisableScoreSubmission("Custom Notes", "Noodle Extensions");
}
}
}
}
Expand Down
Loading

0 comments on commit 19c24be

Please sign in to comment.