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 BearTamingMod v1.0.0
plugins/BearTamingMod.dll
Decompiled 5 months agousing System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Versioning; using BepInEx; using BepInEx.Configuration; using HarmonyLib; using UnityEngine; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)] [assembly: AssemblyTitle("BearTamingMod")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("BearTamingMod")] [assembly: AssemblyCopyright("Copyright © 2025")] [assembly: AssemblyTrademark("")] [assembly: ComVisible(false)] [assembly: Guid("54ea82ab-0379-48cd-b037-c202b4814509")] [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 BearTamingMod; [BepInPlugin("com.mintmango.beartaming", "Bear Taming Mod", "2.3.1")] public class BearTamingMod : BaseUnityPlugin { [Serializable] [CompilerGenerated] private sealed class <>c { public static readonly <>c <>9 = new <>c(); public static ConsoleEvent <>9__37_0; public static ConsoleEvent <>9__37_1; public static ConsoleEvent <>9__37_4; public static ConsoleEvent <>9__37_5; internal void <RegisterConsoleCommandsDirectly>b__37_0(ConsoleEventArgs args) { //IL_0033: Unknown result type (might be due to invalid IL or missing references) //IL_0042: Unknown result type (might be due to invalid IL or missing references) //IL_004c: Unknown result type (might be due to invalid IL or missing references) //IL_0051: Unknown result type (might be due to invalid IL or missing references) //IL_0056: Unknown result type (might be due to invalid IL or missing references) //IL_005b: Unknown result type (might be due to invalid IL or missing references) //IL_0060: Unknown result type (might be due to invalid IL or missing references) //IL_007e: Unknown result type (might be due to invalid IL or missing references) //IL_007f: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)Player.m_localPlayer == (Object)null) { args.Context.AddString("Ошибка: игрок не найден!"); return; } try { Vector3 val = ((Component)Player.m_localPlayer).transform.position + ((Component)Player.m_localPlayer).transform.forward * 3f + Vector3.up; GameObject prefab = ZNetScene.instance.GetPrefab("Bjorn"); if ((Object)(object)prefab != (Object)null) { GameObject bear = Object.Instantiate<GameObject>(prefab, val, Quaternion.identity); MakeBabyBear(bear); args.Context.AddString("Медвежонок создан!"); } else { args.Context.AddString("Ошибка: префаб медведя не найден!"); } } catch (Exception ex) { Debug.LogError((object)$"Ошибка создания медвежонка: {ex}"); args.Context.AddString("Ошибка: " + ex.Message); } } internal void <RegisterConsoleCommandsDirectly>b__37_1(ConsoleEventArgs args) { List<MonsterAI> list = FindAllBears(); int num = 0; int num2 = 0; int num3 = 0; int num4 = 0; int num5 = 0; int num6 = 0; foreach (MonsterAI item in list) { if ((Object)(object)item == (Object)null) { continue; } num++; bool flag = IsBearTamed(item); bool flag2 = IsBabyBear(((Component)item).gameObject); if (flag) { num2++; if (flag2) { num3++; num5++; } else if (BearBreedingSystem.CanBreed(item)) { num6++; } } else { num4++; } } args.Context.AddString($"Всего: {num}, Приручено: {num2}, Диких: {num4}"); args.Context.AddString($"Медвежат: {num3} (растут: {num5})"); args.Context.AddString($"Взрослых готовых к размножению: {num6}"); int num7 = 1; foreach (MonsterAI item2 in list) { if ((Object)(object)item2 != (Object)null && IsBabyBear(((Component)item2).gameObject)) { ZNetView component = ((Component)item2).GetComponent<ZNetView>(); if ((Object)(object)component != (Object)null && component.IsValid()) { float @float = component.GetZDO().GetFloat("ageInDays", 0f); float float2 = component.GetZDO().GetFloat("currentSize", 0.5f); float float3 = component.GetZDO().GetFloat("growthProgress", 0f); long @long = component.GetZDO().GetLong("bornTime", 0L); double num8 = (((Object)(object)ZNet.instance != (Object)null) ? ZNet.instance.GetTimeSeconds() : 0.0); double num9 = ((@long > 0) ? ((num8 - (double)@long) / 1800.0) : 0.0); double num10 = Math.Max(0.0, (double)GrowthDays.Value - num9); float num11 = float3 * 100f; args.Context.AddString($"Медвежонок {num7}: {num9:F2}/{GrowthDays.Value} дн. ({num11:F1}%) Размер: {float2:F2}"); num7++; } } } if (num3 == 0) { args.Context.AddString("Нет растущих медвежат"); } } internal void <RegisterConsoleCommandsDirectly>b__37_4(ConsoleEventArgs args) { BearBreedingSystem.UpdateBreeding(); args.Context.AddString("Система размножения обновлена!"); } internal void <RegisterConsoleCommandsDirectly>b__37_5(ConsoleEventArgs args) { args.Context.AddString($"Система инициализирована: {_isInitialized}"); args.Context.AddString($"ZNet доступен: {(Object)(object)ZNet.instance != (Object)null}"); args.Context.AddString($"Серверный режим: {(Object)(object)ZNet.instance != (Object)null && ZNet.instance.IsServer()}"); List<MonsterAI> list = FindAllBears(); args.Context.AddString($"Всего медведей в мире: {list.Count}"); int num = 0; foreach (MonsterAI item in list) { if ((Object)(object)item != (Object)null && IsBabyBear(((Component)item).gameObject)) { num++; ZNetView component = ((Component)item).GetComponent<ZNetView>(); if ((Object)(object)component != (Object)null && component.IsValid()) { double num2 = (((Object)(object)ZNet.instance != (Object)null) ? ZNet.instance.GetTimeSeconds() : 0.0); long @long = component.GetZDO().GetLong("bornTime", 0L); float num3 = ((@long > 0) ? ((float)((num2 - (double)@long) / 1800.0)) : 0f); float @float = component.GetZDO().GetFloat("currentSize", 0.5f); float float2 = component.GetZDO().GetFloat("growthProgress", 0f); args.Context.AddString($"Медвежонок: возраст {num3:F2} дн., размер {@float:F2}, прогресс {float2:P0}"); } } } args.Context.AddString($"Активных медвежат: {num}"); } } [CompilerGenerated] private sealed class <BreedingUpdateRoutine>d__26 : IEnumerator<object>, IDisposable, IEnumerator { private int <>1__state; private object <>2__current; public BearTamingMod <>4__this; object IEnumerator<object>.Current { [DebuggerHidden] get { return <>2__current; } } object IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } [DebuggerHidden] public <BreedingUpdateRoutine>d__26(int <>1__state) { this.<>1__state = <>1__state; } [DebuggerHidden] void IDisposable.Dispose() { <>1__state = -2; } private bool MoveNext() { //IL_0029: Unknown result type (might be due to invalid IL or missing references) //IL_0033: Expected O, but got Unknown switch (<>1__state) { default: return false; case 0: <>1__state = -1; break; case 1: <>1__state = -1; if (_isInitialized && (Object)(object)ZNet.instance != (Object)null && ZNet.instance.IsServer()) { BearBreedingSystem.UpdateBreeding(); } break; } <>2__current = (object)new WaitForSeconds(60f); <>1__state = 1; return true; } bool IEnumerator.MoveNext() { //ILSpy generated this explicit interface implementation from .override directive in MoveNext return this.MoveNext(); } [DebuggerHidden] void IEnumerator.Reset() { throw new NotSupportedException(); } } [CompilerGenerated] private sealed class <GrowthUpdateRoutine>d__25 : IEnumerator<object>, IDisposable, IEnumerator { private int <>1__state; private object <>2__current; public BearTamingMod <>4__this; object IEnumerator<object>.Current { [DebuggerHidden] get { return <>2__current; } } object IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } [DebuggerHidden] public <GrowthUpdateRoutine>d__25(int <>1__state) { this.<>1__state = <>1__state; } [DebuggerHidden] void IDisposable.Dispose() { <>1__state = -2; } private bool MoveNext() { //IL_0029: Unknown result type (might be due to invalid IL or missing references) //IL_0033: Expected O, but got Unknown switch (<>1__state) { default: return false; case 0: <>1__state = -1; break; case 1: <>1__state = -1; if (_isInitialized && (Object)(object)ZNet.instance != (Object)null && ZNet.instance.IsServer()) { <>4__this.UpdateAllBearGrowth(); } break; } <>2__current = (object)new WaitForSeconds(30f); <>1__state = 1; return true; } bool IEnumerator.MoveNext() { //ILSpy generated this explicit interface implementation from .override directive in MoveNext return this.MoveNext(); } [DebuggerHidden] void IEnumerator.Reset() { throw new NotSupportedException(); } } private readonly Harmony _harmony = new Harmony("com.mintmango.beartaming"); public static ConfigEntry<float> TameTime; public static ConfigEntry<float> FedDuration; public static ConfigEntry<string> ConsumableItems; public static ConfigEntry<float> GrowthDays; public static ConfigEntry<float> BreedChance; public static ConfigEntry<float> BreedCooldownDays; private static bool _isInitialized; private Coroutine _growthCoroutine; private Coroutine _breedingCoroutine; public const string ZDO_BABY = "isBaby"; public const string ZDO_BORN_TIME = "bornTime"; public const string ZDO_AGE_DAYS = "ageInDays"; public const string ZDO_CURRENT_SIZE = "currentSize"; public const string ZDO_GROWTH_COMPLETE = "growthComplete"; public const string ZDO_GROWTH_PROGRESS = "growthProgress"; public const string ZDO_NO_DROP = "noDrop"; public const string ZDO_LAST_BREED_TIME = "lastBreedTime"; public static BearTamingMod Instance { get; private set; } private void Awake() { Instance = this; TameTime = ((BaseUnityPlugin)this).Config.Bind<float>("General", "TameTime", 1200f, "Время приручения медведя в секундах"); FedDuration = ((BaseUnityPlugin)this).Config.Bind<float>("General", "FedDuration", 400f, "Время сытости медведя в секундах"); ConsumableItems = ((BaseUnityPlugin)this).Config.Bind<string>("General", "ConsumableItems", "Honey", "Предметы для приручения (через точку с запятой)"); GrowthDays = ((BaseUnityPlugin)this).Config.Bind<float>("Growth", "GrowthDays", 5f, "Количество игровых суток для роста медвежонка"); BreedChance = ((BaseUnityPlugin)this).Config.Bind<float>("Breeding", "BreedChance", 0.3f, "Шанс размножения при встрече (0-1)"); BreedCooldownDays = ((BaseUnityPlugin)this).Config.Bind<float>("Breeding", "BreedCooldownDays", 2f, "Количество дней между возможностями размножения"); RegisterConsoleCommandsDirectly(); try { _harmony.PatchAll(typeof(ZNetScenePatches)); _harmony.PatchAll(typeof(CharacterHoverPatches)); _harmony.PatchAll(typeof(TameablePatches)); _harmony.PatchAll(typeof(CharacterStatePatches)); _harmony.PatchAll(typeof(PlayerPatches)); _harmony.PatchAll(typeof(ZNetPatches)); _harmony.PatchAll(typeof(CharacterDeathPatches)); ((BaseUnityPlugin)this).Logger.LogInfo((object)"Bear Taming Mod v2.3.1 loaded successfully!"); } catch (Exception arg) { ((BaseUnityPlugin)this).Logger.LogError((object)$"Harmony patching completed with errors: {arg}"); } } private void Start() { _growthCoroutine = ((MonoBehaviour)this).StartCoroutine(GrowthUpdateRoutine()); _breedingCoroutine = ((MonoBehaviour)this).StartCoroutine(BreedingUpdateRoutine()); } private void OnDestroy() { Harmony harmony = _harmony; if (harmony != null) { harmony.UnpatchSelf(); } if (_growthCoroutine != null) { ((MonoBehaviour)this).StopCoroutine(_growthCoroutine); } if (_breedingCoroutine != null) { ((MonoBehaviour)this).StopCoroutine(_breedingCoroutine); } } [IteratorStateMachine(typeof(<GrowthUpdateRoutine>d__25))] private IEnumerator GrowthUpdateRoutine() { //yield-return decompiler failed: Unexpected instruction in Iterator.Dispose() return new <GrowthUpdateRoutine>d__25(0) { <>4__this = this }; } [IteratorStateMachine(typeof(<BreedingUpdateRoutine>d__26))] private IEnumerator BreedingUpdateRoutine() { //yield-return decompiler failed: Unexpected instruction in Iterator.Dispose() return new <BreedingUpdateRoutine>d__26(0) { <>4__this = this }; } public void UpdateAllBearGrowth() { if ((Object)(object)ZNet.instance == (Object)null || !ZNet.instance.IsServer()) { return; } try { double timeSeconds = ZNet.instance.GetTimeSeconds(); List<MonsterAI> list = FindAllBears(); int num = 0; foreach (MonsterAI item in list) { if ((Object)(object)item == (Object)null) { continue; } try { if (UpdateSingleBearGrowth(((Component)item).gameObject, timeSeconds)) { num++; } } catch (Exception ex) { Debug.LogError((object)("Ошибка роста медведя " + ((Object)((Component)item).gameObject).name + ": " + ex.Message)); } } if (num > 0) { Debug.Log((object)$"BearTamingMod: Обновлен рост {num} медведей"); } } catch (Exception ex2) { Debug.LogError((object)("Ошибка в системе роста: " + ex2.Message)); } } private bool UpdateSingleBearGrowth(GameObject bear, double currentTime) { ZNetView component = bear.GetComponent<ZNetView>(); if ((Object)(object)component == (Object)null || !component.IsValid()) { return false; } bool @bool = component.GetZDO().GetBool("isBaby", false); bool bool2 = component.GetZDO().GetBool("growthComplete", false); if (!@bool || bool2) { return false; } long num = component.GetZDO().GetLong("bornTime", 0L); if (num == 0) { num = (long)currentTime; component.GetZDO().Set("bornTime", num); Debug.Log((object)$"BearTamingMod: Установлено время рождения медвежонка: {currentTime}"); } double num2 = currentTime - (double)num; double num3 = num2 / 1800.0; component.GetZDO().Set("ageInDays", (float)num3); float num4 = Mathf.Clamp01((float)num3 / GrowthDays.Value); float num5 = CalculateGrowthCurve(num4); float num6 = Mathf.Lerp(0.5f, 1f, num5); float @float = component.GetZDO().GetFloat("currentSize", 0.5f); if (Mathf.Abs(num6 - @float) > 0.001f) { component.GetZDO().Set("currentSize", num6); UpdateBearSizeImmediate(bear, num6); float num7 = (num6 - 0.5f) / 0.5f; component.GetZDO().Set("growthProgress", num7); Debug.Log((object)$"BearTamingMod: Медвежонок растет: возраст {num3:F2}/{GrowthDays.Value} дней, размер {num6:F2}, прогресс {num7:P0}"); if (num4 >= 0.999f) { CompleteBearGrowth(bear, component); } return true; } return false; } public void RestoreBearState(GameObject bear) { //IL_00db: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)bear == (Object)null) { return; } ZNetView component = bear.GetComponent<ZNetView>(); if ((Object)(object)component == (Object)null || !component.IsValid()) { return; } bool @bool = component.GetZDO().GetBool("isBaby", false); bool bool2 = component.GetZDO().GetBool("growthComplete", false); bool bool3 = component.GetZDO().GetBool("noDrop", false); if (@bool && !bool2) { float @float = component.GetZDO().GetFloat("currentSize", 0.5f); UpdateBearSizeImmediate(bear, @float); if (bool3) { DisableBabyBearDrops(bear); } Debug.Log((object)$"BearTamingMod: Состояние медвежонка восстановлено. Размер: {@float:F2}"); } else if (bool2) { bear.transform.localScale = Vector3.one; RestoreAdultBearDrops(bear); } } public void UpdateBearSizeImmediate(GameObject bear, float newSize) { //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_001c: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)bear == (Object)null) { return; } try { bear.transform.localScale = Vector3.one * newSize; Character component = bear.GetComponent<Character>(); if ((Object)(object)component != (Object)null) { component.SetMaxHealth(component.GetMaxHealth()); } } catch (Exception ex) { Debug.LogError((object)("Ошибка обновления размера медвежонка: " + ex.Message)); } } private void CompleteBearGrowth(GameObject bear, ZNetView znetView) { //IL_0008: Unknown result type (might be due to invalid IL or missing references) try { bear.transform.localScale = Vector3.one; znetView.GetZDO().Set("isBaby", false); znetView.GetZDO().Set("currentSize", 1f); znetView.GetZDO().Set("growthComplete", true); znetView.GetZDO().Set("growthProgress", 1f); znetView.GetZDO().Set("noDrop", false); RestoreAdultBearDrops(bear); Debug.Log((object)"BearTamingMod: Медвежонок полностью вырос во взрослого медведя!"); Player localPlayer = Player.m_localPlayer; if ((Object)(object)localPlayer != (Object)null) { ((Character)localPlayer).Message((MessageType)2, "Медвежонок вырос во взрослого медведя!", 0, (Sprite)null); } } catch (Exception ex) { Debug.LogError((object)("Ошибка завершения роста: " + ex.Message)); } } public void RestoreAdultBearDrops(GameObject bear) { try { CharacterDrop component = bear.GetComponent<CharacterDrop>(); if (!((Object)(object)component != (Object)null)) { return; } GameObject prefab = ZNetScene.instance.GetPrefab("Bjorn"); if ((Object)(object)prefab != (Object)null) { CharacterDrop component2 = prefab.GetComponent<CharacterDrop>(); if ((Object)(object)component2 != (Object)null && component2.m_drops != null) { component.m_drops = new List<Drop>(component2.m_drops); Debug.Log((object)"BearTamingMod: Дроп восстановлен для взрослого медведя"); } } } catch (Exception ex) { Debug.LogError((object)("Ошибка восстановления дропа для взрослого медведя: " + ex.Message)); } } public void DisableBabyBearDrops(GameObject bear) { try { CharacterDrop component = bear.GetComponent<CharacterDrop>(); if ((Object)(object)component != (Object)null) { component.m_drops = new List<Drop>(); Debug.Log((object)"BearTamingMod: Дроп отключен для медвежонка"); } } catch (Exception ex) { Debug.LogError((object)("Ошибка отключения дропа для медвежонка: " + ex.Message)); } } private float CalculateGrowthCurve(float progress) { return progress * progress * (3f - 2f * progress); } public static void InitializeSystem() { if (!_isInitialized) { _isInitialized = true; if ((Object)(object)Instance != (Object)null) { Instance.RestoreAllBabyBears(); } Debug.Log((object)"BearTamingMod: Система роста инициализирована"); } } private void RestoreAllBabyBears() { try { List<MonsterAI> list = FindAllBears(); int num = 0; foreach (MonsterAI item in list) { if ((Object)(object)item != (Object)null && (Object)(object)((Component)item).gameObject != (Object)null) { RestoreBearState(((Component)item).gameObject); num++; } } Debug.Log((object)$"BearTamingMod: Восстановлено состояние {num} медведей"); } catch (Exception ex) { Debug.LogError((object)("Ошибка восстановления медведей: " + ex.Message)); } } private void RegisterConsoleCommandsDirectly() { //IL_0034: Unknown result type (might be due to invalid IL or missing references) //IL_0020: Unknown result type (might be due to invalid IL or missing references) //IL_0025: Unknown result type (might be due to invalid IL or missing references) //IL_002b: Expected O, but got Unknown //IL_006c: Unknown result type (might be due to invalid IL or missing references) //IL_0083: Unknown result type (might be due to invalid IL or missing references) //IL_0096: Expected O, but got Unknown //IL_0091: Unknown result type (might be due to invalid IL or missing references) //IL_00a8: Unknown result type (might be due to invalid IL or missing references) //IL_00bb: Expected O, but got Unknown //IL_00b6: Unknown result type (might be due to invalid IL or missing references) //IL_0058: Unknown result type (might be due to invalid IL or missing references) //IL_005d: Unknown result type (might be due to invalid IL or missing references) //IL_0063: Expected O, but got Unknown //IL_00ee: Unknown result type (might be due to invalid IL or missing references) //IL_00da: Unknown result type (might be due to invalid IL or missing references) //IL_00df: Unknown result type (might be due to invalid IL or missing references) //IL_00e5: Expected O, but got Unknown //IL_0126: Unknown result type (might be due to invalid IL or missing references) //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_011d: Expected O, but got Unknown try { object obj = <>c.<>9__37_0; if (obj == null) { ConsoleEvent val = delegate(ConsoleEventArgs args) { //IL_0033: Unknown result type (might be due to invalid IL or missing references) //IL_0042: Unknown result type (might be due to invalid IL or missing references) //IL_004c: Unknown result type (might be due to invalid IL or missing references) //IL_0051: Unknown result type (might be due to invalid IL or missing references) //IL_0056: Unknown result type (might be due to invalid IL or missing references) //IL_005b: Unknown result type (might be due to invalid IL or missing references) //IL_0060: Unknown result type (might be due to invalid IL or missing references) //IL_007e: Unknown result type (might be due to invalid IL or missing references) //IL_007f: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)Player.m_localPlayer == (Object)null) { args.Context.AddString("Ошибка: игрок не найден!"); return; } try { Vector3 val5 = ((Component)Player.m_localPlayer).transform.position + ((Component)Player.m_localPlayer).transform.forward * 3f + Vector3.up; GameObject prefab = ZNetScene.instance.GetPrefab("Bjorn"); if ((Object)(object)prefab != (Object)null) { GameObject bear = Object.Instantiate<GameObject>(prefab, val5, Quaternion.identity); MakeBabyBear(bear); args.Context.AddString("Медвежонок создан!"); } else { args.Context.AddString("Ошибка: префаб медведя не найден!"); } } catch (Exception ex2) { Debug.LogError((object)$"Ошибка создания медвежонка: {ex2}"); args.Context.AddString("Ошибка: " + ex2.Message); } }; <>c.<>9__37_0 = val; obj = (object)val; } new ConsoleCommand("spawnbabybear", "Создает медвежонка", (ConsoleEvent)obj, false, false, false, false, false, (ConsoleOptionsFetcher)null, false, false, false); object obj2 = <>c.<>9__37_1; if (obj2 == null) { ConsoleEvent val2 = delegate(ConsoleEventArgs args) { List<MonsterAI> list3 = FindAllBears(); int num5 = 0; int num6 = 0; int num7 = 0; int num8 = 0; int num9 = 0; int num10 = 0; foreach (MonsterAI item in list3) { if (!((Object)(object)item == (Object)null)) { num5++; bool flag = IsBearTamed(item); bool flag2 = IsBabyBear(((Component)item).gameObject); if (flag) { num6++; if (flag2) { num7++; num9++; } else if (BearBreedingSystem.CanBreed(item)) { num10++; } } else { num8++; } } } args.Context.AddString($"Всего: {num5}, Приручено: {num6}, Диких: {num8}"); args.Context.AddString($"Медвежат: {num7} (растут: {num9})"); args.Context.AddString($"Взрослых готовых к размножению: {num10}"); int num11 = 1; foreach (MonsterAI item2 in list3) { if ((Object)(object)item2 != (Object)null && IsBabyBear(((Component)item2).gameObject)) { ZNetView component3 = ((Component)item2).GetComponent<ZNetView>(); if ((Object)(object)component3 != (Object)null && component3.IsValid()) { float float3 = component3.GetZDO().GetFloat("ageInDays", 0f); float float4 = component3.GetZDO().GetFloat("currentSize", 0.5f); float float5 = component3.GetZDO().GetFloat("growthProgress", 0f); long long2 = component3.GetZDO().GetLong("bornTime", 0L); double num12 = (((Object)(object)ZNet.instance != (Object)null) ? ZNet.instance.GetTimeSeconds() : 0.0); double num13 = ((long2 > 0) ? ((num12 - (double)long2) / 1800.0) : 0.0); double num14 = Math.Max(0.0, (double)GrowthDays.Value - num13); float num15 = float5 * 100f; args.Context.AddString($"Медвежонок {num11}: {num13:F2}/{GrowthDays.Value} дн. ({num15:F1}%) Размер: {float4:F2}"); num11++; } } } if (num7 == 0) { args.Context.AddString("Нет растущих медвежат"); } }; <>c.<>9__37_1 = val2; obj2 = (object)val2; } new ConsoleCommand("bearinfo", "Информация о медведях", (ConsoleEvent)obj2, false, false, false, false, false, (ConsoleOptionsFetcher)null, false, false, false); new ConsoleCommand("forcegrow", "Мгновенно вырастить всех медвежат", (ConsoleEvent)delegate(ConsoleEventArgs args) { int num4 = 0; List<MonsterAI> list2 = FindAllBears(); foreach (MonsterAI item3 in list2) { if (!((Object)(object)item3 == (Object)null)) { try { if (IsBabyBear(((Component)item3).gameObject)) { ZNetView component2 = ((Component)item3).GetComponent<ZNetView>(); if ((Object)(object)component2 != (Object)null && component2.IsValid()) { CompleteBearGrowth(((Component)item3).gameObject, component2); num4++; } } } catch (Exception ex) { Debug.LogError((object)("Error growing baby bear: " + ex.Message)); } } } args.Context.AddString($"Мгновенно выращено {num4} медвежат!"); }, false, false, false, false, false, (ConsoleOptionsFetcher)null, false, false, false); new ConsoleCommand("beargrowthupdate", "Принудительно обновить систему роста", (ConsoleEvent)delegate(ConsoleEventArgs args) { UpdateAllBearGrowth(); args.Context.AddString("Система роста обновлена!"); }, false, false, false, false, false, (ConsoleOptionsFetcher)null, false, false, false); object obj3 = <>c.<>9__37_4; if (obj3 == null) { ConsoleEvent val3 = delegate(ConsoleEventArgs args) { BearBreedingSystem.UpdateBreeding(); args.Context.AddString("Система размножения обновлена!"); }; <>c.<>9__37_4 = val3; obj3 = (object)val3; } new ConsoleCommand("bearbreedingupdate", "Принудительно обновить систему размножения", (ConsoleEvent)obj3, false, false, false, false, false, (ConsoleOptionsFetcher)null, false, false, false); object obj4 = <>c.<>9__37_5; if (obj4 == null) { ConsoleEvent val4 = delegate(ConsoleEventArgs args) { args.Context.AddString($"Система инициализирована: {_isInitialized}"); args.Context.AddString($"ZNet доступен: {(Object)(object)ZNet.instance != (Object)null}"); args.Context.AddString($"Серверный режим: {(Object)(object)ZNet.instance != (Object)null && ZNet.instance.IsServer()}"); List<MonsterAI> list = FindAllBears(); args.Context.AddString($"Всего медведей в мире: {list.Count}"); int num = 0; foreach (MonsterAI item4 in list) { if ((Object)(object)item4 != (Object)null && IsBabyBear(((Component)item4).gameObject)) { num++; ZNetView component = ((Component)item4).GetComponent<ZNetView>(); if ((Object)(object)component != (Object)null && component.IsValid()) { double num2 = (((Object)(object)ZNet.instance != (Object)null) ? ZNet.instance.GetTimeSeconds() : 0.0); long @long = component.GetZDO().GetLong("bornTime", 0L); float num3 = ((@long > 0) ? ((float)((num2 - (double)@long) / 1800.0)) : 0f); float @float = component.GetZDO().GetFloat("currentSize", 0.5f); float float2 = component.GetZDO().GetFloat("growthProgress", 0f); args.Context.AddString($"Медвежонок: возраст {num3:F2} дн., размер {@float:F2}, прогресс {float2:P0}"); } } } args.Context.AddString($"Активных медвежат: {num}"); }; <>c.<>9__37_5 = val4; obj4 = (object)val4; } new ConsoleCommand("beardiagnostic", "Диагностика системы роста", (ConsoleEvent)obj4, false, false, false, false, false, (ConsoleOptionsFetcher)null, false, false, false); ((BaseUnityPlugin)this).Logger.LogInfo((object)"BearTamingMod: Консольные команды успешно зарегистрированы!"); } catch (Exception arg) { ((BaseUnityPlugin)this).Logger.LogError((object)$"Ошибка регистрации команд: {arg}"); } } public static bool IsBearTamed(MonsterAI bear) { if ((Object)(object)bear == (Object)null) { return false; } try { if (GetPrivateField<bool>(bear, "m_tamed")) { return true; } ZNetView component = ((Component)bear).GetComponent<ZNetView>(); if ((Object)(object)component != (Object)null && component.IsValid()) { return component.GetZDO().GetBool("tamed", false); } } catch (Exception ex) { Debug.LogError((object)("Ошибка проверки приручения: " + ex.Message)); } return false; } public static bool IsBabyBear(GameObject bear) { if ((Object)(object)bear == (Object)null) { return false; } ZNetView component = bear.GetComponent<ZNetView>(); if ((Object)(object)component != (Object)null && component.IsValid()) { bool @bool = component.GetZDO().GetBool("isBaby", false); bool bool2 = component.GetZDO().GetBool("growthComplete", false); return @bool && !bool2; } return false; } public static T GetPrivateField<T>(object obj, string fieldName) { if (obj == null) { return default(T); } FieldInfo field = obj.GetType().GetField(fieldName, BindingFlags.Instance | BindingFlags.NonPublic); return (field != null) ? ((T)field.GetValue(obj)) : default(T); } public static void SetPrivateField(object obj, string fieldName, object value) { if (obj != null) { FieldInfo field = obj.GetType().GetField(fieldName, BindingFlags.Instance | BindingFlags.NonPublic); if (field != null && value != null && field.FieldType == value.GetType()) { field.SetValue(obj, value); } } } public static List<MonsterAI> FindAllBears() { List<MonsterAI> list = new List<MonsterAI>(); MonsterAI[] array = Object.FindObjectsByType<MonsterAI>((FindObjectsSortMode)0); MonsterAI[] array2 = array; foreach (MonsterAI val in array2) { if ((Object)(object)val != (Object)null && (Object)(object)((Component)val).gameObject != (Object)null) { string text = ((Object)((Component)val).gameObject).name.ToLower(); if (text.Contains("bear") || text.Contains("bjorn")) { list.Add(val); } } } return list; } public static void MakeBabyBear(GameObject bear) { //IL_003c: Unknown result type (might be due to invalid IL or missing references) //IL_0046: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)bear == (Object)null) { return; } try { double num = (((Object)(object)ZNet.instance != (Object)null) ? ZNet.instance.GetTimeSeconds() : 0.0); bear.transform.localScale = Vector3.one * 0.5f; Character component = bear.GetComponent<Character>(); if ((Object)(object)component != (Object)null) { component.SetTamed(true); component.SetLevel(1); Instance.DisableBabyBearDrops(bear); } MonsterAI component2 = bear.GetComponent<MonsterAI>(); if ((Object)(object)component2 != (Object)null) { SetPrivateField(component2, "m_tamed", true); SetPrivateField(component2, "m_tamable", true); SetPrivateField(component2, "m_commandable", true); SetPrivateField(component2, "m_tameTimer", TameTime.Value); } Tameable component3 = bear.GetComponent<Tameable>(); if ((Object)(object)component3 != (Object)null) { SetPrivateField(component3, "m_tamed", true); SetPrivateField(component3, "m_timeSinceFeeding", 0f); } ZNetView component4 = bear.GetComponent<ZNetView>(); if ((Object)(object)component4 != (Object)null && component4.IsValid()) { component4.GetZDO().Set("tamed", true); component4.GetZDO().Set("isBaby", true); component4.GetZDO().Set("bornTime", (long)num); component4.GetZDO().Set("ageInDays", 0f); component4.GetZDO().Set("currentSize", 0.5f); component4.GetZDO().Set("growthComplete", false); component4.GetZDO().Set("growthProgress", 0f); component4.GetZDO().Set("noDrop", true); } Debug.Log((object)$"BearTamingMod: Прирученный медвежонок создан! Время рождения: {num}"); } catch (Exception ex) { Debug.LogError((object)("Ошибка создания медвежонка: " + ex.Message)); } } } [HarmonyPatch(typeof(Player))] public static class PlayerPatches { [HarmonyPatch("OnSpawned")] [HarmonyPostfix] private static void OnPlayerSpawned(Player __instance) { if ((Object)(object)__instance == (Object)(object)Player.m_localPlayer) { BearTamingMod.InitializeSystem(); Debug.Log((object)"BearTamingMod: Игрок заспавнен, система роста активирована"); if ((Object)(object)BearTamingMod.Instance != (Object)null) { BearTamingMod.Instance.UpdateAllBearGrowth(); } } } } [HarmonyPatch(typeof(ZNet))] public static class ZNetPatches { [HarmonyPatch("OnWorldLoad")] [HarmonyPostfix] private static void OnWorldLoad(ZNet __instance) { if (__instance.IsServer()) { BearTamingMod.InitializeSystem(); Debug.Log((object)"BearTamingMod: Мир загружен, запущено восстановление медвежат"); } } } [HarmonyPatch(typeof(Tameable))] public static class TameablePatches { [HarmonyPatch("GetHoverText")] [HarmonyPostfix] private static void OnHoverText(Tameable __instance, ref string __result) { if ((Object)(object)BearTamingMod.Instance != (Object)null && (Object)(object)ZNet.instance != (Object)null && ZNet.instance.IsServer()) { BearTamingMod.Instance.UpdateAllBearGrowth(); } if (!((Object)(object)__instance != (Object)null)) { return; } string text = ((Object)((Component)__instance).gameObject).name.ToLower(); if (!text.Contains("bear") && !text.Contains("bjorn")) { return; } bool privateField = BearTamingMod.GetPrivateField<bool>(__instance, "m_tamed"); if (privateField && BearTamingMod.IsBabyBear(((Component)__instance).gameObject)) { ZNetView component = ((Component)__instance).GetComponent<ZNetView>(); if ((Object)(object)component != (Object)null && component.IsValid()) { float @float = component.GetZDO().GetFloat("currentSize", 0.5f); float float2 = component.GetZDO().GetFloat("ageInDays", 0f); long @long = component.GetZDO().GetLong("bornTime", 0L); float float3 = component.GetZDO().GetFloat("growthProgress", 0f); double num = (((Object)(object)ZNet.instance != (Object)null) ? ZNet.instance.GetTimeSeconds() : 0.0); double num2 = ((@long > 0) ? ((num - (double)@long) / 1800.0) : 0.0); double num3 = Math.Max(0.0, (double)BearTamingMod.GrowthDays.Value - num2); float num4 = float3 * 100f; __result += $"\n(Растет: {num4:F1}%, {num3:F1} дн. осталось)"; __result += $"\n(Размер: {@float:F2}, возраст: {num2:F2} дн.)"; } } else if (privateField && !BearTamingMod.IsBabyBear(((Component)__instance).gameObject)) { MonsterAI component2 = ((Component)__instance).GetComponent<MonsterAI>(); if ((Object)(object)component2 != (Object)null && BearBreedingSystem.CanBreed(component2)) { __result += "\n(Готов к размножению)"; } } } [HarmonyPatch("Interact")] [HarmonyPrefix] private static bool HandlePetCommand(Tameable __instance, Humanoid user, bool hold, bool alt) { if (hold || alt) { return true; } string text = ((Object)((Component)__instance).gameObject).name.ToLower(); if (!text.Contains("bear") && !text.Contains("bjorn")) { return true; } try { if (BearTamingMod.GetPrivateField<bool>(__instance, "m_tamed")) { MonsterAI component = ((Component)__instance).GetComponent<MonsterAI>(); if ((Object)(object)component != (Object)null) { bool privateField = BearTamingMod.GetPrivateField<bool>(component, "m_follow"); BearTamingMod.SetPrivateField(component, "m_follow", !privateField); if (!privateField) { ((Character)user).Message((MessageType)2, "$hud_animal_follow", 0, (Sprite)null); } else { ((Character)user).Message((MessageType)2, "$hud_animal_stay", 0, (Sprite)null); } return false; } } } catch (Exception ex) { Debug.LogError((object)("Ошибка обработки команды приласкать: " + ex.Message)); } return true; } } [HarmonyPatch(typeof(ZNetScene))] public static class ZNetScenePatches { private static bool _prefabsInitialized; [HarmonyPatch("Awake")] [HarmonyPostfix] private static void SetupBearPrefab(ZNetScene __instance) { if (_prefabsInitialized) { return; } try { GameObject prefab = __instance.GetPrefab("Bjorn"); if ((Object)(object)prefab == (Object)null) { Debug.LogError((object)"BearTamingMod: Префаб медведя не найден!"); return; } SetupBearTameable(prefab); _prefabsInitialized = true; Debug.Log((object)"BearTamingMod: Настройка префаба медведя завершена!"); } catch (Exception arg) { Debug.LogError((object)$"Ошибка настройка префаба медведя: {arg}"); } } private static void SetupBearTameable(GameObject bearPrefab) { Tameable val = bearPrefab.GetComponent<Tameable>(); if ((Object)(object)val == (Object)null) { val = bearPrefab.AddComponent<Tameable>(); } val.m_tamingTime = BearTamingMod.TameTime.Value; val.m_fedDuration = BearTamingMod.FedDuration.Value; val.m_commandable = true; MonsterAI component = bearPrefab.GetComponent<MonsterAI>(); if ((Object)(object)component != (Object)null) { SetupConsumableItems(component); } } private static void SetupConsumableItems(MonsterAI bearAI) { if (bearAI.m_consumeItems != null) { bearAI.m_consumeItems.Clear(); } string[] array = BearTamingMod.ConsumableItems.Value.Split(new char[1] { ';' }); string[] array2 = array; foreach (string text in array2) { string text2 = text.Trim(); if (!string.IsNullOrEmpty(text2)) { AddConsumableItem(bearAI, text2); } } if (bearAI.m_consumeItems == null || bearAI.m_consumeItems.Count == 0) { AddConsumableItem(bearAI, "Honey"); } } private static void AddConsumableItem(MonsterAI bearAI, string itemName) { GameObject itemPrefab = ObjectDB.instance.GetItemPrefab(itemName); if (!((Object)(object)itemPrefab != (Object)null)) { return; } ItemDrop component = itemPrefab.GetComponent<ItemDrop>(); if ((Object)(object)component != (Object)null) { if (bearAI.m_consumeItems == null) { bearAI.m_consumeItems = new List<ItemDrop>(); } bearAI.m_consumeItems.Add(component); Debug.Log((object)("BearTamingMod: Добавлен предмет для приручения: " + itemName)); } } } [HarmonyPatch(typeof(Character))] public static class CharacterHoverPatches { [HarmonyPatch("GetHoverName")] [HarmonyPostfix] private static void ModifyBearHoverName(Character __instance, ref string __result) { if ((Object)(object)__instance == (Object)null) { return; } string text = ((Object)((Component)__instance).gameObject).name.ToLower(); if (!text.Contains("bear") && !text.Contains("bjorn")) { return; } try { MonsterAI component = ((Component)__instance).GetComponent<MonsterAI>(); if (!((Object)(object)component == (Object)null)) { bool flag = BearTamingMod.IsBearTamed(component); if (BearTamingMod.IsBabyBear(((Component)__instance).gameObject)) { __result = "Медвежонок"; } else { __result = "Медведь"; } } } catch (Exception ex) { Debug.LogError((object)("Ошибка изменения имени медведя: " + ex.Message)); } } } [HarmonyPatch(typeof(Character))] public static class CharacterStatePatches { [HarmonyPatch("Start")] [HarmonyPostfix] private static void RestoreBearState(Character __instance) { if ((Object)(object)__instance == (Object)null || (Object)(object)((Component)__instance).gameObject == (Object)null) { return; } string text = ((Object)((Component)__instance).gameObject).name.ToLower(); if (!text.Contains("bear") && !text.Contains("bjorn")) { return; } try { BearTamingMod.Instance.RestoreBearState(((Component)__instance).gameObject); } catch (Exception ex) { Debug.LogError((object)("Ошибка восстановления состояния медведя: " + ex.Message)); } } } [HarmonyPatch(typeof(Character))] public static class CharacterDeathPatches { [HarmonyPatch("OnDeath")] [HarmonyPrefix] private static void OnDeathPrefix(Character __instance) { if ((Object)(object)__instance == (Object)null) { return; } string text = ((Object)((Component)__instance).gameObject).name.ToLower(); if (!text.Contains("bear") && !text.Contains("bjorn")) { return; } try { if (BearTamingMod.IsBabyBear(((Component)__instance).gameObject)) { BearTamingMod.Instance.DisableBabyBearDrops(((Component)__instance).gameObject); Debug.Log((object)"BearTamingMod: Дроп отключен для убитого медвежонка"); } else { BearTamingMod.Instance.RestoreAdultBearDrops(((Component)__instance).gameObject); } } catch (Exception ex) { Debug.LogError((object)("Ошибка обработки смерти медведя: " + ex.Message)); } } } public static class BearBreedingSystem { public static Dictionary<GameObject, long> _lastBreedTimes = new Dictionary<GameObject, long>(); private const float MIN_BREED_DISTANCE = 3f; private const float MAX_BREED_DISTANCE = 10f; private const float REQUIRED_FULLNESS = 0.7f; public static void UpdateBreeding() { try { List<MonsterAI> list = BearTamingMod.FindAllBears(); List<MonsterAI> list2 = new List<MonsterAI>(); foreach (MonsterAI item in list) { if (!((Object)(object)item == (Object)null) && BearTamingMod.IsBearTamed(item) && !BearTamingMod.IsBabyBear(((Component)item).gameObject) && CanBreed(item)) { list2.Add(item); } } if (list2.Count < 2) { return; } for (int i = 0; i < list2.Count; i++) { for (int j = i + 1; j < list2.Count; j++) { if (CheckBreedingPair(list2[i], list2[j])) { return; } } } } catch (Exception ex) { Debug.LogError((object)("Ошибка в системе размножения: " + ex.Message)); } } private static bool CheckBreedingPair(MonsterAI bear1, MonsterAI bear2) { //IL_0045: Unknown result type (might be due to invalid IL or missing references) //IL_0050: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)bear1 == (Object)null || (Object)(object)bear2 == (Object)null) { return false; } if (!CanBearBreedNow(bear1) || !CanBearBreedNow(bear2)) { return false; } float num = Vector3.Distance(((Component)bear1).transform.position, ((Component)bear2).transform.position); if (num < 3f || num > 10f) { return false; } if (Random.Range(0f, 1f) > BearTamingMod.BreedChance.Value) { return false; } Debug.Log((object)"BearTamingMod: Успешная проверка размножения - создаем медвежонка"); SpawnBabyBear(bear1, bear2); SetBreedCooldown(bear1); SetBreedCooldown(bear2); return true; } public static bool CanBearBreedNow(MonsterAI bear) { if ((Object)(object)bear == (Object)null) { return false; } if (_lastBreedTimes.ContainsKey(((Component)bear).gameObject)) { long num = _lastBreedTimes[((Component)bear).gameObject]; long num2 = (long)ZNet.instance.GetTimeSeconds(); long num3 = (long)(BearTamingMod.BreedCooldownDays.Value * 1800f); long num4 = num2 - num; if (num4 < num3) { return false; } } return true; } private static void SetBreedCooldown(MonsterAI bear) { if ((Object)(object)bear != (Object)null) { long num = (long)ZNet.instance.GetTimeSeconds(); _lastBreedTimes[((Component)bear).gameObject] = num; ZNetView component = ((Component)bear).GetComponent<ZNetView>(); if ((Object)(object)component != (Object)null && component.IsValid()) { component.GetZDO().Set("lastBreedTime", num); } } } public static bool CanBreed(MonsterAI bear) { if ((Object)(object)bear == (Object)null) { return false; } Tameable component = ((Component)bear).GetComponent<Tameable>(); if ((Object)(object)component != (Object)null) { float privateField = BearTamingMod.GetPrivateField<float>(component, "m_timeSinceFeeding"); if (privateField > component.m_fedDuration * 0.7f) { return false; } } if (BearTamingMod.IsBabyBear(((Component)bear).gameObject)) { return false; } return true; } private static void SpawnBabyBear(MonsterAI parent1, MonsterAI parent2) { //IL_0008: Unknown result type (might be due to invalid IL or missing references) //IL_0013: Unknown result type (might be due to invalid IL or missing references) //IL_0018: Unknown result type (might be due to invalid IL or missing references) //IL_0022: Unknown result type (might be due to invalid IL or missing references) //IL_0027: Unknown result type (might be due to invalid IL or missing references) //IL_0028: Unknown result type (might be due to invalid IL or missing references) //IL_0029: Unknown result type (might be due to invalid IL or missing references) //IL_0033: Unknown result type (might be due to invalid IL or missing references) //IL_0038: Unknown result type (might be due to invalid IL or missing references) //IL_0042: Unknown result type (might be due to invalid IL or missing references) //IL_0047: Unknown result type (might be due to invalid IL or missing references) //IL_004c: Unknown result type (might be due to invalid IL or missing references) //IL_0051: Unknown result type (might be due to invalid IL or missing references) //IL_006f: Unknown result type (might be due to invalid IL or missing references) //IL_0070: Unknown result type (might be due to invalid IL or missing references) try { Vector3 val = (((Component)parent1).transform.position + ((Component)parent2).transform.position) / 2f; val += Vector3.up * 0.5f + Random.insideUnitSphere * 1f; GameObject prefab = ZNetScene.instance.GetPrefab("Bjorn"); if ((Object)(object)prefab != (Object)null) { GameObject bear = Object.Instantiate<GameObject>(prefab, val, Quaternion.identity); BearTamingMod.MakeBabyBear(bear); Player localPlayer = Player.m_localPlayer; if ((Object)(object)localPlayer != (Object)null) { ((Character)localPlayer).Message((MessageType)2, "Медведи произвели потомство!", 0, (Sprite)null); } Debug.Log((object)"BearTamingMod: Новый прирученный медвежонок появился через размножение!"); } else { Debug.LogError((object)"BearTamingMod: Не удалось найти префаб медведя для размножения"); } } catch (Exception ex) { Debug.LogError((object)("Ошибка создания медвежонка: " + ex.Message)); } } }