From b9280cba1544a1ef1a78aded8004938db3152c81 Mon Sep 17 00:00:00 2001 From: sctanf <36978460+sctanf@users.noreply.github.com> Date: Thu, 12 Jan 2023 20:06:48 -0600 Subject: [PATCH 1/2] Reset camera on output device change --- PhotonicFreedom.cs | 37 +++++++++++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 4 deletions(-) diff --git a/PhotonicFreedom.cs b/PhotonicFreedom.cs index a92e222..ea187e2 100644 --- a/PhotonicFreedom.cs +++ b/PhotonicFreedom.cs @@ -32,6 +32,12 @@ public static List Types private static JsonSerializerSettings? serializerSettings = new JsonSerializerSettings { NullValueHandling = NullValueHandling.Include, ReferenceLoopHandling = ReferenceLoopHandling.Ignore, TypeNameHandling = TypeNameHandling.Auto }; public static void Bootstrap() { + Slot UserspacePhotonicFreedom = Userspace.UserspaceWorld.RootSlot.Find("PhotonicFreedom"); + if (UserspacePhotonicFreedom != null) + { + UserspacePhotonicFreedom.Destroy(); + } + Userspace.UserspaceWorld.RootSlot.AddSlot("PhotonicFreedom", false); UnityEngine.Camera mainCam = UnityEngine.Camera.main; PostProcessLayer layer = mainCam.GetComponent(); if(layer == null) @@ -128,7 +134,7 @@ public static void WriteCurrentSettings(Type type, object comp) public static void ReadAllSettings(Type type, object comp) { ClassSerializer loaded = JsonConvert.DeserializeObject(File.ReadAllText($"nml_mods/Photonic_Settings/{type.Name}.json"), serializerSettings); - Slot UserspaceRoot = Userspace.UserspaceWorld.RootSlot; + Slot UserspacePhotonicFreedom = Userspace.UserspaceWorld.RootSlot.Find("PhotonicFreedom"); foreach (var field in FieldHolders[type].Fields) { IFieldValuePair pair = loaded.defaultFieldValues.FirstOrDefault(pair => pair.fieldName == field.Name); @@ -137,7 +143,7 @@ public static void ReadAllSettings(Type type, object comp) { field.SetRealValue(comp, pair.BoxedValue); object? SanitizedValue = pair.BoxedValue.GetType() == typeof(UnityEngine.Color) ? UnityNeos.Conversions.ToNeos((UnityEngine.Color)pair.BoxedValue) : pair.BoxedValue; - var DynValue = UserspaceRoot.AttachComponent(typeof(DynamicValueVariable<>).MakeGenericType(SanitizedValue.GetType())); + var DynValue = UserspacePhotonicFreedom.AttachComponent(typeof(DynamicValueVariable<>).MakeGenericType(SanitizedValue.GetType())); if (DynValue == null) return; @@ -173,7 +179,7 @@ public static void ReadAllSettings(Type type, object comp) { property.SetRealValue(comp, pair.BoxedValue); object? SanitizedValue = pair.BoxedValue.GetType() == typeof(UnityEngine.Color) ? UnityNeos.Conversions.ToNeos((UnityEngine.Color)pair.BoxedValue) : pair.BoxedValue; - var DynValue = UserspaceRoot.AttachComponent(typeof(DynamicValueVariable<>).MakeGenericType(SanitizedValue.GetType())); + var DynValue = UserspacePhotonicFreedom.AttachComponent(typeof(DynamicValueVariable<>).MakeGenericType(SanitizedValue.GetType())); if (DynValue == null) { return; @@ -451,11 +457,13 @@ public static IEnumerable OnAttach_Transpiler(IEnumerable Date: Tue, 17 Jan 2023 20:09:03 -0600 Subject: [PATCH 2/2] Update PhotonicFreedom.cs --- PhotonicFreedom.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/PhotonicFreedom.cs b/PhotonicFreedom.cs index ea187e2..ff40f4d 100644 --- a/PhotonicFreedom.cs +++ b/PhotonicFreedom.cs @@ -502,6 +502,7 @@ public static void OnCommonUpdate_Postfix(ScreenModeController __instance) if (mainCam != UnityEngine.Camera.main && UnityEngine.Camera.main != null) { Msg("Resetting Camera"); + mainCam = UnityEngine.Camera.main; OutputDeviceChanged = false; Bootstrap(); }