using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.IO.Compression;
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 System.Text.RegularExpressions;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using HarmonyLib;
using JetBrains.Annotations;
using Microsoft.CodeAnalysis;
using PieceManager;
using UnityEngine;
[assembly: AssemblyFileVersion("1.0.3")]
[assembly: Guid("D7AC9D87-E508-42E6-BEA5-6AD3BA03C95B")]
[assembly: ComVisible(false)]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCopyright("Copyright © 2023")]
[assembly: AssemblyProduct("MineableBarnacle")]
[assembly: AssemblyCompany("blacks7ar")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyDescription("https://valheim.thunderstore.io/package/blacks7ar/MineableBarnacle/")]
[assembly: AssemblyTitle("MineableBarnacle")]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: CompilationRelaxations(8)]
[assembly: TargetFramework(".NETFramework,Version=v4.6.2", FrameworkDisplayName = ".NET Framework 4.6.2")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.3.0")]
[module: UnverifiableCode]
namespace MineableBarnacle
{
[BepInPlugin("blacks7ar.MineableBarnacle", "MineableBarnacle", "1.0.3")]
public class Plugin : BaseUnityPlugin
{
[HarmonyPatch]
public static class Patches
{
[HarmonyPatch(typeof(ZNetScene), "Awake")]
[HarmonyPostfix]
public static void Awake_Postfix(ZNetScene __instance)
{
//IL_0043: Unknown result type (might be due to invalid IL or missing references)
//IL_004e: Unknown result type (might be due to invalid IL or missing references)
//IL_0054: Expected O, but got Unknown
//IL_005d: Unknown result type (might be due to invalid IL or missing references)
//IL_0062: Unknown result type (might be due to invalid IL or missing references)
//IL_0073: Unknown result type (might be due to invalid IL or missing references)
//IL_007a: Unknown result type (might be due to invalid IL or missing references)
//IL_0082: Expected O, but got Unknown
//IL_0084: Unknown result type (might be due to invalid IL or missing references)
//IL_0089: Unknown result type (might be due to invalid IL or missing references)
//IL_009a: 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: Expected O, but got Unknown
//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
//IL_00bb: Expected O, but got Unknown
//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
//IL_00da: Unknown result type (might be due to invalid IL or missing references)
//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
//IL_00e9: Expected O, but got Unknown
//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
//IL_0101: 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_0110: Expected O, but got Unknown
//IL_011c: Unknown result type (might be due to invalid IL or missing references)
//IL_0121: 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_015e: Unknown result type (might be due to invalid IL or missing references)
//IL_0169: Unknown result type (might be due to invalid IL or missing references)
//IL_0170: Unknown result type (might be due to invalid IL or missing references)
//IL_0177: Unknown result type (might be due to invalid IL or missing references)
//IL_0182: Unknown result type (might be due to invalid IL or missing references)
//IL_018e: Expected O, but got Unknown
if (!((Object)(object)__instance == (Object)null))
{
List<GameObject> prefabs = __instance.m_prefabs;
if (prefabs != null && prefabs.Count > 0)
{
MineRock component = _barnacle.GetComponent<MineRock>();
((Component)component).gameObject.transform.localScale = new Vector3(0.7f, 0.7f, 0.7f);
EffectList val = new EffectList();
val.m_effectPrefabs = (EffectData[])(object)new EffectData[2]
{
new EffectData
{
m_prefab = __instance.GetPrefab("sfx_barnacle_destroyed"),
m_enabled = true,
m_variant = -1
},
new EffectData
{
m_prefab = __instance.GetPrefab("vfx_barnacle_destroyed"),
m_enabled = true,
m_variant = -1
}
};
component.m_destroyedEffect = val;
val = new EffectList();
val.m_effectPrefabs = (EffectData[])(object)new EffectData[2]
{
new EffectData
{
m_prefab = __instance.GetPrefab("sfx_rock_hit"),
m_enabled = true,
m_variant = -1
},
new EffectData
{
m_prefab = __instance.GetPrefab("vfx_barnacle_hit"),
m_enabled = true,
m_variant = -1
}
};
component.m_hitEffect = val;
component.m_dropItems = new DropTable
{
m_drops = new List<DropData>
{
new DropData
{
m_item = __instance.GetPrefab("Chitin"),
m_stackMin = 1,
m_stackMax = 1,
m_weight = 1f
}
},
m_dropMin = 1,
m_dropMax = 3,
m_dropChance = 100f,
m_oneOfEach = false
};
}
}
}
[HarmonyPrefix]
[HarmonyPatch(typeof(ZoneSystem), "ValidateVegetation")]
public static void ValidateVegetation_Prefix(ZoneSystem __instance)
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
//IL_0005: 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_001b: Unknown result type (might be due to invalid IL or missing references)
//IL_0026: Unknown result type (might be due to invalid IL or missing references)
//IL_002c: Unknown result type (might be due to invalid IL or missing references)
//IL_0031: Unknown result type (might be due to invalid IL or missing references)
//IL_003c: Unknown result type (might be due to invalid IL or missing references)
//IL_0047: 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_005d: Unknown result type (might be due to invalid IL or missing references)
//IL_0069: Expected O, but got Unknown
ZoneVegetation item = new ZoneVegetation
{
m_min = 12f,
m_max = 12f,
m_chanceToUseGroundTilt = 1f,
m_biome = (Biome)282,
m_minAltitude = -0.6f,
m_maxAltitude = 1.5f,
m_maxTerrainDelta = 2f,
m_groundOffset = -0.5f,
m_prefab = _barnacle
};
if (__instance.m_vegetation.Contains(item))
{
__instance.m_vegetation.Remove(item);
}
__instance.m_vegetation.Add(item);
}
}
private const string modGUID = "blacks7ar.MineableBarnacle";
public const string modName = "MineableBarnacle";
public const string modAuthor = "blacks7ar";
public const string modVersion = "1.0.3";
public const string modLink = "https://valheim.thunderstore.io/package/blacks7ar/MineableBarnacle/";
private static readonly Harmony _harmony = new Harmony("blacks7ar.MineableBarnacle");
private static AssetBundle _barnacleBundle;
private readonly Assembly _assembly = Assembly.GetExecutingAssembly();
private static GameObject _barnacle;
public void Awake()
{
_barnacleBundle = PiecePrefabManager.RegisterAssetBundle("barnaclebundle");
_barnacle = PiecePrefabManager.RegisterPrefab(_barnacleBundle, "BMB_MineRock_Chitin");
MaterialReplacer.RegisterGameObjectForShaderSwap(_barnacle, MaterialReplacer.ShaderType.RockShader);
_harmony.PatchAll(_assembly);
}
}
}
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;
}
}
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
internal sealed class NullableContextAttribute : Attribute
{
public readonly byte Flag;
public NullableContextAttribute(byte P_0)
{
Flag = P_0;
}
}
}
namespace PieceManager
{
[PublicAPI]
internal static class MaterialReplacer
{
public enum ShaderType
{
PieceShader,
VegetationShader,
RockShader,
RugShader,
GrassShader,
CustomCreature,
UseUnityShader
}
private static Dictionary<GameObject, bool> _objectToSwap;
internal static Dictionary<string, Material> originalMaterials;
private static Dictionary<GameObject, ShaderType> _objectsForShaderReplace;
private static bool hasRun;
static MaterialReplacer()
{
//IL_0023: Unknown result type (might be due to invalid IL or missing references)
//IL_0055: Unknown result type (might be due to invalid IL or missing references)
//IL_0062: Expected O, but got Unknown
originalMaterials = new Dictionary<string, Material>();
_objectToSwap = new Dictionary<GameObject, bool>();
_objectsForShaderReplace = new Dictionary<GameObject, ShaderType>();
new Harmony("org.bepinex.helpers.PieceManager").Patch((MethodBase)AccessTools.DeclaredMethod(typeof(ZoneSystem), "Start", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(AccessTools.DeclaredMethod(typeof(MaterialReplacer), "ReplaceAllMaterialsWithOriginal", (Type[])null, (Type[])null)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
}
public static void RegisterGameObjectForShaderSwap(GameObject go, ShaderType type)
{
if (!_objectsForShaderReplace.ContainsKey(go))
{
_objectsForShaderReplace?.Add(go, type);
}
}
public static void RegisterGameObjectForMatSwap(GameObject go, bool isJotunnMock = false)
{
if (!_objectToSwap.ContainsKey(go))
{
_objectToSwap.Add(go, isJotunnMock);
}
}
private static void GetAllMaterials()
{
Material[] array = Resources.FindObjectsOfTypeAll<Material>();
foreach (Material val in array)
{
originalMaterials[((Object)val).name] = val;
}
}
[HarmonyPriority(700)]
private static void ReplaceAllMaterialsWithOriginal()
{
if (hasRun)
{
return;
}
if (originalMaterials.Count <= 0)
{
GetAllMaterials();
}
foreach (Renderer item in _objectToSwap.SelectMany<KeyValuePair<GameObject, bool>, Renderer>((KeyValuePair<GameObject, bool> gameObject) => gameObject.Key.GetComponentsInChildren<Renderer>(true)))
{
_objectToSwap.TryGetValue(((Component)item).gameObject, out var value);
Material[] array = (Material[])(object)new Material[item.sharedMaterials.Length];
int num = 0;
Material[] sharedMaterials = item.sharedMaterials;
foreach (Material val in sharedMaterials)
{
string text = (value ? "JVLmock_" : "_REPLACE_");
if (!((Object)val).name.StartsWith(text, StringComparison.Ordinal))
{
continue;
}
string text2 = ((Object)item.material).name.Replace(" (Instance)", string.Empty).Replace(text, "");
string text3 = ((Object)val).name.Replace(" (Instance)", string.Empty).Replace(text, "");
if (originalMaterials.ContainsKey(text3))
{
if (num <= item.materials.Length)
{
array[num] = originalMaterials[text3];
}
}
else
{
Debug.LogWarning((object)("No suitable material found to replace: " + text3));
originalMaterials[text3] = array[num];
}
if (originalMaterials.ContainsKey(text2))
{
item.material = originalMaterials[text2];
}
else
{
Debug.LogWarning((object)("No suitable material found to replace: " + text2));
originalMaterials[text2] = item.material;
}
num++;
}
item.materials = array;
item.sharedMaterials = array;
}
foreach (Renderer item2 in _objectsForShaderReplace.SelectMany<KeyValuePair<GameObject, ShaderType>, Renderer>((KeyValuePair<GameObject, ShaderType> gameObject) => gameObject.Key.GetComponentsInChildren<Renderer>(true)))
{
_objectsForShaderReplace.TryGetValue(((Component)((Component)item2).gameObject.transform.root).gameObject, out var value2);
if ((Object)(object)item2 == (Object)null)
{
continue;
}
Material[] sharedMaterials = item2.sharedMaterials;
foreach (Material val2 in sharedMaterials)
{
if ((Object)(object)val2 == (Object)null)
{
continue;
}
string name = ((Object)val2.shader).name;
switch (value2)
{
case ShaderType.PieceShader:
val2.shader = Shader.Find("Custom/Piece");
break;
case ShaderType.VegetationShader:
val2.shader = Shader.Find("Custom/Vegetation");
break;
case ShaderType.RockShader:
val2.shader = Shader.Find("Custom/StaticRock");
break;
case ShaderType.RugShader:
val2.shader = Shader.Find("Custom/Rug");
break;
case ShaderType.GrassShader:
val2.shader = Shader.Find("Custom/Grass");
break;
case ShaderType.CustomCreature:
val2.shader = Shader.Find("Custom/Creature");
break;
case ShaderType.UseUnityShader:
if ((Object)(object)Shader.Find(name) != (Object)null)
{
val2.shader = Shader.Find(name);
}
break;
default:
val2.shader = Shader.Find("ToonDeferredShading2017");
break;
}
}
}
hasRun = true;
}
}
[PublicAPI]
internal enum CraftingTable
{
None,
[InternalName("piece_workbench")]
Workbench,
[InternalName("piece_cauldron")]
Cauldron,
[InternalName("forge")]
Forge,
[InternalName("piece_artisanstation")]
ArtisanTable,
[InternalName("piece_stonecutter")]
StoneCutter,
[InternalName("piece_magetable")]
MageTable,
[InternalName("blackforge")]
BlackForge,
Custom
}
internal class InternalName : Attribute
{
public readonly string internalName;
public InternalName(string internalName)
{
this.internalName = internalName;
}
}
[PublicAPI]
internal class ExtensionList
{
public readonly List<ExtensionConfig> ExtensionStations = new List<ExtensionConfig>();
public void Set(CraftingTable table, int maxStationDistance = 5)
{
ExtensionStations.Add(new ExtensionConfig
{
Table = table,
maxStationDistance = maxStationDistance
});
}
public void Set(string customTable, int maxStationDistance = 5)
{
ExtensionStations.Add(new ExtensionConfig
{
Table = CraftingTable.Custom,
custom = customTable,
maxStationDistance = maxStationDistance
});
}
}
internal struct ExtensionConfig
{
public CraftingTable Table;
public float maxStationDistance;
public string? custom;
}
[PublicAPI]
internal class CraftingStationList
{
public readonly List<CraftingStationConfig> Stations = new List<CraftingStationConfig>();
public void Set(CraftingTable table)
{
Stations.Add(new CraftingStationConfig
{
Table = table
});
}
public void Set(string customTable)
{
Stations.Add(new CraftingStationConfig
{
Table = CraftingTable.Custom,
custom = customTable
});
}
}
internal struct CraftingStationConfig
{
public CraftingTable Table;
public int level;
public string? custom;
}
[PublicAPI]
internal enum BuildPieceCategory
{
Misc = 0,
Crafting = 1,
Building = 2,
Furniture = 3,
All = 100,
Custom = 101
}
[PublicAPI]
internal class RequiredResourcesList
{
public readonly List<Requirement> Requirements = new List<Requirement>();
public void Add(string item, int amount, bool recover)
{
Requirements.Add(new Requirement
{
itemName = item,
amount = amount,
recover = recover
});
}
}
internal struct Requirement
{
public string itemName;
public int amount;
public bool recover;
}
internal struct SpecialProperties
{
[Description("Admins should be the only ones that can build this piece.")]
public bool AdminOnly;
[Description("Turns off generating a config for this build piece.")]
public bool NoConfig;
}
[PublicAPI]
internal class BuildingPieceCategoryList
{
public readonly List<BuildPieceTableConfig> BuildPieceCategories = new List<BuildPieceTableConfig>();
public void Add(BuildPieceCategory category)
{
BuildPieceCategories.Add(new BuildPieceTableConfig
{
Category = category
});
}
public void Add(string customCategory)
{
BuildPieceCategories.Add(new BuildPieceTableConfig
{
Category = BuildPieceCategory.Custom,
custom = customCategory
});
}
}
internal struct BuildPieceTableConfig
{
public BuildPieceCategory Category;
public string? custom;
}
[PublicAPI]
internal class BuildPiece
{
private class PieceConfig
{
public ConfigEntry<string> craft;
public ConfigEntry<BuildPieceCategory> category;
public ConfigEntry<string> customCategory;
public ConfigEntry<CraftingTable> extensionTable;
public ConfigEntry<string> customExtentionTable;
public ConfigEntry<float> maxStationDistance;
public ConfigEntry<CraftingTable> table;
public ConfigEntry<string> customTable;
}
private class ConfigurationManagerAttributes
{
[UsedImplicitly]
public int? Order;
[UsedImplicitly]
public bool? Browsable;
[UsedImplicitly]
public string? Category;
[UsedImplicitly]
public Action<ConfigEntryBase>? CustomDrawer;
}
private class SerializedRequirements
{
public readonly List<Requirement> Reqs;
public SerializedRequirements(List<Requirement> reqs)
{
Reqs = reqs;
}
public SerializedRequirements(string reqs)
{
Reqs = reqs.Split(new char[1] { ',' }).Select(delegate(string r)
{
string[] array = r.Split(new char[1] { ':' });
Requirement result = default(Requirement);
result.itemName = array[0];
result.amount = ((array.Length <= 1 || !int.TryParse(array[1], out var result2)) ? 1 : result2);
bool result3 = default(bool);
result.recover = array.Length <= 2 || !bool.TryParse(array[2], out result3) || result3;
return result;
}).ToList();
}
public override string ToString()
{
return string.Join(",", Reqs.Select((Requirement r) => $"{r.itemName}:{r.amount}:{r.recover}"));
}
public static Requirement[] toPieceReqs(SerializedRequirements craft)
{
return craft.Reqs.Where((Requirement r) => r.itemName != "").ToDictionary((Func<Requirement, string>)((Requirement r) => r.itemName), (Func<Requirement, Requirement>)delegate(Requirement r)
{
//IL_000c: Unknown result type (might be due to invalid IL or missing references)
//IL_0011: Unknown result type (might be due to invalid IL or missing references)
//IL_001d: Unknown result type (might be due to invalid IL or missing references)
//IL_0024: Unknown result type (might be due to invalid IL or missing references)
//IL_0031: Expected O, but got Unknown
ItemDrop val = ResItem(r);
return (val != null) ? new Requirement
{
m_amount = r.amount,
m_resItem = val,
m_recover = r.recover
} : ((Requirement)null);
}).Values.Where((Requirement v) => v != null).ToArray();
static ItemDrop? ResItem(Requirement r)
{
GameObject itemPrefab = ObjectDB.instance.GetItemPrefab(r.itemName);
ItemDrop obj = ((itemPrefab != null) ? itemPrefab.GetComponent<ItemDrop>() : null);
if ((Object)(object)obj == (Object)null)
{
Debug.LogWarning((object)("The required item '" + r.itemName + "' does not exist."));
}
return obj;
}
}
}
internal static readonly List<BuildPiece> registeredPieces = new List<BuildPiece>();
private static Dictionary<BuildPiece, PieceConfig> pieceConfigs = new Dictionary<BuildPiece, PieceConfig>();
[Description("Disables generation of the configs for your pieces. This is global, this turns it off for all pieces in your mod.")]
public static bool ConfigurationEnabled = true;
public readonly GameObject Prefab;
[Description("Specifies the resources needed to craft the piece.\nUse .Add to add resources with their internal ID and an amount.\nUse one .Add for each resource type the building piece should need.")]
public readonly RequiredResourcesList RequiredItems = new RequiredResourcesList();
[Description("Sets the category for the building piece.")]
public readonly BuildingPieceCategoryList Category = new BuildingPieceCategoryList();
[Description("Specifies the crafting station needed to build your piece.\nUse .Add to add a crafting station, using the CraftingTable enum and a minimum level for the crafting station.")]
public CraftingStationList Crafting = new CraftingStationList();
[Description("Makes this piece a station extension")]
public ExtensionList Extension = new ExtensionList();
[Description("Change the extended/special properties of your build piece.")]
public SpecialProperties SpecialProperties;
private LocalizeKey? _name;
private LocalizeKey? _description;
private static object? configManager;
private static Localization? _english;
internal static BaseUnityPlugin? _plugin = null;
private static bool hasConfigSync = true;
private static object? _configSync;
public LocalizeKey Name
{
get
{
LocalizeKey name = _name;
if (name != null)
{
return name;
}
Piece component = Prefab.GetComponent<Piece>();
if (component.m_name.StartsWith("$"))
{
_name = new LocalizeKey(component.m_name);
}
else
{
string text = "$piece_" + ((Object)Prefab).name.Replace(" ", "_");
_name = new LocalizeKey(text).English(component.m_name);
component.m_name = text;
}
return _name;
}
}
public LocalizeKey Description
{
get
{
LocalizeKey description = _description;
if (description != null)
{
return description;
}
Piece component = Prefab.GetComponent<Piece>();
if (component.m_description.StartsWith("$"))
{
_description = new LocalizeKey(component.m_description);
}
else
{
string text = "$piece_" + ((Object)Prefab).name.Replace(" ", "_") + "_description";
_description = new LocalizeKey(text).English(component.m_description);
component.m_description = text;
}
return _description;
}
}
private static Localization english => _english ?? (_english = LocalizationCache.ForLanguage("English"));
internal static BaseUnityPlugin plugin
{
get
{
//IL_009f: Unknown result type (might be due to invalid IL or missing references)
//IL_00a9: Expected O, but got Unknown
if (_plugin != null)
{
return _plugin;
}
IEnumerable<TypeInfo> source;
try
{
source = Assembly.GetExecutingAssembly().DefinedTypes.ToList();
}
catch (ReflectionTypeLoadException ex)
{
source = from t in ex.Types
where t != null
select t.GetTypeInfo();
}
_plugin = (BaseUnityPlugin)Chainloader.ManagerObject.GetComponent((Type)source.First((TypeInfo t) => t.IsClass && typeof(BaseUnityPlugin).IsAssignableFrom(t)));
return _plugin;
}
}
private static object? configSync
{
get
{
if (_configSync != null || !hasConfigSync)
{
return _configSync;
}
Type type = Assembly.GetExecutingAssembly().GetType("ServerSync.ConfigSync");
if ((object)type != null)
{
_configSync = Activator.CreateInstance(type, plugin.Info.Metadata.GUID + " PieceManager");
type.GetField("CurrentVersion").SetValue(_configSync, plugin.Info.Metadata.Version.ToString());
type.GetProperty("IsLocked").SetValue(_configSync, true);
}
else
{
hasConfigSync = false;
}
return _configSync;
}
}
public BuildPiece(string assetBundleFileName, string prefabName, string folderName = "assets")
: this(PiecePrefabManager.RegisterAssetBundle(assetBundleFileName, folderName), prefabName)
{
}
public BuildPiece(AssetBundle bundle, string prefabName, bool addToCustom = false, string customPieceTable = "")
{
if (addToCustom)
{
Prefab = PiecePrefabManager.RegisterPrefab(bundle, prefabName, addToPieceTable: false, addToCustomPieceTable: true, customPieceTable);
}
else
{
Prefab = PiecePrefabManager.RegisterPrefab(bundle, prefabName, addToPieceTable: true);
}
registeredPieces.Add(this);
}
internal static void Patch_FejdStartup()
{
//IL_0203: Unknown result type (might be due to invalid IL or missing references)
//IL_020d: Expected O, but got Unknown
//IL_02b9: Unknown result type (might be due to invalid IL or missing references)
//IL_02c3: Expected O, but got Unknown
//IL_0331: Unknown result type (might be due to invalid IL or missing references)
//IL_0411: Unknown result type (might be due to invalid IL or missing references)
//IL_041b: Expected O, but got Unknown
//IL_06d4: Unknown result type (might be due to invalid IL or missing references)
//IL_06de: Expected O, but got Unknown
//IL_0481: Unknown result type (might be due to invalid IL or missing references)
//IL_048b: Expected O, but got Unknown
//IL_0522: Unknown result type (might be due to invalid IL or missing references)
//IL_052c: Expected O, but got Unknown
//IL_0744: Unknown result type (might be due to invalid IL or missing references)
//IL_074e: Expected O, but got Unknown
Type configManagerType = AppDomain.CurrentDomain.GetAssemblies().FirstOrDefault((Assembly a) => a.GetName().Name == "ConfigurationManager")?.GetType("ConfigurationManager.ConfigurationManager");
configManager = ((configManagerType == null) ? null : Chainloader.ManagerObject.GetComponent(configManagerType));
if (!ConfigurationEnabled)
{
return;
}
bool saveOnConfigSet = plugin.Config.SaveOnConfigSet;
plugin.Config.SaveOnConfigSet = false;
foreach (BuildPiece registeredPiece in registeredPieces)
{
BuildPiece piece = registeredPiece;
if (piece.SpecialProperties.NoConfig)
{
continue;
}
PieceConfig pieceConfig2 = (pieceConfigs[piece] = new PieceConfig());
PieceConfig cfg = pieceConfig2;
Piece piecePrefab = piece.Prefab.GetComponent<Piece>();
string pieceName = piecePrefab.m_name;
string englishName = new Regex("['[\"\\]]").Replace(english.Localize(pieceName), "").Trim();
string localizedName = Localization.instance.Localize(pieceName).Trim();
int order = 0;
cfg.category = config(englishName, "Build Table Category", piece.Category.BuildPieceCategories.First().Category, new ConfigDescription("Build Category where " + localizedName + " is available.", (AcceptableValueBase)null, new object[1]
{
new ConfigurationManagerAttributes
{
Order = (order -= 1),
Category = localizedName
}
}));
ConfigurationManagerAttributes customTableAttributes = new ConfigurationManagerAttributes
{
Order = (order -= 1),
Browsable = (cfg.category.Value == BuildPieceCategory.Custom),
Category = localizedName
};
cfg.customCategory = config(englishName, "Custom Build Category", piece.Category.BuildPieceCategories.First().custom ?? "", new ConfigDescription("", (AcceptableValueBase)null, new object[1] { customTableAttributes }));
cfg.category.SettingChanged += BuildTableConfigChanged;
cfg.customCategory.SettingChanged += BuildTableConfigChanged;
if (cfg.category.Value != BuildPieceCategory.Custom)
{
piecePrefab.m_category = (PieceCategory)cfg.category.Value;
}
StationExtension pieceExtensionComp;
List<ConfigurationManagerAttributes> hideWhenNoneAttributes2;
if (piece.Extension.ExtensionStations.Count > 0)
{
pieceExtensionComp = piece.Prefab.GetOrAddComponent<StationExtension>();
PieceConfig pieceConfig3 = cfg;
string group = englishName;
CraftingTable table = piece.Extension.ExtensionStations.First().Table;
string text = "Crafting station that " + localizedName + " extends.";
object[] array = new object[1];
ConfigurationManagerAttributes configurationManagerAttributes = new ConfigurationManagerAttributes();
int num = order - 1;
order = num;
configurationManagerAttributes.Order = num;
array[0] = configurationManagerAttributes;
pieceConfig3.extensionTable = config(group, "Extends Station", table, new ConfigDescription(text, (AcceptableValueBase)null, array));
cfg.customExtentionTable = config(englishName, "Custom Extend Station", piece.Extension.ExtensionStations.First().custom ?? "", new ConfigDescription("", (AcceptableValueBase)null, new object[1] { customTableAttributes }));
PieceConfig pieceConfig4 = cfg;
string group2 = englishName;
float maxStationDistance = piece.Extension.ExtensionStations.First().maxStationDistance;
string text2 = "Distance from the station that " + localizedName + " can be placed.";
object[] array2 = new object[1];
ConfigurationManagerAttributes configurationManagerAttributes2 = new ConfigurationManagerAttributes();
num = order - 1;
order = num;
configurationManagerAttributes2.Order = num;
array2[0] = configurationManagerAttributes2;
pieceConfig4.maxStationDistance = config(group2, "Max Station Distance", maxStationDistance, new ConfigDescription(text2, (AcceptableValueBase)null, array2));
hideWhenNoneAttributes2 = new List<ConfigurationManagerAttributes>();
cfg.extensionTable.SettingChanged += ExtensionTableConfigChanged;
cfg.customExtentionTable.SettingChanged += ExtensionTableConfigChanged;
cfg.maxStationDistance.SettingChanged += ExtensionTableConfigChanged;
ConfigurationManagerAttributes configurationManagerAttributes3 = new ConfigurationManagerAttributes();
num = order - 1;
order = num;
configurationManagerAttributes3.Order = num;
configurationManagerAttributes3.Browsable = cfg.extensionTable.Value != CraftingTable.None;
ConfigurationManagerAttributes item = configurationManagerAttributes3;
hideWhenNoneAttributes2.Add(item);
}
List<ConfigurationManagerAttributes> hideWhenNoneAttributes;
if (piece.Crafting.Stations.Count > 0)
{
hideWhenNoneAttributes = new List<ConfigurationManagerAttributes>();
PieceConfig pieceConfig5 = cfg;
string group3 = englishName;
CraftingTable table2 = piece.Crafting.Stations.First().Table;
string text3 = "Crafting station where " + localizedName + " is available.";
object[] array3 = new object[1];
ConfigurationManagerAttributes configurationManagerAttributes4 = new ConfigurationManagerAttributes();
int num = order - 1;
order = num;
configurationManagerAttributes4.Order = num;
array3[0] = configurationManagerAttributes4;
pieceConfig5.table = config(group3, "Crafting Station", table2, new ConfigDescription(text3, (AcceptableValueBase)null, array3));
cfg.customTable = config(englishName, "Custom Crafting Station", piece.Crafting.Stations.First().custom ?? "", new ConfigDescription("", (AcceptableValueBase)null, new object[1] { customTableAttributes }));
cfg.table.SettingChanged += TableConfigChanged;
cfg.customTable.SettingChanged += TableConfigChanged;
ConfigurationManagerAttributes configurationManagerAttributes5 = new ConfigurationManagerAttributes();
num = order - 1;
order = num;
configurationManagerAttributes5.Order = num;
configurationManagerAttributes5.Browsable = cfg.table.Value != CraftingTable.None;
ConfigurationManagerAttributes item2 = configurationManagerAttributes5;
hideWhenNoneAttributes.Add(item2);
}
cfg.craft = itemConfig("Crafting Costs", new SerializedRequirements(piece.RequiredItems.Requirements).ToString(), "Item costs to craft " + localizedName);
cfg.craft.SettingChanged += delegate
{
if (Object.op_Implicit((Object)(object)ObjectDB.instance) && (Object)(object)ObjectDB.instance.GetItemPrefab("Wood") != (Object)null)
{
Requirement[] resources = SerializedRequirements.toPieceReqs(new SerializedRequirements(cfg.craft.Value));
piecePrefab.m_resources = resources;
Piece[] array4 = Object.FindObjectsOfType<Piece>();
foreach (Piece val in array4)
{
if (val.m_name == pieceName)
{
val.m_resources = resources;
}
}
}
};
void BuildTableConfigChanged(object o, EventArgs e)
{
//IL_0037: Unknown result type (might be due to invalid IL or missing references)
if (registeredPieces.Count > 0 && cfg.category.Value != BuildPieceCategory.Custom)
{
piecePrefab.m_category = (PieceCategory)cfg.category.Value;
}
customTableAttributes.Browsable = cfg.category.Value == BuildPieceCategory.Custom;
ReloadConfigDisplay();
}
void ExtensionTableConfigChanged(object o, EventArgs e)
{
if (piece.RequiredItems.Requirements.Count > 0)
{
if (cfg.extensionTable.Value == CraftingTable.Custom)
{
StationExtension obj2 = pieceExtensionComp;
GameObject prefab2 = ZNetScene.instance.GetPrefab(cfg.customExtentionTable.Value);
obj2.m_craftingStation = ((prefab2 != null) ? prefab2.GetComponent<CraftingStation>() : null);
}
else
{
pieceExtensionComp.m_craftingStation = ZNetScene.instance.GetPrefab(((InternalName)typeof(CraftingTable).GetMember(cfg.extensionTable.Value.ToString())[0].GetCustomAttributes(typeof(InternalName)).First()).internalName).GetComponent<CraftingStation>();
}
pieceExtensionComp.m_maxStationDistance = cfg.maxStationDistance.Value;
}
customTableAttributes.Browsable = cfg.extensionTable.Value == CraftingTable.Custom;
foreach (ConfigurationManagerAttributes item3 in hideWhenNoneAttributes2)
{
item3.Browsable = cfg.extensionTable.Value != CraftingTable.None;
}
ReloadConfigDisplay();
plugin.Config.Save();
}
void TableConfigChanged(object o, EventArgs e)
{
if (piece.RequiredItems.Requirements.Count > 0)
{
switch (cfg.table.Value)
{
case CraftingTable.None:
piecePrefab.m_craftingStation = null;
break;
case CraftingTable.Custom:
{
Piece obj = piecePrefab;
GameObject prefab = ZNetScene.instance.GetPrefab(cfg.customTable.Value);
obj.m_craftingStation = ((prefab != null) ? prefab.GetComponent<CraftingStation>() : null);
break;
}
default:
piecePrefab.m_craftingStation = ZNetScene.instance.GetPrefab(((InternalName)typeof(CraftingTable).GetMember(cfg.table.Value.ToString())[0].GetCustomAttributes(typeof(InternalName)).First()).internalName).GetComponent<CraftingStation>();
break;
}
}
customTableAttributes.Browsable = cfg.table.Value == CraftingTable.Custom;
foreach (ConfigurationManagerAttributes item4 in hideWhenNoneAttributes)
{
item4.Browsable = cfg.table.Value != CraftingTable.None;
}
ReloadConfigDisplay();
plugin.Config.Save();
}
ConfigEntry<string> itemConfig(string name, string value, string desc)
{
//IL_0054: Unknown result type (might be due to invalid IL or missing references)
//IL_005e: Expected O, but got Unknown
ConfigurationManagerAttributes configurationManagerAttributes6 = new ConfigurationManagerAttributes
{
CustomDrawer = DrawConfigTable,
Order = (order -= 1),
Category = localizedName
};
return config(englishName, name, value, new ConfigDescription(desc, (AcceptableValueBase)null, new object[1] { configurationManagerAttributes6 }));
}
}
if (saveOnConfigSet)
{
plugin.Config.SaveOnConfigSet = true;
plugin.Config.Save();
}
void ReloadConfigDisplay()
{
configManagerType?.GetMethod("BuildSettingList").Invoke(configManager, Array.Empty<object>());
}
}
[HarmonyPriority(700)]
internal static void Patch_ObjectDBInit(ObjectDB __instance)
{
if ((Object)(object)__instance.GetItemPrefab("Wood") == (Object)null)
{
return;
}
foreach (BuildPiece registeredPiece in registeredPieces)
{
pieceConfigs.TryGetValue(registeredPiece, out PieceConfig value);
registeredPiece.Prefab.GetComponent<Piece>().m_resources = SerializedRequirements.toPieceReqs((value == null) ? new SerializedRequirements(registeredPiece.RequiredItems.Requirements) : new SerializedRequirements(value.craft.Value));
foreach (ExtensionConfig extensionStation in registeredPiece.Extension.ExtensionStations)
{
switch ((value == null || registeredPiece.Extension.ExtensionStations.Count > 0) ? extensionStation.Table : value.extensionTable.Value)
{
case CraftingTable.None:
registeredPiece.Prefab.GetComponent<StationExtension>().m_craftingStation = null;
break;
case CraftingTable.Custom:
{
GameObject prefab = ZNetScene.instance.GetPrefab((value == null || registeredPiece.Extension.ExtensionStations.Count > 0) ? extensionStation.custom : value.customExtentionTable.Value);
if (prefab != null)
{
registeredPiece.Prefab.GetComponent<StationExtension>().m_craftingStation = prefab.GetComponent<CraftingStation>();
}
else
{
Debug.LogWarning((object)("Custom crafting station '" + ((value == null || registeredPiece.Extension.ExtensionStations.Count > 0) ? extensionStation.custom : value.customExtentionTable.Value) + "' does not exist"));
}
break;
}
default:
if (value != null && value.table.Value == CraftingTable.None)
{
registeredPiece.Prefab.GetComponent<StationExtension>().m_craftingStation = null;
}
else
{
registeredPiece.Prefab.GetComponent<StationExtension>().m_craftingStation = ZNetScene.instance.GetPrefab(((InternalName)typeof(CraftingTable).GetMember(((value == null || registeredPiece.Extension.ExtensionStations.Count > 0) ? extensionStation.Table : value.extensionTable.Value).ToString())[0].GetCustomAttributes(typeof(InternalName)).First()).internalName).GetComponent<CraftingStation>();
}
break;
}
}
foreach (CraftingStationConfig station in registeredPiece.Crafting.Stations)
{
switch ((value == null || registeredPiece.Crafting.Stations.Count > 0) ? station.Table : value.table.Value)
{
case CraftingTable.None:
registeredPiece.Prefab.GetComponent<Piece>().m_craftingStation = null;
break;
case CraftingTable.Custom:
{
GameObject prefab2 = ZNetScene.instance.GetPrefab((value == null || registeredPiece.Crafting.Stations.Count > 0) ? station.custom : value.customTable.Value);
if (prefab2 != null)
{
registeredPiece.Prefab.GetComponent<Piece>().m_craftingStation = prefab2.GetComponent<CraftingStation>();
}
else
{
Debug.LogWarning((object)("Custom crafting station '" + ((value == null || registeredPiece.Crafting.Stations.Count > 0) ? station.custom : value.customTable.Value) + "' does not exist"));
}
break;
}
default:
if (value != null && value.table.Value == CraftingTable.None)
{
registeredPiece.Prefab.GetComponent<Piece>().m_craftingStation = null;
}
else
{
registeredPiece.Prefab.GetComponent<Piece>().m_craftingStation = ZNetScene.instance.GetPrefab(((InternalName)typeof(CraftingTable).GetMember(((value == null || registeredPiece.Crafting.Stations.Count > 0) ? station.Table : value.table.Value).ToString())[0].GetCustomAttributes(typeof(InternalName)).First()).internalName).GetComponent<CraftingStation>();
}
break;
}
}
}
}
public void Snapshot(float lightIntensity = 1.3f, Quaternion? cameraRotation = null)
{
SnapshotPiece(Prefab, lightIntensity, cameraRotation);
}
internal void SnapshotPiece(GameObject prefab, float lightIntensity = 1.3f, Quaternion? cameraRotation = null)
{
//IL_003d: Unknown result type (might be due to invalid IL or missing references)
//IL_0049: 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_00a3: Unknown result type (might be due to invalid IL or missing references)
//IL_009a: Unknown result type (might be due to invalid IL or missing references)
//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
//IL_0102: Unknown result type (might be due to invalid IL or missing references)
//IL_0121: Unknown result type (might be due to invalid IL or missing references)
//IL_0178: Unknown result type (might be due to invalid IL or missing references)
//IL_0197: Unknown result type (might be due to invalid IL or missing references)
//IL_01b4: Unknown result type (might be due to invalid IL or missing references)
//IL_01d8: 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_0202: Unknown result type (might be due to invalid IL or missing references)
//IL_0207: Unknown result type (might be due to invalid IL or missing references)
//IL_021e: Unknown result type (might be due to invalid IL or missing references)
//IL_0223: Unknown result type (might be due to invalid IL or missing references)
//IL_0224: 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_0230: Unknown result type (might be due to invalid IL or missing references)
//IL_0235: Unknown result type (might be due to invalid IL or missing references)
//IL_023f: Unknown result type (might be due to invalid IL or missing references)
//IL_0241: Unknown result type (might be due to invalid IL or missing references)
//IL_0242: 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_029a: Unknown result type (might be due to invalid IL or missing references)
//IL_02a1: Unknown result type (might be due to invalid IL or missing references)
//IL_02e2: Unknown result type (might be due to invalid IL or missing references)
//IL_02f3: Unknown result type (might be due to invalid IL or missing references)
//IL_02f8: Unknown result type (might be due to invalid IL or missing references)
//IL_032a: Unknown result type (might be due to invalid IL or missing references)
//IL_0331: Expected O, but got Unknown
//IL_034f: Unknown result type (might be due to invalid IL or missing references)
//IL_038b: Unknown result type (might be due to invalid IL or missing references)
//IL_0390: Unknown result type (might be due to invalid IL or missing references)
//IL_039a: Unknown result type (might be due to invalid IL or missing references)
if (!((Object)(object)prefab == (Object)null) && (prefab.GetComponentsInChildren<Renderer>().Any() || prefab.GetComponentsInChildren<MeshFilter>().Any()))
{
Camera component = new GameObject("CameraIcon", new Type[1] { typeof(Camera) }).GetComponent<Camera>();
component.backgroundColor = Color.clear;
component.clearFlags = (CameraClearFlags)2;
((Component)component).transform.position = new Vector3(10000f, 10000f, 10000f);
((Component)component).transform.rotation = (Quaternion)(((??)cameraRotation) ?? Quaternion.Euler(0f, 180f, 0f));
component.fieldOfView = 0.5f;
component.farClipPlane = 100000f;
component.cullingMask = 8;
Light component2 = new GameObject("LightIcon", new Type[1] { typeof(Light) }).GetComponent<Light>();
((Component)component2).transform.position = new Vector3(10000f, 10000f, 10000f);
((Component)component2).transform.rotation = Quaternion.Euler(5f, 180f, 5f);
component2.type = (LightType)1;
component2.cullingMask = 8;
component2.intensity = lightIntensity;
GameObject val = Object.Instantiate<GameObject>(prefab);
Transform[] componentsInChildren = val.GetComponentsInChildren<Transform>();
for (int i = 0; i < componentsInChildren.Length; i++)
{
((Component)componentsInChildren[i]).gameObject.layer = 3;
}
val.transform.position = Vector3.zero;
val.transform.rotation = Quaternion.Euler(23f, 51f, 25.8f);
((Object)val).name = ((Object)prefab).name;
MeshRenderer[] componentsInChildren2 = val.GetComponentsInChildren<MeshRenderer>();
Vector3 val2 = componentsInChildren2.Aggregate(Vector3.positiveInfinity, delegate(Vector3 cur, MeshRenderer renderer)
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//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)
Bounds bounds2 = ((Renderer)renderer).bounds;
return Vector3.Min(cur, ((Bounds)(ref bounds2)).min);
});
Vector3 val3 = componentsInChildren2.Aggregate(Vector3.negativeInfinity, delegate(Vector3 cur, MeshRenderer renderer)
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//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)
Bounds bounds = ((Renderer)renderer).bounds;
return Vector3.Max(cur, ((Bounds)(ref bounds)).max);
});
val.transform.position = new Vector3(10000f, 10000f, 10000f) - (val2 + val3) / 2f;
Vector3 val4 = val3 - val2;
val.AddComponent<TimedDestruction>().Trigger(1f);
Rect val5 = default(Rect);
((Rect)(ref val5))..ctor(0f, 0f, 128f, 128f);
component.targetTexture = RenderTexture.GetTemporary((int)((Rect)(ref val5)).width, (int)((Rect)(ref val5)).height);
component.fieldOfView = 20f;
float num = (Mathf.Max(val4.x, val4.y) + 0.1f) / Mathf.Tan(component.fieldOfView * ((float)Math.PI / 180f)) * 1.1f;
((Component)component).transform.position = new Vector3(10000f, 10000f, 10000f) + new Vector3(0f, 0f, num);
component.Render();
RenderTexture active = RenderTexture.active;
RenderTexture.active = component.targetTexture;
Texture2D val6 = new Texture2D((int)((Rect)(ref val5)).width, (int)((Rect)(ref val5)).height, (TextureFormat)4, false);
val6.ReadPixels(new Rect(0f, 0f, (float)(int)((Rect)(ref val5)).width, (float)(int)((Rect)(ref val5)).height), 0, 0);
val6.Apply();
RenderTexture.active = active;
prefab.GetComponent<Piece>().m_icon = Sprite.Create(val6, new Rect(0f, 0f, (float)(int)((Rect)(ref val5)).width, (float)(int)((Rect)(ref val5)).height), Vector2.one / 2f);
((Component)component2).gameObject.SetActive(false);
component.targetTexture.Release();
((Component)component).gameObject.SetActive(false);
val.SetActive(false);
Object.DestroyImmediate((Object)(object)val);
Object.Destroy((Object)(object)component);
Object.Destroy((Object)(object)component2);
Object.Destroy((Object)(object)((Component)component).gameObject);
Object.Destroy((Object)(object)((Component)component2).gameObject);
}
}
private static void DrawConfigTable(ConfigEntryBase cfg)
{
//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_011d: Expected O, but got Unknown
//IL_0146: Unknown result type (might be due to invalid IL or missing references)
//IL_014b: Unknown result type (might be due to invalid IL or missing references)
//IL_016c: Expected O, but got Unknown
//IL_01b2: Unknown result type (might be due to invalid IL or missing references)
//IL_01b7: Unknown result type (might be due to invalid IL or missing references)
//IL_01cc: Expected O, but got Unknown
//IL_01ed: Unknown result type (might be due to invalid IL or missing references)
//IL_01f2: Unknown result type (might be due to invalid IL or missing references)
//IL_0207: Expected O, but got Unknown
//IL_024a: Unknown result type (might be due to invalid IL or missing references)
//IL_024f: Unknown result type (might be due to invalid IL or missing references)
//IL_0264: Expected O, but got Unknown
bool valueOrDefault = cfg.Description.Tags.Select((object a) => (!(a.GetType().Name == "ConfigurationManagerAttributes")) ? null : ((bool?)a.GetType().GetField("ReadOnly")?.GetValue(a))).FirstOrDefault((bool? v) => v.HasValue).GetValueOrDefault();
List<Requirement> list = new List<Requirement>();
bool flag = false;
int num = (int)(configManager?.GetType().GetProperty("RightColumnWidth", BindingFlags.Instance | BindingFlags.NonPublic).GetGetMethod(nonPublic: true)
.Invoke(configManager, Array.Empty<object>()) ?? ((object)130));
GUILayout.BeginVertical(Array.Empty<GUILayoutOption>());
foreach (Requirement req in new SerializedRequirements((string)cfg.BoxedValue).Reqs)
{
GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
int num2 = req.amount;
if (int.TryParse(GUILayout.TextField(num2.ToString(), new GUIStyle(GUI.skin.textField)
{
fixedWidth = 40f
}, Array.Empty<GUILayoutOption>()), out var result) && result != num2 && !valueOrDefault)
{
num2 = result;
flag = true;
}
string text = GUILayout.TextField(req.itemName, new GUIStyle(GUI.skin.textField)
{
fixedWidth = num - 40 - 67 - 21 - 21 - 12
}, Array.Empty<GUILayoutOption>());
string text2 = (valueOrDefault ? req.itemName : text);
flag = flag || text2 != req.itemName;
bool flag2 = req.recover;
if (GUILayout.Toggle(req.recover, "Recover", new GUIStyle(GUI.skin.toggle)
{
fixedWidth = 67f
}, Array.Empty<GUILayoutOption>()) != req.recover)
{
flag2 = !flag2;
flag = true;
}
if (GUILayout.Button("x", new GUIStyle(GUI.skin.button)
{
fixedWidth = 21f
}, Array.Empty<GUILayoutOption>()) && !valueOrDefault)
{
flag = true;
}
else
{
list.Add(new Requirement
{
amount = num2,
itemName = text2,
recover = flag2
});
}
if (GUILayout.Button("+", new GUIStyle(GUI.skin.button)
{
fixedWidth = 21f
}, Array.Empty<GUILayoutOption>()) && !valueOrDefault)
{
flag = true;
list.Add(new Requirement
{
amount = 1,
itemName = "",
recover = false
});
}
GUILayout.EndHorizontal();
}
GUILayout.EndVertical();
if (flag)
{
cfg.BoxedValue = new SerializedRequirements(list).ToString();
}
}
private static ConfigEntry<T> config<T>(string group, string name, T value, ConfigDescription description)
{
ConfigEntry<T> val = plugin.Config.Bind<T>(group, name, value, description);
configSync?.GetType().GetMethod("AddConfigEntry").MakeGenericMethod(typeof(T))
.Invoke(configSync, new object[1] { val });
return val;
}
private static ConfigEntry<T> config<T>(string group, string name, T value, string description)
{
//IL_000a: Unknown result type (might be due to invalid IL or missing references)
//IL_0014: Expected O, but got Unknown
return config(group, name, value, new ConfigDescription(description, (AcceptableValueBase)null, Array.Empty<object>()));
}
}
internal static class GoExtensions
{
public static T GetOrAddComponent<T>(this GameObject gameObject) where T : Component
{
return gameObject.GetComponent<T>() ?? gameObject.AddComponent<T>();
}
}
[PublicAPI]
internal class LocalizeKey
{
private static readonly List<LocalizeKey> keys = new List<LocalizeKey>();
public readonly string Key;
public readonly Dictionary<string, string> Localizations = new Dictionary<string, string>();
public LocalizeKey(string key)
{
Key = key.Replace("$", "");
}
public void Alias(string alias)
{
Localizations.Clear();
if (!alias.Contains("$"))
{
alias = "$" + alias;
}
Localizations["alias"] = alias;
Localization.instance.AddWord(Key, Localization.instance.Localize(alias));
}
public LocalizeKey English(string key)
{
return addForLang("English", key);
}
public LocalizeKey Swedish(string key)
{
return addForLang("Swedish", key);
}
public LocalizeKey French(string key)
{
return addForLang("French", key);
}
public LocalizeKey Italian(string key)
{
return addForLang("Italian", key);
}
public LocalizeKey German(string key)
{
return addForLang("German", key);
}
public LocalizeKey Spanish(string key)
{
return addForLang("Spanish", key);
}
public LocalizeKey Russian(string key)
{
return addForLang("Russian", key);
}
public LocalizeKey Romanian(string key)
{
return addForLang("Romanian", key);
}
public LocalizeKey Bulgarian(string key)
{
return addForLang("Bulgarian", key);
}
public LocalizeKey Macedonian(string key)
{
return addForLang("Macedonian", key);
}
public LocalizeKey Finnish(string key)
{
return addForLang("Finnish", key);
}
public LocalizeKey Danish(string key)
{
return addForLang("Danish", key);
}
public LocalizeKey Norwegian(string key)
{
return addForLang("Norwegian", key);
}
public LocalizeKey Icelandic(string key)
{
return addForLang("Icelandic", key);
}
public LocalizeKey Turkish(string key)
{
return addForLang("Turkish", key);
}
public LocalizeKey Lithuanian(string key)
{
return addForLang("Lithuanian", key);
}
public LocalizeKey Czech(string key)
{
return addForLang("Czech", key);
}
public LocalizeKey Hungarian(string key)
{
return addForLang("Hungarian", key);
}
public LocalizeKey Slovak(string key)
{
return addForLang("Slovak", key);
}
public LocalizeKey Polish(string key)
{
return addForLang("Polish", key);
}
public LocalizeKey Dutch(string key)
{
return addForLang("Dutch", key);
}
public LocalizeKey Portuguese_European(string key)
{
return addForLang("Portuguese_European", key);
}
public LocalizeKey Portuguese_Brazilian(string key)
{
return addForLang("Portuguese_Brazilian", key);
}
public LocalizeKey Chinese(string key)
{
return addForLang("Chinese", key);
}
public LocalizeKey Japanese(string key)
{
return addForLang("Japanese", key);
}
public LocalizeKey Korean(string key)
{
return addForLang("Korean", key);
}
public LocalizeKey Hindi(string key)
{
return addForLang("Hindi", key);
}
public LocalizeKey Thai(string key)
{
return addForLang("Thai", key);
}
public LocalizeKey Abenaki(string key)
{
return addForLang("Abenaki", key);
}
public LocalizeKey Croatian(string key)
{
return addForLang("Croatian", key);
}
public LocalizeKey Georgian(string key)
{
return addForLang("Georgian", key);
}
public LocalizeKey Greek(string key)
{
return addForLang("Greek", key);
}
public LocalizeKey Serbian(string key)
{
return addForLang("Serbian", key);
}
public LocalizeKey Ukrainian(string key)
{
return addForLang("Ukrainian", key);
}
private LocalizeKey addForLang(string lang, string value)
{
Localizations[lang] = value;
if (Localization.instance.GetSelectedLanguage() == lang)
{
Localization.instance.AddWord(Key, value);
}
else if (lang == "English" && !Localization.instance.m_translations.ContainsKey(Key))
{
Localization.instance.AddWord(Key, value);
}
return this;
}
[HarmonyPriority(300)]
internal static void AddLocalizedKeys(Localization __instance, string language)
{
foreach (LocalizeKey key in keys)
{
string value2;
if (key.Localizations.TryGetValue(language, out string value) || key.Localizations.TryGetValue("English", out value))
{
__instance.AddWord(key.Key, value);
}
else if (key.Localizations.TryGetValue("alias", out value2))
{
Localization.instance.AddWord(key.Key, Localization.instance.Localize(value2));
}
}
}
}
internal static class LocalizationCache
{
private static readonly Dictionary<string, Localization> localizations = new Dictionary<string, Localization>();
internal static void LocalizationPostfix(Localization __instance, string language)
{
Localization __instance2 = __instance;
string key = localizations.FirstOrDefault<KeyValuePair<string, Localization>>((KeyValuePair<string, Localization> l) => l.Value == __instance2).Key;
if (key != null)
{
localizations.Remove(key);
}
if (!localizations.ContainsKey(language))
{
localizations.Add(language, __instance2);
}
}
public static Localization ForLanguage(string? language = null)
{
//IL_0024: Unknown result type (might be due to invalid IL or missing references)
//IL_002a: Expected O, but got Unknown
if (localizations.TryGetValue(language ?? PlayerPrefs.GetString("language", "English"), out Localization value))
{
return value;
}
value = new Localization();
if (language != null)
{
value.SetupLanguage(language);
}
return value;
}
}
internal class AdminSyncing
{
private static bool isServer;
internal static bool registeredOnClient;
[HarmonyPriority(700)]
internal static void AdminStatusSync(ZNet __instance)
{
isServer = __instance.IsServer();
if (BuildPiece._plugin != null)
{
if (isServer)
{
ZRoutedRpc instance = ZRoutedRpc.instance;
BaseUnityPlugin? plugin = BuildPiece._plugin;
instance.Register<ZPackage>(((plugin != null) ? plugin.Info.Metadata.Name : null) + " PMAdminStatusSync", (Action<long, ZPackage>)RPC_AdminPieceAddRemove);
}
else if (!registeredOnClient)
{
ZRoutedRpc instance2 = ZRoutedRpc.instance;
BaseUnityPlugin? plugin2 = BuildPiece._plugin;
instance2.Register<ZPackage>(((plugin2 != null) ? plugin2.Info.Metadata.Name : null) + " PMAdminStatusSync", (Action<long, ZPackage>)RPC_AdminPieceAddRemove);
registeredOnClient = true;
}
}
if (isServer)
{
((MonoBehaviour)ZNet.instance).StartCoroutine(WatchAdminListChanges());
}
static void SendAdmin(List<ZNetPeer> peers, bool isAdmin)
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
//IL_0006: Expected O, but got Unknown
ZPackage val = new ZPackage();
val.Write(isAdmin);
((MonoBehaviour)ZNet.instance).StartCoroutine(sendZPackage(peers, val));
}
static IEnumerator WatchAdminListChanges()
{
List<string> currentList = new List<string>(ZNet.instance.m_adminList.GetList());
while (true)
{
yield return (object)new WaitForSeconds(30f);
if (!ZNet.instance.m_adminList.GetList().SequenceEqual(currentList))
{
currentList = new List<string>(ZNet.instance.m_adminList.GetList());
List<ZNetPeer> list = (from p in ZNet.instance.GetPeers()
where ZNet.instance.ListContainsId(ZNet.instance.m_adminList, p.m_rpc.GetSocket().GetHostName())
select p).ToList();
SendAdmin(ZNet.instance.GetPeers().Except(list).ToList(), isAdmin: false);
SendAdmin(list, isAdmin: true);
}
}
}
}
private static IEnumerator sendZPackage(List<ZNetPeer> peers, ZPackage package)
{
ZPackage package2 = package;
if (!Object.op_Implicit((Object)(object)ZNet.instance))
{
yield break;
}
byte[] array = package2.GetArray();
if (array != null && array.LongLength > 10000)
{
ZPackage val = new ZPackage();
val.Write(4);
MemoryStream memoryStream = new MemoryStream();
using (DeflateStream deflateStream = new DeflateStream(memoryStream, CompressionLevel.Optimal))
{
deflateStream.Write(array, 0, array.Length);
}
val.Write(memoryStream.ToArray());
package2 = val;
}
List<IEnumerator<bool>> writers = (from peer in peers
where peer.IsReady()
select peer into p
select TellPeerAdminStatus(p, package2)).ToList();
writers.RemoveAll((IEnumerator<bool> writer) => !writer.MoveNext());
while (writers.Count > 0)
{
yield return null;
writers.RemoveAll((IEnumerator<bool> writer) => !writer.MoveNext());
}
}
private static IEnumerator<bool> TellPeerAdminStatus(ZNetPeer peer, ZPackage package)
{
ZNetPeer peer2 = peer;
ZRoutedRpc rpc = ZRoutedRpc.instance;
if (rpc != null)
{
SendPackage(package);
}
void SendPackage(ZPackage pkg)
{
BaseUnityPlugin? plugin = BuildPiece._plugin;
string text = ((plugin != null) ? plugin.Info.Metadata.Name : null) + " PMAdminStatusSync";
if (isServer)
{
peer2.m_rpc.Invoke(text, new object[1] { pkg });
}
else
{
rpc.InvokeRoutedRPC(peer2.m_server ? 0 : peer2.m_uid, text, new object[1] { pkg });
}
}
yield break;
}
internal static void RPC_AdminPieceAddRemove(long sender, ZPackage package)
{
//IL_005b: Unknown result type (might be due to invalid IL or missing references)
//IL_0061: Expected O, but got Unknown
//IL_008f: Unknown result type (might be due to invalid IL or missing references)
//IL_0095: Expected O, but got Unknown
ZNetPeer peer = ZNet.instance.GetPeer(sender);
bool flag = false;
try
{
flag = package.ReadBool();
}
catch
{
}
if (isServer)
{
ZRoutedRpc instance = ZRoutedRpc.instance;
long everybody = ZRoutedRpc.Everybody;
BaseUnityPlugin? plugin = BuildPiece._plugin;
instance.InvokeRoutedRPC(everybody, ((plugin != null) ? plugin.Info.Metadata.Name : null) + " PMAdminStatusSync", new object[1] { (object)new ZPackage() });
if (ZNet.instance.ListContainsId(ZNet.instance.m_adminList, peer.m_rpc.GetSocket().GetHostName()))
{
ZPackage val = new ZPackage();
val.Write(true);
ZRpc rpc = peer.m_rpc;
BaseUnityPlugin? plugin2 = BuildPiece._plugin;
rpc.Invoke(((plugin2 != null) ? plugin2.Info.Metadata.Name : null) + " PMAdminStatusSync", new object[1] { val });
}
return;
}
foreach (BuildPiece registeredPiece in BuildPiece.registeredPieces)
{
if (!registeredPiece.SpecialProperties.AdminOnly)
{
continue;
}
Piece component = registeredPiece.Prefab.GetComponent<Piece>();
string name = component.m_name;
Localization.instance.Localize(name).Trim();
if (!Object.op_Implicit((Object)(object)ObjectDB.instance) || (Object)(object)ObjectDB.instance.GetItemPrefab("Wood") == (Object)null)
{
continue;
}
Piece[] array = Object.FindObjectsOfType<Piece>();
foreach (Piece val2 in array)
{
if (flag)
{
if (val2.m_name == name)
{
val2.m_enabled = true;
}
}
else if (val2.m_name == name)
{
val2.m_enabled = false;
}
}
List<GameObject> pieces = ObjectDB.instance.GetItemPrefab("Hammer").GetComponent<ItemDrop>().m_itemData.m_shared.m_buildPieces.m_pieces;
if (flag)
{
if (!pieces.Contains(ZNetScene.instance.GetPrefab(((Object)component).name)))
{
pieces.Add(ZNetScene.instance.GetPrefab(((Object)component).name));
}
}
else if (pieces.Contains(ZNetScene.instance.GetPrefab(((Object)component).name)))
{
pieces.Remove(ZNetScene.instance.GetPrefab(((Object)component).name));
}
}
}
}
[HarmonyPatch(typeof(ZNet), "OnNewConnection")]
internal class RegisterClientRPCPatch
{
private static void Postfix(ZNet __instance, ZNetPeer peer)
{
//IL_0045: Unknown result type (might be due to invalid IL or missing references)
//IL_004b: Expected O, but got Unknown
if (!__instance.IsServer())
{
ZRpc rpc = peer.m_rpc;
BaseUnityPlugin? plugin = BuildPiece._plugin;
rpc.Register<ZPackage>(((plugin != null) ? plugin.Info.Metadata.Name : null) + " PMAdminStatusSync", (Action<ZRpc, ZPackage>)RPC_InitialAdminSync);
return;
}
ZPackage val = new ZPackage();
val.Write(__instance.ListContainsId(__instance.m_adminList, peer.m_rpc.GetSocket().GetHostName()));
ZRpc rpc2 = peer.m_rpc;
BaseUnityPlugin? plugin2 = BuildPiece._plugin;
rpc2.Invoke(((plugin2 != null) ? plugin2.Info.Metadata.Name : null) + " PMAdminStatusSync", new object[1] { val });
}
private static void RPC_InitialAdminSync(ZRpc rpc, ZPackage package)
{
AdminSyncing.RPC_AdminPieceAddRemove(0L, package);
}
}
internal static class PiecePrefabManager
{
private struct BundleId
{
[UsedImplicitly]
public string assetBundleFileName;
[UsedImplicitly]
public string folderName;
}
private static readonly Dictionary<BundleId, AssetBundle> bundleCache;
private static readonly List<GameObject> piecePrefabs;
private static readonly Dictionary<GameObject, string> customPiecePrefabs;
private static readonly List<GameObject> ZnetOnlyPrefabs;
static PiecePrefabManager()
{
//IL_002d: Unknown result type (might be due to invalid IL or missing references)
//IL_0032: Unknown result type (might be due to invalid IL or missing references)
//IL_005f: Unknown result type (might be due to invalid IL or missing references)
//IL_006d: Expected O, but got Unknown
//IL_006e: Unknown result type (might be due to invalid IL or missing references)
//IL_009b: Unknown result type (might be due to invalid IL or missing references)
//IL_00a9: Expected O, but got Unknown
//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
//IL_00e5: Expected O, but got Unknown
//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
//IL_0114: Unknown result type (might be due to invalid IL or missing references)
//IL_0121: Expected O, but got Unknown
//IL_0122: Unknown result type (might be due to invalid IL or missing references)
//IL_0150: Unknown result type (might be due to invalid IL or missing references)
//IL_015d: Expected O, but got Unknown
//IL_015e: Unknown result type (might be due to invalid IL or missing references)
//IL_018c: Unknown result type (might be due to invalid IL or missing references)
//IL_0199: Expected O, but got Unknown
//IL_019a: Unknown result type (might be due to invalid IL or missing references)
//IL_01c8: Unknown result type (might be due to invalid IL or missing references)
//IL_01d5: Expected O, but got Unknown
//IL_01d6: Unknown result type (might be due to invalid IL or missing references)
//IL_0204: Unknown result type (might be due to invalid IL or missing references)
//IL_0211: Expected O, but got Unknown
//IL_023f: Unknown result type (might be due to invalid IL or missing references)
//IL_024c: Expected O, but got Unknown
bundleCache = new Dictionary<BundleId, AssetBundle>();
piecePrefabs = new List<GameObject>();
customPiecePrefabs = new Dictionary<GameObject, string>();
ZnetOnlyPrefabs = new List<GameObject>();
Harmony val = new Harmony("org.bepinex.helpers.PieceManager");
val.Patch((MethodBase)AccessTools.DeclaredMethod(typeof(FejdStartup), "Awake", (Type[])null, (Type[])null), new HarmonyMethod(AccessTools.DeclaredMethod(typeof(BuildPiece), "Patch_FejdStartup", (Type[])null, (Type[])null)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
val.Patch((MethodBase)AccessTools.DeclaredMethod(typeof(ZNetScene), "Awake", (Type[])null, (Type[])null), new HarmonyMethod(AccessTools.DeclaredMethod(typeof(PiecePrefabManager), "Patch_ZNetSceneAwake", (Type[])null, (Type[])null)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
val.Patch((MethodBase)AccessTools.DeclaredMethod(typeof(ZNetScene), "Awake", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(AccessTools.DeclaredMethod(typeof(PiecePrefabManager), "RefFixPatch_ZNetSceneAwake", (Type[])null, (Type[])null)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
val.Patch((MethodBase)AccessTools.DeclaredMethod(typeof(ZNet), "Awake", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(AccessTools.DeclaredMethod(typeof(AdminSyncing), "AdminStatusSync", (Type[])null, (Type[])null)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
val.Patch((MethodBase)AccessTools.DeclaredMethod(typeof(ObjectDB), "Awake", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(AccessTools.DeclaredMethod(typeof(PiecePrefabManager), "Patch_ObjectDBInit", (Type[])null, (Type[])null)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
val.Patch((MethodBase)AccessTools.DeclaredMethod(typeof(ObjectDB), "CopyOtherDB", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(AccessTools.DeclaredMethod(typeof(PiecePrefabManager), "Patch_ObjectDBInit", (Type[])null, (Type[])null)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
val.Patch((MethodBase)AccessTools.DeclaredMethod(typeof(ObjectDB), "Awake", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(AccessTools.DeclaredMethod(typeof(BuildPiece), "Patch_ObjectDBInit", (Type[])null, (Type[])null)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
val.Patch((MethodBase)AccessTools.DeclaredMethod(typeof(Localization), "SetupLanguage", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(AccessTools.DeclaredMethod(typeof(LocalizationCache), "LocalizationPostfix", (Type[])null, (Type[])null)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
val.Patch((MethodBase)AccessTools.DeclaredMethod(typeof(Localization), "LoadCSV", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(AccessTools.DeclaredMethod(typeof(LocalizeKey), "AddLocalizedKeys", (Type[])null, (Type[])null)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
}
public static AssetBundle RegisterAssetBundle(string assetBundleFileName, string folderName = "assets")
{
string assetBundleFileName2 = assetBundleFileName;
BundleId bundleId = default(BundleId);
bundleId.assetBundleFileName = assetBundleFileName2;
bundleId.folderName = folderName;
BundleId key = bundleId;
if (!bundleCache.TryGetValue(key, out AssetBundle value))
{
Dictionary<BundleId, AssetBundle> dictionary = bundleCache;
AssetBundle? obj = ((IEnumerable<AssetBundle>)Resources.FindObjectsOfTypeAll<AssetBundle>()).FirstOrDefault((Func<AssetBundle, bool>)((AssetBundle a) => ((Object)a).name == assetBundleFileName2)) ?? AssetBundle.LoadFromStream(Assembly.GetExecutingAssembly().GetManifestResourceStream(Assembly.GetExecutingAssembly().GetName().Name + "." + folderName + "." + assetBundleFileName2));
AssetBundle result = obj;
dictionary[key] = obj;
return result;
}
return value;
}
public static IEnumerable<GameObject> FixRefs(AssetBundle assetBundle)
{
return assetBundle.LoadAllAssets<GameObject>();
}
public static GameObject RegisterPrefab(string assetBundleFileName, string prefabName, string folderName = "assets")
{
return RegisterPrefab(RegisterAssetBundle(assetBundleFileName, folderName), prefabName);
}
public static GameObject RegisterPrefab(AssetBundle assets, string prefabName, bool addToPieceTable = false, bool addToCustomPieceTable = false, string customPieceTable = "")
{
GameObject val = assets.LoadAsset<GameObject>(prefabName);
foreach (GameObject item in FixRefs(assets))
{
MaterialReplacer.RegisterGameObjectForShaderSwap(item, MaterialReplacer.ShaderType.UseUnityShader);
}
if (addToPieceTable)
{
piecePrefabs.Add(val);
}
else if (addToCustomPieceTable)
{
customPiecePrefabs.Add(val, customPieceTable);
}
else
{
ZnetOnlyPrefabs.Add(val);
}
return val;
}
public static Sprite RegisterSprite(string assetBundleFileName, string prefabName, string folderName = "assets")
{
return RegisterSprite(RegisterAssetBundle(assetBundleFileName, folderName), prefabName);
}
public static Sprite RegisterSprite(AssetBundle assets, string prefabName)
{
return assets.LoadAsset<Sprite>(prefabName);
}
[HarmonyPriority(700)]
private static void Patch_ZNetSceneAwake(ZNetScene __instance)
{
foreach (GameObject item in piecePrefabs.Concat(ZnetOnlyPrefabs).Concat(customPiecePrefabs.Keys))
{
if (!__instance.m_prefabs.Contains(item))
{
__instance.m_prefabs.Add(item);
}
}
}
[HarmonyPriority(700)]
private static void RefFixPatch_ZNetSceneAwake(ZNetScene __instance)
{
//IL_008a: Unknown result type (might be due to invalid IL or missing references)
//IL_008f: Unknown result type (might be due to invalid IL or missing references)
foreach (GameObject item in piecePrefabs.Concat(ZnetOnlyPrefabs).Concat(customPiecePrefabs.Keys))
{
if (__instance.m_prefabs.Contains(item) && Object.op_Implicit((Object)(object)item.GetComponent<StationExtension>()))
{
item.GetComponent<Piece>().m_isUpgrade = true;
item.GetComponent<StationExtension>().m_connectionPrefab = __instance.GetPrefab("piece_workbench_ext3").GetComponent<StationExtension>().m_connectionPrefab;
item.GetComponent<StationExtension>().m_connectionOffset = __instance.GetPrefab("piece_workbench_ext3").GetComponent<StationExtension>().m_connectionOffset;
}
}
}
[HarmonyPriority(700)]
private static void Patch_ObjectDBInit(ObjectDB __instance)
{
GameObject itemPrefab = __instance.GetItemPrefab("Hammer");
PieceTable val = ((itemPrefab != null) ? itemPrefab.GetComponent<ItemDrop>().m_itemData.m_shared.m_buildPieces : null);
if (val == null)
{
return;
}
foreach (KeyValuePair<GameObject, string> customPiecePrefab in customPiecePrefabs)
{
GameObject itemPrefab2 = __instance.GetItemPrefab(customPiecePrefab.Value);
PieceTable val2 = ((itemPrefab2 != null) ? itemPrefab2.GetComponent<ItemDrop>().m_itemData.m_shared.m_buildPieces : null);
if (val2 != null && !val2.m_pieces.Contains(customPiecePrefab.Key))
{
val2.m_pieces.Add(customPiecePrefab.Key);
}
}
foreach (GameObject piecePrefab in piecePrefabs)
{
if (val.m_pieces.Contains(piecePrefab))
{
break;
}
val.m_pieces.Add(piecePrefab);
}
}
}
[PublicAPI]
internal class SnapPointMaker
{
private static List<GameObject> _objectsToApplySnaps;
static SnapPointMaker()
{
_objectsToApplySnaps = new List<GameObject>();
}
public static void AddObjectForSnapPoints(GameObject obj)
{
_objectsToApplySnaps.Add(obj);
}
public static void ApplySnapPoints()
{
foreach (GameObject objectsToApplySnap in _objectsToApplySnaps)
{
GrabVerticesAssignSnaps(objectsToApplySnap);
}
}
private static void GrabVerticesAssignSnaps(GameObject obj)
{
Vector3[] colliderVertexPosRotated = GetColliderVertexPosRotated(obj);
AttachSnapPoints(obj, colliderVertexPosRotated);
}
private static Vector3[] GetColliderVertexPosRotated(GameObject obj)
{
//IL_0021: Unknown result type (might be due to invalid IL or missing references)
//IL_0027: Unknown result type (might be due to invalid IL or missing references)
//IL_0031: 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)
//IL_003d: Unknown result type (might be due to invalid IL or missing references)
//IL_0043: 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_0052: Unknown result type (might be due to invalid IL or missing references)
//IL_0057: Unknown result type (might be due to invalid IL or missing references)
//IL_005c: Unknown result type (might be due to invalid IL or missing references)
//IL_0062: Unknown result type (might be due to invalid IL or missing references)
//IL_0068: 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)
//IL_0073: 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_0086: Unknown result type (might be due to invalid IL or missing references)
//IL_008c: Unknown result type (might be due to invalid IL or missing references)
//IL_0093: Unknown result type (might be due to invalid IL or missing references)
//IL_0098: Unknown result type (might be due to invalid IL or missing references)
//IL_009d: Unknown result type (might be due to invalid IL or missing references)
//IL_00a5: 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_00b2: Unknown result type (might be due to invalid IL or missing references)
//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
//IL_00de: Unknown result type (might be due to invalid IL or missing references)
//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
//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_010d: Unknown result type (might be due to invalid IL or missing references)
//IL_0115: Unknown result type (might be due to invalid IL or missing references)
//IL_011c: Unknown result type (might be due to invalid IL or missing references)
//IL_0122: 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_012e: Unknown result type (might be due to invalid IL or missing references)
//IL_0133: Unknown result type (might be due to invalid IL or missing references)
//IL_013b: Unknown result type (might be due to invalid IL or missing references)
//IL_0142: Unknown result type (might be due to invalid IL or missing references)
//IL_0149: Unknown result type (might be due to invalid IL or missing references)
//IL_014f: Unknown result type (might be due to invalid IL or missing references)
//IL_0154: Unknown result type (might be due to invalid IL or missing references)
//IL_0159: Unknown result type (might be due to invalid IL or missing references)
//IL_0161: Unknown result type (might be due to invalid IL or missing references)
//IL_0168: Unknown result type (might be due to invalid IL or missing references)
//IL_016f: Unknown result type (might be due to invalid IL or missing references)
//IL_0176: Unknown result type (might be due to invalid IL or missing references)
//IL_017b: Unknown result type (might be due to invalid IL or missing references)
//IL_0180: Unknown result type (might be due to invalid IL or missing references)
Vector3[] array = (Vector3[])(object)new Vector3[8];
BoxCollider componentInChildren = obj.GetComponentInChildren<BoxCollider>();
if ((Object)(object)componentInChildren == (Object)null)
{
return array;
}
Transform transform = obj.transform;
Vector3 val = componentInChildren.center - componentInChildren.size * 0.5f;
Vector3 val2 = componentInChildren.center + componentInChildren.size * 0.5f;
array[0] = transform.TransformPoint(new Vector3(val.x, val.y, val.z));
array[1] = transform.TransformPoint(new Vector3(val.x, val.y, val2.z));
array[2] = transform.TransformPoint(new Vector3(val.x, val2.y, val.z));
array[3] = transform.TransformPoint(new Vector3(val.x, val2.y, val2.z));
array[4] = transform.TransformPoint(new Vector3(val2.x, val.y, val.z));
array[5] = transform.TransformPoint(new Vector3(val2.x, val.y, val2.z));
array[6] = transform.TransformPoint(new Vector3(val2.x, val2.y, val.z));
array[7] = transform.TransformPoint(new Vector3(val2.x, val2.y, val2.z));
return array;
}
private static void AttachSnapPoints(GameObject objecttosnap, Vector3[] vector3S)
{
//IL_0008: Unknown result type (might be due to invalid IL or missing references)
//IL_000d: 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)
//IL_0013: Unknown result type (might be due to invalid IL or missing references)
//IL_001e: Unknown result type (might be due to invalid IL or missing references)
//IL_0029: Unknown result type (might be due to invalid IL or missing references)
//IL_0031: Unknown result type (might be due to invalid IL or missing references)
//IL_0032: Unknown result type (might be due to invalid IL or missing references)
//IL_0042: Expected O, but got Unknown
foreach (Vector3 val in vector3S)
{
Object.Instantiate<GameObject>(new GameObject
{
name = "_snappoint",
tag = "snappoint",
layer = 10
}, val, Quaternion.identity, objecttosnap.transform).SetActive(false);
}
}
}
}