Skip to content

Commit

Permalink
initial
Browse files Browse the repository at this point in the history
  • Loading branch information
PureDark committed Jul 20, 2018
0 parents commit a999eb5
Show file tree
Hide file tree
Showing 5 changed files with 420 additions and 0 deletions.
25 changes: 25 additions & 0 deletions TransparentWall.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.27703.2026
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TransparentWall", "TransparentWall\TransparentWall.csproj", "{63CE724B-0772-42F6-863D-F3AE19B6E67C}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{63CE724B-0772-42F6-863D-F3AE19B6E67C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{63CE724B-0772-42F6-863D-F3AE19B6E67C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{63CE724B-0772-42F6-863D-F3AE19B6E67C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{63CE724B-0772-42F6-863D-F3AE19B6E67C}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {F7E82560-8FF3-462F-B05F-5AEFA27006C8}
EndGlobalSection
EndGlobal
173 changes: 173 additions & 0 deletions TransparentWall/Plugin.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
using IllusionPlugin;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using UnityEngine;
using UnityEngine.SceneManagement;

namespace TransparentWall
{
class Plugin : IEnhancedPlugin, IPlugin
{
public static string PluginName = "TransparentWall";
public const string VersionNum = "0.1.0";

public string Name => PluginName;
public string Version => VersionNum;
public string[] Filter { get; }

public const string KeyTranparentWall = "TransparentWall";
public const string KeyHMD = "HMD";
public const string KeyCameraPlus = "CameraPlus";
public const string KeyMutiView = "MutiViewFirstPerson";
public const string KeyDynamicCamera = "DynamicCamera";
public const string KeyLIV = "LIVCamera";

public static bool IsTranparentWall
{
get
{
return ModPrefs.GetBool(Plugin.PluginName, KeyTranparentWall, false);
}
set
{
ModPrefs.SetBool(Plugin.PluginName, KeyTranparentWall, value);
}
}

public static bool IsHMDOn
{
get
{
return ModPrefs.GetBool(Plugin.PluginName, KeyHMD, true);
}
set
{
ModPrefs.SetBool(Plugin.PluginName, KeyHMD, value);
}
}

public static bool IsCameraPlusOn
{
get
{
return ModPrefs.GetBool(Plugin.PluginName, KeyCameraPlus, true);
}
set
{
ModPrefs.SetBool(Plugin.PluginName, KeyCameraPlus, value);
}
}

public static bool IsMutiViewFirstPersonOn
{
get
{
return ModPrefs.GetBool(Plugin.PluginName, KeyMutiView, true);
}
set
{
ModPrefs.SetBool(Plugin.PluginName, KeyMutiView, value);
}
}

public static bool IsDynamicCameraOn
{
get
{
return ModPrefs.GetBool(Plugin.PluginName, KeyDynamicCamera, true);
}
set
{
ModPrefs.SetBool(Plugin.PluginName, KeyDynamicCamera, value);
}
}

public static bool IsLIVCameraOn
{
get
{
return ModPrefs.GetBool(Plugin.PluginName, KeyLIV, true);
}
set
{
ModPrefs.SetBool(Plugin.PluginName, KeyLIV, value);
}
}


public void OnApplicationStart()
{
CheckForUserDataFolder();
SceneManager.activeSceneChanged += SceneManagerOnActiveSceneChanged;
}

public void OnApplicationQuit()
{
SceneManager.activeSceneChanged -= SceneManagerOnActiveSceneChanged;
}

private void SceneManagerOnActiveSceneChanged(Scene arg0, Scene scene)
{
if (scene.buildIndex == 5)
{
new GameObject("TransparentWall").AddComponent<TransparentWall>();
}
}

public void OnLateUpdate()
{
}

public void OnLevelWasLoaded(int level)
{
}

public void OnLevelWasInitialized(int level)
{
}

public void OnUpdate()
{
}

public void OnFixedUpdate()
{
}

private void CheckForUserDataFolder()
{
string userDataPath = Environment.CurrentDirectory + "/UserData";
if (!Directory.Exists(userDataPath))
{
Directory.CreateDirectory(userDataPath);
}
if ("".Equals(ModPrefs.GetString(Plugin.PluginName, Plugin.KeyTranparentWall, "")))
{
ModPrefs.SetBool(Plugin.PluginName, Plugin.KeyTranparentWall, true);
}
if ("".Equals(ModPrefs.GetString(Plugin.PluginName, Plugin.KeyHMD, "")))
{
ModPrefs.SetBool(Plugin.PluginName, Plugin.KeyHMD, true);
}
if ("".Equals(ModPrefs.GetString(Plugin.PluginName, Plugin.KeyCameraPlus, "")))
{
ModPrefs.SetBool(Plugin.PluginName, Plugin.KeyCameraPlus, true);
}
if ("".Equals(ModPrefs.GetString(Plugin.PluginName, Plugin.KeyMutiView, "")))
{
ModPrefs.SetBool(Plugin.PluginName, Plugin.KeyMutiView, true);
}
if ("".Equals(ModPrefs.GetString(Plugin.PluginName, Plugin.KeyDynamicCamera, "")))
{
ModPrefs.SetBool(Plugin.PluginName, Plugin.KeyDynamicCamera, true);
}
if ("".Equals(ModPrefs.GetString(Plugin.PluginName, Plugin.KeyLIV, "")))
{
ModPrefs.SetBool(Plugin.PluginName, Plugin.KeyLIV, true);
}
}
}
}
41 changes: 41 additions & 0 deletions TransparentWall/ReflectionUtil.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using System;
using System.Reflection;
using UnityEngine;

namespace TransparentWall
{
public static class ReflectionUtil
{
public static void SetPrivateField(object obj, string fieldName, object value)
{
obj.GetType().GetField(fieldName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic).SetValue(obj, value);
}

public static T GetPrivateField<T>(object obj, string fieldName)
{
return (T)((object)obj.GetType().GetField(fieldName, BindingFlags.Instance | BindingFlags.NonPublic).GetValue(obj));
}

public static void SetPrivateProperty(object obj, string propertyName, object value)
{
obj.GetType().GetProperty(propertyName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic).SetValue(obj, value, null);
}

public static void InvokePrivateMethod(object obj, string methodName, object[] methodParams)
{
obj.GetType().GetMethod(methodName, BindingFlags.Instance | BindingFlags.NonPublic).Invoke(obj, methodParams);
}

public static Component CopyComponent(Component original, Type originalType, Type overridingType, GameObject destination)
{
Component component = destination.AddComponent(overridingType);
FieldInfo[] fields = originalType.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.GetField);
for (int i = 0; i < fields.Length; i++)
{
FieldInfo fieldInfo = fields[i];
fieldInfo.SetValue(component, fieldInfo.GetValue(original));
}
return component;
}
}
}
112 changes: 112 additions & 0 deletions TransparentWall/TransparentWall.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;

namespace TransparentWall
{
public class TransparentWall : MonoBehaviour
{
public static int WallLayer = 25;

private BeatmapObjectSpawnController _beatmapObjectSpawnController;

private void Start()
{
try
{
this._beatmapObjectSpawnController = Resources.FindObjectsOfTypeAll<BeatmapObjectSpawnController>().First();

if (_beatmapObjectSpawnController != null)
{
_beatmapObjectSpawnController.obstacleDiStartMovementEvent += this.HandleObstacleDiStartMovementEvent;
}

setupCams();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message + "\n" + ex.StackTrace);
}
}

private void OnDestroy()
{
if (_beatmapObjectSpawnController != null)
{
_beatmapObjectSpawnController.obstacleDiStartMovementEvent -= this.HandleObstacleDiStartMovementEvent;
}
}
private void setupCams()
{
if (Plugin.IsLIVCameraOn)
{
Camera[] cameras = FindObjectsOfType<Camera>();
foreach (Camera camera in cameras)
{
camera.cullingMask &= ~(1 << WallLayer);
}
}
StartCoroutine(setupCamerasCoroutine());
}

private IEnumerator<WaitForEndOfFrame> setupCamerasCoroutine()
{
yield return new WaitForEndOfFrame();
Camera mainCamera = FindObjectsOfType<Camera>().FirstOrDefault(x => x.CompareTag("MainCamera"));
if (Plugin.IsHMDOn)
mainCamera.cullingMask &= ~(1 << WallLayer);
else
mainCamera.cullingMask |= (1 << WallLayer);

foreach (var plugin in IllusionInjector.PluginManager.Plugins)
{
if (plugin.Name == "CameraPlus" || plugin.Name == "CameraPlusOrbitEdition" || plugin.Name == "DynamicCamera")
{
var _cameraPlus = ReflectionUtil.GetPrivateField<MonoBehaviour>(plugin, "_cameraPlus");
if (_cameraPlus != null)
{
Camera cam = ReflectionUtil.GetPrivateField<Camera>(_cameraPlus, "_cam");
if (cam !=null)
{
if (((plugin.Name == "CameraPlus" || plugin.Name == "CameraPlusOrbitEdition") && Plugin.IsCameraPlusOn) || (plugin.Name == "DynamicCamera" && Plugin.IsDynamicCameraOn))
cam.cullingMask &= ~(1 << WallLayer);
else
cam.cullingMask |= (1 << WallLayer);
}
Camera multi = ReflectionUtil.GetPrivateField<Camera>(_cameraPlus, "multi");
if (multi != null)
{
if (Plugin.IsMutiViewFirstPersonOn)
multi.cullingMask &= ~(1 << WallLayer);
else
multi.cullingMask |= (1 << WallLayer);
}
}
break;
}
}
}

public virtual void HandleObstacleDiStartMovementEvent(BeatmapObjectSpawnController obstacleSpawnController, ObstacleController obstacleController)
{
try
{
if (Plugin.IsTranparentWall)
{
StretchableObstacle _stretchableObstacle = ReflectionUtil.GetPrivateField<StretchableObstacle>(obstacleController, "_stretchableObstacle");
StretchableCube _stretchableCoreOutside = ReflectionUtil.GetPrivateField<StretchableCube>(_stretchableObstacle, "_stretchableCoreOutside");
StretchableCube _stretchableCoreInside = ReflectionUtil.GetPrivateField<StretchableCube>(_stretchableObstacle, "_stretchableCoreInside");
MeshRenderer _meshRenderer = ReflectionUtil.GetPrivateField<MeshRenderer>(_stretchableCoreOutside, "_meshRenderer");
MeshRenderer _meshRenderer2 = ReflectionUtil.GetPrivateField<MeshRenderer>(_stretchableCoreInside, "_meshRenderer");
_stretchableCoreOutside.gameObject.layer = WallLayer;
_stretchableCoreInside.gameObject.layer = WallLayer;
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message + "\n" + ex.StackTrace);
}
}
}
}
Loading

0 comments on commit a999eb5

Please sign in to comment.