using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Text;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using HarmonyLib;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("UsefulTrophies")]
[assembly: AssemblyDescription("https://valheim.thunderstore.io/package/probablykory/UsefulTrophies/")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("probablykory")]
[assembly: AssemblyProduct("UsefulTrophies")]
[assembly: AssemblyCopyright("Copyright probablykory © 2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("fba93479-93ac-43d9-8ef2-cfb83bdb7b6d")]
[assembly: AssemblyFileVersion("1.0.7")]
[assembly: TargetFramework(".NETFramework,Version=v4.6.2", FrameworkDisplayName = ".NET Framework 4.6.2")]
[assembly: AssemblyVersion("1.0.7.0")]
public sealed class ConfigurationManagerAttributes
{
public delegate void CustomHotkeyDrawerFunc(ConfigEntryBase setting, ref bool isCurrentlyAcceptingInput);
public bool? ShowRangeAsPercent;
public Action<ConfigEntryBase> CustomDrawer;
public CustomHotkeyDrawerFunc CustomHotkeyDrawer;
public bool? Browsable;
public string Category;
public object DefaultValue;
public bool? HideDefaultButton;
public bool? HideSettingName;
public string Description;
public string DispName;
public int? Order;
public bool? ReadOnly;
public bool? IsAdvanced;
public Func<object, string> ObjToStr;
public Func<string, object> StrToObj;
}
namespace UsefulTrophies;
public class TrophyConfig
{
public string Prefab;
public int Experience;
public int Value;
}
public static class TrophyEntry
{
public static TrophyConfig[] Deserialize(string trophies)
{
return trophies.Split(new char[1] { ',' }).Select(delegate(string r)
{
string[] array = r.Split(new char[1] { ':' });
int result;
int result2;
return new TrophyConfig
{
Prefab = array[0],
Experience = ((array.Length <= 1 || !int.TryParse(array[1], out result)) ? 1 : result),
Value = ((array.Length > 2 && int.TryParse(array[2], out result2)) ? result2 : 0)
};
}).ToArray();
}
public static string Serialize(TrophyConfig[] trophies)
{
return string.Join(",", trophies.Select((TrophyConfig r) => (r.Value <= 0) ? $"{r.Prefab}:{r.Experience}" : $"{r.Prefab}:{r.Experience}:{r.Value}"));
}
}
public class BossPowerConfig
{
public string Prefab;
public int Duration;
}
public static class BossPowerEntry
{
public static BossPowerConfig[] Deserialize(string powers)
{
return powers.Split(new char[1] { ',' }).Select(delegate(string r)
{
string[] array = r.Split(new char[1] { ':' });
int result;
return new BossPowerConfig
{
Prefab = array[0],
Duration = ((array.Length <= 1 || !int.TryParse(array[1], out result)) ? 1 : result)
};
}).ToArray();
}
public static string Serialize(BossPowerConfig[] powers)
{
return string.Join(",", powers.Select((BossPowerConfig r) => $"{r.Prefab}:{r.Duration}"));
}
}
public interface IPlugin
{
ConfigFile Config { get; }
}
internal static class ConfigHelper
{
public static ConfigEntry<string> ItemRequirementsConfig()
{
return null;
}
public static ConfigurationManagerAttributes GetTags(Action<ConfigEntryBase> action)
{
return new ConfigurationManagerAttributes
{
CustomDrawer = action
};
}
public static ConfigurationManagerAttributes GetTags()
{
return new ConfigurationManagerAttributes();
}
public static ConfigEntry<T> Config<T>(this IPlugin instance, string group, string name, T value, ConfigDescription description)
{
return instance.Config.Bind<T>(group, name, value, description);
}
public static ConfigEntry<T> Config<T>(this IPlugin instance, string group, string name, T value, string description)
{
//IL_0015: Unknown result type (might be due to invalid IL or missing references)
//IL_001f: Expected O, but got Unknown
return instance.Config(group, name, value, new ConfigDescription(description, (AcceptableValueBase)null, new object[1] { GetTags() }));
}
}
public class AcceptableValueConfigNote : AcceptableValueBase
{
public virtual string Note { get; }
public AcceptableValueConfigNote(string note)
: base(typeof(string))
{
if (string.IsNullOrEmpty(note))
{
throw new ArgumentException("A string with atleast 1 character is needed", "Note");
}
Note = note;
}
public override object Clamp(object value)
{
return value;
}
public override bool IsValid(object value)
{
return !string.IsNullOrEmpty(value as string);
}
public override string ToDescriptionString()
{
return "# Note: " + Note;
}
}
public static class ConfigDrawers
{
private static BaseUnityPlugin configManager;
private static BaseUnityPlugin GetConfigManager()
{
if ((Object)(object)configManager == (Object)null && Chainloader.PluginInfos.TryGetValue("com.bepis.bepinex.configurationmanager", out var value) && Object.op_Implicit((Object)(object)value.Instance))
{
configManager = value.Instance;
}
return configManager;
}
private static int GetRightColumnWidth()
{
int result = 130;
BaseUnityPlugin val = GetConfigManager();
if ((Object)(object)val != (Object)null)
{
PropertyInfo propertyInfo = ((object)val)?.GetType().GetProperty("RightColumnWidth", BindingFlags.Instance | BindingFlags.NonPublic);
if (propertyInfo != null)
{
result = (int)propertyInfo.GetValue(val);
}
}
return result;
}
public static Action<ConfigEntryBase> DrawTrophyConfigTable()
{
return delegate(ConfigEntryBase cfg)
{
//IL_005c: Unknown result type (might be due to invalid IL or missing references)
//IL_0061: Unknown result type (might be due to invalid IL or missing references)
//IL_0082: Expected O, but got Unknown
//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
//IL_00e3: Expected O, but got Unknown
//IL_0112: Unknown result type (might be due to invalid IL or missing references)
//IL_0117: Unknown result type (might be due to invalid IL or missing references)
//IL_012c: Expected O, but got Unknown
//IL_0150: Unknown result type (might be due to invalid IL or missing references)
//IL_0155: Unknown result type (might be due to invalid IL or missing references)
//IL_016a: Expected O, but got Unknown
//IL_01a2: Unknown result type (might be due to invalid IL or missing references)
//IL_01a7: Unknown result type (might be due to invalid IL or missing references)
//IL_01bc: Expected O, but got Unknown
List<TrophyConfig> list = new List<TrophyConfig>();
bool flag = false;
int rightColumnWidth = GetRightColumnWidth();
GUILayout.BeginVertical(Array.Empty<GUILayoutOption>());
foreach (TrophyConfig item in TrophyEntry.Deserialize((string)cfg.BoxedValue).ToList())
{
GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
string text = GUILayout.TextField(item.Prefab, new GUIStyle(GUI.skin.textField)
{
fixedWidth = rightColumnWidth - 40 - 40 - 21 - 21 - 9
}, Array.Empty<GUILayoutOption>());
string text2 = (string.IsNullOrEmpty(text) ? item.Prefab : text);
flag = flag || text2 != item.Prefab;
int num = item.Experience;
if (int.TryParse(GUILayout.TextField(num.ToString(), new GUIStyle(GUI.skin.textField)
{
fixedWidth = 40f
}, Array.Empty<GUILayoutOption>()), out var result) && result != num)
{
num = result;
flag = true;
}
int value = item.Value;
if (int.TryParse(GUILayout.TextField(value.ToString(), new GUIStyle(GUI.skin.textField)
{
fixedWidth = 40f
}, Array.Empty<GUILayoutOption>()), out var result2) && result2 != num)
{
value = result2;
flag = true;
}
if (GUILayout.Button("x", new GUIStyle(GUI.skin.button)
{
fixedWidth = 21f
}, Array.Empty<GUILayoutOption>()))
{
flag = true;
}
else
{
list.Add(new TrophyConfig
{
Prefab = text2,
Experience = num,
Value = value
});
}
if (GUILayout.Button("+", new GUIStyle(GUI.skin.button)
{
fixedWidth = 21f
}, Array.Empty<GUILayoutOption>()))
{
flag = true;
list.Add(new TrophyConfig
{
Prefab = "<Prefab Name>",
Experience = 10,
Value = 10
});
}
GUILayout.EndHorizontal();
}
GUILayout.EndVertical();
if (flag)
{
cfg.BoxedValue = TrophyEntry.Serialize(list.ToArray());
}
};
}
public static Action<ConfigEntryBase> DrawBossPowerConfigTable()
{
return delegate(ConfigEntryBase cfg)
{
//IL_005c: Unknown result type (might be due to invalid IL or missing references)
//IL_0061: Unknown result type (might be due to invalid IL or missing references)
//IL_007f: Expected O, but got Unknown
//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
//IL_00e0: Expected O, but got Unknown
//IL_0104: Unknown result type (might be due to invalid IL or missing references)
//IL_0109: Unknown result type (might be due to invalid IL or missing references)
//IL_011e: Expected O, but got Unknown
//IL_014e: Unknown result type (might be due to invalid IL or missing references)
//IL_0153: Unknown result type (might be due to invalid IL or missing references)
//IL_0168: Expected O, but got Unknown
List<BossPowerConfig> list = new List<BossPowerConfig>();
bool flag = false;
int rightColumnWidth = GetRightColumnWidth();
GUILayout.BeginVertical(Array.Empty<GUILayoutOption>());
foreach (BossPowerConfig item in BossPowerEntry.Deserialize((string)cfg.BoxedValue).ToList())
{
GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
string text = GUILayout.TextField(item.Prefab, new GUIStyle(GUI.skin.textField)
{
fixedWidth = rightColumnWidth - 40 - 21 - 21 - 9
}, Array.Empty<GUILayoutOption>());
string text2 = (string.IsNullOrEmpty(text) ? item.Prefab : text);
flag = flag || text2 != item.Prefab;
int num = item.Duration;
if (int.TryParse(GUILayout.TextField(num.ToString(), new GUIStyle(GUI.skin.textField)
{
fixedWidth = 40f
}, Array.Empty<GUILayoutOption>()), out var result) && result != num)
{
num = result;
flag = true;
}
if (GUILayout.Button("x", new GUIStyle(GUI.skin.button)
{
fixedWidth = 21f
}, Array.Empty<GUILayoutOption>()))
{
flag = true;
}
else
{
list.Add(new BossPowerConfig
{
Prefab = text2,
Duration = num
});
}
if (GUILayout.Button("+", new GUIStyle(GUI.skin.button)
{
fixedWidth = 21f
}, Array.Empty<GUILayoutOption>()))
{
flag = true;
list.Add(new BossPowerConfig
{
Prefab = "<Prefab Name>",
Duration = 120
});
}
GUILayout.EndHorizontal();
}
GUILayout.EndVertical();
if (flag)
{
cfg.BoxedValue = BossPowerEntry.Serialize(list.ToArray());
}
};
}
public static Action<ConfigEntryBase> DrawConfigActionButton(string buttonName, Action buttonAction)
{
return delegate
{
GUILayout.BeginVertical(Array.Empty<GUILayoutOption>());
if (GUILayout.Button(buttonName, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(true) }) && buttonAction != null)
{
buttonAction();
}
GUILayout.EndVertical();
};
}
}
[HarmonyPatch]
public static class Patches
{
private static MethodInfo getPlayersInRange;
[HarmonyPatch(typeof(InventoryGrid), "UpdateGui", new Type[]
{
typeof(Player),
typeof(ItemData)
})]
[HarmonyPrefix]
private static bool InventoryGridUpdateGui(InventoryGrid __instance, Player player, ItemData dragItem)
{
if (!UsefulTrophies.Instance.IsSellingEnabled)
{
return true;
}
if ((Object)(object)player != (Object)null)
{
object obj;
if (player == null)
{
obj = null;
}
else
{
Inventory inventory = ((Humanoid)player).GetInventory();
obj = ((inventory != null) ? inventory.GetAllItems() : null);
}
foreach (ItemData item in (List<ItemData>)obj)
{
object obj2;
if (item == null)
{
obj2 = null;
}
else
{
GameObject dropPrefab = item.m_dropPrefab;
obj2 = ((dropPrefab != null) ? ((Object)dropPrefab).name : null);
}
string key = (string)obj2;
if (UsefulTrophies.Instance.TrophyCoinValues.TryGetValue(key, out var value))
{
item.m_shared.m_value = value;
}
}
}
return true;
}
[HarmonyPatch(typeof(ItemData), "GetTooltip", new Type[]
{
typeof(ItemData),
typeof(int),
typeof(bool),
typeof(float)
})]
[HarmonyPostfix]
public static string ItemDataGetTooltip(string __result, ItemData item)
{
string result = __result;
object obj;
if (item == null)
{
obj = null;
}
else
{
GameObject dropPrefab = item.m_dropPrefab;
obj = ((dropPrefab != null) ? ((Object)dropPrefab).name : null);
}
string text = (string)obj;
if (string.IsNullOrEmpty(text))
{
return result;
}
if (UsefulTrophies.Instance.TrophyXPGoldValues.Value.Contains(text) || (UsefulTrophies.Instance.CanConsumeBossSummonItems && UsefulTrophies.Instance.SecondaryBossPowerValues.ContainsKey(text)))
{
StringBuilder stringBuilder = new StringBuilder(256);
stringBuilder.Append(__result);
if (UsefulTrophies.Instance.TrophyXPValues.TryGetValue(text, out var value))
{
stringBuilder.Append($"\nApplies <color=orange>{value}</color> skill points");
}
string value2 = "";
int value3 = 0;
if (UsefulTrophies.Instance.CanConsumeBossTrophies && UsefulTrophies.Instance.BossPowerDict.TryGetValue(text, out value2))
{
value3 = UsefulTrophies.Instance.BossPowerDuration;
}
if ((string.IsNullOrWhiteSpace(value2) || value3 == 0) && UsefulTrophies.Instance.CanConsumeBossSummonItems && UsefulTrophies.Instance.SecondaryPowerDict.TryGetValue(text, out value2))
{
UsefulTrophies.Instance.SecondaryBossPowerValues.TryGetValue(text, out value3);
}
if (!string.IsNullOrWhiteSpace(value2) && value3 > 0)
{
value2 = value2.Substring(3);
if (value > 0)
{
stringBuilder.Append("\n");
}
stringBuilder.Append("\nContains the power of <color=orange>" + value2 + "</color>");
}
result = (__result = stringBuilder.ToString());
}
return result;
}
[HarmonyPatch(typeof(Player), "Load")]
[HarmonyPostfix]
private static void PlayerOnLoad(Player __instance)
{
if (!((Object)(object)Player.m_localPlayer == (Object)null))
{
UsefulTrophies.Instance.DetectAndWhitelistSkills(__instance);
}
}
[HarmonyPatch(typeof(Humanoid), "UseItem")]
[HarmonyPrefix]
private static bool HumanoidUseItem(Humanoid __instance, Inventory inventory, ItemData item, bool fromInventoryGui, Inventory ___m_inventory, ZSyncAnimation ___m_zanim)
{
//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
//IL_0132: Unknown result type (might be due to invalid IL or missing references)
//IL_0137: Unknown result type (might be due to invalid IL or missing references)
//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
//IL_0256: Unknown result type (might be due to invalid IL or missing references)
//IL_0339: Unknown result type (might be due to invalid IL or missing references)
//IL_036e: Unknown result type (might be due to invalid IL or missing references)
//IL_039f: Unknown result type (might be due to invalid IL or missing references)
//IL_03d1: Unknown result type (might be due to invalid IL or missing references)
//IL_03f6: Unknown result type (might be due to invalid IL or missing references)
//IL_0434: Unknown result type (might be due to invalid IL or missing references)
//IL_0468: Unknown result type (might be due to invalid IL or missing references)
//IL_046d: Unknown result type (might be due to invalid IL or missing references)
object obj;
if (item == null)
{
obj = null;
}
else
{
GameObject dropPrefab = item.m_dropPrefab;
obj = ((dropPrefab != null) ? ((Object)dropPrefab).name : null);
}
string text = (string)obj;
if (string.IsNullOrEmpty(text))
{
return false;
}
if (inventory == null)
{
inventory = ___m_inventory;
}
if (!inventory.ContainsItem(item))
{
return false;
}
if (UsefulTrophies.Instance.CanConsumeBossSummonItems && UsefulTrophies.Instance.SecondaryPowerDict.TryGetValue(text, out var value))
{
StatusEffect statusEffect = ObjectDB.instance.GetStatusEffect(StringExtensionMethods.GetStableHashCode(value));
if (!UsefulTrophies.Instance.SecondaryBossPowerValues.TryGetValue(text, out var value2))
{
value2 = 120;
}
OfferingBowl[] array = Object.FindObjectsOfType<OfferingBowl>();
if (array.Length != 0 && ((Object)array[0].m_bossItem).name == text && Vector3.Distance(((Component)__instance).transform.position, ((Component)array[0]).transform.position) < 10f)
{
Debug.Log((object)"Prevented Player from consuming summon item near offering bowl");
return true;
}
ApplyStatusEffect(statusEffect.Clone(), value2, ((Component)__instance).transform.position);
if (!UsefulTrophies.Instance.TrophyXPGoldValues.Value.Contains(text))
{
Debug.Log((object)("Consume " + text + " Secondary Boss Item!"));
inventory.RemoveOneItem(item);
__instance.m_consumeItemEffects.Create(((Component)Player.m_localPlayer).transform.position, Quaternion.identity, (Transform)null, 1f, -1);
___m_zanim.SetTrigger("eat");
return false;
}
}
if (UsefulTrophies.Instance.TrophyXPGoldValues.Value.Contains(text))
{
if (UsefulTrophies.Instance.BossPowerDict.ContainsKey(text))
{
if (!UsefulTrophies.Instance.CanConsumeBossTrophies)
{
return true;
}
if (UsefulTrophies.Instance.BossPowerDict.TryGetValue(text, out value))
{
StatusEffect statusEffect2 = ObjectDB.instance.GetStatusEffect(StringExtensionMethods.GetStableHashCode(value));
BossStone[] array2 = Object.FindObjectsOfType<BossStone>();
if (array2.Length > 1 && array2[0].m_itemStand.m_netViewOverride.IsValid())
{
bool flag = false;
BossStone[] array3 = array2;
foreach (BossStone val in array3)
{
if (val.IsActivated() && statusEffect2.m_name == val.m_itemStand.m_guardianPower.m_name)
{
flag = true;
break;
}
}
if (!flag)
{
Debug.Log((object)"Prevented Player from consuming boss trophy near BossStone");
return true;
}
}
ApplyStatusEffect(statusEffect2.Clone(), UsefulTrophies.Instance.BossPowerDuration, ((Component)__instance).transform.position);
}
}
GameObject hoverObject = __instance.GetHoverObject();
if ((Object.op_Implicit((Object)(object)hoverObject) ? hoverObject.GetComponentInParent<Hoverable>() : null) != null && !fromInventoryGui)
{
Interactable componentInParent = hoverObject.GetComponentInParent<Interactable>();
if (componentInParent != null && componentInParent.UseItem(__instance, item))
{
return false;
}
}
Debug.Log((object)("Consume " + text + "!"));
List<Skill> list = (from s in ((Character)__instance).GetSkills().GetSkillList()
where UsefulTrophies.Instance.WhitelistedSkills.Contains(s.m_info.m_skill)
select s).ToList();
float num = 10f;
if (UsefulTrophies.Instance.TrophyXPValues.TryGetValue(text, out var value3))
{
num = value3;
}
else
{
Debug.Log((object)("No XP value for prefab " + text + "!"));
}
Skill val2 = list[Random.Range(0, list.Count)];
string text2 = Utils.FromSkill(val2.m_info.m_skill);
float num2 = GetNextLevelRequirement(val2) - val2.m_accumulator;
float level = val2.m_level;
float accumulator = val2.m_accumulator;
((Character)__instance).RaiseSkill(val2.m_info.m_skill, num);
if (level == val2.m_level && accumulator == val2.m_accumulator)
{
UsefulTrophies.Instance.WhitelistedSkills.Remove(val2.m_info.m_skill);
list.Remove(val2);
val2 = list[Random.Range(0, list.Count)];
text2 = Utils.FromSkill(val2.m_info.m_skill);
num2 = GetNextLevelRequirement(val2) - val2.m_accumulator;
((Character)__instance).RaiseSkill(val2.m_info.m_skill, num);
}
Debug.Log((object)$"Raising {text2} by {num}");
for (num -= num2; num > 0f; num -= num2)
{
num2 = GetNextLevelRequirement(val2);
((Character)__instance).RaiseSkill(val2.m_info.m_skill, num);
}
inventory.RemoveOneItem(item);
__instance.m_consumeItemEffects.Create(((Component)Player.m_localPlayer).transform.position, Quaternion.identity, (Transform)null, 1f, -1);
___m_zanim.SetTrigger("eat");
((Character)__instance).Message((MessageType)2, "You increase your skill with " + text2, 0, (Sprite)null);
return false;
}
return true;
}
private static void ApplyStatusEffect(StatusEffect statusEffect, float time, Vector3 position)
{
//IL_0049: Unknown result type (might be due to invalid IL or missing references)
if (getPlayersInRange == null)
{
getPlayersInRange = typeof(Player).GetMethod("GetPlayersInRange", BindingFlags.Static | BindingFlags.NonPublic);
}
statusEffect.m_ttl = time;
List<Player> list = new List<Player>();
getPlayersInRange?.Invoke(null, new object[3] { position, 10f, list });
foreach (Player item in list)
{
((Character)item).GetSEMan().AddStatusEffect(statusEffect, true, 0, 0f);
}
}
private static float GetNextLevelRequirement(Skill skill)
{
return (float)((double)Mathf.Pow(skill.m_level + 1f, 1.5f) * 0.5 + 0.5);
}
}
public static class Utils
{
public static string FromSkill(SkillType skill)
{
return Localization.instance.Localize("$skill_" + ((object)(SkillType)(ref skill)).ToString().ToLower());
}
public static SkillType FromName(string englishName)
{
return (SkillType)Math.Abs(StringExtensionMethods.GetStableHashCode(englishName));
}
}
[BepInPlugin("probablykory.UsefulTrophies", "UsefulTrophies", "1.0.7")]
public class UsefulTrophies : BaseUnityPlugin, IPlugin
{
public const string PluginAuthor = "probablykory";
public const string PluginName = "UsefulTrophies";
public const string PluginVersion = "1.0.7";
public const string PluginGUID = "probablykory.UsefulTrophies";
public static UsefulTrophies Instance;
public List<TrophyConfig> TrophyConfigs = new List<TrophyConfig>();
public Dictionary<string, int> TrophyCoinValues = new Dictionary<string, int>();
public Dictionary<string, int> TrophyXPValues = new Dictionary<string, int>();
public Dictionary<string, int> SecondaryBossPowerValues = new Dictionary<string, int>();
public const string DefaultTrophyXPGoldValues = "TrophyDeer:8:15,TrophyBoar:4:10,TrophyNeck:10:10,TrophyGreydwarf:5:10,TrophyFox_TW:15:20,TrophyGreydwarfBrute:25:15,TrophyGreydwarfShaman:15:15,TrophyRazorback_TW:15:15,TrophyBlackBear_TW:15:15,TrophySkeleton:10:10,TrophySkeletonPoison:25:15,TrophyFrostTroll:30:50,TrophySurtling:25:15,TrophyLeech:25:15,TrophyDraugr:20:15,TrophyDraugrElite:30:30,TrophyBlob:20:20,TrophyRottingElk_TW:20:20,TrophyWraith:30:30,TrophyAbomination:100:100,TrophyWolf:35:25,TrophyFenring:40:30,TrophyHatchling:40:35,TrophySGolem:50:500,TrophyUlv:50:50,TrophyCultist:50:100,TrophyGoblin:50:35,TrophyGoblinBrute:50:50,TrophyGoblinShaman:50:50,TrophyLox:120:200,TrophyGrowth:50:50,TrophyDeathsquito:80:25,TrophySerpent:150:250,TrophyHare:50:40,TrophyGjall:100:150,TrophyTick:80:50,TrophyDvergr:300:300,TrophySeeker:150:50,TrophySeekerBrute:300:100,TrophyEikthyr:30:0,TrophyTheElder:80:0,TrophyBonemass:300:0,TrophyDragonQueen:500:0,TrophyGoblinKing:700:0,TrophySeekerQueen:1000:0,TrophySkeletonHildir:80:100,TrophyCultist_Hildir:300:200,TrophyGoblinBruteBrosBrute:600:300,TrophyGoblinBruteBrosShaman:600:300";
public const string DefaultSecondaryBossPowerDurations = "TrophyDeer:120,AncientSeed:120,WitheredBone:120,DragonEgg:300,GoblinTotem:120,DvergrKeyFragment:120";
public Dictionary<string, string> BossPowerDict = new Dictionary<string, string>
{
{ "TrophyEikthyr", "GP_Eikthyr" },
{ "TrophyTheElder", "GP_TheElder" },
{ "TrophyBonemass", "GP_Bonemass" },
{ "TrophyDragonQueen", "GP_Moder" },
{ "TrophyGoblinKing", "GP_Yagluth" },
{ "TrophySeekerQueen", "GP_Queen" }
};
public Dictionary<string, string> SecondaryPowerDict = new Dictionary<string, string>
{
{ "TrophyDeer", "GP_Eikthyr" },
{ "AncientSeed", "GP_TheElder" },
{ "WitheredBone", "GP_Bonemass" },
{ "DragonEgg", "GP_Moder" },
{ "GoblinTotem", "GP_Yagluth" },
{ "DvergrKeyFragment", "GP_Queen" }
};
public List<SkillType> WhitelistedSkills = new List<SkillType>();
public Harmony Harmony { get; } = new Harmony("probablykory.UsefulTrophies");
public ConfigEntry<bool> CanConsumeBossSummonItemsEntry { get; set; }
public bool CanConsumeBossSummonItems
{
get
{
if (!(CanConsumeBossSummonItemsEntry?.Value).Value)
{
return false;
}
return true;
}
}
public ConfigEntry<bool> CanConsumeBossTrophiesEntry { get; set; }
public bool CanConsumeBossTrophies
{
get
{
if (!(CanConsumeBossTrophiesEntry?.Value).Value)
{
return false;
}
return true;
}
}
public ConfigEntry<bool> IsSellingEnabledEntry { get; set; }
public bool IsSellingEnabled
{
get
{
if (!(IsSellingEnabledEntry?.Value).Value)
{
return false;
}
return true;
}
}
public ConfigEntry<int> BossPowerDurationEntry { get; set; }
public int BossPowerDuration
{
get
{
ConfigEntry<int> bossPowerDurationEntry = BossPowerDurationEntry;
if (bossPowerDurationEntry == null || bossPowerDurationEntry.Value <= 0)
{
return 0;
}
return (BossPowerDurationEntry?.Value).Value;
}
}
public ConfigEntry<string> TrophyXPGoldValues { get; set; }
public ConfigEntry<string> SecondaryBossPowerDurations { get; set; }
private void Awake()
{
//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
//IL_00bd: Expected O, but got Unknown
//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
//IL_00ff: Expected O, but got Unknown
//IL_0176: Unknown result type (might be due to invalid IL or missing references)
//IL_0180: Expected O, but got Unknown
Instance = this;
string group = "General";
CanConsumeBossSummonItemsEntry = Instance.Config(group, "CanConsumeBossSummonItems", value: true, "Allows you to consume boss summoning items for a short boss power buff.");
CanConsumeBossTrophiesEntry = Instance.Config(group, "CanConsumeBossTrophies", value: true, "Allows you to consume boss trophies.");
BossPowerDurationEntry = Instance.Config(group, "BossPowerDuration", 720, "The duration of boss power buff when you consume its trophy.");
IsSellingEnabledEntry = Instance.Config(group, "IsSellingEnabled", value: true, "Allows you to sell trophies to traders.");
TrophyXPGoldValues = Instance.Config(group, "Trophies", "TrophyDeer:8:15,TrophyBoar:4:10,TrophyNeck:10:10,TrophyGreydwarf:5:10,TrophyFox_TW:15:20,TrophyGreydwarfBrute:25:15,TrophyGreydwarfShaman:15:15,TrophyRazorback_TW:15:15,TrophyBlackBear_TW:15:15,TrophySkeleton:10:10,TrophySkeletonPoison:25:15,TrophyFrostTroll:30:50,TrophySurtling:25:15,TrophyLeech:25:15,TrophyDraugr:20:15,TrophyDraugrElite:30:30,TrophyBlob:20:20,TrophyRottingElk_TW:20:20,TrophyWraith:30:30,TrophyAbomination:100:100,TrophyWolf:35:25,TrophyFenring:40:30,TrophyHatchling:40:35,TrophySGolem:50:500,TrophyUlv:50:50,TrophyCultist:50:100,TrophyGoblin:50:35,TrophyGoblinBrute:50:50,TrophyGoblinShaman:50:50,TrophyLox:120:200,TrophyGrowth:50:50,TrophyDeathsquito:80:25,TrophySerpent:150:250,TrophyHare:50:40,TrophyGjall:100:150,TrophyTick:80:50,TrophyDvergr:300:300,TrophySeeker:150:50,TrophySeekerBrute:300:100,TrophyEikthyr:30:0,TrophyTheElder:80:0,TrophyBonemass:300:0,TrophyDragonQueen:500:0,TrophyGoblinKing:700:0,TrophySeekerQueen:1000:0,TrophySkeletonHildir:80:100,TrophyCultist_Hildir:300:200,TrophyGoblinBruteBrosBrute:600:300,TrophyGoblinBruteBrosShaman:600:300", new ConfigDescription("The trophy prefab names and their XP and Gold values.", (AcceptableValueBase)(object)new AcceptableValueConfigNote("You must use valid spawn item codes or this will not work."), new object[1] { ConfigHelper.GetTags(ConfigDrawers.DrawTrophyConfigTable()) }));
SecondaryBossPowerDurations = Instance.Config(group, "SummoningItems", "TrophyDeer:120,AncientSeed:120,WitheredBone:120,DragonEgg:300,GoblinTotem:120,DvergrKeyFragment:120", new ConfigDescription("The summon item prefab names and duration values.", (AcceptableValueBase)(object)new AcceptableValueConfigNote("You must use valid spawn item codes or this will not work."), new object[1] { ConfigHelper.GetTags(ConfigDrawers.DrawBossPowerConfigTable()) }));
Instance.Config(group, "resetWhitelist", 0, new ConfigDescription("", (AcceptableValueBase)null, new object[1]
{
new ConfigurationManagerAttributes
{
HideSettingName = true,
HideDefaultButton = true,
CustomDrawer = ConfigDrawers.DrawConfigActionButton("Reset list of boostable skills", delegate
{
Instance.DetectAndWhitelistSkills();
}).Invoke
}
}));
TrophyXPGoldValues.SettingChanged += RefreshDictionaries;
SecondaryBossPowerDurations.SettingChanged += RefreshDictionaries;
RefreshDictionaries(null, null);
Harmony.PatchAll();
}
private void RefreshDictionaries(object sender, EventArgs e)
{
List<TrophyConfig> source = TrophyEntry.Deserialize(Instance.TrophyXPGoldValues.Value).ToList();
List<BossPowerConfig> source2 = BossPowerEntry.Deserialize(Instance.SecondaryBossPowerDurations.Value).ToList();
TrophyCoinValues = source.ToDictionary((TrophyConfig t) => t.Prefab, (TrophyConfig t) => t.Value);
TrophyXPValues = source.ToDictionary((TrophyConfig t) => t.Prefab, (TrophyConfig t) => t.Experience);
SecondaryBossPowerValues = source2.ToDictionary((BossPowerConfig t) => t.Prefab, (BossPowerConfig t) => t.Duration);
}
public void DetectAndWhitelistSkills(Player player = null)
{
//IL_0064: Unknown result type (might be due to invalid IL or missing references)
//IL_006e: Expected O, but got Unknown
//IL_009e: 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)
if ((Object)(object)player == (Object)null)
{
player = Player.m_localPlayer;
}
if ((Object)(object)player == (Object)null)
{
return;
}
Instance.WhitelistedSkills.Clear();
Skills skills = ((Character)player).GetSkills();
FieldInfo fieldInfo = AccessTools.Field(typeof(MessageHud), "m_instance");
object? value = fieldInfo.GetValue(null);
MessageHud value2 = (MessageHud)((value is MessageHud) ? value : null);
fieldInfo.SetValue(null, null);
EffectList skillLevelupEffects = player.m_skillLevelupEffects;
player.m_skillLevelupEffects = new EffectList();
try
{
foreach (Skill skill in skills.GetSkillList())
{
float level = skill.m_level;
float accumulator = skill.m_accumulator;
skills.RaiseSkill(skill.m_info.m_skill, 1f);
if (level == skill.m_level && accumulator == skill.m_accumulator)
{
skill.m_level = level;
skill.m_accumulator = accumulator;
}
else
{
Instance.WhitelistedSkills.Add(skill.m_info.m_skill);
}
}
}
catch (Exception arg)
{
Debug.LogWarning((object)$"Caught error while detecting skill whitelist. Exception:\n{arg}");
Instance.WhitelistedSkills.Clear();
Instance.WhitelistedSkills.AddRange(from s in skills.GetSkillList()
select s.m_info.m_skill);
}
finally
{
fieldInfo.SetValue(null, value2);
player.m_skillLevelupEffects = skillLevelupEffects;
}
}
ConfigFile IPlugin.get_Config()
{
return ((BaseUnityPlugin)this).Config;
}
}