using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using UnityEngine;
using UnityEngine.Rendering;
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: CompilationRelaxations(8)]
[assembly: AssemblyVersion("0.0.0.0")]
[BepInPlugin("brokenruune.coolerplatearmors", "Cooler Plate Armors", "1.0.0")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public sealed class CoolerPlateArmors : BaseUnityPlugin
{
private static readonly HashSet<int> Swaps = new HashSet<int>();
internal static bool Enabled(int id)
{
return Swaps.Contains(id);
}
private void Awake()
{
Bind("Plate", "Armor", 3100003);
Bind("Plate", "Helmet", 3100004);
Bind("Plate", "Boots", 3100005);
Bind("Half Plate", "Armor", 3100006);
Bind("Half Plate", "Helmet", 3100007);
Bind("Half Plate", "Boots", 3100008);
Bind("Elite Knight Plate", "Armor", 3100000);
Bind("Elite Knight Plate", "Helmet", 3100001);
Bind("Elite Knight Plate", "Boots", 3100002);
Bind("Old Legion", "Gladius", 2000090);
Bind("Old Legion", "Shield", 2300070);
if (Enabled(3100003) || Enabled(3100005))
{
WeatheredStandardPlate.Initialize(((BaseUnityPlugin)this).Logger);
}
if (Enabled(3100004))
{
SuttonHooHelmet.Initialize(((BaseUnityPlugin)this).Logger);
}
if (Enabled(3100006) || Enabled(3100007) || Enabled(3100008))
{
WeatheredHalfplate.Initialize(((BaseUnityPlugin)this).Logger);
}
if (Enabled(3100000) || Enabled(3100001) || Enabled(3100002))
{
EliteAutumnReskin.Initialize(((BaseUnityPlugin)this).Logger);
}
if (Enabled(2000090) || Enabled(2300070))
{
OldLegionGearReskin.Initialize(((BaseUnityPlugin)this).Logger);
}
}
private void Bind(string section, string name, int id)
{
if (((BaseUnityPlugin)this).Config.Bind<bool>(section, name, true, "Set to false for the vanilla appearance. Restart Outward after changing.").Value)
{
Swaps.Add(id);
}
}
}
internal static class WeatheredStandardPlate
{
private const string StockMaterial = "mat_cha_plateArmorPlain";
private const int OriginalIndexCount = 27366;
private const int SlenderIndexCount = 25098;
private static readonly Dictionary<Material, Material> Materials = new Dictionary<Material, Material>();
private static Texture2D albedo;
private static Texture2D surface;
private static Texture2D normal;
private static readonly Dictionary<Mesh, Mesh> SlenderMeshes = new Dictionary<Mesh, Mesh>();
private static int[] originalIndices;
private static int[] slenderIndices;
private static Harmony harmony;
internal static void Initialize(ManualLogSource logger)
{
//IL_008e: Unknown result type (might be due to invalid IL or missing references)
//IL_0098: Expected O, but got Unknown
//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
//IL_00d1: Expected O, but got Unknown
//IL_0102: Unknown result type (might be due to invalid IL or missing references)
//IL_0108: Expected O, but got Unknown
albedo = ReadTexture("WeatheredPlateAlbedo", linear: false);
surface = ReadTexture("WeatheredPlateSurface", linear: true);
normal = ReadTexture("WeatheredPlateNormal", linear: true);
using (Stream input = typeof(WeatheredStandardPlate).Assembly.GetManifestResourceStream("WeatheredStandardPlate.SlenderBodyIndices"))
{
using BinaryReader reader = new BinaryReader(input);
originalIndices = ReadIndices(reader, 27366);
slenderIndices = ReadIndices(reader, 25098);
}
harmony = new Harmony("brokenruune.weatheredstandardplate");
harmony.Patch((MethodBase)AccessTools.Method(typeof(ItemVisual), "Awake", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(typeof(WeatheredStandardPlate), "RecolorVisual", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
Harmony obj = harmony;
MethodInfo methodInfo = AccessTools.Method(typeof(VisualSlot), "PositionVisuals", Type.EmptyTypes, (Type[])null);
HarmonyMethod val = new HarmonyMethod(typeof(WeatheredStandardPlate), "AfterEquip", (Type[])null);
val.priority = 0;
obj.Patch((MethodBase)methodInfo, (HarmonyMethod)null, val, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
logger.LogInfo((object)"Weathered standard Plate Armor and Boots enabled.");
}
internal static void Shutdown()
{
if (harmony != null)
{
harmony.UnpatchSelf();
}
}
private static Texture2D ReadTexture(string resource, bool linear)
{
//IL_0005: Unknown result type (might be due to invalid IL or missing references)
//IL_000b: Expected O, but got Unknown
Texture2D val = new Texture2D(2, 2, (TextureFormat)4, true, linear);
((Object)val).name = resource;
((Texture)val).anisoLevel = 4;
Texture2D val2 = val;
using Stream stream = typeof(WeatheredStandardPlate).Assembly.GetManifestResourceStream("WeatheredStandardPlate." + resource);
using MemoryStream memoryStream = new MemoryStream();
stream.CopyTo(memoryStream);
if (!ImageConversion.LoadImage(val2, memoryStream.ToArray(), true))
{
throw new InvalidDataException(resource);
}
return val2;
}
private static int[] ReadIndices(BinaryReader reader, int count)
{
int[] array = new int[count];
for (int i = 0; i < array.Length; i++)
{
array[i] = reader.ReadInt32();
}
return array;
}
private static void SlimEquippedBody(SkinnedMeshRenderer renderer)
{
Mesh sharedMesh = renderer.sharedMesh;
if (!Object.op_Implicit((Object)(object)sharedMesh) || ((Object)sharedMesh).name != "mdl_cha_plateArmorPlainBody")
{
return;
}
if (!SlenderMeshes.TryGetValue(sharedMesh, out var value))
{
if (!sharedMesh.isReadable || sharedMesh.vertexCount != 7027 || sharedMesh.subMeshCount != 1 || sharedMesh.GetIndexCount(0) != 27366)
{
return;
}
int[] triangles = sharedMesh.GetTriangles(0);
if (triangles.Length != originalIndices.Length)
{
return;
}
for (int i = 0; i < triangles.Length; i++)
{
if (triangles[i] != originalIndices[i])
{
return;
}
}
value = Object.Instantiate<Mesh>(sharedMesh);
((Object)value).name = "Weathered Standard Plate Slender Body";
value.SetTriangles(slenderIndices, 0, false);
SlenderMeshes.Add(sharedMesh, value);
}
renderer.sharedMesh = value;
}
private static void AfterEquip(VisualSlot __instance)
{
if (Object.op_Implicit((Object)(object)__instance.CurrentVisual))
{
RecolorVisual(__instance.CurrentVisual);
}
}
private static void RecolorVisual(ItemVisual __instance)
{
//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
//IL_00bd: Expected O, but got Unknown
int itemIDFromName = __instance.GetItemIDFromName();
if ((itemIDFromName != 3100003 && itemIDFromName != 3100005) || !CoolerPlateArmors.Enabled(itemIDFromName))
{
return;
}
Renderer[] componentsInChildren = ((Component)__instance).GetComponentsInChildren<Renderer>(true);
foreach (Renderer val in componentsInChildren)
{
SkinnedMeshRenderer val2 = (SkinnedMeshRenderer)(object)((val is SkinnedMeshRenderer) ? val : null);
if (itemIDFromName == 3100003 && Object.op_Implicit((Object)(object)val2))
{
SlimEquippedBody(val2);
}
Material[] sharedMaterials = val.sharedMaterials;
bool flag = false;
for (int j = 0; j < sharedMaterials.Length; j++)
{
Material val3 = sharedMaterials[j];
if (!Object.op_Implicit((Object)(object)val3) || (((Object)val3).name != "mat_cha_plateArmorPlain" && ((Object)val3).name != "mat_cha_plateArmorPlain (Instance)"))
{
continue;
}
if (!Materials.TryGetValue(val3, out var value))
{
Material val4 = new Material(val3);
((Object)val4).name = "WeatheredStandardPlate";
value = val4;
value.SetTexture("_MainTex", (Texture)(object)albedo);
value.SetTexture("_GenTex", (Texture)(object)surface);
value.SetTexture("_NormTex", (Texture)(object)normal);
if (value.HasProperty("_EmissionTex"))
{
value.SetTexture("_EmissionTex", (Texture)(object)Texture2D.blackTexture);
}
value.DisableKeyword("_DETAIL");
value.DisableKeyword("_DETAIL_ALBEDO");
value.DisableKeyword("_DETAIL_TEXTURED");
value.EnableKeyword("_NORMALMAP");
value.EnableKeyword("_SPECGLOSSMAP");
value.SetFloat("_SpecBoost", 0.015f);
value.SetFloat("_GlossMin", 0.035f);
value.SetFloat("_SmoothMin", 0.035f);
Materials.Add(val3, value);
}
sharedMaterials[j] = value;
flag = true;
}
if (flag)
{
val.sharedMaterials = sharedMaterials;
}
}
}
}
internal static class WeatheredHalfplate
{
private enum Finish
{
Armor,
Sallet,
Cloth
}
private const int ArmorId = 3100006;
private const int HelmetId = 3100007;
private const int BootsId = 3100008;
private const int HeadBone = 18;
private const string DonorMaterial = "mat_cha_plateArmor";
private const string DonorHelmet = "mdl_cha_plateArmorLightHelm";
private static readonly Dictionary<Material, Material> PlateFinishes = new Dictionary<Material, Material>();
private static readonly Dictionary<Material, Material> HelmetFinishes = new Dictionary<Material, Material>();
private static readonly Dictionary<Mesh, Mesh> EquippedMeshes = new Dictionary<Mesh, Mesh>();
private static Texture2D plateAlbedo;
private static Texture2D plateSurface;
private static Texture2D plateNormal;
private static Texture2D salletAlbedo;
private static Texture2D salletSurface;
private static Texture2D salletNormal;
private static readonly Dictionary<Material, Material> ClothFinishes = new Dictionary<Material, Material>();
private static readonly Dictionary<Mesh, Mesh> CollarMeshes = new Dictionary<Mesh, Mesh>();
private static Texture2D clothAlbedo;
private static Texture2D clothSurface;
private static Texture2D clothNormal;
private static int[] originalCollarIndices;
private static int[] revisedCollarIndices;
private static Mesh dropped;
private static Bounds salletHeadBounds;
private static Harmony harmony;
internal static void Initialize(ManualLogSource logger)
{
//IL_0107: Unknown result type (might be due to invalid IL or missing references)
//IL_0111: Expected O, but got Unknown
//IL_013d: Unknown result type (might be due to invalid IL or missing references)
//IL_014a: Expected O, but got Unknown
//IL_017b: Unknown result type (might be due to invalid IL or missing references)
//IL_0181: Expected O, but got Unknown
//IL_01be: Unknown result type (might be due to invalid IL or missing references)
//IL_01c4: Expected O, but got Unknown
//IL_0201: Unknown result type (might be due to invalid IL or missing references)
//IL_020e: Expected O, but got Unknown
//IL_023b: Unknown result type (might be due to invalid IL or missing references)
//IL_0242: Expected O, but got Unknown
plateAlbedo = ReadTexture("PlateAlbedo", linear: false);
plateSurface = ReadTexture("PlateSurface", linear: true);
plateNormal = ReadTexture("PlateNormal", linear: true);
salletAlbedo = ReadTexture("SalletAlbedo", linear: false);
salletSurface = ReadTexture("SalletSurface", linear: true);
salletNormal = ReadTexture("SalletNormal", linear: true);
clothAlbedo = ReadTexture("ClothAlbedo", linear: false);
clothSurface = ReadTexture("ClothSurface", linear: true);
clothNormal = ReadTexture("ClothNormal", linear: true);
using (Stream stream = typeof(WeatheredHalfplate).Assembly.GetManifestResourceStream("WeatheredHalfplate.CollarIndices"))
{
using BinaryReader reader = new BinaryReader(stream);
originalCollarIndices = ReadIndices(reader, 19998);
revisedCollarIndices = ReadIndices(reader, 19374);
if (stream.Position != stream.Length)
{
throw new InvalidDataException("Unexpected Halfplate collar index data.");
}
}
harmony = new Harmony("brokenruune.weatheredhalfplate");
harmony.Patch((MethodBase)AccessTools.Method(typeof(ItemVisual), "Awake", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(typeof(WeatheredHalfplate), "ApplyVisual", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
Harmony obj = harmony;
MethodInfo methodInfo = AccessTools.Method(typeof(VisualSlot), "PositionVisuals", Type.EmptyTypes, (Type[])null);
HarmonyMethod val = new HarmonyMethod(typeof(WeatheredHalfplate), "AfterPosition", (Type[])null);
val.priority = 0;
obj.Patch((MethodBase)methodInfo, (HarmonyMethod)null, val, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
Harmony obj2 = harmony;
MethodInfo methodInfo2 = AccessTools.Method(typeof(ArmorVisuals), "ApplyToCharacterVisuals", (Type[])null, (Type[])null);
HarmonyMethod val2 = new HarmonyMethod(typeof(WeatheredHalfplate), "AfterAttach", (Type[])null);
val2.priority = 0;
obj2.Patch((MethodBase)methodInfo2, (HarmonyMethod)null, val2, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
harmony.Patch((MethodBase)AccessTools.Method(typeof(ArmorVisuals), "ReclaimVisuals", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(typeof(WeatheredHalfplate), "AfterReclaim", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
Harmony obj3 = harmony;
MethodInfo methodInfo3 = AccessTools.Method(typeof(ArmorVisuals), "SkinnedMeshLateSettings", (Type[])null, (Type[])null);
HarmonyMethod val3 = new HarmonyMethod(typeof(WeatheredHalfplate), "AfterAttach", (Type[])null);
val3.priority = 0;
obj3.Patch((MethodBase)methodInfo3, (HarmonyMethod)null, val3, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
logger.LogInfo((object)"Weathered Halfplate, spiked Stahlhelm and snug black bandana v0.1.15 enabled for stock item IDs 3100006–3100008.");
}
internal static void Shutdown()
{
if (harmony != null)
{
harmony.UnpatchSelf();
}
}
private static void AfterPosition(VisualSlot __instance)
{
if (Object.op_Implicit((Object)(object)__instance.CurrentVisual))
{
ApplyVisual(__instance.CurrentVisual);
}
}
private static void ApplyVisual(ItemVisual __instance)
{
int itemIDFromName = __instance.GetItemIDFromName();
if (!CoolerPlateArmors.Enabled(itemIDFromName))
{
return;
}
switch (itemIDFromName)
{
case 3100007:
ApplySallet(__instance);
break;
case 3100006:
case 3100008:
{
Renderer[] componentsInChildren = ((Component)__instance).GetComponentsInChildren<Renderer>(true);
foreach (Renderer val in componentsInChildren)
{
SkinnedMeshRenderer val2 = (SkinnedMeshRenderer)(object)((val is SkinnedMeshRenderer) ? val : null);
if (itemIDFromName == 3100006 && Object.op_Implicit((Object)(object)val2))
{
RemoveCollarStraps(val2);
}
Material[] sharedMaterials = val.sharedMaterials;
bool flag = false;
for (int j = 0; j < sharedMaterials.Length; j++)
{
Material val3 = sharedMaterials[j];
if (Object.op_Implicit((Object)(object)val3) && (!(((Object)val3).name != "mat_cha_plateArmor") || !(((Object)val3).name != "mat_cha_plateArmor (Instance)")))
{
sharedMaterials[j] = GetFinish(val3, Finish.Armor);
flag = true;
}
}
if (flag)
{
val.sharedMaterials = sharedMaterials;
}
}
break;
}
}
}
private static void RemoveCollarStraps(SkinnedMeshRenderer renderer)
{
Mesh sharedMesh = renderer.sharedMesh;
if (!Object.op_Implicit((Object)(object)sharedMesh) || ((Object)sharedMesh).name != "mdl_cha_plateArmorLightBody")
{
return;
}
if (!CollarMeshes.TryGetValue(sharedMesh, out var value))
{
if (!sharedMesh.isReadable || sharedMesh.vertexCount != 5091 || sharedMesh.subMeshCount != 1 || sharedMesh.GetIndexCount(0) != originalCollarIndices.Length)
{
return;
}
int[] triangles = sharedMesh.GetTriangles(0);
for (int i = 0; i < triangles.Length; i++)
{
if (triangles[i] != originalCollarIndices[i])
{
return;
}
}
value = Object.Instantiate<Mesh>(sharedMesh);
((Object)value).name = "Halfplate Body Without Collar Straps";
value.SetTriangles(revisedCollarIndices, 0, false);
CollarMeshes.Add(sharedMesh, value);
}
renderer.sharedMesh = value;
}
private static void AfterAttach(ArmorVisuals __instance)
{
if (CoolerPlateArmors.Enabled(3100007) && ((ItemVisual)__instance).GetItemIDFromName() == 3100007)
{
ApplySallet((ItemVisual)(object)__instance);
}
}
private static void AfterReclaim(ArmorVisuals __instance)
{
if (!CoolerPlateArmors.Enabled(3100007) || ((ItemVisual)__instance).GetItemIDFromName() != 3100007)
{
return;
}
SkinnedMeshRenderer[] componentsInChildren = ((Component)__instance).GetComponentsInChildren<SkinnedMeshRenderer>(true);
foreach (SkinnedMeshRenderer val in componentsInChildren)
{
if (Object.op_Implicit((Object)(object)val.sharedMesh) && ((Object)val.sharedMesh).name == "Sallet Equipped")
{
val.rootBone = null;
}
}
}
private static void SetHeadBounds(SkinnedMeshRenderer renderer)
{
//IL_0028: Unknown result type (might be due to invalid IL or missing references)
Transform[] bones = renderer.bones;
if (bones != null && bones.Length > 18 && Object.op_Implicit((Object)(object)bones[18]))
{
renderer.rootBone = bones[18];
renderer.localBounds = salletHeadBounds;
renderer.updateWhenOffscreen = true;
((Renderer)renderer).allowOcclusionWhenDynamic = false;
}
}
private static void ApplySallet(ItemVisual visual)
{
SkinnedMeshRenderer[] componentsInChildren = ((Component)visual).GetComponentsInChildren<SkinnedMeshRenderer>(true);
foreach (SkinnedMeshRenderer val in componentsInChildren)
{
Mesh sharedMesh = val.sharedMesh;
if (Object.op_Implicit((Object)(object)sharedMesh) && ((Object)sharedMesh).name == "Sallet Equipped")
{
SetHeadBounds(val);
}
else
{
if (!Object.op_Implicit((Object)(object)sharedMesh) || ((Object)sharedMesh).name != "mdl_cha_plateArmorLightHelm" || !Object.op_Implicit((Object)(object)((Renderer)val).sharedMaterial))
{
continue;
}
if (!EquippedMeshes.TryGetValue(sharedMesh, out var value))
{
Matrix4x4[] bindposes = sharedMesh.bindposes;
if (bindposes.Length <= 18 || Mathf.Abs(bindposes[18].m13 - 0.09360039f) > 0.01f)
{
continue;
}
value = ReadMesh(bindposes);
EquippedMeshes.Add(sharedMesh, value);
}
((Renderer)val).sharedMaterials = GetHelmetFinishes(((Renderer)val).sharedMaterial);
val.sharedMesh = value;
SetHeadBounds(val);
}
}
MeshFilter[] componentsInChildren2 = ((Component)visual).GetComponentsInChildren<MeshFilter>(true);
foreach (MeshFilter val2 in componentsInChildren2)
{
if (!Object.op_Implicit((Object)(object)val2.sharedMesh) || ((Object)val2.sharedMesh).name != "mdl_cha_plateArmorLightHelmWorld")
{
continue;
}
MeshRenderer component = ((Component)val2).GetComponent<MeshRenderer>();
if (Object.op_Implicit((Object)(object)component) && Object.op_Implicit((Object)(object)((Renderer)component).sharedMaterial))
{
if (!Object.op_Implicit((Object)(object)dropped))
{
dropped = ReadMesh(null);
}
((Renderer)component).sharedMaterials = GetHelmetFinishes(((Renderer)component).sharedMaterial);
val2.sharedMesh = dropped;
}
}
}
private static Material[] GetHelmetFinishes(Material donor)
{
return (Material[])(object)new Material[2]
{
GetFinish(donor, Finish.Sallet),
GetFinish(donor, Finish.Cloth)
};
}
private static Material GetFinish(Material donor, Finish kind)
{
//IL_0029: Unknown result type (might be due to invalid IL or missing references)
//IL_002f: Expected O, but got Unknown
//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
Dictionary<Material, Material> dictionary = kind switch
{
Finish.Sallet => HelmetFinishes,
Finish.Armor => PlateFinishes,
_ => ClothFinishes,
};
if (dictionary.TryGetValue(donor, out var value))
{
return value;
}
value = new Material(donor);
switch (kind)
{
case Finish.Armor:
((Object)value).name = "Weathered Halfplate";
value.SetTexture("_MainTex", (Texture)(object)plateAlbedo);
value.SetTexture("_GenTex", (Texture)(object)plateSurface);
value.SetTexture("_NormTex", (Texture)(object)plateNormal);
break;
case Finish.Sallet:
((Object)value).name = "Sallet Blackened Steel";
value.SetTexture("_MainTex", (Texture)(object)salletAlbedo);
value.SetTexture("_GenTex", (Texture)(object)salletSurface);
value.SetTexture("_NormTex", (Texture)(object)salletNormal);
break;
case Finish.Cloth:
((Object)value).name = "Snug Charcoal Bandana";
if (value.HasProperty("_Color"))
{
value.SetColor("_Color", Color.white);
}
value.SetTexture("_MainTex", (Texture)(object)clothAlbedo);
value.SetTexture("_GenTex", (Texture)(object)clothSurface);
value.SetTexture("_NormTex", (Texture)(object)clothNormal);
break;
}
if (value.HasProperty("_EmissionTex"))
{
value.SetTexture("_EmissionTex", (Texture)(object)Texture2D.blackTexture);
}
value.DisableKeyword("_DETAIL");
value.DisableKeyword("_DETAIL_ALBEDO");
value.DisableKeyword("_DETAIL_TEXTURED");
value.EnableKeyword("_NORMALMAP");
value.EnableKeyword("_SPECGLOSSMAP");
value.SetFloat("_SpecBoost", (kind == Finish.Cloth) ? 0f : 0.015f);
value.SetFloat("_GlossMin", (kind == Finish.Cloth) ? 0f : 0.035f);
value.SetFloat("_SmoothMin", (kind == Finish.Cloth) ? 0f : 0.035f);
dictionary.Add(donor, value);
return value;
}
private static Texture2D ReadTexture(string resource, bool linear)
{
//IL_0005: Unknown result type (might be due to invalid IL or missing references)
//IL_000b: Expected O, but got Unknown
Texture2D val = new Texture2D(2, 2, (TextureFormat)4, true, linear);
((Object)val).name = resource;
((Texture)val).anisoLevel = 4;
Texture2D val2 = val;
using Stream stream = typeof(WeatheredHalfplate).Assembly.GetManifestResourceStream("WeatheredHalfplate." + resource);
using MemoryStream memoryStream = new MemoryStream();
stream.CopyTo(memoryStream);
if (!ImageConversion.LoadImage(val2, memoryStream.ToArray(), true))
{
throw new InvalidDataException(resource);
}
return val2;
}
private static int[] ReadIndices(BinaryReader reader, int count)
{
int[] array = new int[count];
for (int i = 0; i < count; i++)
{
array[i] = reader.ReadInt32();
}
return array;
}
private static Mesh ReadMesh(Matrix4x4[] poses)
{
//IL_001a: Unknown result type (might be due to invalid IL or missing references)
//IL_002e: Unknown result type (might be due to invalid IL or missing references)
//IL_0033: Unknown result type (might be due to invalid IL or missing references)
//IL_0038: Unknown result type (might be due to invalid IL or missing references)
//IL_000b: 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_0093: 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_00e0: Unknown result type (might be due to invalid IL or missing references)
//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
//IL_0100: Unknown result type (might be due to invalid IL or missing references)
//IL_0105: Unknown result type (might be due to invalid IL or missing references)
//IL_011f: Unknown result type (might be due to invalid IL or missing references)
//IL_0124: Unknown result type (might be due to invalid IL or missing references)
//IL_0137: Unknown result type (might be due to invalid IL or missing references)
//IL_0152: 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_020b: Unknown result type (might be due to invalid IL or missing references)
//IL_0217: 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_0192: 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_01a3: Unknown result type (might be due to invalid IL or missing references)
//IL_01a8: Unknown result type (might be due to invalid IL or missing references)
//IL_01ad: Unknown result type (might be due to invalid IL or missing references)
//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_0171: 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_0163: 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_0246: Unknown result type (might be due to invalid IL or missing references)
//IL_0248: Unknown result type (might be due to invalid IL or missing references)
//IL_024d: Unknown result type (might be due to invalid IL or missing references)
//IL_01ce: Unknown result type (might be due to invalid IL or missing references)
//IL_01d3: Unknown result type (might be due to invalid IL or missing references)
//IL_01dc: 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_0293: Unknown result type (might be due to invalid IL or missing references)
//IL_029a: Expected O, but got Unknown
bool flag = poses != null;
Matrix4x4 val = (flag ? (((Matrix4x4)(ref poses[18])).inverse * Matrix4x4.Translate(new Vector3(0f, -1.6727635f, 0.00797624f))) : Matrix4x4.identity);
using Stream stream = typeof(WeatheredHalfplate).Assembly.GetManifestResourceStream("WeatheredHalfplate.SalletMesh");
using BinaryReader binaryReader = new BinaryReader(stream);
int num = binaryReader.ReadInt32();
Vector3[] array = (Vector3[])(object)new Vector3[num];
Vector3[] array2 = (Vector3[])(object)new Vector3[num];
Vector2[] array3 = (Vector2[])(object)new Vector2[num];
BoneWeight[] array4 = (BoneWeight[])(object)(flag ? new BoneWeight[num] : null);
Bounds val2 = default(Bounds);
Vector3 val3 = default(Vector3);
Vector3 val4 = default(Vector3);
for (int i = 0; i < num; i++)
{
((Vector3)(ref val3))..ctor(binaryReader.ReadSingle(), binaryReader.ReadSingle(), binaryReader.ReadSingle());
((Vector3)(ref val4))..ctor(binaryReader.ReadSingle(), binaryReader.ReadSingle(), binaryReader.ReadSingle());
ref Vector3 reference = ref array[i];
reference = ((Matrix4x4)(ref val)).MultiplyPoint3x4(val3);
ref Vector3 reference2 = ref array2[i];
Vector3 val5 = ((Matrix4x4)(ref val)).MultiplyVector(val4);
reference2 = ((Vector3)(ref val5)).normalized;
ref Vector2 reference3 = ref array3[i];
reference3 = new Vector2(binaryReader.ReadSingle(), binaryReader.ReadSingle());
if (flag)
{
ref BoneWeight reference4 = ref array4[i];
BoneWeight val6 = default(BoneWeight);
((BoneWeight)(ref val6)).boneIndex0 = 18;
((BoneWeight)(ref val6)).weight0 = 1f;
reference4 = val6;
}
else if (i == 0)
{
((Bounds)(ref val2))..ctor(val3, Vector3.zero);
}
else
{
((Bounds)(ref val2)).Encapsulate(val3);
}
}
if (flag)
{
Matrix4x4 val7 = poses[18];
salletHeadBounds = new Bounds(((Matrix4x4)(ref val7)).MultiplyPoint3x4(array[0]), Vector3.zero);
Vector3[] array5 = array;
foreach (Vector3 val8 in array5)
{
((Bounds)(ref salletHeadBounds)).Encapsulate(((Matrix4x4)(ref val7)).MultiplyPoint3x4(val8));
}
((Bounds)(ref salletHeadBounds)).Expand(0.12f);
}
else
{
Vector3 val9 = default(Vector3);
((Vector3)(ref val9))..ctor(((Bounds)(ref val2)).center.x, ((Bounds)(ref val2)).min.y, ((Bounds)(ref val2)).center.z);
for (int k = 0; k < num; k++)
{
ref Vector3 reference5 = ref array[k];
reference5 -= val9;
}
}
int[] array6 = ReadIndices(binaryReader, binaryReader.ReadInt32());
int[] array7 = ReadIndices(binaryReader, binaryReader.ReadInt32());
if (stream.Position != stream.Length)
{
throw new InvalidDataException("Unexpected sallet index data.");
}
Mesh val10 = new Mesh();
((Object)val10).name = (flag ? "Sallet Equipped" : "Sallet Dropped");
Mesh val11 = val10;
val11.vertices = array;
val11.normals = array2;
val11.uv = array3;
if (flag)
{
val11.bindposes = poses;
val11.boneWeights = array4;
}
val11.subMeshCount = 2;
val11.SetTriangles(array6, 0, false);
val11.SetTriangles(array7, 1, false);
val11.RecalculateBounds();
val11.RecalculateTangents();
return val11;
}
}
internal static class SuttonHooHelmet
{
private const int ItemId = -847460;
private const int PlateHelmetId = 3100004;
private const int CloseHelmId = -847461;
private const string BlackReplacement = "Full Plate Black Donor";
private const int HeadBone = 18;
private static Texture2D donorAlbedo;
private static Texture2D donorSurface;
private static Texture2D donorNormal;
private static Sprite plateIcon;
private static Mesh droppedPlate;
private static readonly Dictionary<Mesh, Mesh> CloseEquippedMeshes = new Dictionary<Mesh, Mesh>();
private static readonly Dictionary<Material, Material[]> DonorFinishes = new Dictionary<Material, Material[]>();
private static ManualLogSource log;
private static readonly Dictionary<Mesh, Mesh> EquippedMeshes = new Dictionary<Mesh, Mesh>();
private static readonly Dictionary<Material, Material[]> Finishes = new Dictionary<Material, Material[]>();
private static readonly Dictionary<Material, Material[]> CloseFinishes = new Dictionary<Material, Material[]>();
private static Mesh droppedSuttonHoo;
private static Mesh droppedCloseHelm;
private static Texture2D steelAlbedo;
private static Texture2D steelSurface;
private static Texture2D brassAlbedo;
private static Texture2D brassSurface;
private static Texture2D steelNormal;
private static Sprite suttonHooIcon;
private static Sprite closeHelmIcon;
private static Texture2D chestAlbedo;
private static Texture2D chestSurface;
private static Texture2D chestNormal;
private static Texture2D closeBrassAlbedo;
private static Texture2D closeBrassSurface;
private static Harmony harmony;
internal static void Initialize(ManualLogSource logger)
{
//IL_0117: Unknown result type (might be due to invalid IL or missing references)
//IL_0121: Expected O, but got Unknown
//IL_014d: Unknown result type (might be due to invalid IL or missing references)
//IL_015a: Expected O, but got Unknown
//IL_018b: Unknown result type (might be due to invalid IL or missing references)
//IL_0191: Expected O, but got Unknown
//IL_01e1: Unknown result type (might be due to invalid IL or missing references)
//IL_01e7: Expected O, but got Unknown
log = logger;
steelAlbedo = ReadTexture("PittedSteelAlbedo", linear: false);
steelSurface = ReadTexture("PittedSteelSurface", linear: true);
brassAlbedo = ReadTexture("PlateTrimAlbedo", linear: false);
brassSurface = ReadTexture("PlateTrimSurface", linear: true);
steelNormal = ReadTexture("PittedSteelNormal", linear: true);
chestAlbedo = ReadTexture("CloseHelmSteelAlbedo", linear: false);
chestSurface = ReadTexture("CloseHelmSteelSurface", linear: true);
chestNormal = ReadTexture("CloseHelmPittedNormal", linear: true);
closeBrassAlbedo = ReadTexture("CloseHelmBrassAlbedo", linear: false);
closeBrassSurface = ReadTexture("CloseHelmBrassSurface", linear: true);
suttonHooIcon = ReadIcon("SuttonHooIcon", "Sutton Hoo Helmet");
closeHelmIcon = ReadIcon("CloseHelmIcon", "Knight Close Helm");
plateIcon = ReadIcon("BlackDonorIcon", "Plate Helm");
donorAlbedo = ReadTexture("BlackDonorAlbedo", linear: false);
donorSurface = ReadTexture("BlackDonorSurface", linear: true);
donorNormal = ReadTexture("BlackDonorNormal", linear: true);
harmony = new Harmony("brokenruune.suttonhoohelmet");
harmony.Patch((MethodBase)AccessTools.Method(typeof(ItemVisual), "Awake", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(typeof(SuttonHooHelmet), "AfterVisualAwake", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
Harmony obj = harmony;
MethodInfo methodInfo = AccessTools.Method(typeof(VisualSlot), "PositionVisuals", Type.EmptyTypes, (Type[])null);
HarmonyMethod val = new HarmonyMethod(typeof(SuttonHooHelmet), "AfterVisualPositioned", (Type[])null);
val.priority = 0;
obj.Patch((MethodBase)methodInfo, (HarmonyMethod)null, val, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
Harmony obj2 = harmony;
MethodInfo methodInfo2 = AccessTools.Method(typeof(ResourcesPrefabManager), "GetItemIcon", new Type[1] { typeof(Item) }, (Type[])null);
HarmonyMethod val2 = new HarmonyMethod(typeof(SuttonHooHelmet), "TryGetHelmetIcon", (Type[])null);
val2.priority = 800;
obj2.Patch((MethodBase)methodInfo2, val2, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
}
internal static void Shutdown()
{
if (harmony != null)
{
harmony.UnpatchSelf();
}
}
private static bool TryGetHelmetIcon(Item __0, ref Sprite __result)
{
if (!Object.op_Implicit((Object)(object)__0) || __0.ItemID != 3100004 || !CoolerPlateArmors.Enabled(3100004))
{
return true;
}
__result = ((__0.ItemID == 3100004) ? plateIcon : ((__0.ItemID == -847461) ? closeHelmIcon : suttonHooIcon));
return !Object.op_Implicit((Object)(object)__result);
}
private static void AfterVisualAwake(ItemVisual __instance)
{
int itemIDFromName = __instance.GetItemIDFromName();
if (itemIDFromName == 3100004 && CoolerPlateArmors.Enabled(itemIDFromName))
{
ApplyVisual(((Component)__instance).gameObject, itemIDFromName);
}
}
private static void AfterVisualPositioned(VisualSlot __instance)
{
if (Object.op_Implicit((Object)(object)__instance.CurrentVisual))
{
AfterVisualAwake(__instance.CurrentVisual);
}
}
private static void ApplyVisual(GameObject visual, int id)
{
//IL_0182: Unknown result type (might be due to invalid IL or missing references)
bool flag = id == -847461;
bool flag2 = id == 3100004;
string text = ((id == -847460) ? "mdl_cha_blueSandHelm" : "mdl_cha_plateArmorPlainHelm");
Dictionary<Mesh, Mesh> dictionary = (flag ? CloseEquippedMeshes : EquippedMeshes);
SkinnedMeshRenderer[] componentsInChildren = visual.GetComponentsInChildren<SkinnedMeshRenderer>(true);
foreach (SkinnedMeshRenderer val in componentsInChildren)
{
Mesh sharedMesh = val.sharedMesh;
if (!Object.op_Implicit((Object)(object)sharedMesh) || (((Object)sharedMesh).name != text && (!flag || !(((Object)sharedMesh).name == "Full Plate Black Donor (equipped)"))) || !Object.op_Implicit((Object)(object)((Renderer)val).sharedMaterial))
{
continue;
}
if (!dictionary.TryGetValue(sharedMesh, out var value))
{
Matrix4x4[] bindposes = sharedMesh.bindposes;
if (bindposes.Length <= 18 || Mathf.Abs(bindposes[18].m13 + 1.6727635f) > 0.01f)
{
log.LogWarning((object)("Sutton Hoo helmet could not verify the donor head bind pose for item " + id + "."));
continue;
}
value = ReadMesh(bindposes, id);
dictionary.Add(sharedMesh, value);
log.LogInfo((object)("Prepared " + ((Object)value).name + " for item " + id + "."));
}
((Renderer)val).sharedMaterials = GetFinishes(((Renderer)val).sharedMaterial, id);
val.sharedMesh = value;
val.localBounds = value.bounds;
}
MeshFilter[] componentsInChildren2 = visual.GetComponentsInChildren<MeshFilter>(true);
foreach (MeshFilter val2 in componentsInChildren2)
{
if (!Object.op_Implicit((Object)(object)val2.sharedMesh) || (((Object)val2.sharedMesh).name != text + "World" && (!flag || !(((Object)val2.sharedMesh).name == "Full Plate Black Donor (world)"))))
{
continue;
}
MeshRenderer component = ((Component)val2).GetComponent<MeshRenderer>();
if (!Object.op_Implicit((Object)(object)component) || !Object.op_Implicit((Object)(object)((Renderer)component).sharedMaterial))
{
continue;
}
Mesh val3 = (flag2 ? droppedPlate : (flag ? droppedCloseHelm : droppedSuttonHoo));
if (!Object.op_Implicit((Object)(object)val3))
{
val3 = ReadMesh(null, id);
if (flag2)
{
droppedPlate = val3;
}
else if (flag)
{
droppedCloseHelm = val3;
}
else
{
droppedSuttonHoo = val3;
}
}
((Renderer)component).sharedMaterials = GetFinishes(((Renderer)component).sharedMaterial, id);
val2.sharedMesh = val3;
}
}
private static Material[] GetFinishes(Material donor, int id)
{
bool flag = id == -847461;
bool flag2 = id == 3100004;
Dictionary<Material, Material[]> dictionary = (flag2 ? DonorFinishes : (flag ? CloseFinishes : Finishes));
if (!dictionary.TryGetValue(donor, out var value))
{
value = (Material[])(object)(flag2 ? new Material[1] { FinishMaterial(donor, "Full Plate Black Steel and Bronze", donorAlbedo, donorSurface, donorNormal) } : new Material[2]
{
flag ? FinishMaterial(donor, "Close Helm Blackened Steel", chestAlbedo, chestSurface, chestNormal) : FinishMaterial(donor, "Sutton Hoo Blackened Iron", steelAlbedo, steelSurface, steelNormal),
flag ? FinishMaterial(donor, "Close Helm Aged Brass", closeBrassAlbedo, closeBrassSurface, chestNormal) : FinishMaterial(donor, "Sutton Hoo Dull Brass", brassAlbedo, brassSurface, steelNormal)
});
dictionary.Add(donor, value);
}
return value;
}
private static Sprite ReadIcon(string resourceName, string itemName)
{
//IL_0021: Unknown result type (might be due to invalid IL or missing references)
//IL_0030: Unknown result type (might be due to invalid IL or missing references)
Texture2D val = ReadTexture(resourceName, linear: false);
Sprite val2 = Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f), 100f, 0u, (SpriteMeshType)0);
((Object)val2).name = itemName;
return val2;
}
private static Texture2D ReadTexture(string name, bool linear)
{
//IL_0005: Unknown result type (might be due to invalid IL or missing references)
//IL_000b: Expected O, but got Unknown
Texture2D val = new Texture2D(2, 2, (TextureFormat)4, true, linear);
((Object)val).name = name;
((Texture)val).anisoLevel = 4;
Texture2D val2 = val;
using Stream stream = typeof(SuttonHooHelmet).Assembly.GetManifestResourceStream("SuttonHooHelmet." + name);
using MemoryStream memoryStream = new MemoryStream();
stream.CopyTo(memoryStream);
if (!ImageConversion.LoadImage(val2, memoryStream.ToArray(), true))
{
throw new InvalidDataException(name);
}
return val2;
}
private static Material FinishMaterial(Material donor, string name, Texture2D albedo, Texture2D surface, Texture2D normal)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0007: Expected O, but got Unknown
Material val = new Material(donor);
((Object)val).name = name;
Material val2 = val;
val2.SetTexture("_MainTex", (Texture)(object)albedo);
val2.SetTexture("_GenTex", (Texture)(object)surface);
val2.SetTexture("_NormTex", (Texture)(object)normal);
if (val2.HasProperty("_EmissionTex"))
{
val2.SetTexture("_EmissionTex", (Texture)(object)Texture2D.blackTexture);
}
val2.DisableKeyword("_DETAIL");
val2.DisableKeyword("_DETAIL_ALBEDO");
val2.DisableKeyword("_DETAIL_TEXTURED");
val2.EnableKeyword("_NORMALMAP");
val2.EnableKeyword("_SPECGLOSSMAP");
val2.SetFloat("_SpecBoost", 0.015f);
val2.SetFloat("_GlossMin", 0.035f);
val2.SetFloat("_SmoothMin", 0.035f);
return val2;
}
private static Mesh ReadMesh(Matrix4x4[] bindPoses, int id)
{
//IL_019f: Unknown result type (might be due to invalid IL or missing references)
//IL_01a6: Expected O, but got Unknown
//IL_0110: Unknown result type (might be due to invalid IL or missing references)
//IL_0112: Unknown result type (might be due to invalid IL or missing references)
//IL_0135: Unknown result type (might be due to invalid IL or missing references)
//IL_013a: Unknown result type (might be due to invalid IL or missing references)
//IL_0156: Unknown result type (might be due to invalid IL or missing references)
//IL_015b: Unknown result type (might be due to invalid IL or missing references)
//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
//IL_0104: Unknown result type (might be due to invalid IL or missing references)
//IL_0109: Unknown result type (might be due to invalid IL or missing references)
//IL_016e: Unknown result type (might be due to invalid IL or missing references)
//IL_0189: Unknown result type (might be due to invalid IL or missing references)
//IL_018b: Unknown result type (might be due to invalid IL or missing references)
bool flag = bindPoses != null;
bool flag2 = id == 3100004;
bool flag3 = id == -847461;
int num = (flag2 ? 1 : 2);
string text = ((!flag2) ? (flag3 ? "CloseHelmMesh" : "SuttonHooMesh") : (flag ? "BlackDonorEquipped" : "BlackDonorWorld"));
string text2 = (flag2 ? "Full Plate Black Donor" : (flag3 ? "Knight Close Helm" : "Sutton Hoo Helmet"));
using Stream input = typeof(SuttonHooHelmet).Assembly.GetManifestResourceStream("SuttonHooHelmet." + text);
using BinaryReader binaryReader = new BinaryReader(input);
int num2 = binaryReader.ReadInt32();
Vector3[] array = (Vector3[])(object)new Vector3[num2];
Vector3[] array2 = (Vector3[])(object)new Vector3[num2];
Vector2[] array3 = (Vector2[])(object)new Vector2[num2];
BoneWeight[] array4 = (BoneWeight[])(object)(flag ? new BoneWeight[num2] : null);
Vector3 val = default(Vector3);
for (int i = 0; i < num2; i++)
{
((Vector3)(ref val))..ctor(binaryReader.ReadSingle(), binaryReader.ReadSingle(), binaryReader.ReadSingle());
ref Vector3 reference = ref array[i];
reference = ((flag || flag2) ? val : (val + new Vector3(0f, -1.628f, -0.049f)));
ref Vector3 reference2 = ref array2[i];
reference2 = new Vector3(binaryReader.ReadSingle(), binaryReader.ReadSingle(), binaryReader.ReadSingle());
ref Vector2 reference3 = ref array3[i];
reference3 = new Vector2(binaryReader.ReadSingle(), binaryReader.ReadSingle());
if (flag)
{
ref BoneWeight reference4 = ref array4[i];
BoneWeight val2 = default(BoneWeight);
((BoneWeight)(ref val2)).boneIndex0 = 18;
((BoneWeight)(ref val2)).weight0 = 1f;
reference4 = val2;
}
}
Mesh val3 = new Mesh();
((Object)val3).name = text2 + (flag ? " (equipped)" : " (world)");
val3.indexFormat = (IndexFormat)(num2 > 65535);
val3.vertices = array;
val3.normals = array2;
val3.uv = array3;
val3.subMeshCount = num;
Mesh val4 = val3;
for (int j = 0; j < num; j++)
{
int[] array5 = new int[binaryReader.ReadInt32()];
for (int k = 0; k < array5.Length; k++)
{
array5[k] = binaryReader.ReadInt32();
}
val4.SetTriangles(array5, j);
}
if (flag)
{
val4.bindposes = bindPoses;
val4.boneWeights = array4;
}
val4.RecalculateBounds();
val4.RecalculateTangents();
return val4;
}
}
internal static class EliteAutumnReskin
{
private const string PluginId = "local.dylan.eliteautumnreskin";
private const int StockHelmId = 3100001;
private const int AltHelmId = -847401;
private const string LoudHammerId = "3Rx_R0XDLUmYaNWm66SVCQ";
private const string PlateMaterial = "mat_cha_plateArmor";
private const string AutumnMaterial = "mat_cha_eliteAutumnPlate";
private const string HelmetMaterial = "mat_cha_eliteAutumnHelm";
private static readonly int MainTex = Shader.PropertyToID("_MainTex");
private static readonly int GenTex = Shader.PropertyToID("_GenTex");
private static readonly Dictionary<Material, Material> Finishes = new Dictionary<Material, Material>();
private static readonly Dictionary<Material, Material> HelmetFinishes = new Dictionary<Material, Material>();
private static readonly Dictionary<Mesh, Mesh> AntlerFreeMeshes = new Dictionary<Mesh, Mesh>();
private static Texture2D albedo;
private static Texture2D helmetAlbedo;
private static Texture2D surface;
private static ManualLogSource log;
private static readonly Dictionary<Mesh, Mesh> CloseMeshes = new Dictionary<Mesh, Mesh>();
private static readonly Dictionary<Mesh, Mesh> CloseDonors = new Dictionary<Mesh, Mesh>();
private static readonly Dictionary<Mesh, Material[]> CloseDonorMaterials = new Dictionary<Mesh, Material[]>();
private static readonly Dictionary<Material, Material[]> CloseFinishes = new Dictionary<Material, Material[]>();
private static Texture2D closeAlbedo;
private static Texture2D closeSurface;
private static Texture2D closeTrim;
private static Texture2D closeTorsoSurface;
private static Texture2D closeNormal;
internal static void Initialize(ManualLogSource logger)
{
//IL_008b: Unknown result type (might be due to invalid IL or missing references)
//IL_0091: Expected O, but got Unknown
//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
//IL_00c6: Expected O, but got Unknown
//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
//IL_00f9: Expected O, but got Unknown
log = logger;
albedo = LoadTexture("EliteAlbedo", linear: false);
helmetAlbedo = LoadTexture("EliteHelmetAlbedo", linear: false);
surface = LoadTexture("EliteSurface", linear: true);
closeAlbedo = LoadTexture("EliteCloseAlbedo", linear: false);
closeSurface = LoadTexture("EliteCloseSurface", linear: true);
closeTorsoSurface = LoadTexture("EliteCloseTorsoSurface", linear: true);
closeTrim = LoadTexture("EliteCloseTrim", linear: false);
closeNormal = LoadTexture("EliteCloseNormal", linear: true);
Harmony val = new Harmony("local.dylan.eliteautumnreskin");
val.Patch((MethodBase)AccessTools.Method(typeof(ItemVisual), "Awake", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(typeof(EliteAutumnReskin), "RecolorVisual", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
MethodInfo methodInfo = AccessTools.Method(typeof(VisualSlot), "PositionVisuals", Type.EmptyTypes, (Type[])null);
HarmonyMethod val2 = new HarmonyMethod(typeof(EliteAutumnReskin), "RecolorEquipped", (Type[])null);
val2.priority = 0;
val.Patch((MethodBase)methodInfo, (HarmonyMethod)null, val2, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
}
private static Texture2D LoadTexture(string resource, bool linear)
{
//IL_0005: Unknown result type (might be due to invalid IL or missing references)
//IL_000b: Expected O, but got Unknown
Texture2D val = new Texture2D(2, 2, (TextureFormat)4, true, linear);
((Object)val).name = resource;
((Texture)val).anisoLevel = 4;
Texture2D val2 = val;
using Stream stream = typeof(EliteAutumnReskin).Assembly.GetManifestResourceStream("EliteAutumnReskin." + resource);
using MemoryStream memoryStream = new MemoryStream();
stream.CopyTo(memoryStream);
if (!ImageConversion.LoadImage(val2, memoryStream.ToArray(), true))
{
throw new InvalidDataException("Could not decode " + resource);
}
return val2;
}
private static void RecolorEquipped(VisualSlot __instance)
{
if (Object.op_Implicit((Object)(object)__instance.CurrentVisual))
{
RecolorVisual(__instance.CurrentVisual);
}
}
private static void RecolorVisual(ItemVisual __instance)
{
//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
//IL_00cf: Expected O, but got Unknown
int itemIDFromName = __instance.GetItemIDFromName();
bool flag = itemIDFromName == -847401;
if (itemIDFromName < 3100000 || itemIDFromName > 3100002 || !CoolerPlateArmors.Enabled(itemIDFromName))
{
return;
}
if (itemIDFromName == 3100001)
{
ApplyCloseHelm(__instance, restore: false);
return;
}
if (flag)
{
ApplyCloseHelm(__instance, restore: true);
}
bool flag2 = flag;
Dictionary<Material, Material> dictionary = (flag2 ? HelmetFinishes : Finishes);
Renderer[] componentsInChildren = ((Component)__instance).GetComponentsInChildren<Renderer>(true);
foreach (Renderer val in componentsInChildren)
{
Material[] sharedMaterials = val.sharedMaterials;
bool flag3 = false;
for (int j = 0; j < sharedMaterials.Length; j++)
{
Material val2 = sharedMaterials[j];
if (Object.op_Implicit((Object)(object)val2) && (!(((Object)val2).name != "mat_cha_plateArmor") || !(((Object)val2).name != "mat_cha_plateArmor (Instance)")))
{
if (!dictionary.TryGetValue(val2, out var value))
{
Material val3 = new Material(val2);
((Object)val3).name = (flag2 ? "mat_cha_eliteAutumnHelm" : "mat_cha_eliteAutumnPlate");
value = val3;
value.SetTexture(MainTex, (Texture)(object)(flag2 ? helmetAlbedo : albedo));
value.SetTexture(GenTex, (Texture)(object)surface);
dictionary.Add(val2, value);
}
sharedMaterials[j] = value;
flag3 = true;
}
}
if (flag3)
{
val.sharedMaterials = sharedMaterials;
}
if (flag && sharedMaterials.Length == 2 && Object.op_Implicit((Object)(object)sharedMaterials[1]) && ((Object)sharedMaterials[1]).name.StartsWith("mat_cha_plateArmorHorns", StringComparison.Ordinal))
{
RemoveAntlers(val, sharedMaterials[0]);
}
}
}
private static void ApplyCloseHelm(ItemVisual visual, bool restore)
{
//IL_027c: Unknown result type (might be due to invalid IL or missing references)
//IL_0190: Unknown result type (might be due to invalid IL or missing references)
//IL_0197: Expected O, but got Unknown
//IL_01dc: Unknown result type (might be due to invalid IL or missing references)
//IL_01e3: Expected O, but got Unknown
Renderer[] componentsInChildren = ((Component)visual).GetComponentsInChildren<Renderer>(true);
foreach (Renderer val in componentsInChildren)
{
SkinnedMeshRenderer val2 = (SkinnedMeshRenderer)(object)((val is SkinnedMeshRenderer) ? val : null);
MeshFilter val3 = (Object.op_Implicit((Object)(object)val2) ? null : ((Component)val).GetComponent<MeshFilter>());
Mesh val4 = (Object.op_Implicit((Object)(object)val2) ? val2.sharedMesh : (Object.op_Implicit((Object)(object)val3) ? val3.sharedMesh : null));
if (!Object.op_Implicit((Object)(object)val4))
{
continue;
}
Mesh value;
Material[] sharedMaterials;
if (restore)
{
if (!CloseDonors.TryGetValue(val4, out value))
{
continue;
}
sharedMaterials = CloseDonorMaterials[val4];
}
else
{
if (((Object)val4).name != "mdl_cha_plateArmorHelm" && ((Object)val4).name != "mdl_cha_plateArmorHelmWorld")
{
continue;
}
Material[] sharedMaterials2 = val.sharedMaterials;
if (sharedMaterials2.Length != 2 || !Object.op_Implicit((Object)(object)sharedMaterials2[0]) || !Object.op_Implicit((Object)(object)sharedMaterials2[1]) || !((Object)sharedMaterials2[1]).name.StartsWith("mat_cha_plateArmorHorns", StringComparison.Ordinal))
{
continue;
}
if (!CloseMeshes.TryGetValue(val4, out value))
{
Matrix4x4[] array = (Object.op_Implicit((Object)(object)val2) ? val4.bindposes : null);
if (Object.op_Implicit((Object)(object)val2) && array.Length <= 18)
{
continue;
}
value = ReadCloseMesh(array);
CloseMeshes.Add(val4, value);
CloseDonors.Add(value, val4);
CloseDonorMaterials.Add(value, sharedMaterials2);
log.LogInfo((object)("Prepared antlered Elite Close Helm for " + ((Object)val4).name + "."));
}
if (!CloseFinishes.TryGetValue(sharedMaterials2[0], out var value2))
{
Material val5 = new Material(sharedMaterials2[0]);
((Object)val5).name = "Elite Close Helm Autumn Camo";
Material val6 = val5;
val6.SetTexture(MainTex, (Texture)(object)closeAlbedo);
val6.SetTexture(GenTex, (Texture)(object)closeSurface);
val6.SetTexture("_NormTex", (Texture)(object)closeNormal);
Material val7 = new Material(val6);
((Object)val7).name = "Elite Close Helm Dark Trim";
Material val8 = val7;
val8.SetTexture(MainTex, (Texture)(object)closeTrim);
val8.SetTexture(GenTex, (Texture)(object)closeTorsoSurface);
value2 = (Material[])(object)new Material[2] { val6, val8 };
CloseFinishes.Add(sharedMaterials2[0], value2);
}
sharedMaterials = (Material[])(object)new Material[3]
{
value2[0],
value2[1],
sharedMaterials2[1]
};
}
val.sharedMaterials = sharedMaterials;
if (Object.op_Implicit((Object)(object)val2))
{
val2.sharedMesh = value;
val2.localBounds = value.bounds;
}
else
{
val3.sharedMesh = value;
}
}
}
private static Mesh ReadCloseMesh(Matrix4x4[] poses)
{
//IL_001a: Unknown result type (might be due to invalid IL or missing references)
//IL_002e: Unknown result type (might be due to invalid IL or missing references)
//IL_0033: Unknown result type (might be due to invalid IL or missing references)
//IL_0038: Unknown result type (might be due to invalid IL or missing references)
//IL_000b: 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_0180: Unknown result type (might be due to invalid IL or missing references)
//IL_0187: Expected O, but got Unknown
//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
//IL_00f8: 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_00e8: Unknown result type (might be due to invalid IL or missing references)
//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
//IL_00fd: 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_010f: 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_0118: Unknown result type (might be due to invalid IL or missing references)
//IL_011d: Unknown result type (might be due to invalid IL or missing references)
//IL_0137: Unknown result type (might be due to invalid IL or missing references)
//IL_013c: 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_016a: Unknown result type (might be due to invalid IL or missing references)
//IL_016c: Unknown result type (might be due to invalid IL or missing references)
bool flag = poses != null;
Matrix4x4 val = (flag ? (((Matrix4x4)(ref poses[18])).inverse * Matrix4x4.Translate(new Vector3(0f, -1.6727635f, 0.00797624f))) : Matrix4x4.identity);
using Stream stream = typeof(EliteAutumnReskin).Assembly.GetManifestResourceStream("EliteAutumnReskin.EliteCloseMesh");
using BinaryReader binaryReader = new BinaryReader(stream);
int num = binaryReader.ReadInt32();
Vector3[] array = (Vector3[])(object)new Vector3[num];
Vector3[] array2 = (Vector3[])(object)new Vector3[num];
Vector2[] array3 = (Vector2[])(object)new Vector2[num];
BoneWeight[] array4 = (BoneWeight[])(object)(flag ? new BoneWeight[num] : null);
Vector3 val2 = default(Vector3);
Vector3 val3 = default(Vector3);
for (int i = 0; i < num; i++)
{
((Vector3)(ref val2))..ctor(binaryReader.ReadSingle(), binaryReader.ReadSingle(), binaryReader.ReadSingle());
((Vector3)(ref val3))..ctor(binaryReader.ReadSingle(), binaryReader.ReadSingle(), binaryReader.ReadSingle());
ref Vector3 reference = ref array[i];
reference = (flag ? ((Matrix4x4)(ref val)).MultiplyPoint3x4(val2) : (val2 - new Vector3(0f, 1.628f, 0.049f)));
ref Vector3 reference2 = ref array2[i];
Vector3 val4 = ((Matrix4x4)(ref val)).MultiplyVector(val3);
reference2 = ((Vector3)(ref val4)).normalized;
ref Vector2 reference3 = ref array3[i];
reference3 = new Vector2(binaryReader.ReadSingle(), binaryReader.ReadSingle());
if (flag)
{
ref BoneWeight reference4 = ref array4[i];
BoneWeight val5 = default(BoneWeight);
((BoneWeight)(ref val5)).boneIndex0 = 18;
((BoneWeight)(ref val5)).weight0 = 1f;
reference4 = val5;
}
}
Mesh val6 = new Mesh();
((Object)val6).name = (flag ? "Elite Close Helm (equipped)" : "Elite Close Helm (world)");
val6.vertices = array;
val6.normals = array2;
val6.uv = array3;
val6.subMeshCount = 3;
Mesh val7 = val6;
if (flag)
{
val7.bindposes = poses;
val7.boneWeights = array4;
}
for (int j = 0; j < 3; j++)
{
int[] array5 = new int[binaryReader.ReadInt32()];
for (int k = 0; k < array5.Length; k++)
{
array5[k] = binaryReader.ReadInt32();
}
val7.SetTriangles(array5, j, false);
}
if (stream.Position != stream.Length)
{
throw new InvalidDataException("Invalid Elite Close Helm mesh.");
}
val7.RecalculateBounds();
val7.RecalculateTangents();
return val7;
}
private static void ConfigureAltHelm(Item __0, GameObject __1, GameObject __result)
{
if (Object.op_Implicit((Object)(object)__0) && __0.ItemID == -847401 && Object.op_Implicit((Object)(object)__result) && !((Object)(object)__result == (Object)(object)__1))
{
((Object)__result).name = -847401 + "_AltEliteHelm" + (((Object)__result).name.Contains("_e_v") ? "_e_v" : "_v");
ItemVisual component = __result.GetComponent<ItemVisual>();
if (Object.op_Implicit((Object)(object)component))
{
RecolorVisual(component);
}
}
}
private static void RemoveAntlers(Renderer renderer, Material plate)
{
SkinnedMeshRenderer val = (SkinnedMeshRenderer)(object)((renderer is SkinnedMeshRenderer) ? renderer : null);
MeshFilter val2 = (Object.op_Implicit((Object)(object)val) ? null : ((Component)renderer).GetComponent<MeshFilter>());
Mesh val3 = (Object.op_Implicit((Object)(object)val) ? val.sharedMesh : (Object.op_Implicit((Object)(object)val2) ? val2.sharedMesh : null));
if (!Object.op_Implicit((Object)(object)val3) || val3.subMeshCount != 2 || (((Object)val3).name != "mdl_cha_plateArmorHelm" && ((Object)val3).name != "mdl_cha_plateArmorHelmWorld"))
{
return;
}
if (!AntlerFreeMeshes.TryGetValue(val3, out var value))
{
value = CreateAntlerFreeMesh(val3, Object.op_Implicit((Object)(object)val) ? "EliteHelmEquippedMask" : "EliteHelmDroppedMask");
if (!Object.op_Implicit((Object)(object)value))
{
log.LogWarning((object)("Alt Elite Helm mesh signature did not match " + ((Object)val3).name + "."));
return;
}
AntlerFreeMeshes.Add(val3, value);
log.LogInfo((object)("Removed antlers and their fittings from " + ((Object)val3).name + " for the Alt Elite Helm."));
}
if (Object.op_Implicit((Object)(object)val))
{
val.sharedMesh = value;
}
else
{
val2.sharedMesh = value;
}
renderer.sharedMaterials = (Material[])(object)new Material[1] { plate };
}
private static Mesh CreateAntlerFreeMesh(Mesh source, string resource)
{
using Stream input = typeof(EliteAutumnReskin).Assembly.GetManifestResourceStream("EliteAutumnReskin." + resource);
using BinaryReader binaryReader = new BinaryReader(input);
int num = binaryReader.ReadInt32();
int num2 = binaryReader.ReadInt32();
uint num3 = binaryReader.ReadUInt32();
if (!source.isReadable || source.vertexCount != num || source.GetIndexCount(0) != num2)
{
return null;
}
int[] triangles = source.GetTriangles(0);
uint num4 = 2166136261u;
int[] array = triangles;
foreach (int num5 in array)
{
num4 = (num4 ^ (uint)num5) * 16777619;
}
if (num4 != num3)
{
return null;
}
int num6 = binaryReader.ReadInt32();
HashSet<int> hashSet = new HashSet<int>();
for (int j = 0; j < num6; j++)
{
hashSet.Add(binaryReader.ReadInt32());
}
List<int> list = new List<int>(triangles.Length - num6 * 3);
for (int k = 0; k < triangles.Length; k += 3)
{
if (!hashSet.Contains(k / 3))
{
list.Add(triangles[k]);
list.Add(triangles[k + 1]);
list.Add(triangles[k + 2]);
}
}
Mesh val = Object.Instantiate<Mesh>(source);
((Object)val).name = "mdl_AltEliteHelm";
val.subMeshCount = 1;
val.SetTriangles(list, 0, false);
return val;
}
}
internal static class OldLegionGearReskin
{
private const string PluginId = "local.dylan.oldlegiongearreskin";
private const int GladiusId = 2000090;
private const int ShieldId = 2300070;
private static readonly int MainTex = Shader.PropertyToID("_MainTex");
private static readonly int GenTex = Shader.PropertyToID("_GenTex");
private static readonly int NormTex = Shader.PropertyToID("_NormTex");
private static readonly Dictionary<Material, Material> gladiusMaterials = new Dictionary<Material, Material>();
private static readonly Dictionary<Material, Material> shieldMaterials = new Dictionary<Material, Material>();
private static readonly Dictionary<Material, Material> donors = new Dictionary<Material, Material>();
private static Texture2D bladeColor;
private static Texture2D bladeSurface;
private static Texture2D bladeNormal;
private static Texture2D hiltColor;
private static Texture2D hiltSurface;
private static Texture2D hiltNormal;
private static Texture2D shieldColor;
private static Texture2D shieldSurface;
private static Texture2D shieldNormal;
private static Sprite gladiusIcon;
private static Sprite shieldIcon;
internal static void Initialize(ManualLogSource logger)
{
//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
//IL_00c2: Expected O, but got Unknown
bladeColor = LoadTexture("BladeAlbedo", linear: false);
bladeSurface = LoadTexture("BladeSurface", linear: true);
bladeNormal = LoadTexture("BladeNormal", linear: true);
hiltColor = LoadTexture("HiltAlbedo", linear: false);
hiltSurface = LoadTexture("HiltSurface", linear: true);
hiltNormal = LoadTexture("HiltNormal", linear: true);
shieldColor = LoadTexture("DarkLegionAlbedo", linear: false);
shieldSurface = LoadTexture("DarkLegionSurface", linear: true);
shieldNormal = LoadTexture("DarkLegionNormal", linear: true);
gladiusIcon = LoadIcon("GladiusIcon");
shieldIcon = LoadIcon("ShieldIcon");
Harmony val = new Harmony("local.dylan.oldlegiongearreskin");
val.Patch((MethodBase)AccessTools.Method(typeof(ItemVisual), "Awake", (Type[])null, (Type[])null), (HarmonyMethod)null, Hook("AfterVisualAwake"), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
val.Patch((MethodBase)AccessTools.Method(typeof(VisualSlot), "PositionVisuals", new Type[1] { typeof(Item) }, (Type[])null), (HarmonyMethod)null, Hook("AfterEquip", 0), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
val.Patch((MethodBase)AccessTools.Method(AccessTools.TypeByName("SideLoader.CustomItemVisuals"), "CloneAndSetVisuals", (Type[])null, (Type[])null), (HarmonyMethod)null, Hook("AfterSideLoaderClone", 800), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
val.Patch((MethodBase)AccessTools.Method(typeof(ResourcesPrefabManager), "GetItemIcon", new Type[1] { typeof(Item) }, (Type[])null), (HarmonyMethod)null, Hook("AfterGetIcon"), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
logger.LogInfo((object)"Old Legion Gladius and Old Legion Shield reskins registered.");
}
private static HarmonyMethod Hook(string method, int priority = 400)
{
//IL_000c: Unknown result type (might be due to invalid IL or missing references)
//IL_0012: Expected O, but got Unknown
HarmonyMethod val = new HarmonyMethod(typeof(OldLegionGearReskin), method, (Type[])null);
val.priority = priority;
return val;
}
private static Texture2D LoadTexture(string name, bool linear, bool mipmaps = true)
{
//IL_0005: Unknown result type (might be due to invalid IL or missing references)
//IL_000b: Expected O, but got Unknown
Texture2D val = new Texture2D(2, 2, (TextureFormat)4, mipmaps, linear);
((Object)val).name = name;
((Texture)val).anisoLevel = ((!mipmaps) ? 1 : 4);
Texture2D val2 = val;
using Stream stream = typeof(OldLegionGearReskin).Assembly.GetManifestResourceStream("OldLegionGearReskin." + name);
using MemoryStream memoryStream = new MemoryStream();
if (stream == null)
{
throw new InvalidDataException("Missing texture " + name);
}
stream.CopyTo(memoryStream);
if (!ImageConversion.LoadImage(val2, memoryStream.ToArray(), true))
{
throw new InvalidDataException("Could not decode " + name);
}
return val2;
}
private static Sprite LoadIcon(string name)
{
//IL_0022: 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)
Texture2D val = LoadTexture(name, linear: false, mipmaps: false);
return Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f), 100f, 0u, (SpriteMeshType)0);
}
private static bool IsOldLegion(int id)
{
if (id == 2000090 || id == 2300070)
{
return CoolerPlateArmors.Enabled(id);
}
return false;
}
private static void AfterVisualAwake(ItemVisual __instance)
{
int itemIDFromName = __instance.GetItemIDFromName();
if (IsOldLegion(itemIDFromName))
{
ApplyAppearance(((Component)__instance).gameObject, itemIDFromName);
}
}
private static void AfterEquip(VisualSlot __instance, Item __0)
{
if (Object.op_Implicit((Object)(object)__0) && IsOldLegion(__0.ItemID))
{
ItemVisual currentVisual = __instance.CurrentVisual;
if (Object.op_Implicit((Object)(object)currentVisual) && currentVisual.GetItemIDFromName() == __0.ItemID)
{
ApplyAppearance(((Component)currentVisual).gameObject, __0.ItemID);
}
}
}
private static void AfterSideLoaderClone(Item __0, GameObject __1, GameObject __result)
{
if (Object.op_Implicit((Object)(object)__0) && Object.op_Implicit((Object)(object)__result) && !((Object)(object)__result == (Object)(object)__1) && (IsOldLegion(__0.ItemID) || donors.Count > 0))
{
ApplyAppearance(__result, __0.ItemID);
}
}
private static void AfterGetIcon(Item __0, ref Sprite __result)
{
if (Object.op_Implicit((Object)(object)__0) && IsOldLegion(__0.ItemID))
{
if (__0.ItemID == 2000090)
{
__result = gladiusIcon;
}
else if (__0.ItemID == 2300070)
{
__result = shieldIcon;
}
}
}
private static void ApplyAppearance(GameObject model, int id)
{
Renderer[] componentsInChildren = model.GetComponentsInChildren<Renderer>(true);
foreach (Renderer val in componentsInChildren)
{
Material[] sharedMaterials = val.sharedMaterials;
bool flag = false;
for (int j = 0; j < sharedMaterials.Length; j++)
{
Material val2 = sharedMaterials[j];
if (Object.op_Implicit((Object)(object)val2))
{
if (!donors.TryGetValue(val2, out var value))
{
value = val2;
}
Material material = GetMaterial(value, id);
if ((Object)(object)val2 != (Object)(object)material)
{
sharedMaterials[j] = material;
flag = true;
}
}
}
if (flag)
{
val.sharedMaterials = sharedMaterials;
}
}
}
private static Material GetMaterial(Material original, int id)
{
if (!IsOldLegion(id))
{
return original;
}
if (id == 2300070 && ((Object)original).name.StartsWith("mat_itm_boneWeapons", StringComparison.OrdinalIgnoreCase))
{
return Replace(original, shieldMaterials, shieldColor, shieldSurface, shieldNormal);
}
if (id == 2000090 && ((Object)original).name.StartsWith("mat_itm_hugeSword", StringComparison.OrdinalIgnoreCase))
{
return Replace(original, gladiusMaterials, bladeColor, bladeSurface, bladeNormal);
}
if (id == 2000090 && ((Object)original).name.StartsWith("mat_env_atlasStoneOrnate", StringComparison.OrdinalIgnoreCase))
{
return Replace(original, gladiusMaterials, hiltColor, hiltSurface, hiltNormal);
}
return original;
}
private static Material Replace(Material original, Dictionary<Material, Material> cache, Texture2D color, Texture2D surface, Texture2D normal)
{
//IL_000e: Unknown result type (might be due to invalid IL or missing references)
//IL_0014: Expected O, but got Unknown
if (cache.TryGetValue(original, out var value))
{
return value;
}
Material val = new Material(original);
((Object)val).name = ((Object)color).name + " (Old Legion)";
value = val;
value.SetTexture(MainTex, (Texture)(object)color);
value.SetTexture(GenTex, (Texture)(object)surface);
if (Object.op_Implicit((Object)(object)normal))
{
value.SetTexture(NormTex, (Texture)(object)normal);
}
if (cache == gladiusMaterials || cache == shieldMaterials)
{
value.DisableKeyword("_DETAIL");
value.DisableKeyword("_DETAIL_ALBEDO");
value.DisableKeyword("_DETAIL_MASK");
value.DisableKeyword("_DETAIL_MULX2");
value.DisableKeyword("_DETAIL_TEXTURED");
value.DisableKeyword("_SPEC_COLOR");
value.EnableKeyword("_NORMALMAP");
value.EnableKeyword("_SPECGLOSSMAP");
value.SetFloat("_SpecBoost", 0.015f);
value.SetFloat("_GlossMin", 0.035f);
if (value.HasProperty("_SmoothMin"))
{
value.SetFloat("_SmoothMin", 0.035f);
}
if (cache == gladiusMaterials)
{
Debug.Log((object)("Old Legion Gladius applied " + ((Object)color).name + " to " + ((Object)original).name + "."));
}
}
cache.Add(original, value);
donors.Add(value, original);
return value;
}
}