Decompiled source of DataCompany v1.0.3

DataCompanyMod.dll

Decompiled 11 months ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using DataCompanyMod.Patches;
using DataCompanyMod.ScrapItems;
using GameNetcodeStuff;
using HarmonyLib;
using LethalLib.Modules;
using Microsoft.CodeAnalysis;
using Unity.Netcode;
using UnityEngine;

[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")]
[assembly: AssemblyCompany("DataCompanyMod")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Chdata's Data Company")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+663b8bdef55fbee75665a80b40db2e5a0965cf61")]
[assembly: AssemblyProduct("DataCompanyMod")]
[assembly: AssemblyTitle("DataCompanyMod")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace DataCompanyMod
{
	[BepInPlugin("DataCompanyMod", "DataCompanyMod", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		private readonly Harmony harmony = new Harmony("DataCompanyMod");

		internal static ManualLogSource Logger;

		private ConfigEntry<int> configStaleBreadRarity;

		public static AssetBundle ChdataAssetBundle;

		public static Item StaleBreadItem;

		private void Awake()
		{
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Expected O, but got Unknown
			Logger = ((BaseUnityPlugin)this).Logger;
			Logger.LogInfo((object)"DATA COMPANY LOADED");
			Logger.LogInfo((object)"DATA COMPANY LOADED");
			Logger.LogInfo((object)"DATA COMPANY LOADED");
			configStaleBreadRarity = ((BaseUnityPlugin)this).Config.Bind<int>("Settings", "Stale Bread Rarity", 30, new ConfigDescription("How rare Stale Bread is to find. Lower values = More rare. 0 to MAYBE prevent spawning.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 100), Array.Empty<object>()));
			LoadAssets();
			harmony.PatchAll(typeof(Plugin));
			harmony.PatchAll(typeof(Cheats));
			harmony.PatchAll(typeof(StaleBread));
		}

		private void LoadAssets()
		{
			string text = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "datacompany.assetbundle");
			Logger.LogDebug((object)text);
			ChdataAssetBundle = AssetBundle.LoadFromFile(text);
			if ((Object)(object)ChdataAssetBundle == (Object)null)
			{
				Logger.LogError((object)"Failed to load Chdata's Assets Bundle. File \"datacompany.assetbundle\" belongs in the same folder as the .dll");
			}
			else
			{
				Logger.LogDebug((object)"Succeeded in loading Chdata Assets Bundle.");
			}
			StaleBreadItem = ChdataAssetBundle.LoadAsset<Item>("Assets/Import/StaleBread/StaleBread.asset");
			if ((Object)(object)StaleBreadItem == (Object)null)
			{
				Logger.LogError((object)"Failed to load Stale Bread item. File \"datacompany.assetbundle\" belongs in the same folder as the .dll");
				return;
			}
			Logger.LogDebug((object)"Succeeded in loading Stale Bread item.");
			NetworkPrefabs.RegisterNetworkPrefab(StaleBreadItem.spawnPrefab);
			Items.RegisterScrap(StaleBreadItem, configStaleBreadRarity.Value, (LevelTypes)510);
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "DataCompanyMod";

		public const string PLUGIN_NAME = "DataCompanyMod";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace DataCompanyMod.ScrapItems
{
	internal class StaleBread
	{
		[HarmonyPatch(typeof(PlayerControllerB), "DropAllHeldItems")]
		[HarmonyPrefix]
		private static bool OnDropAllHeldItems(PlayerControllerB __instance, bool itemsFall, bool disconnecting)
		{
			//IL_00b2: 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)
			//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
			int num = 0;
			for (int i = 0; i < __instance.ItemSlots.Length; i++)
			{
				GrabbableObject val = __instance.ItemSlots[i];
				if ((Object)(object)val == (Object)null)
				{
					continue;
				}
				if (val.itemProperties.itemName == "Stale bread")
				{
					num++;
					continue;
				}
				if (itemsFall)
				{
					val.parentObject = null;
					val.heldByPlayerOnServer = false;
					if (__instance.isInElevator)
					{
						((Component)val).transform.SetParent(__instance.playersManager.elevatorTransform, true);
					}
					else
					{
						((Component)val).transform.SetParent(__instance.playersManager.propsContainer, true);
					}
					__instance.SetItemInElevator(__instance.isInHangarShipRoom, __instance.isInElevator, val);
					val.EnablePhysics(true);
					val.EnableItemMeshes(true);
					((Component)val).transform.localScale = val.originalScale;
					val.isHeld = false;
					val.isPocketed = false;
					val.startFallingPosition = ((Component)val).transform.parent.InverseTransformPoint(((Component)val).transform.position);
					val.FallToGround(true);
					val.fallTime = Random.Range(-0.3f, 0.05f);
					if (((NetworkBehaviour)__instance).IsOwner)
					{
						val.DiscardItemOnClient();
					}
					else if (!val.itemProperties.syncDiscardFunction)
					{
						val.playerHeldBy = null;
					}
				}
				if (((NetworkBehaviour)__instance).IsOwner && !disconnecting)
				{
					((Behaviour)HUDManager.Instance.holdingTwoHandedItem).enabled = false;
					((Behaviour)HUDManager.Instance.itemSlotIcons[i]).enabled = false;
					HUDManager.Instance.ClearControlTips();
					__instance.activatingItem = false;
				}
				__instance.ItemSlots[i] = null;
			}
			if (__instance.isHoldingObject)
			{
				__instance.isHoldingObject = false;
				if ((Object)(object)__instance.currentlyHeldObjectServer != (Object)null)
				{
					((object)__instance).GetType().GetMethod("SetSpecialGrabAnimationBool", BindingFlags.Instance | BindingFlags.NonPublic).Invoke(__instance, new object[2] { false, __instance.currentlyHeldObjectServer });
				}
				__instance.playerBodyAnimator.SetBool("cancelHolding", true);
				__instance.playerBodyAnimator.SetTrigger("Throw");
			}
			__instance.activatingItem = false;
			__instance.twoHanded = false;
			__instance.carryWeight = 1f;
			__instance.currentlyHeldObjectServer = null;
			if (num >= 4)
			{
				((MonoBehaviour)__instance).StartCoroutine(SpawnBreadAtPlayer(__instance));
			}
			return false;
		}

		[HarmonyPatch(typeof(ShipTeleporter), "TeleportPlayerOutWithInverseTeleporter")]
		[HarmonyPostfix]
		private static void OnTeleportPlayerOutWithInverseTeleporter(ShipTeleporter __instance, int playerObj, Vector3 teleportPos)
		{
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: 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)
			PlayerControllerB val = StartOfRound.Instance.allPlayerScripts[playerObj];
			if (val.isPlayerDead)
			{
				return;
			}
			GrabbableObject[] array = Object.FindObjectsOfType<GrabbableObject>();
			foreach (GrabbableObject val2 in array)
			{
				if (!(val2.itemProperties.itemName != "Stale bread") && !(Vector3.Distance(((Component)val2).transform.position, __instance.teleportOutPosition.position) >= 2f))
				{
					Vector3 serverPlayerPosition = val.serverPlayerPosition;
					serverPlayerPosition.y += 1f;
					DropGrabbableObjectAtPosition(val2, serverPlayerPosition);
				}
			}
		}

		private static IEnumerator SpawnBreadAtPlayer(PlayerControllerB thePlayer)
		{
			yield return (object)new WaitForSeconds(0.5f);
			if (!thePlayer.isPlayerDead)
			{
				CreateBreadAtLocation(thePlayer.serverPlayerPosition);
			}
		}

		public static void CreateBreadAtLocation(Vector3 spawnPos)
		{
			//IL_001a: 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_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_0086: 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_00b2: 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_00ba: Unknown result type (might be due to invalid IL or missing references)
			spawnPos.y += 1f;
			GameObject obj = Object.Instantiate<GameObject>(Plugin.StaleBreadItem.spawnPrefab, spawnPos, Quaternion.identity);
			GrabbableObject component = obj.GetComponent<GrabbableObject>();
			((Component)component).transform.rotation = Quaternion.Euler(component.itemProperties.restingRotation);
			component.fallTime = 0f;
			component.scrapValue = Random.Range(8, 15);
			NetworkObject component2 = obj.GetComponent<NetworkObject>();
			component2.Spawn(false);
			List<int> list = new List<int>();
			List<NetworkObjectReference> list2 = new List<NetworkObjectReference>();
			list.Add(component.scrapValue);
			list2.Add(NetworkObjectReference.op_Implicit(component2));
			GrabbableObject val = component;
			int num = 0;
			NetworkObjectReference[] array = (NetworkObjectReference[])(object)new NetworkObjectReference[list2.Count];
			foreach (NetworkObjectReference item in list2)
			{
				array[num] = item;
				num++;
			}
			NetworkObjectReference[] spawnedScrap = array;
			int num2 = 0;
			int[] array2 = new int[list.Count];
			foreach (int item2 in list)
			{
				array2[num2] = item2;
				num2++;
			}
			((MonoBehaviour)val).StartCoroutine(WaitForScrapToSpawnToSync(spawnedScrap, array2));
		}

		private static IEnumerator WaitForScrapToSpawnToSync(NetworkObjectReference[] spawnedScrap, int[] scrapValues)
		{
			yield return (object)new WaitForSeconds(1f);
			RoundManager.Instance.SyncScrapValuesClientRpc(spawnedScrap, scrapValues);
		}

		public static void DropGrabbableObjectAtPosition(GrabbableObject grabbableObject, Vector3 telePos)
		{
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			grabbableObject.parentObject = null;
			grabbableObject.heldByPlayerOnServer = false;
			PlayerControllerB playerHeldBy = grabbableObject.playerHeldBy;
			if ((Object)(object)playerHeldBy != (Object)null)
			{
				if (playerHeldBy.isInElevator)
				{
					((Component)grabbableObject).transform.SetParent(playerHeldBy.playersManager.elevatorTransform, true);
				}
				else
				{
					((Component)grabbableObject).transform.SetParent(playerHeldBy.playersManager.propsContainer, true);
				}
				playerHeldBy.SetItemInElevator(playerHeldBy.isInHangarShipRoom, playerHeldBy.isInElevator, grabbableObject);
			}
			grabbableObject.EnablePhysics(true);
			grabbableObject.EnableItemMeshes(true);
			((Component)grabbableObject).transform.localScale = grabbableObject.originalScale;
			grabbableObject.isHeld = false;
			grabbableObject.isPocketed = false;
			((Component)grabbableObject).transform.position = telePos;
			grabbableObject.startFallingPosition = telePos;
			grabbableObject.FallToGround(true);
			grabbableObject.fallTime = Random.Range(-0.3f, 0.05f);
			if (!((Object)(object)playerHeldBy != (Object)null))
			{
				return;
			}
			if (((NetworkBehaviour)playerHeldBy).IsOwner)
			{
				grabbableObject.DiscardItemOnClient();
			}
			else if (!grabbableObject.itemProperties.syncDiscardFunction)
			{
				grabbableObject.playerHeldBy = null;
			}
			int num = -1;
			for (int i = 0; i < playerHeldBy.ItemSlots.Length; i++)
			{
				if ((Object)(object)playerHeldBy.ItemSlots[i] == (Object)(object)grabbableObject)
				{
					num = i;
					break;
				}
			}
			if (num != -1)
			{
				if (((NetworkBehaviour)playerHeldBy).IsOwner)
				{
					((Behaviour)HUDManager.Instance.holdingTwoHandedItem).enabled = false;
					((Behaviour)HUDManager.Instance.itemSlotIcons[num]).enabled = false;
					HUDManager.Instance.ClearControlTips();
					playerHeldBy.activatingItem = false;
				}
				playerHeldBy.ItemSlots[num] = null;
			}
		}
	}
}
namespace DataCompanyMod.Patches
{
	internal class Cheats
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}