Decompiled source of JeidoCommunityProps v1.0.0

BepInEx/plugins/jeido/JeidoPack.dll

Decompiled 6 hours ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using JeidoPack.Handlers;
using JeidoPack.Networking;
using JeidoPack.Scrap;
using LethalLib.Modules;
using Microsoft.CodeAnalysis;
using Unity.Collections;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.UIElements.Collections;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: AssemblyCompany("JeidoPack")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Scrap from Jeido's Community")]
[assembly: AssemblyFileVersion("0.1.0.0")]
[assembly: AssemblyInformationalVersion("0.1.0")]
[assembly: AssemblyProduct("JeidoPack")]
[assembly: AssemblyTitle("JeidoPack")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.1.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[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]
	[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;
		}
	}
	[CompilerGenerated]
	[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 JeidoPack
{
	[BepInPlugin("JeidoPack", "JeidoPack", "0.1.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class JeidoPack : BaseUnityPlugin
	{
		internal ScrapHandler scrapHandler = new ScrapHandler();

		public static JeidoPack Instance { get; private set; }

		internal static ManualLogSource Logger { get; private set; }

		internal static Harmony? Harmony { get; set; }

		public static AssetBundle Bundle { get; private set; }

		private void Awake()
		{
			Instance = this;
			Logger = ((BaseUnityPlugin)this).Logger;
			string directoryName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
			Bundle = AssetBundle.LoadFromFile(Path.Combine(directoryName, "jeido"));
			if ((Object)(object)Bundle == (Object)null)
			{
				Logger.LogError((object)"Failled to load custom assets!");
				return;
			}
			ScrapItemRegistry.Initialize();
			Patch();
			Logger.LogInfo((object)"JeidoPack v0.1.0 (JeidoPack) has loaded!");
		}

		internal static void Patch()
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Expected O, but got Unknown
			if (Harmony == null)
			{
				Harmony = new Harmony("JeidoPack");
			}
			Logger.LogDebug((object)"Patching...");
			Harmony.PatchAll();
			Logger.LogDebug((object)"Finished patching!");
		}

		internal static void Unpatch()
		{
			Logger.LogDebug((object)"Unpatching...");
			Harmony? harmony = Harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
			Logger.LogDebug((object)"Finished unpatching!");
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "JeidoPack";

		public const string PLUGIN_NAME = "JeidoPack";

		public const string PLUGIN_VERSION = "0.1.0";
	}
}
namespace JeidoPack.Scrap
{
	public abstract class BaseScrapItem(GrabbableObject scrap)
	{
		public GrabbableObject Scrap { get; protected set; } = scrap;

		public PlayerControllerB HoldingPlayer { get; set; } = scrap.playerHeldBy;
	}
	internal sealed class ScrapItemAttribute(string scrapName, int rarity = 100, LevelTypes levels = (LevelTypes)(-1)) : Attribute()
	{
		internal string ScrapName { get; } = scrapName;

		internal int Rarity { get; } = rarity;

		internal LevelTypes Levels { get; } = levels;
	}
	internal static class ScrapItemRegistry
	{
		private static readonly Dictionary<string, Type> _registry = new Dictionary<string, Type>();

		internal static void Initialize()
		{
			//IL_0129: Unknown result type (might be due to invalid IL or missing references)
			_registry.Clear();
			Type[] types = Assembly.GetExecutingAssembly().GetTypes();
			foreach (Type type in types)
			{
				if (type.IsAbstract || !type.IsSubclassOf(typeof(BaseScrapItem)))
				{
					continue;
				}
				ScrapItemAttribute customAttribute = type.GetCustomAttribute<ScrapItemAttribute>();
				if (customAttribute == null)
				{
					continue;
				}
				if (_registry.ContainsKey(customAttribute.ScrapName))
				{
					JeidoPack.Logger.LogWarning((object)("ScrapItemRegistry: duplicate registration for '" + customAttribute.ScrapName + "' - '" + type.Name + "' will be ignored."));
					continue;
				}
				if (JeidoPack.Bundle.Contains("Assets/Prefabs/Items/" + customAttribute.ScrapName + "Item.asset"))
				{
					Item val = JeidoPack.Bundle.LoadAsset<Item>("Assets/Prefabs/Items/" + customAttribute.ScrapName + "Item.asset");
					NetworkPrefabs.RegisterNetworkPrefab(val.spawnPrefab);
					Utilities.FixMixerGroups(val.spawnPrefab);
					Items.RegisterScrap(val, customAttribute.Rarity, customAttribute.Levels);
				}
				_registry.Add(customAttribute.ScrapName, type);
				JeidoPack.Logger.LogInfo((object)("ScrapItemRegistry: registered '" + customAttribute.ScrapName + "' - '" + type.Name + "'"));
			}
			JeidoPack.Logger.LogInfo((object)$"ScrapItemRegistry: {_registry.Count} item type(s) registered.");
		}

		internal static BaseScrapItem? Create(GrabbableObject scrapItem)
		{
			string text = ((Object)scrapItem).name.Replace("(Clone)", "").Trim();
			if (!_registry.TryGetValue(text, out Type value))
			{
				JeidoPack.Logger.LogInfo((object)("ScrapItemRegistry: no handler registered for '" + text + "'."));
				return null;
			}
			try
			{
				ConstructorInfo constructorInfo = value.GetConstructor(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, new Type[1] { typeof(GrabbableObject) }, null) ?? throw new MissingMethodException("No constructor(GrabbableObject) found on " + value.Name + " !");
				return (BaseScrapItem)constructorInfo.Invoke(new object[1] { scrapItem });
			}
			catch (Exception arg)
			{
				JeidoPack.Logger.LogError((object)$"ScrapItemRegistry: failed to create '{value.Name}' for '{text}': {arg}");
				return null;
			}
		}

		internal static bool IsRegistered(string scrapName)
		{
			return _registry.ContainsKey(scrapName);
		}
	}
}
namespace JeidoPack.Scrap.Items
{
	[ScrapItem(/*Could not decode attribute arguments.*/)]
	internal class AbaraQuack : BaseScrapItem
	{
		public AbaraQuack(GrabbableObject abaraQuack)
			: base(abaraQuack)
		{
		}
	}
	[ScrapItem(/*Could not decode attribute arguments.*/)]
	internal class Cone : BaseScrapItem
	{
		public Cone(GrabbableObject cone)
			: base(cone)
		{
		}
	}
	[ScrapItem(/*Could not decode attribute arguments.*/)]
	internal class FireWalk : BaseScrapItem
	{
		public FireWalk(GrabbableObject fireWalk)
			: base(fireWalk)
		{
		}
	}
	[ScrapItem(/*Could not decode attribute arguments.*/)]
	internal class GexQuack : BaseScrapItem
	{
		public GexQuack(GrabbableObject gexQuack)
			: base(gexQuack)
		{
		}
	}
	[ScrapItem(/*Could not decode attribute arguments.*/)]
	internal class JeidoPlush : BaseScrapItem
	{
		public JeidoPlush(GrabbableObject jeidoPlush)
			: base(jeidoPlush)
		{
		}
	}
	[ScrapItem(/*Could not decode attribute arguments.*/)]
	internal class JeidoQuack : BaseScrapItem
	{
		public JeidoQuack(GrabbableObject jeidoQuack)
			: base(jeidoQuack)
		{
		}
	}
	[ScrapItem(/*Could not decode attribute arguments.*/)]
	internal class MetwoQuack : BaseScrapItem
	{
		public MetwoQuack(GrabbableObject metwoQuack)
			: base(metwoQuack)
		{
		}
	}
	[ScrapItem(/*Could not decode attribute arguments.*/)]
	internal class Noodles : BaseScrapItem
	{
		public Noodles(GrabbableObject cupNoodle)
			: base(cupNoodle)
		{
		}
	}
	[ScrapItem(/*Could not decode attribute arguments.*/)]
	internal class ShayPlush : BaseScrapItem
	{
		public ShayPlush(GrabbableObject shayPlush)
			: base(shayPlush)
		{
		}
	}
	[ScrapItem(/*Could not decode attribute arguments.*/)]
	internal class ShayQuack : BaseScrapItem
	{
		public ShayQuack(GrabbableObject shayQuack)
			: base(shayQuack)
		{
		}
	}
	[ScrapItem(/*Could not decode attribute arguments.*/)]
	internal class Tire : BaseScrapItem
	{
		public Tire(GrabbableObject tire)
			: base(tire)
		{
		}
	}
}
namespace JeidoPack.Patches
{
	[HarmonyPatch(typeof(PlayerControllerB))]
	internal class PlayerControllerBPatches
	{
		private static readonly JeidoPack pluginInstance = JeidoPack.Instance;

		[HarmonyPatch("GrabObjectServerRpc")]
		[HarmonyPostfix]
		private static void PickUpScrapItem(NetworkObjectReference grabbedObject)
		{
			NetworkObject val = default(NetworkObject);
			((NetworkObjectReference)(ref grabbedObject)).TryGet(ref val, (NetworkManager)null);
			GrabbableObject componentInChildren = ((Component)val).gameObject.GetComponentInChildren<GrabbableObject>();
			BaseScrapItem baseScrapItem = pluginInstance.scrapHandler.RegisterScrapItem(componentInChildren);
			if (baseScrapItem != null)
			{
				SyncManager.BroadcastItemRegistered(((NetworkBehaviour)componentInChildren).NetworkObjectId);
			}
			JeidoPack.Logger.LogInfo((object)$"{((Object)componentInChildren).name} picked up by {componentInChildren.playerHeldBy}");
		}
	}
}
namespace JeidoPack.Networking
{
	[HarmonyPatch]
	internal static class SyncManager
	{
		[CompilerGenerated]
		private static class <>O
		{
			public static HandleNamedMessageDelegate <0>__OnSyncItemRegisteredClientRpc;

			public static HandleNamedMessageDelegate <1>__OnSyncItemRemovedClientRpc;
		}

		internal static bool IsSynced { get; private set; }

		internal static bool HostHasMod { get; private set; }

		[HarmonyPatch(typeof(StartOfRound), "Awake")]
		[HarmonyPrefix]
		public static void ResetValues()
		{
			IsSynced = false;
			HostHasMod = false;
		}

		[HarmonyPatch(typeof(PlayerControllerB), "ConnectClientToPlayerObject")]
		[HarmonyPostfix]
		public static void Init(PlayerControllerB __instance)
		{
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Expected O, but got Unknown
			//IL_0071: 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_007c: Expected O, but got Unknown
			if (NetworkManager.Singleton.IsServer)
			{
				IsSynced = true;
				HostHasMod = true;
				return;
			}
			CustomMessagingManager customMessagingManager = NetworkManager.Singleton.CustomMessagingManager;
			object obj = <>O.<0>__OnSyncItemRegisteredClientRpc;
			if (obj == null)
			{
				HandleNamedMessageDelegate val = OnSyncItemRegisteredClientRpc;
				<>O.<0>__OnSyncItemRegisteredClientRpc = val;
				obj = (object)val;
			}
			customMessagingManager.RegisterNamedMessageHandler("JeidoPack.SyncItemRegisteredClientRpc", (HandleNamedMessageDelegate)obj);
			CustomMessagingManager customMessagingManager2 = NetworkManager.Singleton.CustomMessagingManager;
			object obj2 = <>O.<1>__OnSyncItemRemovedClientRpc;
			if (obj2 == null)
			{
				HandleNamedMessageDelegate val2 = OnSyncItemRemovedClientRpc;
				<>O.<1>__OnSyncItemRemovedClientRpc = val2;
				obj2 = (object)val2;
			}
			customMessagingManager2.RegisterNamedMessageHandler("JeidoPack.SyncItemRemovedClientRpc", (HandleNamedMessageDelegate)obj2);
		}

		public static void BroadcastItemRegistered(ulong networkObjectId)
		{
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			if (NetworkManager.Singleton.IsServer)
			{
				FastBufferWriter val = default(FastBufferWriter);
				((FastBufferWriter)(ref val))..ctor(12, (Allocator)2, -1);
				((FastBufferWriter)(ref val)).WriteValue<ulong>(ref networkObjectId, default(ForPrimitives));
				NetworkManager.Singleton.CustomMessagingManager.SendNamedMessageToAll("JeidoPack.SyncItemRegisteredClientRpc", val, (NetworkDelivery)3);
				JeidoPack.Logger.LogInfo((object)$"SyncManager: Broadcast item registered: id={networkObjectId}");
			}
		}

		public static void BroadcastItemRemoved(ulong networkObjectId)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			if (NetworkManager.Singleton.IsServer)
			{
				FastBufferWriter val = default(FastBufferWriter);
				((FastBufferWriter)(ref val))..ctor(8, (Allocator)2, -1);
				((FastBufferWriter)(ref val)).WriteValue<ulong>(ref networkObjectId, default(ForPrimitives));
				NetworkManager.Singleton.CustomMessagingManager.SendNamedMessageToAll("JeidoPack.SyncItemRemovedClientRpc", val, (NetworkDelivery)3);
				JeidoPack.Logger.LogInfo((object)$"SyncManager: Broadcast item removed id={networkObjectId}");
			}
		}

		private static void OnSyncItemRemovedClientRpc(ulong senderClientId, FastBufferReader messagePayload)
		{
			//IL_001a: 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)
			if (NetworkManager.Singleton.IsClient)
			{
				ulong num = default(ulong);
				((FastBufferReader)(ref messagePayload)).ReadValue<ulong>(ref num, default(ForPrimitives));
				JeidoPack.Logger.LogInfo((object)$"SyncManager: Received item removed: id={num}");
				JeidoPack.Instance.scrapHandler.RemoveScrapItemByNetworkId(num);
			}
		}

		private static void OnSyncItemRegisteredClientRpc(ulong senderClientId, FastBufferReader messagePayload)
		{
			//IL_001a: 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)
			if (NetworkManager.Singleton.IsClient)
			{
				ulong num = default(ulong);
				((FastBufferReader)(ref messagePayload)).ReadValue<ulong>(ref num, default(ForPrimitives));
				JeidoPack.Logger.LogInfo((object)$"SyncManager: Received item registered: id={num}");
				JeidoPack.Instance.scrapHandler.RegisterScrapItemFromNetwork(num);
			}
		}
	}
}
namespace JeidoPack.Networking.Messages
{
	internal static class MessageNames
	{
		internal const string RequestConfigSyncServerRpc = "JeidoPack.RequestConfigSyncServerRpc";

		internal const string RequestConfigSyncClientRpc = "JeidoPack.RequestConfigSyncClientRpc";

		internal const string SyncItemRegisteredClientRpc = "JeidoPack.SyncItemRegisteredClientRpc";

		internal const string SyncItemRemovedClientRpc = "JeidoPack.SyncItemRemovedClientRpc";
	}
}
namespace JeidoPack.Handlers
{
	internal class ScrapHandler
	{
		internal Dictionary<ulong, BaseScrapItem> itemDictionary = new Dictionary<ulong, BaseScrapItem>();

		public BaseScrapItem? RegisterScrapItem(GrabbableObject scrapItem)
		{
			ulong networkObjectId = ((NetworkBehaviour)scrapItem).NetworkObjectId;
			if (!itemDictionary.ContainsKey(networkObjectId))
			{
				BaseScrapItem baseScrapItem = ScrapItemRegistry.Create(scrapItem);
				if (baseScrapItem != null)
				{
					itemDictionary.Add(networkObjectId, baseScrapItem);
					JeidoPack.Logger.LogInfo((object)(((Object)scrapItem).name + " registered in ScrapHandler"));
					return baseScrapItem;
				}
			}
			else if ((Object)(object)scrapItem.playerHeldBy != (Object)null)
			{
				DictionaryExtensions.Get<ulong, BaseScrapItem>((IDictionary<ulong, BaseScrapItem>)itemDictionary, networkObjectId, (BaseScrapItem)null).HoldingPlayer = scrapItem.playerHeldBy;
				return DictionaryExtensions.Get<ulong, BaseScrapItem>((IDictionary<ulong, BaseScrapItem>)itemDictionary, networkObjectId, (BaseScrapItem)null);
			}
			return null;
		}

		public void RegisterScrapItemFromNetwork(ulong networkObjectId)
		{
			if (!NetworkManager.Singleton.SpawnManager.SpawnedObjects.TryGetValue(networkObjectId, out var value))
			{
				JeidoPack.Logger.LogError((object)$"ScrapHandler: Could not find spawned object '{networkObjectId}' for sync.");
				return;
			}
			GrabbableObject componentInChildren = ((Component)value).gameObject.GetComponentInChildren<GrabbableObject>();
			if ((Object)(object)componentInChildren == (Object)null)
			{
				JeidoPack.Logger.LogError((object)$"ScrapHandler: No GrabbableObject on network object '{networkObjectId}'.");
			}
			else
			{
				RegisterScrapItem(componentInChildren);
			}
		}

		internal void RemoveScrapItemByNetworkId(ulong networkObjectId)
		{
			if (itemDictionary.Remove(networkObjectId))
			{
				JeidoPack.Logger.LogInfo((object)$"ScrapHandler: removed item '{networkObjectId}'");
			}
			else
			{
				JeidoPack.Logger.LogInfo((object)$"ScrapHandler: failed to remove item '{networkObjectId}' (not found).");
			}
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}