Skip to content

Commit

Permalink
Fix #29
Browse files Browse the repository at this point in the history
  • Loading branch information
Snow1226 committed May 20, 2024
1 parent 5c2df60 commit 74ddd32
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 18 deletions.
1 change: 1 addition & 0 deletions CameraPlus/CameraPlus.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@
<Compile Include="Configuration\CameraConfig.cs" />
<Compile Include="Configuration\MovementScriptJson.cs" />
<Compile Include="HarmonyPatches\AudioTimeSyncControllerPatch.cs" />
<Compile Include="HarmonyPatches\BeatLeaderReplayPatch.cs" />
<Compile Include="HarmonyPatches\CustomLevelLoaderPatch.cs" />
<Compile Include="HarmonyPatches\SongScriptBeatmapPatch.cs" />
<Compile Include="HarmonyPatches\SmoothCameraPatch.cs" />
Expand Down
4 changes: 3 additions & 1 deletion CameraPlus/CameraPlusController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ public class CameraPlusController : MonoBehaviour
protected EnvironmentSpawnRotation _environmentSpawnRotation;
internal float _beatLineManagerYAngle = 0;

internal bool _isBeatLeaderReplay = false;

private void Awake()
{
if (instance != null)
Expand Down Expand Up @@ -232,7 +234,7 @@ internal IEnumerator waitMainCamera()

private void OnFPFCToglleEvent()
{
if (isFPFC)
if (isFPFC || _isBeatLeaderReplay)
ScreenCamera.gameObject.SetActive(false);
else
ScreenCamera.gameObject.SetActive(true);
Expand Down
46 changes: 46 additions & 0 deletions CameraPlus/HarmonyPatches/BeatLeaderReplayPatch.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using IPA.Loader;
using IPA.Utilities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace CameraPlus.HarmonyPatches
{
internal class BeatLeaderReplayerCameraControllerStartPatch
{
internal static MethodBase TargetMethod()
{
PluginMetadata beatLeader = PluginManager.GetPluginFromId("BeatLeader");
if (beatLeader != null)
return beatLeader.Assembly.GetType("BeatLeader.Replayer.ReplayerCameraController").GetMethod("Start", BindingFlags.Instance | BindingFlags.NonPublic);
else
return null;
}
internal static void Prefix()
{
Plugin.cameraController._isBeatLeaderReplay = true;
Plugin.cameraController.ScreenCamera.enabled = false;
}
}

internal class BeatLeaderReplayerCameraControllerOnDestroyPatch
{
internal static MethodBase TargetMethod()
{
PluginMetadata beatLeader = PluginManager.GetPluginFromId("BeatLeader");
if (beatLeader != null)
return beatLeader.Assembly.GetType("BeatLeader.Replayer.ReplayerCameraController").GetMethod("OnDestroy", BindingFlags.Instance | BindingFlags.NonPublic);
else
return null;
}
internal static void Prefix()
{
Plugin.cameraController._isBeatLeaderReplay = false;
Plugin.cameraController.ScreenCamera.enabled = true;
}
}

}
3 changes: 2 additions & 1 deletion CameraPlus/HarmonyPatches/CustomLevelLoaderPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ internal static class CustomLevelLoaderPatch
static void Postfix(CustomLevelLoader __instance)
{
Instance = __instance;
#if DEBUG
Plugin.Log.Notice($"CustomLevelLoader Loaded");

#endif
}

}
Expand Down
3 changes: 2 additions & 1 deletion CameraPlus/HarmonyPatches/TransparentWallsPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ internal class TransparentWallsPatch
public static int WallLayerMask = 25;
static void Postfix(Transform ____obstacleCore, ref ParametricBoxFakeGlowController ____obstacleFakeGlow)
{
Camera.main.cullingMask |= (1 << TransparentWallsPatch.WallLayerMask);//Enables HMD bits because layer 25 is masked by default
if(Camera.main != null)
Camera.main.cullingMask |= (1 << TransparentWallsPatch.WallLayerMask);//Enables HMD bits because layer 25 is masked by default
if (____obstacleCore != null)
{
____obstacleCore.gameObject.layer = WallLayerMask;
Expand Down
9 changes: 9 additions & 0 deletions CameraPlus/Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public void OnApplicationStart()
{
_harmony = new Harmony("com.brian91292.beatsaber.cameraplus");
_harmony.PatchAll(Assembly.GetExecutingAssembly());

if (HarmonyPatches.FPFCToggleEnable.TargetMethod() != null)
{
_harmony.PatchAll(typeof(HarmonyPatches.FPFCToggleEnable));
Expand All @@ -43,6 +44,14 @@ public void OnApplicationStart()
else
Log.Warn("SiraUtil Not Detected.");

if (HarmonyPatches.BeatLeaderReplayerCameraControllerStartPatch.TargetMethod() != null)
{
_harmony.PatchAll(typeof(HarmonyPatches.BeatLeaderReplayerCameraControllerStartPatch));
_harmony.PatchAll(typeof(HarmonyPatches.BeatLeaderReplayerCameraControllerOnDestroyPatch));
}
else
Log.Warn("BeatLeader Not Detected.");

cameraController = new GameObject("CameraPlusController").AddComponent<CameraPlusController>();
}

Expand Down
37 changes: 22 additions & 15 deletions CameraPlus/Utilities/CameraUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -215,28 +215,35 @@ public static void LoadProfile(string profileName)

string[] files = (profileName != string.Empty ? Directory.GetFiles(Path.Combine(ProfilePath, profileName)) : Directory.GetFiles(ConfigPath));
string fileName, dictKey;
foreach (string filePath in files)
if(GetMainCamera() != null)
{
Plugin.Log.Notice($"Loading profile cameras : {Path.GetFileName(filePath)}");

fileName = Path.GetFileName(filePath);
dictKey = (profileName == string.Empty ? $"{Plugin.Name}_{fileName}" : $"{profileName}_{fileName}");
if (fileName.EndsWith(".json") && !Plugin.cameraController.Cameras.ContainsKey(dictKey))
foreach (string filePath in files)
{
Plugin.Log.Notice($"Found new CameraConfig {filePath}!");
Plugin.Log.Notice($"Loading profile cameras : {Path.GetFileName(filePath)}");

CameraConfig Config = new CameraConfig(filePath);
if (Config.configLoaded)
fileName = Path.GetFileName(filePath);
dictKey = (profileName == string.Empty ? $"{Plugin.Name}_{fileName}" : $"{profileName}_{fileName}");
if (fileName.EndsWith(".json") && !Plugin.cameraController.Cameras.ContainsKey(dictKey))
{
var cam = new GameObject(dictKey).AddComponent<CameraPlusBehaviour>();
cam.transform.SetParent(profileObject.transform);
cam.transform.localPosition = Vector3.zero;
cam.transform.localRotation = Quaternion.identity;
cam.Init(Config);
Plugin.cameraController.Cameras.TryAdd(dictKey, cam);
Plugin.Log.Notice($"Found new CameraConfig {filePath}!");

CameraConfig Config = new CameraConfig(filePath);
if (Config.configLoaded)
{
var cam = new GameObject(dictKey).AddComponent<CameraPlusBehaviour>();
cam.transform.SetParent(profileObject.transform);
cam.transform.localPosition = Vector3.zero;
cam.transform.localRotation = Quaternion.identity;
cam.Init(Config);
Plugin.cameraController.Cameras.TryAdd(dictKey, cam);
}
}
}
}
else
{
Plugin.Log.Notice($"Not found MainCamera / BeatLeader Replay");
}
}
catch (Exception ex)
{
Expand Down

0 comments on commit 74ddd32

Please sign in to comment.