using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("DistributeSpaceWarper")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("DistributeSpaceWarper")]
[assembly: AssemblyCopyright("Copyright © 2021")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("DD23704E-3C0C-4D6B-8EB1-F847CFB2BC2D")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETStandard,Version=v2.0", FrameworkDisplayName = "")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace DistributeSpaceWarper;
public static class Config
{
public static class General
{
public static ConfigEntry<ELogisticStorage> WarperLocalMode;
public static ConfigEntry<ELogisticStorage> WarperRemoteMode;
public static ConfigEntry<int> WarperMaxValue;
public static ConfigEntry<bool> ShowWarperSlot;
public static ConfigEntry<bool> WarpersRequiredToggleAutomation;
}
public static class Utility
{
public static ConfigEntry<bool> DisableMod;
public static ConfigEntry<bool> UninstallMod;
}
private static readonly string GENERAL_SECTION = "General";
private static readonly string UTILITY_SECTION = "Utility";
internal static void Init(ConfigFile config)
{
//IL_002c: Unknown result type (might be due to invalid IL or missing references)
//IL_0036: Expected O, but got Unknown
General.WarperMaxValue = config.Bind<int>(GENERAL_SECTION, "WarperMaxValue", 100, new ConfigDescription("Default number of items set for warper slot. Note: Should be in increments of 100. Otherwise may cause issues.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 10000), new object[1]
{
new { }
}));
General.WarperLocalMode = config.Bind<ELogisticStorage>(GENERAL_SECTION, "WarperLocalMode", (ELogisticStorage)2, "Default local logistics mode of the Warpers");
General.WarperRemoteMode = config.Bind<ELogisticStorage>(GENERAL_SECTION, "WarperRemoteMode", (ELogisticStorage)2, "Default remote logistics mode of the Warpers");
General.WarpersRequiredToggleAutomation = config.Bind<bool>(GENERAL_SECTION, "WarpersRequiredToggleAutomation", true, "If enabled, when `Warpers Required` toggle ticked on, this will setup warper slot to default local mode. When toggle is ticked off this will set wraper slot to local supply.");
Utility.DisableMod = config.Bind<bool>(UTILITY_SECTION, "DisableMod", false, "While true this will disable all mod effects but will not remove additional slot from ILS. Useful if uninstalling mod failed for some reason.");
Utility.UninstallMod = config.Bind<bool>(UTILITY_SECTION, "UninstallMod", false, "WARNING!!! BACKUP YOUR SAVE BEFORE DOING THIS!!! This will not work if mod cannot load properly! If this is true, mod will remove additional slot from all current ILS. This will destroy any items in additional slot To correctly uninstall mod and get vanilla save please follow this steps. Step #1: Set UninstallMod to true. Step #2: Load your save. Step #3: Save your game. Step #4: Exit the game and remove this mod.");
}
}
public static class ModDebug
{
private static ManualLogSource Logger { get; set; }
public static void SetLogger(ManualLogSource logger)
{
Logger = logger;
}
public static void Assert(bool condition)
{
}
public static void Log(object message)
{
Logger.Log((LogLevel)16, message);
}
public static void Error(object message)
{
Logger.Log((LogLevel)2, message);
}
public static void Trace(object message)
{
Logger.Log((LogLevel)16, (object)("DISTR_SPACE_WARP-" + message));
}
public static void LogPlanetType(PlanetData planet)
{
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_0008: Unknown result type (might be due to invalid IL or missing references)
//IL_0009: Unknown result type (might be due to invalid IL or missing references)
//IL_000a: Unknown result type (might be due to invalid IL or missing references)
//IL_0028: Expected I4, but got Unknown
EPlanetType type = planet.type;
EPlanetType val = type;
switch ((int)val)
{
case 5:
Log("Gas");
break;
case 3:
Log("Desert");
break;
case 4:
Log("Ice");
break;
case 2:
Log("Ocean");
break;
case 1:
Log("Vocano");
break;
case 0:
Log("None");
break;
}
}
public static void LogCmdMode(int mode)
{
switch (mode)
{
case -1:
Log("CmdMode: Destruct Mode");
break;
case -2:
Log("CmdMode: Upgrade Mode");
break;
case 1:
Log("CmdMode: Normal Build Mode");
break;
case 2:
Log("CmdMode: Build Mode - Belt");
break;
case 3:
Log("CmdMode: Build Mode - Inserter");
break;
case 4:
Log("CmdMode: Build Mode - Ground");
break;
case 0:
break;
}
}
}
internal static class Patch
{
private static int _ilsId = 2104;
private static bool ModDisabled => Config.Utility.DisableMod.Value || Config.Utility.UninstallMod.Value;
[HarmonyPatch(typeof(PlanetTransport), "Import", new Type[] { typeof(BinaryReader) })]
[HarmonyPostfix]
public static void PlanetTransport_Import_Postfix(BinaryReader r, PlanetTransport __instance)
{
if (Config.Utility.UninstallMod.Value)
{
int warperId = 1210;
PrefabDesc prefabDesc = ((ProtoSet<ItemProto>)(object)LDB.items).Select(_ilsId).prefabDesc;
UninstallMod(__instance, prefabDesc, warperId);
}
}
private static void UninstallMod(PlanetTransport instance, PrefabDesc prefabDesc, int warperId)
{
//IL_0074: Unknown result type (might be due to invalid IL or missing references)
int stationMaxItemKinds = prefabDesc.stationMaxItemKinds;
for (int i = 1; i < instance.stationCursor; i++)
{
if (instance.stationPool[i] == null || instance.stationPool[i].id != i)
{
continue;
}
StationComponent val = instance.stationPool[i];
if (!val.isCollector && val.isStellar)
{
if (val.storage.Length > prefabDesc.stationMaxItemKinds && val.storage.Last().itemId == warperId)
{
instance.SetStationStorage(val.id, stationMaxItemKinds, 0, 0, (ELogisticStorage)0, (ELogisticStorage)0, GameMain.mainPlayer);
List<StationStore> list = new List<StationStore>(val.storage);
list.RemoveAt(stationMaxItemKinds);
val.storage = list.ToArray();
}
instance.RefreshStationTraffic(0);
instance.RefreshDispenserTraffic(0);
instance.gameData.galacticTransport.RefreshTraffic(val.gid);
val.UpdateNeeds();
}
}
}
[HarmonyPatch(typeof(PlanetTransport), "GameTick", new Type[]
{
typeof(long),
typeof(bool),
typeof(bool)
})]
[HarmonyPostfix]
public static void PlanetTransport_GameTick_Postfix(PlanetTransport __instance)
{
//IL_001d: Unknown result type (might be due to invalid IL or missing references)
//IL_0022: Unknown result type (might be due to invalid IL or missing references)
//IL_0028: Unknown result type (might be due to invalid IL or missing references)
//IL_002d: Unknown result type (might be due to invalid IL or missing references)
//IL_010c: Unknown result type (might be due to invalid IL or missing references)
//IL_0112: Unknown result type (might be due to invalid IL or missing references)
//IL_013a: Unknown result type (might be due to invalid IL or missing references)
//IL_013b: Unknown result type (might be due to invalid IL or missing references)
//IL_017f: Unknown result type (might be due to invalid IL or missing references)
//IL_0180: Unknown result type (might be due to invalid IL or missing references)
//IL_01af: Unknown result type (might be due to invalid IL or missing references)
//IL_01b4: Unknown result type (might be due to invalid IL or missing references)
//IL_01d6: Unknown result type (might be due to invalid IL or missing references)
//IL_01e5: Unknown result type (might be due to invalid IL or missing references)
//IL_020f: Unknown result type (might be due to invalid IL or missing references)
//IL_0215: Invalid comparison between Unknown and I4
//IL_03e7: Unknown result type (might be due to invalid IL or missing references)
//IL_03ed: Invalid comparison between Unknown and I4
//IL_0245: Unknown result type (might be due to invalid IL or missing references)
//IL_048b: Unknown result type (might be due to invalid IL or missing references)
//IL_048c: Unknown result type (might be due to invalid IL or missing references)
//IL_04aa: Unknown result type (might be due to invalid IL or missing references)
//IL_04ab: Unknown result type (might be due to invalid IL or missing references)
//IL_0427: Unknown result type (might be due to invalid IL or missing references)
//IL_042d: Invalid comparison between Unknown and I4
if (ModDisabled)
{
return;
}
ELogisticStorage value = Config.General.WarperLocalMode.Value;
ELogisticStorage value2 = Config.General.WarperRemoteMode.Value;
bool value3 = Config.General.WarpersRequiredToggleAutomation.Value;
int value4 = Config.General.WarperMaxValue.Value;
int warperId = 1210;
PrefabDesc prefabDesc = ((ProtoSet<ItemProto>)(object)LDB.items).Select(_ilsId).prefabDesc;
int stationMaxItemKinds = prefabDesc.stationMaxItemKinds;
for (int i = 1; i < __instance.stationCursor; i++)
{
try
{
if (__instance.stationPool[i] == null || __instance.stationPool[i].id != i)
{
continue;
}
StationComponent val = __instance.stationPool[i];
if (val.isCollector || !val.isStellar)
{
continue;
}
bool flag = false;
if (val.storage.Length < prefabDesc.stationMaxItemKinds + 1)
{
ModDebug.Error(1);
List<StationStore> list = new List<StationStore>(val.storage);
list.Add(default(StationStore));
val.storage = list.ToArray();
__instance.SetStationStorage(val.id, stationMaxItemKinds, warperId, value4, value, value2, GameMain.mainPlayer);
}
if (val.storage[stationMaxItemKinds].itemId != warperId)
{
__instance.SetStationStorage(val.id, stationMaxItemKinds, warperId, value4, value, value2, GameMain.mainPlayer);
}
if (value3)
{
if (val.warperNecessary && val.storage[stationMaxItemKinds].localLogic != value)
{
__instance.SetStationStorage(val.id, stationMaxItemKinds, warperId, value4, value, val.storage[stationMaxItemKinds].remoteLogic, GameMain.mainPlayer);
}
else if (!val.warperNecessary && (int)val.storage[stationMaxItemKinds].localLogic != 1)
{
__instance.SetStationStorage(val.id, stationMaxItemKinds, warperId, value4, (ELogisticStorage)1, val.storage[stationMaxItemKinds].remoteLogic, GameMain.mainPlayer);
}
}
int num = Array.FindIndex(val.storage, (StationStore store) => store.itemId == warperId);
if (num != -1 && num != stationMaxItemKinds && val.storage[stationMaxItemKinds].count < val.storage[stationMaxItemKinds].max && val.storage[num].count > val.storage[num].max)
{
int num2 = val.storage[num].count - val.storage[num].max;
int num3 = val.storage[stationMaxItemKinds].max - val.storage[stationMaxItemKinds].count;
int num4 = Mathf.Min(num3, num2);
val.storage[num].count -= num4;
val.storage[stationMaxItemKinds].count += num4;
val.storage[stationMaxItemKinds].localOrder = 0;
val.storage[stationMaxItemKinds].remoteOrder = 0;
flag = true;
}
if (num != -1 && ((val.storage[stationMaxItemKinds].count == val.storage[stationMaxItemKinds].max && (int)val.storage[stationMaxItemKinds].localLogic == 2 && ((StationStore)(ref val.storage[stationMaxItemKinds])).totalOrdered != 0) || (val.storage[stationMaxItemKinds].count == 0 && (int)val.storage[stationMaxItemKinds].localLogic == 1 && ((StationStore)(ref val.storage[stationMaxItemKinds])).totalOrdered != 0)))
{
int count = val.storage[stationMaxItemKinds].count;
val.storage[stationMaxItemKinds].count = 0;
__instance.SetStationStorage(val.id, stationMaxItemKinds, 0, value4, value, value2, GameMain.mainPlayer);
__instance.SetStationStorage(val.id, stationMaxItemKinds, warperId, value4, value, value2, GameMain.mainPlayer);
val.storage[stationMaxItemKinds].count = count;
flag = true;
}
if (flag)
{
val.UpdateNeeds();
__instance.RefreshStationTraffic(0);
__instance.RefreshDispenserTraffic(0);
__instance.gameData.galacticTransport.RefreshTraffic(val.gid);
}
}
catch (Exception arg)
{
ModDebug.Error($"Error occurred :{arg}");
}
}
}
[HarmonyPrefix]
[HarmonyPatch(typeof(UIStationStorage), "OnItemPickerReturn", new Type[] { typeof(ItemProto) })]
public static bool UIStationStorage_OnItemPickerReturn_Prefix(UIStationStorage __instance, ItemProto itemProto)
{
if (ModDisabled)
{
return true;
}
int num = 1210;
int num2 = 2104;
PrefabDesc prefabDesc = ((ProtoSet<ItemProto>)(object)LDB.items).Select(num2).prefabDesc;
int stationMaxItemKinds = prefabDesc.stationMaxItemKinds;
if (itemProto == null)
{
return false;
}
if (__instance.station == null || __instance.index >= __instance.station.storage.Length)
{
return false;
}
ItemProto val = ((ProtoSet<ItemProto>)(object)LDB.items).Select((int)__instance.stationWindow.factory.entityPool[__instance.station.entityId].protoId);
if (val == null)
{
return false;
}
for (int i = 0; i < __instance.station.storage.Length; i++)
{
if (__instance.station.storage[i].itemId == ((Proto)itemProto).ID && (!__instance.station.isStellar || __instance.station.isCollector || i != stationMaxItemKinds || ((Proto)itemProto).ID != num))
{
UIRealtimeTip.Popup(Localization.Translate("不选择重复物品"), true, 0);
return false;
}
}
__instance.stationWindow.transport.SetStationStorage(__instance.station.id, __instance.index, ((Proto)itemProto).ID, val.prefabDesc.stationMaxItemCount, (ELogisticStorage)1, (ELogisticStorage)(__instance.station.isStellar ? 1 : 0), GameMain.mainPlayer);
return false;
}
}
[BepInPlugin("JClark.DSP.DistributeSpaceWarper", "Distribute Space Warper", "1.0.12.0")]
[BepInProcess("DSPGAME.exe")]
public class Plugin : BaseUnityPlugin
{
private static ManualLogSource _logger;
private const string PluginGuid = "JClark.DSP.DistributeSpaceWarper";
private const string PluginName = "Distribute Space Warper";
private const string PluginVersion = "1.0.12.0";
public void Awake()
{
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_000c: Expected O, but got Unknown
Harmony val = new Harmony("JClark.DSP.DistributeSpaceWarper");
Config.Init(((BaseUnityPlugin)this).Config);
val.PatchAll(typeof(Plugin));
val.PatchAll(typeof(Patch));
}
public void Start()
{
_logger = ((BaseUnityPlugin)this).Logger;
_logger.LogInfo((object)"Loaded!");
ModDebug.SetLogger(_logger);
Debugger.Break();
}
}
public static class PluginInfo
{
public const string PLUGIN_GUID = "DistributeSpaceWarper";
public const string PLUGIN_NAME = "DistributeSpaceWarper";
public const string PLUGIN_VERSION = "1.0.0";
}