using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.0.0")]
[module: UnverifiableCode]
namespace ValheimSkapekeysAndMore;
public static class HelperMethods
{
public enum ItemType
{
RIGHTHAND,
RIGHTBACK,
LEFTHAND,
LEFTBACK,
CHEST,
LEGS,
HEAD,
SHOULDER,
UTILITY
}
public static void TryAttachOther(ref VisEquipment vis, SharedData shared, GameObject go, int variant, int numOfVariants, int level, int maxLevel)
{
Transform val = RecursiveSearchFunctions.ChildNodeFinderBreadthFirst(go.transform, "attach_other", contains: true);
if (!((Object)(object)val != (Object)null))
{
return;
}
GameObject go2 = Object.Instantiate<GameObject>(((Component)val).gameObject);
Transform val2 = null;
Transform[] array = null;
val2 = TryApplyChildStyle(ref go2, variant, numOfVariants);
if ((Object)(object)val2 != (Object)null)
{
GameObject go3 = ((Component)((Component)val2).transform).gameObject;
array = TryApplyChildLevel(ref go3, level, maxLevel);
if (array != null)
{
Transform[] array2 = array;
foreach (Transform val3 in array2)
{
GameObject __result = ((Component)((Component)val3).transform).gameObject;
VisEquipment.EnableEquippedEffects(__result);
ApplySexBasedSettings(vis, ref __result);
}
}
else
{
VisEquipment.EnableEquippedEffects(go3);
ApplySexBasedSettings(vis, ref go3);
}
}
else
{
array = TryApplyChildLevel(ref go2, level, maxLevel);
if (array != null)
{
Transform[] array3 = array;
foreach (Transform val4 in array3)
{
GameObject __result2 = ((Component)((Component)val4).transform).gameObject;
VisEquipment.EnableEquippedEffects(__result2);
ApplySexBasedSettings(vis, ref __result2);
}
}
}
go2.SetActive(true);
VisEquipment.CleanupInstance(go2);
AttachOther(vis, shared, go2.transform);
}
private static void AttachOther(VisEquipment vis, SharedData shared, Transform objectTransform)
{
//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
//IL_00d4: Invalid comparison between Unknown and I4
//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
//IL_00e6: 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_00ea: Unknown result type (might be due to invalid IL or missing references)
//IL_00ee: Invalid comparison between Unknown and I4
//IL_00dd: 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_0115: Unknown result type (might be due to invalid IL or missing references)
//IL_0119: Invalid comparison between Unknown and I4
//IL_00f0: 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_0105: Expected I4, but got Unknown
//IL_03a0: 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_0232: Unknown result type (might be due to invalid IL or missing references)
//IL_0328: Unknown result type (might be due to invalid IL or missing references)
//IL_03c9: Unknown result type (might be due to invalid IL or missing references)
//IL_0120: Unknown result type (might be due to invalid IL or missing references)
//IL_0124: Invalid comparison between Unknown and I4
//IL_0165: Unknown result type (might be due to invalid IL or missing references)
//IL_025b: Unknown result type (might be due to invalid IL or missing references)
//IL_0351: Unknown result type (might be due to invalid IL or missing references)
//IL_0107: Unknown result type (might be due to invalid IL or missing references)
//IL_010b: Invalid comparison between Unknown and I4
//IL_040b: Unknown result type (might be due to invalid IL or missing references)
//IL_03fc: Unknown result type (might be due to invalid IL or missing references)
//IL_02ad: Unknown result type (might be due to invalid IL or missing references)
//IL_0198: Unknown result type (might be due to invalid IL or missing references)
//IL_028e: Unknown result type (might be due to invalid IL or missing references)
//IL_0384: 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_02d6: Unknown result type (might be due to invalid IL or missing references)
//IL_01e0: Unknown result type (might be due to invalid IL or missing references)
//IL_0309: Unknown result type (might be due to invalid IL or missing references)
//IL_0213: Unknown result type (might be due to invalid IL or missing references)
VisEquipmentOther component = ((Component)vis).GetComponent<VisEquipmentOther>();
if ((Object)(object)component == (Object)null)
{
return;
}
float result = 0f;
if (((Object)objectTransform).name.Contains("["))
{
string text = ((Object)objectTransform).name.Substring(1 + ((Object)objectTransform).name.IndexOf('['), ((Object)objectTransform).name.IndexOf(']') - ((Object)objectTransform).name.IndexOf('[') - 1);
if (text[0] == 'R')
{
result = ((!float.TryParse(text.Substring(1), out result)) ? 0f : (result * -1f));
}
else if (!float.TryParse(text, out result))
{
result = 0f;
}
}
ItemType val = shared.m_attachOverride;
if ((int)val == 0)
{
val = shared.m_itemType;
}
ItemType val2 = val;
ItemType val3 = val2;
if ((int)val3 <= 14)
{
switch (val3 - 3)
{
default:
if ((int)val3 != 14)
{
break;
}
objectTransform.SetParent(component.backTwohandedMeleeOther);
objectTransform.localRotation = Quaternion.identity;
if (result != 0f)
{
objectTransform.localRotation = Quaternion.Euler(0f, result, 0f);
if ((Object)(object)vis.m_rightBackItemInstance != (Object)null)
{
vis.m_rightBackItemInstance.transform.localRotation = Quaternion.Euler(0f, result, 0f);
}
}
break;
case 0:
objectTransform.SetParent(component.backMeleeOther);
objectTransform.localRotation = Quaternion.identity;
if (result != 0f)
{
objectTransform.localRotation = Quaternion.Euler(0f, result, 0f);
if ((Object)(object)vis.m_rightBackItemInstance != (Object)null)
{
vis.m_rightBackItemInstance.transform.localRotation = Quaternion.Euler(0f, result, 0f);
}
}
break;
case 1:
objectTransform.SetParent(component.backBowOther);
objectTransform.localRotation = Quaternion.identity;
if (result != 0f)
{
objectTransform.localRotation = Quaternion.Euler(0f, result, 0f);
if ((Object)(object)vis.m_rightBackItemInstance != (Object)null)
{
vis.m_rightBackItemInstance.transform.localRotation = Quaternion.Euler(0f, result, 0f);
}
}
break;
case 2:
objectTransform.SetParent(component.backShieldOther);
objectTransform.localRotation = Quaternion.identity;
if (result != 0f)
{
objectTransform.localRotation = Quaternion.Euler(0f, result, 0f);
if ((Object)(object)vis.m_leftBackItemInstance != (Object)null)
{
vis.m_leftBackItemInstance.transform.localRotation = Quaternion.Euler(0f, result, 0f);
}
}
break;
}
}
else if ((int)val3 != 19)
{
if ((int)val3 == 20)
{
objectTransform.SetParent(component.backAtgeirOther);
objectTransform.localRotation = Quaternion.identity;
if (result != 0f)
{
objectTransform.localRotation = Quaternion.Euler(0f, result, 0f);
if ((Object)(object)vis.m_rightBackItemInstance != (Object)null)
{
vis.m_rightBackItemInstance.transform.localRotation = Quaternion.Euler(0f, result, 0f);
}
}
}
}
else
{
objectTransform.SetParent(component.backToolOther);
objectTransform.localRotation = Quaternion.identity;
if (result != 0f)
{
objectTransform.localRotation = Quaternion.Euler(0f, result, 0f);
if ((Object)(object)vis.m_rightBackItemInstance != (Object)null)
{
vis.m_rightBackItemInstance.transform.localRotation = Quaternion.Euler(0f, result, 0f);
}
}
}
objectTransform.localPosition = Vector3.zero;
}
public static void ClearAttachOthers(ref VisEquipment vs)
{
VisEquipmentOther component = ((Component)vs).GetComponent<VisEquipmentOther>();
if (!((Object)(object)component == (Object)null))
{
ClearAttach(component.backAtgeirOther);
ClearAttach(component.backBowOther);
ClearAttach(component.backMeleeOther);
ClearAttach(component.backShieldOther);
ClearAttach(component.backToolOther);
ClearAttach(component.backTwohandedMeleeOther);
}
}
private static void ClearAttach(Transform t)
{
if ((Object)(object)t != (Object)null)
{
while (t.childCount > 0)
{
Transform child = t.GetChild(0);
child.SetParent((Transform)null);
Object.Destroy((Object)(object)((Component)child).gameObject);
}
}
}
private static void TryApplyFemaleShapeKey(SkinnedMeshRenderer smr)
{
int num = -1;
Mesh sharedMesh = smr.sharedMesh;
if (sharedMesh.blendShapeCount <= 0)
{
return;
}
for (int i = 0; i < sharedMesh.blendShapeCount; i++)
{
if (sharedMesh.GetBlendShapeName(i).IndexOf("female", StringComparison.OrdinalIgnoreCase) >= 0)
{
num = i;
break;
}
}
if (num >= 0)
{
smr.SetBlendShapeWeight(num, 100f);
}
}
private static void EnableSexBasedChildren(ref GameObject go, bool male, bool female)
{
if (go.transform.childCount <= 0)
{
return;
}
for (int i = 0; i < go.transform.childCount; i++)
{
Transform child = go.transform.GetChild(i);
string name = ((Object)child).name;
bool flag = name.IndexOf("male", StringComparison.OrdinalIgnoreCase) >= 0 && name.IndexOf("female", StringComparison.OrdinalIgnoreCase) == -1;
bool flag2 = name.IndexOf("male", StringComparison.OrdinalIgnoreCase) == -1;
if (male && !flag2)
{
if (flag)
{
((Component)child).gameObject.SetActive(true);
}
else
{
((Component)child).gameObject.SetActive(false);
}
}
if (female && !flag2)
{
if (!flag)
{
((Component)child).gameObject.SetActive(true);
}
else
{
((Component)child).gameObject.SetActive(false);
}
}
}
}
private static void CheckVisEquipmentModelsSex(out bool male, out bool female, PlayerModel[] models, int index)
{
switch (models.Length)
{
case 2:
male = index == 0;
female = index == 1;
break;
case 1:
male = !((Object)models[0].m_mesh).name.Contains("fem");
female = ((Object)models[0].m_mesh).name.Contains("fem");
break;
default:
male = false;
female = false;
break;
}
}
public static void ApplySexBasedSettings(VisEquipment __instance, ref GameObject __result)
{
try
{
if (!((Object)(object)__result != (Object)null))
{
return;
}
bool male = false;
bool female = false;
if (__instance.m_models != null)
{
CheckVisEquipmentModelsSex(out male, out female, __instance.m_models, __instance.m_modelIndex);
}
else
{
ZNetView component = ((Component)__instance).gameObject.GetComponent<ZNetView>();
if ((Object)(object)component != (Object)null)
{
male = component.GetZDO().GetBool("isMale", false);
female = component.GetZDO().GetBool("isFemale", false);
}
}
if (female)
{
SkinnedMeshRenderer component2 = __result.GetComponent<SkinnedMeshRenderer>();
if ((Object)(object)component2 != (Object)null && female)
{
TryApplyFemaleShapeKey(component2);
}
SkinnedMeshRenderer[] componentsInChildren = __result.GetComponentsInChildren<SkinnedMeshRenderer>();
if (componentsInChildren != null && componentsInChildren.Length != 0)
{
for (int i = 0; i < componentsInChildren.Length; i++)
{
TryApplyFemaleShapeKey(componentsInChildren[i]);
}
}
}
EnableSexBasedChildren(ref __result, male, female);
}
catch (Exception ex)
{
Plugin.Log.LogError((object)"Error in ApplySexBasedSettings, exception handled. Below is the stacktrace.");
Plugin.Log.LogError((object)ex.StackTrace);
}
}
public static Transform TryApplyChildStyle(ref GameObject go, int variant, int numberOfVariants)
{
Transform result = null;
string text = "style_" + variant;
List<Transform> nestedTargets = new List<Transform>();
RecursiveSearchFunctions.ChildNodesFinderBreadthFirst(go.transform, "style_", numberOfVariants, ref nestedTargets, contains: true);
if (nestedTargets != null && nestedTargets.Count > 0)
{
foreach (Transform item in nestedTargets)
{
if (((Object)item).name == text)
{
GameObject gameObject = ((Component)item).gameObject;
gameObject.SetActive(true);
result = gameObject.transform;
}
else
{
((Component)item).gameObject.SetActive(false);
}
}
}
return result;
}
public static Transform[] TryApplyChildLevel(ref GameObject go, int level, int maxLevel)
{
List<Transform> list = new List<Transform>();
int num = level - 1;
List<Transform> nestedTargets = new List<Transform>();
RecursiveSearchFunctions.ChildNodesFinderDepthFirst(go.transform, "level_", ref maxLevel, ref nestedTargets, contains: true);
if (nestedTargets.Count > 0)
{
int num2 = -1;
List<KeyValuePair<int, Transform>> list2 = new List<KeyValuePair<int, Transform>>();
for (int num3 = nestedTargets.Count - 1; num3 >= 0; num3--)
{
if (((Object)nestedTargets[num3]).name.StartsWith("level_"))
{
string[] array = ((Object)nestedTargets[num3]).name.Split(new char[1] { '_' });
if (array.Length > 1)
{
if (array[1].IndexOf('-') > -1)
{
string[] array2 = array[1].Split(new char[1] { '-' });
int num4 = int.Parse(array2[0]);
int num5 = int.Parse(array2[1]);
if (num4 > num2)
{
num2 = num4;
}
if (num5 > num2)
{
num2 = num5;
}
if (num4 == num2 || num5 == num2)
{
list2.Add(new KeyValuePair<int, Transform>(num2, nestedTargets[num3]));
}
if (num >= num4 && num <= num5)
{
((Component)nestedTargets[num3]).gameObject.SetActive(true);
list.Add(nestedTargets[num3]);
}
else
{
((Component)nestedTargets[num3]).gameObject.SetActive(false);
}
}
else
{
int num6 = int.Parse(array[1]);
if (num6 > num2)
{
num2 = num6;
}
if (num6 == num2)
{
list2.Add(new KeyValuePair<int, Transform>(num2, nestedTargets[num3]));
}
if (num == num6)
{
((Component)nestedTargets[num3]).gameObject.SetActive(true);
list.Add(nestedTargets[num3]);
}
else
{
((Component)nestedTargets[num3]).gameObject.SetActive(false);
}
}
}
}
}
if (list2.Count > 0)
{
foreach (KeyValuePair<int, Transform> item in list2)
{
if (item.Key == num2 && num >= num2)
{
if (!list.Contains(item.Value))
{
((Component)item.Value).gameObject.SetActive(true);
list.Add(item.Value);
}
else
{
((Component)item.Value).gameObject.SetActive(true);
}
}
else
{
((Component)item.Value).gameObject.SetActive(false);
}
}
}
}
return (list.Count > 0) ? list.ToArray() : null;
}
public static void GetItemDataFromHumanoid(Humanoid humanoid, ItemType itemType, out ItemData id, out string zdoKey)
{
switch (itemType)
{
case ItemType.RIGHTHAND:
id = humanoid.m_rightItem;
zdoKey = "RightItem";
break;
case ItemType.RIGHTBACK:
id = humanoid.m_hiddenRightItem;
zdoKey = "RightBackItem";
break;
case ItemType.LEFTHAND:
id = humanoid.m_leftItem;
zdoKey = "LeftItem";
break;
case ItemType.LEFTBACK:
id = humanoid.m_hiddenLeftItem;
zdoKey = "LeftBackItem";
break;
case ItemType.CHEST:
id = humanoid.m_chestItem;
zdoKey = "ChestItem";
break;
case ItemType.HEAD:
id = humanoid.m_helmetItem;
zdoKey = "HelmetItem";
break;
case ItemType.SHOULDER:
id = humanoid.m_shoulderItem;
zdoKey = "ShoulderItem";
break;
case ItemType.UTILITY:
id = humanoid.m_utilityItem;
zdoKey = "UtilityItem";
break;
case ItemType.LEGS:
id = humanoid.m_legItem;
zdoKey = "LegItem";
break;
default:
id = null;
zdoKey = "";
break;
}
}
public static void SetItemLevelZDO(ZDO zdo, ItemData id, string zdoName)
{
if (!string.IsNullOrEmpty(zdoName))
{
if (id != null)
{
int quality = id.m_quality;
int maxQuality = id.m_shared.m_maxQuality;
zdo.Set(zdoName + "LevelHTD", quality);
zdo.Set(zdoName + "MaxLevelHTD", maxQuality);
}
else
{
zdo.Set(zdoName + "LevelHTD", 0);
zdo.Set(zdoName + "MaxLevelHTD", 1);
}
}
}
public static void SetItemVariantZDO(ZDO zdo, ItemData id, string zdoName, bool isVanilla = false)
{
if (!string.IsNullOrEmpty(zdoName))
{
if (id != null)
{
int variant = id.m_variant;
int variants = id.m_shared.m_variants;
zdo.Set(zdoName + "Variant" + (isVanilla ? "" : "HTD"), variant);
zdo.Set(zdoName + "MaxVariantHTD", variants);
}
else
{
zdo.Set(zdoName + "Variant" + (isVanilla ? "" : "HTD"), 0);
zdo.Set(zdoName + "MaxVariantHTD", 1);
}
}
}
public static bool TryApply(ref VisEquipment vis, ref GameObject obj, int hash, string zdoName, int variant, int maxVariant, int level, int maxLevel, bool vanillaVariant = false)
{
bool result = false;
if ((Object)(object)obj != (Object)null)
{
Transform val = null;
Transform[] array = null;
Material val2 = null;
bool flag = zdoName.StartsWith("Chest");
bool flag2 = zdoName.StartsWith("Leg");
val = TryApplyChildStyle(ref obj, variant, maxVariant);
if ((Object)(object)val != (Object)null)
{
GameObject go = ((Component)((Component)val).transform).gameObject;
SkinnedMeshRenderer[] componentsInChildren = go.GetComponentsInChildren<SkinnedMeshRenderer>(true);
foreach (SkinnedMeshRenderer val3 in componentsInChildren)
{
val3.rootBone = vis.m_bodyModel.rootBone;
val3.bones = vis.m_bodyModel.bones;
}
Cloth[] componentsInChildren2 = go.GetComponentsInChildren<Cloth>(true);
foreach (Cloth val4 in componentsInChildren2)
{
if (vis.m_clothColliders.Length != 0 && val4.capsuleColliders.Length < vis.m_clothColliders.Length)
{
if (val4.capsuleColliders.Length != 0)
{
List<CapsuleCollider> list = new List<CapsuleCollider>(vis.m_clothColliders);
list.AddRange(val4.capsuleColliders);
val4.capsuleColliders = list.ToArray();
}
else
{
val4.capsuleColliders = vis.m_clothColliders;
}
}
}
array = TryApplyChildLevel(ref go, level, maxLevel);
if (array != null)
{
Transform[] array2 = array;
foreach (Transform val5 in array2)
{
GameObject __result = ((Component)((Component)val5).transform).gameObject;
VisEquipment.EnableEquippedEffects(__result);
ApplySexBasedSettings(vis, ref __result);
VisEquipment.CleanupInstance(__result);
result = true;
}
}
else
{
VisEquipment.EnableEquippedEffects(go);
ApplySexBasedSettings(vis, ref go);
VisEquipment.CleanupInstance(go);
result = true;
}
}
else
{
array = TryApplyChildLevel(ref obj, level, maxLevel);
if (array != null)
{
Transform[] array3 = array;
foreach (Transform val6 in array3)
{
GameObject __result2 = ((Component)((Component)val6).transform).gameObject;
SkinnedMeshRenderer[] componentsInChildren3 = __result2.GetComponentsInChildren<SkinnedMeshRenderer>(true);
foreach (SkinnedMeshRenderer val7 in componentsInChildren3)
{
val7.rootBone = vis.m_bodyModel.rootBone;
val7.bones = vis.m_bodyModel.bones;
}
Cloth[] componentsInChildren4 = __result2.GetComponentsInChildren<Cloth>(true);
foreach (Cloth val8 in componentsInChildren4)
{
if (vis.m_clothColliders.Length != 0 && val8.capsuleColliders.Length < vis.m_clothColliders.Length)
{
if (val8.capsuleColliders.Length != 0)
{
List<CapsuleCollider> list2 = new List<CapsuleCollider>(vis.m_clothColliders);
list2.AddRange(val8.capsuleColliders);
val8.capsuleColliders = list2.ToArray();
}
else
{
val8.capsuleColliders = vis.m_clothColliders;
}
}
}
VisEquipment.EnableEquippedEffects(__result2);
ApplySexBasedSettings(vis, ref __result2);
result = true;
}
}
}
if (flag || flag2)
{
if (array != null)
{
List<Material> list3 = new List<Material>();
Transform[] array4 = array;
foreach (Transform target in array4)
{
Transform val9 = RecursiveSearchFunctions.ChildNodeFinderBreadthFirst(target, "armormat");
if ((Object)(object)val9 != (Object)null)
{
MeshRenderer component = ((Component)val9).gameObject.GetComponent<MeshRenderer>();
if ((Object)(object)component != (Object)null)
{
list3.Add(((Renderer)component).sharedMaterial);
}
}
}
if (list3.Count > 0)
{
val2 = list3[list3.Count - 1];
}
}
else if ((Object)(object)val != (Object)null && (Object)(object)val2 == (Object)null)
{
Transform val10 = RecursiveSearchFunctions.ChildNodeFinderBreadthFirst(val, "armormat");
if ((Object)(object)val10 != (Object)null)
{
val2 = ((Renderer)((Component)val10).GetComponent<MeshRenderer>()).sharedMaterial;
}
}
if (flag)
{
ApplyArmorMat(vis, hash, chest: true, val2);
}
if (flag2)
{
ApplyArmorMat(vis, hash, chest: false, val2);
}
}
}
return result;
}
public static void ApplyArmorMat(VisEquipment vis, int hash, bool chest, Material armorMat = null)
{
int modelIndex = vis.GetModelIndex();
string text = "";
if (modelIndex == 1)
{
text = "Female";
}
Material val = armorMat;
if ((Object)(object)val == (Object)null)
{
GameObject itemPrefab = ObjectDB.instance.GetItemPrefab(hash);
if ((Object)(object)itemPrefab != (Object)null)
{
ItemDrop component = itemPrefab.GetComponent<ItemDrop>();
if ((Object)(object)component != (Object)null)
{
val = component.m_itemData.m_shared.m_armorMaterial;
}
}
}
if (!((Object)(object)val != (Object)null))
{
return;
}
if (chest)
{
if (val.HasProperty("_ChestTex" + text) && (Object)(object)val.GetTexture("_ChestTex" + text) != (Object)null)
{
((Renderer)vis.m_bodyModel).material.SetTexture("_ChestTex", val.GetTexture("_ChestTex" + text));
((Renderer)vis.m_bodyModel).material.SetTexture("_ChestBumpMap", val.GetTexture("_ChestBumpMap" + text));
((Renderer)vis.m_bodyModel).material.SetTexture("_ChestMetal", val.GetTexture("_ChestMetal" + text));
}
else if (val.HasProperty("_ChestTex") && (Object)(object)val.GetTexture("_ChestTex") != (Object)null)
{
((Renderer)vis.m_bodyModel).material.SetTexture("_ChestTex", val.GetTexture("_ChestTex"));
((Renderer)vis.m_bodyModel).material.SetTexture("_ChestBumpMap", val.GetTexture("_ChestBumpMap"));
((Renderer)vis.m_bodyModel).material.SetTexture("_ChestMetal", val.GetTexture("_ChestMetal"));
}
}
else if (val.HasProperty("_LegsTex" + text) && (Object)(object)val.GetTexture("_LegsTex" + text) != (Object)null)
{
((Renderer)vis.m_bodyModel).material.SetTexture("_LegsTex", val.GetTexture("_LegsTex" + text));
((Renderer)vis.m_bodyModel).material.SetTexture("_LegsBumpMap", val.GetTexture("_LegsBumpMap" + text));
((Renderer)vis.m_bodyModel).material.SetTexture("_LegsMetal", val.GetTexture("_LegsMetal" + text));
}
else if (val.HasProperty("_LegsTex") && (Object)(object)val.GetTexture("_LegsTex") != (Object)null)
{
((Renderer)vis.m_bodyModel).material.SetTexture("_LegsTex", val.GetTexture("_LegsTex"));
((Renderer)vis.m_bodyModel).material.SetTexture("_LegsBumpMap", val.GetTexture("_LegsBumpMap"));
((Renderer)vis.m_bodyModel).material.SetTexture("_LegsMetal", val.GetTexture("_LegsMetal"));
}
}
private static void GetVariantAndLevelValues(ZDO zdo, ItemData id, string zdoName, out int variant, out int maxVariant, out int level, out int maxLevel, bool vanillaVariant = false)
{
variant = 0;
maxVariant = 0;
level = 1;
maxLevel = 4;
if (zdo != null)
{
variant = zdo.GetInt(zdoName + "Variant" + (vanillaVariant ? "" : "HTD"), 0);
maxVariant = zdo.GetInt(zdoName + "MaxVariantHTD", 1);
level = zdo.GetInt(zdoName + "LevelHTD", 1);
maxLevel = zdo.GetInt(zdoName + "MaxLevelHTD", 4);
}
else if (id != null)
{
variant = id.m_variant;
maxVariant = id.m_shared.m_variants;
level = id.m_quality;
maxLevel = id.m_shared.m_maxQuality;
}
}
public static void ApplyVisualEffects(VisEquipment vis)
{
ZNetView nview = vis.m_nview;
ZDO zdo = ((nview != null) ? nview.GetZDO() : null);
bool flag = false;
ClearAttachOthers(ref vis);
int variant = 0;
int maxVariant = 0;
int level = 1;
int maxLevel = 4;
Humanoid component = ((Component)vis).gameObject.GetComponent<Humanoid>();
string zdoName;
if (vis.m_chestItemInstances != null && vis.m_chestItemInstances.Count > 0)
{
zdoName = "ChestItem";
GetVariantAndLevelValues(zdo, component?.m_chestItem, zdoName, out variant, out maxVariant, out level, out maxLevel);
for (int i = 0; i < vis.m_chestItemInstances.Count; i++)
{
GameObject obj = vis.m_chestItemInstances[i];
if (!TryApply(ref vis, ref obj, vis.m_currentChestItemHash, zdoName, variant, maxVariant, level, maxLevel))
{
ApplyArmorMat(vis, vis.m_currentChestItemHash, chest: true);
}
flag = false;
}
}
if (vis.m_legItemInstances != null && vis.m_legItemInstances.Count > 0)
{
zdoName = "LegItem";
GetVariantAndLevelValues(zdo, component?.m_legItem, zdoName, out variant, out maxVariant, out level, out maxLevel);
for (int j = 0; j < vis.m_legItemInstances.Count; j++)
{
GameObject obj2 = vis.m_legItemInstances[j];
if (!TryApply(ref vis, ref obj2, vis.m_currentLegItemHash, zdoName, variant, maxVariant, level, maxLevel))
{
ApplyArmorMat(vis, vis.m_currentLegItemHash, chest: false);
}
flag = false;
}
}
if ((Object)(object)vis.m_helmetItemInstance != (Object)null)
{
zdoName = "HelmetItem";
GetVariantAndLevelValues(zdo, component?.m_helmetItem, zdoName, out variant, out maxVariant, out level, out maxLevel);
TryApply(ref vis, ref vis.m_helmetItemInstance, vis.m_currentHelmetItemHash, zdoName, variant, maxVariant, level, maxLevel);
}
if (vis.m_shoulderItemInstances != null && vis.m_shoulderItemInstances.Count > 0)
{
zdoName = "ShoulderItem";
GetVariantAndLevelValues(zdo, component?.m_shoulderItem, zdoName, out variant, out maxVariant, out level, out maxLevel, vanillaVariant: true);
for (int k = 0; k < vis.m_shoulderItemInstances.Count; k++)
{
GameObject obj3 = vis.m_shoulderItemInstances[k];
TryApply(ref vis, ref obj3, vis.m_currentShoulderItemHash, zdoName, variant, maxVariant, level, maxLevel, vanillaVariant: true);
}
}
if (vis.m_utilityItemInstances != null && vis.m_utilityItemInstances.Count > 0)
{
zdoName = "UtilityItem";
GetVariantAndLevelValues(zdo, component?.m_utilityItem, zdoName, out variant, out maxVariant, out level, out maxLevel);
for (int l = 0; l < vis.m_utilityItemInstances.Count; l++)
{
GameObject obj4 = vis.m_utilityItemInstances[l];
TryApply(ref vis, ref obj4, vis.m_currentUtilityItemHash, zdoName, variant, maxVariant, level, maxLevel);
}
}
if ((Object)(object)vis.m_rightItemInstance != (Object)null)
{
zdoName = "RightItem";
GetVariantAndLevelValues(zdo, component?.m_rightItem, zdoName, out variant, out maxVariant, out level, out maxLevel);
TryApply(ref vis, ref vis.m_rightItemInstance, vis.m_currentRightItemHash, zdoName, variant, maxVariant, level, maxLevel);
GameObject itemPrefab = ObjectDB.instance.GetItemPrefab(vis.m_currentRightItemHash);
if ((Object)(object)itemPrefab != (Object)null)
{
ItemDrop component2 = itemPrefab.GetComponent<ItemDrop>();
if ((Object)(object)component2 != (Object)null)
{
TryAttachOther(ref vis, component2.m_itemData.m_shared, itemPrefab, variant, maxVariant, level, maxLevel);
}
}
}
if ((Object)(object)vis.m_rightBackItemInstance != (Object)null)
{
zdoName = "RightBackItem";
GetVariantAndLevelValues(zdo, component?.m_hiddenRightItem, zdoName, out variant, out maxVariant, out level, out maxLevel);
TryApply(ref vis, ref vis.m_rightBackItemInstance, vis.m_currentRightBackItemHash, zdoName, variant, maxVariant, level, maxLevel);
GameObject itemPrefab2 = ObjectDB.instance.GetItemPrefab(vis.m_currentRightBackItemHash);
if ((Object)(object)itemPrefab2 != (Object)null)
{
ItemDrop component3 = itemPrefab2.GetComponent<ItemDrop>();
if ((Object)(object)component3 != (Object)null)
{
TryAttachOther(ref vis, component3.m_itemData.m_shared, itemPrefab2, variant, maxVariant, level, maxLevel);
}
}
}
if ((Object)(object)vis.m_leftItemInstance != (Object)null)
{
zdoName = "LeftItem";
GetVariantAndLevelValues(zdo, component?.m_leftItem, zdoName, out variant, out maxVariant, out level, out maxLevel, vanillaVariant: true);
TryApply(ref vis, ref vis.m_leftItemInstance, vis.m_currentLeftItemHash, zdoName, variant, maxVariant, level, maxLevel, vanillaVariant: true);
GameObject itemPrefab3 = ObjectDB.instance.GetItemPrefab(vis.m_currentLeftItemHash);
if ((Object)(object)itemPrefab3 != (Object)null)
{
ItemDrop component4 = itemPrefab3.GetComponent<ItemDrop>();
if ((Object)(object)component4 != (Object)null)
{
TryAttachOther(ref vis, component4.m_itemData.m_shared, itemPrefab3, variant, maxVariant, level, maxLevel);
}
}
}
if (!((Object)(object)vis.m_leftBackItemInstance != (Object)null))
{
return;
}
zdoName = "LeftBackItem";
GetVariantAndLevelValues(zdo, component?.m_hiddenLeftItem, zdoName, out variant, out maxVariant, out level, out maxLevel, vanillaVariant: true);
TryApply(ref vis, ref vis.m_leftBackItemInstance, vis.m_currentLeftBackItemHash, zdoName, variant, maxVariant, level, maxLevel, vanillaVariant: true);
GameObject itemPrefab4 = ObjectDB.instance.GetItemPrefab(vis.m_currentLeftBackItemHash);
if ((Object)(object)itemPrefab4 != (Object)null)
{
ItemDrop component5 = itemPrefab4.GetComponent<ItemDrop>();
if ((Object)(object)component5 != (Object)null)
{
TryAttachOther(ref vis, component5.m_itemData.m_shared, itemPrefab4, variant, maxVariant, level, maxLevel);
}
}
}
}
[HarmonyPatch]
public class HumanoidPatch
{
[HarmonyPatch(typeof(Humanoid), "OnRagdollCreated")]
[HarmonyPrefix]
public static void OnRagdollCreatedPrefix(Humanoid __instance, Ragdoll ragdoll)
{
//IL_020e: Unknown result type (might be due to invalid IL or missing references)
//IL_0222: Unknown result type (might be due to invalid IL or missing references)
//IL_0227: Unknown result type (might be due to invalid IL or missing references)
//IL_022c: 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_0244: 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)
if ((Object)(object)ragdoll == (Object)null || ((Character)__instance).m_level == 1)
{
return;
}
int num = 1;
try
{
num++;
string prefabName = Utils.GetPrefabName(((Component)__instance).gameObject);
num++;
LevelEffects componentInChildren = ZNetScene.instance.GetPrefab(prefabName).GetComponentInChildren<LevelEffects>();
string nodeName = null;
string nodeName2 = null;
if ((Object)(object)componentInChildren != (Object)null)
{
num++;
if (((Character)__instance).m_level <= 3)
{
num++;
int num2 = ((Character)__instance).m_level - 2;
num++;
if ((Object)(object)componentInChildren.m_baseEnableObject != (Object)null)
{
nodeName = ((Object)componentInChildren.m_baseEnableObject).name;
}
num++;
if (componentInChildren.m_levelSetups == null && componentInChildren.m_levelSetups.Count > 0 && componentInChildren.m_levelSetups.Count >= num2 + 1)
{
num++;
LevelSetup val = componentInChildren.m_levelSetups[num2];
num++;
if ((Object)(object)val.m_enableObject != (Object)null)
{
nodeName2 = ((Object)val.m_enableObject).name;
}
}
}
else
{
num++;
LevelSetup val2 = componentInChildren.m_levelSetups[componentInChildren.m_levelSetups.Count - 1];
num++;
if ((Object)(object)val2.m_enableObject != (Object)null)
{
nodeName2 = ((Object)val2.m_enableObject).name;
}
}
if (nodeName != null)
{
num++;
Transform val3 = RecursiveSearchFunctions.ChildNodeFinderDepthFirst(((Component)ragdoll).gameObject.transform, ref nodeName);
num++;
if ((Object)(object)val3 != (Object)null)
{
num++;
((Component)((Component)val3).transform).gameObject.SetActive(false);
num++;
}
}
if (nodeName2 != null)
{
num++;
Transform val4 = RecursiveSearchFunctions.ChildNodeFinderDepthFirst(((Component)ragdoll).transform, ref nodeName2);
num++;
if ((Object)(object)val4 != (Object)null)
{
num++;
((Component)((Component)val4).transform).gameObject.SetActive(true);
}
}
}
num++;
Vector3 val5 = ((Component)__instance).transform.localScale - new Vector3(1f, 1f, 1f);
num++;
Transform transform = ((Component)ragdoll).gameObject.transform;
transform.localScale += val5;
}
catch (Exception ex)
{
Plugin.Log.LogWarning((object)"And Error as Occurred in Humanoid/RagdollCreated Patch, This error was caught and won't interupt flow.");
Plugin.Log.LogError((object)$"Exception Thrown: {ex.GetType()} last line executed: {num}");
Plugin.Log.LogError((object)ex.Message);
Plugin.Log.LogError((object)ex.StackTrace);
Plugin.Log.LogMessage((object)"End of logged Exception");
}
}
}
[HarmonyPatch]
internal class ItemDropPatch
{
[HarmonyPatch(typeof(ItemDrop), "Start")]
[HarmonyPostfix]
public static void ItemDropStartPostfix(ItemDrop __instance)
{
Transform val = null;
Transform[] array = null;
List<GameObject> list = new List<GameObject>();
Transform val2 = RecursiveSearchFunctions.ChildNodeFinderBreadthFirst(((Component)__instance).gameObject.transform, "attach");
if ((Object)(object)val2 != (Object)null)
{
list.Add(((Component)((Component)val2).transform).gameObject);
}
Transform val3 = RecursiveSearchFunctions.ChildNodeFinderBreadthFirst(((Component)__instance).gameObject.transform, "attach_other");
if ((Object)(object)val3 != (Object)null)
{
list.Add(((Component)((Component)val3).transform).gameObject);
}
if (list.Count <= 0)
{
return;
}
foreach (GameObject item in list)
{
GameObject go = item;
val = HelperMethods.TryApplyChildStyle(ref go, __instance.m_itemData.m_variant, __instance.m_itemData.m_shared.m_variants);
if ((Object)(object)val != (Object)null)
{
GameObject go2 = ((Component)((Component)val).transform).gameObject;
array = HelperMethods.TryApplyChildLevel(ref go2, __instance.m_itemData.m_quality, __instance.m_itemData.m_shared.m_maxQuality);
}
else
{
array = HelperMethods.TryApplyChildLevel(ref go, __instance.m_itemData.m_quality, __instance.m_itemData.m_shared.m_maxQuality);
}
}
}
}
[HarmonyPatch]
public class ItemStandPatches
{
[HarmonyPatch(typeof(ItemStand), "GetAttachPrefab")]
[HarmonyPostfix]
private static void GetAttachPrefabPostfix(ItemStand __instance, GameObject item, ref GameObject __result)
{
Transform val = RecursiveSearchFunctions.ChildNodeFinderBreadthFirst(item.transform, "attach_stand");
if (!((Object)(object)val != (Object)null))
{
return;
}
Transform val2 = val;
string nodeName = "style_" + __instance.m_visualVariant;
Transform val3 = RecursiveSearchFunctions.ChildNodeFinderBreadthFirst(val2, nodeName);
if ((Object)(object)val3 != (Object)null)
{
val2 = val3;
}
string text = ((Component)((Component)__instance).transform).gameObject.GetComponent<Piece>()?.m_description;
if (text != null && text.Trim().Length > 0 && val2.childCount > 0)
{
for (int i = 0; i < val2.childCount; i++)
{
Transform child = val2.GetChild(i);
char c = ((Object)((Component)child).gameObject).name[0];
if ((c == 'v' || c == 'V') && text.Contains("vertical"))
{
val2 = child;
break;
}
if ((c == 'h' || c == 'H') && text.Contains("horizontal"))
{
val2 = child;
break;
}
}
}
__result = ((Component)val2).gameObject;
}
}
[BepInPlugin("htd.sam", "Shapekeys and More", "2.4.1")]
public class Plugin : BaseUnityPlugin
{
public const string Version = "2.4.1";
public const string ModName = "Shapekeys and More";
public const string GUID = "htd.sam";
private Harmony _Harmony;
public static ManualLogSource Log;
public readonly Harmony harmony = new Harmony("htd.sam");
private void Awake()
{
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_0011: Expected O, but got Unknown
_Harmony = new Harmony("htd.sam");
Log = ((BaseUnityPlugin)this).Logger;
_Harmony.PatchAll();
}
}
public class RecursiveSearchFunctions
{
public static Transform ChildNodeFinderDepthFirst(Transform target, ref string nodeName, bool contains = false)
{
if ((!contains && ((Object)((Component)target).gameObject).name == nodeName) || (contains && ((Object)((Component)target).gameObject).name.Contains(nodeName)))
{
return target;
}
if (target.childCount > 0)
{
for (int i = 0; i < target.childCount; i++)
{
Transform val = ChildNodeFinderDepthFirst(target.GetChild(i), nodeName, contains);
if ((Object)(object)val != (Object)null)
{
return val;
}
}
}
return null;
}
public static Transform ChildNodeFinderDepthFirst(Transform target, string nodeName, bool contains = false)
{
return ChildNodeFinderDepthFirst(target, ref nodeName, contains);
}
public static Transform ChildNodeFinderBreadthFirst(Transform[] targets, ref string nodeName, bool contains = false)
{
List<Transform[]> list = new List<Transform[]>();
foreach (Transform val in targets)
{
if ((!contains && ((Object)((Component)val).gameObject).name == nodeName) || (contains && ((Object)((Component)val).gameObject).name.Contains(nodeName)))
{
return val;
}
if (val.childCount > 0)
{
Transform[] array = (Transform[])(object)new Transform[val.childCount];
for (int j = 0; j < val.childCount; j++)
{
array[j] = val.GetChild(j);
}
list.Add(array);
}
}
if (list.Count > 0)
{
foreach (Transform[] item in list)
{
Transform val2 = ChildNodeFinderBreadthFirst(item, ref nodeName, contains);
if ((Object)(object)val2 != (Object)null)
{
return val2;
}
}
}
return null;
}
public static Transform ChildNodeFinderBreadthFirst(Transform target, string nodeName, bool contains = false)
{
return ChildNodeFinderBreadthFirst((Transform[])(object)new Transform[1] { target }, ref nodeName, contains);
}
public static void ChildNodesFinderDepthFirst(Transform target, string nodeName, ref int numberOfNodes, ref List<Transform> nestedTargets, bool contains = false)
{
if (((!contains && ((Object)((Component)target).gameObject).name == nodeName) || (contains && ((Object)((Component)target).gameObject).name.Contains(nodeName))) && nestedTargets.Count < numberOfNodes)
{
nestedTargets.Add(target);
}
if (target.childCount > 0 && nestedTargets.Count < numberOfNodes)
{
for (int i = 0; i < target.childCount; i++)
{
ChildNodesFinderDepthFirst(target.GetChild(i), nodeName, ref numberOfNodes, ref nestedTargets, contains);
}
}
}
public static void ChildNodesFinderDepthFirst(Transform target, string nodeName, int numberOfNodes, ref List<Transform> nestedTargets, bool contains = false)
{
ChildNodesFinderDepthFirst(target, nodeName, ref numberOfNodes, ref nestedTargets, contains);
}
public static void ChildNodesFinderBreadthFirst(Transform[] targets, ref string nodeName, ref int numberOfNodes, ref List<Transform> nestedTargets, bool contains = false)
{
List<Transform[]> list = new List<Transform[]>();
foreach (Transform val in targets)
{
if (((!contains && ((Object)((Component)val).gameObject).name == nodeName) || (contains && ((Object)((Component)val).gameObject).name.Contains(nodeName))) && nestedTargets.Count < numberOfNodes)
{
nestedTargets.Add(val);
if (nestedTargets.Count >= numberOfNodes)
{
return;
}
}
if (val.childCount > 0)
{
Transform[] array = (Transform[])(object)new Transform[val.childCount];
for (int j = 0; j < val.childCount; j++)
{
array[j] = val.GetChild(j);
}
list.Add(array);
}
}
if (list.Count <= 0 || nestedTargets.Count >= numberOfNodes)
{
return;
}
foreach (Transform[] item in list)
{
ChildNodesFinderBreadthFirst(item, ref nodeName, ref numberOfNodes, ref nestedTargets, contains);
if (nestedTargets.Count >= numberOfNodes)
{
break;
}
}
}
public static void ChildNodesFinderBreadthFirst(Transform[] targets, string nodeName, int numberOfNodes, ref List<Transform> nestedTargets, bool contains = false)
{
ChildNodesFinderBreadthFirst(targets, ref nodeName, ref numberOfNodes, ref nestedTargets, contains);
}
public static void ChildNodesFinderBreadthFirst(Transform target, string nodeName, int numberOfNodes, ref List<Transform> nestedTargets, bool contains = false)
{
ChildNodesFinderBreadthFirst((Transform[])(object)new Transform[1] { target }, ref nodeName, ref numberOfNodes, ref nestedTargets, contains);
}
}
[HarmonyPatch(typeof(VisEquipment))]
public class VisEquipmentPatches
{
[HarmonyPatch("Awake")]
[HarmonyPostfix]
public static void AddVisEquipmentOther(VisEquipment __instance)
{
VisEquipmentOther visEquipmentOther = ((Component)__instance).gameObject.AddComponent<VisEquipmentOther>();
visEquipmentOther.visEquipment = __instance;
visEquipmentOther.CreateAttachOtherJoints();
}
[HarmonyPatch("SetShoulderItem")]
[HarmonyPostfix]
public static void SetShoulderItemPatch(VisEquipment __instance, string name)
{
ZNetView nview = __instance.m_nview;
if (((nview != null) ? nview.GetZDO() : null) != null && __instance.m_nview.IsOwner() && __instance.m_isPlayer)
{
ZDO zDO = __instance.m_nview.GetZDO();
Humanoid component = ((Component)__instance).gameObject.GetComponent<Humanoid>();
if ((Object)(object)component != (Object)null)
{
ItemData id = null;
string zdoKey = "";
HelperMethods.GetItemDataFromHumanoid(component, HelperMethods.ItemType.SHOULDER, out id, out zdoKey);
HelperMethods.SetItemVariantZDO(zDO, id, zdoKey, isVanilla: true);
HelperMethods.SetItemLevelZDO(zDO, id, zdoKey);
}
}
}
[HarmonyPatch("SetChestItem")]
[HarmonyPostfix]
public static void SetChestItemPatch(VisEquipment __instance, string name)
{
ZNetView nview = __instance.m_nview;
if (((nview != null) ? nview.GetZDO() : null) != null && __instance.m_nview.IsOwner() && __instance.m_isPlayer)
{
ZDO zDO = __instance.m_nview.GetZDO();
Humanoid component = ((Component)__instance).gameObject.GetComponent<Humanoid>();
if ((Object)(object)component != (Object)null)
{
ItemData id = null;
string zdoKey = "";
HelperMethods.GetItemDataFromHumanoid(component, HelperMethods.ItemType.CHEST, out id, out zdoKey);
HelperMethods.SetItemVariantZDO(zDO, id, zdoKey);
HelperMethods.SetItemLevelZDO(zDO, id, zdoKey);
}
}
}
[HarmonyPatch("SetUtilityItem")]
[HarmonyPostfix]
public static void SetUtilityItemPatch(VisEquipment __instance, string name)
{
ZNetView nview = __instance.m_nview;
if (((nview != null) ? nview.GetZDO() : null) != null && __instance.m_nview.IsOwner() && __instance.m_isPlayer)
{
ZDO zDO = __instance.m_nview.GetZDO();
Humanoid component = ((Component)__instance).gameObject.GetComponent<Humanoid>();
if ((Object)(object)component != (Object)null)
{
ItemData id = null;
string zdoKey = "";
HelperMethods.GetItemDataFromHumanoid(component, HelperMethods.ItemType.UTILITY, out id, out zdoKey);
HelperMethods.SetItemVariantZDO(zDO, id, zdoKey);
HelperMethods.SetItemLevelZDO(zDO, id, zdoKey);
}
}
}
[HarmonyPatch("SetHelmetItem")]
[HarmonyPostfix]
public static void SetHelmetItemPatch(VisEquipment __instance, string name)
{
ZNetView nview = __instance.m_nview;
if (((nview != null) ? nview.GetZDO() : null) != null && __instance.m_nview.IsOwner() && __instance.m_isPlayer)
{
ZDO zDO = __instance.m_nview.GetZDO();
Humanoid component = ((Component)__instance).gameObject.GetComponent<Humanoid>();
if ((Object)(object)component != (Object)null)
{
ItemData id = null;
string zdoKey = "";
HelperMethods.GetItemDataFromHumanoid(component, HelperMethods.ItemType.HEAD, out id, out zdoKey);
HelperMethods.SetItemVariantZDO(zDO, id, zdoKey);
HelperMethods.SetItemLevelZDO(zDO, id, zdoKey);
}
}
}
[HarmonyPatch("SetLegItem")]
[HarmonyPostfix]
public static void SetLegItemPatch(VisEquipment __instance, string name)
{
ZNetView nview = __instance.m_nview;
if (((nview != null) ? nview.GetZDO() : null) != null && __instance.m_nview.IsOwner() && __instance.m_isPlayer)
{
ZDO zDO = __instance.m_nview.GetZDO();
Humanoid component = ((Component)__instance).gameObject.GetComponent<Humanoid>();
if ((Object)(object)component != (Object)null)
{
ItemData id = null;
string zdoKey = "";
HelperMethods.GetItemDataFromHumanoid(component, HelperMethods.ItemType.LEGS, out id, out zdoKey);
HelperMethods.SetItemVariantZDO(zDO, id, zdoKey);
HelperMethods.SetItemLevelZDO(zDO, id, zdoKey);
}
}
}
[HarmonyPatch("SetRightItem")]
[HarmonyPostfix]
public static void SetRightItemPatch(VisEquipment __instance, string name)
{
ZNetView nview = __instance.m_nview;
if (((nview != null) ? nview.GetZDO() : null) != null && __instance.m_nview.IsOwner() && __instance.m_isPlayer)
{
ZDO zDO = __instance.m_nview.GetZDO();
Humanoid component = ((Component)__instance).gameObject.GetComponent<Humanoid>();
if ((Object)(object)component != (Object)null)
{
ItemData id = null;
string zdoKey = "";
HelperMethods.GetItemDataFromHumanoid(component, HelperMethods.ItemType.RIGHTHAND, out id, out zdoKey);
HelperMethods.SetItemVariantZDO(zDO, id, zdoKey);
HelperMethods.SetItemLevelZDO(zDO, id, zdoKey);
}
}
}
[HarmonyPatch("SetRightBackItem")]
[HarmonyPostfix]
public static void SetRightBackItemPatch(VisEquipment __instance, string name)
{
ZNetView nview = __instance.m_nview;
if (((nview != null) ? nview.GetZDO() : null) != null && __instance.m_nview.IsOwner() && __instance.m_isPlayer)
{
ZDO zDO = __instance.m_nview.GetZDO();
Humanoid component = ((Component)__instance).gameObject.GetComponent<Humanoid>();
if ((Object)(object)component != (Object)null)
{
ItemData id = null;
string zdoKey = "";
HelperMethods.GetItemDataFromHumanoid(component, HelperMethods.ItemType.RIGHTBACK, out id, out zdoKey);
HelperMethods.SetItemVariantZDO(zDO, id, zdoKey);
HelperMethods.SetItemLevelZDO(zDO, id, zdoKey);
}
}
}
[HarmonyPatch("SetLeftItem")]
[HarmonyPostfix]
public static void SetLeftItemPatch(VisEquipment __instance, string name)
{
ZNetView nview = __instance.m_nview;
if (((nview != null) ? nview.GetZDO() : null) != null && __instance.m_nview.IsOwner() && __instance.m_isPlayer)
{
ZDO zDO = __instance.m_nview.GetZDO();
Humanoid component = ((Component)__instance).gameObject.GetComponent<Humanoid>();
if ((Object)(object)component != (Object)null)
{
ItemData id = null;
string zdoKey = "";
HelperMethods.GetItemDataFromHumanoid(component, HelperMethods.ItemType.LEFTHAND, out id, out zdoKey);
HelperMethods.SetItemVariantZDO(zDO, id, zdoKey, isVanilla: true);
HelperMethods.SetItemLevelZDO(zDO, id, zdoKey);
}
}
}
[HarmonyPatch("SetLeftBackItem")]
[HarmonyPostfix]
public static void SetLeftBackItemPatch(VisEquipment __instance, string name)
{
ZNetView nview = __instance.m_nview;
if (((nview != null) ? nview.GetZDO() : null) != null && __instance.m_nview.IsOwner() && __instance.m_isPlayer)
{
ZDO zDO = __instance.m_nview.GetZDO();
Humanoid component = ((Component)__instance).gameObject.GetComponent<Humanoid>();
if ((Object)(object)component != (Object)null)
{
ItemData id = null;
string zdoKey = "";
HelperMethods.GetItemDataFromHumanoid(component, HelperMethods.ItemType.LEFTBACK, out id, out zdoKey);
HelperMethods.SetItemVariantZDO(zDO, id, zdoKey, isVanilla: true);
HelperMethods.SetItemLevelZDO(zDO, id, zdoKey);
}
}
}
[HarmonyPatch("UpdateEquipmentVisuals")]
[HarmonyPostfix]
public static void UpdateEquipmentVisualsPostfix(VisEquipment __instance)
{
if (__instance.m_isPlayer)
{
HelperMethods.ApplyVisualEffects(__instance);
__instance.UpdateLodgroup();
}
}
}
public class VisEquipmentOther : MonoBehaviour
{
public VisEquipment visEquipment;
public Transform backAtgeirOther;
public Transform backBowOther;
public Transform backMeleeOther;
public Transform backShieldOther;
public Transform backToolOther;
public Transform backTwohandedMeleeOther;
public void ClearUpdate()
{
visEquipment.m_nview.GetZDO().Set("UpdateVisualsHTD", false);
}
private Transform CreateAttachOtherJoint(Transform joint)
{
//IL_0013: Unknown result type (might be due to invalid IL or missing references)
//IL_0019: Expected O, but got Unknown
//IL_0049: Unknown result type (might be due to invalid IL or missing references)
//IL_005b: Unknown result type (might be due to invalid IL or missing references)
//IL_006d: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)joint == (Object)null)
{
return null;
}
GameObject val = new GameObject();
((Object)val).name = ((Object)joint).name + "Other";
val.transform.parent = joint.parent;
val.transform.localPosition = joint.localPosition;
val.transform.localRotation = joint.localRotation;
val.transform.localScale = joint.localScale;
val.SetActive(((Component)joint).gameObject.activeSelf);
return val.transform;
}
public void CreateAttachOtherJoints()
{
backAtgeirOther = CreateAttachOtherJoint(visEquipment.m_backAtgeir);
backBowOther = CreateAttachOtherJoint(visEquipment.m_backBow);
backMeleeOther = CreateAttachOtherJoint(visEquipment.m_backMelee);
backTwohandedMeleeOther = CreateAttachOtherJoint(visEquipment.m_backTwohandedMelee);
backShieldOther = CreateAttachOtherJoint(visEquipment.m_backShield);
backToolOther = CreateAttachOtherJoint(visEquipment.m_backTool);
}
}