using System;
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 HarmonyLib;
using Microsoft.CodeAnalysis;
using Unity.Netcode;
[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("EarlyDropship")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("My first plugin")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("EarlyDropship")]
[assembly: AssemblyTitle("EarlyDropship")]
[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 EarlyDropship
{
[BepInPlugin("EarlyDropship", "EarlyDropship", "1.0.0")]
public class Plugin : BaseUnityPlugin
{
private Harmony harmony;
internal static ManualLogSource Log;
private void Awake()
{
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_0011: Expected O, but got Unknown
harmony = new Harmony("EarlyDropship");
harmony.PatchAll();
Log = ((BaseUnityPlugin)this).Logger;
((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin EarlyDropship is loaded!");
}
}
public static class PluginInfo
{
public const string PLUGIN_GUID = "EarlyDropship";
public const string PLUGIN_NAME = "EarlyDropship";
public const string PLUGIN_VERSION = "1.0.0";
}
}
namespace EarlyDropship.patch
{
[HarmonyPatch(typeof(ItemDropship))]
internal class ItemDropshipPatch
{
private static readonly Dictionary<string, MethodInfo> MethodCache = new Dictionary<string, MethodInfo>();
private static readonly Dictionary<string, FieldInfo> FieldCache = new Dictionary<string, FieldInfo>();
private static StartOfRound playersManager;
private static Terminal terminalScript;
private static object InvokePrivateMethod(ItemDropship instance, string methodName, object[] parameters = null)
{
MethodCache.TryGetValue(methodName, out var value);
if (value == null)
{
value = typeof(ItemDropship).GetMethod(methodName, BindingFlags.Instance | BindingFlags.NonPublic);
MethodCache[methodName] = value;
}
return value?.Invoke(instance, parameters);
}
private static object GetPrivateFieldValue(ItemDropship instance, string fieldName)
{
FieldCache.TryGetValue(fieldName, out var value);
if (value == null)
{
value = typeof(ItemDropship).GetField(fieldName, BindingFlags.Instance | BindingFlags.NonPublic);
FieldCache[fieldName] = value;
}
return value?.GetValue(instance);
}
[HarmonyPatch("Start")]
[HarmonyPostfix]
public static void EarlyDropship_Start(ref ItemDropship __instance)
{
//IL_000d: Unknown result type (might be due to invalid IL or missing references)
//IL_0017: Expected O, but got Unknown
//IL_0023: Unknown result type (might be due to invalid IL or missing references)
//IL_002d: Expected O, but got Unknown
playersManager = (StartOfRound)GetPrivateFieldValue(__instance, "playersManager");
terminalScript = (Terminal)GetPrivateFieldValue(__instance, "terminalScript");
}
[HarmonyPatch("Update")]
[HarmonyPrefix]
public static void EarlyDropship_Update(ref ItemDropship __instance)
{
if (((NetworkBehaviour)__instance).IsServer && !__instance.deliveringOrder && !__instance.shipLanded && !playersManager.shipHasLanded && terminalScript.orderedItemsFromTerminal.Count > 0)
{
InvokePrivateMethod(__instance, "LandShipOnServer");
Plugin.Log.LogInfo((object)"Ship landing early");
}
}
}
}