using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using SideLoader;
using UnityEngine;
using UnityEngine.SceneManagement;
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: CompilationRelaxations(8)]
[assembly: AssemblyVersion("0.0.0.0")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInPlugin("brokenruune.damascuscollection", "Broken Ruune's Damascus Collection", "1.0.0")]
public sealed class DamascusCollection : BaseUnityPlugin
{
internal static readonly Dictionary<int, GearSettings> Gear = new Dictionary<int, GearSettings>();
private void Awake()
{
Add(-847520, "Damascus Armor", 1000, armor: true);
Add(-847521, "Damascus Helmet", 500, armor: true);
Add(-847522, "Damascus Boots", 500, armor: true);
Add(-847531, "Damascus Shield", 500, armor: false, shield: true);
Add(-847510, "Elegant Sword", 1500);
Add(-847530, "Damascus Pistol", 750);
DamascusArmorSet.Initialize(((BaseUnityPlugin)this).Config, ((BaseUnityPlugin)this).Logger);
DamascusShield.Initialize(((BaseUnityPlugin)this).Config, ((BaseUnityPlugin)this).Logger);
ElegantSword.Initialize(((BaseUnityPlugin)this).Config, ((BaseUnityPlugin)this).Logger);
DamascusPistol.Initialize(((BaseUnityPlugin)this).Config, ((BaseUnityPlugin)this).Logger);
}
private void Add(int id, string name, int price, bool armor = false, bool shield = false)
{
Gear.Add(id, new GearSettings(((BaseUnityPlugin)this).Config, name, price, armor, shield));
}
}
internal sealed class GearSettings
{
internal readonly int Price;
internal readonly float Damage;
internal readonly float Ethereal;
internal readonly float PistolBonus;
internal readonly float ShieldResistanceBonus;
private readonly SL_EquipmentStats overrides;
internal GearSettings(ConfigFile config, string item, int price, bool armor, bool shield)
{
//IL_001f: Unknown result type (might be due to invalid IL or missing references)
//IL_0025: Expected O, but got Unknown
Price = ReadInt(config, item, "BuyPrice", price, 0, "Purchase price in silver at Tokuga.");
SL_EquipmentStats val = new SL_EquipmentStats();
((SL_ItemStats)val).RawWeight = Optional(ReadFloat(config, item, "Weight", -1f, -1f, "Weight. -1 keeps the original."));
((SL_ItemStats)val).MaxDurability = Optional(ReadInt(config, item, "MaxDurability", -1, -1, "Maximum durability. -1 keeps the original."));
SL_EquipmentStats val2 = (overrides = val);
if (armor)
{
val2.Heat_Protection = ReadFloat(config, item, "HotWeatherDefense", 100f, 0f, "Hot Weather Defense.");
val2.Cold_Protection = Optional(ReadFloat(config, item, "ColdWeatherDefense", -1f, -1f, "Cold Weather Defense. -1 keeps the original."));
val2.Damage_Protection = Optional(ReadFloat(config, item, "Protection", -1f, -1f, "Physical Protection. -1 keeps the original."));
val2.BarrierProtection = Optional(ReadFloat(config, item, "Barrier", -1f, -1f, "Elemental Barrier. -1 keeps the original."));
val2.Impact_Resistance = Optional(ReadFloat(config, item, "ImpactResistance", -1f, -1f, "Impact Resistance. -1 keeps the original."));
}
else if (shield)
{
ShieldResistanceBonus = ReadFloat(config, item, "ImpactResistanceBonus", 5f, 0f, "Added Impact Resistance over the Steel Shield.");
Damage = ReadFloat(config, item, "PhysicalDamage", -1f, -1f, "Physical damage for shield attacks. -1 keeps the original.");
}
else if (item == "Elegant Sword")
{
Damage = ReadFloat(config, item, "PhysicalDamage", 25f, 0f, "Base physical damage.");
Ethereal = ReadFloat(config, item, "EtherealDamage", 9f, 0f, "Base ethereal damage.");
}
else
{
Damage = ReadFloat(config, item, "PhysicalDamage", -1f, -1f, "Base physical damage. -1 uses the donor damage plus PhysicalDamageBonus.");
PistolBonus = ReadFloat(config, item, "PhysicalDamageBonus", 4f, 0f, "Added physical damage over the Flintlock Pistol when PhysicalDamage is -1.");
}
}
internal void Apply(EquipmentStats stats)
{
((SL_ItemStats)overrides).ApplyToItem((ItemStats)(object)stats);
}
private static float? Optional(float value)
{
if (!(value < 0f))
{
return value;
}
return null;
}
private static int? Optional(int value)
{
if (value >= 0)
{
return value;
}
return null;
}
private static float ReadFloat(ConfigFile config, string section, string key, float value, float minimum, string description)
{
//IL_001a: Unknown result type (might be due to invalid IL or missing references)
//IL_0024: Expected O, but got Unknown
AcceptableValueRange<float> val = new AcceptableValueRange<float>(minimum, 10000f);
float value2 = config.Bind<float>(section, key, value, new ConfigDescription(description, (AcceptableValueBase)(object)val, new object[0])).Value;
if (!float.IsNaN(value2))
{
return value2;
}
return value;
}
private static int ReadInt(ConfigFile config, string section, string key, int value, int minimum, string description)
{
//IL_0018: Unknown result type (might be due to invalid IL or missing references)
//IL_0022: Expected O, but got Unknown
return config.Bind<int>(section, key, value, new ConfigDescription(description, (AcceptableValueBase)(object)new AcceptableValueRange<int>(minimum, 1000000), new object[0])).Value;
}
internal static void SetShieldDamage(Item item, Item donor, float damage)
{
//IL_0052: 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_0103: Expected O, but got Unknown
if (damage < 0f)
{
return;
}
WeaponStats component = ((Component)item).GetComponent<WeaponStats>();
WeaponStats component2 = ((Component)donor).GetComponent<WeaponStats>();
if (!Object.op_Implicit((Object)(object)component) || !Object.op_Implicit((Object)(object)component2) || (Object)(object)component == (Object)(object)component2 || component2.BaseDamage == null || component2.BaseDamage.Count != 1 || (int)component2.BaseDamage[0].Type != 0 || component2.BaseDamage.TotalDamage <= 0f || component2.Attacks == null)
{
return;
}
float num = damage / component2.BaseDamage.TotalDamage;
AttackData[] array = (AttackData[])component2.Attacks.Clone();
for (int i = 0; i < array.Length; i++)
{
AttackData val = array[i];
if (val != null && val.Damage != null && val.Damage.Count != 0 && !(val.Damage[0] < 0f))
{
List<float> list = new List<float>(val.Damage);
list[0] *= num;
int num2 = i;
AttackData val2 = new AttackData();
val2.Damage = list;
val2.Knockback = val.Knockback;
val2.StamCost = val.StamCost;
val2.AttackSpeed = val.AttackSpeed;
array[num2] = val2;
}
}
component.BaseDamage = component2.BaseDamage.Clone() * num;
component.Attacks = array;
}
}
internal static class DamascusArmorSet
{
private sealed class Finish
{
public readonly string DonorMaterial;
public readonly string MaterialName;
public readonly Texture2D Albedo;
public readonly Texture2D Surface;
public readonly Texture2D Normal;
public Finish(string part, string donorMaterial, Texture2D sharedNormal = null)
{
DonorMaterial = donorMaterial;
MaterialName = "mat_Damascus" + part;
Albedo = LoadTexture(part + "Albedo", linear: false);
Surface = LoadTexture(part + "Surface", linear: true);
Normal = sharedNormal ?? LoadTexture(part + "Normal", linear: true);
}
}
private const string PluginId = "local.dylan.damascusarmorset";
private const int ArmorId = -847520;
private const int HelmetId = -847521;
private const int BootsId = -847522;
private const int ElegantSwordId = -847510;
private const string BlacksmithId = "3Rx_R0XDLUmYaNWm66SVCQ";
private const string TokugaNormalPriceId = "EYhBqM653UGhDd5kcdMFXg";
private static readonly int[] ShopItems = new int[4] { -847520, -847521, -847522, -847510 };
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 int EmissionTex = Shader.PropertyToID("_EmissionTex");
private static ConfigEntry<string> seededInventories;
private static HashSet<string> seededInventoryKeys;
private static ManualLogSource log;
private static Finish armorFinish;
internal static void Initialize(ConfigFile config, ManualLogSource logger)
{
//IL_006e: Unknown result type (might be due to invalid IL or missing references)
//IL_0074: Expected O, but got Unknown
//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
//IL_00e5: Expected O, but got Unknown
//IL_0165: Unknown result type (might be due to invalid IL or missing references)
//IL_0173: Expected O, but got Unknown
//IL_01c1: Unknown result type (might be due to invalid IL or missing references)
//IL_01ce: Expected O, but got Unknown
//IL_022a: Unknown result type (might be due to invalid IL or missing references)
//IL_0230: Expected O, but got Unknown
//IL_027f: Unknown result type (might be due to invalid IL or missing references)
//IL_0294: Unknown result type (might be due to invalid IL or missing references)
//IL_02a1: Expected O, but got Unknown
//IL_02a1: Expected O, but got Unknown
//IL_02ee: Unknown result type (might be due to invalid IL or missing references)
//IL_02fc: Expected O, but got Unknown
log = logger;
seededInventories = config.Bind<string>("Blacksmiths", "SeededStock", "", "Internal record of saves where the initial Damascus Armor set stock has been added.");
seededInventoryKeys = new HashSet<string>(seededInventories.Value.Split(new char[1] { ',' }, StringSplitOptions.RemoveEmptyEntries), StringComparer.Ordinal);
armorFinish = new Finish("Armor", "mat_cha_blueSandArmor");
Harmony val = new Harmony("local.dylan.damascusarmorset");
string[] array = new string[2] { "InstantiateVisuals", "InstantiateSpecialVisuals" };
foreach (string text in array)
{
val.Patch((MethodBase)AccessTools.Method(typeof(ItemManager), text, new Type[1] { typeof(Item) }, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(typeof(DamascusArmorSet), "FinishNewInstance", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
}
string[] array2 = new string[2] { "Internal_PutBackVisual", "Internal_PutBackSpecialVisual" };
foreach (string text2 in array2)
{
val.Patch((MethodBase)AccessTools.Method(typeof(ItemManager), text2, new Type[2]
{
typeof(int),
typeof(Transform)
}, (Type[])null), new HarmonyMethod(typeof(DamascusArmorSet), "KeepVisualInOwnPool", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
}
val.Patch((MethodBase)AccessTools.Method(typeof(SL_Armor), "ApplyToItem", new Type[1] { typeof(Item) }, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(typeof(DamascusArmorSet), "ApplyArmorStats", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
MethodInfo methodInfo = AccessTools.Method(typeof(Item), "GetBuyValue", new Type[3]
{
typeof(Character),
typeof(Merchant),
typeof(bool)
}, (Type[])null);
HarmonyMethod val2 = new HarmonyMethod(typeof(DamascusArmorSet), "SetBlacksmithPrice", (Type[])null);
val2.priority = 0;
val.Patch((MethodBase)methodInfo, (HarmonyMethod)null, val2, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
val.Patch((MethodBase)AccessTools.Method(typeof(MerchantPouch), "RefreshInventory", new Type[1] { typeof(Dropable) }, (Type[])null), new HarmonyMethod(typeof(DamascusArmorSet), "BeforeRestock", (Type[])null), new HarmonyMethod(typeof(DamascusArmorSet), "AfterRestock", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
val.Patch((MethodBase)AccessTools.Method(typeof(Merchant), "OnReceiveConfirmStartShopping", new Type[2]
{
typeof(bool),
typeof(Character)
}, (Type[])null), new HarmonyMethod(typeof(DamascusArmorSet), "SeedExistingStock", (Type[])null), (HarmonyMethod)null, (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 = "Damascus" + resource;
((Texture)val).anisoLevel = 4;
Texture2D val2 = val;
using Stream stream = typeof(DamascusArmorSet).Assembly.GetManifestResourceStream("DamascusArmor." + 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 bool IsDamascus(int id)
{
if (id != -847520 && id != -847521)
{
return id == -847522;
}
return true;
}
private static void KeepVisualInOwnPool(ref int __0, Transform __1)
{
if (!Object.op_Implicit((Object)(object)__1))
{
return;
}
ItemVisual component = ((Component)__1).GetComponent<ItemVisual>();
if (Object.op_Implicit((Object)(object)component))
{
int itemIDFromName = component.GetItemIDFromName();
if (IsDamascus(itemIDFromName) || (IsDamascus(__0) && itemIDFromName != -1))
{
__0 = itemIDFromName;
}
}
}
private static void FinishNewInstance(Item __0, Transform __result)
{
if (!Object.op_Implicit((Object)(object)__0) || !IsDamascus(__0.ItemID) || !Object.op_Implicit((Object)(object)__result))
{
return;
}
ItemVisual component = ((Component)__result).GetComponent<ItemVisual>();
if (Object.op_Implicit((Object)(object)component) && component.ItemID == __0.ItemID)
{
if (ApplyFinish(((Component)component).gameObject, armorFinish) == 0)
{
log.LogWarning((object)("Damascus instance has no Blue Sand material for " + __0.ItemID));
}
else
{
((Object)component).name = __0.ItemID.ToString(CultureInfo.InvariantCulture) + (component.IsSpecialVisual ? "_Damascus_e_v" : "_Damascus_v");
}
}
}
private static int ApplyFinish(GameObject model, Finish finish)
{
//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
//IL_00f9: Expected O, but got Unknown
int num = 0;
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) || !val2.HasProperty(MainTex) || !val2.HasProperty(GenTex) || !val2.HasProperty(NormTex))
{
continue;
}
if ((Object)(object)val2.GetTexture(MainTex) == (Object)(object)finish.Albedo && (Object)(object)val2.GetTexture(GenTex) == (Object)(object)finish.Surface && (Object)(object)val2.GetTexture(NormTex) == (Object)(object)finish.Normal)
{
num++;
}
else if (((Object)val2).name.StartsWith(finish.DonorMaterial, StringComparison.OrdinalIgnoreCase) || ((Object)val2).name.StartsWith(finish.MaterialName, StringComparison.OrdinalIgnoreCase))
{
Material val3 = new Material(val2);
((Object)val3).name = finish.MaterialName;
Material val4 = val3;
val4.SetTexture(MainTex, (Texture)(object)finish.Albedo);
val4.SetTexture(GenTex, (Texture)(object)finish.Surface);
val4.SetTexture(NormTex, (Texture)(object)finish.Normal);
if (val4.HasProperty(EmissionTex))
{
val4.SetTexture(EmissionTex, (Texture)(object)Texture2D.blackTexture);
}
val4.DisableKeyword("_DETAIL");
val4.DisableKeyword("_DETAIL_ALBEDO");
val4.DisableKeyword("_DETAIL_TEXTURED");
val4.DisableKeyword("_DETAIL_MASK");
val4.DisableKeyword("_SPEC_COLOR");
val4.EnableKeyword("_NORMALMAP");
val4.EnableKeyword("_SPECGLOSSMAP");
val4.SetFloat("_SpecBoost", 0.015f);
val4.SetFloat("_GlossMin", 0.035f);
val4.SetFloat("_SmoothMin", 0.035f);
val4.DisableKeyword("_EMISSION");
val4.DisableKeyword("_EMISSION_TEXTURED");
sharedMaterials[j] = val4;
flag = true;
num++;
}
}
if (flag)
{
val.sharedMaterials = sharedMaterials;
}
}
return num;
}
private static void ApplyArmorStats(Item __0)
{
if (!Object.op_Implicit((Object)(object)__0))
{
return;
}
int num = Array.IndexOf(ShopItems, __0.ItemID);
if (num >= 0 && num < 3)
{
EquipmentStats component = ((Component)__0).GetComponent<EquipmentStats>();
if (Object.op_Implicit((Object)(object)component))
{
DamascusCollection.Gear[__0.ItemID].Apply(component);
__0.InitCachedInfos();
log.LogInfo((object)("Damascus item " + __0.ItemID + " Hot Weather Defense: " + component.HeatProtection));
}
}
}
private static string TargetBlacksmith(Merchant merchant)
{
//IL_000e: Unknown result type (might be due to invalid IL or missing references)
//IL_0013: Unknown result type (might be due to invalid IL or missing references)
//IL_002a: Unknown result type (might be due to invalid IL or missing references)
if (Object.op_Implicit((Object)(object)merchant))
{
Scene scene = ((Component)merchant).gameObject.scene;
if (!(((Scene)(ref scene)).name != "Levant"))
{
string text = UID.op_Implicit(merchant.HolderUID);
if (!(text == "3Rx_R0XDLUmYaNWm66SVCQ") && !(text == "EYhBqM653UGhDd5kcdMFXg"))
{
return null;
}
return "Tokuga";
}
}
return null;
}
private static void SetBlacksmithPrice(Item __instance, Character __0, Merchant __1, bool __2, ref int __result)
{
//IL_003d: Unknown result type (might be due to invalid IL or missing references)
int itemID = __instance.ItemID;
if (Array.IndexOf(ShopItems, itemID) >= 0 && TargetBlacksmith(__1) != null && (__2 || !Object.op_Implicit((Object)(object)__0) || !(EnvironmentConditions.GameTime < __instance.RebuyLimitTime) || !(__instance.PreviousOwnerUID == UID.op_Implicit(__0.UID))))
{
__result = DamascusCollection.Gear[itemID].Price;
}
}
private static void BeforeRestock(MerchantPouch __instance, double ___m_nextRefreshTime, out string __state)
{
__state = ((!PhotonNetwork.isNonMasterClientInRoom && EnvironmentConditions.GameTime >= ___m_nextRefreshTime) ? TargetBlacksmith(__instance.Merchant) : null);
}
private static Item FindStock(MerchantPouch pouch, int id)
{
return ((ItemContainer)pouch).GetItemsFromID(id).Find((Item item) => Object.op_Implicit((Object)(object)item) && !item.IsPendingDestroy);
}
private static Item EnsureStock(MerchantPouch pouch, int id)
{
//IL_0024: Unknown result type (might be due to invalid IL or missing references)
//IL_002a: Expected O, but got Unknown
Item val = FindStock(pouch, id);
if (Object.op_Implicit((Object)(object)val) || !Object.op_Implicit((Object)(object)ResourcesPrefabManager.Instance.GetItemPrefab(id)))
{
return val;
}
SL_ItemDrop val2 = new SL_ItemDrop();
val2.DroppedItemID = id;
val2.MinQty = 1;
val2.MaxQty = 1;
val2.GenerateDrop(((Component)pouch).transform);
return FindStock(pouch, id);
}
private static void AfterRestock(MerchantPouch __instance, string __state)
{
if (__state == null)
{
return;
}
int[] shopItems = ShopItems;
foreach (int num in shopItems)
{
if (Object.op_Implicit((Object)(object)EnsureStock(__instance, num)))
{
log.LogInfo((object)(__state + " restocked Damascus Armor item " + num + "."));
}
}
}
private static void SeedExistingStock(Merchant __instance, bool __0, Character __1)
{
//IL_0052: Unknown result type (might be due to invalid IL or missing references)
//IL_006f: Unknown result type (might be due to invalid IL or missing references)
//IL_0074: Unknown result type (might be due to invalid IL or missing references)
//IL_008b: Unknown result type (might be due to invalid IL or missing references)
if (!__0 || !Object.op_Implicit((Object)(object)__1) || PhotonNetwork.isNonMasterClientInRoom)
{
return;
}
string text = TargetBlacksmith(__instance);
if (text == null)
{
return;
}
ItemContainer merchantPouch = __instance.MerchantPouch;
MerchantPouch val = (MerchantPouch)(object)((merchantPouch is MerchantPouch) ? merchantPouch : null);
Character worldHostCharacter = CharacterManager.Instance.GetWorldHostCharacter();
if (!Object.op_Implicit((Object)(object)val) || !Object.op_Implicit((Object)(object)worldHostCharacter))
{
return;
}
string[] array = new string[5]
{
UID.op_Implicit(worldHostCharacter.UID),
":",
null,
null,
null
};
Scene scene = ((Component)__instance).gameObject.scene;
array[2] = ((Scene)(ref scene)).name;
array[3] = ":";
array[4] = UID.op_Implicit(__instance.HolderUID);
string item = string.Concat(array);
if (seededInventoryKeys.Contains(item))
{
return;
}
bool flag = true;
int[] shopItems = ShopItems;
foreach (int num in shopItems)
{
Item val2 = EnsureStock(val, num);
if (!Object.op_Implicit((Object)(object)val2))
{
flag = false;
log.LogWarning((object)(text + " did not receive Damascus Armor item " + num + "."));
}
else
{
log.LogInfo((object)(text + " shop confirmed " + val2.Name + " (" + num + ") at " + val2.GetBuyValue(__1, __instance, true) + " silver."));
}
}
if (flag)
{
seededInventoryKeys.Add(item);
seededInventories.Value = string.Join(",", seededInventoryKeys);
}
}
}
internal static class DamascusShield
{
private sealed class Finish
{
public const string MaterialName = "DamascusShieldSteel";
public readonly Texture2D Albedo = LoadTexture("Albedo", linear: false);
public readonly Texture2D Surface = LoadTexture("Surface", linear: true);
public bool Matches(Material material)
{
if (!(((Object)material).name == "DamascusShieldSteel"))
{
return ((Object)material).name.StartsWith("mat_itm_shieldTurk", StringComparison.Ordinal);
}
return true;
}
}
private const string PluginId = "local.dylan.damascusshield";
private const int ItemId = -847531;
private const string VisualName = "-847531_DamascusShield_v";
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 Finish pistolFinish;
private static ConfigEntry<string> seeded;
private static HashSet<string> seededSaves;
internal static void Initialize(ConfigFile config, ManualLogSource logger)
{
//IL_0055: Unknown result type (might be due to invalid IL or missing references)
//IL_005b: Expected O, but got Unknown
pistolFinish = new Finish();
seeded = config.Bind<string>("Shop State", "ShieldSeededSaves", "", "Saves that received initial Damascus Shield shop stock.");
seededSaves = new HashSet<string>(seeded.Value.Split(new char[1] { ',' }, StringSplitOptions.RemoveEmptyEntries));
Harmony val = new Harmony("local.dylan.damascusshield");
MethodInfo methodInfo = AccessTools.Method(AccessTools.TypeByName("SideLoader.CustomItemVisuals"), "CloneAndSetVisuals", (Type[])null, (Type[])null);
val.Patch((MethodBase)methodInfo, (HarmonyMethod)null, Patch("RecolorClone"), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
val.Patch((MethodBase)AccessTools.Method(typeof(SL_MeleeWeapon), "ApplyToItem", new Type[1] { typeof(Item) }, (Type[])null), (HarmonyMethod)null, Patch("ApplyImpactResistance"), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
val.Patch((MethodBase)AccessTools.Method(typeof(VisualSlot), "PositionVisuals", new Type[1] { typeof(Item) }, (Type[])null), (HarmonyMethod)null, Patch("RecolorEquipped"), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
val.Patch((MethodBase)AccessTools.Method(typeof(Item), "GetBuyValue", new Type[3]
{
typeof(Character),
typeof(Merchant),
typeof(bool)
}, (Type[])null), (HarmonyMethod)null, Patch("SetBuyPrice"), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
val.Patch((MethodBase)AccessTools.Method(typeof(MerchantPouch), "RefreshInventory", new Type[1] { typeof(Dropable) }, (Type[])null), Patch("BeforeRestock"), Patch("AfterRestock"), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
val.Patch((MethodBase)AccessTools.Method(typeof(Merchant), "OnReceiveConfirmStartShopping", new Type[2]
{
typeof(bool),
typeof(Character)
}, (Type[])null), Patch("SeedExistingStock"), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
}
private static HarmonyMethod Patch(string name)
{
//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(DamascusShield), name, (Type[])null);
val.priority = 0;
return val;
}
private static void RecolorClone(Item __0, GameObject __1, GameObject __result)
{
if (Object.op_Implicit((Object)(object)__0) && __0.ItemID == -847531 && Object.op_Implicit((Object)(object)__result) && !((Object)(object)__result == (Object)(object)__1))
{
((Object)__result).name = "-847531_DamascusShield_v";
ApplyFinish(__result);
}
}
private static void RecolorEquipped(VisualSlot __instance, Item __0)
{
if (Object.op_Implicit((Object)(object)__0) && __0.ItemID == -847531)
{
ItemVisual currentVisual = __instance.CurrentVisual;
if (Object.op_Implicit((Object)(object)currentVisual) && currentVisual.GetItemIDFromName() == -847531)
{
ApplyFinish(((Component)currentVisual).gameObject);
}
}
}
private static void ApplyImpactResistance(Item __0)
{
//IL_0059: Unknown result type (might be due to invalid IL or missing references)
//IL_0060: Expected O, but got Unknown
if (Object.op_Implicit((Object)(object)__0) && __0.ItemID == -847531)
{
EquipmentStats component = ((Component)__0).GetComponent<EquipmentStats>();
Item itemPrefab = ResourcesPrefabManager.Instance.GetItemPrefab(2300140);
EquipmentStats val = (Object.op_Implicit((Object)(object)itemPrefab) ? ((Component)itemPrefab).GetComponent<EquipmentStats>() : null);
if (Object.op_Implicit((Object)(object)component) && Object.op_Implicit((Object)(object)val) && !object.ReferenceEquals(component, val))
{
SL_EquipmentStats val2 = new SL_EquipmentStats();
val2.Impact_Resistance = val.ImpactResistance + DamascusCollection.Gear[-847531].ShieldResistanceBonus;
((SL_ItemStats)val2).ApplyToItem((ItemStats)(object)component);
GearSettings gearSettings = DamascusCollection.Gear[-847531];
gearSettings.Apply(component);
GearSettings.SetShieldDamage(__0, itemPrefab, gearSettings.Damage);
__0.InitCachedInfos();
}
}
}
private static bool IsTokuga(Merchant merchant)
{
//IL_000e: Unknown result type (might be due to invalid IL or missing references)
//IL_0013: Unknown result type (might be due to invalid IL or missing references)
//IL_0028: Unknown result type (might be due to invalid IL or missing references)
//IL_0032: Unknown result type (might be due to invalid IL or missing references)
//IL_003f: Unknown result type (might be due to invalid IL or missing references)
//IL_0049: Unknown result type (might be due to invalid IL or missing references)
if (Object.op_Implicit((Object)(object)merchant))
{
Scene scene = ((Component)merchant).gameObject.scene;
if (((Scene)(ref scene)).name == "Levant")
{
if (!(merchant.HolderUID == UID.op_Implicit("3Rx_R0XDLUmYaNWm66SVCQ")))
{
return merchant.HolderUID == UID.op_Implicit("EYhBqM653UGhDd5kcdMFXg");
}
return true;
}
}
return false;
}
private static void SetBuyPrice(Item __instance, Character __0, Merchant __1, bool __2, ref int __result)
{
//IL_0035: Unknown result type (might be due to invalid IL or missing references)
if (__instance.ItemID == -847531 && IsTokuga(__1) && (__2 || !Object.op_Implicit((Object)(object)__0) || !(EnvironmentConditions.GameTime < __instance.RebuyLimitTime) || !(__instance.PreviousOwnerUID == UID.op_Implicit(__0.UID))))
{
__result = DamascusCollection.Gear[-847531].Price;
}
}
private static void BeforeRestock(MerchantPouch __instance, double ___m_nextRefreshTime, out bool __state)
{
__state = !PhotonNetwork.isNonMasterClientInRoom && EnvironmentConditions.GameTime >= ___m_nextRefreshTime && IsTokuga(__instance.Merchant);
}
private static void AfterRestock(MerchantPouch __instance, bool __state)
{
if (__state)
{
EnsureStock(__instance);
}
}
private static void SeedExistingStock(Merchant __instance, bool __0, Character __1)
{
//IL_0044: Unknown result type (might be due to invalid IL or missing references)
//IL_0054: Unknown result type (might be due to invalid IL or missing references)
if (!__0 || !Object.op_Implicit((Object)(object)__1) || PhotonNetwork.isNonMasterClientInRoom || !IsTokuga(__instance))
{
return;
}
ItemContainer merchantPouch = __instance.MerchantPouch;
MerchantPouch val = (MerchantPouch)(object)((merchantPouch is MerchantPouch) ? merchantPouch : null);
Character worldHostCharacter = CharacterManager.Instance.GetWorldHostCharacter();
if (Object.op_Implicit((Object)(object)val) && Object.op_Implicit((Object)(object)worldHostCharacter))
{
string item = UID.op_Implicit(worldHostCharacter.UID) + ":" + UID.op_Implicit(__instance.HolderUID);
if (!seededSaves.Contains(item) && EnsureStock(val))
{
seededSaves.Add(item);
seeded.Value = string.Join(",", seededSaves);
}
}
}
private static bool EnsureStock(MerchantPouch pouch)
{
//IL_0049: Unknown result type (might be due to invalid IL or missing references)
//IL_004f: Expected O, but got Unknown
if (((ItemContainer)pouch).GetItemsFromID(-847531).Exists((Item item) => Object.op_Implicit((Object)(object)item) && !item.IsPendingDestroy))
{
return true;
}
if (!Object.op_Implicit((Object)(object)ResourcesPrefabManager.Instance.GetItemPrefab(-847531)))
{
return false;
}
SL_ItemDrop val = new SL_ItemDrop();
val.DroppedItemID = -847531;
val.MinQty = 1;
val.MaxQty = 1;
val.GenerateDrop(((Component)pouch).transform);
return ((ItemContainer)pouch).GetItemsFromID(-847531).Exists((Item item) => Object.op_Implicit((Object)(object)item) && !item.IsPendingDestroy);
}
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 = "DamascusShield" + resource;
((Texture)val).anisoLevel = 4;
Texture2D val2 = val;
using Stream stream = typeof(DamascusShield).Assembly.GetManifestResourceStream("DamascusShield." + 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 int ApplyFinish(GameObject model)
{
//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
//IL_00d2: Expected O, but got Unknown
int num = 0;
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) || !val2.HasProperty(MainTex) || !val2.HasProperty(GenTex) || !val2.HasProperty(NormTex))
{
continue;
}
Finish finish = (pistolFinish.Matches(val2) ? pistolFinish : null);
if (finish == null)
{
continue;
}
num++;
if (!((Object)(object)val2.GetTexture(MainTex) == (Object)(object)finish.Albedo) || !((Object)(object)val2.GetTexture(GenTex) == (Object)(object)finish.Surface))
{
Material val3 = new Material(val2);
((Object)val3).name = "DamascusShieldSteel";
Material val4 = val3;
val4.SetTexture(MainTex, (Texture)(object)finish.Albedo);
val4.SetTexture(GenTex, (Texture)(object)finish.Surface);
val4.DisableKeyword("_DETAIL");
val4.DisableKeyword("_DETAIL_ALBEDO");
val4.DisableKeyword("_DETAIL_TEXTURED");
val4.DisableKeyword("_SPEC_COLOR");
if (val4.HasProperty("_EmissionTex"))
{
val4.SetTexture("_EmissionTex", (Texture)(object)Texture2D.blackTexture);
val4.DisableKeyword("_EMISSION");
val4.DisableKeyword("_EMISSION_TEXTURED");
}
val4.EnableKeyword("_NORMALMAP");
val4.EnableKeyword("_SPECGLOSSMAP");
val4.SetFloat("_SpecBoost", 0.015f);
val4.SetFloat("_GlossMin", 0.035f);
val4.SetFloat("_SmoothMin", 0.035f);
sharedMaterials[j] = val4;
flag = true;
}
}
if (flag)
{
val.sharedMaterials = sharedMaterials;
}
}
return num;
}
}
internal static class ElegantSword
{
private const int ItemId = -847510;
private const int IronSwordId = 2000010;
private const int BladeId = -847510;
private static Mesh sword;
private static ManualLogSource log;
private static Texture2D albedo;
private static Texture2D surface;
private static Texture2D normal;
private static Material finish;
private static Sprite icon;
internal static void Initialize(ConfigFile config, ManualLogSource logger)
{
//IL_0069: Unknown result type (might be due to invalid IL or missing references)
//IL_0078: Unknown result type (might be due to invalid IL or missing references)
//IL_0093: Unknown result type (might be due to invalid IL or missing references)
//IL_0099: Expected O, but got Unknown
log = logger;
sword = ReadMesh();
albedo = ReadTexture("ElegantAlbedo", linear: false, mipmaps: true);
surface = ReadTexture("ElegantSurface", linear: true, mipmaps: true);
normal = ReadTexture("ElegantNormal", linear: true, mipmaps: true);
Texture2D val = ReadTexture("ElegantIcon", linear: false, mipmaps: false);
icon = 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);
Harmony val2 = new Harmony("brokenruune.elegantsword");
val2.Patch((MethodBase)AccessTools.Method(AccessTools.TypeByName("SideLoader.CustomItemVisuals"), "CloneAndSetVisuals", (Type[])null, (Type[])null), (HarmonyMethod)null, Hook("AfterClone"), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
val2.Patch((MethodBase)AccessTools.Method(typeof(VisualSlot), "PositionVisuals", new Type[1] { typeof(Item) }, (Type[])null), (HarmonyMethod)null, Hook("AfterEquip"), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
val2.Patch((MethodBase)AccessTools.Method(typeof(ResourcesPrefabManager), "GetItemIcon", new Type[1] { typeof(Item) }, (Type[])null), (HarmonyMethod)null, Hook("UseIcon"), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
val2.Patch((MethodBase)AccessTools.Method(typeof(SL_MeleeWeapon), "ApplyToItem", new Type[1] { typeof(Item) }, (Type[])null), (HarmonyMethod)null, Hook("ApplyBladeDamage"), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
logger.LogInfo((object)("Elegant Sword mesh and icon ready (" + -847510 + ")."));
}
private static HarmonyMethod Hook(string name)
{
//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(ElegantSword), name, (Type[])null);
val.priority = 0;
return val;
}
private static void AfterClone(Item __0, GameObject __1, GameObject __result)
{
if (Object.op_Implicit((Object)(object)__0) && __0.ItemID == -847510 && Object.op_Implicit((Object)(object)__result) && !((Object)(object)__result == (Object)(object)__1))
{
((Object)__result).name = -847510 + "_ElegantSword_v";
Apply(__result);
}
}
private static void AfterEquip(VisualSlot __instance, Item __0)
{
if (Object.op_Implicit((Object)(object)__0) && __0.ItemID == -847510)
{
ItemVisual currentVisual = __instance.CurrentVisual;
if (Object.op_Implicit((Object)(object)currentVisual) && currentVisual.GetItemIDFromName() == -847510)
{
Apply(((Component)currentVisual).gameObject);
}
}
}
private static void UseIcon(Item __0, ref Sprite __result)
{
if (Object.op_Implicit((Object)(object)__0) && __0.ItemID == -847510)
{
__result = icon;
}
}
private static void Apply(GameObject model)
{
//IL_01d1: Unknown result type (might be due to invalid IL or missing references)
//IL_0098: Unknown result type (might be due to invalid IL or missing references)
//IL_009f: Expected O, but got Unknown
Transform val = model.transform.Find("SwordTest");
if (!Object.op_Implicit((Object)(object)val))
{
log.LogWarning((object)("Elegant Sword: donor SwordTest mesh not found on " + ((Object)model).name));
return;
}
MeshFilter component = ((Component)val).GetComponent<MeshFilter>();
MeshRenderer component2 = ((Component)val).GetComponent<MeshRenderer>();
if (!Object.op_Implicit((Object)(object)component) || !Object.op_Implicit((Object)(object)component2) || (Object)(object)component.sharedMesh == (Object)(object)sword)
{
return;
}
if (!Object.op_Implicit((Object)(object)finish))
{
Material sharedMaterial = ((Renderer)component2).sharedMaterial;
if (!Object.op_Implicit((Object)(object)sharedMaterial) || !((Object)sharedMaterial).name.StartsWith("mat_itm_longsword", StringComparison.OrdinalIgnoreCase))
{
return;
}
Material val2 = new Material(sharedMaterial);
((Object)val2).name = "Elegant Damascus, brass and mahogany";
finish = val2;
finish.SetTexture("_MainTex", (Texture)(object)albedo);
finish.SetTexture("_GenTex", (Texture)(object)surface);
finish.SetTexture("_NormTex", (Texture)(object)normal);
string[] array = new string[6] { "_DETAIL", "_DETAIL_ALBEDO", "_DETAIL_MASK", "_DETAIL_MULX2", "_DETAIL_TEXTURED", "_SPEC_COLOR" };
foreach (string text in array)
{
finish.DisableKeyword(text);
}
finish.EnableKeyword("_NORMALMAP");
finish.EnableKeyword("_SPECGLOSSMAP");
finish.SetFloat("_SpecBoost", 0.015f);
finish.SetFloat("_GlossMin", 0.035f);
if (finish.HasProperty("_SmoothMin"))
{
finish.SetFloat("_SmoothMin", 0.035f);
}
}
val.localRotation = Quaternion.Euler(0f, -90f, 0f);
component.sharedMesh = sword;
((Renderer)component2).sharedMaterials = (Material[])(object)new Material[1] { finish };
log.LogInfo((object)("Elegant Sword custom visual bound: " + ((Object)model).name + "; " + sword.vertexCount + " vertices; private Damascus material."));
}
private static Texture2D ReadTexture(string name, bool linear, bool mipmaps)
{
//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(ElegantSword).Assembly.GetManifestResourceStream("ElegantSword." + name);
using MemoryStream memoryStream = new MemoryStream();
stream.CopyTo(memoryStream);
if (!ImageConversion.LoadImage(val2, memoryStream.ToArray(), true))
{
throw new InvalidDataException("Could not load " + name);
}
return val2;
}
private static Mesh ReadMesh()
{
//IL_0093: Unknown result type (might be due to invalid IL or missing references)
//IL_0098: Unknown result type (might be due to invalid IL or missing references)
//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
//IL_00db: Unknown result type (might be due to invalid IL or missing references)
//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
//IL_00f9: Expected O, but got Unknown
using BinaryReader binaryReader = new BinaryReader(typeof(ElegantSword).Assembly.GetManifestResourceStream("ElegantSword.ElegantMesh"));
int num = binaryReader.ReadInt32();
if (num <= 0 || num > 65535 || num % 3 != 0 || binaryReader.BaseStream.Length != 4 + 32 * num)
{
throw new InvalidDataException("Unexpected Elegant Sword mesh layout.");
}
Vector3[] array = (Vector3[])(object)new Vector3[num];
Vector3[] array2 = (Vector3[])(object)new Vector3[num];
Vector2[] array3 = (Vector2[])(object)new Vector2[num];
int[] array4 = new int[num];
for (int i = 0; i < num; i++)
{
ref Vector3 reference = ref array[i];
reference = new Vector3(binaryReader.ReadSingle(), binaryReader.ReadSingle(), binaryReader.ReadSingle());
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());
array4[i] = i;
}
Mesh val = new Mesh();
((Object)val).name = "Elegant Sword";
val.vertices = array;
val.normals = array2;
val.uv = array3;
Mesh val2 = val;
val2.SetTriangles(array4, 0);
val2.RecalculateBounds();
val2.RecalculateTangents();
return val2;
}
private static void ApplyBladeDamage(Item __0)
{
//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
//IL_00da: Expected O, but got Unknown
//IL_01aa: Unknown result type (might be due to invalid IL or missing references)
//IL_01b1: Expected O, but got Unknown
Weapon val = (Weapon)(object)((__0 is Weapon) ? __0 : null);
if (!Object.op_Implicit((Object)(object)val) || ((Item)val).ItemID != -847510)
{
return;
}
WeaponStats component = ((Component)val).GetComponent<WeaponStats>();
Item itemPrefab = ResourcesPrefabManager.Instance.GetItemPrefab(2000010);
WeaponStats val2 = (Object.op_Implicit((Object)(object)itemPrefab) ? ((Component)itemPrefab).GetComponent<WeaponStats>() : null);
if (!Object.op_Implicit((Object)(object)component) || !Object.op_Implicit((Object)(object)val2) || val2.BaseDamage == null || val2.BaseDamage.TotalDamage <= 0f || val2.Attacks == null)
{
log.LogWarning((object)"Could not find the Iron Sword damage data for Elegant Sword.");
return;
}
float totalDamage = val2.BaseDamage.TotalDamage;
GearSettings gearSettings = DamascusCollection.Gear[-847510];
float num = gearSettings.Damage / totalDamage;
DamageList val3 = val2.BaseDamage.Clone() * num;
val3.Add(new DamageType((Types)1, gearSettings.Ethereal));
component.BaseDamage = val3;
AttackData[] array = (AttackData[])val2.Attacks.Clone();
for (int i = 0; i < array.Length; i++)
{
AttackData val4 = array[i];
if (val4 == null || val4.Damage == null || val4.Damage.Count == 0)
{
continue;
}
List<float> list = new List<float>(val4.Damage);
for (int j = 0; j < list.Count; j++)
{
if (list[j] >= 0f)
{
list[j] *= num;
}
}
float num2 = val4.Damage[0];
list.Add((num2 < 0f) ? num2 : (gearSettings.Ethereal * num2 / totalDamage));
int num3 = i;
AttackData val5 = new AttackData();
val5.Damage = list;
val5.Knockback = val4.Knockback;
val5.StamCost = val4.StamCost;
val5.AttackSpeed = val4.AttackSpeed;
array[num3] = val5;
}
component.Attacks = array;
gearSettings.Apply((EquipmentStats)(object)component);
((Item)val).InitCachedInfos();
log.LogInfo((object)("Elegant Sword native attack entries: " + array.Length + "; donor arrays unchanged: " + !object.ReferenceEquals(component.Attacks, val2.Attacks)));
log.LogInfo((object)("Elegant Sword base damage: " + val.GetBaseDamageOfType((Types)0) + " physical + " + val.GetBaseDamageOfType((Types)1) + " ethereal. Impact: " + component.Impact + ". Attack speed: " + component.AttackSpeed + "."));
}
}
internal static class DamascusPistol
{
private sealed class Finish
{
public const string MaterialName = "DamascusPistolSteelAndEbony";
public readonly Texture2D Albedo = LoadTexture("Albedo", linear: false);
public readonly Texture2D Surface = LoadTexture("Surface", linear: true);
public readonly Texture2D Normal = LoadTexture("Normal", linear: true);
public bool Matches(Material material)
{
if (!(((Object)material).name == "DamascusPistolSteelAndEbony"))
{
return ((Object)material).name.StartsWith("mat_itm_atlasPistolA", StringComparison.Ordinal);
}
return true;
}
}
private const string PluginId = "local.dylan.damascuspistol";
private const int ItemId = -847530;
private const string VisualName = "-847530_DamascusPistol_v";
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 Finish pistolFinish;
private static ConfigEntry<string> seeded;
private static HashSet<string> seededSaves;
internal static void Initialize(ConfigFile config, ManualLogSource logger)
{
//IL_0055: Unknown result type (might be due to invalid IL or missing references)
//IL_005b: Expected O, but got Unknown
pistolFinish = new Finish();
seeded = config.Bind<string>("Shop State", "PistolSeededSaves", "", "Saves that received initial Damascus Pistol shop stock.");
seededSaves = new HashSet<string>(seeded.Value.Split(new char[1] { ',' }, StringSplitOptions.RemoveEmptyEntries));
Harmony val = new Harmony("local.dylan.damascuspistol");
MethodInfo methodInfo = AccessTools.Method(AccessTools.TypeByName("SideLoader.CustomItemVisuals"), "CloneAndSetVisuals", (Type[])null, (Type[])null);
val.Patch((MethodBase)methodInfo, (HarmonyMethod)null, Patch("RecolorClone"), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
val.Patch((MethodBase)AccessTools.Method(typeof(SL_ProjectileWeapon), "ApplyToItem", new Type[1] { typeof(Item) }, (Type[])null), (HarmonyMethod)null, Patch("ApplyDamage"), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
val.Patch((MethodBase)AccessTools.Method(typeof(VisualSlot), "PositionVisuals", new Type[1] { typeof(Item) }, (Type[])null), (HarmonyMethod)null, Patch("RecolorEquipped"), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
val.Patch((MethodBase)AccessTools.Method(typeof(Item), "GetBuyValue", new Type[3]
{
typeof(Character),
typeof(Merchant),
typeof(bool)
}, (Type[])null), (HarmonyMethod)null, Patch("SetBuyPrice"), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
val.Patch((MethodBase)AccessTools.Method(typeof(MerchantPouch), "RefreshInventory", new Type[1] { typeof(Dropable) }, (Type[])null), Patch("BeforeRestock"), Patch("AfterRestock"), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
val.Patch((MethodBase)AccessTools.Method(typeof(Merchant), "OnReceiveConfirmStartShopping", new Type[2]
{
typeof(bool),
typeof(Character)
}, (Type[])null), Patch("SeedExistingStock"), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
}
private static HarmonyMethod Patch(string name)
{
//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(DamascusPistol), name, (Type[])null);
val.priority = 0;
return val;
}
private static void RecolorClone(Item __0, GameObject __1, GameObject __result)
{
if (Object.op_Implicit((Object)(object)__0) && __0.ItemID == -847530 && Object.op_Implicit((Object)(object)__result) && !((Object)(object)__result == (Object)(object)__1))
{
((Object)__result).name = "-847530_DamascusPistol_v";
ApplyFinish(__result);
}
}
private static void RecolorEquipped(VisualSlot __instance, Item __0)
{
if (Object.op_Implicit((Object)(object)__0) && __0.ItemID == -847530)
{
ItemVisual currentVisual = __instance.CurrentVisual;
if (Object.op_Implicit((Object)(object)currentVisual) && currentVisual.GetItemIDFromName() == -847530)
{
ApplyFinish(((Component)currentVisual).gameObject);
}
}
}
private static void ApplyDamage(Item __0)
{
//IL_0081: Unknown result type (might be due to invalid IL or missing references)
//IL_0165: Unknown result type (might be due to invalid IL or missing references)
//IL_016c: Expected O, but got Unknown
ProjectileWeapon val = (ProjectileWeapon)(object)((__0 is ProjectileWeapon) ? __0 : null);
if (!Object.op_Implicit((Object)(object)val) || ((Item)val).ItemID != -847530)
{
return;
}
WeaponStats component = ((Component)val).GetComponent<WeaponStats>();
Item itemPrefab = ResourcesPrefabManager.Instance.GetItemPrefab(5110100);
WeaponStats val2 = (Object.op_Implicit((Object)(object)itemPrefab) ? ((Component)itemPrefab).GetComponent<WeaponStats>() : null);
if (!Object.op_Implicit((Object)(object)component) || !Object.op_Implicit((Object)(object)val2) || object.ReferenceEquals(component, val2) || val2.BaseDamage == null || val2.BaseDamage.Count != 1 || (int)val2.BaseDamage[0].Type != 0 || val2.BaseDamage.TotalDamage <= 0f || val2.Attacks == null)
{
return;
}
float totalDamage = val2.BaseDamage.TotalDamage;
GearSettings gearSettings = DamascusCollection.Gear[-847530];
float num = ((gearSettings.Damage < 0f) ? (totalDamage + gearSettings.PistolBonus) : gearSettings.Damage) / totalDamage;
AttackData[] array = (AttackData[])val2.Attacks.Clone();
for (int i = 0; i < array.Length; i++)
{
AttackData val3 = array[i];
if (val3 != null && val3.Damage != null && val3.Damage.Count != 0 && !(val3.Damage[0] < 0f))
{
List<float> list = new List<float>(val3.Damage);
list[0] *= num;
int num2 = i;
AttackData val4 = new AttackData();
val4.Damage = list;
val4.Knockback = val3.Knockback;
val4.StamCost = val3.StamCost;
val4.AttackSpeed = val3.AttackSpeed;
array[num2] = val4;
}
}
component.BaseDamage = val2.BaseDamage.Clone() * num;
component.Attacks = array;
gearSettings.Apply((EquipmentStats)(object)component);
((Item)val).InitCachedInfos();
}
private static bool IsTokuga(Merchant merchant)
{
//IL_000e: Unknown result type (might be due to invalid IL or missing references)
//IL_0013: Unknown result type (might be due to invalid IL or missing references)
//IL_0028: Unknown result type (might be due to invalid IL or missing references)
//IL_0032: Unknown result type (might be due to invalid IL or missing references)
//IL_003f: Unknown result type (might be due to invalid IL or missing references)
//IL_0049: Unknown result type (might be due to invalid IL or missing references)
if (Object.op_Implicit((Object)(object)merchant))
{
Scene scene = ((Component)merchant).gameObject.scene;
if (((Scene)(ref scene)).name == "Levant")
{
if (!(merchant.HolderUID == UID.op_Implicit("3Rx_R0XDLUmYaNWm66SVCQ")))
{
return merchant.HolderUID == UID.op_Implicit("EYhBqM653UGhDd5kcdMFXg");
}
return true;
}
}
return false;
}
private static void SetBuyPrice(Item __instance, Character __0, Merchant __1, bool __2, ref int __result)
{
//IL_0035: Unknown result type (might be due to invalid IL or missing references)
if (__instance.ItemID == -847530 && IsTokuga(__1) && (__2 || !Object.op_Implicit((Object)(object)__0) || !(EnvironmentConditions.GameTime < __instance.RebuyLimitTime) || !(__instance.PreviousOwnerUID == UID.op_Implicit(__0.UID))))
{
__result = DamascusCollection.Gear[-847530].Price;
}
}
private static void BeforeRestock(MerchantPouch __instance, double ___m_nextRefreshTime, out bool __state)
{
__state = !PhotonNetwork.isNonMasterClientInRoom && EnvironmentConditions.GameTime >= ___m_nextRefreshTime && IsTokuga(__instance.Merchant);
}
private static void AfterRestock(MerchantPouch __instance, bool __state)
{
if (__state)
{
EnsureStock(__instance);
}
}
private static void SeedExistingStock(Merchant __instance, bool __0, Character __1)
{
//IL_0044: Unknown result type (might be due to invalid IL or missing references)
//IL_0054: Unknown result type (might be due to invalid IL or missing references)
if (!__0 || !Object.op_Implicit((Object)(object)__1) || PhotonNetwork.isNonMasterClientInRoom || !IsTokuga(__instance))
{
return;
}
ItemContainer merchantPouch = __instance.MerchantPouch;
MerchantPouch val = (MerchantPouch)(object)((merchantPouch is MerchantPouch) ? merchantPouch : null);
Character worldHostCharacter = CharacterManager.Instance.GetWorldHostCharacter();
if (Object.op_Implicit((Object)(object)val) && Object.op_Implicit((Object)(object)worldHostCharacter))
{
string item = UID.op_Implicit(worldHostCharacter.UID) + ":" + UID.op_Implicit(__instance.HolderUID);
if (!seededSaves.Contains(item) && EnsureStock(val))
{
seededSaves.Add(item);
seeded.Value = string.Join(",", seededSaves);
}
}
}
private static bool EnsureStock(MerchantPouch pouch)
{
//IL_0049: Unknown result type (might be due to invalid IL or missing references)
//IL_004f: Expected O, but got Unknown
if (((ItemContainer)pouch).GetItemsFromID(-847530).Exists((Item item) => Object.op_Implicit((Object)(object)item) && !item.IsPendingDestroy))
{
return true;
}
if (!Object.op_Implicit((Object)(object)ResourcesPrefabManager.Instance.GetItemPrefab(-847530)))
{
return false;
}
SL_ItemDrop val = new SL_ItemDrop();
val.DroppedItemID = -847530;
val.MinQty = 1;
val.MaxQty = 1;
val.GenerateDrop(((Component)pouch).transform);
return ((ItemContainer)pouch).GetItemsFromID(-847530).Exists((Item item) => Object.op_Implicit((Object)(object)item) && !item.IsPendingDestroy);
}
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 = "DamascusPistol" + resource;
((Texture)val).anisoLevel = 4;
Texture2D val2 = val;
using Stream stream = typeof(DamascusPistol).Assembly.GetManifestResourceStream("DamascusPistol." + 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 int ApplyFinish(GameObject model)
{
//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
//IL_00ec: Expected O, but got Unknown
int num = 0;
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) || !val2.HasProperty(MainTex) || !val2.HasProperty(GenTex) || !val2.HasProperty(NormTex))
{
continue;
}
Finish finish = (pistolFinish.Matches(val2) ? pistolFinish : null);
if (finish == null)
{
continue;
}
num++;
if (!((Object)(object)val2.GetTexture(MainTex) == (Object)(object)finish.Albedo) || !((Object)(object)val2.GetTexture(GenTex) == (Object)(object)finish.Surface) || !((Object)(object)val2.GetTexture(NormTex) == (Object)(object)finish.Normal))
{
Material val3 = new Material(val2);
((Object)val3).name = "DamascusPistolSteelAndEbony";
Material val4 = val3;
val4.SetTexture(MainTex, (Texture)(object)finish.Albedo);
val4.SetTexture(GenTex, (Texture)(object)finish.Surface);
val4.SetTexture(NormTex, (Texture)(object)finish.Normal);
val4.DisableKeyword("_DETAIL");
val4.DisableKeyword("_DETAIL_ALBEDO");
val4.DisableKeyword("_DETAIL_TEXTURED");
val4.DisableKeyword("_SPEC_COLOR");
if (val4.HasProperty("_EmissionTex"))
{
val4.SetTexture("_EmissionTex", (Texture)(object)Texture2D.blackTexture);
val4.DisableKeyword("_EMISSION");
val4.DisableKeyword("_EMISSION_TEXTURED");
}
val4.EnableKeyword("_NORMALMAP");
val4.EnableKeyword("_SPECGLOSSMAP");
val4.SetFloat("_SpecBoost", 0.015f);
val4.SetFloat("_GlossMin", 0.035f);
val4.SetFloat("_SmoothMin", 0.035f);
sharedMaterials[j] = val4;
flag = true;
}
}
if (flag)
{
val.sharedMaterials = sharedMaterials;
}
}
return num;
}
}