Skip to content

Commit

Permalink
Support 90/360 Profile
Browse files Browse the repository at this point in the history
  • Loading branch information
Snow committed Mar 9, 2021
1 parent 953a050 commit b0449ac
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 17 deletions.
10 changes: 10 additions & 0 deletions CameraPlus/CameraPlus.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@
<HintPath>$(BeatSaberDir)\Beat Saber_Data\Managed\HMLib.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="BeatmapCore">
<HintPath>$(BeatSaberDir)\Beat Saber_Data\Managed\BeatmapCore.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="HMUI">
<HintPath>$(BeatSaberDir)\Beat Saber_Data\Managed\HMUI.dll</HintPath>
<Private>False</Private>
Expand Down Expand Up @@ -102,6 +106,11 @@
<HintPath>$(BeatSaberDir)\Beat Saber_Data\Managed\UnityEngine.PhysicsModule.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="UnityEngine.TextRenderingModule, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>$(BeatSaberDir)\Beat Saber_Data\Managed\UnityEngine.TextRenderingModule.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="UnityEngine.VRModule">
<HintPath>$(BeatSaberDir)\Beat Saber_Data\Managed\UnityEngine.VRModule.dll</HintPath>
<Private>False</Private>
Expand All @@ -120,6 +129,7 @@
<Compile Include="Config.cs" />
<Compile Include="ContextMenu.cs" />
<Compile Include="HarmonyPatches\DisableSmoothCamera.cs" />
<Compile Include="HarmonyPatches\LevelDataPatch.cs" />
<Compile Include="Logger.cs" />
<Compile Include="MultiplayerSession.cs" />
<Compile Include="Plugin.cs" />
Expand Down
51 changes: 36 additions & 15 deletions CameraPlus/ContextMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ internal Vector2 menuPos
internal Texture2D Cameratexture = null;
internal GUIStyle CustomEnableStyle = null;
internal GUIStyle CustomDisableStyle = null;
internal GUIStyle ProfileStyle = null;

public void Awake()
{
Expand Down Expand Up @@ -80,6 +81,8 @@ void OnGUI()
CustomEnableStyle.normal.background = CustomEnableStyle.active.background;
CustomEnableStyle.hover.background = CustomEnableStyle.active.background;
CustomDisableStyle = new GUIStyle(GUI.skin.button);
ProfileStyle = new GUIStyle(GUI.skin.box);
ProfileStyle.alignment = UnityEngine.TextAnchor.MiddleLeft;

if (MenuMode == 0)
{
Expand Down Expand Up @@ -680,58 +683,76 @@ void OnGUI()
CameraProfiles.TrySetLast(CameraProfiles.currentlySelected);
if (GUI.Button(new Rect(menuPos.x + 155, menuPos.y + 25, 140, 30), new GUIContent(">")))
CameraProfiles.SetNext(CameraProfiles.currentlySelected);
if (GUI.Button(new Rect(menuPos.x + 30, menuPos.y + 65, 230, 80), new GUIContent("Currently Selected:\n" + CameraProfiles.currentlySelected)))
if (GUI.Button(new Rect(menuPos.x + 30, menuPos.y + 60, 230, 60), new GUIContent("Currently Selected:\n" + CameraProfiles.currentlySelected)))
CameraProfiles.SetNext(CameraProfiles.currentlySelected);
if (GUI.Button(new Rect(menuPos.x, menuPos.y + 155, 140, 30), new GUIContent("Save")))
if (GUI.Button(new Rect(menuPos.x, menuPos.y + 125, 140, 30), new GUIContent("Save")))
CameraProfiles.SaveCurrent();
if (GUI.Button(new Rect(menuPos.x + 150, menuPos.y + 155, 140, 30), new GUIContent("Delete")))
if (GUI.Button(new Rect(menuPos.x + 150, menuPos.y + 125, 140, 30), new GUIContent("Delete")))
{
if (!Plugin.Instance._rootConfig.ProfileLoadCopyMethod)
Plugin.Instance._profileChanger.ProfileChange(null);
CameraProfiles.DeleteProfile(CameraProfiles.currentlySelected);
CameraProfiles.TrySetLast();
}
if (GUI.Button(new Rect(menuPos.x, menuPos.y + 195, 290, 30), new GUIContent("Load Selected")))
if (GUI.Button(new Rect(menuPos.x, menuPos.y + 165, 300, 30), new GUIContent("Load Selected")))
Plugin.Instance._profileChanger.ProfileChange(CameraProfiles.currentlySelected);
if (GUI.Button(new Rect(menuPos.x, menuPos.y + 245, 290, 30), new GUIContent(Plugin.Instance._rootConfig.ProfileSceneChange ? "To SceneChange Off" : "To SceneChange On")))
if (GUI.Button(new Rect(menuPos.x, menuPos.y + 200, 145, 30), new GUIContent("SceneProfile On"), Plugin.Instance._rootConfig.ProfileSceneChange ? CustomEnableStyle : CustomDisableStyle))
{
Plugin.Instance._rootConfig.ProfileSceneChange = !Plugin.Instance._rootConfig.ProfileSceneChange;
Plugin.Instance._rootConfig.ProfileSceneChange = true;
Plugin.Instance._rootConfig.Save();
}
if (GUI.Button(new Rect(menuPos.x+150, menuPos.y + 200, 145, 30), new GUIContent("SceneProfile Off"), !Plugin.Instance._rootConfig.ProfileSceneChange ? CustomEnableStyle : CustomDisableStyle))
{
Plugin.Instance._rootConfig.ProfileSceneChange = false;
Plugin.Instance._rootConfig.Save();
}

if (Plugin.Instance._rootConfig.ProfileSceneChange)
{
GUI.Box(new Rect(menuPos.x + 35, menuPos.y + 275, 260, 30), "Menu Scene Profile : " + (Plugin.Instance._rootConfig.MenuProfile));
GUI.Box(new Rect(menuPos.x + 35, menuPos.y + 305, 260, 30), "Game Scene Profile : " + (Plugin.Instance._rootConfig.GameProfile));
GUI.Box(new Rect(menuPos.x + 35, menuPos.y + 335, 260, 30), "Multiplay Profile : " + (Plugin.Instance._rootConfig.MultiplayerProfile));
if (GUI.Button(new Rect(menuPos.x + 5, menuPos.y + 275, 30, 30), "X"))
GUI.Box(new Rect(menuPos.x + 30, menuPos.y + 230, 270, 30), "Menu Scene : " + (Plugin.Instance._rootConfig.MenuProfile), ProfileStyle);
GUI.Box(new Rect(menuPos.x + 30, menuPos.y + 260, 270, 30), "Game Scene : " + (Plugin.Instance._rootConfig.GameProfile), ProfileStyle);
GUI.Box(new Rect(menuPos.x + 30, menuPos.y + 290, 270, 30), "Game 90/360 : " + (Plugin.Instance._rootConfig.RotateProfile), ProfileStyle);
GUI.Box(new Rect(menuPos.x + 30, menuPos.y + 320, 270, 30), "Multiplayer : " + (Plugin.Instance._rootConfig.MultiplayerProfile), ProfileStyle);
if (GUI.Button(new Rect(menuPos.x, menuPos.y + 240, 30, 30), "X"))
{
if (Plugin.Instance._rootConfig.MenuProfile!=string.Empty)
Plugin.Instance._rootConfig.MenuProfile = string.Empty;
Plugin.Instance._rootConfig.Save();
}
if (GUI.Button(new Rect(menuPos.x + 5, menuPos.y + 305, 30, 30), "X"))
if (GUI.Button(new Rect(menuPos.x, menuPos.y + 260, 30, 30), "X"))
{
if (Plugin.Instance._rootConfig.GameProfile != string.Empty)
Plugin.Instance._rootConfig.GameProfile = string.Empty;
Plugin.Instance._rootConfig.Save();
}
if (GUI.Button(new Rect(menuPos.x + 5, menuPos.y + 335, 30, 30), "X"))
if (GUI.Button(new Rect(menuPos.x, menuPos.y + 290, 30, 30), "X"))
{
if (Plugin.Instance._rootConfig.RotateProfile != string.Empty)
Plugin.Instance._rootConfig.RotateProfile = string.Empty;
Plugin.Instance._rootConfig.Save();
}
if (GUI.Button(new Rect(menuPos.x, menuPos.y + 320, 30, 30), "X"))
{
if (Plugin.Instance._rootConfig.MultiplayerProfile != string.Empty)
Plugin.Instance._rootConfig.MultiplayerProfile = string.Empty;
Plugin.Instance._rootConfig.Save();
}
if (GUI.Button(new Rect(menuPos.x, menuPos.y + 365, 140, 25), new GUIContent("Set Menu Selected")))
if (GUI.Button(new Rect(menuPos.x, menuPos.y + 350, 145, 25), new GUIContent("Menu Selected")))
{
Plugin.Instance._rootConfig.MenuProfile = CameraProfiles.currentlySelected;
Plugin.Instance._rootConfig.Save();
}
if (GUI.Button(new Rect(menuPos.x + 150, menuPos.y + 365, 140, 25), new GUIContent("Set Game Selected")))
if (GUI.Button(new Rect(menuPos.x, menuPos.y + 375, 145, 25), new GUIContent("Game Selected")))
{
Plugin.Instance._rootConfig.GameProfile = CameraProfiles.currentlySelected;
Plugin.Instance._rootConfig.Save();
}
if (GUI.Button(new Rect(menuPos.x , menuPos.y + 395, 290, 25), new GUIContent("Set Multiplayer Selected")))
if (GUI.Button(new Rect(menuPos.x + 150, menuPos.y + 375, 145, 25), new GUIContent("90/360 Selected")))
{
Plugin.Instance._rootConfig.RotateProfile = CameraProfiles.currentlySelected;
Plugin.Instance._rootConfig.Save();
}
if (GUI.Button(new Rect(menuPos.x , menuPos.y + 400, 145, 25), new GUIContent("Multiplay Selected")))
{
Plugin.Instance._rootConfig.MultiplayerProfile = CameraProfiles.currentlySelected;
Plugin.Instance._rootConfig.Save();
Expand Down
45 changes: 45 additions & 0 deletions CameraPlus/HarmonyPatches/LevelDataPatch.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using System;
using System.Linq;
using System.Collections.Generic;
using System.Reflection;
using HarmonyLib;
using LogLevel = IPA.Logging.Logger.Level;

namespace CameraPlus.HarmonyPatches
{
[HarmonyPatch]
class LevelDataPatch
{
public static IDifficultyBeatmap difficultyBeatmap;
public static bool is360Level = false;
public static bool isModdedMap = false;
public static bool isWallMap = false;

static SpawnRotationProcessor spawnRotationProcessor = new SpawnRotationProcessor();

static void Prefix(IDifficultyBeatmap difficultyBeatmap)
{
#if DEBUG
Logger.Log("Got level data!",LogLevel.Notice);
#endif
LevelDataPatch.difficultyBeatmap = difficultyBeatmap;

is360Level = difficultyBeatmap.beatmapData.beatmapEventsData.Any(
x => x.type.IsRotationEvent() && spawnRotationProcessor.RotationForEventValue(x.value) != 0f
);
}

internal static void Reset()
{
is360Level = isModdedMap = isWallMap = false;
difficultyBeatmap = null;
}

[HarmonyTargetMethods]
static IEnumerable<MethodBase> TargetMethods()
{
foreach (var t in new Type[] { typeof(StandardLevelScenesTransitionSetupDataSO), typeof(MissionLevelScenesTransitionSetupDataSO), typeof(MultiplayerLevelScenesTransitionSetupDataSO) })
yield return t.GetMethod("Init", BindingFlags.Instance | BindingFlags.Public);
}
}
}
7 changes: 5 additions & 2 deletions CameraPlus/Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
using UnityEngine;
using UnityEngine.SceneManagement;
using System.IO;
using Newtonsoft.Json;
using CameraPlus.HarmonyPatches;

namespace CameraPlus
{
Expand Down Expand Up @@ -109,7 +109,10 @@ IEnumerator waitForcam()
{
if (to.name == "GameCore" && _rootConfig.GameProfile != "" && (!MultiplayerSession.ConnectedMultiplay || _rootConfig.MultiplayerProfile == ""))
{
_profileChanger.ProfileChange(_rootConfig.GameProfile);
if (LevelDataPatch.is360Level && _rootConfig.RotateProfile !="")
_profileChanger.ProfileChange(_rootConfig.RotateProfile);
else
_profileChanger.ProfileChange(_rootConfig.GameProfile);
}
else if ((to.name == "MenuCore" || to.name == "HealthWarning") && _rootConfig.MenuProfile != "" && (!MultiplayerSession.ConnectedMultiplay || _rootConfig.MultiplayerProfile == ""))
{
Expand Down
1 change: 1 addition & 0 deletions CameraPlus/RootConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public class RootConfig
public bool ProfileSceneChange = false;
public string MenuProfile = "";
public string GameProfile = "";
public string RotateProfile = "";
public string MultiplayerProfile = "";
public bool ProfileLoadCopyMethod = false;
public int CameraQuadLayer = 0;
Expand Down

0 comments on commit b0449ac

Please sign in to comment.