Decompiled source of CartDump v0.1.0

RepoCartDump.dll

Decompiled 16 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 BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Photon.Pun;
using RepoCartDump.Patches;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;

[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: AssemblyCompany("RepoCartDump")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("RepoCartDump")]
[assembly: AssemblyTitle("RepoCartDump")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
}
public static class ModIcons
{
	public static Sprite MyItemIcon;

	public static void Load()
	{
		//IL_0021: Unknown result type (might be due to invalid IL or missing references)
		//IL_0027: Expected O, but got Unknown
		//IL_0048: 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)
		string path = Path.Combine(Paths.PluginPath, "RepoCartDump", "my_item_icon.png");
		byte[] array = File.ReadAllBytes(path);
		Texture2D val = new Texture2D(2, 2, (TextureFormat)4, false);
		ImageConversion.LoadImage(val, array);
		MyItemIcon = Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f), 100f);
	}
}
namespace RepoCartDump
{
	public class CartManager : MonoBehaviour
	{
		private Rigidbody rb;

		private int number = 0;

		private Quaternion lockedRotation;

		private bool rotationLocked = false;

		private void Start()
		{
			rb = ((Component)this).GetComponent<Rigidbody>();
			ItemEquippable component = ((Component)this).GetComponent<ItemEquippable>();
			if ((Object)(object)component != (Object)null)
			{
				component.ItemIcon = ModIcons.MyItemIcon;
			}
		}
	}
	[BepInPlugin("RepoCartDump", "Repo Cart Dump", "0.1.0")]
	public class RepoCartDump : BaseUnityPlugin
	{
		private const string modGUID = "RepoCartDump";

		private const string modName = "Repo Cart Dump";

		private const string modVersion = "0.1.0";

		private readonly Harmony harmony = new Harmony("RepoCartDump");

		private static RepoCartDump instance;

		public static ManualLogSource mls;

		private void Awake()
		{
			if ((Object)(object)instance == (Object)null)
			{
				instance = this;
			}
			mls = Logger.CreateLogSource("RepoCartDump");
			ConfigManager.Initialize(((BaseUnityPlugin)this).Config);
			mls.LogInfo((object)"RepoCartDump is now awake!");
			harmony.PatchAll(typeof(RepoCartDump));
			harmony.PatchAll(typeof(PlayerControllerPatch));
			harmony.PatchAll(typeof(ChatManagerPatch));
			harmony.PatchAll(typeof(PhysGrabCartPatch));
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "RepoCartDump";

		public const string PLUGIN_NAME = "RepoCartDump";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace RepoCartDump.Patches
{
	[HarmonyPatch(typeof(ChatManager))]
	internal class ChatManagerPatch
	{
		public static ChatState chatState;

		[HarmonyPatch("Update")]
		[HarmonyPostfix]
		private static void UpdatePatch(ref ChatState ___chatState)
		{
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			chatState = ___chatState;
		}
	}
	internal class ConfigManager
	{
		public static ConfigEntry<string> rotateKey;

		public static void Initialize(ConfigFile cfg)
		{
			rotateKey = cfg.Bind<string>("Controls", "rotateKey", "x", "The key used to rotate the cart.");
		}
	}
	[HarmonyPatch(typeof(PhysGrabCart))]
	internal class PhysGrabCartPatch
	{
		[HarmonyPatch("Start")]
		[HarmonyPostfix]
		private static void PhysGrabCartStart(PhysGrabCart __instance)
		{
			if (!((Object)(object)RunManager.instance.levelCurrent == (Object)(object)RunManager.instance.levelShop) && (Object)(object)((Component)__instance).GetComponent<CartManager>() == (Object)null)
			{
				((Component)__instance).gameObject.AddComponent<CartManager>();
				((Component)__instance).gameObject.AddComponent<ItemEquippable>();
			}
		}
	}
	public static class PlayerGrabbingTracker
	{
		public static Dictionary<int, GameObject> playerGrabbingMap = new Dictionary<int, GameObject>();

		public static bool IsLocalPlayerGrabbingCart(GameObject cart)
		{
			int actorNumber = PhotonNetwork.LocalPlayer.ActorNumber;
			return playerGrabbingMap.ContainsKey(actorNumber) && (Object)(object)playerGrabbingMap[actorNumber] == (Object)(object)cart;
		}

		public static void SetLocalPlayerGrabbing(GameObject obj)
		{
			int actorNumber = PhotonNetwork.LocalPlayer.ActorNumber;
			if ((Object)(object)obj != (Object)null)
			{
				playerGrabbingMap[actorNumber] = obj;
			}
			else if (playerGrabbingMap.ContainsKey(actorNumber))
			{
				playerGrabbingMap.Remove(actorNumber);
			}
		}
	}
	[HarmonyPatch(typeof(PlayerController))]
	internal class PlayerControllerPatch
	{
		private static List<string> mouseBtns = new List<string> { "leftButton", "rightButton", "middleButton", "forwardButton", "backButton" };

		[HarmonyPatch("Update")]
		[HarmonyPostfix]
		private static void UpdatePatch(PlayerController __instance)
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Invalid comparison between Unknown and I4
			if ((Object)(object)__instance.physGrabObject != (Object)null)
			{
				PlayerGrabbingTracker.SetLocalPlayerGrabbing(__instance.physGrabObject.gameObject);
				if ((int)ChatManagerPatch.chatState != 1 && WasButtonPressedThisFrame(ConfigManager.rotateKey.Value) && (Object)(object)__instance.physGrabObject.GetComponent<CartManager>() != (Object)null)
				{
					CartManager component = __instance.physGrabObject.GetComponent<CartManager>();
					Debug.Log((object)"Joel Du lappi");
				}
			}
			else
			{
				PlayerGrabbingTracker.SetLocalPlayerGrabbing(null);
			}
		}

		private static bool WasButtonPressedThisFrame(string btn)
		{
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			InputControl val = ((!mouseBtns.Contains(btn)) ? ((InputControl)Keyboard.current)[btn] : ((InputControl)Mouse.current)[btn]);
			return ((ButtonControl)val).wasPressedThisFrame;
		}
	}
}