using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using Il2CppInterop.Runtime;
using Il2CppSystem.Collections.Generic;
using Microsoft.CodeAnalysis;
using ProjectM;
using ProjectM.Scripting;
using ProjectM.Shared;
using Stunlock.Core;
using Unity.Entities;
using UnityEngine;
using VampireCommandFramework;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("RisingRepair")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("RisingRepair")]
[assembly: AssemblyTitle("RisingRepair")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[Embedded]
[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
internal sealed class RefSafetyRulesAttribute : Attribute
{
public readonly int Version;
public RefSafetyRulesAttribute(int P_0)
{
Version = P_0;
}
}
}
namespace RisingRepair
{
[BepInPlugin("RisingRepair", "RisingRepair", "1.2.0")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class Plugin : BasePlugin
{
internal static ManualLogSource Logger;
internal static ConfigEntry<int> PaymentItemGuid;
internal static ConfigEntry<int> PaymentItemAmount;
internal static ConfigEntry<bool> RepairWeapons;
internal static ConfigEntry<bool> RepairArmor;
internal static ConfigEntry<bool> RepairAmulets;
internal static ConfigEntry<bool> RepairSoulShards;
internal static ConfigEntry<int> RepairPercent;
public override void Load()
{
//IL_0068: Unknown result type (might be due to invalid IL or missing references)
//IL_0072: Expected O, but got Unknown
//IL_011b: Unknown result type (might be due to invalid IL or missing references)
//IL_0125: Expected O, but got Unknown
if (!(Application.productName != "VRisingServer"))
{
Logger = ((BasePlugin)this).Log;
PaymentItemGuid = ((BasePlugin)this).Config.Bind<int>("Payment", "ItemGuid", -1593377811, "PrefabGUID предмета, которым платят за починку (по умолчанию дерево).");
PaymentItemAmount = ((BasePlugin)this).Config.Bind<int>("Payment", "ItemAmount", 100, new ConfigDescription("Сколько предметов списывается за ОДНО использование команды (0 = бесплатно).", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 100000), Array.Empty<object>()));
RepairWeapons = ((BasePlugin)this).Config.Bind<bool>("RepairTargets", "Weapons", true, "Чинить оружие (топоры, булавы, мечи и т.д.). Проверяются первые 8 слотов инвентаря (хотбар).");
RepairArmor = ((BasePlugin)this).Config.Bind<bool>("RepairTargets", "Armor", true, "Чинить броню (нагрудник, перчатки, штаны, обувь).");
RepairAmulets = ((BasePlugin)this).Config.Bind<bool>("RepairTargets", "Amulets", true, "Чинить амулеты (предмет в слоте Grimoire, кроме осколков душ).");
RepairSoulShards = ((BasePlugin)this).Config.Bind<bool>("RepairTargets", "SoulShards", false, "Чинить осколки душ. Лучше оставить выключенным: у осколков своя механика износа.");
RepairPercent = ((BasePlugin)this).Config.Bind<int>("RepairAmount", "PercentPerUse", 100, new ConfigDescription("На сколько процентов от максимальной прочности чинится каждый предмет за одно использование (100 = полностью, 25 = +25%).", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 100), Array.Empty<object>()));
CommandRegistry.RegisterAll();
((BasePlugin)this).Log.LogInfo((object)"RisingRepair loaded");
}
}
public override bool Unload()
{
CommandRegistry.UnregisterAssembly();
return true;
}
}
public class RepairCommands
{
private static readonly HashSet<int> SoulShards = new HashSet<int> { 666638454, -1581189572, -1260254082, -21943750, 1286615355 };
[Command("repair", null, null, "Починка предметов", null, false)]
public void Repair(ChatCommandContext ctx)
{
//IL_0046: Unknown result type (might be due to invalid IL or missing references)
//IL_004b: 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_0072: Unknown result type (might be due to invalid IL or missing references)
//IL_0085: Unknown result type (might be due to invalid IL or missing references)
//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
//IL_012d: Unknown result type (might be due to invalid IL or missing references)
//IL_0132: Unknown result type (might be due to invalid IL or missing references)
//IL_0133: Unknown result type (might be due to invalid IL or missing references)
//IL_017d: Unknown result type (might be due to invalid IL or missing references)
//IL_0182: Unknown result type (might be due to invalid IL or missing references)
//IL_0183: Unknown result type (might be due to invalid IL or missing references)
//IL_0188: Unknown result type (might be due to invalid IL or missing references)
//IL_018c: Unknown result type (might be due to invalid IL or missing references)
//IL_0193: Unknown result type (might be due to invalid IL or missing references)
//IL_019a: Unknown result type (might be due to invalid IL or missing references)
//IL_01af: Unknown result type (might be due to invalid IL or missing references)
try
{
if (!Plugin.RepairWeapons.Value && !Plugin.RepairArmor.Value && !Plugin.RepairAmulets.Value && !Plugin.RepairSoulShards.Value)
{
ctx.Reply("Починка отключена администратором сервера.");
return;
}
Entity senderCharacterEntity = ctx.Event.SenderCharacterEntity;
Entity val = default(Entity);
if (!InventoryUtilities.TryGetInventoryEntity<EntityManager>(Core.EntityManager, senderCharacterEntity, ref val, 0))
{
ctx.Reply("Не удалось найти ваш инвентарь.");
return;
}
List<Entity> list = new List<Entity>();
CollectEquipped(senderCharacterEntity, list);
if (Plugin.RepairWeapons.Value)
{
CollectHotbarWeapons(val, list);
}
if (list.Count == 0)
{
ctx.Reply("Всё в порядке — чинить нечего.");
return;
}
int num = Math.Max(0, Plugin.PaymentItemAmount.Value);
if (num > 0)
{
PrefabGUID val2 = default(PrefabGUID);
((PrefabGUID)(ref val2))..ctor(Plugin.PaymentItemGuid.Value);
int num2 = CountItem(val, val2);
if (num2 < num)
{
ctx.Reply($"Не хватает ресурса для оплаты: нужно {num}, у вас {num2}.");
return;
}
if (!InventoryUtilitiesServer.TryRemoveItem(Core.EntityManager, val, val2, num))
{
ctx.Reply("Не удалось списать оплату, починка отменена.");
return;
}
}
int num3 = Math.Min(100, Math.Max(1, Plugin.RepairPercent.Value));
float num4 = (float)num3 / 100f;
foreach (Entity item in list)
{
Durability val3 = item.Read<Durability>();
val3.Value = Math.Min(val3.MaxDurability, val3.Value + val3.MaxDurability * num4);
item.Write<Durability>(val3);
}
ctx.Reply($"Починено предметов: {list.Count} (+{num3}% прочности).");
}
catch (Exception ex)
{
Plugin.Logger.LogError((object)ex);
ctx.Reply("Ошибка при починке. Сообщите администратору.");
}
}
private static void CollectEquipped(Entity character, List<Entity> result)
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
//IL_0009: Unknown result type (might be due to invalid IL or missing references)
//IL_000a: Unknown result type (might be due to invalid IL or missing references)
//IL_000f: 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_003f: 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_006d: Unknown result type (might be due to invalid IL or missing references)
//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_00a2: 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_00af: Unknown result type (might be due to invalid IL or missing references)
//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
if (!character.Has<Equipment>())
{
return;
}
Equipment val = character.Read<Equipment>();
if (Plugin.RepairArmor.Value)
{
AddIfDamaged(((NetworkedEntity)(ref val.ArmorChestSlot.SlotEntity)).GetEntityOnServer(), result);
AddIfDamaged(((NetworkedEntity)(ref val.ArmorGlovesSlot.SlotEntity)).GetEntityOnServer(), result);
AddIfDamaged(((NetworkedEntity)(ref val.ArmorLegsSlot.SlotEntity)).GetEntityOnServer(), result);
AddIfDamaged(((NetworkedEntity)(ref val.ArmorFootgearSlot.SlotEntity)).GetEntityOnServer(), result);
}
if (!Plugin.RepairAmulets.Value && !Plugin.RepairSoulShards.Value)
{
return;
}
Entity entityOnServer = ((NetworkedEntity)(ref val.GrimoireSlot.SlotEntity)).GetEntityOnServer();
if (entityOnServer != Entity.Null && entityOnServer.Has<PrefabGUID>())
{
HashSet<int> soulShards = SoulShards;
PrefabGUID val2 = entityOnServer.Read<PrefabGUID>();
if (soulShards.Contains(((PrefabGUID)(ref val2)).GuidHash) ? Plugin.RepairSoulShards.Value : Plugin.RepairAmulets.Value)
{
AddIfDamaged(entityOnServer, result);
}
}
}
private static void CollectHotbarWeapons(Entity inventory, List<Entity> result)
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
//IL_0012: Unknown result type (might be due to invalid IL or missing references)
//IL_0017: Unknown result type (might be due to invalid IL or missing references)
//IL_001f: Unknown result type (might be due to invalid IL or missing references)
//IL_0024: 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_0026: Unknown result type (might be due to invalid IL or missing references)
//IL_0032: 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_003b: Unknown result type (might be due to invalid IL or missing references)
//IL_0040: Unknown result type (might be due to invalid IL or missing references)
//IL_0046: Invalid comparison between Unknown and I4
//IL_0048: Unknown result type (might be due to invalid IL or missing references)
if (!TryGetBuffer(inventory, out var buffer))
{
return;
}
for (int i = 0; i < 8 && i < buffer.Length; i++)
{
InventoryBuffer val = buffer[i];
Entity entityOnServer = ((NetworkedEntity)(ref val.ItemEntity)).GetEntityOnServer();
if (!(entityOnServer == Entity.Null) && entityOnServer.Has<EquippableData>() && (int)entityOnServer.Read<EquippableData>().EquipmentType == 2)
{
AddIfDamaged(entityOnServer, result);
}
}
}
private static void AddIfDamaged(Entity item, List<Entity> result)
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_000d: Unknown result type (might be due to invalid IL or missing references)
//IL_0016: Unknown result type (might be due to invalid IL or missing references)
//IL_0017: 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)
//IL_001d: Unknown result type (might be due to invalid IL or missing references)
//IL_002a: 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)
//IL_0039: Unknown result type (might be due to invalid IL or missing references)
if (!(item == Entity.Null) && item.Has<Durability>())
{
Durability val = item.Read<Durability>();
if (val.MaxDurability > 0f && val.Value < val.MaxDurability)
{
result.Add(item);
}
}
}
private static int CountItem(Entity inventory, PrefabGUID guid)
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
//IL_0015: Unknown result type (might be due to invalid IL or missing references)
//IL_001a: 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 (!TryGetBuffer(inventory, out var buffer))
{
return 0;
}
int num = 0;
for (int i = 0; i < buffer.Length; i++)
{
InventoryBuffer val = buffer[i];
if (((PrefabGUID)(ref val.ItemType)).GuidHash == ((PrefabGUID)(ref guid)).GuidHash)
{
num += val.Amount;
}
}
return num;
}
private static bool TryGetBuffer(Entity inventory, out DynamicBuffer<InventoryBuffer> buffer)
{
//IL_0001: 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_001d: 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)
buffer = default(DynamicBuffer<InventoryBuffer>);
ServerScriptMapper existingSystemManaged = Core.Server.GetExistingSystemManaged<ServerScriptMapper>();
if (existingSystemManaged == null)
{
return false;
}
ServerGameManager serverGameManager = existingSystemManaged._ServerGameManager;
return ((ServerGameManager)(ref serverGameManager)).TryGetBuffer<InventoryBuffer>(inventory, ref buffer);
}
}
internal static class Core
{
private static World _server;
public static World Server => _server ?? (_server = FindWorld("Server"));
public static EntityManager EntityManager => Server.EntityManager;
private static World FindWorld(string name)
{
Enumerator<World> enumerator = World.s_AllWorlds.GetEnumerator();
while (enumerator.MoveNext())
{
World current = enumerator.Current;
if (current.Name == name)
{
return current;
}
}
throw new InvalidOperationException("World '" + name + "' not found");
}
}
internal static class EcsExt
{
private static ComponentType CT<T>()
{
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
return new ComponentType(Il2CppType.Of<T>(), (AccessMode)0);
}
public static bool Has<T>(this Entity e)
{
//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_0008: Unknown result type (might be due to invalid IL or missing references)
//IL_0009: Unknown result type (might be due to invalid IL or missing references)
EntityManager entityManager = Core.EntityManager;
return ((EntityManager)(ref entityManager)).HasComponent(e, CT<T>());
}
public unsafe static T Read<T>(this Entity e) where T : struct
{
//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_0008: Unknown result type (might be due to invalid IL or missing references)
//IL_0009: Unknown result type (might be due to invalid IL or missing references)
//IL_000e: Unknown result type (might be due to invalid IL or missing references)
EntityManager entityManager = Core.EntityManager;
return Marshal.PtrToStructure<T>(new IntPtr(((EntityManager)(ref entityManager)).GetComponentDataRawRO(e, CT<T>().TypeIndex)));
}
public unsafe static void Write<T>(this Entity e, T value) where T : struct
{
//IL_0015: Unknown result type (might be due to invalid IL or missing references)
//IL_001a: Unknown result type (might be due to invalid IL or missing references)
//IL_001d: Unknown result type (might be due to invalid IL or missing references)
//IL_001e: Unknown result type (might be due to invalid IL or missing references)
//IL_0023: Unknown result type (might be due to invalid IL or missing references)
int num = Marshal.SizeOf<T>();
IntPtr intPtr = Marshal.AllocHGlobal(num);
try
{
Marshal.StructureToPtr(value, intPtr, fDeleteOld: false);
EntityManager entityManager = Core.EntityManager;
((EntityManager)(ref entityManager)).SetComponentDataRaw(e, CT<T>().TypeIndex, (void*)intPtr, num);
}
finally
{
Marshal.FreeHGlobal(intPtr);
}
}
}
}