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 BepInEx;
using HarmonyLib;
using Jotunn.Configs;
using Jotunn.Entities;
using Jotunn.Managers;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("MoonforgedGatesAndFences")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("MoonforgedGatesAndFences")]
[assembly: AssemblyCopyright("Copyright © 2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("8ad799d2-7e36-4098-b363-92c0f7924b6a")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace MoonforgedGatesAndFences
{
internal class ConfigSync
{
}
}
namespace Moonforged.GatesAndFences
{
public class LocalizeKey : MonoBehaviour
{
public string Key;
public void Awake()
{
if (!string.IsNullOrEmpty(Key))
{
string text = LocalizationCache.Get(Key);
}
}
}
public static class Localizer
{
public static void Add(string key, string value)
{
LocalizationCache.Add(key, value);
}
public static void Register()
{
LocalizationCache.RegisterToJotunnLocalization();
}
}
public class PlacementWatcher : MonoBehaviour
{
public List<GameObject> RegisterList;
private void Start()
{
if (RegisterList != null && !RegisterList.Contains(((Component)this).gameObject))
{
RegisterList.Add(((Component)this).gameObject);
}
}
private void OnDestroy()
{
if (RegisterList != null)
{
RegisterList.Remove(((Component)this).gameObject);
}
}
}
public static class LocalizationCache
{
private static Dictionary<string, string> translations = new Dictionary<string, string>();
public static void Add(string key, string value)
{
translations[key] = value;
}
public static string Get(string key, string fallback = null)
{
if (translations.TryGetValue(key, out var value))
{
return value;
}
return fallback ?? key;
}
public static void RegisterToJotunnLocalization()
{
CustomLocalization localization = LocalizationManager.Instance.GetLocalization();
foreach (KeyValuePair<string, string> translation in translations)
{
string text = "English";
string key = translation.Key;
localization.AddTranslation(ref text, ref key, translation.Value);
}
}
}
public class RelicRegistration
{
public string PrefabName;
public string DisplayName;
public RequirementConfig[] Requirements;
public string Description;
public string Category;
public int Comfort;
public string CraftingStation;
public RelicRegistration(string prefab, string display, RequirementConfig[] reqs, string desc, string cat, int comfort = 0, string craftingStation = "Workbench")
{
PrefabName = prefab;
DisplayName = display;
Requirements = reqs;
Description = desc;
Category = cat;
Comfort = comfort;
CraftingStation = craftingStation;
}
}
public static class RelicRegistrar
{
private static bool wasAlreadyRegistered = false;
public static readonly List<RelicRegistration> AllRegistrations = new List<RelicRegistration>
{
new RelicRegistration("v2_SilverGate", "Silver Gate", (RequirementConfig[])(object)new RequirementConfig[2]
{
new RequirementConfig("Silver", 5, 0, true),
new RequirementConfig("Crystal", 2, 0, true)
}, "", "building", 0, "Forge"),
new RelicRegistration("v2_DvergrForgedGate", "Dvergr Forged Gate", (RequirementConfig[])(object)new RequirementConfig[2]
{
new RequirementConfig("BlackMetal", 5, 0, true),
new RequirementConfig("Bronze", 1, 0, true)
}, "", "building", 0, "Forge"),
new RelicRegistration("v2_DvergrForgedGate3m", "Dvergr Forged Gate 3m Tall", (RequirementConfig[])(object)new RequirementConfig[2]
{
new RequirementConfig("BlackMetal", 4, 0, true),
new RequirementConfig("Bronze", 1, 0, true)
}, "", "building", 0, "Forge"),
new RelicRegistration("v2_DvergrForgedGate4m", "Dvergr Forged Gate 4m Tall", (RequirementConfig[])(object)new RequirementConfig[2]
{
new RequirementConfig("BlackMetal", 5, 0, true),
new RequirementConfig("Bronze", 1, 0, true)
}, "", "building", 0, "Forge"),
new RelicRegistration("v2_EmberlightGate", "Emberlight Gate", (RequirementConfig[])(object)new RequirementConfig[4]
{
new RequirementConfig("BlackMetal", 5, 0, true),
new RequirementConfig("Bronze", 1, 0, true),
new RequirementConfig("Stone", 5, 0, true),
new RequirementConfig("Resin", 2, 0, true)
}, "", "building", 0, "Forge"),
new RelicRegistration("v2_ValkyriesEntrance", "Valkyrie's Entrance", (RequirementConfig[])(object)new RequirementConfig[4]
{
new RequirementConfig("Iron", 5, 0, true),
new RequirementConfig("Bronze", 1, 0, true),
new RequirementConfig("Silver", 5, 0, true),
new RequirementConfig("Resin", 1, 0, true)
}, "A Gate to Valhalla.", "building", 0, "Forge"),
new RelicRegistration("v2_ValkyriesSideGate", "Valkyrie's Side Gate", (RequirementConfig[])(object)new RequirementConfig[3]
{
new RequirementConfig("Iron", 3, 0, true),
new RequirementConfig("Bronze", 1, 0, true),
new RequirementConfig("Silver", 2, 0, true)
}, "A side gate to Valhalla.", "building", 0, "Forge"),
new RelicRegistration("v2_NeoWall", "Valkyrie's New Wall", (RequirementConfig[])(object)new RequirementConfig[3]
{
new RequirementConfig("BlackMetal", 2, 0, true),
new RequirementConfig("Tar", 3, 0, true),
new RequirementConfig("Bronze", 1, 0, true)
}, "", "building", 0, "Forge"),
new RelicRegistration("v2_SilverFence", "Silver Fence", (RequirementConfig[])(object)new RequirementConfig[2]
{
new RequirementConfig("Silver", 2, 0, true),
new RequirementConfig("Crystal", 2, 0, true)
}, "Silver Fence of the Howling Cavern.", "building", 0, "Forge"),
new RelicRegistration("v2_IroncrestWardenFenceBK", "Ironcrest Warden Fence Black", (RequirementConfig[])(object)new RequirementConfig[1]
{
new RequirementConfig("BlackMetal", 2, 0, true)
}, "", "building", 0, "Forge"),
new RelicRegistration("v2_IroncrestWardenFenceSilver", "Ironcrest Warden Fence Silver", (RequirementConfig[])(object)new RequirementConfig[1]
{
new RequirementConfig("Silver", 2, 0, true)
}, "", "building", 0, "Forge"),
new RelicRegistration("v2_Stonewatch_Palisade", "Stonewatch Palisade", (RequirementConfig[])(object)new RequirementConfig[2]
{
new RequirementConfig("BlackMetal", 2, 0, true),
new RequirementConfig("Stone", 4, 0, true)
}, "", "building", 0, "Forge"),
new RelicRegistration("v2_GildedRingwatchFence", "Gilded Ringwatch Fence", (RequirementConfig[])(object)new RequirementConfig[2]
{
new RequirementConfig("Iron", 2, 0, true),
new RequirementConfig("Bronze", 1, 0, true)
}, "", "building", 0, "Forge"),
new RelicRegistration("v2_chain_fence", "Golden Chain Fence", (RequirementConfig[])(object)new RequirementConfig[2]
{
new RequirementConfig("BlackMetal", 1, 0, true),
new RequirementConfig("Bronze", 1, 0, true)
}, "", "building", 0, "Forge"),
new RelicRegistration("v2_VikingArchGate", "Viking Arch Gate", (RequirementConfig[])(object)new RequirementConfig[3]
{
new RequirementConfig("Stone", 5, 0, true),
new RequirementConfig("Wood", 5, 0, true),
new RequirementConfig("Iron", 2, 0, true)
}, "", "building", 0, "piece_stonecutter"),
new RelicRegistration("v2_CurvedWoodFence", "Curved Wood Fence", (RequirementConfig[])(object)new RequirementConfig[2]
{
new RequirementConfig("Wood", 2, 0, true),
new RequirementConfig("FineWood", 2, 0, true)
}, "", "building"),
new RelicRegistration("v2_BlackFence", "Black Fence", (RequirementConfig[])(object)new RequirementConfig[2]
{
new RequirementConfig("Iron", 2, 0, true),
new RequirementConfig("Bronze", 1, 0, true)
}, "", "building", 0, "BlackForge"),
new RelicRegistration("v2_StoneBlackFence", "Stone Black Fence", (RequirementConfig[])(object)new RequirementConfig[3]
{
new RequirementConfig("Iron", 2, 0, true),
new RequirementConfig("Bronze", 1, 0, true),
new RequirementConfig("Stone", 1, 0, true)
}, "", "building", 0, "BlackForge"),
new RelicRegistration("v2_VikingGate", "Viking Gate", (RequirementConfig[])(object)new RequirementConfig[2]
{
new RequirementConfig("Tar", 4, 0, true),
new RequirementConfig("Wood", 10, 0, true)
}, "Old Viking Gate.", "building"),
new RelicRegistration("v2_BlackFenceStonePillar", "Stone Black Fence Pillar", (RequirementConfig[])(object)new RequirementConfig[4]
{
new RequirementConfig("BlackMetal", 1, 0, true),
new RequirementConfig("Bronze", 1, 0, true),
new RequirementConfig("Stone", 2, 0, true),
new RequirementConfig("Resin", 1, 0, true)
}, "", "building", 0, "Forge")
};
public static IEnumerable<string> GetAllCategories()
{
return AllRegistrations.Select((RelicRegistration r) => CategoryToTab(r.Category)).Distinct();
}
private static string CategoryToTab(string category)
{
string text = category.ToLower();
string text2 = text;
string text3 = text2;
if (text3 == "building")
{
return "Moonforged Structures";
}
return category;
}
public static void RegisterAllRelics(AssetBundle bundle)
{
if (wasAlreadyRegistered)
{
return;
}
foreach (RelicRegistration allRegistration in AllRegistrations)
{
RegisterRelic(bundle, allRegistration);
}
wasAlreadyRegistered = true;
}
private static void RegisterRelic(AssetBundle bundle, RelicRegistration reg)
{
//IL_032d: Unknown result type (might be due to invalid IL or missing references)
//IL_0332: Unknown result type (might be due to invalid IL or missing references)
//IL_0339: Unknown result type (might be due to invalid IL or missing references)
//IL_0345: Expected O, but got Unknown
//IL_0370: Unknown result type (might be due to invalid IL or missing references)
//IL_0377: Expected O, but got Unknown
//IL_0356: Unknown result type (might be due to invalid IL or missing references)
//IL_035b: Unknown result type (might be due to invalid IL or missing references)
//IL_0363: Unknown result type (might be due to invalid IL or missing references)
//IL_036f: Expected O, but got Unknown
//IL_03d6: Unknown result type (might be due to invalid IL or missing references)
//IL_03db: Unknown result type (might be due to invalid IL or missing references)
//IL_03e3: Unknown result type (might be due to invalid IL or missing references)
//IL_03ef: Expected O, but got Unknown
//IL_041a: Unknown result type (might be due to invalid IL or missing references)
//IL_0421: Expected O, but got Unknown
//IL_0400: Unknown result type (might be due to invalid IL or missing references)
//IL_0405: Unknown result type (might be due to invalid IL or missing references)
//IL_040d: Unknown result type (might be due to invalid IL or missing references)
//IL_0419: Expected O, but got Unknown
//IL_0461: Unknown result type (might be due to invalid IL or missing references)
//IL_0468: Expected O, but got Unknown
//IL_04ad: Unknown result type (might be due to invalid IL or missing references)
//IL_04b7: Expected O, but got Unknown
if ((Object)(object)bundle == (Object)null)
{
return;
}
GameObject val = bundle.LoadAsset<GameObject>(reg.PrefabName);
if ((Object)(object)val == (Object)null)
{
return;
}
((Object)val).name = reg.PrefabName;
ZNetView val2 = val.GetComponent<ZNetView>();
if ((Object)(object)val2 == (Object)null)
{
val2 = val.AddComponent<ZNetView>();
}
val2.m_persistent = true;
val2.m_syncInitialScale = true;
if (!Object.op_Implicit((Object)(object)val.GetComponent<ZSyncTransform>()))
{
val.AddComponent<ZSyncTransform>();
}
Piece val3 = val.GetComponent<Piece>();
if ((Object)(object)val3 == (Object)null)
{
val3 = val.AddComponent<Piece>();
}
val3.m_name = reg.DisplayName;
val3.m_description = reg.Description;
val3.m_groundOnly = false;
GameObject val4 = null;
GameObject val5 = null;
GameObject val6 = null;
GameObject val7 = null;
if (reg.PrefabName == "v2_CurvedWoodFence" || reg.PrefabName == "v2_VikingGate")
{
if ((Object)(object)ZNetScene.instance != (Object)null)
{
val4 = ZNetScene.instance.GetPrefab("vfx_Place_wood");
val5 = ZNetScene.instance.GetPrefab("sfx_build_hammer_wood");
val6 = ZNetScene.instance.GetPrefab("vfx_destroyed_wood");
val7 = ZNetScene.instance.GetPrefab("sfx_wood_break");
}
}
else if (reg.PrefabName == "v2_SilverGate" || reg.PrefabName == "v2_DvergrForgedGate" || reg.PrefabName == "v2_DvergrForgedGate3m" || reg.PrefabName == "v2_DvergrForgedGate4m" || reg.PrefabName == "v2_EmberlightGate" || reg.PrefabName == "v2_ValkyriesEntrance" || reg.PrefabName == "v2_ValkyriesSideGate" || reg.PrefabName == "v2_GildedRingwatchFence" || reg.PrefabName == "v2_SilverFence" || reg.PrefabName == "v2_IroncrestWardenFenceBK" || reg.PrefabName == "v2_IroncrestWardenFenceSilver" || reg.PrefabName == "v2_VikingArchGate" || reg.PrefabName == "v2_BlackFence" || reg.PrefabName == "v2_chain_fence")
{
if ((Object)(object)ZNetScene.instance != (Object)null)
{
val4 = ZNetScene.instance.GetPrefab("vfx_Place_stone");
val5 = ZNetScene.instance.GetPrefab("sfx_build_hammer_metal");
val6 = ZNetScene.instance.GetPrefab("vfx_destroyed");
val7 = ZNetScene.instance.GetPrefab("sfx_metal_blocked");
}
}
else if ((Object)(object)ZNetScene.instance != (Object)null)
{
val4 = ZNetScene.instance.GetPrefab("vfx_Place_stone");
val5 = ZNetScene.instance.GetPrefab("sfx_build_hammer_stone");
val6 = ZNetScene.instance.GetPrefab("vfx_destroyed");
val7 = ZNetScene.instance.GetPrefab("sfx_rock_destroyed");
}
List<EffectData> list = new List<EffectData>();
if ((Object)(object)val4 != (Object)null)
{
list.Add(new EffectData
{
m_prefab = val4,
m_enabled = true
});
}
if ((Object)(object)val5 != (Object)null)
{
list.Add(new EffectData
{
m_prefab = val5,
m_enabled = true
});
}
EffectList val8 = new EffectList();
val8.m_effectPrefabs = list.ToArray();
val3.m_placeEffect = val8;
WearNTear val9 = val.GetComponent<WearNTear>();
if ((Object)(object)val9 == (Object)null)
{
val9 = val.AddComponent<WearNTear>();
}
val9.m_health = 1000f;
val9.m_noRoofWear = true;
List<EffectData> list2 = new List<EffectData>();
if ((Object)(object)val6 != (Object)null)
{
list2.Add(new EffectData
{
m_prefab = val6,
m_enabled = true
});
}
if ((Object)(object)val7 != (Object)null)
{
list2.Add(new EffectData
{
m_prefab = val7,
m_enabled = true
});
}
EffectList val10 = new EffectList();
val10.m_effectPrefabs = list2.ToArray();
val9.m_destroyedEffect = val10;
Sprite val11 = bundle.LoadAsset<Sprite>(reg.PrefabName.ToLowerInvariant());
if ((Object)(object)val11 != (Object)null)
{
val3.m_icon = val11;
}
PieceConfig val12 = new PieceConfig();
val12.PieceTable = "Hammer";
val12.Category = CategoryToTab(reg.Category);
val12.CraftingStation = reg.CraftingStation;
val12.Requirements = reg.Requirements;
PieceManager.Instance.AddPiece(new CustomPiece(val, true, val12));
}
}
[BepInPlugin("Moonforged.GatesAndFences", "Moonforged Gates & Fences", "1.0.1")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class MoonforgedGates : BaseUnityPlugin
{
public const string PluginGUID = "Moonforged.GatesAndFences";
public const string PluginName = "Moonforged Gates & Fences";
public const string PluginVersion = "1.0.1";
private AssetBundle gatesBundle;
private static readonly List<GameObject> placedObjects = new List<GameObject>();
public static void TrackAllPrefabsInBundle(AssetBundle bundle)
{
GameObject[] array = bundle.LoadAllAssets<GameObject>();
foreach (GameObject val in array)
{
if ((Object)(object)val != (Object)null && (Object)(object)val.GetComponent<PlacementWatcher>() == (Object)null)
{
val.AddComponent<PlacementWatcher>().RegisterList = placedObjects;
}
}
}
private void Awake()
{
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_006e: Unknown result type (might be due to invalid IL or missing references)
new Harmony("moonforged.gates.scalingdebug").PatchAll();
string resourcePath = "MoonforgedGatesAndFences.gatesandfences";
gatesBundle = EmbeddedAssetBundleLoader.LoadBundle(resourcePath);
if ((Object)(object)gatesBundle == (Object)null)
{
((BaseUnityPlugin)this).Logger.LogError((object)"Failed to load embedded AssetBundle.");
return;
}
TrackAllPrefabsInBundle(gatesBundle);
foreach (string allCategory in RelicRegistrar.GetAllCategories())
{
PieceManager.Instance.AddPieceCategory(allCategory);
}
PrefabManager.OnPrefabsRegistered += delegate
{
RelicRegistrar.RegisterAllRelics(gatesBundle);
};
}
}
public static class EmbeddedAssetBundleLoader
{
public static AssetBundle LoadBundle(string resourcePath)
{
Assembly executingAssembly = Assembly.GetExecutingAssembly();
using Stream stream = executingAssembly.GetManifestResourceStream(resourcePath);
if (stream == null)
{
Debug.LogError((object)("AssetBundle resource not found: " + resourcePath));
return null;
}
byte[] array = new byte[stream.Length];
stream.Read(array, 0, array.Length);
return AssetBundle.LoadFromMemory(array);
}
}
}