using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using EquinoxsModUtils;
using EquinoxsModUtils.Additions;
using HarmonyLib;
using UnityEngine;
using caspersLoaders.Patches;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("caspersLoaders")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("caspersLoaders")]
[assembly: AssemblyCopyright("Copyright © 2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("a14af3df-0b81-4842-826a-b499b79a664d")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace caspersLoaders
{
[BepInPlugin("com.casper.loaders", "Casper's Loaders Plugin", "1.0.0")]
public class LoaderPlugin : BaseUnityPlugin
{
private const string PluginName = "Casper's Loaders Plugin";
private const string VersionString = "1.0.0";
public static readonly ManualLogSource Log = Logger.CreateLogSource("Casper's Loaders Plugin");
public static List<uint> loaderIDs = new List<uint>();
public const string loaderNode = "Loader Unlock";
public const string floaderNode = "Filter Loader Unlock";
private InserterDefinition loaderDefinition;
private InserterDefinition filterLoaderDefinition;
private void Awake()
{
//IL_000d: Unknown result type (might be due to invalid IL or missing references)
//IL_0012: Unknown result type (might be due to invalid IL or missing references)
//IL_001d: 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_002a: Unknown result type (might be due to invalid IL or missing references)
//IL_002f: Unknown result type (might be due to invalid IL or missing references)
//IL_0031: Unknown result type (might be due to invalid IL or missing references)
//IL_0036: Unknown result type (might be due to invalid IL or missing references)
//IL_0038: Unknown result type (might be due to invalid IL or missing references)
//IL_003d: Unknown result type (might be due to invalid IL or missing references)
//IL_0048: Unknown result type (might be due to invalid IL or missing references)
//IL_0050: Unknown result type (might be due to invalid IL or missing references)
//IL_0067: Unknown result type (might be due to invalid IL or missing references)
//IL_0074: Expected O, but got Unknown
//IL_0081: Unknown result type (might be due to invalid IL or missing references)
//IL_0086: Unknown result type (might be due to invalid IL or missing references)
//IL_0091: Unknown result type (might be due to invalid IL or missing references)
//IL_009c: Unknown result type (might be due to invalid IL or missing references)
//IL_009e: Unknown result type (might be due to invalid IL or missing references)
//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
//IL_00db: Unknown result type (might be due to invalid IL or missing references)
//IL_00e8: Expected O, but got Unknown
//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
//IL_0104: Expected O, but got Unknown
Sprite sprite = Images.LoadSpriteFromFile("caspersLoaders.Images.RI_loader.png", false);
EMUAdditions.AddNewUnlock(new NewUnlockDetails
{
displayName = "Loader Unlock",
description = "Direct Loaders",
category = (TechCategory)2,
requiredTier = (ResearchTier)8,
coreTypeNeeded = (CoreType)0,
coreCountNeeded = 200,
treePosition = 60,
dependencyNames = new List<string> { "Filter Inserter" },
sprite = sprite
}, false);
Sprite sprite2 = Images.LoadSpriteFromFile("caspersLoaders.Images.RI_filter.png", false);
EMUAdditions.AddNewUnlock(new NewUnlockDetails
{
displayName = "Filter Loader Unlock",
description = "Direct Loaders",
category = (TechCategory)2,
requiredTier = (ResearchTier)8,
coreTypeNeeded = (CoreType)0,
coreCountNeeded = 300,
treePosition = 80,
dependencyNames = new List<string> { "Loader Unlock" },
sprite = sprite2
}, false);
Log.LogInfo((object)"Casper's Loaders Plugin, Version 1.0.0 is loading...");
Harmony val = new Harmony("com.casper.loaders");
val.PatchAll(typeof(BlockVisualsPatch));
val.PatchAll(typeof(MachineDefinitionPatch));
val.PatchAll(typeof(FlowManagerPatch));
NewResourceDetails val2 = ContentAdder.AddLoader();
NewResourceDetails val3 = ContentAdder.AddFilterLoader();
LoadPrefabs();
if (val2 != null)
{
loaderDefinition = ScriptableObject.CreateInstance<InserterDefinition>();
EMUAdditions.AddNewMachine<InserterInstance, InserterDefinition>((MachineDefinition<InserterInstance, InserterDefinition>)(object)loaderDefinition, val2, false);
}
if (val3 != null)
{
filterLoaderDefinition = ScriptableObject.CreateInstance<InserterDefinition>();
EMUAdditions.AddNewMachine<InserterInstance, InserterDefinition>((MachineDefinition<InserterInstance, InserterDefinition>)(object)filterLoaderDefinition, val3, false);
filterLoaderDefinition.isFilter = true;
}
Events.GameDefinesLoaded += OnGameDefinesLoaded;
Log.LogInfo((object)"Casper's Loaders Plugin, Version 1.0.0 has loaded.");
}
private void FixedUpdate()
{
MachineDefinitionPatch.UpdateAll();
}
private void OnGameDefinesLoaded()
{
loaderDefinition.cyclesPerMinute = 9999999f;
loaderDefinition.runtimeSettings.cyclesPerMinute = 9999999f;
loaderDefinition.isStack = false;
filterLoaderDefinition.cyclesPerMinute = 1E+09f;
filterLoaderDefinition.runtimeSettings.cyclesPerMinute = 1E+09f;
((BuilderInfo)filterLoaderDefinition).isPowered = false;
}
private void LoadPrefabs()
{
Assembly executingAssembly = Assembly.GetExecutingAssembly();
string text = "caspersLoaders.casperloaders";
AssetBundle val = AssetBundle.LoadFromStream(executingAssembly.GetManifestResourceStream(text));
if ((Object)(object)val == (Object)null)
{
Log.LogError((object)("Failed to load AssetBundle '" + text + "'."));
return;
}
Log.LogInfo((object)("Successfully loaded AssetBundle '" + text + "'."));
MachineDefinitionPatch.prefabLoader = val.LoadAsset<GameObject>("LoaderIN");
if ((Object)(object)MachineDefinitionPatch.prefabLoader == (Object)null)
{
Log.LogError((object)"Failed to load prefab 'LoaderIN' from asset bundle.");
}
else
{
Log.LogInfo((object)"Successfully loaded prefab 'LoaderIN'.");
}
MachineDefinitionPatch.filterPrefab = val.LoadAsset<GameObject>("Filter");
if ((Object)(object)MachineDefinitionPatch.filterPrefab == (Object)null)
{
Log.LogError((object)"Failed to load prefab 'Filter' from asset bundle.");
}
else
{
Log.LogInfo((object)"Successfully loaded prefab 'Filter'.");
}
}
}
public static class ContentAdder
{
public static NewResourceDetails AddLoader()
{
//IL_002f: Unknown result type (might be due to invalid IL or missing references)
//IL_0034: Unknown result type (might be due to invalid IL or missing references)
//IL_003f: Unknown result type (might be due to invalid IL or missing references)
//IL_004a: Unknown result type (might be due to invalid IL or missing references)
//IL_004c: Unknown result type (might be due to invalid IL or missing references)
//IL_0051: Unknown result type (might be due to invalid IL or missing references)
//IL_0058: Unknown result type (might be due to invalid IL or missing references)
//IL_0063: Unknown result type (might be due to invalid IL or missing references)
//IL_006e: Unknown result type (might be due to invalid IL or missing references)
//IL_0076: Unknown result type (might be due to invalid IL or missing references)
//IL_0081: Unknown result type (might be due to invalid IL or missing references)
//IL_008c: Unknown result type (might be due to invalid IL or missing references)
//IL_0097: Unknown result type (might be due to invalid IL or missing references)
//IL_00a9: Expected O, but got Unknown
//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
//IL_0103: Unknown result type (might be due to invalid IL or missing references)
//IL_011d: Unknown result type (might be due to invalid IL or missing references)
//IL_0128: Unknown result type (might be due to invalid IL or missing references)
//IL_0142: Unknown result type (might be due to invalid IL or missing references)
//IL_014f: Unknown result type (might be due to invalid IL or missing references)
//IL_0158: Unknown result type (might be due to invalid IL or missing references)
//IL_0172: 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_0187: Unknown result type (might be due to invalid IL or missing references)
//IL_0198: Expected O, but got Unknown
try
{
if ((Object)(object)Resources.GetResourceInfoByName("Loader", false) != (Object)null)
{
LoaderPlugin.Log.LogWarning((object)"Loader is already registered. Skipping addition.");
return null;
}
NewResourceDetails result = new NewResourceDetails
{
name = "Loader",
description = "Unlimited Speed Transfer.",
craftingMethod = (CraftingMethod)0,
craftTierRequired = 0,
headerTitle = "Logistics",
subHeaderTitle = "Inserters",
maxStackCount = 20,
sortPriority = 999,
unlockName = "Loader Unlock",
parentName = "Inserter",
sprite = Images.LoadSpriteFromFile("caspersLoaders.Images.RI_loader.png", false)
};
InserterDefinition val = ScriptableObject.CreateInstance<InserterDefinition>();
val.cyclesPerMinute = 1E+09f;
val.runtimeSettings.cyclesPerMinute = 1E+09f;
val.isStack = true;
EMUAdditions.AddNewRecipe(new NewRecipeDetails
{
GUID = "com.casper.loaders",
craftingMethod = (CraftingMethod)0,
craftTierRequired = 0,
duration = 0.8f,
ingredients = new List<RecipeResourceInfo>
{
new RecipeResourceInfo
{
name = "Iron Frame",
quantity = 8
},
new RecipeResourceInfo
{
name = "Copper Wire",
quantity = 6
}
},
outputs = new List<RecipeResourceInfo>
{
new RecipeResourceInfo
{
name = "Loader",
quantity = 1
}
},
sortPriority = 10,
unlockName = "Loader Unlock"
}, false);
LoaderPlugin.Log.LogInfo((object)"Successfully added Loader to the game.");
return result;
}
catch (Exception ex)
{
LoaderPlugin.Log.LogError((object)("Error adding Loader: " + ex.Message + "\n" + ex.StackTrace));
return null;
}
}
public static NewResourceDetails AddFilterLoader()
{
//IL_002f: Unknown result type (might be due to invalid IL or missing references)
//IL_0034: Unknown result type (might be due to invalid IL or missing references)
//IL_003f: Unknown result type (might be due to invalid IL or missing references)
//IL_004a: Unknown result type (might be due to invalid IL or missing references)
//IL_004c: Unknown result type (might be due to invalid IL or missing references)
//IL_0051: Unknown result type (might be due to invalid IL or missing references)
//IL_0058: Unknown result type (might be due to invalid IL or missing references)
//IL_0063: Unknown result type (might be due to invalid IL or missing references)
//IL_006e: Unknown result type (might be due to invalid IL or missing references)
//IL_0076: Unknown result type (might be due to invalid IL or missing references)
//IL_0081: Unknown result type (might be due to invalid IL or missing references)
//IL_008c: Unknown result type (might be due to invalid IL or missing references)
//IL_0097: Unknown result type (might be due to invalid IL or missing references)
//IL_00a9: Expected O, but got Unknown
//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
//IL_0103: Unknown result type (might be due to invalid IL or missing references)
//IL_011e: Unknown result type (might be due to invalid IL or missing references)
//IL_0129: Unknown result type (might be due to invalid IL or missing references)
//IL_0144: Unknown result type (might be due to invalid IL or missing references)
//IL_014f: Unknown result type (might be due to invalid IL or missing references)
//IL_016a: Unknown result type (might be due to invalid IL or missing references)
//IL_0177: 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_019a: Unknown result type (might be due to invalid IL or missing references)
//IL_01a7: 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_01c0: Expected O, but got Unknown
try
{
if ((Object)(object)Resources.GetResourceInfoByName("FilterLoader", false) != (Object)null)
{
LoaderPlugin.Log.LogWarning((object)"FilterLoader is already registered. Skipping addition.");
return null;
}
NewResourceDetails result = new NewResourceDetails
{
name = "FilterLoader",
description = "High-speed loader with filtering capabilities.",
craftingMethod = (CraftingMethod)0,
craftTierRequired = 1,
headerTitle = "Logistics",
subHeaderTitle = "Inserters",
maxStackCount = 20,
sortPriority = 1000,
unlockName = "Filter Loader Unlock",
parentName = "Filter Inserter",
sprite = Images.LoadSpriteFromFile("caspersLoaders.Images.RI_filter.png", false)
};
InserterDefinition val = ScriptableObject.CreateInstance<InserterDefinition>();
val.cyclesPerMinute = 1E+09f;
val.runtimeSettings.cyclesPerMinute = 1E+09f;
((BuilderInfo)val).isPowered = false;
EMUAdditions.AddNewRecipe(new NewRecipeDetails
{
GUID = "com.casper.filterloaders",
craftingMethod = (CraftingMethod)0,
craftTierRequired = 1,
duration = 1f,
ingredients = new List<RecipeResourceInfo>
{
new RecipeResourceInfo
{
name = "Iron Frame",
quantity = 10
},
new RecipeResourceInfo
{
name = "Copper Wire",
quantity = 10
},
new RecipeResourceInfo
{
name = "Conveyor Belt",
quantity = 50
}
},
outputs = new List<RecipeResourceInfo>
{
new RecipeResourceInfo
{
name = "FilterLoader",
quantity = 1
}
},
sortPriority = 20,
unlockName = "Filter Loader Unlock"
}, false);
LoaderPlugin.Log.LogInfo((object)"Successfully added Filter.");
return result;
}
catch (Exception ex)
{
LoaderPlugin.Log.LogError((object)("Error adding Filter " + ex.Message + "\n" + ex.StackTrace));
return null;
}
}
}
}
namespace caspersLoaders.Patches
{
internal static class BlockVisualsPatch
{
private const string loaderName = "Loader";
private const string filterLoaderName = "FilterLoader";
[HarmonyPatch(typeof(InserterInstance), "SimUpdate")]
[HarmonyPrefix]
private static void BlockVisuals(InserterInstance __instance)
{
//IL_0043: Unknown result type (might be due to invalid IL or missing references)
//IL_0049: Expected O, but got Unknown
//IL_004a: Unknown result type (might be due to invalid IL or missing references)
//IL_004b: Unknown result type (might be due to invalid IL or missing references)
if (!(((ResourceInfo)((InserterInstance)(ref __instance)).myDef).displayName != "Loader") || !(((ResourceInfo)((InserterInstance)(ref __instance)).myDef).displayName != "FilterLoader"))
{
InserterMachineList val = (InserterMachineList)MachineManager.instance.GetMachineList((MachineTypeEnum)7);
int num = default(int);
if (((MachineInstanceList<InserterInstance, InserterDefinition>)(object)val).TryGetVisualIndex(__instance.commonInfo.index, ref num))
{
((MachineInstanceList<InserterInstance, InserterDefinition>)(object)val).visualsList[num].commonData.showGPUIMeshes = false;
}
}
}
}
internal class FlowManagerPatch
{
[HarmonyPatch(typeof(FlowManager), "SwitchStrataTrampoline")]
[HarmonyPostfix]
private static void RedoVisuals()
{
MachineDefinitionPatch.RedoVisualsOnStrataChanged();
}
}
internal class MachineDefinitionPatch
{
public static GameObject prefabLoader;
public static GameObject filterPrefab;
private static Dictionary<uint, GameObject> visualsMap = new Dictionary<uint, GameObject>();
[HarmonyPatch(typeof(MachineDefinition<InserterInstance, InserterDefinition>), "OnBuild")]
[HarmonyPostfix]
private static void AddToLoaderList(MachineInstanceRef<InserterInstance> instRef)
{
//IL_0023: Unknown result type (might be due to invalid IL or missing references)
//IL_0042: Unknown result type (might be due to invalid IL or missing references)
string displayName = ((ResourceInfo)((InserterInstance)(ref instRef.Get())).myDef).displayName;
if (displayName == "Loader")
{
AddLoaderVisuals(instRef, prefabLoader);
}
else
{
if (!(displayName == "FilterLoader"))
{
return;
}
AddLoaderVisuals(instRef, filterPrefab);
}
LoaderPlugin.loaderIDs.Add(instRef.GetCommonInfo().instanceId);
}
private static void AddLoaderVisuals(MachineInstanceRef<InserterInstance> instRef, GameObject loaderPrefab)
{
//IL_002c: Unknown result type (might be due to invalid IL or missing references)
//IL_0031: Unknown result type (might be due to invalid IL or missing references)
//IL_0049: Unknown result type (might be due to invalid IL or missing references)
//IL_004e: Unknown result type (might be due to invalid IL or missing references)
//IL_004f: Unknown result type (might be due to invalid IL or missing references)
//IL_005f: Unknown result type (might be due to invalid IL or missing references)
//IL_0064: Unknown result type (might be due to invalid IL or missing references)
//IL_0069: Unknown result type (might be due to invalid IL or missing references)
//IL_0085: Unknown result type (might be due to invalid IL or missing references)
//IL_008d: Unknown result type (might be due to invalid IL or missing references)
//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
if (instRef.gridInfo.strata == GameState.instance.GetStrata())
{
Vector3 bottomCenter = ((GridInfo)(ref instRef.gridInfo)).BottomCenter;
Quaternion val = Quaternion.Euler(0f, (float)instRef.gridInfo.yawRot, 0f);
val *= Quaternion.Euler(0f, -90f, 0f);
LoaderPlugin.Log.LogInfo((object)$"Instantiating prefab for {((ResourceInfo)((InserterInstance)(ref instRef.Get())).myDef).displayName} at position {bottomCenter}, rotation {((Quaternion)(ref val)).eulerAngles}");
GameObject val2 = Object.Instantiate<GameObject>(loaderPrefab, bottomCenter, val);
val2.transform.localScale = new Vector3(1.31f, 1.31f, 1.31f);
if (visualsMap.ContainsKey(instRef.instanceId))
{
Object.Destroy((Object)(object)visualsMap[instRef.instanceId]);
}
visualsMap[instRef.instanceId] = val2;
}
}
[HarmonyPatch(typeof(MachineDefinition<InserterInstance, InserterDefinition>), "OnDeconstruct")]
[HarmonyPrefix]
private static void RemoveVisuals(ref InserterInstance erasedInstance)
{
string displayName = ((ResourceInfo)((InserterInstance)(ref erasedInstance)).myDef).displayName;
if ((!(displayName != "Loader") || !(displayName != "FilterLoader")) && visualsMap.ContainsKey(erasedInstance.commonInfo.instanceId))
{
Object.Destroy((Object)(object)visualsMap[erasedInstance.commonInfo.instanceId]);
visualsMap.Remove(erasedInstance.commonInfo.instanceId);
}
}
public static void RedoVisualsOnStrataChanged()
{
//IL_004f: Unknown result type (might be due to invalid IL or missing references)
//IL_0054: Unknown result type (might be due to invalid IL or missing references)
//IL_0087: Unknown result type (might be due to invalid IL or missing references)
//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
if (!LoadingStates.hasGameLoaded)
{
return;
}
ClearVisuals();
IMachineInstanceRef val = default(IMachineInstanceRef);
foreach (uint loaderID in LoaderPlugin.loaderIDs)
{
if (MachineManager.instance.GetRefFromId(loaderID, ref val) && val is MachineInstanceRef<InserterInstance> instRef)
{
string displayName = ((ResourceInfo)((InserterInstance)(ref instRef.Get())).myDef).displayName;
if (displayName == "Loader")
{
AddLoaderVisuals(instRef, prefabLoader);
}
else if (displayName == "FilterLoader")
{
AddLoaderVisuals(instRef, filterPrefab);
}
}
}
}
private static void UpdateVisualsRotation()
{
//IL_0062: Unknown result type (might be due to invalid IL or missing references)
//IL_0067: Unknown result type (might be due to invalid IL or missing references)
//IL_0069: Unknown result type (might be due to invalid IL or missing references)
//IL_007a: Unknown result type (might be due to invalid IL or missing references)
//IL_007f: Unknown result type (might be due to invalid IL or missing references)
//IL_0084: Unknown result type (might be due to invalid IL or missing references)
//IL_008c: Unknown result type (might be due to invalid IL or missing references)
MachineInstanceRef<InserterInstance> val = default(MachineInstanceRef<InserterInstance>);
foreach (uint loaderID in LoaderPlugin.loaderIDs)
{
if (MachineManager.instance.GetRefFromId<InserterInstance>(loaderID, ref val) && visualsMap.TryGetValue(loaderID, out var value))
{
Quaternion val2 = Quaternion.Euler(0f, (float)val.gridInfo.yawRot, 0f);
val2 *= Quaternion.Euler(0f, -90f, 0f);
value.transform.rotation = val2;
}
}
}
internal static void OnGameUnloaded()
{
ClearVisuals();
}
private static void ClearVisuals()
{
foreach (GameObject value in visualsMap.Values)
{
Object.Destroy((Object)(object)value);
}
visualsMap.Clear();
}
public static void UpdateAll()
{
UpdateVisualsRotation();
}
}
}