using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using JetBrains.Annotations;
using Jotunn.Configs;
using Jotunn.Entities;
using Jotunn.Managers;
using Jotunn.Utils;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("AdvancedPortals")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Randy Knapp Mods")]
[assembly: AssemblyProduct("AdvancedPortals")]
[assembly: AssemblyCopyright("Copyright © Randy Knapp 2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("0ddde55c-5daf-4b53-b5e2-83b5c44c4682")]
[assembly: AssemblyFileVersion("1.1.3")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.1.3.0")]
[module: UnverifiableCode]
public static class PlayerExtensions
{
public static ZDO GetZDO(this Player player)
{
return ((Character)player).m_nview.GetZDO();
}
}
namespace Common
{
public class ConfigPositionedElement : MonoBehaviour
{
public ConfigEntry<TextAnchor> AnchorConfig;
public ConfigEntry<Vector2> PositionConfig;
protected RectTransform _rt;
protected TextAnchor _currentAnchor;
public virtual void Awake()
{
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_0011: Expected O, but got Unknown
_rt = (RectTransform)((Component)this).transform;
EnsureCorrectPosition();
}
public virtual void Update()
{
EnsureCorrectPosition();
}
public virtual void EnsureCorrectPosition()
{
//IL_0011: Unknown result type (might be due to invalid IL or missing references)
//IL_001c: 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_004d: 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)
//IL_0058: Unknown result type (might be due to invalid IL or missing references)
//IL_0059: Unknown result type (might be due to invalid IL or missing references)
//IL_0083: Expected I4, but got Unknown
//IL_0029: 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_00ab: 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_00b2: Unknown result type (might be due to invalid IL or missing references)
//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
//IL_00b9: 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_00ed: Unknown result type (might be due to invalid IL or missing references)
//IL_00ee: 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_00f5: Unknown result type (might be due to invalid IL or missing references)
//IL_0123: 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_012a: Unknown result type (might be due to invalid IL or missing references)
//IL_012b: Unknown result type (might be due to invalid IL or missing references)
//IL_0131: Unknown result type (might be due to invalid IL or missing references)
//IL_015f: Unknown result type (might be due to invalid IL or missing references)
//IL_0165: Unknown result type (might be due to invalid IL or missing references)
//IL_0166: Unknown result type (might be due to invalid IL or missing references)
//IL_0167: 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_019b: Unknown result type (might be due to invalid IL or missing references)
//IL_01a1: Unknown result type (might be due to invalid IL or missing references)
//IL_01a2: Unknown result type (might be due to invalid IL or missing references)
//IL_01a3: Unknown result type (might be due to invalid IL or missing references)
//IL_01a9: Unknown result type (might be due to invalid IL or missing references)
//IL_01d7: Unknown result type (might be due to invalid IL or missing references)
//IL_01dd: Unknown result type (might be due to invalid IL or missing references)
//IL_01de: Unknown result type (might be due to invalid IL or missing references)
//IL_01df: Unknown result type (might be due to invalid IL or missing references)
//IL_01e5: Unknown result type (might be due to invalid IL or missing references)
//IL_0213: Unknown result type (might be due to invalid IL or missing references)
//IL_0219: Unknown result type (might be due to invalid IL or missing references)
//IL_021a: Unknown result type (might be due to invalid IL or missing references)
//IL_021b: Unknown result type (might be due to invalid IL or missing references)
//IL_0221: Unknown result type (might be due to invalid IL or missing references)
//IL_024c: Unknown result type (might be due to invalid IL or missing references)
//IL_0252: Unknown result type (might be due to invalid IL or missing references)
//IL_0253: Unknown result type (might be due to invalid IL or missing references)
//IL_0254: Unknown result type (might be due to invalid IL or missing references)
//IL_025a: Unknown result type (might be due to invalid IL or missing references)
//IL_0285: Unknown result type (might be due to invalid IL or missing references)
//IL_028b: Unknown result type (might be due to invalid IL or missing references)
//IL_028c: Unknown result type (might be due to invalid IL or missing references)
//IL_028d: Unknown result type (might be due to invalid IL or missing references)
//IL_0293: Unknown result type (might be due to invalid IL or missing references)
//IL_02a5: Unknown result type (might be due to invalid IL or missing references)
if (AnchorConfig != null && PositionConfig != null && (_currentAnchor != AnchorConfig.Value || !(_rt.anchoredPosition == PositionConfig.Value)))
{
_currentAnchor = AnchorConfig.Value;
TextAnchor currentAnchor = _currentAnchor;
Vector2 val = default(Vector2);
switch ((int)currentAnchor)
{
case 0:
{
RectTransform rt25 = _rt;
RectTransform rt26 = _rt;
RectTransform rt27 = _rt;
((Vector2)(ref val))..ctor(0f, 1f);
rt27.anchorMax = val;
Vector2 pivot = (rt26.anchorMin = val);
rt25.pivot = pivot;
break;
}
case 1:
{
RectTransform rt22 = _rt;
RectTransform rt23 = _rt;
RectTransform rt24 = _rt;
((Vector2)(ref val))..ctor(0.5f, 1f);
rt24.anchorMax = val;
Vector2 pivot = (rt23.anchorMin = val);
rt22.pivot = pivot;
break;
}
case 2:
{
RectTransform rt19 = _rt;
RectTransform rt20 = _rt;
RectTransform rt21 = _rt;
((Vector2)(ref val))..ctor(1f, 1f);
rt21.anchorMax = val;
Vector2 pivot = (rt20.anchorMin = val);
rt19.pivot = pivot;
break;
}
case 3:
{
RectTransform rt16 = _rt;
RectTransform rt17 = _rt;
RectTransform rt18 = _rt;
((Vector2)(ref val))..ctor(0f, 0.5f);
rt18.anchorMax = val;
Vector2 pivot = (rt17.anchorMin = val);
rt16.pivot = pivot;
break;
}
case 4:
{
RectTransform rt13 = _rt;
RectTransform rt14 = _rt;
RectTransform rt15 = _rt;
((Vector2)(ref val))..ctor(0.5f, 0.5f);
rt15.anchorMax = val;
Vector2 pivot = (rt14.anchorMin = val);
rt13.pivot = pivot;
break;
}
case 5:
{
RectTransform rt10 = _rt;
RectTransform rt11 = _rt;
RectTransform rt12 = _rt;
((Vector2)(ref val))..ctor(1f, 0.5f);
rt12.anchorMax = val;
Vector2 pivot = (rt11.anchorMin = val);
rt10.pivot = pivot;
break;
}
case 6:
{
RectTransform rt7 = _rt;
RectTransform rt8 = _rt;
RectTransform rt9 = _rt;
((Vector2)(ref val))..ctor(0f, 0f);
rt9.anchorMax = val;
Vector2 pivot = (rt8.anchorMin = val);
rt7.pivot = pivot;
break;
}
case 7:
{
RectTransform rt4 = _rt;
RectTransform rt5 = _rt;
RectTransform rt6 = _rt;
((Vector2)(ref val))..ctor(0.5f, 0f);
rt6.anchorMax = val;
Vector2 pivot = (rt5.anchorMin = val);
rt4.pivot = pivot;
break;
}
case 8:
{
RectTransform rt = _rt;
RectTransform rt2 = _rt;
RectTransform rt3 = _rt;
((Vector2)(ref val))..ctor(1f, 0f);
rt3.anchorMax = val;
Vector2 pivot = (rt2.anchorMin = val);
rt.pivot = pivot;
break;
}
}
_rt.anchoredPosition = PositionConfig.Value;
}
}
}
[Serializable]
public class RecipeRequirementConfig
{
public string item = "";
public int amount = 1;
}
[Serializable]
public class RecipeConfig
{
public string name = "";
public string item = "";
public int amount = 1;
public string craftingStation = "";
public int minStationLevel = 1;
public bool enabled = true;
public string repairStation = "";
public List<RecipeRequirementConfig> resources = new List<RecipeRequirementConfig>();
}
[Serializable]
public class RecipesConfig
{
public List<RecipeConfig> recipes = new List<RecipeConfig>();
}
public static class GameObjectExtensions
{
public static RectTransform RectTransform(this GameObject go)
{
Transform transform = go.transform;
return (RectTransform)(object)((transform is RectTransform) ? transform : null);
}
public static T RequireComponent<T>(this GameObject go) where T : Component
{
T component = go.GetComponent<T>();
if (!((Object)(object)component == (Object)null))
{
return component;
}
return go.AddComponent<T>();
}
}
public class GotDestroyed : MonoBehaviour
{
public void OnDisable()
{
Debug.LogError((object)("I got destroyed! (" + ((Object)((Component)this).gameObject).name + ")"));
Debug.Log((object)Environment.StackTrace);
}
}
public class MultiValueDictionary<TKey, TValue> : Dictionary<TKey, List<TValue>>
{
public void Add(TKey key, TValue value)
{
if (!TryGetValue(key, out var value2))
{
value2 = new List<TValue>();
Add(key, value2);
}
value2.Add(value);
}
public bool ContainsValue(TKey key, TValue value)
{
if (TryGetValue(key, out var value2))
{
return value2.Contains(value);
}
return false;
}
public void Remove(TKey key, TValue value)
{
if (TryGetValue(key, out var value2))
{
value2.Remove(value);
if (value2.Count <= 0)
{
Remove(key);
}
}
}
public void Merge(MultiValueDictionary<TKey, TValue> toMergeWith)
{
if (toMergeWith == null)
{
return;
}
foreach (KeyValuePair<TKey, List<TValue>> item in toMergeWith)
{
foreach (TValue item2 in item.Value)
{
Add(item.Key, item2);
}
}
}
public List<TValue> GetValues(TKey key, bool returnEmptySet = false)
{
if (!TryGetValue(key, out var value) && returnEmptySet)
{
return new List<TValue>();
}
return value;
}
}
public static class PrefabCreator
{
public static ManualLogSource Logger;
public static Dictionary<string, CraftingStation> CraftingStations;
public static T RequireComponent<T>(GameObject go) where T : Component
{
T val = go.GetComponent<T>();
if ((Object)(object)val == (Object)null)
{
val = go.AddComponent<T>();
}
return val;
}
public static void Reset()
{
CraftingStations = null;
}
private static void InitCraftingStations()
{
if (CraftingStations != null)
{
return;
}
CraftingStations = new Dictionary<string, CraftingStation>();
foreach (Recipe recipe in ObjectDB.instance.m_recipes)
{
if ((Object)(object)recipe.m_craftingStation != (Object)null && !CraftingStations.ContainsKey(((Object)recipe.m_craftingStation).name))
{
CraftingStations.Add(((Object)recipe.m_craftingStation).name, recipe.m_craftingStation);
}
}
}
public static Recipe CreateRecipe(string name, string itemId, RecipeConfig recipeConfig)
{
//IL_0200: Unknown result type (might be due to invalid IL or missing references)
//IL_0205: Unknown result type (might be due to invalid IL or missing references)
//IL_0212: Unknown result type (might be due to invalid IL or missing references)
//IL_0224: Expected O, but got Unknown
InitCraftingStations();
GameObject itemPrefab = ObjectDB.instance.GetItemPrefab(itemId);
if ((Object)(object)itemPrefab == (Object)null)
{
ManualLogSource logger = Logger;
if (logger != null)
{
logger.LogWarning((object)("[PrefabCreator] Could not find item prefab (" + itemId + ")"));
}
return null;
}
Recipe val = ScriptableObject.CreateInstance<Recipe>();
((Object)val).name = name;
val.m_amount = recipeConfig.amount;
val.m_minStationLevel = recipeConfig.minStationLevel;
val.m_item = itemPrefab.GetComponent<ItemDrop>();
val.m_enabled = recipeConfig.enabled;
if (!string.IsNullOrEmpty(recipeConfig.craftingStation))
{
if (!CraftingStations.ContainsKey(recipeConfig.craftingStation))
{
ManualLogSource logger2 = Logger;
if (logger2 != null)
{
logger2.LogWarning((object)("[PrefabCreator] Could not find crafting station (" + itemId + "): " + recipeConfig.craftingStation));
}
string text = string.Join(", ", CraftingStations.Keys);
ManualLogSource logger3 = Logger;
if (logger3 != null)
{
logger3.LogInfo((object)("[PrefabCreator] Available Stations: " + text));
}
}
else
{
val.m_craftingStation = CraftingStations[recipeConfig.craftingStation];
}
}
if (!string.IsNullOrEmpty(recipeConfig.repairStation))
{
if (!CraftingStations.ContainsKey(recipeConfig.repairStation))
{
ManualLogSource logger4 = Logger;
if (logger4 != null)
{
logger4.LogWarning((object)("[PrefabCreator] Could not find repair station (" + itemId + "): " + recipeConfig.repairStation));
}
string text2 = string.Join(", ", CraftingStations.Keys);
ManualLogSource logger5 = Logger;
if (logger5 != null)
{
logger5.LogInfo((object)("[PrefabCreator] Available Stations: " + text2));
}
}
else
{
val.m_repairStation = CraftingStations[recipeConfig.repairStation];
}
}
List<Requirement> list = new List<Requirement>();
foreach (RecipeRequirementConfig resource in recipeConfig.resources)
{
GameObject itemPrefab2 = ObjectDB.instance.GetItemPrefab(resource.item);
if ((Object)(object)itemPrefab2 == (Object)null)
{
ManualLogSource logger6 = Logger;
if (logger6 != null)
{
logger6.LogError((object)("[PrefabCreator] Could not find requirement item (" + itemId + "): " + resource.item));
}
}
else
{
list.Add(new Requirement
{
m_amount = resource.amount,
m_resItem = itemPrefab2.GetComponent<ItemDrop>()
});
}
}
val.m_resources = list.ToArray();
return val;
}
public static Recipe AddNewRecipe(string name, string itemId, RecipeConfig recipeConfig)
{
Recipe val = CreateRecipe(name, itemId, recipeConfig);
if ((Object)(object)val == (Object)null)
{
ManualLogSource logger = Logger;
if (logger != null)
{
logger.LogError((object)("[PrefabCreator] Failed to create recipe (" + name + ")"));
}
return null;
}
return AddNewRecipe(val);
}
public static Recipe AddNewRecipe(Recipe recipe)
{
int num = ObjectDB.instance.m_recipes.RemoveAll((Recipe x) => ((Object)x).name == ((Object)recipe).name);
if (num > 0)
{
ManualLogSource logger = Logger;
if (logger != null)
{
logger.LogInfo((object)$"[PrefabCreator] Removed recipe ({((Object)recipe).name}): {num}");
}
}
ObjectDB.instance.m_recipes.Add(recipe);
ManualLogSource logger2 = Logger;
if (logger2 != null)
{
logger2.LogInfo((object)("[PrefabCreator] Added recipe: " + ((Object)recipe).name));
}
return recipe;
}
}
[Serializable]
public struct SerializableVector3
{
public float x;
public float y;
public float z;
public SerializableVector3(float x, float y, float z)
{
this.x = x;
this.y = y;
this.z = z;
}
public void ToPackage(ZPackage pkg)
{
pkg.Write(x);
pkg.Write(y);
pkg.Write(z);
}
public static SerializableVector3 FromPackage(ZPackage pkg)
{
SerializableVector3 result = default(SerializableVector3);
result.x = pkg.ReadSingle();
result.y = pkg.ReadSingle();
result.z = pkg.ReadSingle();
return result;
}
public override string ToString()
{
return $"[{x}, {y}, {z}]";
}
public static implicit operator Vector3(SerializableVector3 s)
{
//IL_0012: Unknown result type (might be due to invalid IL or missing references)
return new Vector3(s.x, s.y, s.z);
}
public static implicit operator SerializableVector3(Vector3 v)
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_000c: Unknown result type (might be due to invalid IL or missing references)
return new SerializableVector3(v.x, v.y, v.z);
}
public static SerializableVector3 operator +(SerializableVector3 a, SerializableVector3 b)
{
return new SerializableVector3(a.x + b.x, a.y + b.y, a.z + b.z);
}
public static SerializableVector3 operator -(SerializableVector3 a, SerializableVector3 b)
{
return new SerializableVector3(a.x - b.x, a.y - b.y, a.z - b.z);
}
public static SerializableVector3 operator -(SerializableVector3 a)
{
return new SerializableVector3(0f - a.x, 0f - a.y, 0f - a.z);
}
public static SerializableVector3 operator *(SerializableVector3 a, float m)
{
return new SerializableVector3(a.x * m, a.y * m, a.z * m);
}
public static SerializableVector3 operator *(float m, SerializableVector3 a)
{
return new SerializableVector3(a.x * m, a.y * m, a.z * m);
}
public static SerializableVector3 operator /(SerializableVector3 a, float d)
{
return new SerializableVector3(a.x / d, a.y / d, a.z / d);
}
}
public static class Utils
{
public static void PrintObject(object o)
{
if (o == null)
{
Debug.Log((object)"null");
}
else
{
Debug.Log((object)(o?.ToString() + ":\n" + GetObjectString(o, " ")));
}
}
public static string GetObjectString(object obj, string indent)
{
string text = "";
foreach (FieldInfo item in from f in obj.GetType().GetFields()
where f.IsPublic
select f)
{
object value = item.GetValue(obj);
string text2 = ((value == null) ? "null" : value.ToString());
text = text + "\n" + indent + item.Name + ": " + text2;
}
return text;
}
public static string RemoveBetween(string s, string from, string to)
{
int num = 0;
while (num >= 0)
{
num = s.IndexOf(from, StringComparison.InvariantCulture);
if (num < 0)
{
break;
}
int num2 = s.IndexOf(to, num, StringComparison.InvariantCulture);
if (num2 < 0)
{
break;
}
s = s.Remove(num, num2 - num + to.Length);
}
return s;
}
public static void CopyFields(object originalObject, object cloneObject, Type typeToReflect, BindingFlags bindingFlags = BindingFlags.Instance | BindingFlags.Public)
{
FieldInfo[] fields = typeToReflect.GetFields(bindingFlags);
foreach (FieldInfo obj in fields)
{
object value = obj.GetValue(originalObject);
obj.SetValue(cloneObject, value);
}
}
public static bool IsServer()
{
//IL_0018: Unknown result type (might be due to invalid IL or missing references)
//IL_001e: Invalid comparison between Unknown and I4
if (!ZNet.instance.IsServer() && !ZNet.instance.IsDedicated())
{
return (int)SystemInfo.graphicsDeviceType == 4;
}
return true;
}
}
public static class ArrayUtils
{
public static bool IsNullOrEmpty<T>(T[] a)
{
if (a != null)
{
return a.Length == 0;
}
return true;
}
public static T[] Copy<T>(T[] other)
{
return other?.ToArray();
}
}
public static class ListExtensions
{
public static bool TryFind<T>(this List<T> list, Predicate<T> predicate, out T result)
{
int num = list.FindIndex(predicate);
if (num != -1)
{
result = list[num];
return true;
}
result = default(T);
return false;
}
}
}
namespace AdvancedPortals
{
[HarmonyPatch]
public static class AddPortal
{
public static readonly HashSet<int> Hashes = new HashSet<int>();
[UsedImplicitly]
private static IEnumerable<MethodInfo> TargetMethods()
{
return new MethodInfo[1] { AccessTools.DeclaredMethod(typeof(Game), "Awake", (Type[])null, (Type[])null) };
}
[UsedImplicitly]
private static void Prefix(Game __instance)
{
__instance.PortalPrefabHash.AddRange(Hashes);
}
}
public class AdvancedPortal : MonoBehaviour
{
public List<string> AllowedItems = new List<string>();
public bool AllowEverything;
private void Awake()
{
}
}
[HarmonyPatch]
public static class Teleport_Patch
{
public static AdvancedPortal CurrentAdvancedPortal;
public static void TargetPortal_HandlePortalClick_Prefix()
{
//IL_000a: Unknown result type (might be due to invalid IL or missing references)
//IL_000f: 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)
//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_006a: Unknown result type (might be due to invalid IL or missing references)
//IL_006f: Unknown result type (might be due to invalid IL or missing references)
//IL_0071: Unknown result type (might be due to invalid IL or missing references)
//IL_0078: Unknown result type (might be due to invalid IL or missing references)
//IL_0080: 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_0090: 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)
Vector3 position = ((Component)Player.m_localPlayer).transform.position;
Collider[] array = Physics.OverlapSphere(position, 2f);
TeleportWorld val = null;
float num = 5f;
Collider[] array2 = array;
foreach (Collider val2 in array2)
{
TeleportWorldTrigger component = ((Component)val2).gameObject.GetComponent<TeleportWorldTrigger>();
if ((Object)(object)component == (Object)null)
{
continue;
}
TeleportWorld componentInParent = ((Component)component).GetComponentInParent<TeleportWorld>();
if (!((Object)(object)componentInParent == (Object)null))
{
Vector3 val3 = ((Component)val2).transform.position - position;
float num2 = val3.x * val3.x + val3.y * val3.y + val3.z * val3.z;
if (num2 < num)
{
val = componentInParent;
num = num2;
}
}
}
if ((Object)(object)val != (Object)null)
{
Generic_Prefix(val);
}
}
public static void Generic_Prefix(TeleportWorld __instance)
{
CurrentAdvancedPortal = ((Component)__instance).GetComponent<AdvancedPortal>();
}
public static void Generic_Postfix()
{
CurrentAdvancedPortal = null;
}
[HarmonyPatch(typeof(TeleportWorld), "UpdatePortal")]
[HarmonyPrefix]
public static void TeleportWorld_UpdatePortal_Prefix(TeleportWorld __instance)
{
CurrentAdvancedPortal = ((Component)__instance).GetComponent<AdvancedPortal>();
}
[HarmonyPatch(typeof(TeleportWorld), "UpdatePortal")]
[HarmonyPostfix]
public static void TeleportWorld_UpdatePortal_Postfix()
{
CurrentAdvancedPortal = null;
}
[HarmonyPatch(typeof(TeleportWorld), "Teleport")]
[HarmonyPrefix]
public static void TeleportWorld_Teleport_Prefix(TeleportWorld __instance)
{
CurrentAdvancedPortal = ((Component)__instance).GetComponent<AdvancedPortal>();
}
[HarmonyPatch(typeof(TeleportWorld), "Teleport")]
[HarmonyPostfix]
public static void TeleportWorld_Teleport_Postfix()
{
CurrentAdvancedPortal = null;
}
[HarmonyPatch(typeof(Inventory), "IsTeleportable")]
[HarmonyPostfix]
[HarmonyPriority(600)]
public static void Inventory_IsTeleportable_Pretfix(Inventory __instance, ref bool __result)
{
if ((Object)(object)CurrentAdvancedPortal == (Object)null || __result)
{
return;
}
if (CurrentAdvancedPortal.AllowEverything)
{
__result = true;
return;
}
foreach (ItemData allItem in __instance.GetAllItems())
{
if (!((Object)(object)allItem.m_dropPrefab == (Object)null) && !allItem.m_shared.m_teleportable && !CurrentAdvancedPortal.AllowedItems.Contains(((Object)allItem.m_dropPrefab).name))
{
return;
}
}
__result = true;
}
}
internal class UpdatePortals
{
public static List<RequirementConfig> MakeRecipeFromConfig(string portalName, string configString)
{
//IL_0094: Unknown result type (might be due to invalid IL or missing references)
//IL_0099: Unknown result type (might be due to invalid IL or missing references)
//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
//IL_00b5: Expected O, but got Unknown
List<RequirementConfig> list = new List<RequirementConfig>();
string[] array = configString.Replace(" ", "").Split(new char[1] { ',' }, StringSplitOptions.RemoveEmptyEntries);
for (int i = 0; i < array.Length; i++)
{
string[] array2 = array[i].Split(new char[1] { ':' }, StringSplitOptions.RemoveEmptyEntries);
if (array2.Length != 2)
{
AdvancedPortals.APLogger.LogError((object)("Incorrectly formatted recipe for " + portalName + "! Should be 'ITEM:QUANITY,ITEM2:QUANTITY' etc."));
continue;
}
string item = array2[0];
if (!int.TryParse(array2[1], out var result))
{
AdvancedPortals.APLogger.LogError((object)("Incorrectly formatted recipe for " + portalName + "! Should be 'ITEM:QUANITY,ITEM2:QUANTITY' etc."));
continue;
}
list.Add(new RequirementConfig
{
Item = item,
Amount = result,
Recover = true
});
}
return list;
}
public static void UpdatePortalConfigurations()
{
GameObject prefab = PrefabManager.Instance.GetPrefab("Hammer");
if ((Object)(object)prefab == (Object)null)
{
AdvancedPortals.APLogger.LogError((object)"Hammer not found, could not update portal configurations.");
return;
}
ItemDrop val = default(ItemDrop);
if (!prefab.TryGetComponent<ItemDrop>(ref val))
{
AdvancedPortals.APLogger.LogError((object)"Hammer not found, could not update portal configurations.");
return;
}
PieceTable buildPieces = val.m_itemData.m_shared.m_buildPieces;
string[] portalPrefabs = AdvancedPortals.PortalPrefabs;
AdvancedPortal advancedPortal = default(AdvancedPortal);
foreach (string text in portalPrefabs)
{
GameObject portalPrefab = PrefabManager.Instance.GetPrefab(text);
if ((Object)(object)portalPrefab == (Object)null)
{
AdvancedPortals.APLogger.LogError((object)(text + " not found, could not update configurations."));
continue;
}
if (!portalPrefab.TryGetComponent<AdvancedPortal>(ref advancedPortal))
{
AdvancedPortals.APLogger.LogError((object)("AdvancedPortal not found, could not update " + text + " configurations."));
continue;
}
string empty = string.Empty;
string empty2 = string.Empty;
bool flag = true;
switch (text)
{
case "portal_ancient":
flag = AdvancedPortals.AncientPortalEnabled.Value;
empty = "Ancient Portal";
empty2 = AdvancedPortals.AncientPortalRecipe.Value;
advancedPortal.AllowEverything = AdvancedPortals.AncientPortalAllowEverything.Value;
advancedPortal.AllowedItems = GetListFromString(AdvancedPortals.AncientPortalAllowedItems.Value);
break;
case "portal_obsidian":
flag = AdvancedPortals.ObsidianPortalEnabled.Value;
empty = "Obsidian Portal";
empty2 = AdvancedPortals.ObsidianPortalRecipe.Value;
advancedPortal.AllowEverything = AdvancedPortals.ObsidianPortalAllowEverything.Value;
advancedPortal.AllowedItems = GetListFromString(AdvancedPortals.ObsidianPortalAllowedItems.Value);
if (AdvancedPortals.ObsidianPortalAllowPreviousPortalItems.Value)
{
advancedPortal.AllowedItems.AddRange(GetListFromString(AdvancedPortals.AncientPortalAllowedItems.Value));
}
break;
case "portal_blackmarble":
flag = AdvancedPortals.BlackMarblePortalEnabled.Value;
empty = "Black Marble Portal";
empty2 = AdvancedPortals.BlackMarblePortalRecipe.Value;
advancedPortal.AllowEverything = AdvancedPortals.BlackMarblePortalAllowEverything.Value;
advancedPortal.AllowedItems = GetListFromString(AdvancedPortals.BlackMarblePortalAllowedItems.Value);
if (AdvancedPortals.BlackMarblePortalAllowPreviousPortalItems.Value)
{
advancedPortal.AllowedItems.AddRange(GetListFromString(AdvancedPortals.AncientPortalAllowedItems.Value));
advancedPortal.AllowedItems.AddRange(GetListFromString(AdvancedPortals.ObsidianPortalAllowedItems.Value));
}
break;
default:
AdvancedPortals.APLogger.LogError((object)("Could not update " + text + " configurations. Not a configurable advance portal."));
continue;
}
Piece component = portalPrefab.GetComponent<Piece>();
if ((Object)(object)component == (Object)null)
{
AdvancedPortals.APLogger.LogError((object)("Could not update portal configurations for " + text + ". Piece not found."));
}
GameObject val2 = buildPieces.m_pieces.Find((GameObject x) => ((Object)x).name == Utils.GetPrefabName(((Object)portalPrefab).name));
if (!flag)
{
if ((Object)(object)val2 != (Object)null)
{
buildPieces.m_pieces.Remove(val2);
}
continue;
}
List<RequirementConfig> list = MakeRecipeFromConfig(empty, empty2);
List<Requirement> list2 = new List<Requirement>();
foreach (RequirementConfig item in list)
{
Requirement requirement = item.GetRequirement();
ItemDrop component2 = PrefabManager.Instance.GetPrefab(item.Item).GetComponent<ItemDrop>();
if ((Object)(object)component2 != (Object)null)
{
requirement.m_resItem = component2;
list2.Add(requirement);
}
else
{
AdvancedPortals.APLogger.LogError((object)("Could not add requirement " + item.Item + ", for " + text));
}
}
component.m_resources = list2.ToArray();
component.m_description = GetAdvancedPortalDescription(advancedPortal.AllowEverything, advancedPortal.AllowedItems);
if ((Object)(object)val2 != (Object)null)
{
val2.GetComponent<Piece>().m_resources = list2.ToArray();
}
else
{
buildPieces.m_pieces.Add(portalPrefab);
}
}
}
private static string GetAdvancedPortalDescription(bool allowEverything, List<string> items)
{
return "$piece_portal_description Can Teleport: (" + (allowEverything ? "Anything" : string.Join(", ", items)) + ")";
}
private static List<string> GetListFromString(string items)
{
return items.Replace(" ", "").Split(new char[1] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToList();
}
}
[BepInDependency(/*Could not decode attribute arguments.*/)]
[NetworkCompatibility(/*Could not decode attribute arguments.*/)]
[BepInPlugin("randyknapp.mods.advancedportals", "Advanced Portals", "1.1.3")]
[BepInIncompatibility("com.github.xafflict.UnrestrictedPortals")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class AdvancedPortals : BaseUnityPlugin
{
public const string PluginId = "randyknapp.mods.advancedportals";
public const string DisplayName = "Advanced Portals";
public const string Version = "1.1.3";
private static string ConfigFileName = "randyknapp.mods.advancedportals.cfg";
private static string ConfigFileFullPath;
public static readonly string[] PortalPrefabs;
public static readonly List<GameObject> RegisteredPrefabs;
public static ConfigEntry<bool> AncientPortalEnabled;
public static string AncientPortalRecipeDefault;
public static ConfigEntry<string> AncientPortalRecipe;
public static ConfigEntry<string> AncientPortalAllowedItems;
public static ConfigEntry<bool> AncientPortalAllowEverything;
public static ConfigEntry<bool> ObsidianPortalEnabled;
public static string ObsidianPortalRecipeDefault;
public static ConfigEntry<string> ObsidianPortalRecipe;
public static ConfigEntry<string> ObsidianPortalAllowedItems;
public static ConfigEntry<bool> ObsidianPortalAllowEverything;
public static ConfigEntry<bool> ObsidianPortalAllowPreviousPortalItems;
public static ConfigEntry<bool> BlackMarblePortalEnabled;
public static string BlackMarblePortalRecipeDefault;
public static ConfigEntry<string> BlackMarblePortalRecipe;
public static ConfigEntry<string> BlackMarblePortalAllowedItems;
public static ConfigEntry<bool> BlackMarblePortalAllowEverything;
public static ConfigEntry<bool> BlackMarblePortalAllowPreviousPortalItems;
public static readonly ManualLogSource APLogger;
private Harmony _harmony;
private DateTime _lastReloadTime;
private const long RELOAD_DELAY = 10000000L;
private readonly ConfigurationManagerAttributes AdminConfig = new ConfigurationManagerAttributes
{
IsAdminOnly = true
};
private readonly ConfigurationManagerAttributes ClientConfig = new ConfigurationManagerAttributes
{
IsAdminOnly = false
};
[UsedImplicitly]
private void Awake()
{
//IL_01b0: Unknown result type (might be due to invalid IL or missing references)
//IL_01b5: Unknown result type (might be due to invalid IL or missing references)
//IL_01c0: Unknown result type (might be due to invalid IL or missing references)
//IL_01cb: Unknown result type (might be due to invalid IL or missing references)
//IL_01d6: Unknown result type (might be due to invalid IL or missing references)
//IL_01e1: Unknown result type (might be due to invalid IL or missing references)
//IL_01ec: Unknown result type (might be due to invalid IL or missing references)
//IL_0210: Expected O, but got Unknown
//IL_0216: Unknown result type (might be due to invalid IL or missing references)
//IL_021b: Unknown result type (might be due to invalid IL or missing references)
//IL_0226: Unknown result type (might be due to invalid IL or missing references)
//IL_0231: Unknown result type (might be due to invalid IL or missing references)
//IL_023c: Unknown result type (might be due to invalid IL or missing references)
//IL_0247: Unknown result type (might be due to invalid IL or missing references)
//IL_0252: Unknown result type (might be due to invalid IL or missing references)
//IL_0276: Expected O, but got Unknown
//IL_027c: Unknown result type (might be due to invalid IL or missing references)
//IL_0281: Unknown result type (might be due to invalid IL or missing references)
//IL_028c: Unknown result type (might be due to invalid IL or missing references)
//IL_0297: Unknown result type (might be due to invalid IL or missing references)
//IL_02a2: Unknown result type (might be due to invalid IL or missing references)
//IL_02ad: Unknown result type (might be due to invalid IL or missing references)
//IL_02b8: Unknown result type (might be due to invalid IL or missing references)
//IL_02dc: Expected O, but got Unknown
//IL_02ef: Unknown result type (might be due to invalid IL or missing references)
//IL_02f9: Expected O, but got Unknown
//IL_030c: Unknown result type (might be due to invalid IL or missing references)
//IL_0316: Expected O, but got Unknown
//IL_0328: Unknown result type (might be due to invalid IL or missing references)
//IL_0332: Expected O, but got Unknown
//IL_03ef: Unknown result type (might be due to invalid IL or missing references)
//IL_03fd: Expected O, but got Unknown
//IL_0417: Unknown result type (might be due to invalid IL or missing references)
//IL_0424: Expected O, but got Unknown
AddConfig("Portal 1 - Ancient", "Ancient Portal Enabled", "Enable the Ancient Portal", synced: true, value: true, ref AncientPortalEnabled);
AddConfig("Portal 1 - Ancient", "Ancient Portal Recipe", "The items needed to build the Ancient Portal. A comma separated list of ITEM:QUANTITY pairs separated by a colon.", synced: true, AncientPortalRecipeDefault, ref AncientPortalRecipe);
AddConfig("Portal 1 - Ancient", "Ancient Portal Allowed Items", "A comma separated list of the item types allowed through the Ancient Portal", synced: true, "Copper, CopperOre, CopperScrap, Tin, TinOre, Bronze, BronzeScrap", ref AncientPortalAllowedItems);
AddConfig("Portal 1 - Ancient", "Ancient Portal Allow Everything", "Allow all items through the Ancient Portal (overrides Allowed Items)", synced: true, value: false, ref AncientPortalAllowEverything);
AddConfig("Portal 2 - Obsidian", "Obsidian Portal Enabled", "Enable the Obsidian Portal", synced: true, value: true, ref ObsidianPortalEnabled);
AddConfig("Portal 2 - Obsidian", "Obsidian Portal Recipe", "The items needed to build the Obsidian Portal. A comma separated list of ITEM:QUANTITY pairs separated by a colon.", synced: true, ObsidianPortalRecipeDefault, ref ObsidianPortalRecipe);
AddConfig("Portal 2 - Obsidian", "Obsidian Portal Allowed Items", "A comma separated list of the item types allowed through the Obsidian Portal", synced: true, "Iron, IronScrap, IronOre", ref ObsidianPortalAllowedItems);
AddConfig("Portal 2 - Obsidian", "Obsidian Portal Allow Everything", "Allow all items through the Obsidian Portal (overrides Allowed Items)", synced: true, value: false, ref ObsidianPortalAllowEverything);
AddConfig("Portal 2 - Obsidian", "Obsidian Portal Use All Previous", "Additionally allow all items from the Ancient Portal", synced: true, value: true, ref ObsidianPortalAllowPreviousPortalItems);
AddConfig("Portal 3 - Black Marble", "Black Marble Portal Enabled", "Enable the Black Marble Portal", synced: true, value: true, ref BlackMarblePortalEnabled);
AddConfig("Portal 3 - Black Marble", "Black Marble Portal Recipe", "The items needed to build the Black Marble Portal. A comma separated list of ITEM:QUANTITY pairs separated by a colon.", synced: true, BlackMarblePortalRecipeDefault, ref BlackMarblePortalRecipe);
AddConfig("Portal 3 - Black Marble", "Black Marble Portal Allowed Items", "A comma separated list of the item types allowed through the Black Marble Portal", synced: true, "Silver, SilverOre, BlackMetal, BlackMetalScrap", ref BlackMarblePortalAllowedItems);
AddConfig("Portal 3 - Black Marble", "Black Marble Portal Allow Everything", "Allow all items through the Black Marble Portal (overrides Allowed Items)", synced: true, value: true, ref BlackMarblePortalAllowEverything);
AddConfig("Portal 3 - Black Marble", "Black Marble Portal Use All Previous", "Additionally allow all items from the Obsidian and Ancient Portal", synced: true, value: true, ref BlackMarblePortalAllowPreviousPortalItems);
AssetBundle obj = LoadAssetBundle("advancedportals");
LoadBuildPiece(obj, "portal_ancient", new PieceConfig
{
Name = "$item_elderbark $piece_portal",
Description = "$piece_portal_description",
PieceTable = "Hammer",
Category = "Misc",
CraftingStation = "piece_workbench",
Requirements = UpdatePortals.MakeRecipeFromConfig("Ancient Portal", AncientPortalRecipe.Value).ToArray()
});
LoadBuildPiece(obj, "portal_obsidian", new PieceConfig
{
Name = "$item_obsidian $piece_portal",
Description = "$piece_portal_description",
PieceTable = "Hammer",
Category = "Misc",
CraftingStation = "piece_workbench",
Requirements = UpdatePortals.MakeRecipeFromConfig("Obsidian Portal", ObsidianPortalRecipe.Value).ToArray()
});
LoadBuildPiece(obj, "portal_blackmarble", new PieceConfig
{
Name = "$item_blackmarble $piece_portal",
Description = "$piece_portal_description",
PieceTable = "Hammer",
Category = "Misc",
CraftingStation = "piece_workbench",
Requirements = UpdatePortals.MakeRecipeFromConfig("Black Marble Portal", BlackMarblePortalRecipe.Value).ToArray()
});
GameObject val = obj.LoadAsset<GameObject>("fx_portal_connected_ancient");
PrefabManager.Instance.AddPrefab(new CustomPrefab(val, true));
GameObject val2 = obj.LoadAsset<GameObject>("fx_portal_connected_blackmarble");
PrefabManager.Instance.AddPrefab(new CustomPrefab(val2, true));
GameObject val3 = obj.LoadAsset<GameObject>("fx_portal_connected_obsidian");
PrefabManager.Instance.AddPrefab(new CustomPrefab(val3, true));
_harmony = Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), "randyknapp.mods.advancedportals");
SetupWatcher();
PieceManager.OnPiecesRegistered += UpdatePortalsOnGameStart;
string[] portalPrefabs = PortalPrefabs;
foreach (string text in portalPrefabs)
{
AddPortal.Hashes.Add(StringExtensionMethods.GetStableHashCode(text));
}
Component component = ((Component)this).gameObject.GetComponent("TargetPortal.TargetPortal");
if (Object.op_Implicit((Object)(object)component))
{
MethodInfo methodInfo = AccessTools.DeclaredMethod(((object)component).GetType().Assembly.GetType("TargetPortal.Map"), "HandlePortalClick", (Type[])null, (Type[])null);
if (methodInfo != null)
{
_harmony.Patch((MethodBase)methodInfo, new HarmonyMethod(typeof(Teleport_Patch), "TargetPortal_HandlePortalClick_Prefix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
_harmony.Patch((MethodBase)methodInfo, (HarmonyMethod)null, new HarmonyMethod(typeof(Teleport_Patch), "Generic_Postfix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
}
}
}
[UsedImplicitly]
private void OnDestroy()
{
((BaseUnityPlugin)this).Config.Save();
}
private void SetupWatcher()
{
FileSystemWatcher fileSystemWatcher = new FileSystemWatcher(Paths.ConfigPath, ConfigFileName);
fileSystemWatcher.Changed += ReadConfigValues;
fileSystemWatcher.Created += ReadConfigValues;
fileSystemWatcher.Renamed += ReadConfigValues;
fileSystemWatcher.IncludeSubdirectories = true;
fileSystemWatcher.SynchronizingObject = ThreadingHelper.SynchronizingObject;
fileSystemWatcher.EnableRaisingEvents = true;
}
private void ReadConfigValues(object sender, FileSystemEventArgs e)
{
DateTime now = DateTime.Now;
long num = now.Ticks - _lastReloadTime.Ticks;
if (File.Exists(ConfigFileFullPath) && num >= 10000000)
{
try
{
APLogger.LogInfo((object)"Attempting to reload configuration...");
((BaseUnityPlugin)this).Config.Reload();
}
catch
{
APLogger.LogWarning((object)("There was an issue loading " + ConfigFileName));
return;
}
if ((Object)(object)ZNet.instance != (Object)null && !ZNet.instance.IsDedicated())
{
UpdatePortals.UpdatePortalConfigurations();
}
_lastReloadTime = now;
}
}
private void AddConfig<T>(string section, string key, string description, bool synced, T value, ref ConfigEntry<T> configEntry)
{
//IL_0033: Unknown result type (might be due to invalid IL or missing references)
//IL_003d: Expected O, but got Unknown
string extendedDescription = GetExtendedDescription(description, synced);
configEntry = ((BaseUnityPlugin)this).Config.Bind<T>(section, key, value, new ConfigDescription(extendedDescription, (AcceptableValueBase)null, new object[1] { synced ? AdminConfig : ClientConfig }));
}
public string GetExtendedDescription(string description, bool synchronizedSetting)
{
return description + (synchronizedSetting ? " [Synced with Server]" : " [Not Synced with Server]");
}
public static AssetBundle LoadAssetBundle(string filename)
{
Assembly callingAssembly = Assembly.GetCallingAssembly();
return AssetBundle.LoadFromStream(callingAssembly.GetManifestResourceStream(callingAssembly.GetName().Name + "." + filename));
}
private static void LoadBuildPiece(AssetBundle assetBundle, string assetName, PieceConfig piececonfig)
{
//IL_0010: Unknown result type (might be due to invalid IL or missing references)
//IL_001a: Expected O, but got Unknown
GameObject val = assetBundle.LoadAsset<GameObject>(assetName);
PieceManager.Instance.AddPiece(new CustomPiece(val, true, piececonfig));
}
private static void UpdatePortalsOnGameStart()
{
UpdatePortals.UpdatePortalConfigurations();
}
static AdvancedPortals()
{
string configPath = Paths.ConfigPath;
char directorySeparatorChar = Path.DirectorySeparatorChar;
ConfigFileFullPath = configPath + directorySeparatorChar + ConfigFileName;
PortalPrefabs = new string[3] { "portal_ancient", "portal_obsidian", "portal_blackmarble" };
RegisteredPrefabs = new List<GameObject>();
AncientPortalRecipeDefault = "ElderBark:20,Iron:5,SurtlingCore:2";
AncientPortalRecipe = null;
AncientPortalAllowedItems = null;
AncientPortalAllowEverything = null;
ObsidianPortalRecipeDefault = "Obsidian:20,Silver:5,SurtlingCore:2";
ObsidianPortalAllowedItems = null;
ObsidianPortalAllowEverything = null;
ObsidianPortalAllowPreviousPortalItems = null;
BlackMarblePortalRecipeDefault = "BlackMarble:20,BlackMetal:5,Eitr:2";
BlackMarblePortalAllowedItems = null;
BlackMarblePortalAllowEverything = null;
BlackMarblePortalAllowPreviousPortalItems = null;
APLogger = Logger.CreateLogSource("Advanced Portals");
}
}
}