Please disclose if any significant portion of your mod was created using AI tools by adding the 'AI Generated' category. Failing to do so may result in the mod being removed from Thunderstore.
Decompiled source of LethalSpongeLegacy v1.0.0
LethalSpongeLegacy/LethalSpongeLegacy.dll
Decompiled 6 months agousing System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Reflection; using System.Reflection.Emit; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; using System.Text; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using GameNetcodeStuff; using HarmonyLib; using Microsoft.CodeAnalysis; using Scoops; using Scoops.patches; using Scoops.rendering; using Scoops.service; using Sponge.Utilities.IL; using Unity.Netcode; using UnityEngine; using UnityEngine.Experimental.Rendering; 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: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: IgnoresAccessChecksTo("Assembly-CSharp")] [assembly: IgnoresAccessChecksTo("Unity.InputSystem")] [assembly: IgnoresAccessChecksTo("Unity.Netcode.Runtime")] [assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.Core.Runtime")] [assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.HighDefinition.Runtime")] [assembly: AssemblyCompany("LethalSpongeLegacy")] [assembly: AssemblyConfiguration("Debug")] [assembly: AssemblyFileVersion("0.0.0.0")] [assembly: AssemblyInformationalVersion("0.0.0-alpha.0.58+5d066a3b176347077dc30d4cec1106211489197e")] [assembly: AssemblyProduct("LethalSpongeLegacy")] [assembly: AssemblyTitle("LethalSpongeLegacy")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("0.0.0.0")] [module: UnverifiableCode] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] [AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } namespace Sponge.Utilities.IL { public class ILInjector { [CompilerGenerated] private sealed class <GetRelativeInstructions>d__32 : IEnumerable<CodeInstruction>, IEnumerable, IEnumerator<CodeInstruction>, IEnumerator, IDisposable { private int <>1__state; private CodeInstruction <>2__current; private int <>l__initialThreadId; private int offset; public int <>3__offset; private int size; public int <>3__size; public ILInjector <>4__this; private int <i>5__1; CodeInstruction IEnumerator<CodeInstruction>.Current { [DebuggerHidden] get { return <>2__current; } } object IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } [DebuggerHidden] public <GetRelativeInstructions>d__32(int <>1__state) { this.<>1__state = <>1__state; <>l__initialThreadId = Environment.CurrentManagedThreadId; } [DebuggerHidden] void IDisposable.Dispose() { <>1__state = -2; } private bool MoveNext() { switch (<>1__state) { default: return false; case 0: <>1__state = -1; <i>5__1 = 0; break; case 1: <>1__state = -1; <i>5__1++; break; } if (<i>5__1 < size) { <>2__current = <>4__this.instructions[<>4__this.index + offset + <i>5__1]; <>1__state = 1; return true; } return false; } bool IEnumerator.MoveNext() { //ILSpy generated this explicit interface implementation from .override directive in MoveNext return this.MoveNext(); } [DebuggerHidden] void IEnumerator.Reset() { throw new NotSupportedException(); } [DebuggerHidden] IEnumerator<CodeInstruction> IEnumerable<CodeInstruction>.GetEnumerator() { <GetRelativeInstructions>d__32 <GetRelativeInstructions>d__; if (<>1__state == -2 && <>l__initialThreadId == Environment.CurrentManagedThreadId) { <>1__state = 0; <GetRelativeInstructions>d__ = this; } else { <GetRelativeInstructions>d__ = new <GetRelativeInstructions>d__32(0) { <>4__this = <>4__this }; } <GetRelativeInstructions>d__.offset = <>3__offset; <GetRelativeInstructions>d__.size = <>3__size; return <GetRelativeInstructions>d__; } [DebuggerHidden] IEnumerator IEnumerable.GetEnumerator() { return ((IEnumerable<CodeInstruction>)this).GetEnumerator(); } } private const string INVALID = "Injector is invalid"; private const string MATCH_END_INVALID = "The end of the last search was invalid"; private List<CodeInstruction> instructions = instructions.ToList(); private ILGenerator generator; private int index; private int matchEnd; public bool IsValid => instructions != null && IsIndexValid(index); public CodeInstruction Instruction { get { if (!IsIndexInRange(index)) { return null; } return instructions[index]; } set { if (!IsIndexInRange(index)) { throw new InvalidOperationException($"Current index {index} is out of range of instruction count {instructions.Count}"); } instructions[index] = value; } } public CodeInstruction LastMatchedInstruction { get { int num = matchEnd - 1; if (!IsIndexInRange(num)) { return null; } return instructions[num]; } set { int num = matchEnd - 1; if (!IsIndexInRange(num)) { throw new InvalidOperationException($"Last matched index {index} is out of range of instruction count {instructions.Count}"); } instructions[num] = value; } } public ICollection<CodeInstruction> Instructions => instructions.AsReadOnly(); public ILInjector(IEnumerable<CodeInstruction> instructions, ILGenerator generator = null) { this.generator = generator; index = 0; matchEnd = -1; base..ctor(); } public ILInjector GoToStart() { matchEnd = index; index = 0; return this; } public ILInjector GoToEnd() { matchEnd = index; index = instructions.Count; return this; } public ILInjector Forward(int offset) { if (!IsValid) { return this; } matchEnd = index; index = Math.Clamp(index + offset, -1, instructions.Count); return this; } public ILInjector Back(int offset) { return Forward(-offset); } private void MarkInvalid() { index = -1; matchEnd = -1; } private void Search(bool forward, ILMatcher[] predicates) { if (!IsValid) { return; } int num = 1; if (!forward) { num = -1; index--; } while (forward ? (index < instructions.Count) : (index >= 0)) { if (forward && index + predicates.Length > instructions.Count) { index = instructions.Count; break; } int i; for (i = 0; i < predicates.Length && predicates[i].Matches(instructions[index + i]); i++) { } if (i == predicates.Length) { matchEnd = index + i; return; } index += num; } MarkInvalid(); } public ILInjector Find(params ILMatcher[] predicates) { Search(forward: true, predicates); return this; } public ILInjector ReverseFind(params ILMatcher[] predicates) { Search(forward: false, predicates); return this; } public ILInjector GoToPush(int popIndex) { if (!IsValid) { return this; } matchEnd = index; index--; int num = 0; while (index >= 0) { CodeInstruction instruction = instructions[index]; num += instruction.PushCount(); num -= instruction.PopCount(); if (num > popIndex) { return this; } index--; } return this; } public ILInjector SkipBranch() { if (Instruction == null) { return this; } if (!(Instruction.operand is Label label) || 1 == 0) { throw new InvalidOperationException($"Current instruction is not a branch: {Instruction}"); } return FindLabel(label); } public ILInjector FindLabel(Label label) { matchEnd = index + 1; for (index = 0; index < instructions.Count; index++) { if (instructions[index].labels.Contains(label)) { return this; } } MarkInvalid(); return this; } public ILInjector GoToMatchEnd() { index = matchEnd; return this; } public ILInjector GoToLastMatchedInstruction() { if (!IsIndexValid(matchEnd)) { return this; } index = matchEnd - 1; return this; } private bool IsIndexValid(int index) { return index != -1; } private bool IsIndexInRange(int index) { return index >= 0 && index < instructions.Count; } public CodeInstruction GetRelativeInstruction(int offset) { if (!IsValid) { throw new InvalidOperationException("Injector is invalid"); } int num = index + offset; if (!IsIndexInRange(num)) { throw new IndexOutOfRangeException($"Offset {offset} would read out of bounds at index {num}"); } return instructions[num]; } public void SetRelativeInstruction(int offset, CodeInstruction instruction) { if (!IsValid) { throw new InvalidOperationException("Injector is invalid"); } int num = index + offset; if (!IsIndexInRange(num)) { throw new IndexOutOfRangeException($"Offset {offset} would write out of bounds at index {num}"); } instructions[num] = instruction; } [IteratorStateMachine(typeof(<GetRelativeInstructions>d__32))] public IEnumerable<CodeInstruction> GetRelativeInstructions(int offset, int size) { //yield-return decompiler failed: Unexpected instruction in Iterator.Dispose() return new <GetRelativeInstructions>d__32(-2) { <>4__this = this, <>3__offset = offset, <>3__size = size }; } public IEnumerable<CodeInstruction> GetRelativeInstructions(int size) { return GetRelativeInstructions(0, size); } private void GetLastMatchRangeAbsolute(out int start, out int end) { start = index; end = matchEnd; if (start > end) { int num = end; int num2 = start; start = num; end = num2; } } private void GetLastMatchRange(out int start, out int size) { GetLastMatchRangeAbsolute(out start, out var end); if (start < 0 || start >= instructions.Count) { throw new InvalidOperationException($"Last match range starts at invalid index {start}"); } if (end < 0 || end > instructions.Count) { throw new InvalidOperationException($"Last match range ends at invalid index {end}"); } size = end - start; } public List<CodeInstruction> GetLastMatch() { GetLastMatchRange(out var start, out var size); return instructions.GetRange(start, size); } public Label AddLabel() { if (generator == null) { throw new InvalidOperationException("No ILGenerator was provided"); } Label label = generator.DefineLabel(); Instruction.labels.Add(label); return label; } public ILInjector AddLabel(Label label) { Instruction.labels.Add(label); return this; } public ILInjector InsertInPlace(params CodeInstruction[] instructions) { if (!IsValid) { throw new InvalidOperationException("Injector is invalid"); } this.instructions.InsertRange(index, instructions); if (matchEnd >= index) { matchEnd += instructions.Length; } return this; } public ILInjector Insert(params CodeInstruction[] instructions) { InsertInPlace(instructions); index += instructions.Length; return this; } public ILInjector InsertInPlaceAfterBranch(params CodeInstruction[] instructions) { if (!IsValid) { throw new InvalidOperationException("Injector is invalid"); } List<Label> labels = Instruction.labels; this.instructions.InsertRange(index, instructions); Instruction.labels.AddRange(labels); labels.Clear(); if (matchEnd >= index) { matchEnd += instructions.Length; } return this; } public ILInjector InsertAfterBranch(params CodeInstruction[] instructions) { InsertInPlaceAfterBranch(instructions); index += instructions.Length; return this; } public ILInjector RemoveAllPreviousInstructions() { if (!IsValid) { throw new InvalidOperationException("Injector is invalid"); } instructions.RemoveRange(0, index); matchEnd -= index; if (matchEnd < 0) { matchEnd = 0; } index = 0; return this; } public ILInjector Remove(int count = 1) { if (!IsValid) { throw new InvalidOperationException("Injector is invalid"); } instructions.RemoveRange(index, count); if (matchEnd > index) { matchEnd = Math.Max(index, matchEnd - count); } return this; } public ILInjector RemoveLastMatch() { GetLastMatchRange(out var start, out var size); instructions.RemoveRange(start, size); index = start; matchEnd = start; return this; } public ILInjector ReplaceLastMatch(params CodeInstruction[] instructions) { RemoveLastMatch(); Insert(instructions); return this; } public List<CodeInstruction> ReleaseInstructions() { List<CodeInstruction> result = instructions; instructions = null; return result; } public ILInjector PrintContext(int context, string header = "") { if (!IsValid) { throw new InvalidOperationException("Injector is invalid (" + header + ")"); } StringBuilder stringBuilder = new StringBuilder(header); if (header.Length > 0) { stringBuilder.Append(':'); } stringBuilder.AppendLine(); GetLastMatchRangeAbsolute(out var start, out var end); int num = Math.Min(end + 1 + context, instructions.Count); for (int i = Math.Max(start - context, 0); i < num; i++) { if (end == -1 && i == index) { stringBuilder.Append("╶> "); } else { if (i >= start && i < end) { stringBuilder.Append("│"); } else { stringBuilder.Append(" "); } if (i == index) { stringBuilder.Append("╶> "); } else { stringBuilder.Append(" "); } } stringBuilder.AppendLine($"{i}: {instructions[i]}"); } Plugin.Log.LogInfo((object)stringBuilder); return this; } public ILInjector PrintContext(string header = "") { return PrintContext(4, header); } } public interface ILMatcher { private static OpCode[] branchInstructions = new OpCode[4] { OpCodes.Br, OpCodes.Br_S, OpCodes.Brfalse, OpCodes.Brfalse_S }; bool Matches(CodeInstruction instruction); static NotMatcher Not(ILMatcher matcher) { return new NotMatcher(matcher); } static OpcodeMatcher Opcode(OpCode opcode) { return new OpcodeMatcher(opcode); } static OpcodesMatcher Opcodes(params OpCode[] opcodes) { return new OpcodesMatcher(opcodes); } static OpcodeOperandMatcher OpcodeOperand(OpCode opcode, object operand) { return new OpcodeOperandMatcher(opcode, operand); } static InstructionMatcher Instruction(CodeInstruction instruction) { return new InstructionMatcher(instruction); } static LdargMatcher Ldarg(int? arg = null) { return new LdargMatcher(arg); } static LdlocMatcher Ldloc(int? loc = null) { return new LdlocMatcher(loc); } static StlocMatcher Stloc(int? loc = null) { return new StlocMatcher(loc); } static LdcI32Matcher Ldc(int? value = null) { return new LdcI32Matcher(value); } static BranchMatcher Branch() { return new BranchMatcher(); } static OpcodeOperandMatcher Ldfld(FieldInfo field) { if (field == null) { Plugin.Log.LogWarning((object)$"Field passed to ILMatcher.Ldfld() was null\n{new StackTrace()}"); } return new OpcodeOperandMatcher(OpCodes.Ldfld, field); } static OpcodeOperandMatcher Ldsfld(FieldInfo field) { if (field == null) { Plugin.Log.LogWarning((object)$"Field passed to ILMatcher.Ldsfld() was null\n{new StackTrace()}"); } return new OpcodeOperandMatcher(OpCodes.Ldsfld, field); } static OpcodeOperandMatcher Stfld(FieldInfo field) { if (field == null) { Plugin.Log.LogWarning((object)$"Field passed to ILMatcher.Stfld() was null\n{new StackTrace()}"); } return new OpcodeOperandMatcher(OpCodes.Stfld, field); } static OpcodeOperandMatcher Stsfld(FieldInfo field) { if (field == null) { Plugin.Log.LogWarning((object)$"Field passed to ILMatcher.Stsfld() was null\n{new StackTrace()}"); } return new OpcodeOperandMatcher(OpCodes.Stsfld, field); } static OpcodeOperandMatcher Callvirt(MethodBase method) { if (method == null) { Plugin.Log.LogWarning((object)$"Method passed to ILMatcher.Callvirt() was null\n{new StackTrace()}"); } return OpcodeOperand(OpCodes.Callvirt, method); } static OpcodeOperandMatcher Call(MethodBase method) { if (method == null) { Plugin.Log.LogWarning((object)$"Method passed to ILMatcher.Call() was null\n{new StackTrace()}"); } return OpcodeOperand(OpCodes.Call, method); } static PredicateMatcher Predicate(Func<CodeInstruction, bool> predicate) { return new PredicateMatcher(predicate); } static PredicateMatcher Predicate(Func<FieldInfo, bool> predicate) { return new PredicateMatcher((CodeInstruction insn) => insn.operand is FieldInfo arg && predicate(arg)); } } public class NotMatcher : ILMatcher { private readonly ILMatcher matcher; public NotMatcher(ILMatcher matcher) { this.matcher = matcher; base..ctor(); } public bool Matches(CodeInstruction instruction) { return !matcher.Matches(instruction); } } public class OpcodeMatcher : ILMatcher { private readonly OpCode opcode; public OpcodeMatcher(OpCode opcode) { this.opcode = opcode; base..ctor(); } public bool Matches(CodeInstruction instruction) { return instruction.opcode == opcode; } } public class OpcodesMatcher : ILMatcher { private readonly OpCode[] opcodes; public OpcodesMatcher(OpCode[] opcodes) { this.opcodes = opcodes; base..ctor(); } public bool Matches(CodeInstruction instruction) { return opcodes.Contains(instruction.opcode); } } public class OpcodeOperandMatcher : ILMatcher { private readonly OpCode opcode; private readonly object operand; public OpcodeOperandMatcher(OpCode opcode, object operand) { this.opcode = opcode; this.operand = operand; base..ctor(); } public bool Matches(CodeInstruction instruction) { return instruction.opcode == opcode && instruction.operand == operand; } } public class InstructionMatcher : ILMatcher { private readonly OpCode opcode = instruction.opcode; private readonly object operand = instruction.operand; private readonly Label[] labels = instruction.labels.ToArray(); public InstructionMatcher(CodeInstruction instruction) { } public bool Matches(CodeInstruction instruction) { if (instruction.opcode != opcode) { return false; } if (instruction.operand != operand) { return false; } if (instruction.labels.Count != labels.Length) { return false; } for (int i = 0; i < labels.Length; i++) { if (labels[i] != instruction.labels[i]) { return false; } } return true; } } public class LdargMatcher : ILMatcher { private readonly int? arg; public LdargMatcher(int? arg) { this.arg = arg; base..ctor(); } public bool Matches(CodeInstruction instruction) { return arg.HasValue ? (instruction.GetLdargIndex() == arg) : instruction.GetLdargIndex().HasValue; } } public class LdlocMatcher : ILMatcher { private readonly int? loc; public LdlocMatcher(int? loc) { this.loc = loc; base..ctor(); } public bool Matches(CodeInstruction instruction) { return loc.HasValue ? (instruction.GetLdlocIndex() == loc) : instruction.GetLdlocIndex().HasValue; } } public class StlocMatcher : ILMatcher { private readonly int? loc; public StlocMatcher(int? loc) { this.loc = loc; base..ctor(); } public bool Matches(CodeInstruction instruction) { return loc.HasValue ? (instruction.GetStlocIndex() == loc) : instruction.GetStlocIndex().HasValue; } } public class LdcI32Matcher : ILMatcher { private readonly int? value; public LdcI32Matcher(int? value) { this.value = value; base..ctor(); } public bool Matches(CodeInstruction instruction) { return (!value.HasValue && instruction.GetLdcI32().HasValue) || instruction.GetLdcI32() == value; } } public class BranchMatcher : ILMatcher { public bool Matches(CodeInstruction instruction) { Label? label = default(Label?); return CodeInstructionExtensions.Branches(instruction, ref label); } } public class PredicateMatcher : ILMatcher { private readonly Func<CodeInstruction, bool> predicate; public PredicateMatcher(Func<CodeInstruction, bool> predicate) { this.predicate = predicate; base..ctor(); } public bool Matches(CodeInstruction instruction) { return predicate(instruction); } } internal static class InstructionUtilities { public static CodeInstruction MakeLdarg(int index) { //IL_007b: Unknown result type (might be due to invalid IL or missing references) //IL_0081: Expected O, but got Unknown //IL_002b: Unknown result type (might be due to invalid IL or missing references) //IL_0031: Expected O, but got Unknown //IL_0039: Unknown result type (might be due to invalid IL or missing references) //IL_003f: Expected O, but got Unknown //IL_0047: Unknown result type (might be due to invalid IL or missing references) //IL_004d: Expected O, but got Unknown //IL_0055: Unknown result type (might be due to invalid IL or missing references) //IL_005b: Expected O, but got Unknown //IL_0068: Unknown result type (might be due to invalid IL or missing references) //IL_006e: Expected O, but got Unknown if (1 == 0) { } CodeInstruction result = (CodeInstruction)((index >= 256) ? ((object)new CodeInstruction(OpCodes.Ldarg, (object)index)) : (index switch { 0 => (object)new CodeInstruction(OpCodes.Ldarg_0, (object)null), 1 => (object)new CodeInstruction(OpCodes.Ldarg_1, (object)null), 2 => (object)new CodeInstruction(OpCodes.Ldarg_2, (object)null), 3 => (object)new CodeInstruction(OpCodes.Ldarg_3, (object)null), _ => (object)new CodeInstruction(OpCodes.Ldarg_S, (object)index), })); if (1 == 0) { } return result; } public static int PopCount(this CodeInstruction instruction) { if (instruction.opcode == OpCodes.Call || instruction.opcode == OpCodes.Callvirt) { MethodInfo methodInfo = (MethodInfo)instruction.operand; int num = methodInfo.GetParameters().Length; if (!methodInfo.IsStatic) { num++; } return num; } if (instruction.opcode == OpCodes.Ret) { return 1; } StackBehaviour stackBehaviourPop = instruction.opcode.StackBehaviourPop; if (1 == 0) { } int result = stackBehaviourPop switch { StackBehaviour.Pop0 => 0, StackBehaviour.Pop1 => 1, StackBehaviour.Pop1_pop1 => 2, StackBehaviour.Popi => 1, StackBehaviour.Popi_pop1 => 2, StackBehaviour.Popi_popi => 2, StackBehaviour.Popi_popi8 => 2, StackBehaviour.Popi_popi_popi => 3, StackBehaviour.Popi_popr4 => 2, StackBehaviour.Popi_popr8 => 2, StackBehaviour.Popref => 1, StackBehaviour.Popref_pop1 => 2, StackBehaviour.Popref_popi => 2, StackBehaviour.Popref_popi_popi => 3, StackBehaviour.Popref_popi_popi8 => 3, StackBehaviour.Popref_popi_popr4 => 3, StackBehaviour.Popref_popi_popr8 => 3, StackBehaviour.Popref_popi_popref => 3, StackBehaviour.Varpop => throw new NotImplementedException($"Variable pop on non-call instruction '{instruction}'"), StackBehaviour.Popref_popi_pop1 => 3, _ => throw new NotSupportedException($"StackBehaviourPop of {instruction.opcode.StackBehaviourPop} was not a pop for instruction '{instruction}'"), }; if (1 == 0) { } return result; } public static int PushCount(this CodeInstruction instruction) { if (instruction.opcode == OpCodes.Call || instruction.opcode == OpCodes.Callvirt) { MethodInfo methodInfo = (MethodInfo)instruction.operand; if (methodInfo.ReturnType == typeof(void)) { return 0; } return 1; } StackBehaviour stackBehaviourPush = instruction.opcode.StackBehaviourPush; if (1 == 0) { } int result = stackBehaviourPush switch { StackBehaviour.Push0 => 0, StackBehaviour.Push1 => 1, StackBehaviour.Push1_push1 => 2, StackBehaviour.Pushi => 1, StackBehaviour.Pushi8 => 1, StackBehaviour.Pushr4 => 1, StackBehaviour.Pushr8 => 1, StackBehaviour.Pushref => 1, StackBehaviour.Varpush => throw new NotImplementedException($"Variable push on non-call instruction '{instruction}'"), _ => throw new NotSupportedException($"StackBehaviourPush of {instruction.opcode.StackBehaviourPush} was not a push for instruction '{instruction}'"), }; if (1 == 0) { } return result; } public static int? GetLdargIndex(this CodeInstruction instruction) { OpCode opcode = instruction.opcode; if (opcode == OpCodes.Ldarg_0) { return 0; } if (opcode == OpCodes.Ldarg_1) { return 1; } if (opcode == OpCodes.Ldarg_2) { return 2; } if (opcode == OpCodes.Ldarg_3) { return 3; } if (opcode == OpCodes.Ldarg || opcode == OpCodes.Ldarg_S) { return instruction.operand as int?; } return null; } public static int? GetLdlocIndex(this CodeInstruction instruction) { OpCode opcode = instruction.opcode; if (opcode == OpCodes.Ldloc_0) { return 0; } if (opcode == OpCodes.Ldloc_1) { return 1; } if (opcode == OpCodes.Ldloc_2) { return 2; } if (opcode == OpCodes.Ldloc_3) { return 3; } if (opcode == OpCodes.Ldloc || opcode == OpCodes.Ldloc_S) { return (instruction.operand as LocalBuilder)?.LocalIndex; } return null; } public static int? GetStlocIndex(this CodeInstruction instruction) { OpCode opcode = instruction.opcode; if (opcode == OpCodes.Stloc_0) { return 0; } if (opcode == OpCodes.Stloc_1) { return 1; } if (opcode == OpCodes.Stloc_2) { return 2; } if (opcode == OpCodes.Stloc_3) { return 3; } if (opcode == OpCodes.Stloc || opcode == OpCodes.Stloc_S) { return (instruction.operand as LocalBuilder)?.LocalIndex; } return null; } public static CodeInstruction LdlocToStloc(this CodeInstruction instruction) { //IL_001d: Unknown result type (might be due to invalid IL or missing references) //IL_0023: Expected O, but got Unknown //IL_003d: Unknown result type (might be due to invalid IL or missing references) //IL_0043: Expected O, but got Unknown //IL_005c: Unknown result type (might be due to invalid IL or missing references) //IL_0062: Expected O, but got Unknown //IL_007b: Unknown result type (might be due to invalid IL or missing references) //IL_0081: Expected O, but got Unknown //IL_00af: Unknown result type (might be due to invalid IL or missing references) //IL_00b5: Expected O, but got Unknown OpCode opcode = instruction.opcode; if (opcode == OpCodes.Ldloc_0) { return new CodeInstruction(OpCodes.Stloc_0, (object)null); } if (opcode == OpCodes.Ldloc_1) { return new CodeInstruction(OpCodes.Stloc_1, (object)null); } if (opcode == OpCodes.Ldloc_2) { return new CodeInstruction(OpCodes.Stloc_2, (object)null); } if (opcode == OpCodes.Ldloc_3) { return new CodeInstruction(OpCodes.Stloc_3, (object)null); } if (opcode == OpCodes.Ldloc || opcode == OpCodes.Ldloc_S) { return new CodeInstruction(OpCodes.Stloc, instruction.operand); } return null; } public static CodeInstruction StlocToLdloc(this CodeInstruction instruction) { //IL_001d: Unknown result type (might be due to invalid IL or missing references) //IL_0023: Expected O, but got Unknown //IL_003d: Unknown result type (might be due to invalid IL or missing references) //IL_0043: Expected O, but got Unknown //IL_005c: Unknown result type (might be due to invalid IL or missing references) //IL_0062: Expected O, but got Unknown //IL_007b: Unknown result type (might be due to invalid IL or missing references) //IL_0081: Expected O, but got Unknown //IL_00af: Unknown result type (might be due to invalid IL or missing references) //IL_00b5: Expected O, but got Unknown OpCode opcode = instruction.opcode; if (opcode == OpCodes.Stloc_0) { return new CodeInstruction(OpCodes.Ldloc_0, (object)null); } if (opcode == OpCodes.Stloc_1) { return new CodeInstruction(OpCodes.Ldloc_1, (object)null); } if (opcode == OpCodes.Stloc_2) { return new CodeInstruction(OpCodes.Ldloc_2, (object)null); } if (opcode == OpCodes.Stloc_3) { return new CodeInstruction(OpCodes.Ldloc_3, (object)null); } if (opcode == OpCodes.Stloc || opcode == OpCodes.Stloc_S) { return new CodeInstruction(OpCodes.Ldloc, instruction.operand); } return null; } public static int? GetLdcI32(this CodeInstruction instruction) { OpCode opcode = instruction.opcode; if (opcode == OpCodes.Ldc_I4_M1) { return -1; } if (opcode == OpCodes.Ldc_I4_0) { return 0; } if (opcode == OpCodes.Ldc_I4_1) { return 1; } if (opcode == OpCodes.Ldc_I4_2) { return 2; } if (opcode == OpCodes.Ldc_I4_3) { return 3; } if (opcode == OpCodes.Ldc_I4_4) { return 4; } if (opcode == OpCodes.Ldc_I4_5) { return 5; } if (opcode == OpCodes.Ldc_I4_6) { return 6; } if (opcode == OpCodes.Ldc_I4_7) { return 7; } if (opcode == OpCodes.Ldc_I4_8) { return 8; } if (opcode == OpCodes.Ldc_I4_S) { return instruction.operand as sbyte?; } if (opcode == OpCodes.Ldc_I4) { return instruction.operand as int?; } return null; } } } namespace Scoops { public class Config { public static ConfigEntry<bool> unloadUnused; public static ConfigEntry<bool> fixCameraSettings; public static ConfigEntry<bool> applyShipCameraQualityOverrides; public static ConfigEntry<bool> applySecurityCameraQualityOverrides; public static ConfigEntry<bool> applyMapCameraQualityOverrides; public static ConfigEntry<bool> cameraRenderTransparent; public static ConfigEntry<bool> patchCameraScript; public static ConfigEntry<float> securityCameraCullDistance; public static ConfigEntry<int> mapCameraFramerate; public static ConfigEntry<int> securityCameraFramerate; public static ConfigEntry<int> shipCameraFramerate; public static ConfigEntry<int> vSyncCount; public static ConfigEntry<bool> qualityOverrides; public static ConfigEntry<int> decalDrawDist; public static ConfigEntry<int> decalAtlasSize; public static ConfigEntry<string> reflectionAtlasSize; public static ConfigEntry<int> maxCubeReflectionProbes; public static ConfigEntry<int> maxPlanarReflectionProbes; public static ConfigEntry<int> shadowsMaxResolution; public static ConfigEntry<int> shadowsAtlasSize; public Config(ConfigFile cfg) { //IL_00f6: Unknown result type (might be due to invalid IL or missing references) //IL_0100: Expected O, but got Unknown //IL_01b2: Unknown result type (might be due to invalid IL or missing references) //IL_01bc: Expected O, but got Unknown //IL_01f6: Unknown result type (might be due to invalid IL or missing references) //IL_0200: Expected O, but got Unknown //IL_0262: Unknown result type (might be due to invalid IL or missing references) //IL_026c: Expected O, but got Unknown //IL_0290: Unknown result type (might be due to invalid IL or missing references) //IL_029a: Expected O, but got Unknown //IL_02bd: Unknown result type (might be due to invalid IL or missing references) //IL_02c7: Expected O, but got Unknown //IL_02fc: Unknown result type (might be due to invalid IL or missing references) //IL_0306: Expected O, but got Unknown //IL_033b: Unknown result type (might be due to invalid IL or missing references) //IL_0345: Expected O, but got Unknown cfg.SaveOnConfigSet = false; unloadUnused = cfg.Bind<bool>("Cleanup", "unloadUnused", true, "Should Sponge call UnloadUnusedAssets each day?"); fixCameraSettings = cfg.Bind<bool>("Cameras", "fixCameraSettings", true, "Should Sponge change the settings for the ship cameras and radar cam to improve performance?"); applyShipCameraQualityOverrides = cfg.Bind<bool>("Cameras", "applyShipCameraQualityOverrides", true, "Should Sponge disable extra HDRP rendering features on the Ship camera? (Requires fixCameraSettings = true)"); applySecurityCameraQualityOverrides = cfg.Bind<bool>("Cameras", "applySecurityCameraQualityOverrides", true, "Should Sponge disable extra HDRP rendering features on the Security camera? (Requires fixCameraSettings = true)"); applyMapCameraQualityOverrides = cfg.Bind<bool>("Cameras", "applyMapCameraQualityOverrides", true, "Should Sponge disable extra HDRP rendering features on the Map camera? (Requires fixCameraSettings = true)"); cameraRenderTransparent = cfg.Bind<bool>("Cameras", "cameraRenderTransparent", true, "Should the Ship and Security camera render transparent objects? (Requires applyShipCameraQualityOverrides or applySecurityCameraQualityOverrides)"); patchCameraScript = cfg.Bind<bool>("Cameras", "patchCameraScript", true, "Should Sponge replace the base Lethal Company ManualCameraRenderer.MeetsCameraEnabledConditions function with one that more reliably disables ship cameras when they're not in view?"); securityCameraCullDistance = cfg.Bind<float>("Cameras", "securityCameraCullDistance", 20f, new ConfigDescription("What should the culling distance be for the ship security camera? You might want to increase this if you're using a mod to re-add planets in orbit. (LC default is 150)", (AcceptableValueBase)(object)new AcceptableValueRange<float>(15f, 150f), Array.Empty<object>())); securityCameraFramerate = cfg.Bind<int>("Cameras", "securityCameraFramerate", 15, "What framerate should the exterior cam run at? 0 = not limited. (Requires fixCameraSettings = true)"); shipCameraFramerate = cfg.Bind<int>("Cameras", "shipCameraFramerate", 15, "What framerate should the interior cam run at? 0 = not limited. (Requires fixCameraSettings = true)"); mapCameraFramerate = cfg.Bind<int>("Cameras", "mapCameraFramerate", 20, "What framerate should the radar map camera run at? 0 = not limited. (Requires fixCameraSettings = true)"); vSyncCount = cfg.Bind<int>("Rendering", "vSyncCount", 1, "When the option \"Use monitor (V-Sync)\" is selected in Options, what VSyncCount should be used? (LC default is 1)"); qualityOverrides = cfg.Bind<bool>("Graphics Quality", "qualityOverrides", true, "Should Sponge change the default quality settings? This must be on for any of the other Graphics Quality settings to take effect."); decalDrawDist = cfg.Bind<int>("Graphics Quality", "decalDrawDist", 100, new ConfigDescription("What should the maximum distance be for drawing decals like blood splatters? (LC default is 1000)", (AcceptableValueBase)(object)new AcceptableValueRange<int>(50, 1000), Array.Empty<object>())); decalAtlasSize = cfg.Bind<int>("Graphics Quality", "decalAtlasSize", 2048, new ConfigDescription("What should the texture size be for the the Decal Atlas? (squared) (LC default is 4096)", (AcceptableValueBase)(object)new AcceptableValueList<int>(new int[2] { 2048, 4096 }), Array.Empty<object>())); reflectionAtlasSize = cfg.Bind<string>("Graphics Quality", "reflectionAtlasSize", "Resolution1024x1024", new ConfigDescription("What should the texture size be for the the Reflection Atlas? (LC default is 16384x8192)", (AcceptableValueBase)(object)new AcceptableValueList<string>(new string[7] { "Resolution512x512", "Resolution1024x512", "Resolution1024x1024", "Resolution2048x1024", "Resolution2048x2048", "Resolution4096x2048", "Resolution16384x8192" }), Array.Empty<object>())); maxCubeReflectionProbes = cfg.Bind<int>("Graphics Quality", "maxCubeReflectionProbes", 12, new ConfigDescription("How many Cube Reflection Probes should be able to be on screen at once? (LC default is 48)", (AcceptableValueBase)(object)new AcceptableValueRange<int>(6, 48), Array.Empty<object>())); maxPlanarReflectionProbes = cfg.Bind<int>("Graphics Quality", "maxPlanarReflectionProbes", 8, new ConfigDescription("How many Cube Reflection Probes should be able to be on screen at once? (LC default is 16)", (AcceptableValueBase)(object)new AcceptableValueRange<int>(4, 16), Array.Empty<object>())); shadowsMaxResolution = cfg.Bind<int>("Graphics Quality", "shadowsMaxResolution", 256, new ConfigDescription("What should the maximum resolution be for Shadow Maps? (LC default is 2048)", (AcceptableValueBase)(object)new AcceptableValueList<int>(new int[6] { 64, 128, 256, 512, 1024, 2048 }), Array.Empty<object>())); shadowsAtlasSize = cfg.Bind<int>("Graphics Quality", "shadowsAtlasSize", 2048, new ConfigDescription("What should the resolution be for the Shadow Map Atlas? (LC default is 4096)", (AcceptableValueBase)(object)new AcceptableValueList<int>(new int[3] { 1024, 2048, 4096 }), Array.Empty<object>())); ClearOrphanedEntries(cfg); cfg.Save(); cfg.SaveOnConfigSet = true; } private static void ClearOrphanedEntries(ConfigFile cfg) { PropertyInfo propertyInfo = AccessTools.Property(typeof(ConfigFile), "OrphanedEntries"); Dictionary<ConfigDefinition, string> dictionary = (Dictionary<ConfigDefinition, string>)propertyInfo.GetValue(cfg); dictionary.Clear(); } } public static class PluginInformation { public const string PLUGIN_GUID = "LethalSpongeLegacy"; public const string PLUGIN_NAME = "LethalSpongeLegacy"; public const string PLUGIN_VERSION = "1.0.0"; } [BepInPlugin("LethalSpongeLegacy", "LethalSpongeLegacy", "1.0.0")] public class Plugin : BaseUnityPlugin { public static AssetBundle SpongeAssets; private readonly Harmony _harmony = new Harmony("LethalSpongeLegacy"); public static Plugin Instance { get; set; } public static Config SpongeConfig { get; internal set; } public static ManualLogSource Log => ((BaseUnityPlugin)Instance).Logger; public Plugin() { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Expected O, but got Unknown Instance = this; } private void Awake() { Log.LogInfo((object)"Loading LethalSpongeLegacy Version 1.0.0"); string directoryName = Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location); string text = Path.Combine(directoryName, "spongeassets"); SpongeAssets = AssetBundle.LoadFromFile(text); SpongeConfig = new Config(((BaseUnityPlugin)this).Config); Log.LogInfo((object)"Applying base patches..."); ApplyPluginPatch(); Log.LogInfo((object)"Base patches applied"); AlterQualitySettings(); } private void ApplyPluginPatch() { _harmony.PatchAll(typeof(StartOfRoundSpongePatch)); if (Config.unloadUnused.Value) { _harmony.PatchAll(typeof(MainMenuSpongePatch)); } if (Config.patchCameraScript.Value) { _harmony.PatchAll(typeof(ManualCameraRendererSpongePatch)); } if (Config.vSyncCount.Value != 1) { _harmony.PatchAll(typeof(IngamePlayerSettingsSpongePatch)); } } private void AlterQualitySettings() { //IL_001c: Unknown result type (might be due to invalid IL or missing references) //IL_0021: 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_00c9: Unknown result type (might be due to invalid IL or missing references) //IL_00ce: Unknown result type (might be due to invalid IL or missing references) //IL_0217: Unknown result type (might be due to invalid IL or missing references) //IL_021c: Unknown result type (might be due to invalid IL or missing references) //IL_021d: Unknown result type (might be due to invalid IL or missing references) //IL_0227: Unknown result type (might be due to invalid IL or missing references) if (Config.qualityOverrides.Value) { RenderPipelineSettings currentPlatformRenderPipelineSettings = ((HDRenderPipelineAsset)GraphicsSettings.currentRenderPipeline).currentPlatformRenderPipelineSettings; if (Config.decalDrawDist.Value != 1000) { currentPlatformRenderPipelineSettings.decalSettings.drawDistance = Config.decalDrawDist.Value; } if (Config.decalAtlasSize.Value != 4096) { currentPlatformRenderPipelineSettings.decalSettings.atlasHeight = Config.decalAtlasSize.Value; currentPlatformRenderPipelineSettings.decalSettings.atlasWidth = Config.decalAtlasSize.Value; } if (Config.reflectionAtlasSize.Value != "Resolution16384x8192") { currentPlatformRenderPipelineSettings.lightLoopSettings.reflectionProbeTexCacheSize = Enum.Parse<ReflectionProbeTextureCacheResolution>(Config.reflectionAtlasSize.Value); } if (Config.maxCubeReflectionProbes.Value != 48) { currentPlatformRenderPipelineSettings.lightLoopSettings.maxCubeReflectionOnScreen = Config.maxCubeReflectionProbes.Value; } if (Config.maxPlanarReflectionProbes.Value != 16) { currentPlatformRenderPipelineSettings.lightLoopSettings.maxPlanarReflectionOnScreen = Config.maxPlanarReflectionProbes.Value; } if (Config.shadowsMaxResolution.Value != 2048) { currentPlatformRenderPipelineSettings.hdShadowInitParams.maxPunctualShadowMapResolution = Config.shadowsMaxResolution.Value; currentPlatformRenderPipelineSettings.hdShadowInitParams.maxDirectionalShadowMapResolution = Config.shadowsMaxResolution.Value; currentPlatformRenderPipelineSettings.hdShadowInitParams.maxAreaShadowMapResolution = Config.shadowsMaxResolution.Value; } if (Config.shadowsAtlasSize.Value != 4096) { currentPlatformRenderPipelineSettings.hdShadowInitParams.punctualLightShadowAtlas.shadowAtlasResolution = Config.shadowsAtlasSize.Value; currentPlatformRenderPipelineSettings.hdShadowInitParams.cachedPunctualLightShadowAtlas = Config.shadowsAtlasSize.Value / 2; currentPlatformRenderPipelineSettings.hdShadowInitParams.areaLightShadowAtlas.shadowAtlasResolution = Config.shadowsAtlasSize.Value; currentPlatformRenderPipelineSettings.hdShadowInitParams.cachedAreaLightShadowAtlas = Config.shadowsAtlasSize.Value / 2; } ((HDRenderPipelineAsset)GraphicsSettings.currentRenderPipeline).m_RenderPipelineSettings = currentPlatformRenderPipelineSettings; ((RenderPipelineAsset)(HDRenderPipelineAsset)GraphicsSettings.currentRenderPipeline).OnValidate(); } } } public static class PluginInfo { public const string PLUGIN_GUID = "LethalSpongeLegacy"; public const string PLUGIN_NAME = "LethalSpongeLegacy"; public const string PLUGIN_VERSION = "1.0.0"; } } namespace Scoops.service { public static class CameraService { public static Camera MapCamera; public static Camera ShipCamera; public static Camera SecurityCamera; public static GameObject MonitorWall; public static GameObject ShipInside; public static MeshRenderer DoorMonitor; public static Terminal MainTerminal; public static GameObject oldVolume; public static GameObject newVolume; public static CustomPass oldPass; public static CustomPass newPass; public static bool Init() { Plugin.Log.LogMessage((object)"Finding Ship cameras."); bool result = true; Transform val = ((Component)StartOfRound.Instance).transform.parent.Find("ItemSystems/MapCamera"); if ((Object)(object)val != (Object)null) { MapCamera = ((Component)val).GetComponent<Camera>(); } else { Plugin.Log.LogError((object)"Sponge could not find MapCamera. Camera fixes may not function."); result = false; } Transform val2 = StartOfRound.Instance.elevatorTransform.Find("Cameras/ShipCamera"); if ((Object)(object)val2 != (Object)null) { ShipCamera = ((Component)val2).GetComponent<Camera>(); } else { Plugin.Log.LogError((object)"Sponge could not find ShipCamera. Camera fixes may not function."); result = false; } Transform val3 = StartOfRound.Instance.elevatorTransform.Find("Cameras/FrontDoorSecurityCam/SecurityCamera"); if ((Object)(object)val3 != (Object)null) { SecurityCamera = ((Component)val3).GetComponent<Camera>(); } else { Plugin.Log.LogError((object)"Sponge could not find SecurityCamera. Camera fixes may not function."); result = false; } Transform val4 = StartOfRound.Instance.elevatorTransform.Find("ShipModels2b/MonitorWall"); if ((Object)(object)val4 != (Object)null) { MonitorWall = ((Component)val4).gameObject; } else { Plugin.Log.LogError((object)"Sponge could not find MonitorWall. Camera fixes may not function."); result = false; } Transform val5 = StartOfRound.Instance.elevatorTransform.Find("Terminal/TerminalTrigger/TerminalScript"); if ((Object)(object)val5 != (Object)null) { MainTerminal = ((Component)val5).GetComponent<Terminal>(); } Transform val6 = StartOfRound.Instance.elevatorTransform.Find("ShipModels2b/MonitorWall/SingleScreen"); if ((Object)(object)val6 != (Object)null) { DoorMonitor = ((Component)val6).GetComponent<MeshRenderer>(); } return result; } public static void DisablePosterization() { //IL_0015: Unknown result type (might be due to invalid IL or missing references) //IL_001f: Expected O, but got Unknown //IL_0054: Unknown result type (might be due to invalid IL or missing references) oldVolume = GameObject.Find("CustomPass"); newVolume = new GameObject("SpongeCustomPass"); newVolume.transform.parent = oldVolume.transform.parent; newVolume.AddComponent<CustomPassVolume>(); newVolume.GetComponent<CustomPassVolume>().injectionPoint = (CustomPassInjectionPoint)1; newPass = (CustomPass)(object)new SpongeCustomPass(); newVolume.GetComponent<CustomPassVolume>().customPasses.Add(newPass); foreach (CustomPass customPass in oldVolume.GetComponent<CustomPassVolume>().customPasses) { if (customPass.name == "FS") { oldPass = customPass; oldPass.enabled = false; break; } } } public static bool TogglePasses() { if (newPass != null && oldPass != null) { oldPass.enabled = !oldPass.enabled; newPass.enabled = !oldPass.enabled; Plugin.Log.LogMessage((object)((newPass.enabled ? "Enabling" : "Disabling") + " Sponge custom shader.")); return newPass.enabled; } return false; } public static void ApplyCameraFixes() { if (Config.applyShipCameraQualityOverrides.Value) { SetOverrides(ShipCamera); } if (Config.applySecurityCameraQualityOverrides.Value) { SetOverrides(SecurityCamera); } if (Config.applyMapCameraQualityOverrides.Value) { SetOverrides(MapCamera, mapCamera: true); } ShipCamera.farClipPlane = 13f; SecurityCamera.farClipPlane = Config.securityCameraCullDistance.Value; if (Config.shipCameraFramerate.Value != 0) { ((Component)ShipCamera).GetComponent<ManualCameraRenderer>().renderAtLowerFramerate = true; ((Component)ShipCamera).GetComponent<ManualCameraRenderer>().fps = Config.shipCameraFramerate.Value; ((Component)ShipCamera).GetComponent<HDAdditionalCameraData>().hasPersistentHistory = true; } if (Config.securityCameraFramerate.Value != 0) { ((Component)SecurityCamera).GetComponent<ManualCameraRenderer>().renderAtLowerFramerate = true; ((Component)SecurityCamera).GetComponent<ManualCameraRenderer>().fps = Config.securityCameraFramerate.Value; ((Component)SecurityCamera).GetComponent<HDAdditionalCameraData>().hasPersistentHistory = true; } if (Config.mapCameraFramerate.Value != 0) { ((Component)MonitorWall.transform.Find("Cube.001/CameraMonitorScript")).GetComponent<ManualCameraRenderer>().renderAtLowerFramerate = true; ((Component)MonitorWall.transform.Find("Cube.001/CameraMonitorScript")).GetComponent<ManualCameraRenderer>().fps = Config.mapCameraFramerate.Value; ((Component)MapCamera).GetComponent<HDAdditionalCameraData>().hasPersistentHistory = true; } Plugin.Log.LogMessage((object)"Ship cameras patched."); } private static void SetOverrides(Camera camera, bool mapCamera = false) { //IL_0029: Unknown result type (might be due to invalid IL or missing references) //IL_0093: Unknown result type (might be due to invalid IL or missing references) //IL_0066: Unknown result type (might be due to invalid IL or missing references) HDAdditionalCameraData component = ((Component)camera).GetComponent<HDAdditionalCameraData>(); component.customRenderingSettings = true; ((BitArray128)(ref component.renderingPathCustomFrameSettingsOverrideMask.mask))[4u] = true; component.renderingPathCustomFrameSettings.msaaMode = (MSAAMode)1; if (!mapCamera) { ((BitArray128)(ref component.renderingPathCustomFrameSettingsOverrideMask.mask))[62u] = true; ((BitArray128)(ref component.renderingPathCustomFrameSettingsOverrideMask.mask))[63u] = true; component.renderingPathCustomFrameSettings.maximumLODLevelMode = (MaximumLODLevelMode)2; component.renderingPathCustomFrameSettings.maximumLODLevel = 2; } ((BitArray128)(ref component.renderingPathCustomFrameSettingsOverrideMask.mask))[66u] = true; component.renderingPathCustomFrameSettings.materialQuality = (MaterialQuality)1; if (!mapCamera || !Config.cameraRenderTransparent.Value) { component.DisableHDField((FrameSettingsField)3); } component.DisableHDField((FrameSettingsField)12); component.DisableHDField((FrameSettingsField)8); component.DisableHDField((FrameSettingsField)9); component.DisableHDField((FrameSettingsField)92); component.DisableHDField((FrameSettingsField)6); component.DisableHDField((FrameSettingsField)10); component.DisableHDField((FrameSettingsField)13); component.DisableHDField((FrameSettingsField)14); component.DisableHDField((FrameSettingsField)39); component.DisableHDField((FrameSettingsField)80); component.DisableHDField((FrameSettingsField)81); component.DisableHDField((FrameSettingsField)82); component.DisableHDField((FrameSettingsField)83); component.DisableHDField((FrameSettingsField)84); component.DisableHDField((FrameSettingsField)85); component.DisableHDField((FrameSettingsField)86); component.DisableHDField((FrameSettingsField)87); component.DisableHDField((FrameSettingsField)89); component.DisableHDField((FrameSettingsField)90); component.DisableHDField((FrameSettingsField)91); component.DisableHDField((FrameSettingsField)93); component.DisableHDField((FrameSettingsField)97); component.DisableHDField((FrameSettingsField)17); component.DisableHDField((FrameSettingsField)68); component.DisableHDField((FrameSettingsField)99); component.DisableHDField((FrameSettingsField)20); component.DisableHDField((FrameSettingsField)21); component.DisableHDField((FrameSettingsField)127); component.DisableHDField((FrameSettingsField)34); component.DisableHDField((FrameSettingsField)23); component.DisableHDField((FrameSettingsField)95); component.DisableHDField((FrameSettingsField)24); component.DisableHDField((FrameSettingsField)26); component.DisableHDField((FrameSettingsField)27); component.DisableHDField((FrameSettingsField)28); component.DisableHDField((FrameSettingsField)29); component.DisableHDField((FrameSettingsField)33); component.DisableHDField((FrameSettingsField)35); component.DisableHDField((FrameSettingsField)37); component.DisableHDField((FrameSettingsField)46); component.DisableHDField((FrameSettingsField)79); if (mapCamera) { component.DisableHDField((FrameSettingsField)38); } } private static void DisableHDField(this HDAdditionalCameraData data, FrameSettingsField field) { //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_0013: Expected I4, but got Unknown //IL_001a: Unknown result type (might be due to invalid IL or missing references) ((BitArray128)(ref data.renderingPathCustomFrameSettingsOverrideMask.mask))[(uint)(int)field] = true; ((FrameSettings)(ref data.renderingPathCustomFrameSettings)).SetEnabled(field, false); } } } namespace Scoops.rendering { internal class SpongeCustomPass : CustomPass { public static Material posterizationMaterial; public static Shader posterizationShader; public static RTHandle posterizationRT; public override void Setup(ScriptableRenderContext renderContext, CommandBuffer cmd) { //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_001a: Expected O, but got Unknown //IL_001a: 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) posterizationShader = (Shader)Plugin.SpongeAssets.LoadAsset("SpongePosterizeNew"); posterizationRT = RTHandles.Alloc(Vector2.one, TextureXR.slices, (DepthBits)0, (GraphicsFormat)74, (FilterMode)0, (TextureWrapMode)0, TextureXR.dimension, false, false, true, false, 1, 0f, (MSAASamples)1, false, true, (RenderTextureMemoryless)0, (VRTextureUsage)0, "Posterization Buffer"); posterizationMaterial = CoreUtils.CreateEngineMaterial(posterizationShader); } public override void Execute(CustomPassContext ctx) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_002d: 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_0059: Unknown result type (might be due to invalid IL or missing references) //IL_006f: Unknown result type (might be due to invalid IL or missing references) //IL_0085: Unknown result type (might be due to invalid IL or missing references) //IL_009b: Unknown result type (might be due to invalid IL or missing references) //IL_00b0: Unknown result type (might be due to invalid IL or missing references) //IL_00bb: Unknown result type (might be due to invalid IL or missing references) //IL_00d6: Unknown result type (might be due to invalid IL or missing references) //IL_00f1: Unknown result type (might be due to invalid IL or missing references) //IL_00f7: Unknown result type (might be due to invalid IL or missing references) //IL_0107: Unknown result type (might be due to invalid IL or missing references) //IL_0112: Unknown result type (might be due to invalid IL or missing references) ctx.propertyBlock.SetFloat("_OutlineThickness", 0.001f); ctx.propertyBlock.SetFloat("_DepthThreshold", 0.4f); ctx.propertyBlock.SetFloat("_DepthCurve", 0.4f); ctx.propertyBlock.SetFloat("_DepthStrength", 6f); ctx.propertyBlock.SetFloat("_ColorThreshold", 0.47f); ctx.propertyBlock.SetFloat("_ColorCurve", 2.94f); ctx.propertyBlock.SetFloat("_ColorStrength", 0.65f); CoreUtils.SetRenderTarget(ctx.cmd, posterizationRT, (ClearFlag)7, 0, (CubemapFace)(-1), -1); CoreUtils.DrawFullScreen(ctx.cmd, posterizationMaterial, ctx.propertyBlock, posterizationMaterial.FindPass("ReadColor")); ctx.propertyBlock.SetTexture("_PosterizationBuffer", RTHandle.op_Implicit(posterizationRT)); CoreUtils.SetRenderTarget(ctx.cmd, ctx.cameraColorBuffer, (ClearFlag)0, 0, (CubemapFace)(-1), -1); CoreUtils.DrawFullScreen(ctx.cmd, posterizationMaterial, ctx.propertyBlock, posterizationMaterial.FindPass("WriteColor")); } public override void Cleanup() { CoreUtils.Destroy((Object)(object)posterizationMaterial); posterizationRT.Release(); } } } namespace Scoops.patches { [HarmonyPatch(typeof(IngamePlayerSettings))] public class IngamePlayerSettingsSpongePatch { [HarmonyPatch("SetFramerateCap")] [HarmonyPostfix] public static void IngamePlayerSettings_SetFramerateCap(int value) { if (value == 0) { QualitySettings.vSyncCount = Config.vSyncCount.Value; } } } public class MainMenuSpongePatch { [HarmonyPatch(typeof(MenuManager), "Start")] [HarmonyPostfix] public static void Start(ref MenuManager __instance) { if (!__instance.isInitScene) { Plugin.Log.LogMessage((object)"Calling initial Resources.UnloadUnusedAssets()."); Resources.UnloadUnusedAssets(); } } } [HarmonyPatch(typeof(ManualCameraRenderer))] public class ManualCameraRendererSpongePatch { [HarmonyPatch("Update")] [HarmonyTranspiler] private static IEnumerable<CodeInstruction> ManualCameraRenderer_Update_Transpiler(IEnumerable<CodeInstruction> instructions) { //IL_009d: Unknown result type (might be due to invalid IL or missing references) //IL_00a3: 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_00cc: Unknown result type (might be due to invalid IL or missing references) //IL_00d2: Expected O, but got Unknown ILInjector iLInjector = new ILInjector(instructions).Find(ILMatcher.Ldarg(0), ILMatcher.Ldfld(AccessTools.Field(typeof(ManualCameraRenderer), "renderAtLowerFramerate")), ILMatcher.Opcode(OpCodes.Brfalse)); if (!iLInjector.IsValid) { Plugin.Log.LogError((object)"Failed to find renderAtLowerFramerate branch in ManualCameraRenderer.Update"); return instructions; } Label label = (Label)iLInjector.LastMatchedInstruction.operand; return iLInjector.GoToLastMatchedInstruction().FindLabel(label).RemoveLastMatch() .InsertInPlace(new CodeInstruction(OpCodes.Ldarg_0, (object)null), new CodeInstruction(OpCodes.Call, (object)typeof(ManualCameraRendererSpongePatch).GetMethod("ApplyFramerateCap")), new CodeInstruction(OpCodes.Ret, (object)null)) .ReleaseInstructions(); } [HarmonyPatch("Update")] [HarmonyPostfix] private static void ManualCameraRenderer_Update(ref ManualCameraRenderer __instance) { if (!((Object)(object)GameNetworkManager.Instance.localPlayerController == (Object)null) && !((Object)(object)NetworkManager.Singleton == (Object)null) && __instance.overrideCameraForOtherUse) { PlayerControllerB localPlayerController = GameNetworkManager.Instance.localPlayerController; Camera camera = (localPlayerController.isPlayerDead ? StartOfRound.Instance.spectateCamera : localPlayerController.gameplayCamera); if ((Object)(object)__instance.mesh != (Object)null && !MeshVisible(camera, __instance.mesh)) { ((Behaviour)__instance.cam).enabled = false; } else if (__instance.renderAtLowerFramerate) { ApplyFramerateCap(__instance); } else { ((Behaviour)__instance.cam).enabled = true; } } } [HarmonyPatch("MeetsCameraEnabledConditions")] [HarmonyAfter(new string[] { "Zaggy1024.OpenBodyCams" })] [HarmonyPostfix] private static void ManualCameraRenderer_MeetsCameraEnabledConditions(ref ManualCameraRenderer __instance, ref bool __result, PlayerControllerB player) { Camera camera = (player.isPlayerDead ? StartOfRound.Instance.spectateCamera : player.gameplayCamera); if ((Object)(object)__instance.mesh != (Object)null && !MeshVisible(camera, __instance.mesh)) { __result = false; if ((Object)(object)__instance.cam == (Object)(object)CameraService.SecurityCamera && (Object)(object)CameraService.DoorMonitor != (Object)null && MeshVisible(camera, CameraService.DoorMonitor)) { __result = true; } } if ((Object)(object)__instance == (Object)(object)StartOfRound.Instance.mapScreen && !__result && !((Object)(object)CameraService.MainTerminal == (Object)null) && (Object)(object)CameraService.MainTerminal.displayingPersistentImage == (Object)(object)__instance.mapCamera.activeTexture && ((Behaviour)CameraService.MainTerminal.terminalUIScreen).isActiveAndEnabled) { __result = true; } } private static bool MeshVisible(Camera camera, MeshRenderer mesh) { //IL_0036: Unknown result type (might be due to invalid IL or missing references) //IL_0066: Unknown result type (might be due to invalid IL or missing references) Plane[] array = GeometryUtility.CalculateFrustumPlanes(camera); if (Object.op_Implicit((Object)(object)((Component)mesh).GetComponent<Collider>())) { return GeometryUtility.TestPlanesAABB(array, ((Component)mesh).GetComponent<Collider>().bounds); } if (Object.op_Implicit((Object)(object)((Component)mesh).GetComponent<Renderer>())) { return GeometryUtility.TestPlanesAABB(array, ((Component)mesh).GetComponent<Renderer>().bounds); } return !array.Any((Plane plane) => ((Plane)(ref plane)).GetDistanceToPoint(((Component)mesh).transform.position) < 0f); } public static void ApplyFramerateCap(ManualCameraRenderer manualCameraRenderer) { ((Behaviour)manualCameraRenderer.cam).enabled = false; manualCameraRenderer.elapsed += Time.deltaTime; if (manualCameraRenderer.elapsed > 1f / manualCameraRenderer.fps) { manualCameraRenderer.elapsed = 0f; ((Behaviour)manualCameraRenderer.cam).enabled = true; } } } [HarmonyPatch(typeof(StartOfRound))] public class StartOfRoundSpongePatch { [HarmonyPatch("Start")] [HarmonyPostfix] private static void StartOfRound_Start(ref StartOfRound __instance) { if (Config.fixCameraSettings.Value && CameraService.Init()) { CameraService.ApplyCameraFixes(); } CameraService.DisablePosterization(); } [HarmonyPatch("PassTimeToNextDay")] [HarmonyPostfix] private static void StartOfRound_PassTimeToNextDay(ref StartOfRound __instance) { if (Config.unloadUnused.Value) { Plugin.Log.LogMessage((object)"Calling Resources.UnloadUnusedAssets()."); Resources.UnloadUnusedAssets(); } } } } namespace System.Runtime.CompilerServices { [AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)] internal sealed class IgnoresAccessChecksToAttribute : Attribute { public IgnoresAccessChecksToAttribute(string assemblyName) { } } }