Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom Notes for other players #26

Draft
wants to merge 8 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions CustomNotes/CustomNotes.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@
<HintPath>$(BeatSaberDir)\Beat Saber_Data\Managed\BeatmapCore.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="BGNet, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<Private>False</Private>
<HintPath>$(BeatSaberDir)\Beat Saber_Data\Managed\BGNet.dll</HintPath>
<SpecificVersion>False</SpecificVersion>
</Reference>
<Reference Include="BSML">
<HintPath>$(BeatSaberDir)\Plugins\BSML.dll</HintPath>
<Private>False</Private>
Expand Down Expand Up @@ -65,10 +70,20 @@
<HintPath>$(BeatSaberDir)\Beat Saber_Data\Managed\IPA.Loader.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="LiteNetLib, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<Private>False</Private>
<HintPath>$(BeatSaberDir)\Beat Saber_Data\Managed\LiteNetLib.dll</HintPath>
<SpecificVersion>False</SpecificVersion>
</Reference>
<Reference Include="Main">
<HintPath>$(BeatSaberDir)\Beat Saber_Data\Managed\Main.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="MultiplayerExtensions, Version=0.4.3.0, Culture=neutral, processorArchitecture=MSIL">
<Private>False</Private>
<HintPath>$(BeatSaberDir)\Plugins\MultiplayerExtensions.dll</HintPath>
<SpecificVersion>False</SpecificVersion>
</Reference>
<Reference Include="SemVer">
<HintPath>$(BeatSaberDir)\Libs\SemVer.dll</HintPath>
<Private>False</Private>
Expand All @@ -78,6 +93,7 @@
<HintPath>$(BeatSaberDir)\Plugins\SiraUtil.dll</HintPath>
<SpecificVersion>False</SpecificVersion>
</Reference>
<Reference Include="System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL" />
<Reference Include="Unity.TextMeshPro">
<HintPath>$(BeatSaberDir)\Beat Saber_Data\Managed\Unity.TextMeshPro.dll</HintPath>
<Private>False</Private>
Expand Down Expand Up @@ -114,18 +130,29 @@
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Data\MultiplayerCustomNoteData.cs" />
<Compile Include="Installers\CustomNotesCoreInstaller.cs" />
<Compile Include="Installers\CustomNotesGameInstaller.cs" />
<Compile Include="Installers\CustomNotesMenuInstaller.cs" />
<Compile Include="Interfaces\ICustomNoteNetworkPacketManager.cs" />
<Compile Include="Managers\CustomBombController.cs" />
<Compile Include="Managers\CustomMultiplayerBombController.cs" />
<Compile Include="Managers\CustomMultiplayerNoteController.cs" />
<Compile Include="Managers\CustomNoteController.cs" />
<Compile Include="Managers\CustomMultiplayerNoteEventManager.cs" />
<Compile Include="Managers\MenuButtonManager.cs" />
<Compile Include="Managers\CustomNoteManager.cs" />
<Compile Include="Managers\CustomNotesNetworkPacketManager.cs" />
<Compile Include="Overrides\CustomNoteColorNoteVisuals.cs" />
<Compile Include="Packets\CustomNotesPacket.cs" />
<Compile Include="Providers\ConnectedPlayerNotePoolProvider.cs" />
<Compile Include="Providers\CustomBombNoteProvider.cs" />
<Compile Include="Providers\CustomMultiplayerBombProvider.cs" />
<Compile Include="Providers\CustomMultiplayerNoteProvider.cs" />
<Compile Include="Providers\CustomGameNoteProvider.cs" />
<Compile Include="Settings\UI\NoteDetailsViewController.cs" />
<Compile Include="Settings\UI\NotePreviewViewController.cs" />
<Compile Include="Settings\UI\NoteQuickAccessController.cs" />
<Compile Include="Settings\UI\NotesFlowCoordinator.cs" />
<Compile Include="Utilities\MaterialSwapper.cs" />
<Compile Include="Data\CustomNote.cs" />
Expand All @@ -137,6 +164,7 @@
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Settings\UI\NoteListViewController.cs" />
<Compile Include="Managers\NoteAssetLoader.cs" />
<Compile Include="Utilities\MultiplayerCustomNoteMode.cs" />
<Compile Include="Utilities\Utils.cs" />
</ItemGroup>
<ItemGroup>
Expand All @@ -151,6 +179,14 @@
<EmbeddedResource Include="Settings\UI\Views\noteList.bsml" />
<EmbeddedResource Include="Settings\UI\Views\notePreview.bsml" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Settings\UI\Views\quickAccess.bsml" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Settings\UI\NoteQuickAccessController.bsml">
<DependentUpon>NoteQuickAccessController.cs</DependentUpon>
</EmbeddedResource>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PostBuildEvent>copy "$(TargetPath)" "$(BeatSaberDir)\Plugins"</PostBuildEvent>
Expand Down
14 changes: 13 additions & 1 deletion CustomNotes/Data/CustomNote.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using CustomNotes.Utilities;
using System;
using System.IO;
using System.Security.Cryptography;
using UnityEngine;

namespace CustomNotes.Data
Expand All @@ -15,6 +16,7 @@ public class CustomNote
public GameObject NoteDotLeft { get; }
public GameObject NoteDotRight { get; }
public GameObject NoteBomb { get; }
public string MD5Hash { get; } = string.Empty;
public string ErrorMessage { get; } = string.Empty;

public CustomNote(string fileName)
Expand All @@ -25,7 +27,17 @@ public CustomNote(string fileName)
{
try
{
AssetBundle = AssetBundle.LoadFromFile(Path.Combine(Plugin.PluginAssetPath, fileName));
string path = Path.Combine(Plugin.PluginAssetPath, fileName);

using (var stream = File.OpenRead(path)) {
using (var md5 = MD5.Create()) {
var hash = md5.ComputeHash(stream);
// https://modelsaber.com/api/v2/get.php?type=bloq&filter=hash:<md5_hash_of_assetbundle_here>
MD5Hash = BitConverter.ToString(hash).Replace("-", "").ToLowerInvariant();
AssetBundle = AssetBundle.LoadFromStream(stream);
}
}

GameObject note = AssetBundle.LoadAsset<GameObject>("assets/_customnote.prefab");

Descriptor = note.GetComponent<NoteDescriptor>();
Expand Down
22 changes: 22 additions & 0 deletions CustomNotes/Data/MultiplayerCustomNoteData.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using CustomNotes.Packets;

namespace CustomNotes.Data
{
class MultiplayerCustomNoteData
{

public string NoteHash { get; private set; } = CustomNotesPacket.DEFAULT_NOTES;
public float NoteScale { get; private set; } = 1f;

public MultiplayerCustomNoteData(string noteHash = CustomNotesPacket.DEFAULT_NOTES, float noteScale = 1f) {
NoteHash = noteHash;
NoteScale = noteScale;
}

public void UpdateFromPacket(CustomNotesPacket packet) {
NoteHash = packet.NoteHash;
NoteScale = packet.NoteScale;
}

}
}
16 changes: 16 additions & 0 deletions CustomNotes/INoteHashPacketManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CustomNotes.Interfaces
{
internal interface INoteHashPacketManager
{

bool HasHashFromPlayer(IConnectedPlayer connectedPlayer);
string GetHashFromPlayer(IConnectedPlayer connectedPlayer);

}
}
19 changes: 16 additions & 3 deletions CustomNotes/Installers/CustomNotesCoreInstaller.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
using Zenject;
using SiraUtil.Interfaces;
using CustomNotes.Managers;
using CustomNotes.Managers;
using CustomNotes.Providers;
using CustomNotes.Settings.Utilities;
using IPA.Loader;
using SiraUtil.Interfaces;
using Zenject;

namespace CustomNotes.Installers
{
Expand All @@ -22,6 +23,18 @@ public override void InstallBindings()

Container.Bind(typeof(IModelProvider), typeof(CustomGameNoteProvider)).To<CustomGameNoteProvider>().AsSingle();
Container.Bind(typeof(IModelProvider), typeof(CustomBombNoteProvider)).To<CustomBombNoteProvider>().AsSingle();

Container.Bind(typeof(IModelProvider), typeof(CustomMultiplayerNoteProvider)).To<CustomMultiplayerNoteProvider>().AsSingle();
Container.Bind(typeof(IModelProvider), typeof(CustomMultiplayerBombProvider)).To<CustomMultiplayerBombProvider>().AsSingle();

if (PluginManager.GetPluginFromId("MultiplayerExtensions") != null)
{
Container.BindInterfacesAndSelfTo<CustomNotesNetworkPacketManager>().AsSingle();
}
else
{
Container.BindInterfacesAndSelfTo<DummyCustomNotesNetworkPacketManager>().AsSingle();
}
}
}
}
6 changes: 4 additions & 2 deletions CustomNotes/Installers/CustomNotesGameInstaller.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Zenject;
using CustomNotes.Managers;
using CustomNotes.Managers;
using CustomNotes.Providers;
using Zenject;

namespace CustomNotes.Installers
{
Expand All @@ -17,6 +18,7 @@ public override void InstallBindings()
if (_noteAssetLoader.SelectedNote != 0)
{
Container.Bind<IInitializable>().To<CustomNoteManager>().AsSingle();
Container.BindInterfacesAndSelfTo<ConnectedPlayerNotePoolProvider>().AsSingle();
}
}
}
Expand Down
11 changes: 5 additions & 6 deletions CustomNotes/Installers/CustomNotesMenuInstaller.cs
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
using Zenject;
using SiraUtil;
using CustomNotes.Managers;
using CustomNotes.Managers;
using CustomNotes.Settings;
using CustomNotes.Settings.UI;
using SiraUtil;
using Zenject;

namespace CustomNotes.Installers
{
internal class CustomNotesMenuInstaller : Installer
{
public override void InstallBindings()
{


Container.Bind<NotePreviewViewController>().FromNewComponentAsViewController().AsSingle();
Container.Bind<NoteDetailsViewController>().FromNewComponentAsViewController().AsSingle();
Container.Bind<NoteListViewController>().FromNewComponentAsViewController().AsSingle();
Container.BindFlowCoordinator<NotesFlowCoordinator>();
Container.Bind<NotesFlowCoordinator>().FromNewComponentOnNewGameObject($"{nameof(NotesFlowCoordinator)}HostGameObject").AsSingle();

Container.BindInterfacesAndSelfTo<NoteQuickAccessController>().AsSingle();
Container.BindInterfacesTo<MenuButtonManager>().AsSingle();
}
}
Expand Down
11 changes: 11 additions & 0 deletions CustomNotes/Interfaces/ICustomNoteNetworkPacketManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using CustomNotes.Data;

namespace CustomNotes.Interfaces
{
internal interface ICustomNoteNetworkPacketManager
{
bool HasDataFromPlayer(IConnectedPlayer connectedPlayer);

MultiplayerCustomNoteData GetData(IConnectedPlayer connectedPlayer);
}
}
50 changes: 28 additions & 22 deletions CustomNotes/Managers/CustomBombController.cs
Original file line number Diff line number Diff line change
@@ -1,29 +1,18 @@
using Zenject;
using UnityEngine;
using CustomNotes.Data;
using CustomNotes.Data;
using CustomNotes.Settings.Utilities;
using SiraUtil.Objects;
using UnityEngine;
using Zenject;

namespace CustomNotes.Managers
{
internal class CustomBombController : MonoBehaviour
internal class CustomBombController : CustomBombControllerBase
{
private PluginConfig _pluginConfig;

private CustomNote _customNote;
private NoteMovement _noteMovement;
private BombNoteController _bombNoteController;

protected Transform bombMesh;

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)
{
_pluginConfig = pluginConfig;
_noteSize = pluginConfig.NoteSize;

_customNote = noteAssetLoader.CustomNoteObjects[noteAssetLoader.SelectedNote];
_bombNoteController = GetComponent<BombNoteController>();
Expand All @@ -36,37 +25,54 @@ internal void Init(PluginConfig pluginConfig, NoteAssetLoader noteAssetLoader, [
MeshRenderer bm = GetComponentInChildren<MeshRenderer>();
bm.enabled = false;
}
}

internal abstract class CustomBombControllerBase : MonoBehaviour
{
protected PluginConfig _pluginConfig;

protected CustomNote _customNote;
protected NoteMovement _noteMovement;
protected NoteController _bombNoteController;

protected float _noteSize = 1f;

protected Transform bombMesh;

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

private void DidFinish()
protected virtual void DidFinish()
{
container.transform.SetParent(null);
bombPool.Despawn(container);
}

private void Controller_Init(NoteController noteController)
protected virtual void Controller_Init(NoteController noteController)
{
SpawnThenParent(bombPool);
}

private void ParentNote(GameObject fakeMesh)
protected virtual void ParentNote(GameObject fakeMesh)
{
fakeMesh.SetActive(true);
container.transform.SetParent(bombMesh);
fakeMesh.transform.localPosition = container.transform.localPosition = new Vector3(0.0f, 0.0f, 0.0f);
container.transform.localRotation = Quaternion.identity;
fakeMesh.transform.localScale = new Vector3(0.4f, 0.4f, 0.4f) * _pluginConfig.NoteSize;
fakeMesh.transform.localScale = new Vector3(0.4f, 0.4f, 0.4f) * _noteSize;
container.transform.localScale = Vector3.one;
}

private void SpawnThenParent(SiraPrefabContainer.Pool bombModelPool)
protected virtual void SpawnThenParent(SiraPrefabContainer.Pool bombModelPool)
{
container = bombModelPool.Spawn();
activeNote = container.Prefab;
bombPool = bombModelPool;
ParentNote(activeNote);
}

protected void OnDestroy()
protected virtual void OnDestroy()
{
if (_bombNoteController != null)
{
Expand Down
Loading