Decompiled source of MoreSpookerVideo v1.0.7

lanthane.morespookertube.dll

Decompiled 8 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
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 HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
using Zorro.Core;

[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("lanthane.morespookertube")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("MoreSpookerVideo")]
[assembly: AssemblyTitle("lanthane.morespookertube")]
[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.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;
		}
	}
	[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 MoreSpookerVideo
{
	[BepInPlugin("lanthane.morespookertube", "MoreSpookerVideo", "1.0.0")]
	public class MoreSpookerVideo : BaseUnityPlugin
	{
		public static MoreSpookerVideo Instance { get; private set; }

		internal static ManualLogSource Logger { get; private set; }

		internal static Harmony? Harmony { get; set; }

		internal static ConfigEntry<int>? CameraPrice { get; private set; }

		internal static ConfigEntry<int>? CameraTimeMultiplier { get; private set; }

		internal static ConfigEntry<float>? ViewRateMultiplier { get; private set; }

		internal static ConfigEntry<int>? StartMoney { get; private set; }

		internal static ConfigEntry<bool>? EnabledAllItem { get; private set; }

		internal static ConfigEntry<float>? ChangePriceOfItem { get; private set; }

		public static List<Item> AllBasicItems => Resources.FindObjectsOfTypeAll<Item>().ToList();

		public static List<Item> AllItems => ((DatabaseAsset<ItemDatabase, Item>)(object)SingletonAsset<ItemDatabase>.Instance).Objects.ToList();

		private void Awake()
		{
			Logger = ((BaseUnityPlugin)this).Logger;
			Instance = this;
			CameraPrice = ((BaseUnityPlugin)this).Config.Bind<int>("General", "CameraPrice", 100, "The price of camera in shop (-1 = default ingame price)");
			CameraTimeMultiplier = ((BaseUnityPlugin)this).Config.Bind<int>("General", "CameraTimeMultiplier", 0, "Multiplier of camera times (0 = default ingame value, -1 = infinite time)");
			ViewRateMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("General", "ViewRateMultiplier", 0f, "Multiplier of view rates (0 = default ingame value)");
			EnabledAllItem = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "EnabledAllItem", false, "Unlock all game items (default false)");
			StartMoney = ((BaseUnityPlugin)this).Config.Bind<int>("General", "StartMoney", 0, "Define money in start of game party");
			ChangePriceOfItem = ((BaseUnityPlugin)this).Config.Bind<float>("General", "ChangePriceOfItem", 1f, "Change price value of item (1 = default ingame value, 0 = free item)");
			AddShopItem();
			Patch();
			Logger.LogInfo((object)"lanthane.morespookertube v1.0.0 has loaded!");
		}

		private 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("lanthane.morespookertube");
			}
			Logger.LogDebug((object)"Patching...");
			Harmony.PatchAll();
			Logger.LogDebug((object)"Finished patching!");
		}

		private void AddShopItem()
		{
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_012a: Unknown result type (might be due to invalid IL or missing references)
			if (EnabledAllItem.Value)
			{
				Item defaultItem = ((IEnumerable<Item>)AllItems).FirstOrDefault((Func<Item, bool>)((Item item) => ((Object)item).name.ToLower().Equals("disc")));
				AllItems.ForEach(delegate(Item item)
				{
					//IL_0101: Unknown result type (might be due to invalid IL or missing references)
					//IL_0125: Unknown result type (might be due to invalid IL or missing references)
					//IL_012d: Unknown result type (might be due to invalid IL or missing references)
					//IL_01a0: Unknown result type (might be due to invalid IL or missing references)
					if (item.displayName == null || item.displayName.Equals(""))
					{
						item.displayName = ((Object)item).name;
					}
					ConfigEntry<bool> val2 = null;
					bool flag = ((object)(ItemType)(ref item.itemType)).Equals((object)(ItemType)0) && ((Object)item).name.ToLower().Equals("camera");
					if (!item.purchasable && !flag)
					{
						val2 = ((BaseUnityPlugin)this).Config.Bind<bool>("Item", ((Object)item).name.Replace(" ", "").Trim(), false, "Enabled/Disabled item '" + item.displayName + "' (default false, Only when the 'enable all items' option is active)");
					}
					if ((Object)(object)item.icon == (Object)null || ((object)item.icon).Equals((object?)""))
					{
						item.icon = defaultItem.icon;
					}
					if (flag)
					{
						item.Category = (ShopItemCategory)3;
					}
					else
					{
						item.Category = (ShopItemCategory)(((object)(ShopItemCategory)(ref item.Category)).Equals((object)(ShopItemCategory)0) ? 7 : ((int)item.Category));
					}
					item.purchasable = val2?.Value ?? true;
					if (ChangePriceOfItem.Value != -1f)
					{
						item.price = Mathf.FloorToInt((float)item.price * ChangePriceOfItem.Value);
					}
					ManualLogSource logger2 = Logger;
					if (logger2 != null)
					{
						logger2.LogInfo((object)$"Item {item.displayName} has unlocked to {item.price}$ ! ({item.Category})");
					}
				});
				return;
			}
			Item val = ((IEnumerable<Item>)AllBasicItems).FirstOrDefault((Func<Item, bool>)((Item i) => ((object)(ItemType)(ref i.itemType)).Equals((object)(ItemType)0) && ((Object)i).name.ToLower().Equals("camera")));
			if (Object.op_Implicit((Object)(object)val))
			{
				val.purchasable = true;
				val.Category = (ShopItemCategory)3;
				if (ChangePriceOfItem.Value != -1f)
				{
					val.price = Mathf.FloorToInt((float)val.price * ChangePriceOfItem.Value);
				}
				else if (CameraPrice.Value >= 0)
				{
					val.price = CameraPrice.Value;
				}
				ManualLogSource logger = Logger;
				if (logger != null)
				{
					logger.LogInfo((object)$"{val.displayName} added to {val.Category} shop to {val.price}$ !");
				}
			}
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "lanthane.morespookertube";

		public const string PLUGIN_NAME = "MoreSpookerVideo";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace MoreSpookerVideo.Patches
{
	[HarmonyPatch(typeof(RoomStatsHolder))]
	internal class DefineQuotaDayInfoPatch
	{
		[HarmonyPatch(/*Could not decode attribute arguments.*/)]
		[HarmonyPrefix]
		private static void RoomStatsHolderCtorPrefix(ref int startMoney, ref int startQuotaToReachToReach)
		{
			startMoney = MoreSpookerVideo.StartMoney.Value;
			bool flag = MoreSpookerVideo.StartMoney.Value > 0;
			if (MoreSpookerVideo.ViewRateMultiplier.Value > 0f)
			{
				startQuotaToReachToReach = Mathf.FloorToInt((float)startQuotaToReachToReach * MoreSpookerVideo.ViewRateMultiplier.Value);
				flag = true;
			}
			if (flag)
			{
				ManualLogSource logger = MoreSpookerVideo.Logger;
				if (logger != null)
				{
					logger.LogInfo((object)$"You have {startMoney}$ in start game!");
				}
				ManualLogSource logger2 = MoreSpookerVideo.Logger;
				if (logger2 != null)
				{
					logger2.LogInfo((object)$"You have {startQuotaToReachToReach} quota to reach!");
				}
			}
		}

		[HarmonyPatch("CalculateNewQuota")]
		[HarmonyPostfix]
		private static void CalculateNewQuotaPostfix(RoomStatsHolder __instance, ref int ___m_quotaToReachInternal)
		{
			if (MoreSpookerVideo.ViewRateMultiplier.Value > 0f)
			{
				___m_quotaToReachInternal = Mathf.FloorToInt((float)__instance.QuotaToReach * MoreSpookerVideo.ViewRateMultiplier.Value);
			}
			ManualLogSource logger = MoreSpookerVideo.Logger;
			if (logger != null)
			{
				logger.LogInfo((object)$"You have {___m_quotaToReachInternal} quota to reach!");
			}
		}
	}
	[HarmonyPatch(typeof(VideoInfoEntry))]
	internal class DefineTimeOfCameraPatch
	{
		private static bool fisrtPass;

		[HarmonyPatch("Deserialize")]
		[HarmonyPostfix]
		private static void OnSerializePostfix(ref float ___maxTime, ref float ___timeLeft)
		{
			if (!fisrtPass && ___maxTime == ___timeLeft)
			{
				fisrtPass = true;
				if (MoreSpookerVideo.CameraTimeMultiplier.Value < 0)
				{
					ManualLogSource logger = MoreSpookerVideo.Logger;
					if (logger != null)
					{
						logger.LogDebug((object)"Apply infinite time in camera!");
					}
					___maxTime = float.MaxValue;
					___timeLeft = ___maxTime;
				}
				else if (MoreSpookerVideo.CameraTimeMultiplier.Value > 0)
				{
					ManualLogSource logger2 = MoreSpookerVideo.Logger;
					if (logger2 != null)
					{
						logger2.LogDebug((object)$"Apply value time * {MoreSpookerVideo.CameraTimeMultiplier.Value} in camera on {___maxTime} default value!");
					}
					___maxTime *= MoreSpookerVideo.CameraTimeMultiplier.Value;
					___timeLeft = ___maxTime;
				}
				ManualLogSource logger3 = MoreSpookerVideo.Logger;
				if (logger3 != null)
				{
					logger3.LogInfo((object)$"Your can rec {___maxTime}s with camera!");
				}
			}
			else
			{
				fisrtPass = false;
			}
		}
	}
}