using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("DropShipDeliveryCapModifier")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+1ada45fbc2567a4253f57e28e54442b0849e84d7")]
[assembly: AssemblyProduct("DropShipDeliveryCapModifier")]
[assembly: AssemblyTitle("DropShipDeliveryCapModifier")]
[assembly: AssemblyVersion("1.0.0.0")]
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;
}
}
}
namespace DropShipDeliveryCapModifier
{
public class Configuration
{
public ConfigFile configFile;
public ConfigEntry<int> deliveryCap;
public ConfigEntry<int> buyCap;
public Configuration()
{
//IL_0017: Unknown result type (might be due to invalid IL or missing references)
//IL_0021: Expected O, but got Unknown
configFile = new ConfigFile(Paths.ConfigPath + "\\DropShipDeliveryCapModifier.cfg", true);
deliveryCap = configFile.Bind<int>("Settings", "Delivery Cap", 9999, "Drop ship wont be able to hold more than this.");
buyCap = configFile.Bind<int>("Settings", "Buy Cap", 999, "You wont be able to buy more than this in a single purchase.");
}
}
internal class Log
{
internal static ManualLogSource logSource;
internal static void Initalize(ManualLogSource LogSource)
{
logSource = LogSource;
}
internal static void Debug(object data)
{
logSource.LogDebug(data);
}
internal static void Error(object data)
{
logSource.LogError(data);
}
internal static void Fatal(object data)
{
logSource.LogFatal(data);
}
internal static void Info(object data)
{
logSource.LogInfo(data);
}
internal static void Message(object data)
{
logSource.LogMessage(data);
}
internal static void Warning(object data)
{
logSource.LogWarning(data);
}
}
[HarmonyPatch]
[BepInPlugin("com.github.Sylkadi.DropShipDeliveryCapModifier", "DropShipDeliveryCapModifier", "1.0.1")]
public class Plugin : BaseUnityPlugin
{
private const string GUID = "com.github.Sylkadi.DropShipDeliveryCapModifier";
private const string NAME = "DropShipDeliveryCapModifier";
private const string VERSION = "1.0.1";
public static readonly Harmony harmony = new Harmony("com.github.Sylkadi.DropShipDeliveryCapModifier");
public static Configuration config { get; private set; }
private void Awake()
{
Log.Initalize(((BaseUnityPlugin)this).Logger);
config = new Configuration();
harmony.PatchAll();
Log.Info("DropShipDeliveryCapModifier 1.0.1 is done patching.");
}
}
[HarmonyPatch]
[HarmonyPatch(typeof(Terminal))]
public class TerminalPatcher
{
[HarmonyPostfix]
[HarmonyPatch("Start")]
private static void OnStart(Terminal __instance)
{
__instance.terminalNodes.specialNodes[4].displayText = __instance.terminalNodes.specialNodes[4].displayText.Replace("12", Plugin.config.deliveryCap.Value.ToString());
}
[HarmonyTranspiler]
[HarmonyPatch("LoadNewNodeIfAffordable")]
public static IEnumerable<CodeInstruction> OnLoadNewNodeIfAffordableIL(IEnumerable<CodeInstruction> instructions)
{
//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
//IL_00d6: Expected O, but got Unknown
//IL_01d9: Unknown result type (might be due to invalid IL or missing references)
//IL_01e3: Expected O, but got Unknown
Log.Info("Modifying Terminal.LoadNewNodeIfAffordable");
List<CodeInstruction> list = new List<CodeInstruction>(instructions);
int num = 0;
for (int i = 2; i < list.Count; i++)
{
if (list[i - 2].opcode == OpCodes.Ldarg_0 && list[i - 1].opcode == OpCodes.Ldfld && list[i - 1].operand.ToString() == "System.Int32 playerDefinedAmount" && list[i].opcode == OpCodes.Ldc_I4_S && list[i].operand.ToString() == "12")
{
num = i;
list.RemoveAt(i);
list.Insert(i, new CodeInstruction(OpCodes.Ldc_I4, (object)Plugin.config.deliveryCap.Value));
break;
}
}
for (int j = num + 4; j < list.Count; j++)
{
if (list[j - 4].opcode == OpCodes.Ldarg_0 && list[j - 3].opcode == OpCodes.Ldfld && list[j - 3].operand.ToString() == "System.Int32 numberOfItemsInDropship" && list[j - 2].opcode == OpCodes.Conv_R4 && list[j - 1].opcode == OpCodes.Add && list[j].opcode == OpCodes.Ldc_R4 && list[j].operand.ToString() == "12")
{
list.RemoveAt(j);
list.Insert(j, new CodeInstruction(OpCodes.Ldc_R4, (object)(float)Plugin.config.deliveryCap.Value));
break;
}
}
return list.AsEnumerable();
}
[HarmonyTranspiler]
[HarmonyPatch("SyncBoughtItemsWithServer")]
public static IEnumerable<CodeInstruction> OnSyncBoughtItemsWithServerIL(IEnumerable<CodeInstruction> instructions)
{
//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
//IL_00c0: Expected O, but got Unknown
List<CodeInstruction> list = new List<CodeInstruction>(instructions);
for (int i = 3; i < list.Count; i++)
{
if (list[i - 3].opcode == OpCodes.Ldarg_1 && list[i - 2].opcode == OpCodes.Ldlen && list[i - 1].opcode == OpCodes.Conv_I4 && list[i].opcode == OpCodes.Ldc_I4_S && list[i].operand.ToString() == "12")
{
list.RemoveAt(i);
list.Insert(i, new CodeInstruction(OpCodes.Ldc_I4, (object)Plugin.config.deliveryCap.Value));
break;
}
}
return list.AsEnumerable();
}
[HarmonyTranspiler]
[HarmonyPatch("BuyItemsServerRpc")]
public static IEnumerable<CodeInstruction> OnBuyItemsServerRpcIL(IEnumerable<CodeInstruction> instructions)
{
//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
//IL_00dd: Expected O, but got Unknown
List<CodeInstruction> list = new List<CodeInstruction>(instructions);
for (int i = 4; i < list.Count; i++)
{
if (list[i - 4].opcode == OpCodes.Nop && list[i - 3].opcode == OpCodes.Ldarg_1 && list[i - 2].opcode == OpCodes.Ldlen && list[i - 1].opcode == OpCodes.Conv_I4 && list[i].opcode == OpCodes.Ldc_I4_S && list[i].operand.ToString() == "12")
{
list.RemoveAt(i);
list.Insert(i, new CodeInstruction(OpCodes.Ldc_I4, (object)Plugin.config.deliveryCap.Value));
break;
}
}
return list.AsEnumerable();
}
[HarmonyTranspiler]
[HarmonyPatch("ParsePlayerSentence")]
public static IEnumerable<CodeInstruction> OnParsePlayerSentenceIL(IEnumerable<CodeInstruction> instructions)
{
//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
//IL_00e7: Expected O, but got Unknown
Log.Info("Modifying Terminal.ParsePlayerSentence");
List<CodeInstruction> list = new List<CodeInstruction>(instructions);
for (int i = 4; i < list.Count; i++)
{
if (list[i - 4].opcode == OpCodes.Ldarg_0 && list[i - 3].opcode == OpCodes.Ldloc_3 && list[i - 2].opcode == OpCodes.Call && list[i - 1].opcode == OpCodes.Ldc_I4_0 && list[i].opcode == OpCodes.Ldc_I4_S && list[i].operand.ToString() == "10")
{
list.RemoveAt(i);
list.Insert(i, new CodeInstruction(OpCodes.Ldc_I4, (object)Plugin.config.buyCap.Value));
break;
}
}
return list.AsEnumerable();
}
}
}