Please disclose if any significant portion of your mod was created using AI tools by adding the 'AI Generated' category. Failing to do so may result in the mod being removed from Thunderstore.
Decompiled source of AfineQuota v1.0.4
BepInEx/plugins/FatFunT.AfineQuota.dll
Decompiled a month agousing System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Serialization.Formatters.Binary; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; using AfineQuota.Network; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using GameNetcodeStuff; using HarmonyLib; using LethalNetworkAPI; using Microsoft.CodeAnalysis; using Unity.Collections; using Unity.Netcode; using UnityEngine; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: IgnoresAccessChecksTo("Assembly-CSharp")] [assembly: IgnoresAccessChecksTo("UnityEngine")] [assembly: AssemblyCompany("FatFunT.AfineQuota")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.0.3.0")] [assembly: AssemblyInformationalVersion("1.0.3")] [assembly: AssemblyProduct("AfineQuota")] [assembly: AssemblyTitle("FatFunT.AfineQuota")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.0.3.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 AfineQuota { [BepInPlugin("FatFunT.AfineQuota", "AfineQuota", "1.0.3")] [BepInDependency(/*Could not decode attribute arguments.*/)] public class AfineQuota : BaseUnityPlugin { public static AfineQuota Instance { get; private set; } internal static ManualLogSource Logger { get; private set; } internal static Harmony Harmony { get; set; } internal static ModConfig BoundConfig { get; private set; } private void Awake() { Logger = ((BaseUnityPlugin)this).Logger; Instance = this; Networker.Init(); Patch(); BoundConfig = new ModConfig(((BaseUnityPlugin)this).Config); Logger.LogInfo((object)"FatFunT.AfineQuota v1.0.3 has loaded!"); } internal static void Patch() { //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0017: Expected O, but got Unknown if (Harmony == null) { Harmony = new Harmony("FatFunT.AfineQuota"); } Logger.LogDebug((object)"Patching..."); Harmony.PatchAll(); Logger.LogDebug((object)"Finished patching!"); } internal static void Unpatch() { Logger.LogDebug((object)"Unpatching..."); Harmony harmony = Harmony; if (harmony != null) { harmony.UnpatchSelf(); } Logger.LogDebug((object)"Finished unpatching!"); } } [Serializable] internal class ModConfig : SyncedInstance<ModConfig> { [CompilerGenerated] private static class <>O { public static HandleNamedMessageDelegate <0>__OnRequestSync; public static HandleNamedMessageDelegate <1>__OnReceiveSync; } public readonly ConfigEntry<int> Deadlinemin; public readonly ConfigEntry<int> Deadlinemax; public readonly ConfigEntry<bool> Deadlinetoggle; public readonly ConfigEntry<int> QuotaCeiling; public readonly ConfigEntry<float> Scale; public readonly ConfigEntry<int> FlatMin; public readonly ConfigEntry<int> FlatMax; public ModConfig(ConfigFile cfg) { InitInstance(this); cfg.SaveOnConfigSet = false; Deadlinemin = cfg.Bind<int>("Deadline Min", "deadlinemin", 3, "Minimum day for deadline."); Deadlinemax = cfg.Bind<int>("Deadline Max", "deadlinemax", 4, "Maximum day for deadline."); Deadlinetoggle = cfg.Bind<bool>("Deadline Toggle", "deadlinetoggle", true, "Toggle random Quota Deadline."); QuotaCeiling = cfg.Bind<int>("Day Ceiling", "dayceiling", 6, "Day at which the quota is going to start to soften."); Scale = cfg.Bind<float>("Scaling", "scaling", 11f, "Scaling of the softening [Lower values soften the quota increase harder]."); ClearOrphanedEntries(cfg); cfg.Save(); cfg.SaveOnConfigSet = true; } private static void ClearOrphanedEntries(ConfigFile cfg) { PropertyInfo propertyInfo = AccessTools.Property(typeof(ConfigFile), "OrphanedEntries"); Dictionary<ConfigDefinition, string> dictionary = (Dictionary<ConfigDefinition, string>)propertyInfo.GetValue(cfg); dictionary.Clear(); } public static void RequestSync() { //IL_0022: Unknown result type (might be due to invalid IL or missing references) if (!SyncedInstance<ModConfig>.IsClient) { return; } FastBufferWriter val = default(FastBufferWriter); ((FastBufferWriter)(ref val))..ctor(SyncedInstance<ModConfig>.IntSize, (Allocator)2, -1); try { SyncedInstance<ModConfig>.MessageManager.SendNamedMessage("AfineQuota_OnRequestConfigSync", 0uL, val, (NetworkDelivery)3); } finally { ((IDisposable)(FastBufferWriter)(ref val)).Dispose(); } } public static void OnRequestSync(ulong clientId, FastBufferReader _) { //IL_0050: Unknown result type (might be due to invalid IL or missing references) //IL_0056: Unknown result type (might be due to invalid IL or missing references) //IL_0072: Unknown result type (might be due to invalid IL or missing references) if (!SyncedInstance<ModConfig>.IsHost) { return; } AfineQuota.Logger.LogInfo((object)$"Config sync request received from client: {clientId}"); byte[] array = SyncedInstance<ModConfig>.SerializeToBytes(SyncedInstance<ModConfig>.Instance); int num = array.Length; int num2 = FastBufferWriter.GetWriteSize<byte>(array, -1, 0) + SyncedInstance<ModConfig>.IntSize; FastBufferWriter val = default(FastBufferWriter); ((FastBufferWriter)(ref val))..ctor(num2, (Allocator)2, -1); try { ((FastBufferWriter)(ref val)).WriteValueSafe<int>(ref num, default(ForPrimitives)); ((FastBufferWriter)(ref val)).WriteBytesSafe(array, -1, 0); SyncedInstance<ModConfig>.MessageManager.SendNamedMessage("AfineQuota_OnReceiveConfigSync", clientId, val, (NetworkDelivery)3); } catch (Exception arg) { AfineQuota.Logger.LogInfo((object)$"Error occurred syncing config with client: {clientId}\n{arg}"); } finally { ((IDisposable)(FastBufferWriter)(ref val)).Dispose(); } } public static void OnReceiveSync(ulong _, FastBufferReader reader) { //IL_0024: Unknown result type (might be due to invalid IL or missing references) //IL_002a: Unknown result type (might be due to invalid IL or missing references) if (!((FastBufferReader)(ref reader)).TryBeginRead(SyncedInstance<ModConfig>.IntSize)) { AfineQuota.Logger.LogError((object)"Config sync error: Could not begin reading buffer."); return; } int num = default(int); ((FastBufferReader)(ref reader)).ReadValueSafe<int>(ref num, default(ForPrimitives)); if (!((FastBufferReader)(ref reader)).TryBeginRead(num)) { AfineQuota.Logger.LogError((object)"Config sync error: Host could not sync."); return; } byte[] data = new byte[num]; ((FastBufferReader)(ref reader)).ReadBytesSafe(ref data, num, 0); SyncedInstance<ModConfig>.SyncInstance(data); AfineQuota.Logger.LogInfo((object)"Successfully synced config with host."); } [HarmonyPostfix] [HarmonyPatch(typeof(PlayerControllerB), "ConnectClientToPlayerObject")] public static void InitializeLocalPlayer() { //IL_0058: Unknown result type (might be due to invalid IL or missing references) //IL_005d: Unknown result type (might be due to invalid IL or missing references) //IL_0063: Expected O, but got Unknown //IL_0021: Unknown result type (might be due to invalid IL or missing references) //IL_0026: Unknown result type (might be due to invalid IL or missing references) //IL_002c: Expected O, but got Unknown if (SyncedInstance<ModConfig>.IsHost) { CustomMessagingManager messageManager = SyncedInstance<ModConfig>.MessageManager; object obj = <>O.<0>__OnRequestSync; if (obj == null) { HandleNamedMessageDelegate val = OnRequestSync; <>O.<0>__OnRequestSync = val; obj = (object)val; } messageManager.RegisterNamedMessageHandler("AfineQuota_OnRequestConfigSync", (HandleNamedMessageDelegate)obj); SyncedInstance<ModConfig>.Synced = true; return; } SyncedInstance<ModConfig>.Synced = false; CustomMessagingManager messageManager2 = SyncedInstance<ModConfig>.MessageManager; object obj2 = <>O.<1>__OnReceiveSync; if (obj2 == null) { HandleNamedMessageDelegate val2 = OnReceiveSync; <>O.<1>__OnReceiveSync = val2; obj2 = (object)val2; } messageManager2.RegisterNamedMessageHandler("AfineQuota_OnReceiveConfigSync", (HandleNamedMessageDelegate)obj2); RequestSync(); } } internal static class Networker { internal static readonly LNetworkMessage<int> DeadlineSync = LNetworkMessage<int>.Connect("AfineQuota_DeadlineSync", (Action<int, ulong>)null, (Action<int>)null, (Action<int, ulong>)null); internal static void Init() { DeadlineSync.OnClientReceived += delegate(int deadline) { if (TimeOfDay.Instance?.quotaVariables != null) { TimeOfDay.Instance.quotaVariables.deadlineDaysAmount = deadline; AfineQuota.Logger.LogInfo((object)$"[Client] Deadline synced: {deadline}"); } }; } } [HarmonyPatch(typeof(TimeOfDay), "Awake")] internal class QuotaPatch { private static void Postfix(TimeOfDay __instance) { if (__instance.quotaVariables != null) { AfineQuota.Logger.LogInfo((object)"quota deadline initiated."); } } } [HarmonyPatch(typeof(TimeOfDay), "SetNewProfitQuota")] internal class OnQuotaPatch { private static void Prefix(TimeOfDay __instance) { if (__instance.quotaVariables != null && AfineQuota.BoundConfig.Deadlinetoggle.Value && ((NetworkBehaviour)__instance).IsServer) { int num = Mathf.RoundToInt(Random.Range((float)AfineQuota.BoundConfig.Deadlinemin.Value, (float)AfineQuota.BoundConfig.Deadlinemax.Value)); AfineQuota.Logger.LogInfo((object)$"quota deadline random: {num}"); __instance.quotaVariables.deadlineDaysAmount = num; Networker.DeadlineSync.SendClients(num); } } } [HarmonyPatch(typeof(TimeOfDay), "SetNewProfitQuota")] internal class QuotaCalculationPatch { private static void Prefix(TimeOfDay __instance, out int __state) { __state = __instance.profitQuota; } private static void Postfix(TimeOfDay __instance, ref int __state) { if (((NetworkBehaviour)__instance).IsServer) { int num = __state; int profitQuota = __instance.profitQuota; int timesFulfilledQuota = __instance.timesFulfilledQuota; int value = AfineQuota.BoundConfig.QuotaCeiling.Value; float value2 = AfineQuota.BoundConfig.Scale.Value; if (timesFulfilledQuota > value) { float num2 = timesFulfilledQuota - value; float num3 = profitQuota - num; float num4 = num3 / (1f + Mathf.Pow(num2 / value2, 2f)); __instance.profitQuota = Mathf.RoundToInt((float)num + num4); } } } } public static class MyPluginInfo { public const string PLUGIN_GUID = "FatFunT.AfineQuota"; public const string PLUGIN_NAME = "AfineQuota"; public const string PLUGIN_VERSION = "1.0.3"; } } namespace AfineQuota.Network { [Serializable] public class SyncedInstance<T> { [NonSerialized] protected static int IntSize = 4; internal static CustomMessagingManager MessageManager => NetworkManager.Singleton.CustomMessagingManager; internal static bool IsClient => NetworkManager.Singleton.IsClient; internal static bool IsHost => NetworkManager.Singleton.IsHost; public static T Default { get; private set; } public static T Instance { get; private set; } public static bool Synced { get; internal set; } protected void InitInstance(T instance) { Default = instance; Instance = instance; IntSize = 4; } internal static void SyncInstance(byte[] data) { Instance = DeserializeFromBytes(data); Synced = true; } internal static void RevertSync() { Instance = Default; Synced = false; } public static byte[] SerializeToBytes(T val) { BinaryFormatter binaryFormatter = new BinaryFormatter(); using MemoryStream memoryStream = new MemoryStream(); try { binaryFormatter.Serialize(memoryStream, val); return memoryStream.ToArray(); } catch (Exception arg) { AfineQuota.Logger.LogError((object)$"Error serializing instance: {arg}"); return null; } } public static T DeserializeFromBytes(byte[] data) { BinaryFormatter binaryFormatter = new BinaryFormatter(); using MemoryStream serializationStream = new MemoryStream(data); try { return (T)binaryFormatter.Deserialize(serializationStream); } catch (Exception arg) { AfineQuota.Logger.LogError((object)$"Error deserializing instance: {arg}"); return default(T); } } } } namespace System.Runtime.CompilerServices { [AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)] internal sealed class IgnoresAccessChecksToAttribute : Attribute { public IgnoresAccessChecksToAttribute(string assemblyName) { } } }