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 HarmonyLib;
using Microsoft.CodeAnalysis;
using Photon.Pun;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("Omniscye")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+7caf00520587bc4705fdf22c05a4ce546279ff19")]
[assembly: AssemblyProduct("EmpressShopAPI")]
[assembly: AssemblyTitle("EmpressShopAPI")]
[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.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]
[Microsoft.CodeAnalysis.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]
[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 Empress_ShopLoaderAPI
{
[BepInPlugin("com.Empress.ShopAPI", "Empress Shop Loader API", "1.0.0")]
public class ShopLoaderPlugin : BaseUnityPlugin
{
internal class ShopEntry
{
public GameObject Prefab;
public string ResourcePath;
public ConfigEntry<bool> EnabledConfig;
}
internal static ShopLoaderPlugin Instance;
internal static List<ShopEntry> RegisteredShops = new List<ShopEntry>();
private void Awake()
{
Instance = this;
Harmony.CreateAndPatchAll(typeof(LevelGeneratorPatch), (string)null);
}
}
public static class ShopAPI
{
public static void RegisterShop(GameObject shopPrefab, string uniqueResourcePath)
{
if (!((Object)(object)shopPrefab == (Object)null) && !((Object)(object)ShopLoaderPlugin.Instance == (Object)null))
{
Object.DontDestroyOnLoad((Object)(object)shopPrefab);
((Object)shopPrefab).hideFlags = (HideFlags)32;
ConfigEntry<bool> enabledConfig = ((BaseUnityPlugin)ShopLoaderPlugin.Instance).Config.Bind<bool>("Registered Shops", uniqueResourcePath, true, "Enable the " + uniqueResourcePath + " shop.");
ShopLoaderPlugin.RegisteredShops.Add(new ShopLoaderPlugin.ShopEntry
{
Prefab = shopPrefab,
ResourcePath = uniqueResourcePath,
EnabledConfig = enabledConfig
});
}
}
}
[HarmonyPatch(typeof(LevelGenerator), "Start")]
public static class LevelGeneratorPatch
{
private static void Postfix(LevelGenerator __instance)
{
//IL_0103: Unknown result type (might be due to invalid IL or missing references)
//IL_0108: Unknown result type (might be due to invalid IL or missing references)
//IL_0146: Unknown result type (might be due to invalid IL or missing references)
//IL_014d: Expected O, but got Unknown
if (!SemiFunc.RunIsShop())
{
return;
}
List<ShopLoaderPlugin.ShopEntry> list = ShopLoaderPlugin.RegisteredShops.Where((ShopLoaderPlugin.ShopEntry x) => x.EnabledConfig.Value).ToList();
if (list.Count != 0)
{
ShopLoaderPlugin.ShopEntry shopEntry = list[Random.Range(0, list.Count)];
RunManager instance = RunManager.instance;
if (instance.singleplayerPool != null && !instance.singleplayerPool.ContainsKey(shopEntry.ResourcePath))
{
instance.singleplayerPool.Add(shopEntry.ResourcePath, shopEntry.Prefab);
}
DefaultPool multiplayerPool = instance.multiplayerPool;
if (multiplayerPool?.ResourceCache != null && !multiplayerPool.ResourceCache.ContainsKey(shopEntry.ResourcePath))
{
multiplayerPool.ResourceCache.Add(shopEntry.ResourcePath, shopEntry.Prefab);
}
Vector3[] value = (Vector3[])(object)new Vector3[1] { Vector3.zero };
AccessTools.Field(typeof(LevelGenerator), "ModuleRotations").SetValue(__instance, value);
Level levelCurrent = instance.levelCurrent;
if ((Object)(object)levelCurrent != (Object)null)
{
PrefabRef val = new PrefabRef();
AccessTools.Field(typeof(PrefabRef), "prefabName").SetValue(val, ((Object)shopEntry.Prefab).name);
AccessTools.Field(typeof(PrefabRef), "resourcePath").SetValue(val, shopEntry.ResourcePath);
levelCurrent.StartRooms.Clear();
levelCurrent.StartRooms.Add(val);
levelCurrent.ModulesNormal1.Clear();
levelCurrent.ModulesNormal2.Clear();
levelCurrent.ModulesNormal3.Clear();
}
}
}
}
}