Please disclose if any significant portion of your mod was created using AI tools by adding the 'AI Generated' category. Failing to do so may result in the mod being removed from Thunderstore.
Decompiled source of VargheimRanching v1.1.2
VargheimRanching.dll
Decompiled 10 hours agousing System; using System.Collections.Generic; using System.Diagnostics; using System.Reflection; using System.Runtime.CompilerServices; using BepInEx; using BepInEx.Configuration; using HarmonyLib; using Microsoft.CodeAnalysis; using UnityEngine; using VargheimProfessions; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: AssemblyVersion("0.0.0.0")] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } namespace VargheimRanching { [BepInPlugin("digi.vargheim.ranching", "VargheimRanching", "1.1.2")] [BepInDependency("digi.vargheim.professions", "0.4.0")] public class Plugin : BaseUnityPlugin { private sealed class Orig { public float Run; public float Speed; public float Swim; public float Stamina; public float Regen; } private sealed class Saved { public float A; public float B; } [HarmonyPatch] internal static class Patches { [HarmonyPatch(typeof(Procreation), "Awake")] [HarmonyPostfix] private static void ProcAwake(Procreation __instance) { if (__instance.m_partnerCheckRange < PartnerRange.Value) { __instance.m_partnerCheckRange = PartnerRange.Value; } } [HarmonyPatch(typeof(Tameable), "Tame")] [HarmonyPrefix] private static bool Tame(Tameable __instance) { //IL_0021: Unknown result type (might be due to invalid IL or missing references) try { string text = PrefabName(((Component)__instance).gameObject); if (Api.Active && !Content.IsVanillaPrefab(text) && BestRancherNear(((Component)__instance).transform.position, NearRange.Value) < StockLevel.Value) { return false; } } catch { } return true; } [HarmonyPatch(typeof(Character), "RPC_Damage")] [HarmonyPrefix] private static void Damage(Character __instance, HitData hit) { //IL_0019: Unknown result type (might be due to invalid IL or missing references) try { if (hit != null && !(__instance is Player) && __instance.IsTamed() && BestRancherNear(((Component)__instance).transform.position, NearRange.Value) >= GentleLevel.Value) { hit.ApplyModifier(1f - GentleCut.Value); } } catch { } } [HarmonyPatch(typeof(Procreation), "Procreate")] [HarmonyPrefix] [HarmonyPriority(800)] private static void ProcPre(Procreation __instance, out Saved __state) { //IL_000f: Unknown result type (might be due to invalid IL or missing references) __state = null; s_cur = __instance; try { int num = BestRancherNear(((Component)__instance).transform.position, BreedRange.Value); if (num >= BreedLevel.Value) { __state = new Saved { A = __instance.m_pregnancyDuration, B = __instance.m_pregnancyChance }; __instance.m_pregnancyDuration *= 1f - BreedFaster.Value; __instance.m_pregnancyChance = Mathf.Min(1f, __instance.m_pregnancyChance / Mathf.Max(0.05f, 1f - BreedFaster.Value)); } s_birth = num >= BloodLevel.Value; } catch { } } [HarmonyPatch(typeof(Procreation), "Procreate")] [HarmonyFinalizer] private static void ProcPost(Procreation __instance, Saved __state) { s_birth = false; s_cur = null; if (__state != null) { __instance.m_pregnancyDuration = __state.A; __instance.m_pregnancyChance = __state.B; } } [HarmonyPatch(typeof(Character), "SetLevel")] [HarmonyPrefix] private static void SetLevel(ref int level) { if (s_birth && Random.value < BloodChance.Value) { level++; s_birth = false; } } [HarmonyPatch(typeof(Growup), "GrowUpdate")] [HarmonyPrefix] private static void GrowPre(Growup __instance, out float __state) { //IL_000d: Unknown result type (might be due to invalid IL or missing references) __state = -1f; try { if (BestRancherNear(((Component)__instance).transform.position, BreedRange.Value) >= BreedLevel.Value) { __state = __instance.m_growTime; __instance.m_growTime *= 1f - BreedFaster.Value; } } catch { } } [HarmonyPatch(typeof(Growup), "GrowUpdate")] [HarmonyFinalizer] private static void GrowPost(Growup __instance, float __state) { if (__state >= 0f) { __instance.m_growTime = __state; } } [HarmonyPatch(typeof(CharacterDrop), "GenerateDropList")] [HarmonyPostfix] private static void Butcher(CharacterDrop __instance, List<KeyValuePair<GameObject, int>> __result) { try { Character value = Traverse.Create((object)__instance).Field("m_character").GetValue<Character>(); if ((Object)(object)value == (Object)null || !value.IsTamed() || __result == null) { return; } HitData val = s_lastHit.Invoke(value); Player val2 = (Player)((val != null) ? /*isinst with value type is only supported in some contexts*/: null); if ((Object)(object)val2 == (Object)null || Api.PerkLevelOf(val2, "Ranching") < ButcherLevel.Value) { return; } for (int i = 0; i < __result.Count; i++) { KeyValuePair<GameObject, int> keyValuePair = __result[i]; if (!((Object)(object)keyValuePair.Key == (Object)null) && ButcherItem(((Object)keyValuePair.Key).name)) { float num = (float)keyValuePair.Value * ButcherBonus.Value; int num2 = Mathf.FloorToInt(num) + ((Random.value < num - Mathf.Floor(num)) ? 1 : 0); if (num2 > 0) { __result[i] = new KeyValuePair<GameObject, int>(keyValuePair.Key, keyValuePair.Value + num2); } } } } catch { } } } public const string Guid = "digi.vargheim.ranching"; public const string Version = "1.1.2"; private const string Prof = "Ranching"; internal static ConfigEntry<float> PartnerRange; internal static ConfigEntry<float> NearRange; internal static ConfigEntry<float> GentleCut; internal static ConfigEntry<float> BreedFaster; internal static ConfigEntry<float> BreedRange; internal static ConfigEntry<float> RiderBonus; internal static ConfigEntry<float> ButcherBonus; internal static ConfigEntry<float> BloodChance; internal static ConfigEntry<float> WinterMult; internal static ConfigEntry<int> StockLevel; internal static ConfigEntry<int> GentleLevel; internal static ConfigEntry<int> BreedLevel; internal static ConfigEntry<int> RiderLevel; internal static ConfigEntry<int> ButcherLevel; internal static ConfigEntry<int> BloodLevel; internal static ConfigEntry<int> WinterLevel; internal static ConfigEntry<string> RancherItems; internal static ConfigEntry<string> ButcherItems; internal static ConfigEntry<string> HideRecipe; internal const string Hide = "VP_TannedHide"; internal static ConfigEntry<int> HideLevel; internal static ConfigEntry<int> HideAmount; internal static HashSet<string> ButcherSet = new HashSet<string>(StringComparer.Ordinal); [ThreadStatic] internal static Procreation s_cur; private static readonly Dictionary<Sadle, Orig> s_boosted = new Dictionary<Sadle, Orig>(); private float _next; [ThreadStatic] private static bool s_birth; private static readonly FieldRef<Character, HitData> s_lastHit = AccessTools.FieldRefAccess<Character, HitData>("m_lastHit"); private void Awake() { //IL_03bf: Unknown result type (might be due to invalid IL or missing references) //IL_03c5: Expected O, but got Unknown //IL_03d3: Unknown result type (might be due to invalid IL or missing references) //IL_03d9: Expected O, but got Unknown //IL_0442: Unknown result type (might be due to invalid IL or missing references) //IL_0448: Expected O, but got Unknown //IL_04b1: Unknown result type (might be due to invalid IL or missing references) //IL_04b7: Expected O, but got Unknown //IL_0520: Unknown result type (might be due to invalid IL or missing references) //IL_0526: Expected O, but got Unknown //IL_0563: Unknown result type (might be due to invalid IL or missing references) //IL_0569: Expected O, but got Unknown //IL_05a6: Unknown result type (might be due to invalid IL or missing references) //IL_05ac: Expected O, but got Unknown //IL_05e4: Unknown result type (might be due to invalid IL or missing references) //IL_05ea: Expected O, but got Unknown //IL_05f4: Unknown result type (might be due to invalid IL or missing references) //IL_05fa: Expected O, but got Unknown PartnerRange = ((BaseUnityPlugin)this).Config.Bind<float>("Perks", "MinimumPartnerRange", 5f, "Every animal looks for a breeding partner at least this far away (metres). Applies to everyone."); NearRange = ((BaseUnityPlugin)this).Config.Bind<float>("Perks", "RancherNearRange", 30f, "How close a rancher must be for Stockman and Gentle hand."); StockLevel = ((BaseUnityPlugin)this).Config.Bind<int>("Perks", "StockmanLevel", 25, "Stockman: creatures added by mods can only be tamed with a rancher of this level nearby."); RancherItems = ((BaseUnityPlugin)this).Config.Bind<string>("Perks", "RancherCraftedItems", "rae_SaddleHorse,rae_saddlebags", "Items only ranchers (Stockman level) can craft."); HideLevel = ((BaseUnityPlugin)this).Config.Bind<int>("Perks", "TannedHideLevel", 35, "Tanned hide: level to make Tanned Hide, which smiths need for modded armor."); HideRecipe = ((BaseUnityPlugin)this).Config.Bind<string>("Perks", "TannedHideRecipe", "DeerHide:2,LeatherScraps:2,Resin:2", "Materials for Tanned Hide (at a workbench)."); HideAmount = ((BaseUnityPlugin)this).Config.Bind<int>("Perks", "TannedHideAmount", 2, "Tanned Hide per craft."); Content.AddItem("DeerHide", "VP_TannedHide", "Tanned Hide", "Hide scraped, cured and worked soft. Smiths need it for modded armor. Only a rancher can tan it.", (Action<SharedData>)delegate(SharedData s) { s.m_weight = 1f; s.m_maxStackSize = 50; }); Content.AddRecipe("VP_TannedHide", "piece_workbench", 1, Math.Max(1, HideAmount.Value), HideRecipe.Value, "Ranching", HideLevel.Value); GentleLevel = ((BaseUnityPlugin)this).Config.Bind<int>("Perks", "GentleHandLevel", 35, "Gentle hand level."); GentleCut = ((BaseUnityPlugin)this).Config.Bind<float>("Perks", "GentleHandDamageReduction", 0.15f, "Gentle hand: tamed animals near a rancher take this much less damage."); BreedLevel = ((BaseUnityPlugin)this).Config.Bind<int>("Perks", "HerdBreederLevel", 45, "Herd breeder level."); BreedRange = ((BaseUnityPlugin)this).Config.Bind<float>("Perks", "HerdBreederRange", 10f, "Herd breeder range."); BreedFaster = ((BaseUnityPlugin)this).Config.Bind<float>("Perks", "HerdBreederSpeedup", 0.25f, "Herd breeder: breeding and growing up this much faster."); WinterLevel = ((BaseUnityPlugin)this).Config.Bind<int>("Perks", "WinterHerdLevel", 25, "Winter herd: when Seasons sets the winter breeding rate to 0, animals within Herd breeder range of a rancher of this level still breed."); WinterMult = ((BaseUnityPlugin)this).Config.Bind<float>("Perks", "WinterHerdMultiplier", 0.5f, "Winter herd: breeding rate used in winter near a rancher (1 = normal, 0.5 = half as often). Only applies when Seasons has winter breeding at 0."); RiderLevel = ((BaseUnityPlugin)this).Config.Bind<int>("Perks", "TrailRiderLevel", 60, "Trail rider level."); RiderBonus = ((BaseUnityPlugin)this).Config.Bind<float>("Perks", "TrailRiderBonus", 0.15f, "Trail rider: mount speed and stamina bonus while the rancher rides."); ButcherLevel = ((BaseUnityPlugin)this).Config.Bind<int>("Perks", "ButcherLevel", 75, "Butcher level."); ButcherBonus = ((BaseUnityPlugin)this).Config.Bind<float>("Perks", "ButcherBonus", 0.25f, "Butcher: extra meat, leather and hides from tamed animals the rancher slaughters."); ButcherItems = ((BaseUnityPlugin)this).Config.Bind<string>("Perks", "ButcherExtraItems", "LeatherScraps,DeerHide,TrollHide,WolfPelt,LoxPelt,ScaleHide,AskHide,BjornHide,Feathers,NeckTail,Entrails", "Items Butcher adds to, besides anything with Meat, Hide or Pelt in its name."); BloodLevel = ((BaseUnityPlugin)this).Config.Bind<int>("Perks", "BloodlineLevel", 100, "Bloodline level."); BloodChance = ((BaseUnityPlugin)this).Config.Bind<float>("Perks", "BloodlineChance", 0.1f, "Bloodline: chance an animal born near the rancher gets one more star."); Load(); ((BaseUnityPlugin)this).Config.SettingChanged += delegate { Load(); }; Api.RegisterLadder("Ranching", "VargheimRanching 1.1.2", "Smoothbrain Ranching: faster taming and more drops from tamed animals. Every animal needs a partner within " + PartnerRange.Value + " m to breed.", (Perk[])(object)new Perk[8] { new Perk(StockLevel.Value, "Stockman", "Creatures added by mods (horses and others) can only be tamed with you nearby. You craft saddles and saddlebags. Riding stays open to everyone."), new Perk(10, "Tier hides", "Make the Rancher's tier material at a workbench, one per biome from that biome's hides (Tanned Hide at 10, Troll Leather at 25, Draugr Sinew at 35, Frost Pelt at 45 ...). Smiths need it for every modded armor piece and cape of that tier."), new Perk(GentleLevel.Value, "Gentle hand", "Tamed animals within " + NearRange.Value + " m of you take " + Mathf.RoundToInt(GentleCut.Value * 100f) + "% less damage."), new Perk(WinterLevel.Value, "Winter herd", "Animals do not breed in winter unless a rancher is within " + BreedRange.Value + " m; near you they breed at " + Mathf.RoundToInt(WinterMult.Value * 100f) + "% of the normal rate."), new Perk(BreedLevel.Value, "Herd breeder", "Animals within " + BreedRange.Value + " m of you breed " + Mathf.RoundToInt(BreedFaster.Value * 100f) + "% faster and their young grow up faster."), new Perk(RiderLevel.Value, "Trail rider", "+" + Mathf.RoundToInt(RiderBonus.Value * 100f) + "% speed and stamina for the mount you ride."), new Perk(ButcherLevel.Value, "Butcher", "Tamed animals you slaughter drop " + Mathf.RoundToInt(ButcherBonus.Value * 100f) + "% more meat, leather and hides."), new Perk(BloodLevel.Value, "Bloodline", Mathf.RoundToInt(BloodChance.Value * 100f) + "% chance an animal born near you comes out one star higher.") }); Harmony val = new Harmony("digi.vargheim.ranching"); val.PatchAll(typeof(Patches)); PatchSeasons(val); ((BaseUnityPlugin)this).Logger.LogInfo((object)"VargheimRanching 1.1.2 loaded."); } private static void Load() { ButcherSet = new HashSet<string>(ButcherItems.Value.Split(new char[1] { ',' }, StringSplitOptions.RemoveEmptyEntries), StringComparer.Ordinal); string[] array = RancherItems.Value.Split(new char[1] { ',' }, StringSplitOptions.RemoveEmptyEntries); for (int i = 0; i < array.Length; i++) { Content.SetGate(array[i].Trim(), "Ranching", StockLevel.Value); } } private void PatchSeasons(Harmony h) { //IL_0043: Unknown result type (might be due to invalid IL or missing references) //IL_0050: Expected O, but got Unknown try { Type type = AccessTools.TypeByName("Seasons.SeasonState"); MethodInfo methodInfo = ((type == null) ? null : AccessTools.Method(type, "GetLivestockProcreationMultiplier", (Type[])null, (Type[])null)); if (!(methodInfo == null)) { h.Patch((MethodBase)methodInfo, (HarmonyMethod)null, new HarmonyMethod(typeof(Plugin), "SeasonsMult", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); ((BaseUnityPlugin)this).Logger.LogInfo((object)"VargheimRanching: Seasons found, winter herd hook on."); } } catch (Exception ex) { ((BaseUnityPlugin)this).Logger.LogWarning((object)("VargheimRanching: Seasons hook failed: " + ex.Message)); } } private static void SeasonsMult(ref float __result) { //IL_0031: Unknown result type (might be due to invalid IL or missing references) try { if ((Object)(object)s_cur != (Object)null && __result <= 0.0001f && WinterMult.Value > 0f && BestRancherNear(((Component)s_cur).transform.position, BreedRange.Value) >= WinterLevel.Value) { __result = WinterMult.Value; } } catch { } } internal static int BestRancherNear(Vector3 pos, float range) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) List<Player> list = new List<Player>(); Player.GetPlayersInRange(pos, range, list); int num = 0; foreach (Player item in list) { num = Math.Max(num, Api.PerkLevelOf(item, "Ranching")); } return num; } private static string PrefabName(GameObject go) { string name = ((Object)go).name; int num = name.IndexOf("(Clone)", StringComparison.Ordinal); return ((num >= 0) ? name.Substring(0, num) : name).Trim(); } internal static bool ButcherItem(string name) { if (!ButcherSet.Contains(name) && name.IndexOf("Meat", StringComparison.OrdinalIgnoreCase) < 0 && name.IndexOf("Hide", StringComparison.OrdinalIgnoreCase) < 0) { return name.IndexOf("Pelt", StringComparison.OrdinalIgnoreCase) >= 0; } return true; } private void Update() { if (Time.time < _next) { return; } _next = Time.time + 0.5f; try { Player localPlayer = Player.m_localPlayer; Sadle val = (Sadle)(((Object)(object)localPlayer != (Object)null) ? /*isinst with value type is only supported in some contexts*/: null); if ((Object)(object)val != (Object)null && !Api.HasPerk("Ranching", RiderLevel.Value)) { val = null; } List<Sadle> list = new List<Sadle>(); foreach (KeyValuePair<Sadle, Orig> item in s_boosted) { if ((Object)(object)item.Key != (Object)(object)val) { list.Add(item.Key); } } foreach (Sadle item2 in list) { Restore(item2); } if ((Object)(object)val != (Object)null && !s_boosted.ContainsKey(val)) { Boost(val); } } catch (Exception ex) { ((BaseUnityPlugin)this).Logger.LogWarning((object)ex.Message); } } private static void Boost(Sadle s) { Character value = Traverse.Create((object)s).Field("m_character").GetValue<Character>(); if (!((Object)(object)value == (Object)null)) { Orig value2 = new Orig { Run = value.m_runSpeed, Speed = value.m_speed, Swim = value.m_swimSpeed, Stamina = s.m_maxStamina, Regen = s.m_staminaRegen }; float num = 1f + RiderBonus.Value; value.m_runSpeed *= num; value.m_speed *= num; value.m_swimSpeed *= num; s.m_maxStamina *= num; s.m_staminaRegen *= num; s_boosted[s] = value2; } } private static void Restore(Sadle s) { if ((Object)(object)s == (Object)null || !s_boosted.TryGetValue(s, out var value)) { s_boosted.Remove(s); return; } s_boosted.Remove(s); Character value2 = Traverse.Create((object)s).Field("m_character").GetValue<Character>(); if ((Object)(object)value2 != (Object)null) { value2.m_runSpeed = value.Run; value2.m_speed = value.Speed; value2.m_swimSpeed = value.Swim; } s.m_maxStamina = value.Stamina; s.m_staminaRegen = value.Regen; } } }