using System; 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.Configuration; using BepInEx.Logging; using HarmonyLib; using Microsoft.CodeAnalysis; using Pigeon.Math; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: IgnoresAccessChecksTo("Assembly-CSharp")] [assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: AssemblyCompany("Sparroh")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0")] [assembly: AssemblyProduct("AuthoredMapsOnly")] [assembly: AssemblyTitle("AuthoredMapsOnly")] [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.Module, AllowMultiple = false, Inherited = false)] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } [BepInPlugin("sparroh.authoredmapsonly", "AuthoredMapsOnly", "1.0.0")] [MycoMod(/*Could not decode attribute arguments.*/)] public class AuthoredMapsOnlyPlugin : BaseUnityPlugin { public const string PluginGUID = "sparroh.authoredmapsonly"; public const string PluginName = "AuthoredMapsOnly"; public const string PluginVersion = "1.0.0"; internal static ManualLogSource Log; internal static ConfigEntry AuthoredMapsOnly; private Harmony _harmony; internal static bool Enabled { get { if (AuthoredMapsOnly != null) { return AuthoredMapsOnly.Value; } return true; } } private void Awake() { //IL_0031: Unknown result type (might be due to invalid IL or missing references) //IL_003b: Expected O, but got Unknown Log = ((BaseUnityPlugin)this).Logger; AuthoredMapsOnly = ((BaseUnityPlugin)this).Config.Bind("General", "AuthoredMapsOnly", true, "When enabled, missions use hand-authored (designed) maps instead of procedural/uncharted ones whenever authored maps exist for the region."); _harmony = new Harmony("sparroh.authoredmapsonly"); ApplyPatches(); Log.LogInfo((object)string.Format("{0} v{1} loaded (AuthoredMapsOnly={2})", "AuthoredMapsOnly", "1.0.0", Enabled)); } private void ApplyPatches() { //IL_0027: Unknown result type (might be due to invalid IL or missing references) //IL_0032: Expected O, but got Unknown //IL_005a: Unknown result type (might be due to invalid IL or missing references) //IL_0064: Expected O, but got Unknown //IL_015f: Unknown result type (might be due to invalid IL or missing references) //IL_0169: Expected O, but got Unknown TryPatch(AccessTools.Method(typeof(Mission), "GetValidMissions", (Type[])null, (Type[])null), new HarmonyMethod(typeof(AuthoredMapsOnlyPatches), "GetValidMissions_Prefix", (Type[])null)); TryPatch(AccessTools.Method(typeof(Mission), "GetMissionData", (Type[])null, (Type[])null), null, new HarmonyMethod(typeof(AuthoredMapsOnlyPatches), "GetMissionData_Postfix", (Type[])null)); ConstructorInfo constructorInfo = AccessTools.Constructor(typeof(MissionData), new Type[8] { typeof(int), typeof(Mission), typeof(WorldRegion), typeof(SceneData), typeof(MissionContainer), typeof(int), typeof(bool), typeof(Span) }, false); if (constructorInfo == null) { ConstructorInfo[] constructors = typeof(MissionData).GetConstructors(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); int num = -1; ConstructorInfo[] array = constructors; foreach (ConstructorInfo constructorInfo2 in array) { int num2 = constructorInfo2.GetParameters().Length; if (num2 > num) { num = num2; constructorInfo = constructorInfo2; } } if (constructorInfo != null) { Log.LogWarning((object)$"MissionData Span ctor lookup failed; using {num}-param ctor instead."); } } TryPatch(constructorInfo, null, new HarmonyMethod(typeof(AuthoredMapsOnlyPatches), "MissionData_Ctor_Postfix", (Type[])null)); } private void TryPatch(MethodBase original, HarmonyMethod prefix = null, HarmonyMethod postfix = null) { if (original == null) { Log.LogError((object)"Failed to find a patch target method."); return; } try { _harmony.Patch(original, prefix, postfix, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); Log.LogInfo((object)("Patched " + original.DeclaringType?.Name + "." + original.Name)); } catch (Exception arg) { Log.LogError((object)$"Failed to patch {original.DeclaringType?.Name}.{original.Name}: {arg}"); } } } internal static class AuthoredMapsOnlyUtil { internal static bool IsGameReady() { Global instance = Global.Instance; if (instance != null && instance.Regions != null && instance.Regions.Length != 0) { return instance.Missions != null; } return false; } internal static bool RegionHasAuthoredMaps(WorldRegion region) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Unknown result type (might be due to invalid IL or missing references) if (region == null) { return false; } if ((region.Flags & 0x8000) == 0) { return false; } SceneData[] legacyScenes = region.LegacyScenes; if (legacyScenes != null) { return legacyScenes.Length != 0; } return false; } internal static bool TryPickAuthoredScene(WorldRegion region, int seed, out SceneData scene) { //IL_0001: 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_003b: Unknown result type (might be due to invalid IL or missing references) scene = default(SceneData); if (!RegionHasAuthoredMaps(region)) { return false; } SceneData[] legacyScenes = region.LegacyScenes; Random val = default(Random); ((Random)(ref val))..ctor(MathUtil.Squirrel3Hash(seed, 168275997)); scene = legacyScenes[((Random)(ref val)).Next(legacyScenes.Length)]; return ((SceneData)(ref scene)).IsValid; } internal static bool IsProceduralMission(ref MissionData missionData, WorldRegion region) { //IL_0004: Unknown result type (might be due to invalid IL or missing references) //IL_000e: Unknown result type (might be due to invalid IL or missing references) if (region == null || (region.Flags & 0x8000) == 0) { return false; } if (missionData.locationNameID == 0) { return false; } WorldProfile[] worldProfiles = region.WorldProfiles; if (worldProfiles == null || worldProfiles.Length == 0) { return false; } SceneData[] scenes = region.Scenes; if (scenes == null) { return false; } for (int i = 0; i < scenes.Length; i++) { if (Global.GetSceneIndex(scenes[i].scene) == missionData.sceneIndex) { return true; } } return false; } internal static void ForceAuthoredScene(ref MissionData missionData, WorldRegion region = null, Mission mission = null, int seed = int.MinValue) { //IL_00b6: 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) if (!AuthoredMapsOnlyPlugin.Enabled || !IsGameReady()) { return; } if (region == null) { if (missionData.regionIndex < 0 || missionData.regionIndex >= Global.Instance.Regions.Length) { return; } region = Global.Instance.Regions[missionData.regionIndex]; } if (RegionHasAuthoredMaps(region)) { if (mission == null && missionData.missionIndex >= 0 && missionData.missionIndex < Global.Instance.Missions.Length) { mission = Global.Instance.Missions[missionData.missionIndex]; } if (seed == int.MinValue) { seed = ((MissionData)(ref missionData)).Seed; } SceneData val = default(SceneData); if ((mission == null || !mission.OverrideScene(ref val, region, seed)) && IsProceduralMission(ref missionData, region) && TryPickAuthoredScene(region, seed, out var scene)) { missionData.sceneIndex = Global.GetSceneIndex(scene.scene); ((MissionData)(ref missionData)).SetLocation(scene); } } } } internal static class AuthoredMapsOnlyPatches { public static void GetValidMissions_Prefix(ref LevelFlags compatibleLevels) { //IL_0022: Unknown result type (might be due to invalid IL or missing references) //IL_003a: Unknown result type (might be due to invalid IL or missing references) //IL_0044: 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_0052: Unknown result type (might be due to invalid IL or missing references) //IL_0053: Unknown result type (might be due to invalid IL or missing references) if (!AuthoredMapsOnlyPlugin.Enabled || !AuthoredMapsOnlyUtil.IsGameReady() || ((uint)compatibleLevels & 0x8000u) == 0) { return; } LevelFlags val = (LevelFlags)((int)compatibleLevels & 0x640F0); WorldRegion[] regions = Global.Instance.Regions; foreach (WorldRegion val2 in regions) { if (val2 != null && (val2.Flags & 0x8000) != 0 && (LevelFlags)(val2.Flags & 0x640F0) == val && AuthoredMapsOnlyUtil.RegionHasAuthoredMaps(val2)) { compatibleLevels = (LevelFlags)((uint)compatibleLevels & 0xFFFF7FFFu); break; } } } public static void GetMissionData_Postfix(ref MissionData __result) { AuthoredMapsOnlyUtil.ForceAuthoredScene(ref __result); } public static void MissionData_Ctor_Postfix(ref MissionData __instance, int seed, Mission mission, WorldRegion region) { if (region != null) { AuthoredMapsOnlyUtil.ForceAuthoredScene(ref __instance, region, mission, seed); } } } namespace AuthoredMapsOnly { public static class MyPluginInfo { public const string PLUGIN_GUID = "AuthoredMapsOnly"; public const string PLUGIN_NAME = "AuthoredMapsOnly"; public const string PLUGIN_VERSION = "1.0.0"; } } namespace System.Runtime.CompilerServices { [AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)] internal sealed class IgnoresAccessChecksToAttribute : Attribute { public IgnoresAccessChecksToAttribute(string assemblyName) { } } }