|
@@ -1,3 +1,4 @@
|
|
|
+using System.Reflection;
|
|
|
using UnityEngine;
|
|
|
|
|
|
namespace COM3D2.MeidoPhotoStudio.Plugin
|
|
@@ -5,14 +6,31 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
|
|
|
internal class BloomEffectManager : IEffectManager
|
|
|
{
|
|
|
public const string header = "EFFECT_BLOOM";
|
|
|
+ private const float bloomDefIntensity = 5.7f;
|
|
|
+ private static readonly CameraMain camera = GameMain.Instance.MainCamera;
|
|
|
private Bloom Bloom { get; set; }
|
|
|
+ // CMSystem's bloomValue;
|
|
|
+ private static int backupBloomValue;
|
|
|
+ private static readonly float backup_m_fBloomDefIntensity;
|
|
|
+ private static readonly FieldInfo m_fBloomDefIntensity
|
|
|
+ = Utility.GetFieldInfo<CameraMain>("m_fBloomDefIntensity");
|
|
|
+ private static float BloomDefIntensity
|
|
|
+ {
|
|
|
+ set => m_fBloomDefIntensity.SetValue(camera, value);
|
|
|
+ get => (float)m_fBloomDefIntensity.GetValue(camera);
|
|
|
+ }
|
|
|
private float initialIntensity;
|
|
|
private int initialBlurIterations;
|
|
|
private Color initialThresholdColour;
|
|
|
private Bloom.HDRBloomMode initialHDRBloomMode;
|
|
|
public bool Ready { get; private set; }
|
|
|
public bool Active { get; private set; }
|
|
|
- public float Intensity { get; set; }
|
|
|
+ private float bloomValue;
|
|
|
+ public float BloomValue
|
|
|
+ {
|
|
|
+ get => bloomValue;
|
|
|
+ set => GameMain.Instance.CMSystem.BloomValue = (int)(bloomValue = value);
|
|
|
+ }
|
|
|
private int blurIterations;
|
|
|
public int BlurIterations
|
|
|
{
|
|
@@ -52,21 +70,23 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
|
|
|
get => bloomThresholdColour;
|
|
|
set => bloomThresholdColour = Bloom.bloomThreshholdColor = value;
|
|
|
}
|
|
|
- private bool HDRBloomMode;
|
|
|
+ private bool bloomHdr;
|
|
|
public bool BloomHDR
|
|
|
{
|
|
|
- get => HDRBloomMode;
|
|
|
+ get => bloomHdr;
|
|
|
set
|
|
|
{
|
|
|
Bloom.hdr = value ? Bloom.HDRBloomMode.On : Bloom.HDRBloomMode.Auto;
|
|
|
- HDRBloomMode = value;
|
|
|
+ bloomHdr = value;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ static BloomEffectManager() => backup_m_fBloomDefIntensity = BloomDefIntensity;
|
|
|
+
|
|
|
public void Serialize(System.IO.BinaryWriter binaryWriter)
|
|
|
{
|
|
|
binaryWriter.Write(header);
|
|
|
- binaryWriter.Write(Intensity);
|
|
|
+ binaryWriter.Write(BloomValue);
|
|
|
binaryWriter.Write(BlurIterations);
|
|
|
binaryWriter.WriteColour(BloomThresholdColour);
|
|
|
binaryWriter.Write(BloomHDR);
|
|
@@ -75,7 +95,7 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
|
|
|
|
|
|
public void Deserialize(System.IO.BinaryReader binaryReader)
|
|
|
{
|
|
|
- Intensity = binaryReader.ReadSingle();
|
|
|
+ BloomValue = binaryReader.ReadSingle();
|
|
|
BlurIterations = binaryReader.ReadInt32();
|
|
|
BloomThresholdColour = binaryReader.ReadColour();
|
|
|
BloomHDR = binaryReader.ReadBoolean();
|
|
@@ -87,57 +107,56 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
|
|
|
if (Bloom == null)
|
|
|
{
|
|
|
Ready = true;
|
|
|
- Bloom = Utility.GetFieldValue<CameraMain, Bloom>(GameMain.Instance.MainCamera, "m_gcBloom");
|
|
|
- initialIntensity = Intensity = Bloom.bloomIntensity;
|
|
|
- initialBlurIterations = BlurIterations = Bloom.bloomBlurIterations;
|
|
|
- initialThresholdColour = BloomThresholdColour = Bloom.bloomThreshholdColor;
|
|
|
+ Bloom = GameMain.Instance.MainCamera.GetComponent<Bloom>();
|
|
|
+ initialIntensity = bloomValue = 50f;
|
|
|
+ initialBlurIterations = blurIterations = Bloom.bloomBlurIterations;
|
|
|
+ initialThresholdColour = bloomThresholdColour = Bloom.bloomThreshholdColor;
|
|
|
initialHDRBloomMode = Bloom.hdr;
|
|
|
- BloomHDR = initialHDRBloomMode == Bloom.HDRBloomMode.On;
|
|
|
+ bloomHdr = Bloom.hdr == Bloom.HDRBloomMode.On;
|
|
|
+
|
|
|
+ backupBloomValue = GameMain.Instance.CMSystem.BloomValue;
|
|
|
}
|
|
|
+ SetEffectActive(false);
|
|
|
}
|
|
|
|
|
|
public void Deactivate()
|
|
|
{
|
|
|
- Intensity = initialIntensity;
|
|
|
+ BloomValue = initialIntensity;
|
|
|
BlurIterations = initialBlurIterations;
|
|
|
BloomThresholdColour = initialThresholdColour;
|
|
|
BloomHDR = initialHDRBloomMode == Bloom.HDRBloomMode.On;
|
|
|
BloomHDR = false;
|
|
|
- Bloom.enabled = true;
|
|
|
Active = false;
|
|
|
+
|
|
|
+ BloomDefIntensity = backup_m_fBloomDefIntensity;
|
|
|
+ GameMain.Instance.CMSystem.BloomValue = backupBloomValue;
|
|
|
}
|
|
|
|
|
|
public void Reset()
|
|
|
{
|
|
|
- Bloom.bloomIntensity = initialIntensity;
|
|
|
+ GameMain.Instance.CMSystem.BloomValue = backupBloomValue;
|
|
|
Bloom.bloomBlurIterations = initialBlurIterations;
|
|
|
Bloom.bloomThreshholdColor = initialThresholdColour;
|
|
|
Bloom.hdr = initialHDRBloomMode;
|
|
|
+
|
|
|
+ BloomDefIntensity = backup_m_fBloomDefIntensity;
|
|
|
}
|
|
|
|
|
|
public void SetEffectActive(bool active)
|
|
|
{
|
|
|
- Bloom.enabled = active;
|
|
|
if (Active = active)
|
|
|
{
|
|
|
- Bloom.bloomIntensity = Intensity;
|
|
|
+ backupBloomValue = GameMain.Instance.CMSystem.BloomValue;
|
|
|
+ GameMain.Instance.CMSystem.BloomValue = (int)BloomValue;
|
|
|
Bloom.bloomBlurIterations = BlurIterations;
|
|
|
Bloom.bloomThreshholdColor = BloomThresholdColour;
|
|
|
Bloom.hdr = BloomHDR ? Bloom.HDRBloomMode.On : Bloom.HDRBloomMode.Auto;
|
|
|
+
|
|
|
+ BloomDefIntensity = bloomDefIntensity;
|
|
|
}
|
|
|
else Reset();
|
|
|
}
|
|
|
|
|
|
- public void Update()
|
|
|
- {
|
|
|
- if (Active)
|
|
|
- {
|
|
|
- // Fuck this stupid shit
|
|
|
- // 2020/08/15 this stupid shit doesn't even work anymore
|
|
|
- // TODO: Fix this stupid shit
|
|
|
- Bloom.enabled = true;
|
|
|
- Bloom.bloomIntensity = Intensity;
|
|
|
- }
|
|
|
- }
|
|
|
+ public void Update() { }
|
|
|
}
|
|
|
}
|