Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions CameraHelperFunctions.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
using NeosModLoader;
using ResoniteModLoader;
using FrooxEngine;
using BaseX;
using Elements.Core;
using UnityEngine;
using Camera = FrooxEngine.Camera;
using Component = FrooxEngine.Component;
using System.Reflection;
using UnityEngine.Rendering.PostProcessing;
using UnityNeos;
using UnityFrooxEngineRunner;

namespace ReFract;

Expand Down Expand Up @@ -52,12 +52,12 @@ public static void SetCameraVariable(DynamicVariableSpace? space, string CameraN

UnityCam = cam.ToUnity(); // ToUnity() wants a ton of unity references, if that's why you're questioning the excessive unity libraries >.>
Value = ValueTransformer(Value);
NeosMod.Debug("Re:Fract : " + CameraName + " Camera Found");
ResoniteMod.Debug("Re:Fract : " + CameraName + " Camera Found");

// If the camera is not null, but the unity cam is assume it's still initializing and try running the set variable function again in a bit
if (cam != null && UnityCam == null) // My null checks are paranoid, sue me
{
NeosMod.Debug($"Re:Fract : {CameraName} Camera Connector Found on {cam?.Slot.Name} but no UnityCamera, looping again");
ResoniteMod.Debug($"Re:Fract : {CameraName} Camera Connector Found on {cam?.Slot.Name} but no UnityCamera, looping again");
Engine.Current.WorldManager.FocusedWorld.RunInSeconds(0.25f, () => SetCameraVariable(space, CameraName, ComponentName, ParamName, Value));
return;
}
Expand All @@ -82,8 +82,8 @@ public static void SetCameraVariable(DynamicVariableSpace? space, string CameraN

if (target == null) return;

NeosMod.Debug($"Re:Fract : Camera is {cam}");
NeosMod.Debug($"Re:Fract : setting the {ParamName} parameter of the {target.GetType()} on camera {cam?.Slot.Name} to {Value} (of type {Value.GetType()}");
ResoniteMod.Debug($"Re:Fract : Camera is {cam}");
ResoniteMod.Debug($"Re:Fract : setting the {ParamName} parameter of the {target.GetType()} on camera {cam?.Slot.Name} to {Value} (of type {Value.GetType()}");
// Call into introspection and give it our override for parameters. Introspection again lets us set values on private fields without reflection
// Also checking to see if the field name ends with an exclamaition mark, it's an easy way to tell if you wanna set a property or a field
if (ParamName.EndsWith("!"))
Expand Down Expand Up @@ -132,14 +132,14 @@ public static void RefreshCameraState(DynamicReferenceVariable<Camera> camVar, C
// Make sure the variables follow the naming conventions for Re:Fract
if (splitName.Length == 3 && stringTokens != null && stringTokens.Length == 4 && stringTokens[1] == splitName[2])
{
NeosMod.Debug("Re:Fract : " + keyName + " interacts with this camera");
ResoniteMod.Debug("Re:Fract : " + keyName + " interacts with this camera");
object? val = spaceDict[key].GetType().GetProperty("Value")?.GetValue(spaceDict[key]);
NeosMod.Debug("Re:Fract : " + keyName + " is " + val + " from " + handler);
ResoniteMod.Debug("Re:Fract : " + keyName + " is " + val + " from " + handler);
if (val != null && handler != null)
{
// If all is well, set the camera's post processing variables back to the ones provided by the space
SetCameraVariable(handler.CurrentSpace, stringTokens[1], stringTokens[2], stringTokens[3], val, altCameraInstance);
NeosMod.Debug("Re:Fract : Tokens are " + stringTokens[1] + " " + stringTokens[2] + " " + stringTokens[3]);
ResoniteMod.Debug("Re:Fract : Tokens are " + stringTokens[1] + " " + stringTokens[2] + " " + stringTokens[3]);
}
}
}
Expand Down
30 changes: 15 additions & 15 deletions Introspection.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using NeosModLoader;
using ResoniteModLoader;
using System.Reflection;
using System.Reflection.Emit;
namespace ReFract;
Expand All @@ -22,17 +22,17 @@ public static class Introspection
{
if (obj == null || fieldName == null || fieldName.Length == 0)
return null;
NeosMod.Debug("Introspection : Getting field");
ResoniteMod.Debug("Introspection : Getting field");
// Get the target field
FieldInfo field = obj.GetField(fieldName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
NeosMod.Debug("Introspection : Field is " + (field == null ? "null" : "not null"));
ResoniteMod.Debug("Introspection : Field is " + (field == null ? "null" : "not null"));
if (field == null)
return null;

NeosMod.Debug("Introspection : Field is " + field.Name);
ResoniteMod.Debug("Introspection : Field is " + field.Name);
// Get the delegate that acts as a field accessor the target field
var del = GetDynamicMethod(obj, field, ilOverride);
NeosMod.Debug("Introspection : Delegate is " + (del == null ? "null" : "not null & " + del.GetType().ToString()));
ResoniteMod.Debug("Introspection : Delegate is " + (del == null ? "null" : "not null & " + del.GetType().ToString()));

if (del == null)
return null;
Expand All @@ -42,7 +42,7 @@ public static class Introspection
_cachedSetters.Add(obj, new Dictionary<string, RefAction<object, object>>());

_cachedSetters[obj].Add(fieldName, del);
NeosMod.Debug("Introspection : Added delegate to dictionary at " + obj.ToString() + "." + fieldName);
ResoniteMod.Debug("Introspection : Added delegate to dictionary at " + obj.ToString() + "." + fieldName);
return del;
}
}
Expand All @@ -61,17 +61,17 @@ public static class Introspection
if (obj == null || propName == null || propName.Length == 0)
return null;

NeosMod.Debug("Introspection : Getting property");
ResoniteMod.Debug("Introspection : Getting property");
// Get the target property
PropertyInfo prop = obj.GetProperty(propName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
NeosMod.Debug("Introspection : Property is " + (prop == null ? "null" : "not null"));
ResoniteMod.Debug("Introspection : Property is " + (prop == null ? "null" : "not null"));
if (prop == null)
return null;

NeosMod.Debug("Introspection : Property is " + prop.Name);
ResoniteMod.Debug("Introspection : Property is " + prop.Name);
// Get the delegate that acts as a property accessor the target property
var del = GetDynamicPropMethod(obj, prop);
NeosMod.Debug("Introspection : Delegate is " + (del == null ? "null" : "not null & " + del.GetType().ToString()));
ResoniteMod.Debug("Introspection : Delegate is " + (del == null ? "null" : "not null & " + del.GetType().ToString()));

if (del == null)
return null;
Expand All @@ -81,7 +81,7 @@ public static class Introspection
_cachedPropSetters.Add(obj, new Dictionary<string, Action<object, object>>());

_cachedPropSetters[obj].Add(propName, del);
NeosMod.Debug("Introspection : Added delegate to dictionary at " + obj.ToString() + "." + propName);
ResoniteMod.Debug("Introspection : Added delegate to dictionary at " + obj.ToString() + "." + propName);
return del;
}
}
Expand Down Expand Up @@ -136,11 +136,11 @@ public static RefAction<object, object> GetDynamicMethod(Type obj, FieldInfo fie
// If the type doesn't match, print out a message and return, doing nothing.
il.MarkLabel(typeFailed);
il.Emit(OpCodes.Ldstr, $"Re:Fract : Wrong type for field \"{field.Name}\" which takes \"{field.FieldType}\"");
il.Emit(OpCodes.Call, typeof(NeosMod).GetMethod("Msg", new Type[] { typeof(string) }));
il.Emit(OpCodes.Call, typeof(ResoniteMod).GetMethod("Msg", new Type[] { typeof(string) }));
il.Emit(OpCodes.Ret);
NeosMod.Debug("Introspection : Generated dynamic method with default IL");
ResoniteMod.Debug("Introspection : Generated dynamic method with default IL");
}
NeosMod.Debug("Introspection : Creation of DynamicMethod was successful for " + obj.ToString() + "." + field.Name);
ResoniteMod.Debug("Introspection : Creation of DynamicMethod was successful for " + obj.ToString() + "." + field.Name);
return (RefAction<object, object>)method.CreateDelegate(typeof(RefAction<,>).MakeGenericType(typeof(object), typeof(object)));
}

Expand All @@ -164,7 +164,7 @@ public static RefAction<object, object> GetDynamicMethod(Type obj, FieldInfo fie
il.Emit(OpCodes.Call, method);
il.Emit(OpCodes.Ret);

NeosMod.Debug("Introspection : Created delegate for property " + prop.Name);
ResoniteMod.Debug("Introspection : Created delegate for property " + prop.Name);

var ret = (Action<object, object>)del.CreateDelegate(typeof(Action<object, object>));
// Add the delegate to the dictionary
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Re:Fract

## Re:Fract is a [NeosModLoader](https://github.com/zkxs/NeosModLoader) mod that exposes many settings on the unity post processing stack for Neos cameras.
## Re:Fract is a [ResoniteModLoader](https://github.com/resonite-modding-group/ResoniteModLoader) mod that exposes many settings on the unity post processing stack for Neos cameras.

## You can find usage instructions in: [Usage.md](Usage.md)
## Main Features:
Expand Down
49 changes: 31 additions & 18 deletions ReFract.cs
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
using HarmonyLib;
using NeosModLoader;
using ResoniteModLoader;
using FrooxEngine;
using BaseX;
using Elements.Core;
using UnityEngine;
using Camera = FrooxEngine.Camera;
using Component = FrooxEngine.Component;
using System.Text;
using System.Reflection;
using UnityEngine.Rendering.PostProcessing;
using System.Reflection.Emit;
using UnityNeos;
using UnityFrooxEngineRunner;

namespace ReFract;
public class ReFract : NeosMod
public class ReFract : ResoniteMod
{
public override string Author => "Cyro";
public override string Name => "ReFract";
public override string Version => "1.1.1";
public override string Version => "1.1.3";
public static string DynVarKeyString => "Re.Fract_";
public static string DynVarCamKeyString => "Re.Fract_Camera_";
public static string ReFractTag => "Re:FractCameraSpace";
Expand Down Expand Up @@ -72,7 +71,7 @@ public static bool ILOverride(Type obj, FieldInfo field, ILGenerator il)
// Call Msg() and print out a silly message if we failed to cast the argument
il.MarkLabel(typeFailed);
il.Emit(OpCodes.Ldstr, $"Re:Fract : Wrong type for field \"{field.Name}\" which takes \"{BaseFieldType.GetGenericArguments()[0]}\"! You fool!");
il.Emit(OpCodes.Call, typeof(NeosMod).GetMethod("Msg", new Type[] { typeof(string) }));
il.Emit(OpCodes.Call, typeof(ResoniteMod).GetMethod("Msg", new Type[] { typeof(string) }));
il.Emit(OpCodes.Ret);
return true;
}
Expand All @@ -98,16 +97,30 @@ public override void OnEngineInit()
Harmony harmony = new Harmony("net.Cyro.ReFract");

// Get all types that inherit from PostProcessEffectSettings
foreach (Assembly assembly in AppDomain.CurrentDomain.GetAssemblies())
{
foreach (Type type in assembly.GetTypes())
{
if (type.IsSubclassOf(typeof(PostProcessEffectSettings)))
{
TypeLookups.Add(type.Name, type);
}
}
}
// foreach (Assembly assembly in AppDomain.CurrentDomain.GetAssemblies())
// {
// foreach (Type type in assembly.GetTypes())
// {
// if (type.IsSubclassOf(typeof(PostProcessEffectSettings)))
// {
// TypeLookups.Add(type.Name, type);
// }
// }
// }

// Manual
TypeLookups.Add("AmbientOcclusion", typeof(AmbientOcclusion));
TypeLookups.Add("AutoExposure", typeof(AutoExposure));
TypeLookups.Add("Bloom", typeof(Bloom));
TypeLookups.Add("ChromaticAberration", typeof(ChromaticAberration));
TypeLookups.Add("ColorGrading", typeof(ColorGrading));
TypeLookups.Add("DepthOfField", typeof(DepthOfField));
TypeLookups.Add("Grain", typeof(Grain));
TypeLookups.Add("LensDistortion", typeof(LensDistortion));
TypeLookups.Add("MotionBlur", typeof(MotionBlur));
TypeLookups.Add("ScreenSpaceReflections", typeof(ScreenSpaceReflections));
TypeLookups.Add("Vignette", typeof(Vignette));

TypeLookups.Add("AmplifyOcclusionBase", typeof(AmplifyOcclusionBase)); // Include this specifically since it does post processing, but is not part of the bundle stack
// TypeLookups will be used to easily get a type from one specified in a dynamic variable name string

Expand Down Expand Up @@ -412,7 +425,7 @@ public static bool RenderImmediatePrefix(ref byte[] __result, RenderConnector __
else
{
UnityEngine.RenderTexture active = UnityEngine.RenderTexture.active;
UnityEngine.Texture2D tex = new UnityEngine.Texture2D(camRes.x, camRes.y, renderSettings.textureFormat.ToUnity(true), false);
UnityEngine.Texture2D tex = new UnityEngine.Texture2D(camRes.x, camRes.y, renderSettings.textureFormat.ToUnity(true), false, true);

unityCam.Render();
UnityEngine.RenderTexture.active = renderTexture;
Expand Down
45 changes: 24 additions & 21 deletions ReFract.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,46 +11,49 @@
</PropertyGroup>


<ItemGroup>
<PackageReference Include="System.Net.Http" Version="4.3.4" />
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="6.0.0" />
</ItemGroup>


<ItemGroup>
<Reference Include="0Harmony">
<HintPath>SymlinkedLibraries\0Harmony.dll</HintPath>
</Reference>
<Reference Include="BaseX">
<HintPath>SymlinkedLibraries\BaseX.dll</HintPath>
<Reference Include="Assembly-CSharp">
<HintPath>SymlinkedLibraries\Assembly-CSharp.dll</HintPath>
</Reference>
<Reference Include="Elements.Assets">
<HintPath>SymlinkedLibraries\Elements.Assets.dll</HintPath>
</Reference>
<Reference Include="CodeX">
<HintPath>SymlinkedLibraries\CodeX.dll</HintPath>
<Reference Include="Elements.Core">
<HintPath>SymlinkedLibraries\Elements.Core.dll</HintPath>
</Reference>
<Reference Include="FrooxEngine">
<HintPath>SymlinkedLibraries\FrooxEngine.dll</HintPath>
</Reference>
<Reference Include="NeosModLoader">
<HintPath>SymlinkedLibraries\NeosModLoader.dll</HintPath>
</Reference>
<Reference Include="UnityNeos">
<HintPath>SymlinkedLibraries\UnityNeos.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.CoreModule">
<HintPath>SymlinkedLibraries\UnityEngine.CoreModule.dll</HintPath>
<Reference Include="ResoniteModLoader">
<HintPath>SymlinkedLibraries\ResoniteModLoader.dll</HintPath>
</Reference>
<Reference Include="Unity.Rendering.PostProcessing">
<Reference Include="Unity.Postprocessing.Runtime">
<HintPath>SymlinkedLibraries\Unity.Postprocessing.Runtime.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.Rendering">
<HintPath>SymlinkedLibraries\Assembly-CSharp.dll</HintPath>
<Reference Include="UnityEngine">
<HintPath>SymlinkedLibraries\UnityEngine.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.AudioModule">
<HintPath>SymlinkedLibraries\UnityEngine.AudioModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.CoreModule">
<HintPath>SymlinkedLibraries\UnityEngine.CoreModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.ParticleSystemModule">
<HintPath>SymlinkedLibraries\UnityEngine.ParticleSystemModule.dll</HintPath>
</Reference>
</ItemGroup>


<ItemGroup>
<PackageReference Include="System.Net.Http" Version="4.3.4" />
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="6.0.0" />
<Reference Include="UnityFrooxEngineRunner">
<HintPath>SymlinkedLibraries\UnityFrooxEngineRunner.dll</HintPath>
</Reference>
</ItemGroup>

</Project>
25 changes: 25 additions & 0 deletions ReFract.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 Version 17
VisualStudioVersion = 17.7.34031.279
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ReFract", "ReFract.csproj", "{7E0630EC-DE03-4697-B369-5205863EDCE0}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{7E0630EC-DE03-4697-B369-5205863EDCE0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7E0630EC-DE03-4697-B369-5205863EDCE0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7E0630EC-DE03-4697-B369-5205863EDCE0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7E0630EC-DE03-4697-B369-5205863EDCE0}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {3AA62700-EF27-4CA8-9031-C0B787D4A8C8}
EndGlobalSection
EndGlobal
2 changes: 1 addition & 1 deletion SymlinkedLibraries/0Harmony.dll
2 changes: 1 addition & 1 deletion SymlinkedLibraries/Assembly-CSharp.dll
1 change: 0 additions & 1 deletion SymlinkedLibraries/BaseX.dll

This file was deleted.

1 change: 0 additions & 1 deletion SymlinkedLibraries/CodeX.dll

This file was deleted.

1 change: 1 addition & 0 deletions SymlinkedLibraries/Elements.Assets.dll
1 change: 1 addition & 0 deletions SymlinkedLibraries/Elements.Core.dll
2 changes: 1 addition & 1 deletion SymlinkedLibraries/FrooxEngine.dll
1 change: 0 additions & 1 deletion SymlinkedLibraries/NeosModLoader.dll

This file was deleted.

1 change: 1 addition & 0 deletions SymlinkedLibraries/ResoniteModLoader.dll
2 changes: 1 addition & 1 deletion SymlinkedLibraries/Unity.Postprocessing.Runtime.dll
2 changes: 1 addition & 1 deletion SymlinkedLibraries/UnityEngine.AudioModule.dll
2 changes: 1 addition & 1 deletion SymlinkedLibraries/UnityEngine.CoreModule.dll
Loading