using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using GraphicsAPI.CustomPostProcessing;
using GraphicsAPI.Patches;
using HarmonyLib;
using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.Rendering.HighDefinition;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("GraphicsAPI")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("GraphicsAPI")]
[assembly: AssemblyCopyright("Copyright © 2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("7521315c-659d-4e22-9c13-bd47917bc92e")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace GraphicsAPI
{
public class Content
{
public static AssetBundle MainAssets;
public static void TryLoadAssets()
{
if ((Object)(object)MainAssets == (Object)null)
{
MainAssets = AssetBundle.LoadFromFile(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "custompassasset"));
Plugin.mls.LogInfo((object)"Loaded asset bundle!");
}
}
}
public class HDRPGraphicSettings
{
private static HDRenderPipelineAsset instance;
public static RenderPipelineSettings GetCurrentSettings()
{
//IL_0047: Unknown result type (might be due to invalid IL or missing references)
//IL_004c: Unknown result type (might be due to invalid IL or missing references)
//IL_004f: Unknown result type (might be due to invalid IL or missing references)
RenderPipelineAsset renderPipeline = QualitySettings.renderPipeline;
HDRenderPipelineAsset val = (HDRenderPipelineAsset)(object)((renderPipeline is HDRenderPipelineAsset) ? renderPipeline : null);
if ((Object)(object)instance == (Object)null)
{
instance = Object.Instantiate<HDRenderPipelineAsset>(val);
}
else
{
Object.Destroy((Object)(object)instance);
instance = Object.Instantiate<HDRenderPipelineAsset>(val);
}
return instance.currentPlatformRenderPipelineSettings;
}
public static void ApplySettings(RenderPipelineSettings newSettings)
{
//IL_003d: Unknown result type (might be due to invalid IL or missing references)
//IL_0042: Unknown result type (might be due to invalid IL or missing references)
//IL_0043: Unknown result type (might be due to invalid IL or missing references)
//IL_0044: Unknown result type (might be due to invalid IL or missing references)
//IL_0046: Unknown result type (might be due to invalid IL or missing references)
List<HDRenderPipelineAsset> list = new List<HDRenderPipelineAsset>();
RenderPipelineAsset renderPipeline = QualitySettings.renderPipeline;
list.Add((HDRenderPipelineAsset)(object)((renderPipeline is HDRenderPipelineAsset) ? renderPipeline : null));
RenderPipelineAsset currentRenderPipeline = GraphicsSettings.currentRenderPipeline;
list.Add((HDRenderPipelineAsset)(object)((currentRenderPipeline is HDRenderPipelineAsset) ? currentRenderPipeline : null));
foreach (HDRenderPipelineAsset item in list)
{
RenderPipelineSettings currentPlatformRenderPipelineSettings = item.currentPlatformRenderPipelineSettings;
currentPlatformRenderPipelineSettings = newSettings;
item.currentPlatformRenderPipelineSettings = currentPlatformRenderPipelineSettings;
}
}
}
[BepInPlugin("Chaos.GraphicsAPI", "GraphicsAPI", "1.0.0")]
public class Plugin : BaseUnityPlugin
{
private const string modGUID = "Chaos.GraphicsAPI";
private const string modName = "GraphicsAPI";
private const string modVersion = "1.0.0";
private readonly Harmony harmony = new Harmony("Chaos.GraphicsAPI");
public static Plugin Instance;
public static ManualLogSource mls;
private void Awake()
{
if ((Object)(object)Instance == (Object)null)
{
Instance = this;
}
mls = ((BaseUnityPlugin)this).Logger;
Content.TryLoadAssets();
harmony.PatchAll(typeof(HUDManagerPatch));
mls.LogInfo((object)"GraphicsAPI started.");
}
}
}
namespace GraphicsAPI.Patches
{
[HarmonyPatch(typeof(HUDManager))]
public class HUDManagerPatch
{
[HarmonyPatch(typeof(HUDManager), "Awake")]
[HarmonyPrefix]
private static void Awake(ref HUDManager __instance)
{
CustomPostProcessingManager component = ((Component)__instance).gameObject.GetComponent<CustomPostProcessingManager>();
if (!Object.op_Implicit((Object)(object)component))
{
((Component)__instance).gameObject.AddComponent<CustomPostProcessingManager>();
}
}
}
}
namespace GraphicsAPI.CustomPostProcessing
{
public class CustomPostProcessingManager : MonoBehaviour
{
private GameObject go;
private List<FullScreenCustomPass> _customFSPasses = new List<FullScreenCustomPass>();
private Material fetchColor;
public Material dither;
public Material screenShake;
public static CustomPostProcessingManager Instance { get; private set; }
public static bool Initialized { get; private set; }
public IList<FullScreenCustomPass> CustomFSPasses => _customFSPasses.AsReadOnly();
public static event EventHandler OnLoad;
private void Awake()
{
if ((Object)(object)Instance == (Object)null)
{
Instance = this;
Initialized = false;
}
else
{
Object.Destroy((Object)(object)((Component)Instance).gameObject);
Instance = this;
Initialized = false;
}
}
private void Start()
{
Init();
}
private void Init()
{
//IL_008b: Unknown result type (might be due to invalid IL or missing references)
//IL_0091: Expected O, but got Unknown
//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
//IL_00b6: Expected O, but got Unknown
//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
//IL_00de: Unknown result type (might be due to invalid IL or missing references)
//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
if (!Initialized)
{
fetchColor = Content.MainAssets.LoadAsset<Material>("Assets/Custom/Materials/FetchColor.mat");
dither = Content.MainAssets.LoadAsset<Material>("Assets/Custom/Materials/Dither.mat");
screenShake = Content.MainAssets.LoadAsset<Material>("Assets/Custom/Materials/Shake.mat");
((MonoBehaviour)this).StartCoroutine(SetCamera());
go = GameObject.Find("Systems/Rendering/CustomPass");
if (Object.op_Implicit((Object)(object)go))
{
GameObject val = new GameObject("FetchColorPass");
val.transform.SetParent(go.transform, false);
CustomPassVolume val2 = val.AddComponent<CustomPassVolume>();
FullScreenCustomPass val3 = new FullScreenCustomPass();
((CustomPass)val3).name = "FetchColorPass";
val3.fetchColorBuffer = true;
val3.fullscreenPassMaterial = fetchColor;
((CustomPass)val3).targetColorBuffer = (TargetBuffer)1;
((CustomPass)val3).targetDepthBuffer = (TargetBuffer)1;
val2.injectionPoint = (CustomPassInjectionPoint)3;
val2.priority = 1f;
val2.customPasses.Add((CustomPass)(object)val3);
val2.isGlobal = true;
Plugin.mls.LogInfo((object)"Custom Post Processing Manager initialized!");
}
}
else
{
Plugin.mls.LogWarning((object)"Tried to initialize Custom Post Processing Manager when already initialized!");
}
}
private IEnumerator SetCamera()
{
yield return (object)new WaitUntil((Func<bool>)(() => (Object)(object)StartOfRound.Instance != (Object)null && (Object)(object)StartOfRound.Instance.localPlayerController != (Object)null));
Initialized = true;
CustomPostProcessingManager.OnLoad?.Invoke(this, EventArgs.Empty);
}
public FullScreenCustomPass AddPostProcess(PostProcess post)
{
//IL_001b: Unknown result type (might be due to invalid IL or missing references)
//IL_0022: Expected O, but got Unknown
//IL_0099: Unknown result type (might be due to invalid IL or missing references)
//IL_009f: Expected O, but got Unknown
//IL_00be: Unknown result type (might be due to invalid IL or missing references)
//IL_00c4: Expected O, but got Unknown
//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
//IL_00de: Unknown result type (might be due to invalid IL or missing references)
//IL_010f: Unknown result type (might be due to invalid IL or missing references)
//IL_0114: Unknown result type (might be due to invalid IL or missing references)
//IL_0121: Unknown result type (might be due to invalid IL or missing references)
//IL_0126: Unknown result type (might be due to invalid IL or missing references)
//IL_013f: Unknown result type (might be due to invalid IL or missing references)
//IL_0144: Unknown result type (might be due to invalid IL or missing references)
foreach (Transform item in go.transform)
{
Transform val = item;
if (((Object)((Component)val).gameObject).name.ToLower() == post.Name.ToLower())
{
Plugin.mls.LogWarning((object)("There's already a PostProcess of name '" + post.Name + "' added!"));
return null;
}
}
GameObject val2 = new GameObject(post.Name);
val2.transform.SetParent(go.transform, false);
CustomPassVolume val3 = val2.AddComponent<CustomPassVolume>();
FullScreenCustomPass val4 = new FullScreenCustomPass();
((CustomPass)val4).name = post.Name;
((CustomPass)val4).clearFlags = CheckFlag(post.ClearFlags);
val4.fetchColorBuffer = post.FetchColorBuffer;
val4.fullscreenPassMaterial = post.FullScreenMaterial;
val4.materialPassName = post.MaterialPassName;
((CustomPass)val4).targetColorBuffer = CheckTarget(post.TargetColorType);
((CustomPass)val4).targetDepthBuffer = CheckTarget(post.TargetDepthType);
((CustomPass)val4).enabled = post.Enabled;
val3.injectionPoint = CheckInjection(post.InjectionType);
val3.priority = post.Priority;
val3.customPasses.Add((CustomPass)(object)val4);
val3.isGlobal = true;
_customFSPasses.Add(val4);
Plugin.mls.LogMessage((object)("Added '" + post.Name + "' to the custom passes!"));
return val4;
}
public FullScreenCustomPass GetPass(string name)
{
FullScreenCustomPass val = _customFSPasses.Find((FullScreenCustomPass x) => ((CustomPass)x).name.ToLower() == name.ToLower());
if (val != null)
{
return val;
}
Plugin.mls.LogWarning((object)("Couldn't find pass of name '" + name + "'!"));
return null;
}
public void EnablePass(FullScreenCustomPass fsPass)
{
if (fsPass == null)
{
Plugin.mls.LogError((object)"The given pass is null!");
return;
}
FullScreenCustomPass val = _customFSPasses.Find((FullScreenCustomPass x) => x == fsPass);
if (val != null)
{
if (!((CustomPass)val).enabled)
{
((CustomPass)val).enabled = true;
}
}
else
{
Plugin.mls.LogWarning((object)("Couldn't find pass of name '" + ((Object)this).name + "'!"));
}
}
public void DisablePass(FullScreenCustomPass fsPass)
{
if (fsPass == null)
{
Plugin.mls.LogError((object)"The given pass is null!");
return;
}
FullScreenCustomPass val = _customFSPasses.Find((FullScreenCustomPass x) => x == fsPass);
if (val != null)
{
if (((CustomPass)val).enabled)
{
((CustomPass)val).enabled = false;
}
}
else
{
Plugin.mls.LogWarning((object)("Couldn't find pass of name '" + ((Object)this).name + "'!"));
}
}
private ClearFlag CheckFlag(ClearFlagsType type)
{
//IL_000a: Unknown result type (might be due to invalid IL or missing references)
//IL_0016: Unknown result type (might be due to invalid IL or missing references)
//IL_0037: Unknown result type (might be due to invalid IL or missing references)
//IL_0022: Unknown result type (might be due to invalid IL or missing references)
//IL_0034: Unknown result type (might be due to invalid IL or missing references)
//IL_0030: Unknown result type (might be due to invalid IL or missing references)
return (ClearFlag)(type switch
{
ClearFlagsType.None => 0,
ClearFlagsType.Color => 1,
ClearFlagsType.Depth => 2,
ClearFlagsType.All => 7,
_ => 0,
});
}
private TargetBuffer CheckTarget(TargetType type)
{
//IL_000a: Unknown result type (might be due to invalid IL or missing references)
//IL_0016: Unknown result type (might be due to invalid IL or missing references)
//IL_0029: Unknown result type (might be due to invalid IL or missing references)
//IL_0026: Unknown result type (might be due to invalid IL or missing references)
//IL_0022: Unknown result type (might be due to invalid IL or missing references)
return (TargetBuffer)(type switch
{
TargetType.None => 2,
TargetType.Camera => 0,
TargetType.Custom => 1,
_ => 0,
});
}
private CustomPassInjectionPoint CheckInjection(InjectionType type)
{
//IL_000a: Unknown result type (might be due to invalid IL or missing references)
//IL_0016: Unknown result type (might be due to invalid IL or missing references)
//IL_0061: Unknown result type (might be due to invalid IL or missing references)
//IL_0022: Unknown result type (might be due to invalid IL or missing references)
//IL_0030: Unknown result type (might be due to invalid IL or missing references)
//IL_003e: Unknown result type (might be due to invalid IL or missing references)
//IL_004c: Unknown result type (might be due to invalid IL or missing references)
//IL_005e: Unknown result type (might be due to invalid IL or missing references)
//IL_005a: Unknown result type (might be due to invalid IL or missing references)
return (CustomPassInjectionPoint)(type switch
{
InjectionType.AfterOpaqueAndSky => 6,
InjectionType.AfterOpaqueDepthAndNormal => 5,
InjectionType.AfterPostProcess => 3,
InjectionType.BeforePostProcess => 2,
InjectionType.BeforePreRefraction => 4,
InjectionType.BeforeRendering => 0,
InjectionType.BeforeTransparent => 1,
_ => 1,
});
}
}
public enum ClearFlagsType
{
None,
Color,
Depth,
All
}
public enum InjectionType
{
BeforeRendering,
AfterOpaqueDepthAndNormal,
AfterOpaqueAndSky,
BeforePreRefraction,
BeforeTransparent,
BeforePostProcess,
AfterPostProcess
}
public enum TargetType
{
Camera,
Custom,
None
}
public class PostProcess
{
public string Name { get; private set; }
public Material FullScreenMaterial { get; private set; }
public InjectionType InjectionType { get; set; } = InjectionType.BeforeTransparent;
public TargetType TargetColorType { get; set; } = TargetType.Camera;
public TargetType TargetDepthType { get; set; } = TargetType.Camera;
public ClearFlagsType ClearFlags { get; set; } = ClearFlagsType.None;
public bool FetchColorBuffer { get; set; } = false;
public float Priority { get; set; } = 0f;
public bool Enabled { get; set; } = true;
public string MaterialPassName { get; set; } = "DrawProcedural";
public PostProcess(string passName, Material material)
{
Name = passName;
FullScreenMaterial = material;
}
}
}