Skip to content

Commit

Permalink
add UIBloom setting
Browse files Browse the repository at this point in the history
add final grain removal
gnivler committed Sep 14, 2018
1 parent c195220 commit a2cc696
Showing 6 changed files with 159 additions and 110 deletions.
123 changes: 68 additions & 55 deletions CrystalClear.cs
Original file line number Diff line number Diff line change
@@ -1,27 +1,22 @@
using Harmony;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Text;
using BattleTech;
using BattleTech.Rendering;
using Org.BouncyCastle.Math.Raw;
using UnityEngine;
using UnityEngine.PostProcessing;
using static CrystalClear.Logger;

namespace CrystalClear
{
public class ModSettings
public class Settings
{
public bool Dithering;
public bool Grain;
public bool Vignette;
public bool Bloom;
public bool UIBloom;
public bool Shadows;
public bool ChromaticAberration;
public bool EyeAdaptation;
@@ -34,194 +29,212 @@ public class ModSettings
public bool HDR;
public bool Grunge;
public bool Scanlines;
public bool enableDebug;
}

public static class CrystalClear
{
private static ModSettings settings;
public static Settings modSettings;
public static string modDirectory;

public static void Init(string modDirectory, string settingsJson)
{
FileLog.logPath = Path.Combine(modDirectory, "log.txt");
Clear();
var harmony = HarmonyInstance.Create("ca.gnivler.ScorchedEarth");
var harmony = HarmonyInstance.Create("ca.gnivler.CrystalClear");
//HarmonyInstance.DEBUG = false;
harmony.PatchAll(Assembly.GetExecutingAssembly());
try
{
CrystalClear.modDirectory = modDirectory;
settings = JsonConvert.DeserializeObject<ModSettings>(settingsJson);
modSettings = JsonConvert.DeserializeObject<Settings>(settingsJson);
}
catch (Exception e)
{
Error(e);
}

if (settings.Grunge || settings.Scanlines) return;
if (modSettings.Grunge || modSettings.Scanlines) return;
int mainTex = Shader.PropertyToID("_MainTex");
Type uniformsType = AccessTools.Inner(typeof(BTPostProcess), "Uniforms");
if (!settings.Grunge)
if (!modSettings.Grunge)
{
AccessTools.Field(uniformsType, "_GrungeTex").SetValue(null, mainTex);
}

if (!settings.Scanlines)
if (!modSettings.Scanlines)
{
AccessTools.Field(uniformsType, "_ScanlineTex").SetValue(null, mainTex);
}

if (!modSettings.Dithering)
{
AccessTools.Field(uniformsType, "_DitheringTex").SetValue(null, 0);
}
}

[HarmonyPatch(typeof(BTPostProcess), "OnEnable", MethodType.Normal)]
public static class BTPostProcess_Ctor_Patch
{
public static void Postfix(ref float ___uiBloomIntensity)
{
if (!modSettings.UIBloom)
{
___uiBloomIntensity = 0f;
LogDebug("Patching UI bloom");
}
}
}

[HarmonyPatch(typeof(MenuCamera), "OnEnable", MethodType.Normal)]
public static class MenuCamera_Ctor_Patch
{
public static void Postfix(ref float ___uiBloomIntensity)
{
if (!modSettings.UIBloom)
{
LogDebug("Patching menu bloom");
___uiBloomIntensity = 0f;
}
}
}

[HarmonyPatch(typeof(DitheringComponent))]
[HarmonyPatch("active", PropertyMethod.Getter)]
[HarmonyPatch(typeof(DitheringComponent), "active", MethodType.Getter)]
public static class PatchDitheringComp
{
public static bool Prefix(ref bool __result)
{
__result = settings.Dithering;
__result = modSettings.Dithering;
return false;
}
}

[HarmonyPatch(typeof(GrainComponent))]
[HarmonyPatch("active", PropertyMethod.Getter)]
[HarmonyPatch(typeof(GrainComponent), "active", MethodType.Getter)]
public static class PatchGrainComp
{
public static bool Prefix(ref bool __result)
{
__result = settings.Grain;
__result = modSettings.Grain;
return false;
}
}

[HarmonyPatch(typeof(VignetteComponent))]
[HarmonyPatch("active", PropertyMethod.Getter)]
[HarmonyPatch(typeof(VignetteComponent), "active", MethodType.Getter)]
public static class PatchVignette
{
public static bool Prefix(ref bool __result)
{
__result = settings.Vignette;
__result = modSettings.Vignette;
return false;
}
}

[HarmonyPatch(typeof(BloomComponent))]
[HarmonyPatch("active", PropertyMethod.Getter)]
[HarmonyPatch(typeof(BloomComponent), "active", MethodType.Getter)]
public static class PatchBloom
{
public static bool Prefix(ref bool __result)
{
__result = settings.Bloom;
__result = modSettings.Bloom;
return false;
}
}

[HarmonyPatch(typeof(ScreenSpaceShadowsComponent))]
[HarmonyPatch("active", PropertyMethod.Getter)]
[HarmonyPatch(typeof(ScreenSpaceShadowsComponent), "active", MethodType.Getter)]
public static class PatchShadows
{
public static bool Prefix(ref bool __result)
{
__result = settings.Shadows;
__result = modSettings.Shadows;
return false;
}
}

[HarmonyPatch(typeof(ChromaticAberrationComponent))]
[HarmonyPatch("active", PropertyMethod.Getter)]
[HarmonyPatch(typeof(ChromaticAberrationComponent), "active", MethodType.Getter)]
public static class ChromaticAberration
{
public static bool Prefix(ref bool __result)
{
__result = settings.ChromaticAberration;
__result = modSettings.ChromaticAberration;
return false;
}
}

[HarmonyPatch(typeof(EyeAdaptationComponent))]
[HarmonyPatch("active", PropertyMethod.Getter)]
[HarmonyPatch(typeof(EyeAdaptationComponent), "active", MethodType.Getter)]
public static class EyeAdaptation
{
public static bool Prefix(ref bool __result)
{
__result = settings.EyeAdaptation;
__result = modSettings.EyeAdaptation;
return false;
}
}

[HarmonyPatch(typeof(FogComponent))]
[HarmonyPatch("active", PropertyMethod.Getter)]
[HarmonyPatch(typeof(FogComponent), "active", MethodType.Getter)]
public static class Fog
{
public static bool Prefix(ref bool __result)
{
__result = settings.Fog;
__result = modSettings.Fog;
return false;
}
}

[HarmonyPatch(typeof(ColorGradingComponent))]
[HarmonyPatch("active", PropertyMethod.Getter)]
[HarmonyPatch(typeof(ColorGradingComponent), "active", MethodType.Getter)]
public static class ColorGrading
{
public static bool Prefix(ref bool __result)
{
__result = settings.ColorGrading;
__result = modSettings.ColorGrading;
return false;
}
}

[HarmonyPatch(typeof(AmbientOcclusionComponent))]
[HarmonyPatch("active", PropertyMethod.Getter)]
[HarmonyPatch(typeof(AmbientOcclusionComponent), "active", MethodType.Getter)]
public static class AmbientOcclusion
{
public static bool Prefix(ref bool __result)
{
__result = settings.AmbientOcclusion;
__result = modSettings.AmbientOcclusion;
return false;
}
}

[HarmonyPatch(typeof(TaaComponent))]
[HarmonyPatch("active", PropertyMethod.Getter)]
[HarmonyPatch(typeof(TaaComponent), "active", MethodType.Getter)]
public static class Taa
{
public static bool Prefix(ref bool __result)
{
__result = settings.Taa;
__result = modSettings.Taa;
return false;
}
}

[HarmonyPatch(typeof(DepthOfFieldComponent))]
[HarmonyPatch("active", PropertyMethod.Getter)]
[HarmonyPatch(typeof(DepthOfFieldComponent), "active", MethodType.Getter)]
public static class DepthOfField
{
public static bool Prefix(ref bool __result)
{
__result = settings.DepthOfField;
__result = modSettings.DepthOfField;
return false;
}
}

[HarmonyPatch(typeof(FxaaComponent))]
[HarmonyPatch("active", PropertyMethod.Getter)]
[HarmonyPatch(typeof(FxaaComponent), "active", MethodType.Getter)]
public static class Fxaa
{
public static bool Prefix(ref bool __result)
{
__result = settings.Fxaa;
__result = modSettings.Fxaa;
return false;
}
}

[HarmonyPatch(typeof(PostProcessingContext))]
[HarmonyPatch("isHdr", PropertyMethod.Getter)]
[HarmonyPatch(typeof(PostProcessingContext), "isHdr", MethodType.Getter)]
public static class HdrPatch
{
public static bool Prefix(ref bool __result)
{
__result = settings.HDR;
__result = modSettings.HDR;
return false;
}
}
4 changes: 2 additions & 2 deletions CrystalClear.csproj
Original file line number Diff line number Diff line change
@@ -31,11 +31,11 @@
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<ItemGroup>
<Reference Include="0Harmony, Version=1.1.0.0, Culture=neutral, PublicKeyToken=null">
<Reference Include="0Harmony, Version=1.2.0.1, Culture=neutral, PublicKeyToken=null">
<HintPath>C:\References\0Harmony.dll</HintPath>
</Reference>
<Reference Include="Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
<HintPath>C:\References\publicized_assemblies\Assembly-CSharp_publicized.dll</HintPath>
<HintPath>C:\References\Assembly-CSharp.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json">
<HintPath>C:\References\Newtonsoft.Json.dll</HintPath>
3 changes: 2 additions & 1 deletion Logger.cs
Original file line number Diff line number Diff line change
@@ -15,8 +15,9 @@ public static void Error(Exception ex)
}
}

public static void Debug(string line)
public static void LogDebug(string line)
{
if (!CrystalClear.modSettings.enableDebug) return;
using (var writer = new StreamWriter(LogFilePath, true))
{
writer.WriteLine(line);
6 changes: 3 additions & 3 deletions Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -8,9 +8,9 @@
[assembly: AssemblyTitle("CrystalClear")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyCompany("gnivler")]
[assembly: AssemblyProduct("CrystalClear")]
[assembly: AssemblyCopyright("Copyright © 2018")]
[assembly: AssemblyCopyright("MIT")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

@@ -32,4 +32,4 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.4")]
[assembly: AssemblyVersion("2.2")]
48 changes: 24 additions & 24 deletions Unlicense.txt
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
This is free and unencumbered software released into the public domain.
Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.
In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
software to the public domain. We make this dedication for the benefit
of the public at large and to the detriment of our heirs and
successors. We intend this dedication to be an overt act of
relinquishment in perpetuity of all present and future rights to this
software under copyright law.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
For more information, please refer to <http://unlicense.org>
This is free and unencumbered software released into the public domain.

Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.

In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
software to the public domain. We make this dedication for the benefit
of the public at large and to the detriment of our heirs and
successors. We intend this dedication to be an overt act of
relinquishment in perpetuity of all present and future rights to this
software under copyright law.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.

For more information, please refer to <http://unlicense.org>
85 changes: 60 additions & 25 deletions mod.json
Original file line number Diff line number Diff line change
@@ -1,29 +1,64 @@
{
"Name": "CrystalClear",
"Version": "1.3",
"Enabled": true,

"DLL": "CrystalClear.dll",

"Settings": {
"Grain": false, /* reduces clarity when enabled */
"Dithering": false, /* reduces clarity when enabled */
"Vignette": true, /* darkens the edges of the scene */
"Bloom": true, /* makes light sources overblown when enabled */
"Shadows": true, /* can fully disable */
"ChromaticAberration": true, /* unsure if used. it should appear as green/purple edge tinting */
"EyeAdaptation": true, /* simulates pupil dilation response */
"Fog": false, /* setting to true makes everywhere foggy */
"ColorGrading": true, /* unsure */
"AmbientOcclusion": true, /* looks so good I wouldn't disable it */
"Taa": true, /* temporal antialiasing aka MFAA - good fidelity */
"DepthOfField": true, /* stuff at different distances is focused differently (blurred) */
"Fxaa": true, /* almost-free light anti-aliasing */
"HDR": true, /* renderer is expecting this to be on but works without */
"Grunge": true, /* dirty UI */
"Scanlines": true, /* scanline animation on UI */

}
"Name": "CrystalClear",
"Version": "2.2",
"Enabled": true,
"DLL": "CrystalClear.dll",

// default: only Grain and Dithering off
// recommended: all false except ColorGrading, Taa, DepthofField, Fxaa and HDR

"Settings": {
// reduces clarity
"Grain": false,

// reduces clarity
"Dithering": false,

// darkens the edges of the scene
"Vignette": true,

// makes light sources overblown when enabled
"Bloom": true,

// make UI elements glow
"UIBloom": true,

// can fully disable
"Shadows": true,

// unsure if used. it should appear as green/purple edge tinting
"ChromaticAberration": true,

// simulates pupil dilation response
"EyeAdaptation": true,

// setting to true makes everywhere foggy
"Fog": false,

// unsure */
"ColorGrading": true,

// looks so good I wouldn't disable it
"AmbientOcclusion": true,

// temporal antialiasing aka MFAA - good fidelity
"Taa": true,

// stuff at different distances is focused differently (blurred)
"DepthOfField": true,

// almost-free anti-aliasing
"Fxaa": true,

// renderer is expecting this to be on but works without
"HDR": true,

// dirty UI */
"Grunge": true,

// scanline animation on UI
"Scanlines": true
}
}


0 comments on commit a2cc696

Please sign in to comment.