Decompiled source of Archipelago v0.1.0

Archipelago.dll

Decompiled 3 days ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using GameData;
using HarmonyLib;
using Il2CppInterop.Runtime.Injection;
using Il2CppInterop.Runtime.InteropTypes;
using Il2CppSystem.Collections.Generic;
using Microsoft.CodeAnalysis;
using ReTFO.ArchipelagoCore;
using ReTFO.ArchipelagoCore.Features;
using ReTFO.ArchipelagoCore.Features.ObjectiveHandlers;
using ReTFO.ArchipelagoCore.Features.Pickups;
using ReTFO.ArchipelagoCore.Features.ZoneHandlers;
using ReTFO.ArchipelagoCore.FeaturesAPI;
using ReTFO.ArchipelagoCore.ModdedInstanceData;
using ReTFO.ArchipelagoCore.ModdedInstanceData.Model;
using ReTFO.ArchipelagoCore.ModdedInstanceData.Processors;
using ReTFO.ArchipelagoCore.Utilities;
using TheArchive;
using TheArchive.Core;
using TheArchive.Core.Attributes;
using TheArchive.Core.Attributes.Feature.Settings;
using TheArchive.Core.Localization;
using TheArchive.Interfaces;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("Archipelago")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+91c2a0683dea8ad2fb4d02133239b6ba538b620e")]
[assembly: AssemblyProduct("Archipelago")]
[assembly: AssemblyTitle("Archipelago")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[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]
	[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]
	[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 ReTFO.Archipelago
{
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct, AllowMultiple = false)]
	internal class InjectToIl2Cpp : Attribute
	{
		public Type[] InterfaceTypes;

		public InjectToIl2Cpp()
		{
			InterfaceTypes = Array.Empty<Type>();
		}

		public InjectToIl2Cpp(Type type)
		{
			InterfaceTypes = new Type[1] { type };
		}

		public InjectToIl2Cpp(Type[] types)
		{
			InterfaceTypes = types;
		}
	}
	[BepInPlugin("RoboRyGuy.ArchipelagoVanilla", "ArchipelagoVanilla", "0.1.0")]
	[BepInProcess("GTFO.exe")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BasePlugin
	{
		public const string Name = "ArchipelagoVanilla";

		public const string Author = "RoboRyGuy";

		public const string GUID = "RoboRyGuy.ArchipelagoVanilla";

		public const string Version = "0.1.0";

		private static Plugin? _plugin;

		protected Harmony harmony = new Harmony("RoboRyGuy.ArchipelagoVanilla");

		private ArchipelagoArchiveModule? m_archiveModule;

		public ArchipelagoArchiveModule ArchiveModule
		{
			get
			{
				return m_archiveModule ?? (m_archiveModule = ArchiveMod.Modules.OfType<ArchipelagoArchiveModule>().First());
			}
			internal set
			{
				m_archiveModule = value;
			}
		}

		public IArchiveLogger Logger => ArchiveModule.Logger;

		public static Plugin Get()
		{
			return TryGet() ?? throw new NullReferenceException("Tried to retrieve ArchipelagoVanilla, but it was not loaded!");
		}

		public static Plugin? TryGet()
		{
			return _plugin ?? (_plugin = ((BaseChainloader<BasePlugin>)(object)IL2CPPChainloader.Instance).Plugins.FirstOrDefault((KeyValuePair<string, PluginInfo> p) => p.Key == "RoboRyGuy.ArchipelagoVanilla").Value.Instance as Plugin);
		}

		public static bool TryGet([NotNullWhen(true)] out Plugin? plugin)
		{
			plugin = TryGet();
			return plugin != null;
		}

		public override void Load()
		{
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Expected O, but got Unknown
			_plugin = this;
			harmony.PatchAll(((object)this).GetType());
			IEnumerable<Type> types = from t in Assembly.GetExecutingAssembly().GetTypes()
				where t.DeclaringType == null
				select t;
			InjectRecursive(types);
			PatchRecursive(types);
			SetUpArchipelago();
			ManualLogSource log = ((BasePlugin)this).Log;
			bool flag = default(bool);
			BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(11, 1, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("RoboRyGuy.ArchipelagoVanilla");
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" is loaded!");
			}
			log.LogInfo(val);
		}

		public override bool Unload()
		{
			harmony.UnpatchSelf();
			return true;
		}

		private void InjectRecursive(IEnumerable<Type> types)
		{
			//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_0043: Expected O, but got Unknown
			foreach (Type type in types)
			{
				InjectToIl2Cpp customAttribute = type.GetCustomAttribute<InjectToIl2Cpp>();
				if (customAttribute != null)
				{
					if (type.IsAssignableTo(typeof(Il2CppObjectBase)))
					{
						RegisterTypeOptions val = new RegisterTypeOptions();
						val.set_Interfaces(Il2CppInterfaceCollection.op_Implicit(customAttribute.InterfaceTypes));
						RegisterTypeOptions val2 = val;
						ClassInjector.RegisterTypeInIl2Cpp(type, val2);
					}
					InjectRecursive(type.GetNestedTypes(AccessTools.all));
				}
			}
		}

		private void PatchRecursive(IEnumerable<Type> types)
		{
			foreach (Type type in types)
			{
				if (((MemberInfo)type).GetCustomAttribute<HarmonyPatch>() != null)
				{
					harmony.PatchAll(type);
					PatchRecursive(type.GetNestedTypes(AccessTools.all));
				}
			}
		}

		private void SetUpArchipelago()
		{
			Plugin val = Plugin.Get();
			val.MidManager.AddNamedHash("grKE4GD3ryTqcYMm5qGsWSUUm3GKSiilVU5sG4k_2wk=", "Vanilla");
			val.MidManager.PreProcessGameData += PreProcessGameData;
			Processor<Data> processor = val.MidManager.GetProcessor<Data>();
			Processor val2 = (Processor)(object)((processor is Processor) ? processor : null);
			((List<Func<bool, ExpeditionDescriptor, ExpeditionInTierData, bool>>)(object)val2.ExpeditionValidator).Add((Func<bool, ExpeditionDescriptor, ExpeditionInTierData, bool>)VanillaExpeditionValidator);
		}

		public static void PreProcessGameData(Data data)
		{
			//IL_00bb: 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)
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: Expected O, but got Unknown
			TriggerEventsHandler feature = ArchipelagoFeatureHelper.GetFeature<TriggerEventsHandler>();
			if (!((List<Func<int, Data, List<WorldEventFromSourceData>, int>>)(object)feature.Subhandlers).Contains((Func<int, Data, List<WorldEventFromSourceData>, int>)VanillaTriggerEventSubhandler))
			{
				((List<Func<int, Data, List<WorldEventFromSourceData>, int>>)(object)feature.Subhandlers).Insert(0, (Func<int, Data, List<WorldEventFromSourceData>, int>)VanillaTriggerEventSubhandler);
			}
			foreach (ExpeditionInTierData item in ((IEnumerable<RundownDataBlock>)GameDataBlockBase<RundownDataBlock>.GetAllBlocks()).SelectMany(UnpackExpeditions))
			{
				if (!Il2CppListIter.Any<DimensionInExpeditionData>(item.DimensionDatas, (Func<DimensionInExpeditionData, bool>)((DimensionInExpeditionData d) => d.Enabled && (int)d.DimensionIndex == 22)))
				{
					item.DimensionDatas.Add(new DimensionInExpeditionData
					{
						Enabled = true,
						DimensionIndex = (eDimensionIndex)22,
						DimensionData = 14u
					});
				}
			}
			LevelLayoutDataBlock block = GameDataBlockBase<LevelLayoutDataBlock>.GetBlock(1044535672u);
			if (((GameDataBlockBase<LevelLayoutDataBlock>)(object)block)?.name == "R7_E1_Reactor_Startup_L1")
			{
				block.Zones[18].AllowResourceContainerAllocation = false;
			}
			block = GameDataBlockBase<LevelLayoutDataBlock>.GetBlock(1556013495u);
			if (((GameDataBlockBase<LevelLayoutDataBlock>)(object)block)?.name == "R8_D1_Empty_L1")
			{
				block.Zones[2].MarkerSubSeed = 0;
			}
			static IEnumerable<ExpeditionInTierData> UnpackExpeditions(RundownDataBlock rundown)
			{
				for (int i = 0; i < rundown.TierA.Count; i++)
				{
					yield return rundown.TierA[i];
				}
				for (int i = 0; i < rundown.TierB.Count; i++)
				{
					yield return rundown.TierB[i];
				}
				for (int i = 0; i < rundown.TierC.Count; i++)
				{
					yield return rundown.TierC[i];
				}
				for (int i = 0; i < rundown.TierD.Count; i++)
				{
					yield return rundown.TierD[i];
				}
				for (int i = 0; i < rundown.TierE.Count; i++)
				{
					yield return rundown.TierE[i];
				}
			}
		}

		public static bool VanillaExpeditionValidator(bool wasValid, ExpeditionDescriptor desc, ExpeditionInTierData expedition)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			if (!wasValid)
			{
				return false;
			}
			if (((GameDataBlockBase<RundownDataBlock>)(object)desc.Rundown).persistentID == 27 && ((GameDataBlockBase<RundownDataBlock>)(object)desc.Rundown).name == "Geomorph Tester")
			{
				return false;
			}
			return true;
		}

		public static int VanillaTriggerEventSubhandler(int numProcessed, Data data, List<WorldEventFromSourceData> events)
		{
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: 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_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_010a: Unknown result type (might be due to invalid IL or missing references)
			//IL_010f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_016d: 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_018b: 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_019e: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ba: Unknown result type (might be due to invalid IL or missing references)
			string text;
			Data val;
			ItemID val2;
			if (data.ZoneName == "R8A1 (Main) ZONE_74" && ((GameDataBlockBase<RundownDataBlock>)(object)((Data)data).Rundown).persistentID == 35 && ((GameDataBlockBase<RundownDataBlock>)(object)((Data)data).Rundown).name == "Rundown 8.0")
			{
				text = "Evt_Shuttlebox_Interact_R8A1";
				val = Zone.FindZoneByIndex(Layer.GetLayer((Data)(object)data, LayerType.Main), (eLocalZoneIndex)4);
				val2 = RetrieveBigItemsHandler_Tags.Item_BigRetrieval_Instance(Objective.GetObjectiveDatas((Data)(object)data).ElementAt(0), 1);
			}
			else if (data.ZoneName == "R8D2 (Main) ZONE_41" && ((GameDataBlockBase<RundownDataBlock>)(object)((Data)data).Rundown).persistentID == 35 && ((GameDataBlockBase<RundownDataBlock>)(object)((Data)data).Rundown).name == "Rundown 8.0")
			{
				text = "WE_Hearsay_Interact_02";
				val = Zone.FindZoneByIndex(Layer.GetLayer((Data)(object)data, LayerType.Main), (eLocalZoneIndex)7);
				val2 = default(ItemID);
			}
			else if (data.CustomGeo == "Assets/AssetPrefabs/Complex/Tech/Geomorphs/geo_64x64_Lab_dead_end_room_02_R8C2.prefab")
			{
				text = "WE_Dataextractor_Interact";
				val = data;
				val2 = BigPickupHandler_Tags.Item_BigPickup_Instance((Data)(object)data, 181u);
			}
			else
			{
				if (!(data.CustomGeo == "Assets/AssetPrefabs/Complex/Service/Geomorphs/Gardens/geo_64x64_service_gardens_X_01.prefab"))
				{
					return numProcessed;
				}
				text = "Evt_Shuttlebox_Interact_R7B1";
				val = data;
				val2 = BigPickupHandler_Tags.Item_BigPickup_Instance((Data)(object)data, 173u);
			}
			List<WardenObjectiveEventData> val3 = new List<WardenObjectiveEventData>();
			for (int i = 0; i < events.Count - numProcessed; i++)
			{
				if (events[i].WorldEventTriggerObjectFilter == text)
				{
					val3.Add((WardenObjectiveEventData)(object)events[i]);
					events.RemoveAt(i--);
				}
			}
			if (val3.Count == 0)
			{
				return numProcessed;
			}
			RegionID val4 = TriggerEventsHandler_Tags.Region_OnTriggerEvents(val, text);
			Path val5 = default(Path);
			((Path)(ref val5))..ctor();
			((Path)(ref val5)).set_StartingRegion(val.Region_Zone);
			((Path)(ref val5)).set_EndingRegion(val4);
			((Path)(ref val5)).set_Reqs(((ItemID)(ref val2)).IsNull ? new MultiPathReq() : new MultiPathReq((eType)1, val2, 1u));
			((Data)data).AddPath(val5);
			Event.ProcessEvents((Data)(object)data, val4, val3);
			Enumerator<WardenObjectiveEventData> enumerator = val3.GetEnumerator();
			while (enumerator.MoveNext())
			{
				WardenObjectiveEventData current = enumerator.Current;
				events.Add(TriggerEventsHandler.AsTriggerData(current, text));
			}
			return numProcessed + val3.Count;
		}
	}
	[ArchiveModule("RoboRyGuy.ArchipelagoVanilla", "ArchipelagoVanilla", "0.1.0")]
	[ArchiveDependency(/*Could not decode attribute arguments.*/)]
	public class ArchipelagoArchiveModule : IArchiveModule
	{
		public class SpawnTanksDeathLinkEffect : SpawnEnemyEffect
		{
			[FSSeparator]
			[FSDisplayName("Spawn Tanks")]
			[FSDescription("If on, spawns one or more tanks when a deathlink is received.")]
			public bool IsEnabled { get; set; }

			public override string GetID()
			{
				return "ArchipelagoVanilla.Effects.SpawnTanks";
			}

			public override bool GetIsEnabled()
			{
				return IsEnabled;
			}

			public override uint GetEnemyID()
			{
				return 29u;
			}

			public SpawnTanksDeathLinkEffect()
			{
				((SpawnEnemyEffect)this).SpawnMode = (eSpawnMode)0;
				((SpawnEnemyEffect)this).Quantity = 1;
			}
		}

		public class SpawnSnatchersDeathLinkEffect : SpawnEnemyEffect
		{
			[FSSeparator]
			[FSDisplayName("Spawn Snatchers")]
			[FSDescription("If on, spawns one or more snatchers when a deathlink is received.")]
			public bool IsEnabled { get; set; }

			public override string GetID()
			{
				return "ArchipelagoVanilla.Effects.SpawnSnatchers";
			}

			public override bool GetIsEnabled()
			{
				return IsEnabled;
			}

			public override uint GetEnemyID()
			{
				return 46u;
			}

			public SpawnSnatchersDeathLinkEffect()
			{
				((SpawnEnemyEffect)this).SpawnMode = (eSpawnMode)1;
				((SpawnEnemyEffect)this).Quantity = 2;
			}
		}

		public class SpawnNightmareScoutsDeathLinkEffect : SpawnEnemyEffect
		{
			[FSSeparator]
			[FSDisplayName("Spawn Nightmare Scouts")]
			[FSDescription("If on, spawns one or more nightmare scouts when a deathlink is received.")]
			public bool IsEnabled { get; set; }

			public override string GetID()
			{
				return "ArchipelagoVanilla.Effects.SpawnNightmareScouts";
			}

			public override bool GetIsEnabled()
			{
				return IsEnabled;
			}

			public override uint GetEnemyID()
			{
				return 56u;
			}

			public SpawnNightmareScoutsDeathLinkEffect()
			{
				((SpawnEnemyEffect)this).SpawnMode = (eSpawnMode)4;
				((SpawnEnemyEffect)this).Quantity = 2;
			}
		}

		private IArchiveLogger? m_logger;

		public ILocalizationService LocalizationService { get; set; }

		public IArchiveLogger Logger
		{
			get
			{
				return m_logger ?? throw new NullReferenceException("Module logger was not initalized!");
			}
			set
			{
				m_logger = value;
			}
		}

		public void Init()
		{
			if (!Plugin.TryGet(out Plugin plugin))
			{
				Logger.Error("Failed to find Plugin while loading Archipelago Archive Module!");
			}
			else
			{
				plugin.ArchiveModule = this;
			}
			DeathLinkHandler.RegisterDeathEffect((DeathLinkEffect)(object)new SpawnTanksDeathLinkEffect());
			DeathLinkHandler.RegisterDeathEffect((DeathLinkEffect)(object)new SpawnSnatchersDeathLinkEffect());
			DeathLinkHandler.RegisterDeathEffect((DeathLinkEffect)(object)new SpawnNightmareScoutsDeathLinkEffect());
		}
	}
}