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 Kindred v0.1.0
KindredMod.dll
Decompiled 14 hours agousing System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Versioning; using BepInEx; using BepInEx.Logging; using HarmonyLib; using Jotunn.Configs; using Jotunn.Entities; using Jotunn.Managers; using UnityEngine; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)] [assembly: AssemblyTitle("ValheimMod1")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("ValheimMod1")] [assembly: AssemblyCopyright("Copyright © 2026")] [assembly: AssemblyTrademark("")] [assembly: ComVisible(false)] [assembly: Guid("6543427b-21b7-4f8f-9fae-f50a6de8735a")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")] [assembly: AssemblyVersion("1.0.0.0")] namespace ValheimMod1; [BepInPlugin("com.grandin.valheimmod1", "Custom Kindred Mod", "1.0.0")] [BepInDependency(/*Could not decode attribute arguments.*/)] public class Plugin : BaseUnityPlugin { [HarmonyPatch(typeof(ZNetScene), "Awake")] public static class KindredWorldInitPatch { [Serializable] [CompilerGenerated] private sealed class <>c { public static readonly <>c <>9 = new <>c(); public static ConsoleEvent <>9__0_0; public static ConsoleEvent <>9__0_1; internal void <Postfix>b__0_0(ConsoleEventArgs args) { Instance.SpawnKindred(args); } internal void <Postfix>b__0_1(ConsoleEventArgs args) { Instance.PrintKindredStatus(args); } } [HarmonyPriority(700)] private static void Postfix(ZNetScene __instance) { //IL_00a0: 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) //IL_0090: Unknown result type (might be due to invalid IL or missing references) //IL_0096: Expected O, but got Unknown //IL_00d9: Unknown result type (might be due to invalid IL or missing references) //IL_00c4: Unknown result type (might be due to invalid IL or missing references) //IL_00c9: Unknown result type (might be due to invalid IL or missing references) //IL_00cf: Expected O, but got Unknown if ((Object)(object)Instance == (Object)null || (Object)(object)Instance.s_kindredPrefab == (Object)null) { return; } Instance.EnsureArrowProjectile(); Instance.EnsureCombatEffects(); Instance.EnsureTameFoods(); Instance.EnsureDrops(); Instance.EnsureRagdollCycle(); Instance.EnsureProcreationEffects(); try { object obj = <>c.<>9__0_0; if (obj == null) { ConsoleEvent val = delegate(ConsoleEventArgs args) { Instance.SpawnKindred(args); }; <>c.<>9__0_0 = val; obj = (object)val; } new ConsoleCommand("spawnkindred", "Spawns a Kindred mob near the player.", (ConsoleEvent)obj, true, false, false, false, false, false, (ConsoleOptionsFetcher)null, false, false, false); object obj2 = <>c.<>9__0_1; if (obj2 == null) { ConsoleEvent val2 = delegate(ConsoleEventArgs args) { Instance.PrintKindredStatus(args); }; <>c.<>9__0_1 = val2; obj2 = (object)val2; } new ConsoleCommand("kindredstatus", "Prints Kindred AI diagnostics.", (ConsoleEvent)obj2, true, false, false, false, false, false, (ConsoleOptionsFetcher)null, false, false, false); Instance.Log.LogInfo((object)"[Kindred] Debug commands registered."); } catch (Exception ex) { Plugin instance = Instance; if (instance != null) { instance.Log.LogError((object)("[Kindred] Failed to register command: " + ex.Message)); } } } } private AssetBundle s_bundle; internal GameObject s_kindredPrefab; internal ItemDrop s_bowItem; internal float AltAttackChance = 0.25f; internal int BurstCount = 3; internal float BurstInterval = 0.4f; internal float AltAttackAnimSpeed = 0.4f; internal float ArrowVelocity = 60f; internal float ArrowAccuracy = 2f; internal float ViewRange = 20f; internal float HearRange = 10f; internal bool DropEnabled = true; internal float MeadChance = 1f; internal float MeadBonusChance = 0.2f; internal int MeadAmount = 1; internal float CorpseTTL = 3f; internal float TamingTime = 120f; internal string TameFoodNames = "Carrot,Mushroom"; internal float FedDuration = 60f; internal float ConsumeSearchRange = 8f; internal float ConsumeRange = 2.5f; internal List<ItemDrop> TameFoodDrops = new List<ItemDrop>(); internal bool EnableBreeding = true; internal float BreedSpeedMultiplier = 1f; internal float BreedUpdateIntervalBase = 10f; internal int BreedLovePointsBase = 4; internal float BreedPregnancyBase = 60f; internal int BreedMaxCreatures = 8; internal float BreedPartnerRange = 6f; internal float BreedTotalRange = 10f; internal string OffspringPrefabName = ""; internal bool EnableSpawn = true; internal Biome SpawnBiomes = (Biome)8; internal float SpawnInterval = 120f; internal int SpawnMaxPerZone = 2; internal float SpawnChance = 100f; internal int SpawnGroupMin = 1; internal int SpawnGroupMax = 1; internal float SpawnMinDistance = 10f; internal float SpawnRadiusMin = 0f; internal float SpawnRadiusMax = 0f; internal bool SpawnAtDay = true; internal bool SpawnAtNight = true; internal int s_spawnInjectedLists = 0; private const string SpawnEntryName = "KindredSpawn"; private bool s_tameFoodsApplied; private bool s_dropsApplied; private bool s_ragdollCycleApplied; private bool s_procreationEffectsApplied; public static Plugin Instance { get; private set; } public ManualLogSource Log => ((BaseUnityPlugin)this).Logger; private void Awake() { //IL_0689: Unknown result type (might be due to invalid IL or missing references) //IL_065c: Unknown result type (might be due to invalid IL or missing references) //IL_0661: Unknown result type (might be due to invalid IL or missing references) //IL_06cf: Unknown result type (might be due to invalid IL or missing references) //IL_06d5: Expected O, but got Unknown Instance = this; ((BaseUnityPlugin)this).Logger.LogInfo((object)"[Kindred] Starting Custom Kindred Mod..."); AltAttackChance = ((BaseUnityPlugin)this).Config.Bind<float>("Kindred.Combat", "altAttackChance", 0.25f, "Chance (0..1) of the alt burst attack (3 arrows, slow-mo).").Value; BurstCount = ((BaseUnityPlugin)this).Config.Bind<int>("Kindred.Combat", "burstArrowCount", 3, "Arrows in the alt burst attack.").Value; BurstInterval = ((BaseUnityPlugin)this).Config.Bind<float>("Kindred.Combat", "burstInterval", 0.4f, "Seconds between arrows in the burst.").Value; AltAttackAnimSpeed = ((BaseUnityPlugin)this).Config.Bind<float>("Kindred.Combat", "altAttackAnimSpeed", 0.4f, "Animation speed multiplier during alt attack.").Value; ArrowVelocity = ((BaseUnityPlugin)this).Config.Bind<float>("Kindred.Combat", "arrowVelocity", 60f, "Projectile velocity.").Value; ArrowAccuracy = ((BaseUnityPlugin)this).Config.Bind<float>("Kindred.Combat", "arrowAccuracyDeg", 2f, "Projectile spread in degrees.").Value; ViewRange = ((BaseUnityPlugin)this).Config.Bind<float>("Kindred.AI", "viewRange", 20f, "Sight range.").Value; HearRange = ((BaseUnityPlugin)this).Config.Bind<float>("Kindred.AI", "hearRange", 10f, "Hear range.").Value; DropEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("Kindred.Drop", "enabled", true, "Master switch for the CharacterDrop setup.").Value; MeadChance = ((BaseUnityPlugin)this).Config.Bind<float>("Kindred.Drop", "meadChance", 1f, "Chance of the base MeadHealthMinor portion.").Value; MeadBonusChance = ((BaseUnityPlugin)this).Config.Bind<float>("Kindred.Drop", "meadBonusChance", 0.2f, "Chance of one extra MeadHealthMinor portion.").Value; MeadAmount = ((BaseUnityPlugin)this).Config.Bind<int>("Kindred.Drop", "meadAmount", 1, "Portion size (stack).").Value; CorpseTTL = ((BaseUnityPlugin)this).Config.Bind<float>("Kindred.Drop", "corpseTTL", 3f, "Seconds the ragdoll lies before vanishing and dropping loot.").Value; TamingTime = ((BaseUnityPlugin)this).Config.Bind<float>("Kindred.Taming", "tamingTime", 120f, "Seconds to tame (while fed and calm).").Value; TameFoodNames = ((BaseUnityPlugin)this).Config.Bind<string>("Kindred.Taming", "tameFoods", "Carrot,Mushroom", "Comma-separated ObjectDB item names the Kindred eats (MonsterAI.m_consumeItems).").Value; FedDuration = ((BaseUnityPlugin)this).Config.Bind<float>("Kindred.Taming", "fedDuration", 60f, "Seconds the mob counts as 'fed' after eating once.").Value; ConsumeSearchRange = ((BaseUnityPlugin)this).Config.Bind<float>("Kindred.Taming", "consumeSearchRange", 8f, "Radius in which the mob looks for food on the ground.").Value; ConsumeRange = ((BaseUnityPlugin)this).Config.Bind<float>("Kindred.Taming", "consumeRange", 2.5f, "Distance at which the mob actually eats the food.").Value; EnableBreeding = ((BaseUnityPlugin)this).Config.Bind<bool>("Kindred.Breeding", "enableBreeding", true, "Enable the vanilla Procreation component on Kindred.").Value; BreedSpeedMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("Kindred.Breeding", "speedMultiplier", 1f, "Test acceleration: interval/love points/pregnancy are divided by this (1 = release pace).").Value; BreedUpdateIntervalBase = ((BaseUnityPlugin)this).Config.Bind<float>("Kindred.Breeding", "updateIntervalBase", 10f, "Base seconds between procreation checks.").Value; BreedLovePointsBase = ((BaseUnityPlugin)this).Config.Bind<int>("Kindred.Breeding", "lovePointsBase", 4, "Base love points required for pregnancy.").Value; BreedPregnancyBase = ((BaseUnityPlugin)this).Config.Bind<float>("Kindred.Breeding", "pregnancyDurationBase", 60f, "Base pregnancy duration in seconds.").Value; BreedMaxCreatures = ((BaseUnityPlugin)this).Config.Bind<int>("Kindred.Breeding", "maxCreatures", 8, "Population cap (real head count; code doubles the internal counter when offspring == self).").Value; BreedPartnerRange = ((BaseUnityPlugin)this).Config.Bind<float>("Kindred.Breeding", "partnerCheckRange", 6f, "Radius in which a ready partner must stand.").Value; BreedTotalRange = ((BaseUnityPlugin)this).Config.Bind<float>("Kindred.Breeding", "totalCheckRange", 10f, "Radius for the population cap count.").Value; OffspringPrefabName = ((BaseUnityPlugin)this).Config.Bind<string>("Kindred.Breeding", "offspringPrefab", "", "ZNetScene prefab name for babies (empty = same Kindred prefab).").Value; EnableSpawn = ((BaseUnityPlugin)this).Config.Bind<bool>("Kindred.Spawn", "enableSpawn", true, "Inject our own SpawnData entry into every zone's spawn lists.").Value; string value = ((BaseUnityPlugin)this).Config.Bind<string>("Kindred.Spawn", "biomes", "BlackForest", "Comma-separated Heightmap.Biome flags, e.g. BlackForest or BlackForest,Meadows.").Value; SpawnInterval = ((BaseUnityPlugin)this).Config.Bind<float>("Kindred.Spawn", "spawnIntervalSec", 120f, "Seconds between spawn attempts per zone.").Value; SpawnMaxPerZone = ((BaseUnityPlugin)this).Config.Bind<int>("Kindred.Spawn", "maxSpawnedPerZone", 2, "Concurrent Kindred cap per zone.").Value; SpawnChance = ((BaseUnityPlugin)this).Config.Bind<float>("Kindred.Spawn", "spawnChancePct", 100f, "Chance per interval, 0..100.").Value; SpawnGroupMin = ((BaseUnityPlugin)this).Config.Bind<int>("Kindred.Spawn", "groupSizeMin", 1, "Min group size per spawn.").Value; SpawnGroupMax = ((BaseUnityPlugin)this).Config.Bind<int>("Kindred.Spawn", "groupSizeMax", 1, "Max group size per spawn.").Value; SpawnMinDistance = ((BaseUnityPlugin)this).Config.Bind<float>("Kindred.Spawn", "minDistanceToAnother", 10f, "Min distance to another Kindred instance.").Value; SpawnRadiusMin = ((BaseUnityPlugin)this).Config.Bind<float>("Kindred.Spawn", "spawnRadiusMin", 0f, "0 = vanilla global 40m from player.").Value; SpawnRadiusMax = ((BaseUnityPlugin)this).Config.Bind<float>("Kindred.Spawn", "spawnRadiusMax", 0f, "0 = vanilla global 80m from player.").Value; SpawnAtDay = ((BaseUnityPlugin)this).Config.Bind<bool>("Kindred.Spawn", "spawnAtDay", true, "Allow daytime spawning.").Value; SpawnAtNight = ((BaseUnityPlugin)this).Config.Bind<bool>("Kindred.Spawn", "spawnAtNight", true, "Allow nighttime spawning.").Value; try { SpawnBiomes = (Biome)Enum.Parse(typeof(Biome), value); } catch { ((BaseUnityPlugin)this).Logger.LogWarning((object)("[Kindred] Cannot parse biomes '" + value + "' — fallback to BlackForest.")); SpawnBiomes = (Biome)8; } LoadAssetBundle(); if ((Object)(object)s_bundle == (Object)null) { ((BaseUnityPlugin)this).Logger.LogError((object)"[Kindred] Failed to load asset bundle!"); return; } PrepareBow(); PrepareAndRegisterKindred(); Harmony val = new Harmony("com.grandin.kindred.patch"); val.PatchAll(Assembly.GetExecutingAssembly()); ((BaseUnityPlugin)this).Logger.LogInfo((object)"[Kindred] Custom Kindred Mod loaded successfully."); } private void LoadAssetBundle() { try { string directoryName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); string text = Path.Combine(directoryName, "kindred"); if (!File.Exists(text)) { ((BaseUnityPlugin)this).Logger.LogError((object)("[Kindred] Bundle file not found at: " + text)); return; } s_bundle = AssetBundle.LoadFromFile(text); if ((Object)(object)s_bundle == (Object)null) { ((BaseUnityPlugin)this).Logger.LogError((object)"[Kindred] Failed to open AssetBundle!"); return; } string[] allAssetNames = s_bundle.GetAllAssetNames(); ((BaseUnityPlugin)this).Logger.LogInfo((object)$"[Kindred] Found {allAssetNames.Length} assets in bundle:"); string[] array = allAssetNames; foreach (string text2 in array) { ((BaseUnityPlugin)this).Logger.LogInfo((object)(" - " + text2)); } } catch (Exception arg) { ((BaseUnityPlugin)this).Logger.LogError((object)$"[Kindred] Critical error during bundle loading: {arg}"); } } private T FindBundleAsset<T>(string nameContains) where T : Object { if ((Object)(object)s_bundle == (Object)null) { return default(T); } string[] allAssetNames = s_bundle.GetAllAssetNames(); foreach (string text in allAssetNames) { if (text.IndexOf(nameContains, StringComparison.OrdinalIgnoreCase) >= 0) { return s_bundle.LoadAsset<T>(text); } } return default(T); } private GameObject FindBundlePrefab(string exactName) { if ((Object)(object)s_bundle == (Object)null) { return null; } string[] allAssetNames = s_bundle.GetAllAssetNames(); foreach (string text in allAssetNames) { if (text.EndsWith("/" + exactName + ".prefab", StringComparison.OrdinalIgnoreCase) || text.Equals(exactName + ".prefab", StringComparison.OrdinalIgnoreCase)) { return s_bundle.LoadAsset<GameObject>(text); } } return null; } private GameObject FindRagdollPrefab() { GameObject val = FindBundlePrefab("kindred_ragdoll"); if ((Object)(object)val == (Object)null) { val = FindBundleAsset<GameObject>("kindred_ragdoll"); } return val; } private void PrepareBow() { //IL_007d: Unknown result type (might be due to invalid IL or missing references) //IL_0087: Expected O, but got Unknown //IL_010d: Unknown result type (might be due to invalid IL or missing references) //IL_0114: Unknown result type (might be due to invalid IL or missing references) //IL_0145: Unknown result type (might be due to invalid IL or missing references) //IL_00ed: Unknown result type (might be due to invalid IL or missing references) //IL_00f3: Expected O, but got Unknown //IL_0170: Unknown result type (might be due to invalid IL or missing references) //IL_0158: Unknown result type (might be due to invalid IL or missing references) //IL_01cc: Unknown result type (might be due to invalid IL or missing references) //IL_01ba: Unknown result type (might be due to invalid IL or missing references) //IL_01bf: Unknown result type (might be due to invalid IL or missing references) //IL_01c2: Expected O, but got Unknown //IL_01c7: Expected O, but got Unknown GameObject val = FindBundlePrefab("bow"); if ((Object)(object)val == (Object)null) { val = FindBundleAsset<GameObject>("bow"); } if ((Object)(object)val == (Object)null) { ((BaseUnityPlugin)this).Logger.LogError((object)"[Kindred] Bow prefab not found in bundle!"); return; } ItemDrop val2 = val.GetComponent<ItemDrop>(); if ((Object)(object)val2 == (Object)null) { ((BaseUnityPlugin)this).Logger.LogWarning((object)"[Kindred] Bow prefab has no ItemDrop — adding via code. (Recommended: add 'Item Drop' component to bow.prefab in Unity.)"); val2 = val.AddComponent<ItemDrop>(); val2.m_itemData.m_shared = new SharedData(); } ItemDrop[] components = val.GetComponents<ItemDrop>(); foreach (ItemDrop val3 in components) { if ((Object)(object)val3 != (Object)(object)val2) { ((BaseUnityPlugin)this).Logger.LogWarning((object)"[Kindred] Removing duplicate ItemDrop on Bow prefab."); Object.DestroyImmediate((Object)(object)val3); } } SharedData val4 = val2.m_itemData.m_shared; if (val4 == null) { val4 = new SharedData(); val2.m_itemData.m_shared = val4; } val4.m_name = "Kindred Bow"; val4.m_itemType = (ItemType)4; val4.m_skillType = (SkillType)8; val4.m_ammoType = ""; val4.m_useDurability = false; val4.m_attackForce = 10f; val4.m_blockable = true; val4.m_dodgeable = true; _ = val4.m_damages; if (false) { val4.m_damages = default(DamageTypes); } val4.m_damages.m_pierce = 45f; val4.m_aiTargetType = (AiTarget)0; val4.m_aiWhenWalking = true; val4.m_aiAttackRange = 20f; val4.m_aiAttackRangeMin = 0f; val4.m_aiAttackInterval = 4f; val4.m_aiAttackMaxAngle = 30f; val4.m_aiPrioritized = true; Attack obj = val4.m_attack; if (obj == null) { SharedData obj2 = val4; Attack val5 = new Attack(); Attack val6 = val5; obj2.m_attack = val5; obj = val6; } Attack val7 = obj; val7.m_attackType = (AttackType)2; val7.m_attackAnimation = "attack"; val7.m_chargeAnimationBool = "draw"; val7.m_bowDraw = false; val7.m_randomVelocity = false; val7.m_skillAccuracy = false; val7.m_projectileVel = ArrowVelocity; val7.m_projectileVelMin = Mathf.Max(1f, ArrowVelocity - 5f); val7.m_projectileAccuracy = ArrowAccuracy; val7.m_projectileAccuracyMin = ArrowAccuracy * 2f; val7.m_attackRange = 0.4f; val7.m_attackHeight = 1.3f; val7.m_attackOffset = 0f; val7.m_attackStamina = 0f; val7.m_attackStartNoise = 10f; val7.m_attackHitNoise = 20f; s_bowItem = val2; } internal void EnsureArrowProjectile() { if ((Object)(object)s_bowItem == (Object)null) { return; } Attack attack = s_bowItem.m_itemData.m_shared.m_attack; if (attack == null || (Object)(object)attack.m_attackProjectile != (Object)null) { return; } GameObject val = null; try { if ((Object)(object)ObjectDB.instance != (Object)null) { GameObject itemPrefab = ObjectDB.instance.GetItemPrefab("Bow"); Attack val2 = ((!((Object)(object)itemPrefab != (Object)null)) ? null : itemPrefab.GetComponent<ItemDrop>()?.m_itemData.m_shared.m_attack); if (val2 != null) { if ((Object)(object)val2.m_attackProjectile != (Object)null) { val = val2.m_attackProjectile; } if (attack.m_triggerEffect == null || attack.m_triggerEffect.m_effectPrefabs == null || attack.m_triggerEffect.m_effectPrefabs.Length == 0) { attack.m_triggerEffect = val2.m_triggerEffect; attack.m_startEffect = val2.m_startEffect; } } if ((Object)(object)val == (Object)null) { string[] array = new string[3] { "Arrows", "ArrowWood", "WoodArrow" }; foreach (string text in array) { GameObject itemPrefab2 = ObjectDB.instance.GetItemPrefab(text); ItemDrop val3 = (((Object)(object)itemPrefab2 != (Object)null) ? itemPrefab2.GetComponent<ItemDrop>() : null); SharedData val4 = (((Object)(object)val3 != (Object)null) ? val3.m_itemData.m_shared : null); if (val4 != null && val4.m_attack != null && (Object)(object)val4.m_attack.m_attackProjectile != (Object)null) { val = val4.m_attack.m_attackProjectile; break; } } } } if ((Object)(object)val == (Object)null && (Object)(object)ZNetScene.instance != (Object)null) { GameObject val5 = null; foreach (GameObject prefab in ZNetScene.instance.m_prefabs) { if ((Object)(object)prefab == (Object)null || prefab.GetComponent<IProjectile>() == null) { continue; } string text2 = ((Object)prefab).name.ToLower(); if (text2.StartsWith("arrow")) { if (text2 == "arrowwood" || text2 == "arrow" || text2 == "bow_projectile") { val = prefab; break; } if ((Object)(object)val5 == (Object)null) { val5 = prefab; } } } if ((Object)(object)val == (Object)null && (Object)(object)val5 != (Object)null) { val = val5; } } } catch (Exception ex) { ((BaseUnityPlugin)this).Logger.LogWarning((object)("[Kindred] EnsureArrowProjectile: " + ex.Message)); } if ((Object)(object)val != (Object)null) { attack.m_attackProjectile = val; } else { ((BaseUnityPlugin)this).Logger.LogWarning((object)"[Kindred] Arrow projectile NOT resolved (will retry on world init)."); } } internal void EnsureCombatEffects() { if ((Object)(object)s_kindredPrefab == (Object)null || (Object)(object)ZNetScene.instance == (Object)null) { return; } Humanoid component = s_kindredPrefab.GetComponent<Humanoid>(); if ((Object)(object)component == (Object)null) { return; } bool flag = ((Character)component).m_critHitEffects == null || !((Character)component).m_critHitEffects.HasEffects(); bool flag2 = ((Character)component).m_hitEffects == null || !((Character)component).m_hitEffects.HasEffects(); bool flag3 = ((Character)component).m_backstabHitEffects == null || !((Character)component).m_backstabHitEffects.HasEffects(); if (!flag && !flag2 && !flag3) { return; } Character val = null; string[] array = new string[5] { "Skeleton", "Greydwarf", "Boar", "Deer", "Troll" }; foreach (string text in array) { GameObject prefab = ZNetScene.instance.GetPrefab(text); Character val2 = (((Object)(object)prefab != (Object)null) ? prefab.GetComponent<Character>() : null); if ((Object)(object)val2 != (Object)null && val2.m_critHitEffects != null && val2.m_critHitEffects.HasEffects()) { val = val2; break; } } if ((Object)(object)val == (Object)null) { foreach (GameObject prefab2 in ZNetScene.instance.m_prefabs) { Character val3 = (((Object)(object)prefab2 != (Object)null) ? prefab2.GetComponent<Character>() : null); if ((Object)(object)val3 != (Object)null && val3.m_critHitEffects != null && val3.m_critHitEffects.HasEffects()) { val = val3; break; } } } if ((Object)(object)val == (Object)null) { ((BaseUnityPlugin)this).Logger.LogWarning((object)"[Kindred] No donor with crit effects found in ZNetScene."); return; } if (flag) { ((Character)component).m_critHitEffects = val.m_critHitEffects; } if (flag2 && val.m_hitEffects != null && val.m_hitEffects.HasEffects()) { ((Character)component).m_hitEffects = val.m_hitEffects; } if (flag3 && val.m_backstabHitEffects != null && val.m_backstabHitEffects.HasEffects()) { ((Character)component).m_backstabHitEffects = val.m_backstabHitEffects; } } internal void EnsureTameFoods() { if (s_tameFoodsApplied || (Object)(object)s_kindredPrefab == (Object)null || (Object)(object)ObjectDB.instance == (Object)null) { return; } MonsterAI component = s_kindredPrefab.GetComponent<MonsterAI>(); if ((Object)(object)component == (Object)null) { return; } List<ItemDrop> list = new List<ItemDrop>(); string[] array = TameFoodNames.Split(new char[1] { ',' }); foreach (string text in array) { string text2 = text.Trim(); if (text2.Length == 0) { continue; } GameObject itemPrefab = ObjectDB.instance.GetItemPrefab(text2); if ((Object)(object)itemPrefab == (Object)null) { ((BaseUnityPlugin)this).Logger.LogWarning((object)("[Kindred] Tame food '" + text2 + "' not found in ObjectDB.")); continue; } ItemDrop component2 = itemPrefab.GetComponent<ItemDrop>(); if ((Object)(object)component2 != (Object)null) { list.Add(component2); } } if (list.Count != 0) { TameFoodDrops = list; component.m_consumeItems = list; component.m_consumeSearchInterval = 3f; component.m_consumeSearchRange = ConsumeSearchRange; component.m_consumeRange = ConsumeRange; s_tameFoodsApplied = true; } } internal void EnsureDrops() { //IL_00ab: Unknown result type (might be due to invalid IL or missing references) //IL_00b0: 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_00c3: Unknown result type (might be due to invalid IL or missing references) //IL_00cf: 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_00e2: Unknown result type (might be due to invalid IL or missing references) //IL_00ee: Expected O, but got Unknown //IL_0109: Unknown result type (might be due to invalid IL or missing references) //IL_010e: Unknown result type (might be due to invalid IL or missing references) //IL_0115: Unknown result type (might be due to invalid IL or missing references) //IL_0121: Unknown result type (might be due to invalid IL or missing references) //IL_012d: Unknown result type (might be due to invalid IL or missing references) //IL_0139: Unknown result type (might be due to invalid IL or missing references) //IL_0140: Unknown result type (might be due to invalid IL or missing references) //IL_014c: Expected O, but got Unknown if (s_dropsApplied || (Object)(object)s_kindredPrefab == (Object)null || (Object)(object)ObjectDB.instance == (Object)null || !DropEnabled) { return; } GameObject itemPrefab = ObjectDB.instance.GetItemPrefab("MeadHealthMinor"); if ((Object)(object)itemPrefab == (Object)null) { ((BaseUnityPlugin)this).Logger.LogWarning((object)"[Kindred] MeadHealthMinor not found in ObjectDB — drops skipped."); return; } CharacterDrop val = s_kindredPrefab.GetComponent<CharacterDrop>(); if ((Object)(object)val == (Object)null) { val = s_kindredPrefab.AddComponent<CharacterDrop>(); } val.m_drops.Clear(); val.m_drops.Add(new Drop { m_prefab = itemPrefab, m_amountMin = MeadAmount, m_amountMax = MeadAmount, m_chance = MeadChance, m_levelMultiplier = false, m_dontScale = true }); if (MeadBonusChance > 0f) { val.m_drops.Add(new Drop { m_prefab = itemPrefab, m_amountMin = MeadAmount, m_amountMax = MeadAmount, m_chance = MeadBonusChance, m_levelMultiplier = false, m_dontScale = true }); } s_dropsApplied = true; } internal void EnsureRagdollCycle() { if (s_ragdollCycleApplied) { return; } GameObject val = FindRagdollPrefab(); if ((Object)(object)val == (Object)null) { return; } Ragdoll component = val.GetComponent<Ragdoll>(); if ((Object)(object)component == (Object)null) { return; } component.m_ttl = CorpseTTL; component.m_dropItems = true; if ((component.m_removeEffect == null || !component.m_removeEffect.HasEffects()) && (Object)(object)ZNetScene.instance != (Object)null) { foreach (GameObject prefab in ZNetScene.instance.m_prefabs) { if (!((Object)(object)prefab == (Object)null) && !((Object)(object)prefab == (Object)(object)val)) { Ragdoll component2 = prefab.GetComponent<Ragdoll>(); if ((Object)(object)component2 != (Object)null && component2.m_removeEffect != null && component2.m_removeEffect.HasEffects()) { component.m_removeEffect = component2.m_removeEffect; break; } } } } s_ragdollCycleApplied = true; } internal void EnsureProcreationEffects() { if (s_procreationEffectsApplied || (Object)(object)s_kindredPrefab == (Object)null || (Object)(object)ZNetScene.instance == (Object)null) { return; } Procreation component = s_kindredPrefab.GetComponent<Procreation>(); if ((Object)(object)component == (Object)null) { return; } if (!string.IsNullOrWhiteSpace(OffspringPrefabName)) { GameObject prefab = ZNetScene.instance.GetPrefab(OffspringPrefabName); if ((Object)(object)prefab != (Object)null) { component.m_offspring = prefab; } else { ((BaseUnityPlugin)this).Logger.LogWarning((object)("[Kindred] Offspring prefab '" + OffspringPrefabName + "' not found in ZNetScene — keeping self.")); } } bool flag = component.m_birthEffects == null || !component.m_birthEffects.HasEffects(); bool flag2 = component.m_loveEffects == null || !component.m_loveEffects.HasEffects(); if (!flag && !flag2) { s_procreationEffectsApplied = true; return; } foreach (GameObject prefab2 in ZNetScene.instance.m_prefabs) { if ((Object)(object)prefab2 == (Object)null || (Object)(object)prefab2 == (Object)(object)s_kindredPrefab) { continue; } Procreation component2 = prefab2.GetComponent<Procreation>(); if (!((Object)(object)component2 == (Object)null)) { if (flag && component2.m_birthEffects != null && component2.m_birthEffects.HasEffects()) { component.m_birthEffects = component2.m_birthEffects; flag = false; } if (flag2 && component2.m_loveEffects != null && component2.m_loveEffects.HasEffects()) { component.m_loveEffects = component2.m_loveEffects; flag2 = false; } if (!flag && !flag2) { break; } } } s_procreationEffectsApplied = true; } internal void InjectOwnSpawnEntry(SpawnSystem ss) { //IL_010c: Unknown result type (might be due to invalid IL or missing references) //IL_0111: Unknown result type (might be due to invalid IL or missing references) //IL_011c: Unknown result type (might be due to invalid IL or missing references) //IL_0123: Unknown result type (might be due to invalid IL or missing references) //IL_012f: Unknown result type (might be due to invalid IL or missing references) //IL_0131: Unknown result type (might be due to invalid IL or missing references) //IL_0136: Unknown result type (might be due to invalid IL or missing references) //IL_013b: Unknown result type (might be due to invalid IL or missing references) //IL_013d: Unknown result type (might be due to invalid IL or missing references) //IL_0142: Unknown result type (might be due to invalid IL or missing references) //IL_014e: Unknown result type (might be due to invalid IL or missing references) //IL_0164: Unknown result type (might be due to invalid IL or missing references) //IL_017f: Unknown result type (might be due to invalid IL or missing references) //IL_018b: Unknown result type (might be due to invalid IL or missing references) //IL_0197: Unknown result type (might be due to invalid IL or missing references) //IL_01a3: Unknown result type (might be due to invalid IL or missing references) //IL_01b5: Unknown result type (might be due to invalid IL or missing references) //IL_01cc: Unknown result type (might be due to invalid IL or missing references) //IL_01d7: Unknown result type (might be due to invalid IL or missing references) //IL_01e3: Unknown result type (might be due to invalid IL or missing references) //IL_01ef: Unknown result type (might be due to invalid IL or missing references) //IL_01fa: Unknown result type (might be due to invalid IL or missing references) //IL_0205: Unknown result type (might be due to invalid IL or missing references) //IL_0210: Unknown result type (might be due to invalid IL or missing references) //IL_021b: Unknown result type (might be due to invalid IL or missing references) //IL_0222: Unknown result type (might be due to invalid IL or missing references) //IL_0229: Unknown result type (might be due to invalid IL or missing references) //IL_0230: Unknown result type (might be due to invalid IL or missing references) //IL_0237: Unknown result type (might be due to invalid IL or missing references) //IL_023e: Unknown result type (might be due to invalid IL or missing references) //IL_0245: Unknown result type (might be due to invalid IL or missing references) //IL_0250: Unknown result type (might be due to invalid IL or missing references) //IL_0257: Unknown result type (might be due to invalid IL or missing references) //IL_025f: Expected O, but got Unknown //IL_02af: Unknown result type (might be due to invalid IL or missing references) if (!EnableSpawn || (Object)(object)s_kindredPrefab == (Object)null || (Object)(object)ss == (Object)null) { return; } if (ss.m_spawnLists == null) { ss.m_spawnLists = new List<SpawnSystemList>(); } foreach (SpawnSystemList spawnList in ss.m_spawnLists) { if ((Object)(object)spawnList == (Object)null || spawnList.m_spawners == null) { continue; } foreach (SpawnData spawner in spawnList.m_spawners) { if (spawner != null && (spawner.m_name == "KindredSpawn" || (Object)(object)spawner.m_prefab == (Object)(object)s_kindredPrefab)) { return; } } } SpawnData val = new SpawnData { m_name = "KindredSpawn", m_enabled = true, m_prefab = s_kindredPrefab, m_biome = SpawnBiomes, m_biomeArea = (BiomeArea)3, m_maxSpawned = SpawnMaxPerZone, m_spawnInterval = Mathf.Max(0.25f, SpawnInterval), m_spawnChance = Mathf.Clamp(SpawnChance, 0f, 100f), m_spawnDistance = SpawnMinDistance, m_spawnRadiusMin = SpawnRadiusMin, m_spawnRadiusMax = SpawnRadiusMax, m_groupSizeMin = Mathf.Max(1, SpawnGroupMin), m_groupSizeMax = Mathf.Max(SpawnGroupMin, SpawnGroupMax), m_groupRadius = 3f, m_spawnAtDay = SpawnAtDay, m_spawnAtNight = SpawnAtNight, m_minAltitude = -1000f, m_maxAltitude = 1000f, m_minTilt = 0f, m_maxTilt = 35f, m_inForest = true, m_outsideForest = true, m_inLava = false, m_outsideLava = true, m_canSpawnCloseToPlayer = false, m_insidePlayerBase = false, m_groundOffset = 0.5f, m_minLevel = 1, m_maxLevel = 1 }; SpawnSystemList val2 = ((Component)ss).gameObject.AddComponent<SpawnSystemList>(); val2.m_spawners.Add(val); ss.m_spawnLists.Add(val2); s_spawnInjectedLists++; if (s_spawnInjectedLists == 1) { ((BaseUnityPlugin)this).Logger.LogInfo((object)$"[Kindred] World spawn enabled: biomes={SpawnBiomes}, interval={val.m_spawnInterval:F0}s, cap={val.m_maxSpawned}/zone."); } } private void PrepareAndRegisterKindred() { //IL_00fd: Unknown result type (might be due to invalid IL or missing references) //IL_016a: Unknown result type (might be due to invalid IL or missing references) //IL_0171: Expected O, but got Unknown //IL_019b: Unknown result type (might be due to invalid IL or missing references) //IL_03b6: Unknown result type (might be due to invalid IL or missing references) //IL_03bd: Expected O, but got Unknown //IL_03e9: Unknown result type (might be due to invalid IL or missing references) //IL_03f0: Expected O, but got Unknown GameObject val = FindBundleAsset<GameObject>("/kindred.prefab"); if ((Object)(object)val == (Object)null) { val = FindBundleAsset<GameObject>(".prefab"); } if ((Object)(object)val == (Object)null) { ((BaseUnityPlugin)this).Logger.LogError((object)"[Kindred] No .prefab found in bundle!"); return; } Humanoid component = val.GetComponent<Humanoid>(); MonsterAI component2 = val.GetComponent<MonsterAI>(); ItemDrop[] components = val.GetComponents<ItemDrop>(); foreach (ItemDrop val2 in components) { ((BaseUnityPlugin)this).Logger.LogWarning((object)"[Kindred] Removing stray ItemDrop on Kindred root."); Object.DestroyImmediate((Object)(object)val2); } Animator componentInChildren = val.GetComponentInChildren<Animator>(); if ((Object)(object)componentInChildren == (Object)null) { ((BaseUnityPlugin)this).Logger.LogError((object)"[Kindred] No Animator found on Kindred prefab!"); } else if ((Object)(object)((Component)componentInChildren).GetComponent<CharacterAnimEvent>() == (Object)null) { ((Component)componentInChildren).gameObject.AddComponent<CharacterAnimEvent>(); } if ((Object)(object)component != (Object)null) { ((Character)component).m_name = "Kindred"; ((Character)component).m_faction = (Faction)2; ((Character)component).m_health = 80f; if (((Character)component).m_staggerDamageFactor <= 0f) { ((Character)component).m_staggerDamageFactor = 0.3f; } if ((Object)(object)((Character)component).m_eye == (Object)null) { Transform val3 = val.transform.Find("EyePos"); if ((Object)(object)val3 == (Object)null) { GameObject val4 = new GameObject("EyePos"); val4.transform.SetParent(val.transform, false); val4.transform.localPosition = new Vector3(0f, 1.5f, 0.3f); val3 = val4.transform; ((BaseUnityPlugin)this).Logger.LogWarning((object)"[Kindred] m_eye was null — created EyePos child at (0, 1.5, 0.3)."); } ((Character)component).m_eye = val3; } if ((Object)(object)s_bowItem != (Object)null) { component.m_defaultItems = (GameObject[])(object)new GameObject[1] { ((Component)s_bowItem).gameObject }; } AssignRagdollToDeathEffects(component); } Tameable val5 = val.GetComponent<Tameable>(); if ((Object)(object)val5 == (Object)null) { val5 = val.AddComponent<Tameable>(); } val5.m_tamingTime = TamingTime; val5.m_fedDuration = FedDuration; if ((Object)(object)component2 != (Object)null) { ((BaseAI)component2).m_viewRange = ViewRange; ((BaseAI)component2).m_viewAngle = 160f; ((BaseAI)component2).m_hearRange = HearRange; component2.m_minAttackInterval = 1.5f; component2.m_fleeIfHurtWhenTargetCantBeReached = false; component2.m_fleeIfNotAlerted = false; component2.m_fleeIfLowHealth = 0f; component2.m_fleeTimeSinceHurt = 0f; } Procreation val6 = val.GetComponent<Procreation>(); if (!EnableBreeding) { if ((Object)(object)val6 != (Object)null) { Object.DestroyImmediate((Object)(object)val6); } } else { if ((Object)(object)val6 == (Object)null) { val6 = val.AddComponent<Procreation>(); } float num = Mathf.Max(1f, BreedSpeedMultiplier); val6.m_updateInterval = Mathf.Max(0.25f, BreedUpdateIntervalBase / num); val6.m_requiredLovePoints = Mathf.Max(1, Mathf.RoundToInt((float)BreedLovePointsBase / num)); val6.m_pregnancyDuration = Mathf.Max(1f, BreedPregnancyBase / num); val6.m_pregnancyChance = 0f; val6.m_partnerCheckRange = BreedPartnerRange; val6.m_totalCheckRange = BreedTotalRange; val6.m_offspring = val; val6.m_minOffspringLevel = 1; val6.m_spawnOffset = 1.5f; val6.m_spawnOffsetMax = 2.5f; val6.m_spawnRandomDirection = true; val6.m_maxCreatures = BreedMaxCreatures * 2; } s_kindredPrefab = val; CreatureConfig val7 = new CreatureConfig(); val7.Name = "$kindred"; val7.Group = "forest_monsters"; val7.Faction = (Faction)2; CustomCreature val8 = new CustomCreature(val, true, val7); if (CreatureManager.Instance.AddCreature(val8)) { ((BaseUnityPlugin)this).Logger.LogInfo((object)"[Kindred] Creature registered."); } else { ((BaseUnityPlugin)this).Logger.LogError((object)"[Kindred] Failed to register Kindred creature!"); } GameObject val9 = FindRagdollPrefab(); if (!((Object)(object)val9 != (Object)null)) { return; } try { PrefabManager.Instance.AddPrefab(val9); } catch (Exception ex) { ((BaseUnityPlugin)this).Logger.LogWarning((object)("[Kindred] Ragdoll ZNetScene registration skipped: " + ex.Message)); } } private void AssignRagdollToDeathEffects(Humanoid hum) { //IL_009d: Unknown result type (might be due to invalid IL or missing references) //IL_00a4: Expected O, but got Unknown //IL_00ae: Unknown result type (might be due to invalid IL or missing references) //IL_00b3: Unknown result type (might be due to invalid IL or missing references) //IL_00ba: Unknown result type (might be due to invalid IL or missing references) //IL_00c2: Expected O, but got Unknown GameObject val = FindRagdollPrefab(); if ((Object)(object)val == (Object)null) { ((BaseUnityPlugin)this).Logger.LogWarning((object)"[Kindred] Kindred_ragdoll.prefab not found in bundle — m_deathEffects left as in inspector."); return; } if ((Object)(object)val.GetComponent<ZNetView>() == (Object)null) { ((BaseUnityPlugin)this).Logger.LogWarning((object)"[Kindred] Ragdoll has no ZNetView!"); } if ((Object)(object)val.GetComponent<Ragdoll>() == (Object)null) { ((BaseUnityPlugin)this).Logger.LogWarning((object)"[Kindred] Ragdoll has no Ragdoll component!"); } if (((Character)hum).m_deathEffects == null || ((Character)hum).m_deathEffects.m_effectPrefabs == null || ((Character)hum).m_deathEffects.m_effectPrefabs.Length == 0) { EffectList val2 = new EffectList(); val2.m_effectPrefabs = (EffectData[])(object)new EffectData[1] { new EffectData { m_prefab = val, m_enabled = true } }; ((Character)hum).m_deathEffects = val2; } } internal void SpawnKindred(ConsoleEventArgs args) { //IL_006c: Unknown result type (might be due to invalid IL or missing references) //IL_007b: Unknown result type (might be due to invalid IL or missing references) //IL_0085: Unknown result type (might be due to invalid IL or missing references) //IL_008a: Unknown result type (might be due to invalid IL or missing references) //IL_008f: Unknown result type (might be due to invalid IL or missing references) //IL_00a6: Unknown result type (might be due to invalid IL or missing references) //IL_00a7: Unknown result type (might be due to invalid IL or missing references) //IL_00de: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)Player.m_localPlayer == (Object)null || (Object)(object)s_kindredPrefab == (Object)null) { args.Context.AddString("Error: Player or Prefab missing!"); return; } EnsureArrowProjectile(); EnsureCombatEffects(); EnsureTameFoods(); EnsureDrops(); EnsureRagdollCycle(); EnsureProcreationEffects(); Vector3 val = ((Component)Player.m_localPlayer).transform.position + ((Component)Player.m_localPlayer).transform.forward * 5f; val.y += 1f; GameObject val2 = Object.Instantiate<GameObject>(s_kindredPrefab, val, Quaternion.identity); args.Context.AddString("Kindred spawned! (" + ((Object)val2).name + ")"); ((BaseUnityPlugin)this).Logger.LogInfo((object)$"[Kindred] Spawned at {val}"); } internal void PrintKindredStatus(ConsoleEventArgs args) { //IL_0049: Unknown result type (might be due to invalid IL or missing references) //IL_0128: 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_03f1: Unknown result type (might be due to invalid IL or missing references) //IL_0412: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)Player.m_localPlayer == (Object)null) { args.Context.AddString("Error: no local player."); return; } args.Context.AddString($"Spawn: own entry in {s_spawnInjectedLists} zones (biomes {SpawnBiomes}, interval {SpawnInterval}s, cap {SpawnMaxPerZone}, chance {SpawnChance}%, enableSpawn={EnableSpawn})."); int num = 0; foreach (Character allCharacter in Character.GetAllCharacters()) { if ((Object)(object)allCharacter == (Object)null || allCharacter.IsPlayer() || allCharacter.m_name == null || allCharacter.m_name.ToLower().IndexOf("kindred") < 0) { continue; } num++; MonsterAI component = ((Component)allCharacter).GetComponent<MonsterAI>(); Humanoid component2 = ((Component)allCharacter).GetComponent<Humanoid>(); Tameable component3 = ((Component)allCharacter).GetComponent<Tameable>(); Procreation component4 = ((Component)allCharacter).GetComponent<Procreation>(); float num2 = Vector3.Distance(((Component)allCharacter).transform.position, ((Component)Player.m_localPlayer).transform.position); string text = (((Object)(object)component != (Object)null && (Object)(object)((BaseAI)component).GetTargetCreature() != (Object)null) ? ((BaseAI)component).GetTargetCreature().m_name : "none"); bool flag = (Object)(object)component != (Object)null && ((BaseAI)component).IsAlerted(); bool flag2 = (Object)(object)component != (Object)null && ((BaseAI)component).HaveTarget(); bool flag3 = (Object)(object)component != (Object)null && ((BaseAI)component).CanSenseTarget((Character)(object)Player.m_localPlayer); bool flag4 = (Object)(object)component3 != (Object)null && component3.IsHungry(); args.Context.AddString($"Kindred #{num}: dist={num2:F1} alerted={flag} haveTarget={flag2} target={text} staggering={allCharacter.IsStaggering()} tamed={allCharacter.IsTamed()} hungry={flag4}"); args.Context.AddString($" eye={(Object)(object)allCharacter.m_eye != (Object)null} senseNow={flag3} viewRange={(((Object)(object)component != (Object)null) ? ((BaseAI)component).m_viewRange : (-1f))} tameable={(Object)(object)component3 != (Object)null}"); if ((Object)(object)component != (Object)null) { string text2 = ""; if (component.m_consumeItems != null) { foreach (ItemDrop consumeItem in component.m_consumeItems) { text2 = text2 + (((Object)(object)consumeItem != (Object)null) ? ((Object)consumeItem).name : "null") + ","; } } args.Context.AddString($" consume: list={((component.m_consumeItems != null) ? component.m_consumeItems.Count : 0)} [{text2}] searchRange={component.m_consumeSearchRange} eatRange={component.m_consumeRange}"); } if ((Object)(object)component4 != (Object)null && (Object)(object)s_kindredPrefab != (Object)null) { ZNetView component5 = ((Component)allCharacter).GetComponent<ZNetView>(); bool flag5 = (Object)(object)component5 != (Object)null && component5.IsValid() && component5.GetZDO().GetLong(ZDOVars.s_pregnant, 0L) != 0; int nrOfInstances = SpawnSystem.GetNrOfInstances(s_kindredPrefab, ((Component)allCharacter).transform.position, component4.m_totalCheckRange, false, false); int nrOfInstances2 = SpawnSystem.GetNrOfInstances(s_kindredPrefab, ((Component)allCharacter).transform.position, component4.m_partnerCheckRange, false, true); args.Context.AddString($" breeding: love={component4.GetLovePoints()}/{component4.m_requiredLovePoints} pregnant={flag5} ready={component4.ReadyForProcreation()} pop={nrOfInstances}/{component4.m_maxCreatures}(internal, head cap ~{component4.m_maxCreatures / 2}) partners={nrOfInstances2}(need >=2)"); } if (!((Object)(object)component2 != (Object)null)) { continue; } string text3 = ""; foreach (ItemData allItem in component2.GetInventory().GetAllItems()) { text3 = text3 + allItem.m_shared.m_name + (allItem.m_equipped ? "(E)" : "") + "; "; } args.Context.AddString(" inventory: " + ((text3.Length == 0) ? "EMPTY (no bow!)" : text3)); } if (num == 0) { args.Context.AddString("No Kindred found among loaded characters."); } } } [HarmonyPatch(typeof(SpawnSystem), "Awake")] public static class KindredSpawnInjectPatch { private static void Postfix(SpawnSystem __instance) { if ((Object)(object)Plugin.Instance != (Object)null) { Plugin.Instance.InjectOwnSpawnEntry(__instance); } } } [HarmonyPatch(typeof(MonsterAI), "Awake")] public static class KindredConsumeInstancePatch { private static void Postfix(MonsterAI __instance) { if ((Object)(object)Plugin.Instance == (Object)null || Plugin.Instance.TameFoodDrops.Count == 0) { return; } Character component = ((Component)__instance).GetComponent<Character>(); if (!((Object)(object)component == (Object)null) && component.m_name != null && component.m_name.ToLower().IndexOf("kindred") >= 0) { if (__instance.m_consumeItems == null || __instance.m_consumeItems.Count == 0) { __instance.m_consumeItems = new List<ItemDrop>(Plugin.Instance.TameFoodDrops); } __instance.m_consumeSearchInterval = 3f; __instance.m_consumeSearchRange = Plugin.Instance.ConsumeSearchRange; __instance.m_consumeRange = Plugin.Instance.ConsumeRange; } } } [HarmonyPatch(typeof(Attack), "Start", new Type[] { typeof(Humanoid), typeof(Rigidbody), typeof(ZSyncAnimation), typeof(CharacterAnimEvent), typeof(VisEquipment), typeof(ItemData), typeof(Attack), typeof(float), typeof(float) })] public static class KindredAltAttackPatch { internal static readonly Dictionary<Attack, ZSyncAnimation> s_altAttacks = new Dictionary<Attack, ZSyncAnimation>(); private static void Postfix(Attack __instance, bool __result, Humanoid character, ZSyncAnimation zanim) { if (__result && __instance != null && !((Object)(object)character == (Object)null) && !((Character)character).IsPlayer() && ((Character)character).m_name != null && ((Character)character).m_name.ToLower().IndexOf("kindred") >= 0 && !((Object)(object)Plugin.Instance == (Object)null) && !(Random.value >= Plugin.Instance.AltAttackChance)) { __instance.m_projectileBursts = Plugin.Instance.BurstCount; __instance.m_burstInterval = Plugin.Instance.BurstInterval; if ((Object)(object)zanim != (Object)null && Plugin.Instance.AltAttackAnimSpeed > 0f && Plugin.Instance.AltAttackAnimSpeed < 1f) { zanim.SetSpeed(Plugin.Instance.AltAttackAnimSpeed); s_altAttacks[__instance] = zanim; } } } } [HarmonyPatch(typeof(Attack), "Stop")] public static class KindredAltAttackStopPatch { private static void Postfix(Attack __instance) { if (__instance == null) { return; } if (KindredAltAttackPatch.s_altAttacks.TryGetValue(__instance, out var value)) { KindredAltAttackPatch.s_altAttacks.Remove(__instance); if ((Object)(object)value != (Object)null) { value.SetSpeed(1f); } } __instance.m_projectileBursts = 1; __instance.m_burstInterval = 0f; } } [HarmonyPatch(typeof(Character), "IsStaggering")] public static class KindredStaggerByStateNamePatch { private static readonly Dictionary<int, Animator> s_animCache = new Dictionary<int, Animator>(); private static void Postfix(Character __instance, ref bool __result) { //IL_00ae: Unknown result type (might be due to invalid IL or missing references) //IL_00b3: Unknown result type (might be due to invalid IL or missing references) //IL_007b: Unknown result type (might be due to invalid IL or missing references) //IL_0080: Unknown result type (might be due to invalid IL or missing references) if (__result || (Object)(object)__instance == (Object)null || __instance.IsPlayer()) { return; } int instanceID = ((Object)__instance).GetInstanceID(); if (!s_animCache.TryGetValue(instanceID, out var value)) { value = ((Component)__instance).GetComponentInChildren<Animator>(); s_animCache[instanceID] = value; } if ((Object)(object)value == (Object)null) { return; } if (value.IsInTransition(0)) { AnimatorStateInfo nextAnimatorStateInfo = value.GetNextAnimatorStateInfo(0); if (((AnimatorStateInfo)(ref nextAnimatorStateInfo)).IsName("Stagger") || ((AnimatorStateInfo)(ref nextAnimatorStateInfo)).IsName("stagger")) { __result = true; return; } } AnimatorStateInfo currentAnimatorStateInfo = value.GetCurrentAnimatorStateInfo(0); if (((AnimatorStateInfo)(ref currentAnimatorStateInfo)).IsName("Stagger") || ((AnimatorStateInfo)(ref currentAnimatorStateInfo)).IsName("stagger")) { __result = true; } } } [HarmonyPatch(typeof(Character), "RPC_Stagger", new Type[] { typeof(long), typeof(Vector3) })] public static class KindredStaggerSfxPatch { private static void Prefix(Character __instance) { //IL_008b: Unknown result type (might be due to invalid IL or missing references) //IL_0090: Unknown result type (might be due to invalid IL or missing references) //IL_00a2: Unknown result type (might be due to invalid IL or missing references) if (!((Object)(object)__instance == (Object)null) && !__instance.IsPlayer() && __instance.m_name != null && __instance.m_name.ToLower().IndexOf("kindred") >= 0 && !__instance.IsStaggering()) { Humanoid val = (Humanoid)(object)((__instance is Humanoid) ? __instance : null); if (!((Object)(object)val == (Object)null) && ((Character)val).m_hitEffects != null && ((Character)val).m_hitEffects.HasEffects()) { ((Character)val).m_hitEffects.Create(__instance.GetCenterPoint(), Quaternion.identity, ((Component)__instance).transform, 1f, -1, __instance.GetZDOID()); } } } } [HarmonyPatch(typeof(ObjectDB), "Awake")] public static class KindredObjectDBPatch { private static void Postfix(ObjectDB __instance) { if (!((Object)(object)Plugin.Instance == (Object)null) && !((Object)(object)Plugin.Instance.s_bowItem == (Object)null)) { GameObject gameObject = ((Component)Plugin.Instance.s_bowItem).gameObject; if (!__instance.m_items.Contains(gameObject)) { __instance.m_items.Add(gameObject); } } } } [HarmonyPatch(typeof(ZSyncAnimation), "SetFloat", new Type[] { typeof(int), typeof(float) })] public static class ForwardSpeedHoldPatch { private class State { public bool isPlayer; public float held; public float pending; public float pendingSince; public float lastSwitch; public float walkSpeed = 2f; public float runSpeed = 6f; } private static readonly int s_fwdHash = Animator.StringToHash("forward_speed"); private const float Sustain = 0.25f; private const float MinHold = 1f; private static readonly Dictionary<int, State> s_map = new Dictionary<int, State>(); public static void Prefix(ZSyncAnimation __instance, int hash, ref float value) { if (hash != s_fwdHash) { return; } int instanceID = ((Object)__instance).GetInstanceID(); if (!s_map.TryGetValue(instanceID, out var value2)) { value2 = new State(); Character componentInParent = ((Component)__instance).GetComponentInParent<Character>(); value2.isPlayer = (Object)(object)componentInParent == (Object)null || componentInParent.IsPlayer(); value2.held = value; value2.pending = value; value2.pendingSince = Time.time; value2.lastSwitch = Time.time - 1f; if ((Object)(object)componentInParent != (Object)null) { value2.walkSpeed = componentInParent.m_walkSpeed; value2.runSpeed = componentInParent.m_runSpeed; } s_map[instanceID] = value2; } if (value2.isPlayer) { return; } float num = Quantize(value, value2); float time = Time.time; if (Mathf.Abs(num - value2.held) < 0.01f) { value2.pending = num; value2.pendingSince = time; value = value2.held; return; } if (Mathf.Abs(num - value2.pending) > 0.01f) { value2.pending = num; value2.pendingSince = time; } if (time - value2.pendingSince >= 0.25f && time - value2.lastSwitch >= 1f) { value2.held = num; value2.lastSwitch = time; value2.pending = num; value2.pendingSince = time; } value = value2.held; } private static float Quantize(float raw, State s) { if (raw < s.walkSpeed * 0.35f) { return 0f; } if (raw < (s.walkSpeed + s.runSpeed) * 0.5f) { return s.walkSpeed; } return s.runSpeed; } }