using System;
using System.Collections.Generic;
using System.Diagnostics;
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.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
[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("ShipTurrets")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Plugin that spawns two turrets on the front and rear of the player ship that targets and neutralises enemies instead of players.")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("ShipTurrets")]
[assembly: AssemblyTitle("ShipTurrets")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.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 ShipTurrets
{
public static class PluginInfo
{
public const string PLUGIN_GUID = "ShipTurrets";
public const string PLUGIN_NAME = "ShipTurrets";
public const string PLUGIN_VERSION = "1.0.0";
}
}
namespace MapSeedPlugin
{
public enum InteriorEnum
{
Factory = 0,
Manor = 1,
Mineshaft = 4
}
[BepInPlugin("com.woah25.SelectInteriors", "SelectInteriors", "1.0.0")]
public class MapSeedPlugin : BaseUnityPlugin
{
public static ConfigEntry<bool> ConfigLegacyMode;
public static ConfigEntry<InteriorEnum> ConfigSelectedInterior;
public static ManualLogSource LoggerInstance;
private void Awake()
{
//IL_0050: Unknown result type (might be due to invalid IL or missing references)
ConfigLegacyMode = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "LegacyMode", false, "Enable legacy mode");
ConfigSelectedInterior = ((BaseUnityPlugin)this).Config.Bind<InteriorEnum>("General", "SelectedInterior", InteriorEnum.Mineshaft, "Select the interior type to always be generated");
LoggerInstance = ((BaseUnityPlugin)this).Logger;
new Harmony("SelectInteriors").PatchAll();
((BaseUnityPlugin)this).Logger.LogInfo((object)"SelectInteriors loaded.");
}
}
[HarmonyPatch(typeof(StartOfRound), "ChooseNewRandomMapSeed")]
public class ChooseNewRandomMapSeedPatch
{
private static void Postfix(StartOfRound __instance)
{
if (MapSeedPlugin.ConfigLegacyMode.Value)
{
return;
}
InteriorEnum value = MapSeedPlugin.ConfigSelectedInterior.Value;
int randomMapSeed = __instance.randomMapSeed;
RoundManager instance = RoundManager.Instance;
InteriorEnum? interiorEnum = CalcInteriorType(randomMapSeed, instance);
if (!interiorEnum.HasValue)
{
return;
}
if (interiorEnum.GetValueOrDefault() == value)
{
MapSeedPlugin.LoggerInstance.LogInfo((object)$"Detected the current map seed ({randomMapSeed}) will generate {value} interior, doing nothing.");
return;
}
MapSeedPlugin.LoggerInstance.LogInfo((object)$"Detected the current map seed ({randomMapSeed}) will generate {interiorEnum} interior, regenerating to get {value}.");
instance.hasInitializedLevelRandomSeed = false;
instance.InitializeRandomNumberGenerators();
for (int i = 0; i < 1000; i++)
{
randomMapSeed = NewMapSeed();
interiorEnum = CalcInteriorType(randomMapSeed, instance);
MapSeedPlugin.LoggerInstance.LogInfo((object)$"Try No.{i} (Seed {randomMapSeed}) Interior: {interiorEnum}");
if (!interiorEnum.HasValue)
{
MapSeedPlugin.LoggerInstance.LogWarning((object)"Detected unknown interior type. Ignoring.");
return;
}
if (interiorEnum.GetValueOrDefault() == value)
{
__instance.randomMapSeed = randomMapSeed;
MapSeedPlugin.LoggerInstance.LogInfo((object)$"Generated {value} map seed: {randomMapSeed} after {i + 1} retries.");
return;
}
}
MapSeedPlugin.LoggerInstance.LogWarning((object)$"Failed to generate {value} after 1000 retries.");
}
private static InteriorEnum? CalcInteriorType(int mapSeed, RoundManager roundManager)
{
Random random = new Random(mapSeed);
if (roundManager.currentLevel.dungeonFlowTypes == null || roundManager.currentLevel.dungeonFlowTypes.Length == 0)
{
return null;
}
List<int> list = roundManager.currentLevel.dungeonFlowTypes.Select((IntWithRarity flowType) => flowType.rarity).ToList();
MapSeedPlugin.LoggerInstance.LogDebug((object)("List: " + string.Join(", ", list)));
int randomWeightedIndex = roundManager.GetRandomWeightedIndex(list.ToArray(), random);
MapSeedPlugin.LoggerInstance.LogDebug((object)$"randomWeightedIndex: {randomWeightedIndex}");
int id = roundManager.currentLevel.dungeonFlowTypes[randomWeightedIndex].id;
MapSeedPlugin.LoggerInstance.LogDebug((object)$"mapId: {id}");
if (Enum.IsDefined(typeof(InteriorEnum), id))
{
return (InteriorEnum)id;
}
return null;
}
private static int NewMapSeed()
{
return Random.Range(1, 100000000);
}
}
[HarmonyPatch(typeof(RoundManager), "GenerateNewFloor")]
public class GenerateNewFloorPatch
{
private static bool Prefix(RoundManager __instance)
{
if (!MapSeedPlugin.ConfigLegacyMode.Value)
{
return true;
}
InteriorEnum selectedInterior = MapSeedPlugin.ConfigSelectedInterior.Value;
__instance.currentLevel.dungeonFlowTypes = __instance.currentLevel.dungeonFlowTypes.Where((IntWithRarity dungeonFlowType) => dungeonFlowType.id == (int)selectedInterior).ToArray();
MapSeedPlugin.LoggerInstance.LogInfo((object)$"Forced {selectedInterior} generation for {((Object)__instance.currentLevel).name}.");
return true;
}
}
}