Skip to content

Commit

Permalink
Merge pull request #5 from Zingabopp/PullReq
Browse files Browse the repository at this point in the history
Beat Saber 0.12.0p1 compatibility
  • Loading branch information
PureDark authored Dec 13, 2018
2 parents ba77a5d + 9c752db commit 7ea136c
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 8 deletions.
2 changes: 2 additions & 0 deletions TransparentWall/Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ public void OnApplicationStart()
public void OnApplicationQuit()
{
SceneManager.activeSceneChanged -= SceneManagerOnActiveSceneChanged;
if (_scenesManager != null)
_scenesManager.transitionDidFinishEvent -= SceneTransitionDidFinish;
}

private void SceneManagerOnActiveSceneChanged(Scene arg0, Scene scene)
Expand Down
53 changes: 46 additions & 7 deletions TransparentWall/TransparentWall.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,26 @@ namespace TransparentWall
public class TransparentWall : MonoBehaviour
{
public static int WallLayer = 25;
public static int MoveBackLayer = 27;
public static string LIVCam_Name = "MainCamera";

private BeatmapObjectSpawnController _beatmapObjectSpawnController;
private LIV.SDK.Unity.LIV _livObject = null;
private MoveBackWall _moveBackWall;

private void Start()
{
if (!Plugin.IsTranparentWall)
return;
try
{
this._beatmapObjectSpawnController = Resources.FindObjectsOfTypeAll<BeatmapObjectSpawnController>().First();
if (Resources.FindObjectsOfTypeAll<BeatmapObjectSpawnController>().Count() > 0)
this._beatmapObjectSpawnController = Resources.FindObjectsOfTypeAll<BeatmapObjectSpawnController>().First();
if (Resources.FindObjectsOfTypeAll<MoveBackWall>().Count() > 0)
{
this._moveBackWall = Resources.FindObjectsOfTypeAll<MoveBackWall>().First();
MoveBackLayer = _moveBackWall.gameObject.layer;
}

if (_beatmapObjectSpawnController != null)
{
Expand All @@ -40,16 +50,30 @@ private void OnDestroy()
}
}
private void setupCams()
{
CullLiv();
StartCoroutine(setupCamerasCoroutine());
}

/// <summary>
/// Attempts to find the LIV.SDK.Unity.LIV object and apply the layer mask to the LIV output.
/// </summary>
public void CullLiv()
{
if (Plugin.IsLIVCameraOn)
{
Camera[] cameras = FindObjectsOfType<Camera>();
foreach (Camera camera in cameras)
if (_livObject == null)
_livObject = LIV.SDK.Unity.LIV.FindObjectOfType<LIV.SDK.Unity.LIV>();

if (_livObject != null)
{
camera.cullingMask &= ~(1 << WallLayer);
if (_livObject.name == LIVCam_Name)
{
_livObject.SpectatorLayerMask &= ~(1 << WallLayer);
_livObject.SpectatorLayerMask &= ~(1 << MoveBackLayer);
}
}
}
StartCoroutine(setupCamerasCoroutine());
}

private IEnumerator<WaitForEndOfFrame> setupCamerasCoroutine()
Expand All @@ -58,7 +82,7 @@ private IEnumerator<WaitForEndOfFrame> setupCamerasCoroutine()

StandardLevelSceneSetupDataSO levelSetup = Resources.FindObjectsOfTypeAll<StandardLevelSceneSetupDataSO>().FirstOrDefault();

Camera mainCamera = FindObjectsOfType<Camera>().FirstOrDefault(x => x.CompareTag("MainCamera"));
Camera mainCamera = Camera.main;

if (Plugin.IsHMDOn && levelSetup.gameplayCoreSetupData.gameplayModifiers.noFail)
mainCamera.cullingMask &= ~(1 << WallLayer);
Expand All @@ -75,13 +99,24 @@ private IEnumerator<WaitForEndOfFrame> setupCamerasCoroutine()
yield return new WaitForEndOfFrame();
_cameraPlus = ReflectionUtil.GetPrivateField<MonoBehaviour>(plugin, "_cameraPlus");
}
Camera cam = ReflectionUtil.GetPrivateField<Camera>(_cameraPlus, "_cam");
Camera cam = null;
while (cam == null) // Camera is null on the first attempt.
{
yield return new WaitForEndOfFrame();
cam = GameObject.FindObjectsOfType<Camera>().Where(c => c.name == "Camera Plus").FirstOrDefault();
}
if (cam != null)
{
if (((plugin.Name == "CameraPlus" || plugin.Name == "CameraPlusOrbitEdition") && Plugin.IsCameraPlusOn) || (plugin.Name == "DynamicCamera" && Plugin.IsDynamicCameraOn))
{
cam.cullingMask &= ~(1 << WallLayer);
cam.cullingMask &= ~(1 << MoveBackLayer);
}
else
{
cam.cullingMask |= (1 << WallLayer);
cam.cullingMask |= ~(1 << MoveBackLayer);
}
}
Camera multi = ReflectionUtil.GetPrivateField<Camera>(_cameraPlus, "multi");
if (multi != null)
Expand All @@ -100,6 +135,10 @@ public virtual void HandleObstacleDiStartMovementEvent(BeatmapObjectSpawnControl
{
try
{
if (_livObject == null)
{
CullLiv();
}
StretchableObstacle _stretchableObstacle = ReflectionUtil.GetPrivateField<StretchableObstacle>(obstacleController, "_stretchableObstacle");
StretchableCube _stretchableCoreOutside = ReflectionUtil.GetPrivateField<StretchableCube>(_stretchableObstacle, "_stretchableCoreOutside");
StretchableCube _stretchableCoreInside = ReflectionUtil.GetPrivateField<StretchableCube>(_stretchableObstacle, "_stretchableCoreInside");
Expand Down
2 changes: 1 addition & 1 deletion TransparentWall/TransparentWall.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,4 @@
<PostBuildEvent>copy ".\TransparentWall.dll" "F:\SteamLibrary\SteamApps\common\Beat Saber\Plugins"
Start steam://rungameid/620980</PostBuildEvent>
</PropertyGroup>
</Project>
</Project>

0 comments on commit 7ea136c

Please sign in to comment.