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 EventRewards v0.5.31
plugins/EventRewards.dll
Decompiled 2 weeks ago
The result has been truncated due to the large size, download it to view full contents!
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.Globalization; using System.IO; using System.Linq; using System.Reflection; using System.Reflection.Emit; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Text; using System.Text.RegularExpressions; using BepInEx; using BepInEx.Bootstrap; using BepInEx.Configuration; using BepInEx.Logging; using EventRewards.Core; using EventRewards.Patches; using HarmonyLib; using Jotunn.Entities; using Jotunn.Managers; using Jotunn.Utils; using Microsoft.CodeAnalysis; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using UnityEngine; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETFramework,Version=v4.6.2", FrameworkDisplayName = ".NET Framework 4.6.2")] [assembly: AssemblyCompany("EventRewards")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("0.5.31.0")] [assembly: AssemblyInformationalVersion("0.5.31+4113c2a7cec089c386ac075e1a2b476a49ca1b76")] [assembly: AssemblyProduct("EventRewards")] [assembly: AssemblyTitle("EventRewards")] [assembly: AssemblyVersion("0.5.31.0")] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Embedded] internal sealed class IsReadOnlyAttribute : Attribute { } [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } namespace EventRewards { internal static class DeliveryServer { private sealed class Presence { public ZDOID Character; public float Since; public Vector3 LastPos; public bool Still; public long PeerUid; public bool Local; } private sealed class Retry { public float Next; public float Delay; } internal struct OnlineCharacter { public long PlayerId; public long PeerUid; public bool Local; public int Code; public string Name; } private sealed class Parsed<T> { public bool Ok; public T Value; public string Error; } private const float TeleportJumpMeters = 50f; private const float StillMeters = 2f; private const float RosterSaveSeconds = 300f; private const float SpawnHeight = 1f; private const float RetryFirstSeconds = 10f; private const float RetryMaxSeconds = 300f; private const int RecoveredQueueReserve = 1000; private const int ZAnimBoolOffset = 438569; private static string _loadError; private static PlayerRoster _roster; private static DeliveryQueue _queue; private static float _timer; private static float _rosterSaveTimer; private static bool _rosterDirty; private static bool _queueDirty; private static int _inWaterKey; private static readonly Dictionary<long, Presence> Presences = new Dictionary<long, Presence>(); private static readonly HashSet<long> Online = new HashSet<long>(); private static readonly HashSet<int> WarnedEntries = new HashSet<int>(); private static readonly HashSet<string> HuntWarned = new HashSet<string>(StringComparer.Ordinal); private static readonly Dictionary<int, Retry> Retries = new Dictionary<int, Retry>(); private static readonly RateLimiter IdentityWarnings = new RateLimiter(1, 300.0); public static string RosterPath => Path.Combine(Paths.ConfigPath, "sansara.EventRewards.players.json"); public static string QueuePath => Path.Combine(Paths.ConfigPath, "sansara.EventRewards.queue.json"); public static bool Running { get; private set; } internal static PlayerRoster Roster => _roster; public static void Init() { Shutdown(); if (!((Object)(object)ZNet.instance == (Object)null) && ZNet.instance.IsServer()) { if (!LoadRoster(out var error) || !LoadQueue(out error)) { _loadError = error; Plugin.Log.LogError((object)("Event Rewards: " + error + "; список игроков и очередь доставки отключены до исправления файла")); } else { Running = true; Plugin.Log.LogInfo((object)($"Event Rewards: игроков в списке {_roster.Count}, в очереди доставки ожидают {_queue.Pending(null).Count}" + (PluginConfig.DeliveryEnabled.Value ? "" : " (доставка выключена в cfg)"))); } } } public static void Shutdown() { if (Running) { if (_rosterDirty) { SaveRoster(); } if (_queueDirty) { SaveQueue(); } } Running = false; _loadError = null; _roster = null; _queue = null; _timer = 0f; _rosterSaveTimer = 0f; _rosterDirty = false; _queueDirty = false; Presences.Clear(); Online.Clear(); WarnedEntries.Clear(); HuntWarned.Clear(); Retries.Clear(); } public static void Tick(float deltaTime) { _timer += deltaTime; _rosterSaveTimer += deltaTime; if (_timer < PluginConfig.DeliveryCheckIntervalSeconds.Value) { return; } _timer = 0f; try { Check(); } catch (Exception ex) { Plugin.Log.LogWarning((object)("Event Rewards: ошибка проверки игроков и доставки: " + ex)); } } private static void Check() { //IL_0054: Unknown result type (might be due to invalid IL or missing references) //IL_00bb: 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) if ((Object)(object)ZNet.instance == (Object)null || ZDOMan.instance == null) { return; } DateTime utcNow = DateTime.UtcNow; float realtimeSinceStartup = Time.realtimeSinceStartup; Online.Clear(); foreach (ZNetPeer peer in ZNet.instance.GetPeers()) { ZDO val = CharacterOf(peer); if (val != null) { Observe(val, peer.m_characterID, peer.m_playerID, peer.m_playerName, HostOf(peer), peer.m_uid, local: false, utcNow, realtimeSinceStartup); } } if (!ZNet.instance.IsDedicated() && (Object)(object)Player.m_localPlayer != (Object)null) { ZDO zDO = ZDOMan.instance.GetZDO(((Character)Player.m_localPlayer).GetZDOID()); if (zDO != null) { ZDOID uid = zDO.m_uid; Game instance = Game.instance; long? obj; if (instance == null) { obj = null; } else { PlayerProfile playerProfile = instance.GetPlayerProfile(); obj = ((playerProfile != null) ? new long?(playerProfile.GetPlayerID()) : ((long?)null)); } long? num = obj; long valueOrDefault = num.GetValueOrDefault(); Game instance2 = Game.instance; object fallbackName; if (instance2 == null) { fallbackName = null; } else { PlayerProfile playerProfile2 = instance2.GetPlayerProfile(); fallbackName = ((playerProfile2 != null) ? playerProfile2.GetName() : null); } Observe(zDO, uid, valueOrDefault, (string)fallbackName, "local", ZDOMan.GetSessionID(), local: true, utcNow, realtimeSinceStartup); } } foreach (long item in Presences.Keys.Where((long id) => !Online.Contains(id)).ToList()) { Presences.Remove(item); } RevocationServer.OnCheck(OnlineCharacters()); if (_queueDirty) { SaveQueue(); } if (_rosterDirty && _rosterSaveTimer >= 300f) { SaveRoster(); } if (!PluginConfig.DeliveryEnabled.Value || _queueDirty) { return; } foreach (long item2 in Online.ToList()) { if (_queue.HasPending(item2)) { TryDeliver(item2, utcNow, realtimeSinceStartup); } } } private static ZDO CharacterOf(ZNetPeer peer) { //IL_0072: 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) if (peer == null || !peer.IsReady() || ((ZDOID)(ref peer.m_characterID)).IsNone() || ZDOMan.instance == null) { return null; } if (((ZDOID)(ref peer.m_characterID)).UserID != peer.m_uid) { WarnIdentity(peer.m_uid, $"Event Rewards: {RewardLoss.Sanitize(peer.m_playerName)} ({peer.m_uid}) сообщил чужой ZDOID персонажа {peer.m_characterID}, пропущен"); return null; } ZDO zDO = ZDOMan.instance.GetZDO(peer.m_characterID); if (zDO == null) { return null; } if (zDO.GetOwner() != peer.m_uid) { return null; } return zDO; } private static void Observe(ZDO zdo, ZDOID character, long fallbackId, string fallbackName, string host, long uid, bool local, DateTime now, float t) { //IL_0139: Unknown result type (might be due to invalid IL or missing references) //IL_013e: Unknown result type (might be due to invalid IL or missing references) //IL_0162: Unknown result type (might be due to invalid IL or missing references) //IL_0163: Unknown result type (might be due to invalid IL or missing references) //IL_0171: Unknown result type (might be due to invalid IL or missing references) //IL_0172: Unknown result type (might be due to invalid IL or missing references) //IL_014f: Unknown result type (might be due to invalid IL or missing references) //IL_0154: Unknown result type (might be due to invalid IL or missing references) //IL_01c5: Unknown result type (might be due to invalid IL or missing references) //IL_01c6: Unknown result type (might be due to invalid IL or missing references) //IL_018d: Unknown result type (might be due to invalid IL or missing references) //IL_018f: Unknown result type (might be due to invalid IL or missing references) //IL_0194: Unknown result type (might be due to invalid IL or missing references) //IL_0199: Unknown result type (might be due to invalid IL or missing references) long num = zdo.GetLong(ZDOVars.s_playerID, 0L); if (num == 0L) { num = fallbackId; } if (num == 0L) { return; } string text = zdo.GetString(ZDOVars.s_playerName, ""); if (string.IsNullOrWhiteSpace(text)) { text = fallbackName; } switch (_roster.Touch(num, text, host, now)) { case RosterChange.HostMismatch: { _roster.TryGetById(num, out var entry2); WarnIdentity(num, $"Event Rewards: персонаж {RewardLoss.Sanitize(text)} ({uid}, платформа «{host}») выдаёт себя за " + PlayerCode.Format(entry2.Code) + " " + entry2.Name + ", привязанного к другой платформе; не учитывается (если это тот же игрок — eventreward players unbind " + PlayerCode.Format(entry2.Code) + ")"); return; } case RosterChange.New: { _roster.TryGetById(num, out var entry); Plugin.Log.LogInfo((object)("Event Rewards: новый игрок " + PlayerCode.Format(entry.Code) + " " + entry.Name)); SaveRoster(); break; } case RosterChange.Updated: SaveRoster(); break; case RosterChange.Seen: _rosterDirty = true; break; } Online.Add(num); Vector3 position = zdo.GetPosition(); if (!Presences.TryGetValue(num, out var value) || value.Character != character) { value = new Presence { Character = character, Since = t, LastPos = position, Still = false }; Presences[num] = value; } else { Vector3 val = position - value.LastPos; float magnitude = ((Vector3)(ref val)).magnitude; if (magnitude > 50f) { value.Since = t; } value.Still = magnitude < 2f; } value.LastPos = position; value.PeerUid = uid; value.Local = local; } internal static bool IsOnline(long playerId) { if (Running) { return Online.Contains(playerId); } return false; } internal static List<OnlineCharacter> OnlineCharacters() { List<OnlineCharacter> list = new List<OnlineCharacter>(); if (!Running) { return list; } foreach (KeyValuePair<long, Presence> presence in Presences) { if (Online.Contains(presence.Key)) { _roster.TryGetById(presence.Key, out var entry); list.Add(new OnlineCharacter { PlayerId = presence.Key, PeerUid = presence.Value.PeerUid, Local = presence.Value.Local, Code = (entry?.Code ?? 0), Name = (entry?.Name ?? "?") }); } } return list; } internal static bool TryGetOnlineByPeer(long peerUid, out OnlineCharacter character) { foreach (OnlineCharacter item in OnlineCharacters()) { if (item.PeerUid == peerUid) { character = item; return true; } } character = default(OnlineCharacter); return false; } internal static List<int> PendingWith(ICollection<string> rewardIds, long playerId) { List<int> list = new List<int>(); if (!Running || rewardIds == null) { return list; } foreach (DeliveryEntry item in _queue.Pending(null)) { if (rewardIds.Contains(item.RewardId) && (playerId == 0L || item.PlayerId == playerId)) { list.Add(item.N); } } return list; } public static string HostOf(ZNetPeer peer) { try { object obj; if (peer == null) { obj = null; } else { ISocket socket = peer.m_socket; obj = ((socket != null) ? socket.GetHostName() : null); } if (obj == null) { obj = ""; } return (string)obj; } catch (Exception) { return ""; } } public static long PlayerIdOf(ZNetPeer peer) { ZDO val = CharacterOf(peer); long num = ((val != null) ? val.GetLong(ZDOVars.s_playerID, 0L) : 0); if (num == 0L) { if (val == null) { return 0L; } return peer.m_playerID; } return num; } private static void WarnIdentity(long key, string text) { if (IdentityWarnings.TryAcquire(key, Time.realtimeSinceStartup)) { Plugin.Log.LogWarning((object)text); } } private static bool InWater(ZDO zdo) { try { if (_inWaterKey == 0) { _inWaterKey = 438569 + ZSyncAnimation.GetHash("inWater"); } return zdo.GetInt(_inWaterKey, 0) != 0; } catch (Exception) { return false; } } private static void TryDeliver(long playerId, DateTime now, float t) { //IL_0033: Unknown result type (might be due to invalid IL or missing references) //IL_0108: Unknown result type (might be due to invalid IL or missing references) //IL_010d: 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_011c: Unknown result type (might be due to invalid IL or missing references) if (!Presences.TryGetValue(playerId, out var value) || t - value.Since < PluginConfig.DeliverySettleSeconds.Value || !value.Still) { return; } ZDO zDO = ZDOMan.instance.GetZDO(value.Character); if (zDO == null || zDO.GetBool(ZDOVars.s_dead, false) || InWater(zDO)) { return; } foreach (DeliveryEntry item in _queue.PendingFor(playerId)) { if (!ServerCatalog.Current.TryGet(item.RewardId, out var definition)) { if (WarnedEntries.Add(item.N)) { Plugin.Log.LogWarning((object)($"Event Rewards: #{item.N} {item.RewardId} — такой награды нет в наборе сервера, запись ждёт " + $"(исправьте набор и eventreward reload или eventreward cancel {item.N})")); } } else { if (Retries.TryGetValue(item.N, out var value2) && t < value2.Next) { continue; } string error; List<ZDO> list = SpawnReward(definition, playerId, zDO.GetPosition() + Vector3.up * 1f, out error); if (list != null) { Retries.Remove(item.N); _queue.MarkDelivered(item.N, now); RosterEntry entry; string text = (_roster.TryGetById(playerId, out entry) ? entry.Name : "?"); if (!SaveQueue()) { foreach (ZDO item2 in list) { ZDOMan.instance.DestroyZDO(item2); } _queue.Unmark(item.N); Plugin.Log.LogError((object)($"Event Rewards: #{item.N} {item.RewardId} → {PlayerCode.Format(item.Code)} {text}: файл очереди " + "не записан — предмет убран, запись снова ожидает")); break; } Plugin.Log.LogInfo((object)DeliveryText.DeliveredLog(item, text)); string text2 = DeliveryText.FormatMessage(PluginConfig.DeliveryMessage.Value, definition.Name); if (text2.Length <= 0) { break; } if (value.Local) { MessageHud instance = MessageHud.instance; if (instance != null) { instance.ShowMessage((MessageType)2, text2, 0, (Sprite)null, false, true); } break; } ZRoutedRpc instance2 = ZRoutedRpc.instance; if (instance2 != null) { instance2.InvokeRoutedRPC(value.PeerUid, "ShowMessage", new object[2] { 2, text2 }); } break; } float num = ((value2 == null) ? 10f : Math.Min(value2.Delay * 2f, 300f)); Retries[item.N] = new Retry { Next = t + num, Delay = num }; if (WarnedEntries.Add(item.N)) { Plugin.Log.LogWarning((object)$"Event Rewards: #{item.N} {item.RewardId} не выложена: {error}; повтор с паузой до {300f:0} с"); } } } } private static List<ZDO> SpawnReward(RewardDefinition def, long recipient, Vector3 position, out string error) { //IL_00c9: 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_011c: Unknown result type (might be due to invalid IL or missing references) if (!ResolvePrefab(def, out var prefab, out var drop, out var nview, out error)) { return null; } int stableHashCode = StringExtensionMethods.GetStableHashCode(((Object)prefab).name); int num = ((!def.Plain) ? 1 : Math.Max(1, drop.m_itemData.m_shared.m_maxStackSize)); List<ZDO> list = new List<ZDO>(); for (int num2 = def.Stack; num2 > 0; num2 -= num) { ItemData val; try { val = BuildItem(def, prefab, drop, recipient, Math.Min(num2, num)); } catch (Exception ex) { error = "данные предмета не собраны: " + ex.Message; foreach (ZDO item in list) { ZDOMan.instance.DestroyZDO(item); } return null; } ZDO val2 = null; try { val2 = ZDOMan.instance.CreateNewZDO(position, stableHashCode); val2.Persistent = nview.m_persistent; val2.Type = nview.m_type; val2.Distant = nview.m_distant; val2.SetPrefab(stableHashCode); val2.SetRotation(Quaternion.Euler(0f, Random.Range(0f, 360f), 0f)); val2.Set(ZDOVars.s_spawnTime, ZNet.instance.GetTime().Ticks); ItemDrop.SaveToZDO(val, val2, -1); list.Add(val2); } catch (Exception ex2) { if (val2 != null) { ZDOMan.instance.DestroyZDO(val2); } foreach (ZDO item2 in list) { ZDOMan.instance.DestroyZDO(item2); } error = "ZDO предмета не создан: " + ex2.Message; return null; } } return list; } private static bool ResolvePrefab(RewardDefinition def, out GameObject prefab, out ItemDrop drop, out ZNetView nview, out string error) { error = null; prefab = (((Object)(object)ObjectDB.instance != (Object)null) ? ObjectDB.instance.GetItemPrefab(def.BasePrefab) : null); drop = (((Object)(object)prefab != (Object)null) ? prefab.GetComponent<ItemDrop>() : null); nview = (((Object)(object)prefab != (Object)null) ? prefab.GetComponent<ZNetView>() : null); if ((Object)(object)drop == (Object)null || (Object)(object)nview == (Object)null) { error = "предмет " + def.BasePrefab + " не найден в ObjectDB"; return false; } if ((Object)(object)ZNetScene.instance == (Object)null || (Object)(object)ZNetScene.instance.GetPrefab(StringExtensionMethods.GetStableHashCode(((Object)prefab).name)) == (Object)null) { error = "префаб " + ((Object)prefab).name + " не зарегистрирован в ZNetScene"; return false; } return true; } private static ItemData BuildItem(RewardDefinition def, GameObject prefab, ItemDrop drop, long recipient, int stack) { ItemData val = drop.m_itemData.Clone(); val.m_dropPrefab = prefab; val.m_stack = stack; val.m_quality = def.Quality; val.m_variant = def.Variant; val.m_durability = (def.Plain ? val.GetMaxDurability() : BonusCalculator.ApplyMaxDurability(val.GetMaxDurability(), BonusCalculator.EffectiveDurabilityPercent(def))); val.m_crafterID = 0L; val.m_crafterName = ""; val.m_worldLevel = (byte)Game.m_worldLevel; val.m_pickedUp = false; val.m_cheated = false; val.m_equipped = false; val.m_customData = new Dictionary<string, string>(); if (!def.Plain) { val.m_customData["sansara.EventRewards.id"] = def.Id; RewardTag.SetOwner(val.m_customData, recipient); } return val; } internal static ItemData CreateExternal(RewardDefinition def, out string error) { error = ExternalItem.CreateError(def); if (error != null) { return null; } if (!ResolvePrefab(def, out var prefab, out var drop, out var _, out error)) { return null; } try { return BuildItem(def, prefab, drop, 0L, 1); } catch (Exception ex) { error = "данные предмета не собраны: " + ex.Message; return null; } } public static bool EnqueueHunt(HuntState state, HuntSettings settings) { if (state == null || settings == null || !state.Completed || !settings.AutoDeliver) { return false; } if (!Running) { if (HuntWarned.Add("off:" + state.Id)) { Plugin.Log.LogError((object)("Event Hunt: автовыдача " + settings.RewardId + " невозможна — очередь доставки отключена (" + (_loadError ?? "не сервер") + ")")); } return false; } if (!ServerCatalog.Current.TryGet(settings.RewardId, out var _)) { if (HuntWarned.Add("reward:" + state.Id + ":" + settings.RewardId)) { Plugin.Log.LogError((object)("Event Hunt: награды " + settings.RewardId + " нет в наборе сервера — участники не поставлены в очередь (исправьте набор, eventreward reload; очередь пополнится при следующем изменении или перезапуске)")); } return false; } HuntEnqueueResult huntEnqueueResult = HuntDelivery.Enqueue(state, settings.RewardId, _queue, _roster, DateTime.UtcNow); if (huntEnqueueResult.RosterChanged) { SaveRoster(); } if (huntEnqueueResult.Added.Count > 0) { if (!SaveQueue()) { Plugin.Log.LogError((object)"Event Hunt: очередь не записана — новые записи охоты сохранятся при следующей успешной записи"); } foreach (DeliveryEntry item in huntEnqueueResult.Added) { Plugin.Log.LogInfo((object)DeliveryText.EnqueuedLog(item, _roster.TryGetById(item.PlayerId, out var entry) ? entry.Name : "?")); } } foreach (KeyValuePair<long, HuntPlayer> conflict in huntEnqueueResult.Conflicts) { if (HuntWarned.Add("conflict:" + state.Id + ":" + conflict.Key)) { Plugin.Log.LogWarning((object)("Event Hunt: участник " + RewardLoss.Sanitize(conflict.Value.Name) + " (платформа «" + conflict.Value.Host + "») сдавал с ID персонажа, который в списке игроков привязан к другой платформе, — не поставлен в очередь, проверьте и выдайте вручную")); } } List<KeyValuePair<string, int>> list = HuntDelivery.ManualOnly(state); if (list.Count > 0 && HuntWarned.Add("manual:" + state.Id + ":" + list.Count)) { Plugin.Log.LogWarning((object)("Event Hunt: участники без ID персонажа (вклад записан до 0.5.11) — выдать " + settings.RewardId + " вручную: " + string.Join(", ", list.Select((KeyValuePair<string, int> m) => $"{m.Key} ({m.Value})")))); } return huntEnqueueResult.StateChanged; } internal static string EnqueueExternal(long playerId, string rewardId, string reason) { if (!_roster.TryGetById(playerId, out var entry)) { return $"персонажа {playerId} нет в списке игроков"; } DeliveryEntry deliveryEntry = _queue.EnqueueOnce(rewardId, playerId, entry.Code, reason, DateTime.UtcNow); if (deliveryEntry == null) { return null; } if (!SaveQueue()) { Plugin.Log.LogError((object)("Event Rewards: очередь не записана — запись " + reason + " сохранится при следующей успешной записи")); } Plugin.Log.LogInfo((object)DeliveryText.EnqueuedLog(deliveryEntry, entry.Name)); return null; } internal static string DropExternal(RewardDefinition def, Vector3 position, string reason) { //IL_0003: Unknown result type (might be due to invalid IL or missing references) //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_0021: 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) if (SpawnReward(def, 0L, position, out var error) == null) { return error; } Plugin.Log.LogInfo((object)DeliveryText.DroppedLog(def.Id, reason, position.x, position.y, position.z)); return null; } public static string DescribeHuntRecipient(long playerId, string huntId) { if (!Running) { return ""; } RosterEntry entry; string text = (_roster.TryGetById(playerId, out entry) ? (PlayerCode.Format(entry.Code) + " ") : ""); string text2 = DeliveryReason.Hunt(huntId); foreach (DeliveryEntry entry2 in _queue.Entries) { if (entry2.PlayerId == playerId && !(entry2.Reason != text2)) { string arg = ((entry2.State == DeliveryState.Delivered) ? "доставлено" : ((entry2.State == DeliveryState.Cancelled) ? "отменено" : "в очереди")); return $"{text}{arg} #{entry2.N}"; } } return text + "не в очереди"; } public static string HandleCommand(string sub, string arg1, string arg2) { if (!Running) { return "eventreward " + sub + ": " + (_loadError ?? "работает только на сервере"); } switch (sub) { case "players": { string text = (arg1 ?? "").Trim(); if (text == "unbind" || text.StartsWith("unbind ", StringComparison.Ordinal)) { return Unbind(text.Substring("unbind".Length).Trim()); } return DeliveryText.Players(_roster, Online, text, ServerOffset()); } case "give": return Give(arg1, arg2); case "queue": return QueueList(arg1); case "cancel": return Cancel(arg1); case "revoke": case "unrevoke": return RevocationServer.HandleCommand(sub, arg1, arg2); default: return "eventreward: неизвестная команда '" + sub + "'"; } } private static string Unbind(string codeArg) { if (!PlayerCode.TryParse(codeArg, out var code)) { return "eventreward players unbind: укажите код игрока, например eventreward players unbind @3"; } if (!_roster.TryGetByCode(code, out var entry)) { return "eventreward players unbind: нет игрока с кодом " + PlayerCode.Format(code); } string host = entry.Host; _roster.Unbind(code); SaveRoster(); Plugin.Log.LogInfo((object)("Event Rewards: привязка " + PlayerCode.Format(code) + " " + entry.Name + " к платформе «" + host + "» снята")); return "eventreward players unbind: привязка " + PlayerCode.Format(code) + " " + entry.Name + " к платформе «" + host + "» снята; персонаж привяжется к платформе, с которой войдёт первым"; } private static string Give(string idList, string codeArg) { List<RewardDefinition> defs; RosterEntry player; string text = GiveCommand.ValidateDelivery(idList, codeArg, ServerCatalog.Current, _roster, out defs, out player); if (text != null) { return "eventreward give: " + text; } DateTime now = DateTime.UtcNow; List<DeliveryEntry> list = defs.Select((RewardDefinition d) => _queue.Enqueue(d.Id, player.PlayerId, player.Code, "admin", now)).ToList(); bool flag = SaveQueue(); foreach (DeliveryEntry item in list) { Plugin.Log.LogInfo((object)DeliveryText.EnqueuedLog(item, player.Name)); } StringBuilder stringBuilder = new StringBuilder("eventreward give: в очереди "); stringBuilder.Append(string.Join(", ", list.Select((DeliveryEntry e) => $"#{e.N} {e.RewardId}"))); stringBuilder.Append(" → " + PlayerCode.Format(player.Code) + " " + player.Name + "; "); stringBuilder.Append((!PluginConfig.DeliveryEnabled.Value) ? "доставка выключена в cfg ([Delivery (server)] Enabled)" : (Online.Contains(player.PlayerId) ? "игрок в игре — награда появится у его ног, когда он постоит на месте несколько секунд" : "игрок не в игре — доставка при следующем входе")); if (!flag) { stringBuilder.Append("; ВНИМАНИЕ: файл очереди не записан, доставка приостановлена — см. журнал сервера"); } return stringBuilder.ToString(); } private static string QueueList(string codeArg) { int? code = null; if (!string.IsNullOrWhiteSpace(codeArg)) { if (!PlayerCode.TryParse(codeArg.Trim(), out var code2)) { return "eventreward queue: код игрока '" + codeArg + "' должен быть вида @N (см. eventreward players)"; } code = code2; } return DeliveryText.Queue(_queue, _roster, ServerCatalog.Current, code, ServerOffset()); } private static string Cancel(string arg) { if (!DeliveryQueue.TryParseNumber((arg ?? "").Trim(), out var n)) { return "eventreward cancel: укажите номер записи, например eventreward cancel 12 (см. eventreward queue)"; } _queue.TryGet(n, out var entry); switch (_queue.Cancel(n, DateTime.UtcNow)) { case CancelResult.NotFound: return $"eventreward cancel: записи #{n} нет"; case CancelResult.AlreadyDelivered: return $"eventreward cancel: #{n} уже доставлена {DeliveryText.FormatTime(entry.ClosedAt, ServerOffset())}"; case CancelResult.AlreadyCancelled: return $"eventreward cancel: #{n} уже отменена"; default: { Retries.Remove(n); bool flag = SaveQueue(); RosterEntry entry2; string text = (_roster.TryGetById(entry.PlayerId, out entry2) ? entry2.Name : "?"); Plugin.Log.LogInfo((object)$"Event Rewards: отменено #{entry.N} {entry.RewardId} → {PlayerCode.Format(entry.Code)} {text}"); return $"eventreward cancel: #{entry.N} {entry.RewardId} → {PlayerCode.Format(entry.Code)} {text} отменена" + (flag ? "" : "; ВНИМАНИЕ: файл очереди не записан — см. журнал сервера"); } } } private static TimeSpan ServerOffset() { return TimeZoneInfo.Local.GetUtcOffset(DateTime.UtcNow); } private static bool LoadFile<T>(string path, string what, Func<string, Parsed<T>> parse, Func<T> empty, out T value, out bool recovered, out string error) { value = default(T); recovered = false; error = null; try { if (File.Exists(path)) { Parsed<T> parsed = parse(File.ReadAllText(path)); if (!parsed.Ok) { error = what + " " + path + " не прочитан(а): " + parsed.Error; return false; } value = parsed.Value; return true; } List<string> list = ServerFiles.RecoveryCandidates(path); if (list.Count == 0) { value = empty(); Plugin.Log.LogInfo((object)("Event Rewards: файла " + path + " нет, " + what + " пуст(а) (создастся при первой записи)")); return true; } foreach (string item in list) { Parsed<T> parsed2 = parse(File.ReadAllText(item)); if (!parsed2.Ok) { Plugin.Log.LogWarning((object)("Event Rewards: " + item + " не прочитан: " + parsed2.Error)); continue; } value = parsed2.Value; recovered = true; Plugin.Log.LogWarning((object)("Event Rewards: файла " + path + " нет — " + what + " восстановлен(а) из " + item)); return true; } error = "файла " + path + " нет, а " + string.Join(" и ", list) + " не читаются — " + what + " не восстановлен(а); исправьте или удалите эти файлы"; return false; } catch (Exception ex) { error = what + " " + path + " не прочитан(а): " + ex.Message; return false; } } private static bool LoadRoster(out string error) { if (!LoadFile(RosterPath, "список игроков", delegate(string json) { RosterResult rosterResult = PlayerRosterJson.Parse(json); return new Parsed<PlayerRoster> { Ok = rosterResult.Success, Value = rosterResult.Roster, Error = (rosterResult.Success ? null : rosterResult.Errors[0]) }; }, () => new PlayerRoster(), out _roster, out var recovered, out error)) { return false; } if (recovered) { SaveRoster(); } return true; } private static bool LoadQueue(out string error) { if (!LoadFile(QueuePath, "очередь доставки", delegate(string json) { DeliveryQueueResult deliveryQueueResult = DeliveryQueueJson.Parse(json); return new Parsed<DeliveryQueue> { Ok = deliveryQueueResult.Success, Value = deliveryQueueResult.Queue, Error = (deliveryQueueResult.Success ? null : deliveryQueueResult.Errors[0]) }; }, () => new DeliveryQueue(), out _queue, out var recovered, out error)) { return false; } if (recovered) { _queue.ReserveNumbers(1000); Plugin.Log.LogWarning((object)($"Event Rewards: номера записей очереди продолжатся с #{_queue.NextN}; записи, сделанные после " + "резервной копии, потеряны — проверьте журнал сервера (строки «в очереди» и «доставлено»)")); if (!SaveQueue()) { error = "восстановленная очередь доставки не записана"; return false; } } return true; } private static void SaveRoster() { try { ServerFiles.WriteAtomic(RosterPath, PlayerRosterJson.Serialize(_roster)); _rosterDirty = false; _rosterSaveTimer = 0f; } catch (Exception ex) { _rosterDirty = true; Plugin.Log.LogError((object)("Event Rewards: список игроков не сохранён в " + RosterPath + ": " + ex.Message)); } } private static bool SaveQueue() { try { ServerFiles.WriteAtomic(QueuePath, DeliveryQueueJson.Serialize(_queue)); if (_queueDirty) { Plugin.Log.LogInfo((object)"Event Rewards: очередь доставки снова сохраняется, доставка продолжена"); } _queueDirty = false; return true; } catch (Exception ex) { if (!_queueDirty) { Plugin.Log.LogError((object)("Event Rewards: очередь доставки не сохранена в " + QueuePath + ": " + ex.Message + "; доставка приостановлена до успешной записи")); } _queueDirty = true; return false; } } } internal sealed class EventRewardCommand : ConsoleCommand { public override string Name => "eventreward"; public override string Help => "list | give <id>[,<id>...] [count] | give <id>[,<id>...] @<код> | players [фильтр] | players unbind @<код> | queue [@код] | cancel <№> | revoke <id>[,<id>...] @<код>|all | revoke list | unrevoke #<№> | ship <id>|clear | piece <id>|clear | reload | dualoffset [back] [px py pz rx ry rz [зеркало]]"; public override List<string> CommandOptionList() { return new List<string> { "list", "give", "players", "queue", "cancel", "revoke", "unrevoke", "ship", "piece", "reload", "dualoffset" }; } public override void Run(string[] args) { switch ((args.Length != 0) ? args[0].ToLowerInvariant() : "") { case "list": List(); break; case "give": Give(args); break; case "reload": Reload(); break; case "players": Remote("players", string.Join(" ", args.Skip(1)).Trim(), ""); break; case "queue": Remote("queue", (args.Length > 1) ? args[1] : "", ""); break; case "cancel": Remote("cancel", (args.Length > 1) ? args[1] : "", ""); break; case "revoke": Revoke(args); break; case "unrevoke": Unrevoke(args); break; case "ship": ShipRewards.Command((args.Length > 1) ? args[1] : "", Print); break; case "piece": PieceRewards.Command((args.Length > 1) ? args[1] : "", Print); break; case "dualoffset": Print(DualWield.OffsetCommand(args)); break; default: Print("Использование: eventreward " + ((ConsoleCommand)this).Help); break; } } private static void List() { RewardCatalog catalog = RewardState.Catalog; if (catalog.Count == 0) { Print("Наград нет (сервер без мода или пустой набор)"); return; } foreach (RewardDefinition item in catalog.All) { Print(string.Format("{0}: {1} ({2}, качество {3}{4})", item.Id, item.Name, item.BasePrefab, item.Quality, (item.Variant != 0) ? (", вариант " + item.Variant) : "")); } } private static void Give(string[] args) { if (!SynchronizationManager.Instance.PlayerIsAdmin) { Print("Отказано: нужны права администратора"); return; } GiveRequest giveRequest = GiveCommand.Parse(args.Skip(1).ToList()); if (!giveRequest.Ok) { Print(giveRequest.Error); return; } if (giveRequest.Code.HasValue) { Remote("give", giveRequest.IdList, PlayerCode.Format(giveRequest.Code.Value)); return; } List<string> list = GiveCommand.UnknownIds(giveRequest.Ids, RewardState.Catalog); if (list.Count > 0) { Print(GiveCommand.FormatUnknown(list)); return; } List<string> list2 = PieceReward.PlacedIds(giveRequest.Ids, RewardState.Catalog); if (list2.Count > 0) { Print(PieceReward.FormatNotItems(list2)); return; } Player localPlayer = Player.m_localPlayer; if ((Object)(object)localPlayer == (Object)null) { Print("Нет персонажа"); return; } Inventory inventory = ((Humanoid)localPlayer).GetInventory(); List<string> list3 = new List<string>(); bool flag = false; foreach (string id in giveRequest.Ids) { RewardState.Catalog.TryGet(id, out var definition); int i; for (i = 0; i < giveRequest.Count; i++) { if (!inventory.HaveEmptySlot()) { Print("Нет места в инвентаре"); flag = true; break; } if (definition.Plain) { int j; for (j = 0; j < definition.Stack; j++) { if (inventory.AddItem(definition.BasePrefab, 1, definition.Quality, definition.Variant, 0L, "", false, false) == null) { break; } } if (j < definition.Stack) { Print($"Не удалось создать {definition.BasePrefab}: выдано {j} из {definition.Stack}"); flag = true; break; } } else { ItemData val = inventory.AddItem(definition.BasePrefab, 1, definition.Quality, definition.Variant, 0L, "", false, false); if (val == null) { Print("Не удалось создать " + definition.BasePrefab); flag = true; break; } val.m_customData["sansara.EventRewards.id"] = definition.Id; DurabilityScale.FillToMax(val); } } if (i > 0) { list3.Add($"{definition.Name} × {i}"); } if (flag) { break; } } RewardState.MarkDirty(); Print("Выдано: " + ((list3.Count > 0) ? string.Join(", ", list3) : "ничего")); } private static void Revoke(string[] args) { RevokeRequest revokeRequest = RevokeCommand.ParseRevoke(args.Skip(1).ToList()); if (!revokeRequest.Ok) { Print(revokeRequest.Error); } else if (revokeRequest.Action == RevokeAction.List) { Remote("revoke", "list", "", "0.5.14"); } else { Remote("revoke", revokeRequest.IdList, revokeRequest.Target, "0.5.14"); } } private static void Unrevoke(string[] args) { RevokeRequest revokeRequest = RevokeCommand.ParseUnrevoke(args.Skip(1).ToList()); if (!revokeRequest.Ok) { Print(revokeRequest.Error); } else { Remote("unrevoke", "#" + revokeRequest.N, "", "0.5.14"); } } private static void Reload() { if ((Object)(object)ZNet.instance == (Object)null) { Print("Нет подключения к миру"); } else if (ZNet.instance.IsServer()) { Print("eventreward reload: " + ServerCatalog.Reload()); RewardNetwork.BroadcastCatalog(); } else if (!SynchronizationManager.Instance.PlayerIsAdmin) { Print("Отказано: нужны права администратора"); } else if (!ModCompatibility.IsModuleOnServer("sansara.EventRewards")) { Print("На сервере нет мода Event Rewards"); } else if (!RewardNetwork.RequestReload()) { Print("Нет подключения к серверу"); } else { Print("Запрос отправлен на сервер"); } } private static void Remote(string sub, string arg1, string arg2, string minServer = "0.5.11") { if ((Object)(object)ZNet.instance == (Object)null) { Print("Нет подключения к миру"); } else if (ZNet.instance.IsServer()) { Print(DeliveryServer.HandleCommand(sub, arg1, arg2)); } else if (!SynchronizationManager.Instance.PlayerIsAdmin) { Print("Отказано: нужны права администратора"); } else if (!ModCompatibility.IsModuleOnServer("sansara.EventRewards")) { Print("На сервере нет мода Event Rewards"); } else if (!RewardNetwork.RequestDelivery(sub, arg1, arg2)) { Print("Нет подключения к серверу"); } else { Print("Запрос отправлен на сервер (нужен Event Rewards " + minServer + " или новее на сервере)"); } } internal static void Print(string text) { if ((Object)(object)Console.instance != (Object)null) { Console.instance.Print(text); } } } public static class ExternalRewards { public static string Enqueue(long playerId, string rewardId, string reason) { if (!DeliveryServer.Running) { return "очередь доставки Event Rewards не работает"; } string text = DeliveryReason.ExternalError(reason); if (text != null) { return text; } if (!ServerCatalog.Current.TryGet(rewardId, out var _)) { return "награды " + rewardId + " нет в наборе сервера"; } return DeliveryServer.EnqueueExternal(playerId, rewardId, reason); } public static string DropAt(Vector3 position, string rewardId, string reason) { //IL_0053: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)ZNet.instance == (Object)null || !ZNet.instance.IsServer() || ZDOMan.instance == null) { return "не сервер или мир не загружен"; } string text = DeliveryReason.ExternalError(reason); if (text != null) { return text; } if (!ServerCatalog.Current.TryGet(rewardId, out var definition)) { return "награды " + rewardId + " нет в наборе сервера"; } return DeliveryServer.DropExternal(definition, position, reason); } public static ItemData CreateItem(string rewardId, out string error) { if ((Object)(object)ZNet.instance == (Object)null || !ZNet.instance.IsServer() || (Object)(object)ObjectDB.instance == (Object)null) { error = "не сервер или мир не загружен"; return null; } if (!ServerCatalog.Current.TryGet(rewardId, out var definition)) { error = "награды " + rewardId + " нет в наборе сервера"; return null; } return DeliveryServer.CreateExternal(definition, out error); } } internal sealed class HuntCommand : ConsoleCommand { private static readonly List<string> Subcommands = new List<string> { "setchest", "start", "stop", "status" }; public override string Name => "eventhunt"; public override string Help => "setchest | start | stop | status (ивент «Охота», только администратор)"; public override List<string> CommandOptionList() { return Subcommands; } public override void Run(string[] args) { //IL_0044: Unknown result type (might be due to invalid IL or missing references) //IL_0049: Unknown result type (might be due to invalid IL or missing references) //IL_0078: 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) string text = ((args.Length != 0) ? args[0].ToLowerInvariant() : ""); if (!Subcommands.Contains(text)) { Print("Использование: eventhunt setchest | start | stop | status"); return; } if ((Object)(object)ZNet.instance == (Object)null) { Print("Нет подключения к миру"); return; } ZDOID id = ZDOID.None; if (text == "setchest" && !TryGetHoveredContainer(out id)) { Print("eventhunt setchest: наведите курсор на сундук"); } else if (ZNet.instance.IsServer()) { Print(HuntServer.HandleCommand(text, id)); } else if (!SynchronizationManager.Instance.PlayerIsAdmin) { Print("Отказано: нужны права администратора"); } else if (!ModCompatibility.IsModuleOnServer("sansara.EventRewards")) { Print("На сервере нет мода Event Rewards"); } else if (!RewardNetwork.RequestHunt(text, id)) { Print("Нет подключения к серверу"); } else { Print("Запрос отправлен на сервер (нужен Event Rewards 0.5.1 или новее на сервере)"); } } private static bool TryGetHoveredContainer(out ZDOID id) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_0064: Unknown result type (might be due to invalid IL or missing references) //IL_0069: Unknown result type (might be due to invalid IL or missing references) id = ZDOID.None; GameObject val = (((Object)(object)Player.m_localPlayer != (Object)null) ? ((Humanoid)Player.m_localPlayer).GetHoverObject() : null); if ((Object)(object)val == (Object)null) { return false; } Container componentInParent = val.GetComponentInParent<Container>(); if ((Object)(object)componentInParent == (Object)null) { return false; } ZNetView componentInParent2 = ((Component)componentInParent).GetComponentInParent<ZNetView>(); if ((Object)(object)componentInParent2 == (Object)null || !componentInParent2.IsValid()) { return false; } id = componentInParent2.GetZDO().m_uid; return true; } private static void Print(string text) { if ((Object)(object)Console.instance != (Object)null) { Console.instance.Print(text); } } } internal static class HuntServer { private const int StatusDecreases = 5; public static bool Watching; public static ZDOID ChestId = ZDOID.None; private static bool _running; private static string _loadError; private static HuntSettings _settings; private static HuntState _state; private static int _trophyHash; private static uint _lastRevision; private static bool _haveRevision; private static float _timer; private static bool _missingChestWarned; private static bool _oldFormatWarned; private static readonly ItemData Scratch = new ItemData(); private static readonly List<ZDO> SearchBuffer = new List<ZDO>(); private const float ChestMatchDistance = 0.5f; public static string SettingsPath => Path.Combine(Paths.ConfigPath, "sansara.EventRewards.hunt.json"); public static string StatePath => Path.Combine(Paths.ConfigPath, "sansara.EventRewards.hunt.state.json"); public static void Init() { Shutdown(); if ((Object)(object)ZNet.instance == (Object)null || !ZNet.instance.IsServer()) { return; } _running = true; if (!LoadSettings(out var error)) { _loadError = error; Plugin.Log.LogError((object)("Event Hunt: " + error)); return; } if (!LoadState(out error)) { _loadError = error; Plugin.Log.LogError((object)("Event Hunt: " + error)); return; } UpdateWatch(); Plugin.Log.LogInfo((object)("Event Hunt: id " + _state.Id + ", " + (_state.Active ? "идёт" : "не запущен") + ", " + string.Format("прогресс {0} / {1}, сундук {2}", _state.Best, _settings.Goal, (_state.Chest != null) ? "задан" : "не задан") + (_settings.AutoDeliver ? (", автовыдача " + _settings.RewardId) : ""))); if (DeliveryServer.EnqueueHunt(_state, _settings)) { Save(); } } public static void Shutdown() { //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_0011: Unknown result type (might be due to invalid IL or missing references) _running = false; Watching = false; ChestId = ZDOID.None; _settings = null; _state = null; _loadError = null; _haveRevision = false; _timer = 0f; _missingChestWarned = false; _oldFormatWarned = false; } public static void Tick(float deltaTime) { if (!Watching) { return; } _timer += deltaTime; if (_timer < _settings.CheckIntervalSeconds) { return; } _timer = 0f; try { Check(null); } catch (Exception ex) { Plugin.Log.LogWarning((object)("Event Hunt: ошибка проверки сундука: " + ex)); } } public static void OnChestData(ZDO zdo) { try { Check(zdo); } catch (Exception ex) { Plugin.Log.LogWarning((object)("Event Hunt: ошибка разбора данных сундука: " + ex)); } } private static void Check(ZDO zdo) { if (zdo == null) { zdo = ResolveChest(); } if (zdo == null) { if (!_missingChestWarned) { Plugin.Log.LogWarning((object)$"Event Hunt: сундук {_state.Chest.Prefab} ({_state.Chest.X:0.0}, {_state.Chest.Y:0.0}, {_state.Chest.Z:0.0}) не найден (разрушен?)"); } _missingChestWarned = true; return; } _missingChestWarned = false; if (_haveRevision && zdo.DataRevision == _lastRevision) { return; } _lastRevision = zdo.DataRevision; _haveRevision = true; if (!TryCount(zdo, out var count)) { return; } long playerId; string host; string text = ResolvePlayer(zdo.GetOwner(), out playerId, out host); int lastCount = _state.LastCount; HuntUpdateResult huntUpdateResult = HuntTracker.Update(_state, count, text, _settings.Goal, DateTime.UtcNow, playerId, host); if (huntUpdateResult.Changed) { Plugin.Log.LogInfo((object)$"Event Hunt: в сундуке {count} ({count - lastCount:+#;-#;0}), игрок {text}, прогресс {_state.Best} / {_settings.Goal}"); Save(); if (huntUpdateResult.GoalReached) { Announce(HuntText.Format(_settings.VictoryMessage, _state.Best, _settings.Goal)); Plugin.Log.LogInfo((object)"Event Hunt: цель достигнута"); } else if (huntUpdateResult.ProgressIncreased) { Announce(HuntText.Format(_settings.ProgressMessage, _state.Best, _settings.Goal)); } if (_state.Completed && DeliveryServer.EnqueueHunt(_state, _settings)) { Save(); } } } private static bool TryCount(ZDO zdo, out int count) { //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_001d: Expected O, but got Unknown count = 0; byte[] byteArray = zdo.GetByteArray(ZDOVars.s_items, (byte[])null); if (byteArray == null) { return true; } try { ZPackage val = new ZPackage(byteArray); int num = val.ReadInt(); if (num < 108) { if (!_oldFormatWarned) { Plugin.Log.LogWarning((object)$"Event Hunt: сундук в старом формате {num}, считаю 0"); } _oldFormatWarned = true; return true; } int num2 = val.ReadUShort(); for (int i = 0; i < num2; i++) { if (HuntCounter.Matches(ItemData.Load(val, Scratch, (Item)num), Scratch.m_quality, Scratch.m_worldLevel, Scratch.m_customData, _trophyHash, _settings.TrophyQuality, _settings.TrophyWorldLevel, _state.Id)) { count += Scratch.m_stack; } } return true; } catch (Exception ex) { Plugin.Log.LogWarning((object)("Event Hunt: содержимое сундука не прочитано: " + ex.Message)); return false; } } private static string ResolvePlayer(long owner, out long playerId, out string host) { playerId = 0L; host = ""; if (owner == 0L || owner == ZDOMan.GetSessionID()) { return "неизвестно"; } ZNet instance = ZNet.instance; ZNetPeer val = ((instance != null) ? instance.GetPeer(owner) : null); if (val == null) { return "неизвестно"; } playerId = DeliveryServer.PlayerIdOf(val); host = DeliveryServer.HostOf(val); if (string.IsNullOrWhiteSpace(val.m_playerName)) { return "неизвестно"; } return val.m_playerName; } private static void Announce(string text) { if (!string.IsNullOrEmpty(text)) { Plugin.Log.LogInfo((object)("Event Hunt: объявление: " + text)); ZRoutedRpc instance = ZRoutedRpc.instance; if (instance != null) { instance.InvokeRoutedRPC(0L, "ShowMessage", new object[2] { 2, text }); } } } public static string HandleCommand(string sub, ZDOID target) { //IL_0043: Unknown result type (might be due to invalid IL or missing references) if (!_running) { return "eventhunt: модуль работает только на сервере"; } return sub switch { "setchest" => SetChest(target), "start" => Start(), "stop" => Stop(), "status" => Status(), _ => "eventhunt: неизвестная команда '" + sub + "'", }; } private static string SetChest(ZDOID target) { //IL_0046: Unknown result type (might be due to invalid IL or missing references) //IL_00d8: Unknown result type (might be due to invalid IL or missing references) //IL_00dd: Unknown result type (might be due to invalid IL or missing references) //IL_010f: Unknown result type (might be due to invalid IL or missing references) //IL_011b: Unknown result type (might be due to invalid IL or missing references) //IL_0127: Unknown result type (might be due to invalid IL or missing references) //IL_0160: Unknown result type (might be due to invalid IL or missing references) //IL_016e: Unknown result type (might be due to invalid IL or missing references) //IL_017c: Unknown result type (might be due to invalid IL or missing references) if (_state == null) { return "eventhunt setchest: " + (_loadError ?? "состояние не загружено"); } if (_state.Active) { return "eventhunt setchest: ивент идёт, сначала eventhunt stop"; } if (((ZDOID)(ref target)).IsNone()) { return "eventhunt setchest: наведите курсор на сундук"; } ZDO zDO = ZDOMan.instance.GetZDO(target); if (zDO == null) { return "eventhunt setchest: объект не найден на сервере"; } GameObject val = (((Object)(object)ZNetScene.instance != (Object)null) ? ZNetScene.instance.GetPrefab(zDO.GetPrefab()) : null); if ((Object)(object)val == (Object)null || (Object)(object)val.GetComponentInChildren<Container>(true) == (Object)null) { return "eventhunt setchest: это не контейнер"; } if ((Object)(object)val.GetComponentInChildren<Vagon>(true) != (Object)null || (Object)(object)val.GetComponentInChildren<Ship>(true) != (Object)null || (Object)(object)val.GetComponent<ZSyncTransform>() != (Object)null) { return "eventhunt setchest: " + ((Object)val).name + " передвигается (телега, корабль), нужен неподвижный сундук"; } Vector3 position = zDO.GetPosition(); _state.Chest = new HuntChest { UserId = ((ZDOID)(ref target)).UserID, Id = ((ZDOID)(ref target)).ID, Prefab = ((Object)val).name, X = position.x, Y = position.y, Z = position.z }; UpdateWatch(); Save(); TryCount(zDO, out var count); return $"eventhunt setchest: сундук {((Object)val).name} ({position.x:0}, {position.y:0}, {position.z:0}) задан, засчитываемых трофеев в нём: {count}"; } private static string Start() { if (_state == null) { return "eventhunt start: " + (_loadError ?? "состояние не загружено"); } if (_state.Active) { return "eventhunt start: ивент уже идёт"; } if (!LoadSettings(out var error)) { return "eventhunt start: " + error + " (прежние настройки оставлены)"; } if (_state.Id != _settings.Id) { SwitchEvent(); } if (_state.Chest == null) { return "eventhunt start: сначала eventhunt setchest"; } ZDO val = ResolveChest(); if (val == null) { return "eventhunt start: сундук не найден на сервере, задайте его заново"; } if (!TryCount(val, out var count)) { return "eventhunt start: содержимое сундука не прочитано"; } HuntTracker.Start(_state, count, DateTime.UtcNow); bool flag = HuntTracker.CheckGoal(_state, _settings.Goal); _lastRevision = val.DataRevision; _haveRevision = true; UpdateWatch(); Save(); Plugin.Log.LogInfo((object)$"Event Hunt: запущен {_state.Id}, в сундуке {count}, прогресс {_state.Best} / {_settings.Goal}"); Announce(HuntText.Format(_settings.StartMessage, _state.Best, _settings.Goal)); if (flag) { Announce(HuntText.Format(_settings.VictoryMessage, _state.Best, _settings.Goal)); Plugin.Log.LogInfo((object)"Event Hunt: цель достигнута"); } if (DeliveryServer.EnqueueHunt(_state, _settings)) { Save(); } return $"eventhunt start: ивент {_state.Id} идёт; в сундуке {count}, прогресс {_state.Best} / {_settings.Goal}" + ((count > 0) ? " (уже лежавшие трофеи записаны на «неизвестно»)" : "") + (flag ? "; цель уже достигнута, объявлена победа" : ""); } private static string Stop() { if (_state == null) { return "eventhunt stop: " + (_loadError ?? "состояние не загружено"); } if (!_state.Active) { return "eventhunt stop: ивент не запущен"; } HuntTracker.Stop(_state); UpdateWatch(); Save(); if (!_state.Completed) { Announce(HuntText.Format(_settings.StopMessage, _state.Best, _settings.Goal)); } Plugin.Log.LogInfo((object)$"Event Hunt: остановлен {_state.Id}, прогресс {_state.Best} / {_settings.Goal}"); return $"eventhunt stop: ивент {_state.Id} остановлен, прогресс {_state.Best} / {_settings.Goal}"; } private static string Status() { if (_state == null || _settings == null) { return "eventhunt status: " + (_loadError ?? "состояние не загружено"); } StringBuilder stringBuilder = new StringBuilder(); stringBuilder.Append("Ивент " + _state.Id + ": " + (_state.Active ? "идёт" : "остановлен") + (_state.Completed ? ", цель достигнута" : "")); stringBuilder.Append($"\nПрогресс (максимум): {_state.Best} / {_settings.Goal}, сейчас в сундуке: {_state.LastCount}"); stringBuilder.Append(string.Format("\nТрофей: {0}, уровень {1}, уровень мира {2}, метка {3}={4}", _settings.TrophyPrefab, _settings.TrophyQuality, _settings.TrophyWorldLevel, "sansara.EventHunt.id", _state.Id)); if (_settings.Id != _state.Id) { stringBuilder.Append("\nВ настройках уже id " + _settings.Id + ": он начнётся после eventhunt stop и eventhunt start"); } if (_state.Chest == null) { stringBuilder.Append("\nСундук: не задан"); } else { bool flag = ResolveChest() != null; stringBuilder.Append(string.Format("\nСундук: {0} ({1:0}, {2:0}, {3:0}){4}", _state.Chest.Prefab, _state.Chest.X, _state.Chest.Y, _state.Chest.Z, flag ? "" : " — НЕ НАЙДЕН")); } List<KeyValuePair<string, int>> list = HuntTracker.Participants(_state); stringBuilder.Append($"\nУчастники ({list.Count}):"); foreach (KeyValuePair<string, int> item in list) { stringBuilder.Append($"\n {item.Key}: {item.Value}"); } stringBuilder.Append("\nАвтовыдача: " + (_settings.AutoDeliver ? "включена" : "выключена") + ", награда " + _settings.RewardId + ((_settings.AutoDeliver && !_state.Completed) ? " (после победы)" : "")); List<KeyValuePair<long, HuntPlayer>> list2 = HuntDelivery.Recipients(_state); if (list2.Count > 0) { stringBuilder.Append($"\nПо персонажам ({list2.Count}):"); foreach (KeyValuePair<long, HuntPlayer> item2 in list2) { string text = DeliveryServer.DescribeHuntRecipient(item2.Key, _state.Id); stringBuilder.Append(string.Format("\n {0}: {1}{2}", item2.Value.Name, item2.Value.Count, (text.Length > 0) ? (" — " + text) : "")); } } List<KeyValuePair<string, int>> list3 = HuntDelivery.ManualOnly(_state); if (list3.Count > 0) { stringBuilder.Append("\nБез ID персонажа (вклад до 0.5.11, выдать вручную " + _settings.RewardId + "):"); foreach (KeyValuePair<string, int> item3 in list3) { stringBuilder.Append($"\n {item3.Key}: {item3.Value}"); } } List<HuntLogEntry> list4 = HuntTracker.LastDecreases(_state, 5); if (list4.Count > 0) { stringBuilder.Append("\nПоследние уменьшения (UTC):"); foreach (HuntLogEntry item4 in list4) { stringBuilder.Append($"\n {item4.Time:yyyy-MM-dd HH:mm:ss} {item4.Delta} (стало {item4.Count}), {item4.Player}"); } } return stringBuilder.ToString(); } private static bool LoadSettings(out string error) { error = null; try { if (!File.Exists(SettingsPath)) { WriteFile(SettingsPath, HuntSettingsJson.Serialize(HuntSettings.Default())); Plugin.Log.LogInfo((object)("Event Hunt: создан файл настроек по умолчанию " + SettingsPath)); } HuntSettingsResult huntSettingsResult = HuntSettingsJson.Parse(File.ReadAllText(SettingsPath)); foreach (string warning in huntSettingsResult.Warnings) { Plugin.Log.LogWarning((object)("Event Hunt: " + warning)); } if (!huntSettingsResult.Success) { error = "настройки " + SettingsPath + " не приняты: " + huntSettingsResult.Errors[0]; return false; } _settings = huntSettingsResult.Settings; _trophyHash = StringExtensionMethods.GetStableHashCode(_settings.TrophyPrefab); if ((Object)(object)ObjectDB.instance != (Object)null && (Object)(object)ObjectDB.instance.GetItemPrefab(_settings.TrophyPrefab) == (Object)null) { Plugin.Log.LogWarning((object)("Event Hunt: предмет " + _settings.TrophyPrefab + " не найден в ObjectDB")); } return true; } catch (Exception ex) { error = "настройки " + SettingsPath + " не прочитаны: " + ex.Message; return false; } } private static bool LoadState(out string error) { error = null; try { if (!File.Exists(StatePath)) { _state = HuntState.New(_settings.Id); return true; } HuntStateResult huntStateResult = HuntStateJson.Parse(File.ReadAllText(StatePath)); if (!huntStateResult.Success) { error = "состояние " + StatePath + " не прочитано: " + huntStateResult.Errors[0] + "; модуль отключён до исправления файла"; return false; } _state = huntStateResult.State; if (_state.Id != _settings.Id) { if (_state.Active) { Plugin.Log.LogWarning((object)("Event Hunt: в настройках id " + _settings.Id + ", а идёт " + _state.Id + "; ивент продолжается до eventhunt stop")); } else { SwitchEvent(); } } return true; } catch (Exception ex) { error = "состояние " + StatePath + " не прочитано: " + ex.Message; return false; } } private static void SwitchEvent() { if (File.Exists(StatePath)) { string text = Path.Combine(Paths.ConfigPath, "sansara.EventRewards.hunt.state." + _state.Id + ".json"); int num = 2; while (File.Exists(text)) { text = Path.Combine(Paths.ConfigPath, $"sansara.EventRewards.hunt.state.{_state.Id}.{num}.json"); num++; } File.Copy(StatePath, text, overwrite: false); Plugin.Log.LogInfo((object)("Event Hunt: новый ивент " + _settings.Id + "; состояние " + _state.Id + " сохранено в " + text)); } else { Plugin.Log.LogInfo((object)("Event Hunt: новый ивент " + _settings.Id + " (файла состояния " + _state.Id + " не было)")); } HuntChest chest = _state.Chest; _state = HuntState.New(_settings.Id); _state.Chest = chest; Save(); } private static void Save() { try { WriteFile(StatePath, HuntStateJson.Serialize(_state)); } catch (Exception ex) { Plugin.Log.LogError((object)("Event Hunt: состояние не сохранено в " + StatePath + ": " + ex.Message)); } } private static void WriteFile(string path, string text) { ServerFiles.WriteAtomic(path, text); } private static ZDO ResolveChest() { //IL_0054: Unknown result type (might be due to invalid IL or missing references) //IL_00a5: 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_00ae: Unknown result type (might be due to invalid IL or missing references) //IL_006f: Unknown result type (might be due to invalid IL or missing references) //IL_0074: Unknown result type (might be due to invalid IL or missing references) //IL_0075: Unknown result type (might be due to invalid IL or missing references) //IL_007a: Unknown result type (might be due to invalid IL or missing references) //IL_00e1: Unknown result type (might be due to invalid IL or missing references) //IL_00e6: Unknown result type (might be due to invalid IL or missing references) //IL_00e7: Unknown result type (might be due to invalid IL or missing references) //IL_00ec: Unknown result type (might be due to invalid IL or missing references) //IL_0130: Unknown result type (might be due to invalid IL or missing references) //IL_0135: Unknown result type (might be due to invalid IL or missing references) //IL_0199: Unknown result type (might be due to invalid IL or missing references) HuntChest huntChest = _state?.Chest; if (huntChest == null || ZDOMan.instance == null) { return null; } int stableHashCode = StringExtensionMethods.GetStableHashCode(huntChest.Prefab); Vector3 val = default(Vector3); ((Vector3)(ref val))..ctor(huntChest.X, huntChest.Y, huntChest.Z); ZDO val2 = (((ZDOID)(ref ChestId)).IsNone() ? null : ZDOMan.instance.GetZDO(ChestId)); Vector3 val3; if (val2 != null && val2.GetPrefab() == stableHashCode) { val3 = val2.GetPosition() - val; if (((Vector3)(ref val3)).sqrMagnitude <= 0.25f) { return val2; } } ZDO val4 = null; float num = 0.25f; SearchBuffer.Clear(); ZDOMan.instance.FindSectorObjects(ZoneSystem.GetZone(val), new SimulationDistance(1, 0, true), SearchBuffer, (List<ZDO>)null); foreach (ZDO item in SearchBuffer) { if (item.GetPrefab() == stableHashCode) { val3 = item.GetPosition() - val; float sqrMagnitude = ((Vector3)(ref val3)).sqrMagnitude; if (sqrMagnitude <= num) { val4 = item; num = sqrMagnitude; } } } SearchBuffer.Clear(); if (val4 == null) { return null; } ChestId = val4.m_uid; _haveRevision = false; if (huntChest.UserId != ((ZDOID)(ref ChestId)).UserID || huntChest.Id != ((ZDOID)(ref ChestId)).ID) { huntChest.UserId = ((ZDOID)(ref ChestId)).UserID; huntChest.Id = ((ZDOID)(ref ChestId)).ID; Save(); } Plugin.Log.LogInfo((object)$"Event Hunt: сундук {huntChest.Prefab} найден, ZDOID {ChestId}"); return val4; } private static ZDOID ChestFromState() { //IL_0037: Unknown result type (might be due to invalid IL or missing references) //IL_0031: Unknown result type (might be due to invalid IL or missing references) if (_state?.Chest != null) { return new ZDOID(_state.Chest.UserId, _state.Chest.Id); } return ZDOID.None; } private static void UpdateWatch() { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_002b: Unknown result type (might be due to invalid IL or missing references) //IL_0030: Unknown result type (might be due to invalid IL or missing references) ChestId = ChestFromState(); if (_running && _state?.Chest != null && ResolveChest() == null) { ChestId = ZDOID.None; } Watching = _running && _settings != null && _state != null && _state.Active && _state.Chest != null; _timer = 0f; if (!Watching) { _haveRevision = false; } } } internal static class PieceRewards { private struct Dome { public ShieldGenerator Generator; public Vector3 Center; public float Radius; } public static readonly int KeyHash = StringExtensionMethods.GetStableHashCode("sansara.EventRewards.piece"); private static readonly FieldRef<List<ShieldGenerator>> Instances = AccessTools.StaticFieldRefAccess<List<ShieldGenerator>>(AccessTools.Field(typeof(ShieldGenerator), "m_instances")); private static readonly FieldRef<ShieldGenerator, float> Radius = AccessTools.FieldRefAccess<ShieldGenerator, float>("m_radius"); private static readonly List<Dome> Domes = new List<Dome>(); private static int _domesFrame = -1; private static readonly Dictionary<ShieldGenerator, EffectArea> Areas = new Dictionary<ShieldGenerator, EffectArea>(); public static bool TryGet(ZDO zdo, out RewardDefinition def) { def = null; if (zdo == null || !PluginConfig.Enabled.Value) { return false; } string text = zdo.GetString(KeyHash, ""); if (text.Length == 0 || RevocationClient.IsRevoked(text)) { return false; } if (!(((Object)(object)ZNet.instance != (Object)null && ZNet.instance.IsDedicated()) ? ServerCatalog.Current : RewardState.Catalog).TryGet(text, out def) || !PieceReward.IsPiece(def)) { def = null; return false; } return true; } public static bool TryGet(Component c, out RewardDefinition def) { def = null; if ((Object)(object)c == (Object)null) { return false; } ZNetView component = c.GetComponent<ZNetView>(); if ((Object)(object)component != (Object)null && component.IsValid()) { return TryGet(component.GetZDO(), out def); } return false; } public static bool RaidCovers(Vector3 center) { //IL_001e: 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) RandomEvent val = (((Object)(object)RandEventSystem.instance != (Object)null) ? RandEventSystem.instance.GetCurrentRandomEvent() : null); if (val != null) { return PieceReward.RaidCovers(Utils.DistanceXZ(center, val.m_pos), val.m_eventRange); } return false; } private static List<Dome> LiveDomes() { //IL_009c: Unknown result type (might be due to invalid IL or missing references) //IL_00a1: Unknown result type (might be due to invalid IL or missing references) //IL_00a3: 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_00c5: Unknown result type (might be due to invalid IL or missing references) int frameCount = Time.frameCount; if (frameCount == _domesFrame) { return Domes; } _domesFrame = frameCount; Domes.Clear(); List<ShieldGenerator> list = Instances.Invoke(); if (list == null) { return Domes; } for (int i = 0; i < list.Count; i++) { ShieldGenerator val = list[i]; if ((Object)(object)val == (Object)null || (Object)(object)val.m_shieldDome == (Object)null) { continue; } float num = Radius.Invoke(val); if (num > 0f && TryGet((Component)(object)val, out var def) && def.Bonuses.CalmDome) { Vector3 position = val.m_shieldDome.transform.position; if (!RaidCovers(position)) { Domes.Add(new Dome { Generator = val, Center = position, Radius = num }); } } } return Domes; } public static EffectArea Find(Vector3 p, bool close) { //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) List<Dome> list = LiveDomes(); for (int i = 0; i < list.Count; i++) { Dome d = list[i]; if (PieceReward.InDome(Vector3.Distance(d.Center, p), d.Radius, close)) { return AreaOf(d); } } return null; } private static EffectArea AreaOf(Dome d) { //IL_0035: Unknown result type (might be due to invalid IL or missing references) //IL_003a: Unknown result type (might be due to invalid IL or missing references) //IL_0041: 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_007d: Unknown result type (might be due to invalid IL or missing references) if (!Areas.TryGetValue(d.Generator, out var value) || (Object)(object)value == (Object)null) { if (Areas.Count > 64) { Prune(); } GameObject val = new GameObject("sansara.EventRewards.CalmDome"); val.SetActive(false); val.transform.SetParent(((Component)d.Generator).transform, false); value = val.AddComponent<EffectArea>(); value.m_type = (Type)0; Areas[d.Generator] = value; } ((Component)value).transform.position = d.Center; return value; } private static void Prune() { List<ShieldGenerator> list = new List<ShieldGenerator>(); foreach (KeyValuePair<ShieldGenerator, EffectArea> area in Areas) { if ((Object)(object)area.Key == (Object)null || (Object)(object)area.Value == (Object)null) { list.Add(area.Key); } } foreach (ShieldGenerator item in list) { Areas.Remove(item); } } public static void Command(string arg, Action<string> print) { //IL_0198: Unknown result type (might be due to invalid IL or missing references) //IL_025a: Unknown result type (might be due to invalid IL or missing references) Player localPlayer = Player.m_localPlayer; if ((Object)(object)localPlayer == (Object)null) { print("Нет персонажа"); return; } GameObject hoverObject = ((Humanoid)localPlayer).GetHoverObject(); ShieldGenerator val = (((Object)(object)hoverObject != (Object)null) ? hoverObject.GetComponentInParent<ShieldGenerator>() : null); ZNetView val2 = (((Object)(object)val != (Object)null) ? ((Component)val).GetComponent<ZNetView>() : null); if ((Object)(object)val2 == (Object)null || !val2.IsValid()) { print("Наведите взгляд на щитовой генератор. eventreward piece <id> | piece clear | piece (глядя на постройку)"); return; } ZDO zDO = val2.GetZDO(); string text = zDO.GetString(KeyHash, ""); string prefabName = Utils.GetPrefabName(((Component)val).gameObject); if (arg.Length == 0) { if (text.Length == 0) { print(prefabName + ": не наградная постройка"); return; } RewardDefinition definition; string text2 = (RewardState.Catalog.TryGet(text, out definition) ? definition.Name : "нет в наборе"); print(prefabName + ": награда " + text + " (" + text2 + ")"); return; } if (!SynchronizationManager.Instance.PlayerIsAdmin) { print("Отказано: нужны права администратора"); return; } if (arg.Equals("clear", StringComparison.OrdinalIgnoreCase)) { if (text.Length == 0) { print(prefabName + ": не наградная постройка"); return; } val2.ClaimOwnership(); zDO.Set(KeyHash, ""); print(prefabName + ": награда " + text + " снята"); Plugin.Log.LogInfo((object)$"Постройка {prefabName} {zDO.m_uid}: награда {text} снята администратором {localPlayer.GetPlayerName()}"); return; } string text3 = PieceReward.ValidateTag(arg, PieceReward.IsPiecePrefab(prefabName) ? prefabName : null, RewardState.Catalog); if (text3 != null) { print(text3); return; } val2.ClaimOwnership(); zDO.Set(KeyHash, arg); RewardState.Catalog.TryGet(arg, out var definition2); print(prefabName + ": теперь «" + definition2.Name + "» (" + arg + "). Действует у игроков с модом 0.5.18+, пока горит купол"); Plugin.Log.LogInfo((object)$"Постройка {prefabName} {zDO.m_uid}: награда {arg} назначена администратором {localPlayer.GetPlayerName()}"); } } [BepInPlugin("sansara.EventRewards", "Event Rewards", "0.5.31")] [BepInDependency(/*Could not decode attribute arguments.*/)] [BepInDependency(/*Could not decode attribute arguments.*/)] [NetworkCompatibility(/*Could not decode attribute arguments.*/)] public sealed class Plugin : BaseUnityPlugin { public const string Guid = "sansara.EventRewards"; public const string Version = "0.5.31"; internal static ManualLogSource Log; private void Awake() { //IL_001b: 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_003a: Expected O, but got Unknown Log = ((BaseUnityPlugin)this).Logger; PluginConfig.Bind(((BaseUnityPlugin)this).Config); Harmony val = new Harmony("sansara.EventRewards"); val.PatchAll(typeof(Plugin).Assembly); DualWield.PatchShieldMeBruh(val); RewardNetwork.Init(); CommandManager.Instance.AddConsoleCommand((ConsoleCommand)(object)new EventRewardCommand()); CommandManager.Instance.AddConsoleCommand((ConsoleCommand)(object)new HuntCommand()); CustomLocalization localization = LocalizationManager.Instance.GetLocalization(); string text = "Russian"; string text2 = "item_newgameplusitem"; localization.AddTranslation(ref text, ref text2, "Трофей ивента"); Log.LogInfo((object)"Event Rewards 0.5.31 loaded"); } } internal static class PluginConfig { public static ConfigEntry<bool> Enabled; private static ConfigEntry<float> _maxCarryWeight; private static ConfigEntry<float> _maxMoveSpeed; private static ConfigEntry<float> _maxStaminaRegen; private static ConfigEntry<float> _maxRunDrainReduction; private static ConfigEntry<float> _maxHealth; private static ConfigEntry<float> _maxStamina; private static ConfigEntry<float> _maxDamage; private static ConfigEntry<float> _maxBlockPower; private static ConfigEntry<float> _maxDurability; private static ConfigEntry<float> _maxToolTier; public static ConfigEntry<int> MaxQualityAboveBase; private static ConfigEntry<string> _maxResistance; private static ConfigEntry<string> _allowedEffects; private static ConfigEntry<int> _maxAirJumps; private static ConfigEntry<float> _maxEitr; private static ConfigEntry<float> _maxEitrRegen; private static ConfigEntry<float> _maxEitrCostReduction; private static ConfigEntry<float> _maxHealthCostReduction; private static ConfigEntry<float> _maxSkillLevel; private static ConfigEntry<float> _maxSkillGain; private static ConfigEntry<float> _maxDamageSkill; private static ConfigEntry<float> _maxAdrenaline; private static ConfigEntry<float> _maxAdrenalineThresholdReduction; private static ConfigEntry<float> _maxAdrenalineDuration; private static ConfigEntry<float> _maxAdrenalineOnHit; private static ConfigEntry<float> _maxShipSpeed; private static ConfigEntry<float> _maxAdrenalineEffectDuration; private static ConfigEntry<string> _allowedAdrenalineEffects; private static ConfigEntry<float> _maxHealthRegen; private static ConfigEntry<float> _maxFoodStats; private static ConfigEntry<float> _maxFoodDrainReduction; private static ConfigEntry<float> _maxPotionDuration; private static ConfigEntry<float> _maxPotionCooldownReduction; private static ConfigEntry<float> _maxPotionPower; private static ConfigEntry<float> _maxBuildStaminaReduction; private static ConfigEntry<float> _maxBuildRange; private static ConfigEntry<float> _maxArmor; private static ConfigEntry<float> _maxFallDamageReduction; private static ConfigEntry<float> _maxCraftCostReduction; private static ConfigEntry<float> _maxUpgradeCostReduction; private static ConfigEntry<float> _maxAmmoSave; private static ConfigEntry<float> _maxCraftYield; private static ConfigEntry<float> _maxGrappleRange; private static ConfigEntry<float> _maxHullArmor; private static ConfigEntry<float> _maxRudder; private static ConfigEntry<float> _maxRowSpeed; private static ConfigEntry<float> _maxDomeRadius; private static ConfigEntry<float> _maxAddDamage; public static ConfigEntry<bool> AnnounceRewardLoss; public static ConfigEntry<string> RewardLossMessage; public static ConfigEntry<bool> DeliveryEnabled; public static ConfigEntry<float> DeliveryCheckIntervalSeconds; public static ConfigEntry<float> DeliverySettleSeconds; public static ConfigEntry<string> DeliveryMessage; public static ConfigEntry<bool> AnnounceRevocation; public static ConfigEntry<string> RevocationMessage; public static ConfigEntry<float> RevocationRescanMinutes; public static ConfigEntry<string> ShipSpeedPercent; public static ConfigEntry<Vector3> DualLeftPosition; public static ConfigEntry<Vector3> DualLeftRotation; public static ConfigEntry<bool> DualLeftMirror; public static ConfigEntry<Vector3> DualBackPosition; public static ConfigEntry<Vector3> DualBackRotation; public static ConfigEntry<bool> DualBackMirror; private static string _warnedMaxResistance; public static void Bind(ConfigFile cfg) { //IL_0062: Unknown result type (might be due to invalid IL or missing references) //IL_0067: Unknown result type (might be due to invalid IL or missing references) //IL_006f: Expected O, but got Unknown //IL_006f: Unknown result type (might be due to invalid IL or missing references) //IL_0079: Expected O, but got Unknown //IL_00e1: Unknown result type (might be due to invalid IL or missing references) //IL_00eb: Expected O, but got Unknown //IL_010b: Unknown result type (might be due to invalid IL or missing references) //IL_0115: Expected O, but got Unknown //IL_0135: Unknown result type (might be due to invalid IL or missing references) //IL_013f: Expected O, but got Unknown //IL_015f: Unknown result type (might be due to invalid IL or missing references) //IL_0169: Expected O, but got Unknown //IL_0189: Unknown result type (might be due to invalid IL or missing references) //IL_0193: Expected O, but got Unknown //IL_01b3: Unknown result type (might be due to invalid IL or missing references) //IL_01bd: Expected O, but got Unknown //IL_01dd: Unknown result type (might be due to invalid IL or missing references) //IL_01e7: Expected O, but got Unknown //IL_0207: Unknown result type (might be due to invalid IL or missing references) //IL_0211: Expected O, but got Unknown //IL_023f: Unknown result type (might be due to invalid IL or missing references) //IL_0249: Expected O, but got Unknown //IL_026f: Unknown result type (might be due to invalid IL or missing references) //IL_0279: Expected O, but got Unknown //IL_02da: Unknown result type (might be due to invalid IL or missing references) //IL_02e4: Expected O, but got Unknown //IL_0314: Unknown result type (might be due to invalid IL or missing references) //IL_031e: Expected O, but got Unknown //IL_033e: Unknown result type (might be due to invalid IL or missing references) //IL_0348: Expected O, but got Unknown //IL_0368: Unknown result type (might be due to invalid IL or missing references) //IL_0372: Expected O, but got Unknown //IL_0392: Unknown result type (might be due to invalid IL or missing references) //IL_039c: Expected O, but got Unknown //IL_03ca: Unknown result type (might be due to invalid IL or missing references) //IL_03d4: Expected O, but got Unknown //IL_03f4: Unknown result type (might be due to invalid IL or missing references) //IL_03fe: Expected O, but got Unknown //IL_041e: Unknown result type (might be due to invalid IL or missing references) //IL_0428: Expected O, but got Unknown //IL_0448: Unknown result type (might be due to invalid IL or missing references) //IL_0452: Expected O, but got Unknown //IL_0480: Unknown result type (might be due to invalid IL or missing references) //IL_048a: Expected O, but got Unknown //IL_04aa: Unknown result type (might be due to invalid IL or missing references) //IL_04b4: Expected O, but got Unknown //IL_04e2: Unknown result type (might be due to invalid IL or missing references) //IL_04ec: Expected O, but got Unknown //IL_051a: Unknown result type (might be due to invalid IL or missing references) //IL_0524: Expected O, but got Unknown //IL_0552: Unknown result type (might be due to invalid IL or missing references) //IL_055c: Expected O, but got Unknown //IL_05a9: Unknown result type (might be due to invalid IL or missing references) //IL_05b3: Expected O, but got Unknown //IL_05e1: Unknown result type (might be due to invalid IL or missing references) //IL_05eb: Expected O, but got Unknown //IL_0619: Unknown result type (might be due to invalid IL or missing references) //IL_0623: Expected O, but got Unknown //IL_0651: Unknown result type (might be due to invalid IL or missing references) //IL_065b: Expected O, but got Unknown //IL_0689: Unknown result type (might be due to invalid IL or missing references) //IL_0693: Expected O, but got Unknown //IL_06c1: Unknown result type (might be due to invalid IL or missing references) //IL_06cb: Expected O, but got Unknown //IL_06f9: Unknown result type (might be due to invalid IL or missing references) //IL_0703: Expected O, but got Unknown //IL_0731: Unknown result type (might be due to invalid IL or missing references) //IL_073b: Expected O, but got Unknown //IL_075b: Unknown result type (might be due to invalid IL or missing references) //IL_0765: Expected O, but got Unknown //IL_0785: Unknown result type (might be due to invalid IL or missing references) //IL_078f: Expected O, but got Unknown //IL_07bd: Unknown result type (might be due to invalid IL or missing references) //IL_07c7: Expected O, but got Unknown //IL_07f5: Unknown result type (might be due to invalid IL or missing references) //IL_07ff: Expected O, but got Unknown //IL_082d: Unknown result type (might be due to invalid IL or missing references) //IL_0837: Expected O, but got Unknown //IL_0865: Unknown result type (might be due to invalid IL or missing references) //IL_086f: Expected O, but got Unknown //IL_089d: Unknown result type (might be due to invalid IL or missing references) //IL_08a7: Expected O, but got Unknown //IL_08d5: Unknown result type (might be due to invalid IL or missing references) //IL_08df: Expected O, but got Unknown //IL_090d: Unknown result type (might be due to invalid IL or missing references) //IL_0917: Expected O, but got Unknown //IL_0945: Unknown result type (might be due to invalid IL or missing references) //IL_094f: Expected O, but got Unknown //IL_097d: Unknown result type (might be due to invalid IL or missing references) //IL_0987: Expected O, but got Unknown //IL_09b5: Unknown result type (might be due to invalid IL or missing references) //IL_09bf: Expected O, but got Unknown //IL_09ed: Unknown result type (might be due to invalid IL or missing references) //IL_09f7: Expected O, but got Unknown //IL_0a99: Unknown result type (might be due to invalid IL or missing references) //IL_0aa3: Expected O, but got Unknown //IL_0aec: Unknown result type (might be due to invalid IL or missing references) //IL_0af6: Expected O, but got Unknown //IL_0b24: Unknown result type (might be due to invalid IL or missing references) //IL_0b2e: Expected O, but got Unknown //IL_0b5d: Unknown result type (might be due to invalid IL or missing references) //IL_0b7c: Unknown result type (might be due to invalid IL or missing references) //IL_0bc5: Unknown result type (might be due to invalid IL or missing references) //IL_0bf3: Unknown result type (might be due to invalid IL or missing references) Enabled = cfg.Bind<bool>("General", "Enabled", true, "Включает бонусы и подсказки наград на этом клиенте. Предметы с меткой остаются ванильными при false."); Enabled.SettingChanged += delegate { RewardState.MarkDirty(); }; ShipSpeedPercent = cfg.Bind<string>("Ships (server)", "ShipSpeedPercent", "", new ConfigDescription("Прибавка к максимальной скорости кораблей для всех, % по имени префаба: «Karve:25» или «Karve:25, VikingShip:10» (Karve — карви, VikingShip — длинный корабль, VikingShip_Ashlands — драккар). Предел записи 50. Перемножается с наградным shipSpeed. Значение сервера передаётся клиентам с модом; действует, когда у рулевого (владельца корабля) стоит мод 0.5.16+, иначе корабль идёт с обычной скоростью. Пусто — выключено.", (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes { IsAdminOnly = true } })); ShipSpeedPercent.SettingChanged += delegate { ShipSpeed.RebuildPrefabTable(ShipSpeedPercent.Value); }; ShipSpeed.RebuildPrefabTable(ShipSpeedPercent.Value); AcceptableValueRange<float> val = new AcceptableValueRange<float>(0f, 100000f); _maxCarryWeight = cfg.Bind<float>("Limits (server)", "MaxCarryWeight", 500f, new ConfigDescription("Предел бонуса carryWeight, единицы веса.", (AcceptableValueBase)(object)val, Array.Empty<object>())); _maxMoveSpeed = cfg.Bind<float>("Limits (server)", "MaxMoveSpeedPercent", 20f, new ConfigDescription("Предел бонуса moveSpeed, %.", (AcceptableValueBase)(object)val, Array.Empty<object>())); _maxStaminaRegen = cfg.Bind<float>("Limits (server)", "MaxStaminaRegenPercent", 50f, new ConfigDescription("Предел бонуса staminaRegen, %.", (AcceptableValueBase)(object)val, Array.Empty<object>())); _maxRunDrainReduction = cfg.Bind<float>("Limits (server)", "MaxRunStaminaDrainReductionPercent", 50f, new ConfigDescription("Предел экономии runStaminaDrain, %.", (AcceptableValueBase)(object)val, Array.Empty<object>())); _maxHealth = cfg.Bind<float>("Limits (server)", "MaxHealth", 50f, new ConfigDescription("Предел бонуса maxHealth, единицы здоровья.", (AcceptableValueBase)(object)val, Array.Empty<object>())); _maxStamina = cfg.Bind<float>("Limits (server)", "MaxStamina", 50f, new ConfigDescription("Предел бонуса maxStamina, единицы выносливости.", (AcceptableValueBase)(object)val, Array.Empty<object>())); _maxDamage = cfg.Bind<float>("Limits (server)", "MaxDamagePercent", 20f, new ConfigDescription("Предел бонуса damage, %.", (AcceptableValueBase)(object)val, Array.Empty<object>())); _maxBlockPower = cfg.Bind<float>("Limits (server)", "MaxBlockPowerPercent", 100f, new ConfigDescription("Предел бонуса blockPower (прочность блока и отбрасывание при парировании самого предмета), %.", (AcceptableValueBase)(object)val, Array.Empty<object>())); _maxToolTier = cfg.Bind<float>("Limits (server)", "MaxToolTier", 10f, new ConfigDescription("Предел бонуса toolTier (минимальный уровень инструмента).", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 100f), Array.Empty<object>())); MaxQualityAboveBase = cfg.Bind<int>("Limits (server)", "MaxQualityAboveBase", 0, new ConfigDescription("На сколько уровней выше обычного максимума предмета можно выдавать награду (как после Кузницы возможностей). 0 — не выше обычного максимума; -1 — без ограничения (технический предел игры 65535). Не действует на предметы с одним уровнем качества (пояса).", (AcceptableValueBase)(object)new AcceptableValueRange<int>(-1, 65535), Array.Empty<object>())); _maxResistance = cfg.Bind<string>("Limits (server)", "MaxResistance", "veryResistant", "Предел бонуса resist: уровень сильнее предела понижается до него с предупреждением. Значения (регистр не важен): none (сопротивления наград отключены), slightlyResistant, resistant, veryResistant, immune. Неверное значение — используется veryResistant (предупреждение в журнале). frost: immune всегда понижается до veryResistant."); _allowedEffects = cfg.Bind<string>("Limits (server)", "AllowedEffects", "Wishbone,Demister,WindRun,SlowFall,GP_Eikthyr,GP_TheElder,GP_Bonemass,GP_Moder,GP_Yagluth,GP_Queen,GP_Fader,Potion_frostresist,Potion_poisonresist,Potion_barleywine,Potion_swimmer,Potion_LightFoot,Potion_tamer,Potion_BugRepellent", "Имена ванильных StatusEffect, разрешённые в поле effects наград (через запятую, с учётом регистра). Силы боссов (GP_*) из effects действуют без таймера, пока награда надета. Медовухи без группы (Potion_*) из effects действуют без таймера, пока награда надета; медовухи лечения, выносливости и эйтра сюда не добавлять — постоянный эффект группы навсегда запретит пить медовухи этой группы. Пусто — эффекты наград отключены."); _maxAirJumps = cfg.Bind<int>("Limits (server)", "MaxAirJumps", 1, new ConfigDescription("Предел бонуса doubleJump (число прыжков в воздухе).", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 10), Array.Empty<object>())); AcceptableValueRange<float> val2 = new AcceptableValueRange<float>(0f, 100f); _maxEitr = cfg.Bind<float>("Limits (server)", "MaxEitr", 100f, new ConfigDescription("Предел бонуса maxEitr, единицы эйтра (базового эйтра у игрока нет, бонус даёт эйтр и без еды).", (AcceptableValueBase)(object)val, Array.Empty<object>())); _maxEitrRegen = cfg.Bind<float>("Limits (server)", "MaxEitrRegenPercent", 100f, new ConfigDescription("Предел бонуса eitrRegen, %. Полный комплект мага даёт +100 %.", (AcceptableValueBase)(object)val, Array.Empty<object>())); _maxEitrCostReduction = cfg.Bind<float>("Limits (server)", "MaxEitrCostReductionPercent", 50f, new ConfigDescription("Предел экономии eitrCost (расход эйтра на заклинания), %.", (AcceptableValueBase)(object)val2, Array.Empty<object>())); _maxHealthCostReduction = cfg.Bind<float>("Limits (server)", "MaxHealthCostReductionPercent", 50f, new ConfigDescription("Предел экономии healthCost (цена здоровьем у магии крови), %.", (AcceptableValueBase)(object)val2, Array.Empty<object>())); _maxSkillLevel = cfg.Bind<float>("Limits (server)", "MaxSkillLevel", 25f, new ConfigDescription("Предел бонуса skillLevel для каждого навыка, уровни.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1000f), Array.Empty<object>())); _maxSkillGain = cfg.Bind<float>("Limits (server)", "MaxSkillGainPercent", 100f, new ConfigDescription("Предел бонуса skillGain (ускорение роста навыка) для каждого навыка, %.", (AcceptableValueBase)(object)val, Array.Empty<object>())); _maxDamageSkill = cfg.Bind<float>("Limits (server)", "MaxDamageSkillPercent", 100f, new ConfigDescription("Предел бонуса damageSkill (урон атак навыком) для каждого навыка, %.", (AcceptableValueBase)(object)val, Array.Empty<object>())); _maxAdrenaline = cfg.Bind<float>("Limits (server)", "MaxAdrenalinePercent", 100f, new ConfigDescription("Предел бонуса adrenaline (ускорение набора адреналина), %.", (AcceptableValueBase)(object)val, Array.Empty<object>())); _maxAdrenalineThresholdReduction = cfg.Bind<float>("Limits (server)", "MaxAdrenalineThresholdReductionPercent", 50f, new ConfigDescription("Предел бонуса adrenalineThreshold (снижение порога шкалы наградного украшения), %.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 90f), Array.Empty<object>())); _maxAdrenalineDuration = cfg.Bind<float>("Limits (server)", "MaxAdrenalineDurationPercent", 100f, new ConfigDescription("Предел бонуса adrenalineDuration (удлинение эффекта полной шкалы наградного украшения), %.", (AcceptableValueBase)(object)val, Array.Empty<object>())); _maxAdrenalineOnHit = cfg.Bind<float>("Limits (server)", "MaxAdrenalineOnHit", 2f, new ConfigDescription("Предел бонуса adrenalineOnHit, единиц адреналина за попадание по врагу (для сравнения: идеальный блок даёт 5, обычный — 2).", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 100f), Array.Empty<object>())); _maxShipSpeed = cfg.Bind<float>("Limits (server)", "MaxShipSpeedPercent", 50f, new ConfigDescription("Предел бонуса shipSpeed одной награды (прибавка к максимальной скорости корабля под парусом и на вёслах), %. Сумму нескольких наград игрока клиенты ограничивают 50 %; на корабле действует лучшее значение среди игроков на борту, не сумма.", (Accept