using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using AIGraph;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using GTFO.API;
using GTFO.API.Utilities;
using HarmonyLib;
using Il2CppInterop.Runtime.InteropTypes;
using Il2CppSystem;
using LevelGeneration;
using LevelGeneration.Core;
using Microsoft.CodeAnalysis;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("STFU")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("STFU")]
[assembly: AssemblyTitle("STFU")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
internal sealed class NullableAttribute : Attribute
{
public readonly byte[] NullableFlags;
public NullableAttribute(byte P_0)
{
NullableFlags = new byte[1] { P_0 };
}
public NullableAttribute(byte[] P_0)
{
NullableFlags = P_0;
}
}
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
internal sealed class NullableContextAttribute : Attribute
{
public readonly byte Flag;
public NullableContextAttribute(byte P_0)
{
Flag = P_0;
}
}
}
namespace STFU
{
internal static class Configuration
{
private static readonly ConfigFile Config;
private static readonly ConfigEntry<bool> SuppressMCP3;
private static readonly ConfigEntry<bool> GeoVolumeResults;
private static readonly ConfigEntry<bool> BoxColliderResults;
private static readonly ConfigEntry<bool> FixedBoxColliders;
public static bool SuppressMCP3Logs => SuppressMCP3.Value;
public static bool LogGeoVolumeResults => GeoVolumeResults.Value;
public static bool LogBoxColliderResults => BoxColliderResults.Value;
public static bool ShowFixedBoxColliders => FixedBoxColliders.Value;
static Configuration()
{
//IL_0011: Unknown result type (might be due to invalid IL or missing references)
//IL_001b: Expected O, but got Unknown
Config = new ConfigFile(Path.Combine(Paths.ConfigPath, "STFU.cfg"), true);
string text = "General Settings";
SuppressMCP3 = Config.Bind<bool>(text, "Suppress All MyCoolPlugin3 Logs", false, "If enabled, don't show any unique logs from MCP3.");
GeoVolumeResults = Config.Bind<bool>(text, "Log GeomorphVolume Results", true, "Show the total amount logs intercepted from TryGetGeomorphVolume during level generation upon entering the level.");
BoxColliderResults = Config.Bind<bool>(text, "Log BoxCollider Results", true, "Show the total amount BoxColliders fixed upon entering the level.");
FixedBoxColliders = Config.Bind<bool>(text, "Show Fixed BoxColliders", false, "If enabled, show the BoxCollider GameObjects that were fixed upon entering the level.");
}
internal static void Init()
{
//IL_001a: Unknown result type (might be due to invalid IL or missing references)
//IL_0024: Expected O, but got Unknown
LiveEditListener val = LiveEdit.CreateListener(Paths.ConfigPath, "STFU.cfg", false);
val.FileChanged += new LiveEditEventHandler(OnFileChanged);
}
private static void OnFileChanged(LiveEditEventArgs e)
{
STFULogger.LogWarning("Config file changed: " + e.FullPath);
Config.Reload();
}
}
[BepInPlugin("Amor.STFU", "STFU", "1.1.0")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
internal class EntryPoint : BasePlugin
{
public override void Load()
{
//IL_000c: Unknown result type (might be due to invalid IL or missing references)
Configuration.Init();
new Harmony("Amor.STFU").PatchAll();
Fix_BoxColliders.Setup();
STFULogger.LogInfo("STFU is done loading!");
}
}
internal static class Fix_BoxColliders
{
public static readonly HashSet<string> BoxColliders = new HashSet<string>();
public const string NegativeScaleSize = "BoxColliders does not support negative scale or size.";
private const string Warning = "Warning";
public static void Setup()
{
LevelAPI.OnBuildDone += OnBuildDone;
LevelAPI.OnEnterLevel += OnEnterLevel;
LevelAPI.OnLevelCleanup += OnLevelCleanup;
}
private static void OnBuildDone()
{
//IL_0022: Unknown result type (might be due to invalid IL or missing references)
//IL_0027: 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_002e: 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_003d: Unknown result type (might be due to invalid IL or missing references)
//IL_005c: Unknown result type (might be due to invalid IL or missing references)
//IL_004a: Unknown result type (might be due to invalid IL or missing references)
//IL_006a: Unknown result type (might be due to invalid IL or missing references)
//IL_0078: Unknown result type (might be due to invalid IL or missing references)
//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
//IL_00f9: 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_0110: Unknown result type (might be due to invalid IL or missing references)
//IL_011c: Unknown result type (might be due to invalid IL or missing references)
//IL_0128: Unknown result type (might be due to invalid IL or missing references)
//IL_0134: Unknown result type (might be due to invalid IL or missing references)
foreach (BoxCollider item in Object.FindObjectsOfType<BoxCollider>())
{
Transform transform = ((Component)item).transform;
Vector3 lossyScale = transform.lossyScale;
Vector3 size = item.size;
bool flag = lossyScale.x < 0f || lossyScale.y < 0f || lossyScale.z < 0f;
bool flag2 = size.x < 0f || size.y < 0f || size.z < 0f;
if (flag || flag2)
{
BoxColliders.Add(((Object)item).name);
STFULogger.LogAs("Warning", "BoxColliders does not support negative scale or size.", suppressLog: true);
Vector3 localScale = transform.localScale;
localScale.x *= Mathf.Sign(lossyScale.x);
localScale.y *= Mathf.Sign(lossyScale.y);
localScale.z *= Mathf.Sign(lossyScale.z);
transform.localScale = localScale;
item.size = new Vector3(Mathf.Abs(size.x), Mathf.Abs(size.y), Mathf.Abs(size.z));
}
}
}
private static void OnEnterLevel()
{
if (Configuration.LogBoxColliderResults && BoxColliders.Any())
{
STFULogger.LogWarning($"Fixed {BoxColliders.Count} BoxColliders with negative size/scale");
if (Configuration.ShowFixedBoxColliders)
{
STFULogger.LogDebug(string.Join(", ", BoxColliders));
}
}
}
private static void OnLevelCleanup()
{
BoxColliders.Clear();
}
}
[HarmonyPatch]
internal static class MCP3_Wrapper
{
public const string PLUGIN_GUID = "com.MyName.MyGTFOPlugin";
private static readonly Type? Ltype;
private static readonly string[] Lmethods;
public static bool IsLoaded { get; private set; }
static MCP3_Wrapper()
{
IsLoaded = false;
Lmethods = new string[3] { "Info", "Debug", "Error" };
if (((BaseChainloader<BasePlugin>)(object)IL2CPPChainloader.Instance).Plugins.TryGetValue("com.MyName.MyGTFOPlugin", out var value))
{
try
{
Assembly assembly = ((value == null) ? null : value.Instance?.GetType()?.Assembly) ?? throw new Exception("MCP3 Assembly is missing!");
Type[] typesFromAssembly = AccessTools.GetTypesFromAssembly(assembly);
Ltype = typesFromAssembly.First((Type t) => t.Name == "L");
IsLoaded = Ltype != null;
}
catch (Exception value2)
{
STFULogger.LogError($"Exception thrown while reading data from MyCoolPLugin3:\n{value2}");
IsLoaded = false;
}
}
STFULogger.LogDebug($"MyCoolPlugin3 is loaded: {IsLoaded}");
}
[HarmonyPrepare]
private static bool PrepPatches()
{
return IsLoaded;
}
[HarmonyTargetMethods]
private static IEnumerable<MethodBase> GetTargetMethods()
{
string[] lmethods = Lmethods;
foreach (string name in lmethods)
{
yield return AccessTools.Method(Ltype, name, (Type[])null, (Type[])null);
STFULogger.LogAs(name, "Found MCP3 patch method: " + name);
}
}
[HarmonyTranspiler]
private static IEnumerable<CodeInstruction> Transpile_Lspam(IEnumerable<CodeInstruction> instructions, MethodBase __originalMethod)
{
yield return new CodeInstruction(OpCodes.Ldstr, (object)__originalMethod.Name);
yield return new CodeInstruction(OpCodes.Ldarg_0, (object)null);
yield return new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(MCP3_Wrapper), "Intercept", new Type[2]
{
typeof(string),
typeof(object)
}, (Type[])null));
yield return new CodeInstruction(OpCodes.Ret, (object)null);
}
public static void Intercept(string method, object data)
{
STFULogger.LogAs(method, data?.ToString() ?? string.Empty, Configuration.SuppressMCP3Logs);
}
}
[HarmonyPatch]
internal static class Patch_TryGetGeomorphVolume
{
public const string DimensionIsBorken = "ERROR: Dimension X is borken";
public const string NoCellInGrid = "ERROR: Couldn't find cell in grid";
public const string BorkenCell = "ERROR: Borken cell";
private const string Error = "Error";
public static bool IsNotInLevel { get; private set; }
static Patch_TryGetGeomorphVolume()
{
IsNotInLevel = true;
LevelAPI.OnEnterLevel += OnEnterLevel;
LevelAPI.OnLevelCleanup += OnLevelCleanup;
}
private static void OnEnterLevel()
{
string[] array = new string[3] { "ERROR: Dimension X is borken", "ERROR: Couldn't find cell in grid", "ERROR: Borken cell" };
foreach (string text in array)
{
if (Configuration.LogGeoVolumeResults && STFULogger.UniqueLogMap.TryGetValue(text, out var value))
{
STFULogger.LogWarning($"\"{text}\" message was logged {value} time(s)");
}
}
IsNotInLevel = false;
}
private static void OnLevelCleanup()
{
IsNotInLevel = true;
}
[HarmonyTargetMethod]
private static MethodBase TargetMethod()
{
return AccessTools.Method(typeof(AIG_GeomorphNodeVolume), "TryGetGeomorphVolume", (Type[])null, (Type[])null);
}
[HarmonyTranspiler]
private static IEnumerable<CodeInstruction> Transpile_GeomorphVolume(IEnumerable<CodeInstruction> instructions)
{
MethodInfo helper = AccessTools.Method(typeof(Patch_TryGetGeomorphVolume), "TryGetGeomorphVolumeSilent", new Type[4]
{
typeof(int),
typeof(eDimensionIndex),
typeof(Vector3),
typeof(AIG_GeomorphNodeVolume).MakeByRefType()
}, (Type[])null);
yield return new CodeInstruction(OpCodes.Ldarg_0, (object)null);
yield return new CodeInstruction(OpCodes.Ldarg_1, (object)null);
yield return new CodeInstruction(OpCodes.Ldarg_2, (object)null);
yield return new CodeInstruction(OpCodes.Ldarg_3, (object)null);
yield return new CodeInstruction(OpCodes.Call, (object)helper);
yield return new CodeInstruction(OpCodes.Ret, (object)null);
}
public static bool TryGetGeomorphVolumeSilent(int floorNR, eDimensionIndex dimensionIndex, Vector3 pos, out AIG_GeomorphNodeVolume resultingGeoVolume)
{
//IL_005e: Unknown result type (might be due to invalid IL or missing references)
//IL_002f: Unknown result type (might be due to invalid IL or missing references)
//IL_0089: Unknown result type (might be due to invalid IL or missing references)
//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
//IL_0109: 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_0147: Unknown result type (might be due to invalid IL or missing references)
//IL_0152: Unknown result type (might be due to invalid IL or missing references)
resultingGeoVolume = null;
LG_Floor currentFloor = Builder.CurrentFloor;
if ((Object)(object)currentFloor == (Object)null)
{
Debug.LogError(Object.op_Implicit($"TryGetGeomorphVolume: No floor found! Dim: {dimensionIndex}. Doing this too early?"));
return false;
}
Dimension val = default(Dimension);
if (!currentFloor.GetDimension(dimensionIndex, ref val))
{
Debug.LogError(Object.op_Implicit($"TryGetGeomorphVolume: Tried to get dimension with index ({dimensionIndex}) but failed."));
return false;
}
if (val.Grid == null || !TryGetCell(val.Grid, pos, out LG_Cell cell))
{
LogErrorAs("ERROR: Dimension X is borken", val.DimensionIndex, val.Grid, pos, null);
if (val.Grid != null)
{
LogErrorAs("ERROR: Couldn't find cell in grid", val.DimensionIndex, val.Grid, pos, null);
}
return false;
}
LG_Tile grouping = ((CellBase<LG_Tile, LG_Cell>)(object)cell).m_grouping;
if ((Object)(object)((grouping != null) ? grouping.m_geoRoot : null) == (Object)null)
{
LogErrorAs("ERROR: Borken cell", val.DimensionIndex, val.Grid, pos, cell);
return false;
}
resultingGeoVolume = ((Il2CppObjectBase)((CellBase<LG_Tile, LG_Cell>)(object)cell).m_grouping.m_geoRoot.m_nodeVolume).TryCast<AIG_GeomorphNodeVolume>();
return (Object)(object)resultingGeoVolume != (Object)null;
}
private static bool TryGetCell(LG_Grid grid, Vector3 pos, [MaybeNullWhen(false)] out LG_Cell cell)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0003: Unknown result type (might be due to invalid IL or missing references)
//IL_0008: Unknown result type (might be due to invalid IL or missing references)
//IL_000d: Unknown result type (might be due to invalid IL or missing references)
//IL_000f: 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)
pos -= ((CellGridBase<LG_Grid, LG_Tile, LG_Cell>)(object)grid).m_gridPosition;
int num = Mathf.RoundToInt((pos.x - ((CellGridBase<LG_Grid, LG_Tile, LG_Cell>)(object)grid).m_cellDimHalf) / ((CellGridBase<LG_Grid, LG_Tile, LG_Cell>)(object)grid).m_cellDim);
int num2 = Mathf.RoundToInt((pos.z - ((CellGridBase<LG_Grid, LG_Tile, LG_Cell>)(object)grid).m_cellDimHalf) / ((CellGridBase<LG_Grid, LG_Tile, LG_Cell>)(object)grid).m_cellDim);
if (num < 0 || num2 < 0 || num >= ((CellGridBase<LG_Grid, LG_Tile, LG_Cell>)(object)grid).m_sizeX || num2 >= ((CellGridBase<LG_Grid, LG_Tile, LG_Cell>)(object)grid).m_sizeZ)
{
cell = null;
return false;
}
cell = ((CellGridBase<LG_Grid, LG_Tile, LG_Cell>)(object)grid).GetCell(num, num2);
return true;
}
public static void LogErrorAs(string simpleStr, eDimensionIndex dim, LG_Grid? grid, Vector3 pos, LG_Cell? cell)
{
//IL_006e: Unknown result type (might be due to invalid IL or missing references)
//IL_00b1: 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_0103: Unknown result type (might be due to invalid IL or missing references)
//IL_014f: Unknown result type (might be due to invalid IL or missing references)
//IL_0122: Unknown result type (might be due to invalid IL or missing references)
//IL_01ff: Unknown result type (might be due to invalid IL or missing references)
if (IsNotInLevel)
{
STFULogger.LogAs("Error", simpleStr, IsNotInLevel);
return;
}
string text;
switch (simpleStr)
{
case "ERROR: Dimension X is borken":
text = $"ERROR : Dimension {dim} is borken. grid: {grid}, cell: {cell}, DimIndexLookup: {dim}";
break;
case "ERROR: Couldn't find cell in grid":
text = $"ERROR COULDN'T FIND CELL IN GRID : {dim}, gridPos: {((CellGridBase<LG_Grid, LG_Tile, LG_Cell>)(object)grid)?.m_gridPosition}, cellPos: {pos}";
break;
case "ERROR: Borken cell":
{
DefaultInterpolatedStringHandler defaultInterpolatedStringHandler = new DefaultInterpolatedStringHandler(82, 5);
defaultInterpolatedStringHandler.AppendLiteral("ERROR : Borken cell (pos(");
defaultInterpolatedStringHandler.AppendFormatted<Vector3>(pos);
defaultInterpolatedStringHandler.AppendLiteral(") | cellpos(x:");
defaultInterpolatedStringHandler.AppendFormatted(((CellBase<LG_Tile, LG_Cell>)(object)cell)?.x);
defaultInterpolatedStringHandler.AppendLiteral(", z:");
defaultInterpolatedStringHandler.AppendFormatted(((CellBase<LG_Tile, LG_Cell>)(object)cell)?.z);
defaultInterpolatedStringHandler.AppendLiteral(")) grouping or root. grouping: ");
object obj;
if (cell == null)
{
obj = null;
}
else
{
LG_Tile grouping = ((CellBase<LG_Tile, LG_Cell>)(object)cell).m_grouping;
obj = ((grouping != null) ? ((Object)grouping).ToString() : null);
}
if (obj == null)
{
obj = "<null>";
}
defaultInterpolatedStringHandler.AppendFormatted((string?)obj);
defaultInterpolatedStringHandler.AppendLiteral(" | dim: ");
defaultInterpolatedStringHandler.AppendFormatted<eDimensionIndex>(dim);
text = defaultInterpolatedStringHandler.ToStringAndClear();
break;
}
default:
text = simpleStr;
break;
}
Debug.LogError(Object.op_Implicit(text));
}
}
internal static class STFULogger
{
private static readonly ManualLogSource MLS;
public static ConcurrentDictionary<string, int> UniqueLogMap { get; internal set; }
static STFULogger()
{
UniqueLogMap = new ConcurrentDictionary<string, int>();
MLS = Logger.CreateLogSource("STFU");
LevelAPI.OnBuildStart += Clear;
LevelAPI.OnLevelCleanup += Clear;
}
private static void Clear()
{
UniqueLogMap.Clear();
}
public static void LogInfo(string str)
{
MLS.Log((LogLevel)8, (object)str);
}
public static void LogWarning(string str)
{
MLS.Log((LogLevel)4, (object)str);
}
public static void LogError(string str)
{
MLS.Log((LogLevel)2, (object)str);
}
public static void LogDebug(string str)
{
MLS.Log((LogLevel)32, (object)str);
}
public static void LogAs(string logLevel, string str, bool suppressLog = false)
{
string str2 = str;
string logLevel2 = logLevel;
UniqueLogMap.AddOrUpdate(str2, delegate
{
if (!string.IsNullOrEmpty(str2) && !suppressLog)
{
switch (logLevel2)
{
case "Info":
LogInfo(str2);
break;
case "Debug":
LogDebug(str2);
break;
case "Error":
LogError(str2);
break;
case "Warning":
LogWarning(str2);
break;
default:
LogError("<null> " + str2);
break;
}
}
return 1;
}, (string key, int cnt) => ++cnt);
}
}
}