using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
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.RegularExpressions;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using JetBrains.Annotations;
using LethalConfig;
using LethalConfig.ConfigItems;
using LethalConfig.ConfigItems.Options;
using LethalLevelLoader;
using LethalLib.Modules;
using LobbyCompatibility.Enums;
using LobbyCompatibility.Features;
using MattyFixes.Dependency;
using MattyFixes.Patches;
using Microsoft.CodeAnalysis;
using MonoMod.RuntimeDetour;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.Pool;
using UnityEngine.Rendering;
using VertexLibrary;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp-firstpass")]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: IgnoresAccessChecksTo("Unity.Netcode.Components")]
[assembly: IgnoresAccessChecksTo("Unity.Netcode.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.HighDefinition.Runtime")]
[assembly: AssemblyCompany("MattyFixes")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.1.32.0")]
[assembly: AssemblyInformationalVersion("1.1.32+43ad65c25ab77dbd551e2c3206c95d4bad4d43a6")]
[assembly: AssemblyProduct("Matty's Fixes")]
[assembly: AssemblyTitle("MattyFixes")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.1.32.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 MattyFixes
{
[BepInPlugin("mattymatty.MattyFixes", "Matty's Fixes", "1.1.32")]
[BepInDependency("com.github.lethalcompanymodding.vertexlibrary", "1.0.0")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
internal class MattyFixes : BaseUnityPlugin
{
internal static class PluginConfig
{
internal static class ReadableMeshes
{
internal static ConfigEntry<bool> Enabled;
internal static ConfigEntry<bool> FixLightning;
}
internal static class BadgeFixes
{
internal static ConfigEntry<bool> Enabled;
}
internal static class CupBoard
{
internal static ConfigEntry<bool> Enabled;
internal static ConfigEntry<float> Tolerance;
internal static ConfigEntry<float> Shift;
}
internal static class Radar
{
internal static ConfigEntry<bool> Enabled;
internal static ConfigEntry<bool> RemoveDeleted;
internal static ConfigEntry<bool> RemoveOnShip;
}
internal static class ItemClipping
{
internal static ConfigEntry<bool> Enabled;
internal static ConfigEntry<bool> RotateOnSpawn;
internal static ConfigEntry<float> VerticalOffset;
internal static ConfigEntry<string> ManualOffsets;
internal static readonly Dictionary<string, float> ManualOffsetMap = new Dictionary<string, float>(StringComparer.InvariantCultureIgnoreCase);
internal static readonly Dictionary<Item, ItemRotationConfig> ItemRotations = new Dictionary<Item, ItemRotationConfig>();
}
internal static class OutOfBounds
{
internal static ConfigEntry<bool> Enabled;
internal static ConfigEntry<float> VerticalOffset;
internal static ConfigEntry<bool> SpawnInFurniture;
}
internal static class LightingParticle
{
internal static ConfigEntry<bool> Enabled;
}
internal static class Debug
{
internal static ConfigEntry<LogLevel> VerboseMeshes;
internal static ConfigEntry<LogLevel> VerboseCupboard;
internal static ConfigEntry<LogLevel> VerboseItems;
}
internal static void Init()
{
//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
//IL_00aa: Expected O, but got Unknown
//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
//IL_00e2: Expected O, but got Unknown
//IL_0197: Unknown result type (might be due to invalid IL or missing references)
//IL_01a1: Expected O, but got Unknown
//IL_0209: Unknown result type (might be due to invalid IL or missing references)
//IL_0213: Expected O, but got Unknown
ConfigFile config = ((BaseUnityPlugin)Instance).Config;
ReadableMeshes.Enabled = config.Bind<bool>("ReadableMeshes", "enabled", true, "convert all meshes to readable at runtime");
ReadableMeshes.FixLightning = config.Bind<bool>("ReadableMeshes", "fix_lightning", true, "show lightning particles as dev intended! ( will have no effect if AlternateLightningParticles is active )");
BadgeFixes.Enabled = config.Bind<bool>("BadgeFixes", "enabled", true, "show correct level tag");
CupBoard.Enabled = config.Bind<bool>("CupBoard", "enabled", true, "prevent items inside or above the Storage Closet from falling to the ground");
CupBoard.Tolerance = config.Bind<float>("CupBoard", "tolerance", 0.05f, new ConfigDescription("how loosely \"close\" the items have to be to the top of the closet for them to count X/Z", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 0.5f), Array.Empty<object>()));
CupBoard.Shift = config.Bind<float>("CupBoard", "shift", 0.1f, new ConfigDescription("how much move the items inside the closet on load ( only if ItemClippingFix disabled )", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 0.5f), Array.Empty<object>()));
Radar.Enabled = config.Bind<bool>("Radar", "enabled", true, "remove orphan radar icons from deleted/collected scrap");
Radar.RemoveDeleted = config.Bind<bool>("Radar", "deleted_scrap", true, "remove orphan radar icons from deleted scrap ( company building )");
Radar.RemoveOnShip = config.Bind<bool>("Radar", "ship_loot", true, "remove orphan radar icons from scrap on the ship in a recently created game");
ItemClipping.Enabled = config.Bind<bool>("ItemClipping", "enabled", true, "fix rotation and height of various items when on the Ground");
ItemClipping.RotateOnSpawn = config.Bind<bool>("ItemClipping", "rotate_on_spawn", true, "fix rotation of newly spawned items");
ItemClipping.VerticalOffset = config.Bind<float>("ItemClipping", "vertical_offset", 0f, new ConfigDescription("additional y offset for items on the ground", (AcceptableValueBase)(object)new AcceptableValueRange<float>(-0.5f, 0.5f), Array.Empty<object>()));
ItemClipping.ManualOffsets = config.Bind<string>("ItemClipping", "manual_offsets", "", "y offset for items on the ground\nDictionary Format: '[key]:[value],[key2]:[value2]'\neg: `Vanilla/Ammo:0.0`");
OutOfBounds.Enabled = config.Bind<bool>("OutOfBounds", "enabled", true, "prevent items from falling below the ship");
OutOfBounds.VerticalOffset = config.Bind<float>("OutOfBounds", "vertical_offset", 0.01f, new ConfigDescription("vertical offset to apply to objects on load to prevent them from clipping into the floor", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.001f, 1f), Array.Empty<object>()));
OutOfBounds.SpawnInFurniture = config.Bind<bool>("OutOfBounds", "spawn_in_furniture", true, "Fix items generating inside furniture ( eg: lamps inside the kitchen counter )");
LightingParticle.Enabled = config.Bind<bool>("AlternateLightningParticles", "enabled", true, "use sphere shape for lightning particles ");
Debug.VerboseMeshes = config.Bind<LogLevel>("Debug", "Mesh Verbosity Level", (LogLevel)0, "Print A LOT more logs about Meshes");
Debug.VerboseCupboard = config.Bind<LogLevel>("Debug", "Cupboard Verbosity Level", (LogLevel)0, "Print A LOT more logs about Cupboard detection");
Debug.VerboseItems = config.Bind<LogLevel>("Debug", "Item Verbosity Level", (LogLevel)0, "Print A LOT more logs about Cupboard detection");
string value = ItemClipping.ManualOffsets.Value;
string[] array = value.Split(',');
foreach (string text in array)
{
string[] array2 = text.Split(':');
if (array2.Length > 1)
{
string key = array2[0].Trim();
if (float.TryParse(array2[1], NumberStyles.Float | NumberStyles.AllowThousands, NumberFormatInfo.InvariantInfo, out var result))
{
ItemClipping.ManualOffsetMap.Add(key, result);
}
}
}
if (LethalConfigProxy.Enabled)
{
LethalConfigProxy.AddButton("Cleanup", "Clear old entries", "remove unused entries in the config file\n(IF RUN FROM MENU WILL DELETE ALL ITEM OFFSETS!!)", "Clean&Save", RemoveOrphans);
LethalConfigProxy.AddConfig(ReadableMeshes.Enabled, requiresRestart: true);
LethalConfigProxy.AddConfig(ReadableMeshes.FixLightning);
LethalConfigProxy.AddConfig(BadgeFixes.Enabled, requiresRestart: true);
LethalConfigProxy.AddConfig(CupBoard.Enabled);
LethalConfigProxy.AddConfig(CupBoard.Tolerance);
LethalConfigProxy.AddConfig(CupBoard.Shift);
LethalConfigProxy.AddConfig(Radar.Enabled);
LethalConfigProxy.AddConfig(Radar.RemoveDeleted);
LethalConfigProxy.AddConfig(Radar.RemoveOnShip);
LethalConfigProxy.AddConfig(ItemClipping.Enabled);
LethalConfigProxy.AddConfig(ItemClipping.RotateOnSpawn);
LethalConfigProxy.AddConfig(ItemClipping.VerticalOffset);
LethalConfigProxy.AddConfig(ItemClipping.ManualOffsets, requiresRestart: true);
LethalConfigProxy.AddConfig(OutOfBounds.Enabled, requiresRestart: true);
LethalConfigProxy.AddConfig(OutOfBounds.VerticalOffset);
LethalConfigProxy.AddConfig(OutOfBounds.SpawnInFurniture, requiresRestart: true);
LethalConfigProxy.AddConfig(LightingParticle.Enabled, requiresRestart: true);
LethalConfigProxy.AddConfig<LogLevel>(Debug.VerboseMeshes, requiresRestart: false);
LethalConfigProxy.AddConfig<LogLevel>(Debug.VerboseCupboard, requiresRestart: false);
LethalConfigProxy.AddConfig<LogLevel>(Debug.VerboseItems, requiresRestart: false);
}
}
internal static void RemoveOrphans()
{
ConfigFile config = ((BaseUnityPlugin)Instance).Config;
PropertyInfo property = ((object)config).GetType().GetProperty("OrphanedEntries", BindingFlags.Instance | BindingFlags.NonPublic);
Dictionary<ConfigDefinition, string> dictionary = (Dictionary<ConfigDefinition, string>)property.GetValue(config, null);
dictionary.Clear();
config.Save();
}
}
internal readonly struct ItemRotationConfig
{
public Vector3 Original { get; }
public ConfigEntry<string> Config { get; }
public ItemRotationConfig(Vector3 original, ConfigEntry<string> config)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
Original = original;
Config = config;
}
}
public const string GUID = "mattymatty.MattyFixes";
public const string NAME = "Matty's Fixes";
public const string VERSION = "1.1.32";
internal static ManualLogSource Log;
private static int? _visibleLayerMask;
internal static Harmony Harmony { get; private set; }
internal static HashSet<Hook> Hooks { get; } = new HashSet<Hook>();
internal static MattyFixes Instance { get; private set; }
public static int VisibleLayerMask
{
get
{
int valueOrDefault = _visibleLayerMask.GetValueOrDefault();
if (!_visibleLayerMask.HasValue)
{
valueOrDefault = LayerMask.GetMask(new string[13]
{
"Default", "Player", "Water", "Props", "Room", "InteractableObject", "Foliage", "PhysicsObject", "Enemies", "PlayerRagdoll",
"MapHazards", "MiscLevelGeometry", "Terrain"
});
_visibleLayerMask = valueOrDefault;
}
return _visibleLayerMask.Value;
}
}
private void Awake()
{
//IL_0057: Unknown result type (might be due to invalid IL or missing references)
//IL_0061: Expected O, but got Unknown
if ((Object)(object)Instance == (Object)null)
{
Instance = this;
}
Log = ((BaseUnityPlugin)this).Logger;
try
{
if (LobbyCompatibilityChecker.Enabled)
{
LobbyCompatibilityChecker.Init();
}
Log.LogInfo((object)"Initializing Configs");
PluginConfig.Init();
Log.LogInfo((object)"Patching Methods");
CategorizeItemPatch.Init();
Harmony = new Harmony("mattymatty.MattyFixes");
Harmony.PatchAll(Assembly.GetExecutingAssembly());
Log.LogInfo((object)"Matty's Fixes v1.1.32 Loaded!");
}
catch (Exception ex)
{
Log.LogError((object)("Exception while initializing: \n" + ex));
}
}
internal static void VerboseMeshLog(LogType logLevel, Func<string> message)
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
//IL_0006: Invalid comparison between Unknown and I4
//IL_003d: Unknown result type (might be due to invalid IL or missing references)
//IL_0043: Invalid comparison between Unknown and I4
//IL_0008: Unknown result type (might be due to invalid IL or missing references)
//IL_000a: Invalid comparison between Unknown and I4
//IL_005f: Unknown result type (might be due to invalid IL or missing references)
//IL_0065: Invalid comparison between Unknown and I4
//IL_0045: Unknown result type (might be due to invalid IL or missing references)
//IL_004b: Invalid comparison between Unknown and I4
//IL_001d: Unknown result type (might be due to invalid IL or missing references)
//IL_0020: Invalid comparison between Unknown and I4
//IL_000c: Unknown result type (might be due to invalid IL or missing references)
//IL_000e: Invalid comparison between Unknown and I4
//IL_0079: Unknown result type (might be due to invalid IL or missing references)
//IL_007f: Invalid comparison between Unknown and I4
//IL_0067: Unknown result type (might be due to invalid IL or missing references)
//IL_006d: Invalid comparison between Unknown and I4
//IL_0099: Unknown result type (might be due to invalid IL or missing references)
//IL_004d: Unknown result type (might be due to invalid IL or missing references)
//IL_0053: Invalid comparison between Unknown and I4
//IL_002e: Unknown result type (might be due to invalid IL or missing references)
//IL_0031: Invalid comparison between Unknown and I4
//IL_0022: Unknown result type (might be due to invalid IL or missing references)
//IL_0025: Invalid comparison between Unknown and I4
//IL_008c: Unknown result type (might be due to invalid IL or missing references)
//IL_0010: Unknown result type (might be due to invalid IL or missing references)
//IL_0012: Invalid comparison between Unknown and I4
//IL_009e: Unknown result type (might be due to invalid IL or missing references)
//IL_0081: Unknown result type (might be due to invalid IL or missing references)
//IL_0087: Invalid comparison between Unknown and I4
//IL_006f: Unknown result type (might be due to invalid IL or missing references)
//IL_0075: Invalid comparison between Unknown and I4
//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
//IL_0055: Unknown result type (might be due to invalid IL or missing references)
//IL_005b: Invalid comparison between Unknown and I4
//IL_0033: Unknown result type (might be due to invalid IL or missing references)
//IL_0039: Invalid comparison between Unknown and I4
//IL_0027: Unknown result type (might be due to invalid IL or missing references)
//IL_002a: Invalid comparison between Unknown and I4
//IL_0090: Unknown result type (might be due to invalid IL or missing references)
//IL_0014: Unknown result type (might be due to invalid IL or missing references)
//IL_0016: Invalid comparison between Unknown and I4
//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
//IL_0094: Unknown result type (might be due to invalid IL or missing references)
//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
LogLevel val;
if ((int)logLevel <= 128)
{
if ((int)logLevel <= 8)
{
if ((int)logLevel != 2)
{
if ((int)logLevel != 4)
{
if ((int)logLevel != 8)
{
goto IL_00a6;
}
val = (LogLevel)4;
}
else
{
val = (LogLevel)2;
}
}
else
{
val = (LogLevel)1;
}
goto IL_00a8;
}
if ((int)logLevel <= 32)
{
if ((int)logLevel == 16 || (int)logLevel == 32)
{
goto IL_0097;
}
}
else if ((int)logLevel == 64 || (int)logLevel == 128)
{
goto IL_0097;
}
}
else if ((int)logLevel <= 512)
{
if ((int)logLevel == 240)
{
goto IL_0097;
}
if ((int)logLevel == 256 || (int)logLevel == 512)
{
goto IL_009c;
}
}
else if ((int)logLevel <= 2048)
{
if ((int)logLevel == 1024 || (int)logLevel == 2048)
{
goto IL_009c;
}
}
else
{
if ((int)logLevel == 3840)
{
goto IL_009c;
}
if ((int)logLevel == 4094)
{
val = (LogLevel)63;
goto IL_00a8;
}
}
goto IL_00a6;
IL_0097:
val = (LogLevel)16;
goto IL_00a8;
IL_00a6:
val = (LogLevel)0;
goto IL_00a8;
IL_009c:
val = (LogLevel)32;
goto IL_00a8;
IL_00a8:
LogLevel logLevel2 = val;
VerboseMeshLog(logLevel2, message);
}
internal static void VerboseMeshLog(LogLevel logLevel, Func<string> message)
{
//IL_0005: Unknown result type (might be due to invalid IL or missing references)
//IL_000a: Unknown result type (might be due to invalid IL or missing references)
//IL_000b: Unknown result type (might be due to invalid IL or missing references)
//IL_0013: Unknown result type (might be due to invalid IL or missing references)
if ((PluginConfig.Debug.VerboseMeshes.Value & logLevel) != 0)
{
Log.Log(logLevel, (object)message());
}
}
internal static void VerboseCupboardLog(LogLevel logLevel, Func<string> message)
{
//IL_0005: Unknown result type (might be due to invalid IL or missing references)
//IL_000a: Unknown result type (might be due to invalid IL or missing references)
//IL_000b: Unknown result type (might be due to invalid IL or missing references)
//IL_0013: Unknown result type (might be due to invalid IL or missing references)
if ((PluginConfig.Debug.VerboseCupboard.Value & logLevel) != 0)
{
Log.Log(logLevel, (object)message());
}
}
internal static void VerboseItemsLog(LogLevel logLevel, Func<string> message)
{
//IL_0005: Unknown result type (might be due to invalid IL or missing references)
//IL_000a: Unknown result type (might be due to invalid IL or missing references)
//IL_000b: Unknown result type (might be due to invalid IL or missing references)
//IL_0013: Unknown result type (might be due to invalid IL or missing references)
if ((PluginConfig.Debug.VerboseItems.Value & logLevel) != 0)
{
Log.Log(logLevel, (object)message());
}
}
}
}
namespace MattyFixes.Patches
{
[HarmonyPatch]
public class CategorizeItemPatch
{
internal static Item[] VanillaItems;
internal static readonly Dictionary<Item, Tuple<string, string>> ItemModMap = new Dictionary<Item, Tuple<string, string>>();
private static readonly Regex ConfigFilterRegex = new Regex("[\\n\\t\\\\\\'\\[\\]]");
internal static void Init()
{
//IL_0036: Unknown result type (might be due to invalid IL or missing references)
//IL_0040: Expected O, but got Unknown
MattyFixes.Hooks.Add(new Hook((MethodBase)AccessTools.Method(typeof(StartOfRound), "Awake", (Type[])null, (Type[])null), (Delegate)new Action<Action<StartOfRound>, StartOfRound>(PrepareItemCache)));
}
private static void PrepareItemCache(Action<StartOfRound> orig, StartOfRound __instance)
{
ItemModMap.Clear();
if (VanillaItems == null)
{
VanillaItems = __instance.allItemsList.itemsList.ToArray();
}
Item[] vanillaItems = VanillaItems;
foreach (Item key in vanillaItems)
{
ItemModMap.TryAdd(key, new Tuple<string, string>("Vanilla", ""));
}
orig(__instance);
}
[HarmonyPrefix]
[HarmonyPatch(typeof(StartOfRound), "Start")]
private static void PopulateModdedCache(StartOfRound __instance)
{
if (LethalLibProxy.Enabled)
{
LethalLibProxy.GetModdedItems(in ItemModMap);
}
if (LethalLevelLoaderProxy.Enabled)
{
LethalLevelLoaderProxy.GetModdedItems(in ItemModMap);
}
foreach (Item items in __instance.allItemsList.itemsList)
{
ItemModMap.TryAdd(items, new Tuple<string, string>("Unknown", ""));
}
}
public static string GetPathForItem(Item item)
{
Tuple<string, string> tagForItem = GetTagForItem(item);
return GetPathForTag(tagForItem, item);
}
public static Tuple<string, string> GetTagForItem(Item item)
{
if (!ItemModMap.TryGetValue(item, out var value))
{
return new Tuple<string, string>("Unknown", "");
}
return value;
}
public static string GetPathForTag(Tuple<string, string> modTag, Item item)
{
string path = string.Join("_", item.itemName.Split(Path.GetInvalidFileNameChars(), StringSplitOptions.RemoveEmptyEntries)).TrimEnd('.');
string path2 = string.Join("_", modTag.Item2.Split(Path.GetInvalidPathChars(), StringSplitOptions.RemoveEmptyEntries)).TrimEnd('.');
return Path.Combine(modTag.Item1, path2, path);
}
public static string SanitizeForConfig(string input)
{
return ConfigFilterRegex.Replace(input, "").Trim();
}
}
[HarmonyPatch]
internal class CupBoardFix
{
internal struct ClosetHolder
{
public readonly UnlockableItem Unlockable;
public readonly GameObject gameObject;
public readonly List<ShelfHolder> Shelves;
public readonly Collider Collider;
public bool IsInitialized;
public ClosetHolder()
{
IsInitialized = false;
Unlockable = StartOfRound.Instance.unlockablesList.unlockables.Find((UnlockableItem u) => u.unlockableName == "Cupboard");
gameObject = GameObject.Find("/Environment/HangarShip/StorageCloset");
Collider = gameObject.GetComponent<Collider>();
Shelves = gameObject.GetComponentsInChildren<PlaceableObjectsSurface>().Select(delegate(PlaceableObjectsSurface s)
{
ShelfHolder result = default(ShelfHolder);
result.Shelf = s;
result.Collider = ((Component)s).GetComponent<Collider>();
return result;
}).ToList();
}
}
internal struct ShelfHolder
{
public PlaceableObjectsSurface Shelf;
public Collider Collider;
}
private static ClosetHolder? _closet;
internal static ClosetHolder Closet
{
get
{
ClosetHolder valueOrDefault = _closet.GetValueOrDefault();
if (!_closet.HasValue)
{
valueOrDefault = new ClosetHolder();
_closet = valueOrDefault;
}
return _closet.Value;
}
}
[HarmonyPostfix]
[HarmonyPatch(typeof(StartOfRound), "OnLocalDisconnect")]
[HarmonyPatch(typeof(StartOfRound), "OnDestroy")]
private static void ResetOnDisconnect()
{
_closet = null;
}
[HarmonyPostfix]
[HarmonyPatch(typeof(StartOfRound), "SyncShipUnlockablesClientRpc")]
private static void AfterCupboardSync(StartOfRound __instance)
{
//IL_001a: Unknown result type (might be due to invalid IL or missing references)
//IL_0020: Invalid comparison between Unknown and I4
NetworkManager networkManager = ((NetworkBehaviour)__instance).NetworkManager;
if ((Object)(object)networkManager == (Object)null || !networkManager.IsListening || (int)((NetworkBehaviour)__instance).__rpc_exec_stage != 2 || (!networkManager.IsClient && !networkManager.IsHost) || ((NetworkBehaviour)__instance).IsServer)
{
return;
}
ClosetHolder closet = Closet;
if (closet.IsInitialized)
{
MattyFixes.VerboseCupboardLog((LogLevel)4, () => "SyncShipUnlockablesClientRpc Cupboard Triggered but was already Initialized!");
return;
}
closet.IsInitialized = true;
if (closet.Unlockable.inStorage)
{
return;
}
closet.gameObject.GetComponent<AutoParentToShip>().MoveToOffset();
Physics.SyncTransforms();
GrabbableObject[] source = Object.FindObjectsOfType<GrabbableObject>();
foreach (GrabbableObject item in source.Where((GrabbableObject g) => g.isInShipRoom))
{
float offset = 0f;
if (item.hasHitGround)
{
offset = item.itemProperties.verticalOffset;
}
ShelfCheck(item, offset);
}
}
[HarmonyPostfix]
[HarmonyPriority(0)]
[HarmonyPatch(typeof(StartOfRound), "LoadShipGrabbableItems")]
private static void OnServerSpawn(GrabbableObject __instance)
{
ClosetHolder closet = Closet;
if (closet.IsInitialized)
{
MattyFixes.VerboseCupboardLog((LogLevel)4, () => "LoadShipGrabbableItems Cupboard Triggered but was already Initialized!");
return;
}
closet.IsInitialized = true;
if (closet.Unlockable.inStorage)
{
return;
}
closet.gameObject.GetComponent<AutoParentToShip>().MoveToOffset();
Physics.SyncTransforms();
GrabbableObject[] source = Object.FindObjectsOfType<GrabbableObject>();
foreach (GrabbableObject item in source.Where((GrabbableObject g) => g.isInShipRoom))
{
ShelfCheck(item);
}
}
private static void ShelfCheck(GrabbableObject grabbable, float offset = 0f)
{
//IL_0084: 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_008f: Unknown result type (might be due to invalid IL or missing references)
//IL_0094: Unknown result type (might be due to invalid IL or missing references)
//IL_0099: 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_0108: Unknown result type (might be due to invalid IL or missing references)
//IL_010c: Unknown result type (might be due to invalid IL or missing references)
//IL_011d: 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_0127: Unknown result type (might be due to invalid IL or missing references)
//IL_0284: Unknown result type (might be due to invalid IL or missing references)
//IL_0289: Unknown result type (might be due to invalid IL or missing references)
//IL_02a9: Unknown result type (might be due to invalid IL or missing references)
//IL_02ae: Unknown result type (might be due to invalid IL or missing references)
//IL_02b3: Unknown result type (might be due to invalid IL or missing references)
//IL_02d9: Unknown result type (might be due to invalid IL or missing references)
//IL_02f6: Unknown result type (might be due to invalid IL or missing references)
//IL_02fb: Unknown result type (might be due to invalid IL or missing references)
//IL_0174: Unknown result type (might be due to invalid IL or missing references)
//IL_0179: Unknown result type (might be due to invalid IL or missing references)
//IL_017e: Unknown result type (might be due to invalid IL or missing references)
//IL_0193: Unknown result type (might be due to invalid IL or missing references)
//IL_01fa: Unknown result type (might be due to invalid IL or missing references)
MattyFixes.VerboseCupboardLog((LogLevel)16, () => $"{grabbable.itemProperties.itemName}({((NetworkBehaviour)grabbable).NetworkObjectId}) - Cupboard Triggered!");
if (grabbable is ClipboardItem || (grabbable is PhysicsProp && grabbable.itemProperties.itemName == "Sticky note"))
{
return;
}
float value = MattyFixes.PluginConfig.CupBoard.Tolerance.Value;
float num = value * value;
try
{
Vector3 pos = ((Component)grabbable).transform.position + Vector3.down * offset;
MattyFixes.VerboseCupboardLog((LogLevel)32, () => $"{grabbable.itemProperties.itemName}({((NetworkBehaviour)grabbable).NetworkObjectId}) - Item pos {pos}!");
ClosetHolder closet = Closet;
float distance = float.MaxValue;
PlaceableObjectsSurface val = null;
Vector3? closest = null;
MattyFixes.VerboseCupboardLog((LogLevel)32, delegate
{
//IL_003a: Unknown result type (might be due to invalid IL or missing references)
//IL_003f: 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)
string itemName = grabbable.itemProperties.itemName;
object arg2 = ((NetworkBehaviour)grabbable).NetworkObjectId;
Bounds bounds2 = closet.Collider.bounds;
return $"{itemName}({arg2}) - Cupboard pos {((Bounds)(ref bounds2)).min}!";
});
Collider collider = closet.Collider;
float y = pos.y;
Bounds bounds = collider.bounds;
if (y < ((Bounds)(ref bounds)).max.y)
{
bounds = collider.bounds;
if (((Bounds)(ref bounds)).SqrDistance(pos) <= num)
{
foreach (ShelfHolder shelf in closet.Shelves)
{
Vector3 val2 = shelf.Collider.ClosestPointOnBounds(pos);
float tmp = pos.y - val2.y;
MattyFixes.VerboseCupboardLog((LogLevel)32, () => $"{grabbable.itemProperties.itemName}({((NetworkBehaviour)grabbable).NetworkObjectId}) - Shelve is {tmp} away!");
if (tmp >= 0f && tmp < distance)
{
val = shelf.Shelf;
distance = tmp;
closest = val2;
}
}
MattyFixes.VerboseCupboardLog((LogLevel)32, () => $"{grabbable.itemProperties.itemName}({((NetworkBehaviour)grabbable).NetworkObjectId}) - Chosen Shelve is {distance} away!");
MattyFixes.VerboseCupboardLog((LogLevel)32, () => $"{grabbable.itemProperties.itemName}({((NetworkBehaviour)grabbable).NetworkObjectId}) - With hitpoint at {closest}!");
}
}
Transform transform = ((Component)grabbable).transform;
if ((Object)(object)val != (Object)null)
{
Vector3 newPos = closest.Value + Vector3.up * grabbable.itemProperties.verticalOffset;
transform.parent = closet.gameObject.transform;
transform.position = newPos;
grabbable.targetFloorPosition = transform.localPosition;
MattyFixes.VerboseCupboardLog((LogLevel)16, () => $"{grabbable.itemProperties.itemName}({((NetworkBehaviour)grabbable).NetworkObjectId}) - Pos on shelf {newPos}!");
}
}
catch (Exception arg)
{
MattyFixes.Log.LogError((object)$"Exception while checking for Cupboard {arg}");
}
}
}
[HarmonyPatch]
internal class GrabbableStartPatch
{
private static readonly HashSet<Item> ComputedOffsets = new HashSet<Item>();
private static readonly Dictionary<Item, List<GrabbableObject>> PendingObjects = new Dictionary<Item, List<GrabbableObject>>();
[HarmonyPrefix]
[HarmonyPatch(typeof(GrabbableObject), "Start")]
internal static void OnObjectSpawn(GrabbableObject __instance)
{
if (!MattyFixes.PluginConfig.ItemClipping.Enabled.Value)
{
return;
}
Item itemProperties = __instance.itemProperties;
if (ComputedOffsets.Contains(itemProperties))
{
return;
}
string pathForItem = CategorizeItemPatch.GetPathForItem(itemProperties);
pathForItem = pathForItem.Replace(Path.DirectorySeparatorChar, '/');
MattyFixes.Log.LogDebug((object)$"{pathForItem}({((NetworkBehaviour)__instance).NetworkObjectId}) needs to compute vertical offset - scheduled");
((MonoBehaviour)__instance).StartCoroutine(ProcessGrabbable(__instance));
if (ShouldSpawnOnGround(__instance) || !((Object)(object)((Component)__instance).transform.parent != (Object)(object)CupBoardFix.Closet.gameObject.transform))
{
if (!PendingObjects.TryGetValue(itemProperties, out var value))
{
value = CollectionPool<List<GrabbableObject>, GrabbableObject>.Get();
PendingObjects[itemProperties] = value;
}
value.Add(__instance);
MattyFixes.Log.LogDebug((object)$"{pathForItem}({((NetworkBehaviour)__instance).NetworkObjectId}) will need to update the position - enqueued");
}
}
private static IEnumerator ProcessGrabbable(GrabbableObject grabbable)
{
Item itemType = grabbable.itemProperties;
Animator[] animators = ((Component)grabbable).GetComponentsInChildren<Animator>();
yield return (object)new WaitUntil((Func<bool>)(() => animators.All(delegate(Animator a)
{
//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)
if (Object.op_Implicit((Object)(object)a) && !Mathf.Approximately(a.speed, 0f))
{
AnimatorStateInfo currentAnimatorStateInfo = a.GetCurrentAnimatorStateInfo(0);
return ((AnimatorStateInfo)(ref currentAnimatorStateInfo)).normalizedTime >= 1f;
}
return true;
})));
if (!ComputedOffsets.Add(itemType))
{
yield break;
}
string pathForItem = CategorizeItemPatch.GetPathForItem(itemType);
pathForItem = pathForItem.Replace(Path.DirectorySeparatorChar, '/');
MattyFixes.Log.LogDebug((object)$"{pathForItem}({((NetworkBehaviour)grabbable).NetworkObjectId}) is computing vertical offset");
float verticalOffset = itemType.verticalOffset;
itemType.verticalOffset = ComputeVerticalOffset(grabbable);
bool flag = Mathf.Approximately(verticalOffset, itemType.verticalOffset);
MattyFixes.Log.LogDebug((object)string.Format("{0} {1} offset is {2}", pathForItem, flag ? "original" : "new", itemType.verticalOffset));
if (flag || !PendingObjects.TryGetValue(itemType, out var value))
{
yield break;
}
foreach (GrabbableObject item in value)
{
if (Object.op_Implicit((Object)(object)item))
{
Vector3 targetFloorPosition = item.targetFloorPosition;
item.targetFloorPosition -= Vector3.up * verticalOffset;
item.targetFloorPosition += Vector3.up * itemType.verticalOffset;
MattyFixes.Log.LogDebug((object)$"{pathForItem}({((NetworkBehaviour)item).NetworkObjectId}) position updated [{targetFloorPosition}] -> [{item.targetFloorPosition}]");
}
}
value.Clear();
CollectionPool<List<GrabbableObject>, GrabbableObject>.Release(value);
PendingObjects.Remove(itemType);
}
private static float ComputeVerticalOffset(GrabbableObject grabbable)
{
//IL_0033: Unknown result type (might be due to invalid IL or missing references)
//IL_0038: Unknown result type (might be due to invalid IL or missing references)
//IL_0076: Unknown result type (might be due to invalid IL or missing references)
//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
//IL_00b8: 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_00c7: 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_00d2: Unknown result type (might be due to invalid IL or missing references)
//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
Item itemProperties = grabbable.itemProperties;
string pathForItem = CategorizeItemPatch.GetPathForItem(itemProperties);
pathForItem = pathForItem.Replace(Path.DirectorySeparatorChar, '/');
try
{
if (MattyFixes.PluginConfig.ItemClipping.ManualOffsetMap.TryGetValue(pathForItem, out var value))
{
return value;
}
ExecutionOptions val = new ExecutionOptions();
((ExecutionOptions)(ref val)).VertexCache = VertexesExtensions.GlobalPartialCache;
((ExecutionOptions)(ref val)).CullingMask = MattyFixes.VisibleLayerMask;
((ExecutionOptions)(ref val)).LogHandler = MattyFixes.VerboseMeshLog;
((ExecutionOptions)(ref val)).OverrideMatrix = Matrix4x4.TRS(Vector3.zero, Quaternion.Euler(grabbable.itemProperties.restingRotation.x, (float)grabbable.itemProperties.floorYOffset + 90f, grabbable.itemProperties.restingRotation.z), ((Component)grabbable).transform.lossyScale);
ExecutionOptions val2 = val;
Bounds val3 = default(Bounds);
if (VertexesExtensions.TryGetBounds(((Component)grabbable).transform, ref val3, val2))
{
value = 0f - ((Bounds)(ref val3)).min.y;
value += MattyFixes.PluginConfig.ItemClipping.VerticalOffset.Value;
}
else
{
value = itemProperties.verticalOffset;
}
return value;
}
catch (Exception arg)
{
MattyFixes.Log.LogError((object)$"{pathForItem} Failed to compute vertical offset! {arg}");
}
return itemProperties.verticalOffset;
}
[HarmonyTranspiler]
[HarmonyPatch(typeof(GrabbableObject), "Start")]
private static IEnumerable<CodeInstruction> RedirectSpawnOnGroundCheck(IEnumerable<CodeInstruction> instructions)
{
//IL_004a: Unknown result type (might be due to invalid IL or missing references)
//IL_0051: 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
//IL_007c: Unknown result type (might be due to invalid IL or missing references)
//IL_0082: Expected O, but got Unknown
//IL_0090: Unknown result type (might be due to invalid IL or missing references)
//IL_0096: Expected O, but got Unknown
//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
//IL_00aa: Expected O, but got Unknown
//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
//IL_00e3: Expected O, but got Unknown
List<CodeInstruction> list = instructions.ToList();
FieldInfo fieldInfo = AccessTools.Field(typeof(GrabbableObject), "itemProperties");
FieldInfo fieldInfo2 = AccessTools.Field(typeof(Item), "itemSpawnsOnGround");
MethodInfo methodInfo = AccessTools.Method(typeof(GrabbableStartPatch), "NewSpawnOnGroundCheck", (Type[])null, (Type[])null);
CodeMatcher val = new CodeMatcher((IEnumerable<CodeInstruction>)list, (ILGenerator)null);
val.MatchForward(false, (CodeMatch[])(object)new CodeMatch[4]
{
new CodeMatch((OpCode?)OpCodes.Ldarg_0, (object)null, (string)null),
new CodeMatch((OpCode?)OpCodes.Ldfld, (object)fieldInfo, (string)null),
new CodeMatch((OpCode?)OpCodes.Ldfld, (object)fieldInfo2, (string)null),
new CodeMatch((OpCode?)OpCodes.Brfalse, (object)null, (string)null)
});
if (val.IsInvalid)
{
return list;
}
val.Advance(1);
val.RemoveInstructions(2);
val.Insert((CodeInstruction[])(object)new CodeInstruction[1]
{
new CodeInstruction(OpCodes.Call, (object)methodInfo)
});
MattyFixes.Log.LogDebug((object)"GrabbableObject.Start patched!");
return val.Instructions();
}
private static bool NewSpawnOnGroundCheck(GrabbableObject grabbableObject)
{
MattyFixes.VerboseItemsLog((LogLevel)32, () => $"{grabbableObject.itemProperties.itemName}({((NetworkBehaviour)grabbableObject).NetworkObjectId}) processing GrabbableObject pos {((Component)grabbableObject).transform.position}");
bool ret = ShouldSpawnOnGround(grabbableObject);
MattyFixes.VerboseItemsLog((LogLevel)32, () => $"{grabbableObject.itemProperties.itemName}({((NetworkBehaviour)grabbableObject).NetworkObjectId}) processing GrabbableObject spawnState " + $"OnGround - was: {grabbableObject.itemProperties.itemSpawnsOnGround} new:{ret}");
return ret;
}
private static bool ShouldSpawnOnGround(GrabbableObject grabbableObject)
{
bool result = grabbableObject.itemProperties.itemSpawnsOnGround;
if (!MattyFixes.PluginConfig.OutOfBounds.Enabled.Value && !MattyFixes.PluginConfig.CupBoard.Enabled.Value)
{
return result;
}
if (grabbableObject is ClipboardItem || (grabbableObject is PhysicsProp && grabbableObject.itemProperties.itemName == "Sticky note"))
{
return result;
}
if (Object.op_Implicit((Object)(object)StartOfRound.Instance.localPlayerController) && !StartOfRoundPatch._isInitializingGame)
{
return result;
}
if (MattyFixes.PluginConfig.OutOfBounds.Enabled.Value)
{
result = ((NetworkBehaviour)StartOfRound.Instance).IsServer;
}
if (!MattyFixes.PluginConfig.CupBoard.Enabled.Value)
{
return result;
}
if (Object.op_Implicit((Object)(object)CupBoardFix.Closet.gameObject) && (Object)(object)((Component)grabbableObject).transform.parent == (Object)(object)CupBoardFix.Closet.gameObject.transform)
{
result = false;
}
return result;
}
}
[HarmonyPatch]
internal static class ItemPatches
{
[HarmonyPatch(typeof(NetworkBehaviour), "OnNetworkSpawn")]
internal static class NetworkSpawnPatch
{
[HarmonyPrefix]
[HarmonyPriority(900)]
private static void Prefix(NetworkBehaviour __instance)
{
GrabbableObject val = (GrabbableObject)(object)((__instance is GrabbableObject) ? __instance : null);
if (val == null)
{
return;
}
Item itemProperties = val.itemProperties;
if (!ComputedItems.Add(itemProperties))
{
return;
}
string pathForItem = CategorizeItemPatch.GetPathForItem(itemProperties);
pathForItem = pathForItem.Replace(Path.DirectorySeparatorChar, '/');
if (!itemProperties.isConductiveMetal || !MattyFixes.PluginConfig.ReadableMeshes.Enabled.Value || !MattyFixes.PluginConfig.ReadableMeshes.FixLightning.Value || MattyFixes.PluginConfig.LightingParticle.Enabled.Value)
{
return;
}
try
{
if ((Object)(object)itemProperties.spawnPrefab != (Object)null)
{
MakeMeshReadable(itemProperties.spawnPrefab);
}
}
catch (Exception arg)
{
MattyFixes.Log.LogError((object)$"{pathForItem} Failed to mark prefab Mesh Readable! {arg}");
BrokenMeshItems.Add(itemProperties);
MattyFixes.Log.LogWarning((object)(pathForItem + " Added to the ignored Meshes!"));
}
}
[HarmonyPostfix]
[HarmonyPriority(-900)]
private static void Postfix(NetworkBehaviour __instance)
{
//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
//IL_0102: Unknown result type (might be due to invalid IL or missing references)
GrabbableObject val = (GrabbableObject)(object)((__instance is GrabbableObject) ? __instance : null);
if (val == null || val is ClipboardItem || (val is PhysicsProp && val.itemProperties.itemName == "Sticky note") || (Object.op_Implicit((Object)(object)StartOfRound.Instance.localPlayerController) && !StartOfRoundPatch._isInitializingGame))
{
return;
}
try
{
val.isInElevator = true;
val.isInShipRoom = true;
LungProp val2 = (LungProp)(object)((val is LungProp) ? val : null);
if (val2 != null)
{
val2.isLungDocked = false;
val2.isLungPowered = false;
val2.isLungDockedInElevator = false;
AudioSource component = ((Component)val2).GetComponent<AudioSource>();
if (component != null)
{
component.Stop();
}
}
if (MattyFixes.PluginConfig.ItemClipping.RotateOnSpawn.Value)
{
val.floorYRot = (int)Math.Floor(((Component)val).transform.eulerAngles.y - 90f - (float)val.itemProperties.floorYOffset);
((Component)val).transform.rotation = Quaternion.Euler(val.itemProperties.restingRotation.x, ((Component)val).transform.eulerAngles.y, val.itemProperties.restingRotation.z);
}
}
catch (Exception arg)
{
string pathForItem = CategorizeItemPatch.GetPathForItem(val.itemProperties);
pathForItem = pathForItem.Replace(Path.DirectorySeparatorChar, '/');
MattyFixes.Log.LogError((object)$"Exception while setting rotation of {pathForItem} :{arg}");
}
}
}
[HarmonyPatch]
internal class StormyWeatherPatch
{
[HarmonyPostfix]
[HarmonyPatch(typeof(StormyWeather), "SetStaticElectricityWarning")]
private static void ChangeParticleShape(StormyWeather __instance, NetworkObject warningObject)
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
//IL_000b: 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_001b: Unknown result type (might be due to invalid IL or missing references)
//IL_0020: 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_002c: Unknown result type (might be due to invalid IL or missing references)
//IL_0050: Unknown result type (might be due to invalid IL or missing references)
//IL_0055: 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_0099: 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_00a2: Unknown result type (might be due to invalid IL or missing references)
//IL_00c0: 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_00c9: 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)
//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
//IL_0102: 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)
try
{
Matrix4x4 overrideMatrix = Matrix4x4.TRS(Vector3.zero, ((Component)warningObject).transform.rotation, ((Component)warningObject).transform.lossyScale);
ShapeModule shape = __instance.staticElectricityParticle.shape;
if (MattyFixes.PluginConfig.LightingParticle.Enabled.Value)
{
((ShapeModule)(ref shape)).shapeType = (ParticleSystemShapeType)0;
((ShapeModule)(ref shape)).radiusThickness = 0.01f;
ExecutionOptions val = new ExecutionOptions();
((ExecutionOptions)(ref val)).VertexCache = VertexesExtensions.GlobalPartialCache;
((ExecutionOptions)(ref val)).CullingMask = MattyFixes.VisibleLayerMask;
((ExecutionOptions)(ref val)).LogHandler = MattyFixes.VerboseMeshLog;
((ExecutionOptions)(ref val)).OverrideMatrix = overrideMatrix;
ExecutionOptions val2 = val;
Vector3[] vertexes = VertexesExtensions.GetVertexes(((Component)warningObject).transform, val2);
Bounds? bounds = VertexesExtensions.GetBounds((IEnumerable<Vector3>)vertexes);
if (bounds.HasValue)
{
Bounds value = bounds.Value;
float item = VertexesExtensions.GetFarthestPoint((IEnumerable<Vector3>)vertexes, ((Bounds)(ref value)).center).Item2;
((ShapeModule)(ref shape)).radius = item;
value = bounds.Value;
_staticElectricityParticleOffset = ((Bounds)(ref value)).center + Vector3.up * 0.5f;
}
return;
}
GrabbableObject component = ((Component)warningObject).gameObject.GetComponent<GrabbableObject>();
if (!MattyFixes.PluginConfig.ReadableMeshes.Enabled.Value || !MattyFixes.PluginConfig.ReadableMeshes.FixLightning.Value || BrokenMeshItems.Contains(component.itemProperties))
{
return;
}
try
{
MakeMeshReadable(((Component)warningObject).gameObject, updateOriginal: true, ReverseMeshMap);
}
catch (Exception arg)
{
string pathForItem = CategorizeItemPatch.GetPathForItem(component.itemProperties);
pathForItem = pathForItem.Replace(Path.DirectorySeparatorChar, '/');
MattyFixes.Log.LogError((object)$"{pathForItem} Failed to mark prefab Mesh Readable! {arg}");
BrokenMeshItems.Add(component.itemProperties);
MattyFixes.Log.LogWarning((object)(pathForItem + " Added to the ignored Meshes!"));
}
}
catch (Exception ex)
{
MattyFixes.Log.LogError((object)ex);
}
}
[HarmonyPrefix]
[HarmonyPatch(typeof(StormyWeather), "LightningStrike")]
private static void ResetMeshes(StormyWeather __instance, bool useTargetedObject)
{
if (!((Object)(object)__instance.setStaticToObject == (Object)null) && useTargetedObject)
{
if (MattyFixes.PluginConfig.ReadableMeshes.Enabled.Value)
{
ApplyMeshMap(__instance.setStaticToObject, ReverseMeshMap);
}
ReverseMeshMap.Clear();
}
}
[HarmonyPostfix]
[HarmonyPatch(typeof(StormyWeather), "Update")]
private static void SetCorrectParticlePosition(StormyWeather __instance)
{
//IL_0027: Unknown result type (might be due to invalid IL or missing references)
//IL_002c: Unknown result type (might be due to invalid IL or missing references)
//IL_0031: Unknown result type (might be due to invalid IL or missing references)
if (!((Object)(object)__instance.setStaticToObject == (Object)null) && MattyFixes.PluginConfig.LightingParticle.Enabled.Value)
{
Transform transform = ((Component)__instance.staticElectricityParticle).transform;
transform.position += _staticElectricityParticleOffset;
}
}
}
private static readonly HashSet<Item> ComputedItems = new HashSet<Item>();
private static readonly Dictionary<Mesh, Mesh> ReadableMeshMap = new Dictionary<Mesh, Mesh>();
private static readonly HashSet<Item> BrokenMeshItems = new HashSet<Item>();
private static readonly Dictionary<MeshFilter, Mesh> ReverseMeshMap = new Dictionary<MeshFilter, Mesh>();
private static Vector3 _staticElectricityParticleOffset;
private static readonly Dictionary<string, List<float>> ItemRotations = new Dictionary<string, List<float>>
{
{
"Flashlight",
new List<float>(3) { 90f, 0f, 90f }
},
{
"Jetpack",
new List<float>(3) { 45f, 0f, 0f }
},
{
"Key",
new List<float>(3) { 180f, 0f, 90f }
},
{
"Apparatus",
new List<float>(3) { 0f, 0f, 135f }
},
{
"Pro-flashlight",
new List<float>(3) { 90f, 0f, 90f }
},
{
"Shovel",
new List<float>(3) { 0f, 0f, -90f }
},
{
"Stun grenade",
new List<float>(3) { 0f, 0f, 90f }
},
{
"Extension ladder",
new List<float>(3) { 0f, 90f, 0f }
},
{
"TZP-Inhalant",
new List<float>(3) { 0f, 0f, -90f }
},
{
"Zap gun",
new List<float>(3) { 95f, 0f, 90f }
},
{
"Magic 7 ball",
new List<float>(3) { 0f, 0f, 0f }
},
{
"Airhorn",
new List<float>(3) { 0f, -90f, 270f }
},
{
"Big bolt",
new List<float>(3) { -21f, 0f, 0f }
},
{
"Bottles",
new List<float>(3) { -90f, 0f, 0f }
},
{
"Brush",
new List<float>(3) { 90f, 180f, 0f }
},
{
"Candy",
new List<float>(3) { 90f, -135f, 0f }
},
{
"Cash register",
new List<float>(3) { -90f, -90f, 40f }
},
{
"Chemical jug",
new List<float>(3) { -90f, 0f, 0f }
},
{
"Clown horn",
new List<float>(3) { -90f, -30f, 0f }
},
{
"Large axle",
new List<float>(3) { 7f, 180f, 0f }
},
{
"Teeth",
new List<float>(3) { -90f, 0f, 0f }
},
{
"Dust pan",
new List<float>(3) { -90f, 180f, 0f }
},
{
"Egg beater",
new List<float>(3) { 90f, 180f, 0f }
},
{
"V-type engine",
new List<float>(3) { -90f, 0f, 0f }
},
{
"Plastic fish",
new List<float>(3) { -45f, 0f, 90f }
},
{
"Laser pointer",
new List<float>(3) { 0f, 0f, 0f }
},
{
"Gold bar",
new List<float>(3) { -90f, 0f, -90f }
},
{
"Hairdryer",
new List<float>(3) { 0f, -90f, -90f }
},
{
"Magnifying glass",
new List<float>(3) { 0f, -45f, -90f }
},
{
"Cookie mold pan",
new List<float>(3) { -90f, 0f, 90f }
},
{
"Mug",
new List<float>(3) { -90f, 0f, 0f }
},
{
"Perfume bottle",
new List<float>(3) { -90f, 0f, 0f }
},
{
"Old phone",
new List<float>(3) { -90f, 180f, -90f }
},
{
"Jar of pickles",
new List<float>(3) { -90f, 0f, 0f }
},
{
"Pill bottle",
new List<float>(3) { -90f, 0f, 0f }
},
{
"Remote",
new List<float>(3) { -90f, 180f, 0f }
},
{
"Ring",
new List<float>(3) { 0f, -90f, 90f }
},
{
"Toy robot",
new List<float>(3) { -90f, 0f, 0f }
},
{
"Rubber Ducky",
new List<float>(3) { -90f, 0f, 90f }
},
{
"Steering wheel",
new List<float>(3) { -90f, 0f, 0f }
},
{
"Toothpaste",
new List<float>(3) { -90f, 0f, 0f }
},
{
"Hive",
new List<float>(3) { 7f, 0f, 0f }
},
{
"Radar-booster",
new List<float>(3) { 0f, 0f, 0f }
},
{
"Shotgun",
new List<float>(3) { 180f, 90f, -5f }
},
{
"Ammo",
new List<float>(3) { 0f, 0f, 90f }
},
{
"Spray paint",
new List<float>(3) { 0f, 0f, 195f }
},
{
"Homemade flashbang",
new List<float>(3) { 0f, 0f, 90f }
},
{
"Gift",
new List<float>(3) { -90f, 0f, 0f }
},
{
"Flask",
new List<float>(3) { 25f, 0f, 0f }
},
{
"Tragedy",
new List<float>(3) { -90f, 90f, 0f }
},
{
"Comedy",
new List<float>(3) { -90f, 90f, 0f }
},
{
"Whoopie cushion",
new List<float>(3) { -90f, 180f, 0f }
},
{
"Zed Dog",
new List<float>(3) { 0f, -90f, 0f }
}
};
private static void UpdateItemRotation(Item item, string itemPath = null)
{
//IL_017e: Unknown result type (might be due to invalid IL or missing references)
//IL_0183: Unknown result type (might be due to invalid IL or missing references)
//IL_01f7: Unknown result type (might be due to invalid IL or missing references)
//IL_01f8: Unknown result type (might be due to invalid IL or missing references)
//IL_0203: Unknown result type (might be due to invalid IL or missing references)
//IL_009a: Unknown result type (might be due to invalid IL or missing references)
//IL_009f: 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)
if (!MattyFixes.PluginConfig.ItemClipping.ItemRotations.TryGetValue(item, out var value))
{
if (itemPath == null)
{
itemPath = CategorizeItemPatch.GetPathForItem(item);
}
string text = Path.GetDirectoryName(itemPath) ?? "";
string text2 = CategorizeItemPatch.SanitizeForConfig(Path.GetFileName(itemPath) ?? item.itemName);
text = text.Replace(Path.DirectorySeparatorChar, '|');
text = CategorizeItemPatch.SanitizeForConfig(text);
Vector3 restingRotation = item.restingRotation;
restingRotation.y = item.floorYOffset;
string text3 = restingRotation.x.ToString(CultureInfo.InvariantCulture) + "," + restingRotation.y.ToString(CultureInfo.InvariantCulture) + "," + restingRotation.z.ToString(CultureInfo.InvariantCulture);
value = new MattyFixes.ItemRotationConfig(restingRotation, ((BaseUnityPlugin)MattyFixes.Instance).Config.Bind<string>(text, text2, "default", "Comma separated Vector3 rotation\nvanilla default = '" + text3 + "'"));
MattyFixes.PluginConfig.ItemClipping.ItemRotations[item] = value;
value.Config.SettingChanged += delegate
{
UpdateItemRotation(item, itemPath);
};
if (LethalConfigProxy.Enabled)
{
LethalConfigProxy.AddConfig(value.Config);
}
}
Vector3 original = value.Original;
string[] array = value.Config.Value.Split(",");
if (array.Length == 3 && float.TryParse(array[0], NumberStyles.Float, CultureInfo.InvariantCulture, out var result) && float.TryParse(array[1], NumberStyles.Float, CultureInfo.InvariantCulture, out var result2) && float.TryParse(array[2], NumberStyles.Float, CultureInfo.InvariantCulture, out var result3))
{
((Vector3)(ref original))..ctor(result, result2, result3);
}
item.restingRotation = original;
item.floorYOffset = (int)Math.Round(original.y);
}
[HarmonyPrefix]
[HarmonyPatch(typeof(StartOfRound), "Start")]
[HarmonyPriority(0)]
private static void RegisterItems(StartOfRound __instance, bool __runOriginal)
{
//IL_0069: Unknown result type (might be due to invalid IL or missing references)
//IL_006e: Unknown result type (might be due to invalid IL or missing references)
//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
if (!MattyFixes.PluginConfig.ItemClipping.Enabled.Value || !__runOriginal)
{
return;
}
foreach (Item items in __instance.allItemsList.itemsList)
{
Tuple<string, string> tagForItem = CategorizeItemPatch.GetTagForItem(items);
string pathForTag = CategorizeItemPatch.GetPathForTag(tagForItem, items);
pathForTag = pathForTag.Replace(Path.DirectorySeparatorChar, '/');
try
{
if (!((Object)(object)items.spawnPrefab == (Object)null))
{
Transform transform = items.spawnPrefab.transform;
ExecutionOptions val = new ExecutionOptions();
((ExecutionOptions)(ref val)).CullingMask = MattyFixes.VisibleLayerMask;
((ExecutionOptions)(ref val)).LogHandler = MattyFixes.VerboseMeshLog;
((ExecutionOptions)(ref val)).VertexCache = VertexesExtensions.GlobalPartialCache;
VertexesExtensions.CacheVertexes(transform, val);
if (tagForItem.Item1 == "Vanilla" && ItemRotations.TryGetValue(items.itemName, out var value))
{
((Vector3)(ref items.restingRotation)).Set(value[0], value[1], value[2]);
items.floorYOffset = (int)Math.Round(value[1]);
}
UpdateItemRotation(items, CategorizeItemPatch.GetPathForTag(tagForItem, items));
}
}
catch (Exception arg)
{
MattyFixes.Log.LogError((object)$"{pathForTag} crashed badly ! {arg}");
}
}
}
[HarmonyPostfix]
[HarmonyPatch(typeof(StartOfRound), "LoadUnlockables")]
private static void CorrectlyPlaceAllUnlockables(StartOfRound __instance)
{
if (MattyFixes.PluginConfig.ItemClipping.Enabled.Value)
{
AutoParentToShip[] array = Object.FindObjectsOfType<AutoParentToShip>();
foreach (AutoParentToShip val in array)
{
val.MoveToOffset();
}
Physics.SyncTransforms();
}
}
private static void MakeMeshReadable(GameObject go, bool updateOriginal = false, Dictionary<MeshFilter, Mesh> reverseMap = null)
{
MeshFilter component = go.GetComponent<MeshFilter>();
MeshFilter[] array = (MeshFilter[])((component == null) ? ((Array)go.GetComponentsInChildren<MeshFilter>()) : ((Array)new MeshFilter[1] { component }));
MeshFilter[] array2 = array;
foreach (MeshFilter val in array2)
{
Mesh sharedMesh = val.sharedMesh;
if (!sharedMesh.isReadable)
{
if (!ReadableMeshMap.TryGetValue(sharedMesh, out var value))
{
value = MakeReadableMeshCopy(sharedMesh);
}
ReadableMeshMap[sharedMesh] = value;
if (updateOriginal)
{
val.sharedMesh = value;
}
if (reverseMap != null)
{
reverseMap[val] = sharedMesh;
}
}
}
}
private static void ApplyMeshMap(GameObject go, Dictionary<MeshFilter, Mesh> meshMap)
{
MeshFilter component = go.GetComponent<MeshFilter>();
MeshFilter[] array = (MeshFilter[])((component == null) ? ((Array)go.GetComponentsInChildren<MeshFilter>()) : ((Array)new MeshFilter[1] { component }));
MeshFilter[] array2 = array;
foreach (MeshFilter val in array2)
{
if (meshMap.TryGetValue(val, out var value))
{
val.sharedMesh = value;
}
}
}
private static Mesh MakeReadableMeshCopy(Mesh nonReadableMesh)
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
//IL_0006: Expected O, but got Unknown
//IL_0008: Unknown result type (might be due to invalid IL or missing references)
//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
Mesh val = new Mesh();
val.indexFormat = nonReadableMesh.indexFormat;
nonReadableMesh.vertexBufferTarget = (Target)1;
if (nonReadableMesh.vertexBufferCount > 0)
{
GraphicsBuffer vertexBuffer = nonReadableMesh.GetVertexBuffer(0);
int num = vertexBuffer.stride * vertexBuffer.count;
byte[] array = new byte[num];
vertexBuffer.GetData((Array)array);
val.SetVertexBufferParams(nonReadableMesh.vertexCount, nonReadableMesh.GetVertexAttributes());
val.SetVertexBufferData<byte>(array, 0, 0, num, 0, (MeshUpdateFlags)0);
vertexBuffer.Release();
}
nonReadableMesh.indexBufferTarget = (Target)2;
val.subMeshCount = nonReadableMesh.subMeshCount;
GraphicsBuffer indexBuffer = nonReadableMesh.GetIndexBuffer();
int num2 = indexBuffer.stride * indexBuffer.count;
byte[] array2 = new byte[num2];
indexBuffer.GetData((Array)array2);
val.SetIndexBufferParams(indexBuffer.count, nonReadableMesh.indexFormat);
val.SetIndexBufferData<byte>(array2, 0, 0, num2, (MeshUpdateFlags)0);
indexBuffer.Release();
uint num3 = 0u;
for (int i = 0; i < val.subMeshCount; i++)
{
uint indexCount = nonReadableMesh.GetIndexCount(i);
val.SetSubMesh(i, new SubMeshDescriptor((int)num3, (int)indexCount, (MeshTopology)0), (MeshUpdateFlags)0);
num3 += indexCount;
}
val.RecalculateNormals();
val.RecalculateBounds();
((Object)val).name = "Readable " + ((Object)nonReadableMesh).name;
return val;
}
}
[HarmonyPatch]
internal class OutOfBoundsItemsFix
{
[HarmonyPostfix]
[HarmonyPatch(typeof(RoundManager), "DespawnPropsAtEndOfRound")]
private static void ShipLeave(RoundManager __instance, bool despawnAllItems)
{
//IL_00c4: 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_00cd: Unknown result type (might be due to invalid IL or missing references)
//IL_0090: Unknown result type (might be due to invalid IL or missing references)
//IL_0095: Unknown result type (might be due to invalid IL or missing references)
//IL_0099: Unknown result type (might be due to invalid IL or missing references)
//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
//IL_01c0: Unknown result type (might be due to invalid IL or missing references)
//IL_01f3: Unknown result type (might be due to invalid IL or missing references)
//IL_01f8: Unknown result type (might be due to invalid IL or missing references)
//IL_01fc: Unknown result type (might be due to invalid IL or missing references)
//IL_0219: Unknown result type (might be due to invalid IL or missing references)
//IL_021e: Unknown result type (might be due to invalid IL or missing references)
if (!MattyFixes.PluginConfig.OutOfBounds.Enabled.Value)
{
return;
}
MattyFixes.VerboseItemsLog((LogLevel)16, () => "Ship left the planet: starting check for OOB items!");
Transform elevatorTransform = StartOfRound.Instance.elevatorTransform;
GrabbableObject[] componentsInChildren = ((Component)elevatorTransform).GetComponentsInChildren<GrabbableObject>();
Collider shipInnerRoomBounds = StartOfRound.Instance.shipInnerRoomBounds;
BoxCollider vehicleCollider = Object.FindObjectOfType<VehicleController>()?.boundsCollider;
MattyFixes.VerboseItemsLog((LogLevel)32, () => $"Cruiser? {(Object)(object)vehicleCollider != (Object)null}");
Bounds bounds;
float num;
if (!((Object)(object)vehicleCollider == (Object)null))
{
bounds = shipInnerRoomBounds.bounds;
float y = ((Bounds)(ref bounds)).min.y;
bounds = ((Collider)vehicleCollider).bounds;
num = Math.Min(y, ((Bounds)(ref bounds)).min.y);
}
else
{
bounds = shipInnerRoomBounds.bounds;
num = ((Bounds)(ref bounds)).min.y;
}
float miny = num;
MattyFixes.VerboseItemsLog((LogLevel)32, () => $"Bottom Ship is at y? {miny}");
GrabbableObject[] array = componentsInChildren;
foreach (GrabbableObject item in array)
{
if ((Object)(object)((Component)((NetworkBehaviour)item).NetworkObject).transform.parent != (Object)(object)elevatorTransform)
{
MattyFixes.VerboseItemsLog((LogLevel)32, () => $"{item.itemProperties.itemName}({((NetworkBehaviour)item).NetworkObjectId}) was not parented to the ship. SKIPPING!");
continue;
}
MattyFixes.VerboseItemsLog((LogLevel)32, () => $"{item.itemProperties.itemName}({((NetworkBehaviour)item).NetworkObjectId}) in ship room? {item.isInShipRoom}");
if (!item.isInShipRoom)
{
continue;
}
Transform transform = ((Component)item).transform;
MattyFixes.VerboseItemsLog((LogLevel)32, () => $"{item.itemProperties.itemName}({((NetworkBehaviour)item).NetworkObjectId}) y position? {transform.position.y}");
if (!(transform.position.y >= miny))
{
MattyFixes.VerboseItemsLog((LogLevel)16, () => $"{item.itemProperties.itemName}({((NetworkBehaviour)item).NetworkObjectId}) was found OutOfBounds, teleporting inside!");
Transform obj = transform;
bounds = shipInnerRoomBounds.bounds;
obj.position = ((Bounds)(ref bounds)).center;
item.targetFloorPosition = transform.localPosition;
item.FallToGround(false);
MattyFixes.VerboseItemsLog((LogLevel)32, () => $"{item.itemProperties.itemName}({((NetworkBehaviour)item).NetworkObjectId}) new pos: {item.targetFloorPosition}");
}
}
}
[HarmonyTranspiler]
[HarmonyPatch(typeof(GameNetworkManager), "SaveItemsInShip")]
private static IEnumerable<CodeInstruction> SaveItemsCorrectly(IEnumerable<CodeInstruction> instructions, ILGenerator ilGenerator)
{
//IL_0054: Unknown result type (might be due to invalid IL or missing references)
//IL_005b: Expected O, but got Unknown
//IL_0072: Unknown result type (might be due to invalid IL or missing references)
//IL_0078: Expected O, but got Unknown
//IL_0086: Unknown result type (might be due to invalid IL or missing references)
//IL_008c: Expected O, but got Unknown
//IL_009a: Unknown result type (might be due to invalid IL or missing references)
//IL_00a0: Expected O, but got Unknown
//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
//IL_00b4: Expected O, but got Unknown
//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
//IL_00c8: Expected O, but got Unknown
//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
//IL_00dc: Expected O, but got Unknown
//IL_012a: Unknown result type (might be due to invalid IL or missing references)
//IL_0130: Expected O, but got Unknown
//IL_014f: Unknown result type (might be due to invalid IL or missing references)
//IL_0155: Expected O, but got Unknown
List<CodeInstruction> list = instructions.ToList();
MethodInfo methodInfo = AccessTools.Method(typeof(OutOfBoundsItemsFix), "ApplyVerticalOffset", (Type[])null, (Type[])null);
MethodInfo getMethod = AccessTools.Property(typeof(Component), "transform").GetMethod;
MethodInfo getMethod2 = AccessTools.Property(typeof(Transform), "position").GetMethod;
CodeMatcher val = new CodeMatcher((IEnumerable<CodeInstruction>)list, ilGenerator);
val.MatchForward(false, (CodeMatch[])(object)new CodeMatch[6]
{
new CodeMatch((OpCode?)OpCodes.Ldloc_2, (object)null, (string)null),
new CodeMatch((OpCode?)OpCodes.Ldloc_0, (object)null, (string)null),
new CodeMatch((OpCode?)OpCodes.Ldloc_S, (object)null, (string)null),
new CodeMatch((OpCode?)OpCodes.Ldelem_Ref, (object)null, (string)null),
new CodeMatch((OpCode?)OpCodes.Callvirt, (object)getMethod, (string)null),
new CodeMatch((OpCode?)OpCodes.Callvirt, (object)getMethod2, (string)null)
});
if (val.IsInvalid)
{
MattyFixes.Log.LogError((object)"Cannot patch SaveItemsInShip");
MattyFixes.Log.LogDebug((object)string.Join("\n", list));
return list;
}
val.Advance(4);
val.Insert((CodeInstruction[])(object)new CodeInstruction[1]
{
new CodeInstruction(OpCodes.Dup, (object)null)
});
val.Advance(3);
val.Insert((CodeInstruction[])(object)new CodeInstruction[1]
{
new CodeInstruction(OpCodes.Call, (object)methodInfo)
});
MattyFixes.Log.LogDebug((object)"SaveItemsInShip Patched");
return val.Instructions();
}
private static Vector3 ApplyVerticalOffset(GrabbableObject grabbable, Vector3 position)
{
//IL_000e: 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_0021: 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)
//IL_0057: 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_0063: Unknown result type (might be due to invalid IL or missing references)
//IL_0068: Unknown result type (might be due to invalid IL or missing references)
//IL_007d: Unknown result type (might be due to invalid IL or missing references)
//IL_0082: Unknown result type (might be due to invalid IL or missing references)
//IL_0087: Unknown result type (might be due to invalid IL or missing references)
//IL_008e: 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_00a2: Unknown result type (might be due to invalid IL or missing references)
//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
//IL_00ac: 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)
if (!MattyFixes.PluginConfig.OutOfBounds.Enabled.Value)
{
return position;
}
if (grabbable.isHeld || grabbable.isHeldByEnemy || !grabbable.hasHitGround)
{
return position;
}
Vector3 newPos = position;
newPos += Vector3.down * grabbable.itemProperties.verticalOffset;
newPos += Vector3.up * MattyFixes.PluginConfig.OutOfBounds.VerticalOffset.Value;
MattyFixes.VerboseItemsLog((LogLevel)32, () => $"{grabbable.itemProperties.itemName}({((NetworkBehaviour)grabbable).NetworkObjectId}) fixing saved position pos:{position} newpos:{newPos}");
return newPos;
}
[HarmonyTranspiler]
[HarmonyPatch(typeof(RoundManager), "SpawnScrapInLevel")]
private static IEnumerable<CodeInstruction> FixSpawns(IEnumerable<CodeInstruction> instructions, ILGenerator ilGenerator)
{
//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
//IL_00e0: Expected O, but got Unknown
//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
//IL_00fe: Expected O, but got Unknown
//IL_010c: Unknown result type (might be due to invalid IL or missing references)
//IL_0112: Expected O, but got Unknown
//IL_0120: Unknown result type (might be due to invalid IL or missing references)
//IL_0126: Expected O, but got Unknown
//IL_0134: Unknown result type (might be due to invalid IL or missing references)
//IL_013a: Expected O, but got Unknown
//IL_0148: Unknown result type (might be due to invalid IL or missing references)
//IL_014e: Expected O, but got Unknown
//IL_015c: Unknown result type (might be due to invalid IL or missing references)
//IL_0162: Expected O, but got Unknown
//IL_0170: Unknown result type (might be due to invalid IL or missing references)
//IL_0176: Expected O, but got Unknown
//IL_0184: Unknown result type (might be due to invalid IL or missing references)
//IL_018a: Expected O, but got Unknown
//IL_0198: Unknown result type (might be due to invalid IL or missing references)
//IL_019e: Expected O, but got Unknown
//IL_01ae: Unknown result type (might be due to invalid IL or missing references)
//IL_01b4: Expected O, but got Unknown
//IL_01c4: Unknown result type (might be due to invalid IL or missing references)
//IL_01ca: Expected O, but got Unknown
//IL_01d9: Unknown result type (might be due to invalid IL or missing references)
//IL_01df: Expected O, but got Unknown
List<CodeInstruction> list = instructions.ToList();
if (!MattyFixes.PluginConfig.OutOfBounds.Enabled.Value)
{
return list;
}
if (!MattyFixes.PluginConfig.OutOfBounds.SpawnInFurniture.Value)
{
return list;
}
MethodInfo getMethod = AccessTools.Property(typeof(Vector3), "up").GetMethod;
MethodInfo methodInfo = AccessTools.Method(typeof(RoundManager), "GetRandomNavMeshPositionInBoxPredictable", (Type[])null, (Type[])null);
FieldInfo fieldInfo = AccessTools.Field(typeof(Item), "verticalOffset");
MethodInfo methodInfo2 = AccessTools.Method(typeof(Vector3), "op_Multiply", new Type[2]
{
typeof(Vector3),
typeof(float)
}, (Type[])null);
MethodInfo methodInfo3 = AccessTools.Method(typeof(Vector3), "op_Addition", new Type[2]
{
typeof(Vector3),
typeof(Vector3)
}, (Type[])null);
CodeMatcher val = new CodeMatcher((IEnumerable<CodeInstruction>)list, ilGenerator);
val.MatchForward(false, (CodeMatch[])(object)new CodeMatch[12]
{
new CodeMatch((OpCode?)OpCodes.Call, (object)methodInfo, (string)null),
new CodeMatch((OpCode?)OpCodes.Call, (object)getMethod, (string)null),
new CodeMatch((OpCode?)OpCodes.Ldloc_S, (object)null, (string)null),
new CodeMatch((OpCode?)OpCodes.Ldfld, (object)null, (string)null),
new CodeMatch((OpCode?)OpCodes.Ldfld, (object)null, (string)null),
new CodeMatch((OpCode?)OpCodes.Ldloc_S, (object)null, (string)null),
new CodeMatch((OpCode?)OpCodes.Ldfld, (object)null, (string)null),
new CodeMatch((OpCode?)OpCodes.Callvirt, (object)null, (string)null),
new CodeMatch((OpCode?)OpCodes.Ldfld, (object)fieldInfo, (string)null),
new CodeMatch((OpCode?)OpCodes.Call, (object)methodInfo2, (string)null),
new CodeMatch((OpCode?)OpCodes.Call, (object)methodInfo3, (string)null),
new CodeMatch((OpCode?)OpCodes.Stloc_S, (object)null, (string)null)
});
if (val.IsInvalid)
{
MattyFixes.Log.LogError((object)"RoundManager.SpawnScrapInLevel IL Not Found!");
return list;
}
val.Advance(1).RemoveInstructions(10);
MattyFixes.Log.LogDebug((object)"RoundManager.SpawnScrapInLevel patched");
return val.Instructions();
}
}
[HarmonyPatch]
public static class PlaceableSurfacePatch
{
[HarmonyPrefix]
[HarmonyPatch(typeof(PlaceableObjectsSurface), "itemPlacementPosition")]
private static bool ItemPlacementPositionPatch(PlaceableObjectsSurface __instance, ref Vector3 __result, Transform gameplayCamera, GrabbableObject heldObject)
{
//IL_0010: 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_0069: Unknown result type (might be due to invalid IL or missing references)
//IL_006e: Unknown result type (might be due to invalid IL or missing references)
//IL_0038: 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_0042: 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_0045: Unknown result type (might be due to invalid IL or missing references)
//IL_0055: 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)
//IL_005f: Unknown result type (might be due to invalid IL or missing references)
if (!MattyFixes.PluginConfig.CupBoard.Enabled.Value)
{
return true;
}
try
{
RaycastHit val = default(RaycastHit);
if (Physics.Raycast(gameplayCamera.position, gameplayCamera.forward, ref val, 7f, 1073744640, (QueryTriggerInteraction)1))
{
Vector3 val2 = ((RaycastHit)(ref val)).collider.ClosestPointOnBounds(((RaycastHit)(ref val)).point);
__result = val2 + Vector3.up * heldObject.itemProperties.verticalOffset;
return false;
}
__result = Vector3.zero;
return false;
}
catch (Exception arg)
{
MattyFixes.Log.LogError((object)$"Exception while finding the Placement {arg}");
return true;
}
}
}
[HarmonyPatch]
internal class PlayerLevelPatch
{
[HarmonyTranspiler]
[HarmonyPatch(typeof(HUDManager), "SyncAllPlayerLevelsClientRpc", new Type[]
{
typeof(int[]),
typeof(int)
})]
private static IEnumerable<CodeInstruction> AlwaysUpdateLocalPlayer(IEnumerable<CodeInstruction> instructions)
{
//IL_006b: Unknown result type (might be due to invalid IL or missing references)
//IL_0070: Unknown result type (might be due to invalid IL or missing references)
//IL_0083: Unknown result type (might be due to invalid IL or missing references)
//IL_009b: Expected O, but got Unknown
//IL_00b8: 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_00d1: Unknown result type (might be due to invalid IL or missing references)
//IL_00ea: Expected O, but got Unknown
if (!MattyFixes.PluginConfig.BadgeFixes.Enabled.Value)
{
return instructions;
}
List<CodeInstruction> list = instructions.ToList();
FieldInfo field = typeof(GameNetworkManager).GetField("localPlayerController");
Label? label = default(Label?);
for (int i = 0; i < list.Count; i++)
{
CodeInstruction val = list[i];
if (CodeInstructionExtensions.LoadsField(val, field, false) && CodeInstructionExtensions.Branches(list[i + 2], ref label))
{
for (int j = i - 5; j < i + 2; j++)
{
list[j] = new CodeInstruction(OpCodes.Nop, (object)null)
{
labels = list[j].labels,
blocks = list[j].blocks
};
}
list[i + 2] = new CodeInstruction(OpCodes.Br, (object)label)
{
labels = list[i + 2].labels,
blocks = list[i + 2].blocks
};
MattyFixes.Log.LogDebug((object)"SyncAllPlayerLevelsClientRpc patched!");
break;
}
}
return list;
}
}
[HarmonyPatch]
internal class RadarPatch
{
[HarmonyPatch]
internal class ItemInShipPatch
{
[HarmonyPostfix]
[HarmonyPatch(typeof(GrabbableObject), "LateUpdate")]
[HarmonyPriority(0)]
private static void UpdatePatch(GrabbableObject __instance, bool __runOriginal)
{
if (__runOriginal && MattyFixes.PluginConfig.Radar.RemoveOnShip.Value && __instance.isInShipRoom && (Object)(object)__instance.radarIcon != (Object)null)
{
Object.Destroy((Object)(object)((Component)__instance.radarIcon).gameObject);
}
}
}
[HarmonyPatch]
internal class DeletedObjectPatch
{
[HarmonyPrefix]
[HarmonyPatch(typeof(NetworkBehaviour), "OnDestroy")]
private static void DestroyPatch(NetworkBehaviour __instance)
{
if (MattyFixes.PluginConfig.Radar.Enabled.Value && MattyFixes.PluginConfig.Radar.RemoveDeleted.Value)
{
GrabbableObject val = (GrabbableObject)(object)((__instance is GrabbableObject) ? __instance : null);
if ((Object)(object)val != (Object)null && (Object)(object)val.radarIcon != (Object)null && (Object)(object)((Component)val.radarIcon).gameObject != (Object)null)
{
Object.Destroy((Object)(object)((Component)val.radarIcon).gameObject);
}
}
}
}
}
[HarmonyPatch]
internal class StartOfRoundPatch
{
internal static bool _isInitializingGame;
[HarmonyPrefix]
[HarmonyPatch(typeof(StartOfRound), "Start")]
private static void MarkServerStart(StartOfRound __instance)
{
_isInitializingGame = true;
((MonoBehaviour)__instance).StartCoroutine(WaitCoupleOfFrames());
}
private static IEnumerator WaitCoupleOfFrames()
{
yield return (object)new WaitForEndOfFrame();
yield return (object)new WaitForEndOfFrame();
yield return (object)new WaitForEndOfFrame();
_isInitializingGame = false;
}
}
}
namespace MattyFixes.Dependency
{
public static class LethalConfigProxy
{
[Serializable]
[CompilerGenerated]
private sealed class <>c__7<T> where T : Enum
{
public static readonly <>c__7<T> <>9 = new <>c__7<T>();
public static CanModifyDelegate <>9__7_0;
internal CanModifyResult <AddConfig>b__7_0()
{
//IL_000b: Unknown result type (might be due to invalid IL or missing references)
return CanModifyResult.op_Implicit((false, "THIS IS A FLAG TYPE ENUM, EDITING CURRENTLY NOT SUPPORTED!"));
}
}
private static bool? _enabled;
public static bool Enabled
{
get
{
bool valueOrDefault = _enabled.GetValueOrDefault();
if (!_enabled.HasValue)
{
valueOrDefault = Chainloader.PluginInfos.ContainsKey("ainavt.lc.lethalconfig");
_enabled = valueOrDefault;
}
return _enabled.Value;
}
}
[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
public static void AddConfig(ConfigEntry<string> entry, bool requiresRestart = false)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0006: 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_001e: Expected O, but got Unknown
//IL_0019: Unknown result type (might be due to invalid IL or missing references)
//IL_0023: Expected O, but got Unknown
LethalConfigManager.AddConfigItem((BaseConfigItem)new TextInputFieldConfigItem(entry, new TextInputFieldOptions
{
RequiresRestart = requiresRestart,
Name = GetPrettyConfigName<string>(entry)
}));
}
[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
public static void AddConfig(ConfigEntry<bool> entry, bool requiresRestart = false)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0006: 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_001e: Expected O, but got Unknown
//IL_0019: Unknown result type (might be due to invalid IL or missing references)
//IL_0023: Expected O, but got Unknown
LethalConfigManager.AddConfigItem((BaseConfigItem)new BoolCheckBoxConfigItem(entry, new BoolCheckBoxOptions
{
RequiresRestart = requiresRestart,
Name = GetPrettyConfigName<bool>(entry)
}));
}
[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
public static void AddConfig(ConfigEntry<float> entry, bool requiresRestart = false)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0006: 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_001e: Expected O, but got Unknown
//IL_0019: Unknown result type (might be due to invalid IL or missing references)
//IL_0023: Expected O, but got Unknown
LethalConfigManager.AddConfigItem((BaseConfigItem)new FloatInputFieldConfigItem(entry, new FloatInputFieldOptions
{
RequiresRestart = requiresRestart,
Name = GetPrettyConfigName<float>(entry)
}));
}
[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
public static void AddConfig(ConfigEntry<int> entry, bool requiresRestart = false)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0006: 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_001e: Expected O, but got Unknown
//IL_0019: Unknown result type (might be due to invalid IL or missing references)
//IL_0023: Expected O, but got Unknown
LethalConfigManager.AddConfigItem((BaseConfigItem)new IntInputFieldConfigItem(entry, new IntInputFieldOptions
{
RequiresRestart = requiresRestart,
Name = GetPrettyConfigName<int>(entry)
}));
}
[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
public static void AddConfig<T>(ConfigEntry<T> entry, bool requiresRestart = false) where T : Enum
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0006: 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_0037: Expected O, but got Unknown
//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_002d: Expected O, but got Unknown
EnumDropDownOptions val = new EnumDropDownOptions
{
RequiresRestart = requiresRestart
};
object obj = <>c__7<T>.<>9__7_0;
if (obj == null)
{
CanModifyDelegate val2 = () => CanModifyResult.op_Implicit((false, "THIS IS A FLAG TYPE ENUM, EDITING CURRENTLY NOT SUPPORTED!"));
<>c__7<T>.<>9__7_0 = val2;
obj = (object)val2;
}
((BaseOptions)val).CanModifyCallback = (CanModifyDelegate)obj;
LethalConfigManager.AddConfigItem((BaseConfigItem)(object)new EnumDropDownConfigItem<T>(entry, val));
}
[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
public static void AddButton(string section, string name, string description, string buttonText, Action callback)
{
//IL_0019: Unknown result type (might be due to invalid IL or missing references)
//IL_0023: Expected O, but got Unknown
//IL_001e: Unknown result type (might be due to invalid IL or missing references)
//IL_0028: Expected O, but got Unknown
LethalConfigManager.AddConfigItem((BaseConfigItem)new GenericButtonConfigItem(section, name, description, buttonText, (GenericButtonHandler)delegate
{
callback?.Invoke();
}));
}
private static string GetPrettyConfigName<T>(ConfigEntry<T> entry)
{
return CultureInfo.InvariantCulture.TextInfo.ToTitleCase(((ConfigEntryBase)entry).Definition.Key.Replace("_", " "));
}
}
public static class LethalLevelLoaderProxy
{
private static bool? _enabled;
public static bool Enabled
{
get
{
bool valueOrDefault = _enabled.GetValueOrDefault();
if (!_enabled.HasValue)
{
valueOrDefault = Chainloader.PluginInfos.ContainsKey("imabatby.lethallevelloader");
_enabled = valueOrDefault;
}
return _enabled.Value;
}
}
[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
public static void GetModdedItems([NotNull] in Dictionary<Item, Tuple<string, string>> items)
{
//IL_0025: Unknown result type (might be due to invalid IL or missing references)
MattyFixes.Log.LogWarning((object)"LethalLevelLoader found, reading PatchedContent.ExtendedItems");
foreach (ExtendedItem extendedItem in PatchedContent.ExtendedItems)
{
if ((int)((ExtendedContent)extendedItem).ContentType != 0)
{
items.TryAdd(extendedItem.Item, new Tuple<string, string>("LethalLevelLoader", ((ExtendedContent)extendedItem).ModName));
}
}
}
}
public static class LethalLibProxy
{
private static bool? _enabled;
public static bool Enabled
{
get
{
bool valueOrDefault = _enabled.GetValueOrDefault();
if (!_enabled.HasValue)
{
valueOrDefault = Chainloader.PluginInfos.ContainsKey("evaisa.lethallib");
_enabled = valueOrDefault;
}
return _enabled.Value;
}
}
[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
public static void GetModdedItems([NotNull] in Dictionary<Item, Tuple<string, string>> items)
{
MattyFixes.Log.LogWarning((object)"LethalLib found, reading Items.scrapItems");
foreach (ScrapItem scrapItem in Items.scrapItems)
{
items.TryAdd(scrapItem.item, new Tuple<string, string>("LethalLib", scrapItem.modName));
}
foreach (PlainItem plainItem in Items.plainItems)
{
items.TryAdd(plainItem.item, new Tuple<string, string>("LethalLib", plainItem.modName));
}
foreach (ShopItem shopItem in Items.shopItems)
{
items.TryAdd(shopItem.item, new Tuple<string, string>("LethalLib", shopItem.modName));
}
}
}
public static class LobbyCompatibilityChecker
{
public static bool Enabled => Chainloader.PluginInfos.ContainsKey("BMX.LobbyCompatibility");
[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
public static void Init()
{
PluginHelper.RegisterPlugin("mattymatty.MattyFixes", Version.Parse("1.1.32"), (CompatibilityLevel)0, (VersionStrictness)2);
}
}
}
namespace System.Runtime.CompilerServices
{
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
internal sealed class IgnoresAccessChecksToAttribute : Attribute
{
public IgnoresAccessChecksToAttribute(string assemblyName)
{
}
}
}