Decompiled source of SharedShops TESTING TEST v1.0.0

SharedShops.dll

Decompiled 4 months ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using Microsoft.CodeAnalysis;
using On.RoR2;
using R2API.Networking;
using R2API.Networking.Interfaces;
using RoR2;
using SharedShops.Networking;
using UnityEngine;
using UnityEngine.Networking;

[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("SharedShops")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("SharedShops")]
[assembly: AssemblyTitle("SharedShops")]
[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 SharedShops
{
	public static class GeneralHooks
	{
		[CompilerGenerated]
		private static class <>O
		{
			public static hook_PlaceTeleporter <0>__OverrideShopCount;
		}

		private static List<string> NoInteractibleOverrideScenes = new List<string> { "MAP_BAZAAR_TITLE", "MAP_ARENA_TITLE", "MAP_LIMBO_TITLE", "MAP_MYSTERYSPACE_TITLE" };

		internal static void Hook()
		{
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Expected O, but got Unknown
			Run.onRunStartGlobal += delegate
			{
				foreach (PlayerCharacterMasterController instance in PlayerCharacterMasterController.instances)
				{
					instance.master.money = 10000u;
				}
			};
			object obj = <>O.<0>__OverrideShopCount;
			if (obj == null)
			{
				hook_PlaceTeleporter val = OverrideShopCount;
				<>O.<0>__OverrideShopCount = val;
				obj = (object)val;
			}
			SceneDirector.PlaceTeleporter += (hook_PlaceTeleporter)obj;
		}

		private static void OverrideShopCount(orig_PlaceTeleporter orig, SceneDirector self)
		{
			//IL_00df: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
			orig.Invoke(self);
			Debug.Log((object)SceneInfo.instance.sceneDef.nameToken);
			int num = 200;
			ClassicStageInfo component = ((Component)SceneInfo.instance).GetComponent<ClassicStageInfo>();
			if (Object.op_Implicit((Object)(object)component))
			{
				num = component.sceneDirectorInteractibleCredits;
				int num2 = Math.Min(Run.instance.participatingPlayerCount, 8);
				float num3 = (float)(0.95 + (double)num2 * 0.05);
				num3 *= (float)Math.Max(1.0 + 0.1 * (double)Math.Min(Run.instance.participatingPlayerCount * 2 - Run.instance.stageClearCount - 2, 3), 1.0);
				num = (int)((float)num / num3);
				if (component.bonusInteractibleCreditObjects != null)
				{
					BonusInteractibleCreditObject[] bonusInteractibleCreditObjects = component.bonusInteractibleCreditObjects;
					foreach (BonusInteractibleCreditObject val in bonusInteractibleCreditObjects)
					{
						if (val.objectThatGrantsPointsIfEnabled.activeSelf)
						{
							num += val.points / num2;
						}
					}
				}
			}
			if (!Object.op_Implicit((Object)(object)SceneInfo.instance) || !NoInteractibleOverrideScenes.Contains(SceneInfo.instance.sceneDef.nameToken))
			{
				self.interactableCredit = num;
			}
		}
	}
	internal static class Log
	{
		private static ManualLogSource _logSource;

		internal static void Init(ManualLogSource logSource)
		{
			_logSource = logSource;
		}

		internal static void Debug(object data)
		{
			_logSource.LogDebug(data);
		}

		internal static void Error(object data)
		{
			_logSource.LogError(data);
		}

		internal static void Fatal(object data)
		{
			_logSource.LogFatal(data);
		}

		internal static void Info(object data)
		{
			_logSource.LogInfo(data);
		}

		internal static void Message(object data)
		{
			_logSource.LogMessage(data);
		}

		internal static void Warning(object data)
		{
			_logSource.LogWarning(data);
		}
	}
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInPlugin("Techtress.SharedShops", "SharedShops", "1.0.0")]
	public class SharedShops : BaseUnityPlugin
	{
		public const string PluginGUID = "Techtress.SharedShops";

		public const string PluginAuthor = "Techtress";

		public const string PluginName = "SharedShops";

		public const string PluginVersion = "1.0.0";

		public const short NetworkMessageType = 5569;

		public void Awake()
		{
			Log.Init(((BaseUnityPlugin)this).Logger);
			LoadHooks();
		}

		private void LoadHooks(object _ = null, EventArgs __ = null)
		{
			GeneralHooks.Hook();
			ShopLocalizerHooks.Hook();
		}
	}
	public static class ShopLocalizerHooks
	{
		[CompilerGenerated]
		private static class <>O
		{
			public static hook_Start <0>__OnShopSpawn;

			public static hook_OnInteractionBegin <1>__OnShopInteract;
		}

		public static Dictionary<NetworkInstanceId, List<int>> PlayerUnlockedChests = new Dictionary<NetworkInstanceId, List<int>>();

		internal static void Hook()
		{
			//IL_0011: 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_001c: Expected O, but got Unknown
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Expected O, but got Unknown
			object obj = <>O.<0>__OnShopSpawn;
			if (obj == null)
			{
				hook_Start val = OnShopSpawn;
				<>O.<0>__OnShopSpawn = val;
				obj = (object)val;
			}
			PurchaseInteraction.Start += (hook_Start)obj;
			object obj2 = <>O.<1>__OnShopInteract;
			if (obj2 == null)
			{
				hook_OnInteractionBegin val2 = OnShopInteract;
				<>O.<1>__OnShopInteract = val2;
				obj2 = (object)val2;
			}
			PurchaseInteraction.OnInteractionBegin += (hook_OnInteractionBegin)obj2;
		}

		private static void OnShopSpawn(orig_Start orig, PurchaseInteraction self)
		{
			orig.Invoke(self);
		}

		private static void OnShopInteract(orig_OnInteractionBegin orig, PurchaseInteraction self, Interactor activator)
		{
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			orig.Invoke(self, activator);
			ChestBehavior component = ((Component)self).GetComponent<ChestBehavior>();
			if (Object.op_Implicit((Object)(object)component))
			{
				CharacterMaster master = ((Component)activator).GetComponent<CharacterBody>().master;
				NetworkInstanceId netId = ((NetworkBehaviour)component).netId;
				short playerControllerId = ((NetworkBehaviour)master).playerControllerId;
				NetMessageExtensions.Send((INetMessage)(object)new ChestOpenMessage(netId, playerControllerId), (NetworkDestination)1);
				component.Roll();
				self.SetAvailable(false);
			}
		}
	}
}
namespace SharedShops.Networking
{
	public class ChestOpenMessage : INetMessage, ISerializableObject
	{
		[CompilerGenerated]
		private sealed class <CloseChest>d__13 : IEnumerator<object>, IEnumerator, IDisposable
		{
			private int <>1__state;

			private object <>2__current;

			public ChestBehavior chest;

			private EntityStateMachine <component>5__1;

			object IEnumerator<object>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <CloseChest>d__13(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<component>5__1 = null;
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_0026: Unknown result type (might be due to invalid IL or missing references)
				//IL_0030: Expected O, but got Unknown
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<>2__current = (object)new WaitForSeconds(1f);
					<>1__state = 1;
					return true;
				case 1:
					<>1__state = -1;
					<component>5__1 = ((Component)chest).GetComponent<EntityStateMachine>();
					if (Object.op_Implicit((Object)(object)<component>5__1))
					{
						<component>5__1.SetNextState(EntityStateCatalog.InstantiateState(ref chest.closingState));
					}
					((Component)chest).GetComponent<PurchaseInteraction>().available = true;
					return false;
				}
			}

			bool IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			[DebuggerHidden]
			void IEnumerator.Reset()
			{
				throw new NotSupportedException();
			}
		}

		public NetworkInstanceId ChestId { get; private set; }

		public int PlayerId { get; private set; }

		public ChestOpenMessage()
		{
		}

		public ChestOpenMessage(NetworkInstanceId chestId, int playerId)
		{
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			ChestId = chestId;
			PlayerId = PlayerId;
		}

		public void Serialize(NetworkWriter writer)
		{
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			writer.Write(ChestId);
			writer.Write(PlayerId);
		}

		public void Deserialize(NetworkReader reader)
		{
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			ChestId = reader.ReadNetworkId();
			PlayerId = reader.ReadInt32();
		}

		public void OnReceived()
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: 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_007d: 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)
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			NetworkUser currentNetworkUser = LocalUserManager.readOnlyLocalUsersList[0].currentNetworkUser;
			Log.Info($"Player {PlayerId} opened {ChestId}");
			NetworkInstanceId chestId = ChestId;
			int playerId = PlayerId;
			if (!ShopLocalizerHooks.PlayerUnlockedChests.ContainsKey(chestId))
			{
				ShopLocalizerHooks.PlayerUnlockedChests[chestId] = new List<int>();
			}
			bool flag = ShopLocalizerHooks.PlayerUnlockedChests[chestId].Contains(playerId);
			ChestBehavior component = NetworkServer.FindLocalObject(chestId).GetComponent<ChestBehavior>();
			if (!flag)
			{
				if (((NetworkBehaviour)LocalUserManager.readOnlyLocalUsersList[0].currentNetworkUser).playerControllerId == playerId)
				{
					Log.Info("We are the local player");
					ShopLocalizerHooks.PlayerUnlockedChests[chestId].Add(playerId);
				}
				else
				{
					((MonoBehaviour)component).StartCoroutine(CloseChest(component));
				}
			}
		}

		[IteratorStateMachine(typeof(<CloseChest>d__13))]
		private static IEnumerator CloseChest(ChestBehavior chest)
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <CloseChest>d__13(0)
			{
				chest = chest
			};
		}
	}
	public static class NetworkHandler
	{
	}
}