Decompiled source of InfiniteNewspapers v1.0.1

kotos-GuiltyNewspapersCooldown.dll

Decompiled 2 months ago
using System;
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.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Mirror;
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("kotos-GuiltyNewspapersCooldown")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("Infinite Newspaper")]
[assembly: AssemblyTitle("kotos-GuiltyNewspapersCooldown")]
[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 GuiltyNewspapersCooldown
{
	public class NewspaperConfig
	{
		public ConfigEntry<float> CooldownDuration { get; private set; }

		public NewspaperConfig(ConfigFile file)
		{
			CooldownDuration = file.Bind<float>("General", "CooldownDuration", 60f, "Time to wait before allowing another article to be published, seconds.");
		}
	}
	public class NetworkManagerPatch
	{
		[HarmonyPatch(typeof(LobbyManager), "StartGame")]
		[HarmonyPostfix]
		public static void OnClientConnect(LobbyManager __instance)
		{
			if (((NetworkBehaviour)__instance).isServer)
			{
				Plugin.synchronisedConfig.SendSynchroniseMessage();
			}
		}
	}
	public class ReporterCountPatch
	{
		[HarmonyPatch(typeof(PlayerJournalist), "Publish")]
		[HarmonyPostfix]
		public static void Publish(PlayerJournalist __instance)
		{
			__instance.PublishedArticleCount = 0;
			Plugin.Logger.LogDebug((object)"Reset article count to 0");
		}

		[HarmonyPatch(typeof(ArticleCreationUICanvas), "EnableCanvas")]
		[HarmonyPostfix]
		public static void AlterCooldown(ArticleCreationUICanvas __instance)
		{
			Traverse val = Traverse.Create((object)__instance);
			val.Field("publishingDelay").SetValue((object)Mathf.Clamp(Plugin.config.CooldownDuration.Value, 30f, 300f));
		}

		[HarmonyPatch(typeof(BoardUI), "UpdateNews")]
		[HarmonyPrefix]
		public static bool UpdateNewsPre(BoardUI __instance)
		{
			Traverse val = Traverse.Create((object)__instance);
			BoardNewsUI[] array = val.Field("news").GetValue() as BoardNewsUI[];
			int value = val.Field("index").GetValue<int>();
			val.Field("index").SetValue((object)(value % array?.Length));
			return true;
		}
	}
	[BepInPlugin("kotos-GuiltyNewspapersCooldown", "Infinite Newspaper", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		public static NewspaperConfig config;

		public static SynchronisedConfig synchronisedConfig;

		internal static ManualLogSource Logger;

		private void Awake()
		{
			config = new NewspaperConfig(((BaseUnityPlugin)this).Config);
			synchronisedConfig = new SynchronisedConfig(config);
			Logger = ((BaseUnityPlugin)this).Logger;
			Logger.LogInfo((object)"Plugin kotos-GuiltyNewspapersCooldown is loaded");
			Harmony.CreateAndPatchAll(typeof(ReporterCountPatch), (string)null);
			Logger.LogInfo((object)"Patched!");
		}
	}
	public class SynchronisedConfig
	{
		public struct SynchroniseMessage : NetworkMessage
		{
			public float newspaperCooldown;
		}

		public float newspaperCooldown = 60f;

		public SynchronisedConfig(NewspaperConfig config)
		{
			newspaperCooldown = config.CooldownDuration.Value;
			NetworkClient.RegisterHandler<SynchroniseMessage>((Action<SynchroniseMessage>)OnSynchroniseClient, true);
		}

		public void SendSynchroniseMessage()
		{
			SynchroniseMessage synchroniseMessage = default(SynchroniseMessage);
			synchroniseMessage.newspaperCooldown = newspaperCooldown;
			NetworkServer.SendToAll<SynchroniseMessage>(synchroniseMessage, 0, false);
		}

		public void OnSynchroniseClient(SynchroniseMessage synchronise)
		{
			newspaperCooldown = synchronise.newspaperCooldown;
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "kotos-GuiltyNewspapersCooldown";

		public const string PLUGIN_NAME = "Infinite Newspaper";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}