Decompiled source of MoreAds v0.1.0

MoreAds.dll

Decompiled a day ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Logging;
using HarmonyLib;
using LobbyCompatibility.Enums;
using LobbyCompatibility.Features;
using Microsoft.CodeAnalysis;
using MoreAds.Compat;
using MoreAds.Patches;
using UnityEngine;

[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("MoreAds")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Get enough dystopian hellscape in real life? Hate ads? Say no more!")]
[assembly: AssemblyFileVersion("0.1.0.0")]
[assembly: AssemblyInformationalVersion("0.1.0+e78d8c4f0eaf7eb4818b3cbf5ad58f3d309ecb14")]
[assembly: AssemblyProduct("MoreAds")]
[assembly: AssemblyTitle("MoreAds")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.1.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 MoreAds
{
	[BepInPlugin("com.github.cdusold.LethalMoreAds", "MoreAds", "0.1.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		private readonly Harmony harmony = new Harmony("cdusold.LethalMoreAds");

		private static Plugin Instance;

		public static ManualLogSource logger;

		private void Awake()
		{
			if ((Object)(object)Instance == (Object)null)
			{
				Instance = this;
			}
			logger = ((BaseUnityPlugin)this).Logger;
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Mod cdusold.LethalMoreAds is loaded!");
			if (Chainloader.PluginInfos.ContainsKey("BMX.LobbyCompatibility"))
			{
				LobbyCompatibilityManager.Init();
			}
			harmony.PatchAll(typeof(Plugin));
			harmony.PatchAll(typeof(HUDManagerPatch));
			harmony.PatchAll(typeof(TimeOfDayPatch));
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "MoreAds";

		public const string PLUGIN_NAME = "MoreAds";

		public const string PLUGIN_VERSION = "0.1.0";
	}
}
namespace MoreAds.Patches
{
	[HarmonyPatch(typeof(HUDManager))]
	internal class HUDManagerPatch
	{
		[HarmonyPatch("displayAd")]
		[HarmonyPostfix]
		private static void displayAd()
		{
			Plugin.logger.LogInfo((object)"Ad done, reset boolean.");
			TimeOfDay.Instance.hasShownAdThisQuota = false;
		}
	}
	[HarmonyPatch(typeof(TimeOfDay))]
	internal class TimeOfDayPatch
	{
		[HarmonyPatch("Start")]
		[HarmonyPostfix]
		private static void Start()
		{
			Plugin.logger.LogInfo((object)"Ad not shown yet, game just started.");
			TimeOfDay.Instance.hasShownAdThisQuota = false;
		}

		[HarmonyPatch("SetTimeForAdToPlay")]
		[HarmonyPostfix]
		private static void SetTimeForAdToPlay()
		{
			Plugin.logger.LogInfo((object)"Setting time to play to 0.04f.");
			TimeOfDay.Instance.normalizedTimeToShowAd = 0.04f;
		}

		[HarmonyPatch("GetClientInfo")]
		[HarmonyPostfix]
		private static void GetClientInfoPatch()
		{
			Plugin.logger.LogInfo((object)"Resetting client info time to show ad to 0.04f and resetting ad shown bool.");
			TimeOfDay.Instance.normalizedTimeToShowAd = 0.04f;
			TimeOfDay.Instance.hasShownAdThisQuota = false;
		}

		[HarmonyPatch("MeetsRequirementsToShowAd")]
		[HarmonyPostfix]
		private static void MeetsRequirementsToShowAdPatch(ref bool __result)
		{
			Plugin.logger.LogInfo((object)"Checking ad requirements.");
			Plugin.logger.LogInfo((object)"Should be good to go.");
			__result = true;
		}

		[HarmonyPatch("DisplayAdAtScheduledTime")]
		[HarmonyTranspiler]
		private static IEnumerable<CodeInstruction> DisplayAdAtScheduledTimeTranspiler(IEnumerable<CodeInstruction> instructions)
		{
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Expected O, but got Unknown
			List<CodeInstruction> list = new List<CodeInstruction>(instructions);
			for (int i = 1; i < list.Count; i++)
			{
				if (list[i].opcode == OpCodes.Ldc_I4_1 && list[i - 1].opcode == OpCodes.Ldfld && list[i - 1].operand.ToString().Contains("livingPlayers"))
				{
					list[i] = new CodeInstruction(OpCodes.Ldc_I4_0, (object)null);
					Plugin.logger.LogInfo((object)"Patched ads to display even if only one player is alive.");
					break;
				}
			}
			return list;
		}

		[HarmonyPatch("DisplayAdAtScheduledTime")]
		[HarmonyPrefix]
		private static bool DisplayAdAtScheduledTime()
		{
			if (TimeOfDay.Instance.normalizedTimeToShowAd == -1f)
			{
				TimeOfDay.Instance.normalizedTimeToShowAd = 0.04f;
			}
			if (TimeOfDay.Instance.hasShownAdThisQuota)
			{
				TimeOfDay.Instance.hasShownAdThisQuota = false;
			}
			if (Traverse.Create((object)TimeOfDay.Instance).Field("checkingIfClientsAreReadyForAd").GetValue<bool>())
			{
				Traverse.Create((object)TimeOfDay.Instance).Field("adWaitInterval").SetValue((object)30f);
				Traverse.Create((object)TimeOfDay.Instance).Field("checkingIfClientsAreReadyForAd").SetValue((object)false);
			}
			return true;
		}

		[HarmonyPatch("ReceiveInfoFromClientForShowingAdServerRpc")]
		[HarmonyPrefix]
		private static bool ReceiveInfoFromClientForShowingAdServerRpc(ref bool doesntMeetRequirements)
		{
			Plugin.logger.LogInfo((object)"Received info from client for showing ad server RPC.");
			Plugin.logger.LogInfo((object)$"Doesn't meet requirements: {doesntMeetRequirements}");
			doesntMeetRequirements = false;
			return true;
		}
	}
}
namespace MoreAds.Compat
{
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	internal class LobbyCompatibilityManager
	{
		public static LobbyCompatibilityManager Instance { get; private set; }

		public static void Init()
		{
			if (Instance == null)
			{
				Instance = new LobbyCompatibilityManager();
			}
		}

		private LobbyCompatibilityManager()
		{
			PluginHelper.RegisterPlugin("MoreAds", new Version("0.1.0"), (CompatibilityLevel)1, (VersionStrictness)0);
		}
	}
}