using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using Il2CppInterop.Runtime;
using Il2CppSystem.Collections.Generic;
using Microsoft.CodeAnalysis;
using ProjectM;
using ProjectM.Network;
using ProjectM.Terrain;
using Stunlock.Core;
using Unity.Collections;
using Unity.Entities;
using Unity.Mathematics;
using Unity.Transforms;
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("ResourceMap")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.2.0")]
[assembly: AssemblyInformationalVersion("1.0.2+e51c22e6dea05a110783c9c649e51a0d95c63fb7")]
[assembly: AssemblyProduct("ResourceMap")]
[assembly: AssemblyTitle("ResourceMap")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.2.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 ResourceMap
{
public class ChainReader
{
public struct ChainInfo
{
public int SpotId;
public int ChainDef;
public int Element;
public int SpawnerDef;
public int SpawnerId;
}
public class ChainDef
{
public string Name;
public int Main;
public List<ChainElementDef> Elements = new List<ChainElementDef>();
}
public class ChainElementDef
{
public string Name;
public string Prefab;
public float AfterSeconds;
}
public class SpawnerDef
{
public string Name;
public List<SpawnerOptionDef> Options = new List<SpawnerOptionDef>();
}
public class SpawnerOptionDef
{
public string Chain;
public int ChainDef;
public float Chance;
}
private const int ChainElementSize = 96;
private const int ElementNameOffset = 8;
private const int ElementIndexOffset = 40;
private const int ElementPrefabOffset = 44;
private const int UseAutoTransitionOffset = 48;
private const int AutoTransitionAfterOffset = 92;
private const int GroupSize = 16;
private const int RandomChainSize = 8;
private const int MaxListLength = 256;
public readonly List<ChainDef> Chains = new List<ChainDef>();
public readonly List<SpawnerDef> Spawners = new List<SpawnerDef>();
private readonly EntityManager _em;
private readonly PrefabCollectionSystem _prefabs;
private readonly Func<PrefabGUID, string> _nameOf;
private readonly ComponentType _spawnChainChild = ComponentType.ReadOnly(Il2CppType.Of<SpawnChainChild>());
private readonly ComponentType _chainConstants = ComponentType.ReadOnly(Il2CppType.Of<SpawnChainConstants>());
private readonly ComponentType _randomizedChild = ComponentType.ReadOnly(Il2CppType.Of<RandomizedSpawnChainChild>());
private readonly ComponentType _randomized = ComponentType.ReadOnly(Il2CppType.Of<RandomizedSpawnChain>());
private readonly ComponentType _randomizedSettings = ComponentType.ReadOnly(Il2CppType.Of<RandomizedSpawnChainSettings>());
private readonly ComponentType _prefabGuid = ComponentType.ReadOnly(Il2CppType.Of<PrefabGUID>());
private readonly Dictionary<IntPtr, int> _chainByBlob = new Dictionary<IntPtr, int>();
private readonly Dictionary<int, int> _spawnerBySettings = new Dictionary<int, int>();
private readonly Dictionary<int, ChainInfo> _chainByEntity = new Dictionary<int, ChainInfo>();
public bool Broken { get; private set; }
public ChainReader(EntityManager em, PrefabCollectionSystem prefabs, Func<PrefabGUID, string> nameOf)
{
//IL_001c: 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_002c: 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)
//IL_003c: 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_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_005c: Unknown result type (might be due to invalid IL or missing references)
//IL_0061: Unknown result type (might be due to invalid IL or missing references)
//IL_006c: Unknown result type (might be due to invalid IL or missing references)
//IL_0071: Unknown result type (might be due to invalid IL or missing references)
//IL_009e: Unknown result type (might be due to invalid IL or missing references)
//IL_009f: Unknown result type (might be due to invalid IL or missing references)
_em = em;
_prefabs = prefabs;
_nameOf = nameOf;
}
public ChainInfo? Read(Entity node)
{
//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)
//IL_0011: Unknown result type (might be due to invalid IL or missing references)
//IL_0013: Unknown result type (might be due to invalid IL or missing references)
//IL_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)
//IL_0033: Unknown result type (might be due to invalid IL or missing references)
//IL_0034: 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)
//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_0047: Unknown result type (might be due to invalid IL or missing references)
//IL_0148: Unknown result type (might be due to invalid IL or missing references)
//IL_0063: Unknown result type (might be due to invalid IL or missing references)
//IL_008b: Unknown result type (might be due to invalid IL or missing references)
//IL_0090: Unknown result type (might be due to invalid IL or missing references)
//IL_0093: Unknown result type (might be due to invalid IL or missing references)
//IL_0139: Unknown result type (might be due to invalid IL or missing references)
//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
//IL_00cc: 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_00d2: Unknown result type (might be due to invalid IL or missing references)
//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
//IL_00da: Unknown result type (might be due to invalid IL or missing references)
//IL_00df: Unknown result type (might be due to invalid IL or missing references)
//IL_00e2: 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_00f1: Unknown result type (might be due to invalid IL or missing references)
//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
//IL_0105: Unknown result type (might be due to invalid IL or missing references)
//IL_0115: Unknown result type (might be due to invalid IL or missing references)
//IL_011a: Unknown result type (might be due to invalid IL or missing references)
//IL_011d: Unknown result type (might be due to invalid IL or missing references)
//IL_011f: Unknown result type (might be due to invalid IL or missing references)
//IL_0124: Unknown result type (might be due to invalid IL or missing references)
if (!Broken)
{
EntityManager em = _em;
if (((EntityManager)(ref em)).HasComponent(node, _spawnChainChild))
{
try
{
em = _em;
SpawnChainChild componentData = ((EntityManager)(ref em)).GetComponentData<SpawnChainChild>(node);
Entity spawnChain = componentData.SpawnChain;
if (!_chainByEntity.TryGetValue(spawnChain.Index, out var value))
{
value = new ChainInfo
{
SpotId = spawnChain.Index,
ChainDef = -1,
SpawnerDef = -1,
SpawnerId = -1
};
em = _em;
if (((EntityManager)(ref em)).Exists(spawnChain))
{
value.ChainDef = ChainDefOf(spawnChain);
em = _em;
if (((EntityManager)(ref em)).HasComponent(spawnChain, _randomizedChild))
{
em = _em;
Entity parent = ((EntityManager)(ref em)).GetComponentData<RandomizedSpawnChainChild>(spawnChain).Parent;
em = _em;
if (((EntityManager)(ref em)).Exists(parent))
{
em = _em;
if (((EntityManager)(ref em)).HasComponent(parent, _randomized))
{
value.SpawnerId = parent.Index;
em = _em;
value.SpawnerDef = SpawnerDefOf(((EntityManager)(ref em)).GetComponentData<RandomizedSpawnChain>(parent).Settings);
}
}
}
}
_chainByEntity[spawnChain.Index] = value;
}
value.Element = componentData.SpawnChainElementIndex;
return value;
}
catch (Exception ex)
{
TurnOff("Couldn't read spawn chains: " + ex.Message);
return null;
}
}
}
return null;
}
private unsafe int ChainDefOf(Entity chainEntity)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0003: Unknown result type (might be due to invalid IL or missing references)
//IL_003d: Unknown result type (might be due to invalid IL or missing references)
//IL_0042: Unknown result type (might be due to invalid IL or missing references)
//IL_0046: Unknown result type (might be due to invalid IL or missing references)
//IL_0048: Unknown result type (might be due to invalid IL or missing references)
//IL_005c: Unknown result type (might be due to invalid IL or missing references)
//IL_0061: Unknown result type (might be due to invalid IL or missing references)
//IL_0065: Unknown result type (might be due to invalid IL or missing references)
//IL_0066: Unknown result type (might be due to invalid IL or missing references)
//IL_0151: Unknown result type (might be due to invalid IL or missing references)
byte* ptr = BlobOf(chainEntity, _chainConstants);
if (ptr == null)
{
return -1;
}
if (_chainByBlob.TryGetValue((IntPtr)ptr, out var value))
{
return value;
}
ChainDef chainDef = new ChainDef
{
Main = ((int*)ptr)[2]
};
EntityManager em = _em;
if (((EntityManager)(ref em)).HasComponent(chainEntity, _prefabGuid))
{
Func<PrefabGUID, string> nameOf = _nameOf;
em = _em;
chainDef.Name = nameOf(((EntityManager)(ref em)).GetComponentData<PrefabGUID>(chainEntity));
}
int length;
byte* ptr2 = BlobArray(ptr, out length);
if (length <= 0 || length > 256 || chainDef.Main < 0 || chainDef.Main >= length)
{
TurnOff($"Spawn chain list looks wrong (count {length}, main {chainDef.Main}).");
return -1;
}
PrefabGUID arg = default(PrefabGUID);
for (int i = 0; i < length; i++)
{
byte* ptr3 = ptr2 + i * 96;
if (((int*)ptr3)[10] != i)
{
TurnOff("Spawn chain element layout doesn't match this game version.");
return -1;
}
((PrefabGUID)(ref arg))..ctor(((int*)ptr3)[11]);
chainDef.Elements.Add(new ChainElementDef
{
Name = FixedString32(ptr3 + 8),
Prefab = ((((PrefabGUID)(ref arg)).GuidHash == 0) ? null : _nameOf(arg)),
AfterSeconds = ((ptr3[48] != 0) ? ((float*)ptr3)[23] : 0f)
});
}
value = Chains.Count;
Chains.Add(chainDef);
_chainByBlob[(IntPtr)ptr] = value;
return value;
}
private unsafe int SpawnerDefOf(PrefabGUID settingsGuid)
{
//IL_0031: Unknown result type (might be due to invalid IL or missing references)
//IL_0036: 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_0047: 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_0067: Unknown result type (might be due to invalid IL or missing references)
//IL_01c7: Unknown result type (might be due to invalid IL or missing references)
//IL_01cc: Unknown result type (might be due to invalid IL or missing references)
//IL_01d0: Unknown result type (might be due to invalid IL or missing references)
//IL_01f7: Unknown result type (might be due to invalid IL or missing references)
//IL_01dc: Unknown result type (might be due to invalid IL or missing references)
if (_spawnerBySettings.TryGetValue(((PrefabGUID)(ref settingsGuid)).GuidHash, out var value))
{
return value;
}
_spawnerBySettings[((PrefabGUID)(ref settingsGuid)).GuidHash] = -1;
PrefabLookupMap prefabLookupMap = _prefabs._PrefabLookupMap;
Entity entity = default(Entity);
if (!((PrefabLookupMap)(ref prefabLookupMap)).TryGetValueWithoutLogging(settingsGuid, ref entity))
{
return -1;
}
byte* ptr = BlobOf(entity, _randomizedSettings);
if (ptr == null)
{
return -1;
}
SpawnerDef spawnerDef = new SpawnerDef
{
Name = _nameOf(settingsGuid)
};
float num = ((float*)ptr)[2];
int length;
byte* ptr2 = BlobArray(ptr, out length);
if (length < 0 || length > 256)
{
TurnOff($"Randomized spawner list looks wrong (groups {length}).");
return -1;
}
PrefabGUID val = default(PrefabGUID);
Entity chainEntity = default(Entity);
for (int i = 0; i < length; i++)
{
byte* ptr3 = ptr2 + i * 16;
float num2 = ((num > 0f) ? (((float*)ptr3)[2] / num) : (1f / (float)length));
float num3 = ((float*)ptr3)[3];
int length2;
byte* ptr4 = BlobArray(ptr3, out length2);
if (length2 < 0 || length2 > 256)
{
TurnOff($"Randomized spawner list looks wrong (chains {length2}).");
return -1;
}
for (int j = 0; j < length2; j++)
{
byte* ptr5 = ptr4 + j * 8;
((PrefabGUID)(ref val))..ctor(*(int*)ptr5);
float num4 = ((float*)ptr5)[1];
float num5 = num2 * ((num3 > 0f) ? (num4 / num3) : (1f / (float)length2));
if (float.IsNaN(num5) || num5 < 0f || num5 > 1.001f)
{
TurnOff("Randomized spawner weights don't make sense for this game version.");
return -1;
}
int chainDef = -1;
prefabLookupMap = _prefabs._PrefabLookupMap;
if (((PrefabLookupMap)(ref prefabLookupMap)).TryGetValueWithoutLogging(val, ref chainEntity))
{
chainDef = ChainDefOf(chainEntity);
}
spawnerDef.Options.Add(new SpawnerOptionDef
{
Chain = _nameOf(val),
ChainDef = chainDef,
Chance = num5
});
}
}
value = Spawners.Count;
Spawners.Add(spawnerDef);
_spawnerBySettings[((PrefabGUID)(ref settingsGuid)).GuidHash] = value;
return value;
}
private unsafe byte* BlobOf(Entity entity, ComponentType type)
{
//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_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_0016: 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_001e: 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_0020: Unknown result type (might be due to invalid IL or missing references)
EntityManager em = _em;
if (!((EntityManager)(ref em)).HasComponent(entity, type))
{
return null;
}
em = _em;
void* componentDataRawRO = ((EntityManager)(ref em)).GetComponentDataRawRO(entity, type.TypeIndex);
if (componentDataRawRO != null)
{
return *(byte**)componentDataRawRO;
}
return null;
}
private unsafe static byte* BlobArray(byte* field, out int length)
{
length = ((int*)field)[1];
return field + *(int*)field;
}
private unsafe static string FixedString32(byte* p)
{
int num = *(ushort*)p;
if (num <= 0 || num > 29)
{
return "";
}
return Encoding.UTF8.GetString(p + 2, num);
}
private void TurnOff(string reason)
{
//IL_001a: Unknown result type (might be due to invalid IL or missing references)
//IL_0020: Expected O, but got Unknown
if (!Broken)
{
Broken = true;
ManualLogSource logger = Plugin.Logger;
bool flag = default(bool);
BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(52, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(reason);
((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" The dump will not include what spots can turn into.");
}
logger.LogWarning(val);
}
}
}
[CommandGroup("rmap", null)]
public class Commands
{
private static readonly Dictionary<int, string> Names = new Dictionary<int, string>();
private static readonly Dictionary<ulong, DateTime> LastFind = new Dictionary<ulong, DateTime>();
public static void Register()
{
CommandRegistry.RegisterAll();
}
[Command("help", null, null, "Show the ResourceMap commands you can use.", null, false)]
public void Help(ChatCommandContext ctx)
{
bool num = Plugin.FindEnabled.Value && (ctx.IsAdmin || !Plugin.FindAdminOnly.Value);
List<string> list = new List<string>();
string text = ((Plugin.FindMaxRange.Value > 0) ? $" (within {Plugin.FindMaxRange.Value}m)" : "");
if (num && Permitted(ctx, "Find"))
{
list.Add(".rmap find <resource> - nearest resource around you" + text + ", e.g. .rmap find copper");
}
if (num && Permitted(ctx, "Mark"))
{
list.Add(".rmap mark <resource> - same, and puts your map marker on it");
}
if (Permitted(ctx, "Dump"))
{
list.Add(".rmap dump - write a fresh resource dump now");
}
if (Permitted(ctx, "Reload"))
{
list.Add(".rmap reload - reload the ResourceMap config");
}
ctx.Reply((list.Count > 0) ? ("ResourceMap commands:\n" + string.Join("\n", list)) : "There are no ResourceMap commands you can use on this server.");
}
private static bool Permitted(ChatCommandContext ctx, string methodName)
{
//IL_0066: Unknown result type (might be due to invalid IL or missing references)
//IL_006d: Expected O, but got Unknown
MethodInfo method = typeof(Commands).GetMethod(methodName);
CommandAttribute customAttribute = ((MemberInfo)method).GetCustomAttribute<CommandAttribute>();
try
{
foreach (CommandMiddleware middleware in CommandRegistry.Middlewares)
{
if (!middleware.CanExecute((ICommandContext)(object)ctx, customAttribute, method))
{
return false;
}
}
return true;
}
catch (Exception ex)
{
ManualLogSource logger = Plugin.Logger;
bool flag = default(bool);
BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(61, 2, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Permission check for .rmap ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(customAttribute.Name);
((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" failed; using its admin setting. ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(ex.Message);
}
logger.LogWarning(val);
return !customAttribute.AdminOnly || ctx.IsAdmin;
}
}
[Command("dump", null, null, "Write a fresh resource dump now.", null, true)]
public void Dump(ChatCommandContext ctx)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
if (!NodeDumper.TryStart(ctx.User))
{
ctx.Reply("A dump is already running. You'll get a message when it's done.");
}
else
{
ctx.Reply("Dump started. You'll get a message when it's written.");
}
}
[Command("reload", null, null, "Reload the ResourceMap config file.", null, true)]
public void Reload(ChatCommandContext ctx)
{
Plugin.Settings.Reload();
ctx.Reply("ResourceMap config reloaded.");
}
[Command("find", null, "<resource> [range]", "Find the nearest resource around you, e.g. .rmap find copper", null, false)]
public void Find(ChatCommandContext ctx, string resource, string word2 = "", string word3 = "", string word4 = "")
{
Search(ctx, resource, word2, word3, word4, mark: false);
}
[Command("mark", null, "<resource> [range]", "Put your map marker on the nearest resource, e.g. .rmap mark copper", null, false)]
public void Mark(ChatCommandContext ctx, string resource, string word2 = "", string word3 = "", string word4 = "")
{
Search(ctx, resource, word2, word3, word4, mark: true);
}
private static void Search(ChatCommandContext ctx, string first, string word2, string word3, string word4, bool mark)
{
//IL_00be: Unknown result type (might be due to invalid IL or missing references)
//IL_01a3: Unknown result type (might be due to invalid IL or missing references)
//IL_01a8: Unknown result type (might be due to invalid IL or missing references)
//IL_01b3: Unknown result type (might be due to invalid IL or missing references)
//IL_01bb: Unknown result type (might be due to invalid IL or missing references)
//IL_01c0: 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_01ff: Unknown result type (might be due to invalid IL or missing references)
//IL_0204: Unknown result type (might be due to invalid IL or missing references)
//IL_0209: Unknown result type (might be due to invalid IL or missing references)
//IL_0212: Unknown result type (might be due to invalid IL or missing references)
//IL_0217: Unknown result type (might be due to invalid IL or missing references)
//IL_021c: Unknown result type (might be due to invalid IL or missing references)
//IL_0225: Unknown result type (might be due to invalid IL or missing references)
//IL_022a: Unknown result type (might be due to invalid IL or missing references)
//IL_022f: Unknown result type (might be due to invalid IL or missing references)
//IL_0235: Unknown result type (might be due to invalid IL or missing references)
//IL_023a: Unknown result type (might be due to invalid IL or missing references)
//IL_0246: Unknown result type (might be due to invalid IL or missing references)
//IL_024b: Unknown result type (might be due to invalid IL or missing references)
//IL_0250: Unknown result type (might be due to invalid IL or missing references)
//IL_0254: Unknown result type (might be due to invalid IL or missing references)
//IL_0259: Unknown result type (might be due to invalid IL or missing references)
//IL_025f: Unknown result type (might be due to invalid IL or missing references)
//IL_0264: Unknown result type (might be due to invalid IL or missing references)
//IL_0268: Unknown result type (might be due to invalid IL or missing references)
//IL_026a: Unknown result type (might be due to invalid IL or missing references)
//IL_026f: Unknown result type (might be due to invalid IL or missing references)
//IL_0273: Unknown result type (might be due to invalid IL or missing references)
//IL_0279: Invalid comparison between Unknown and I4
//IL_027b: Unknown result type (might be due to invalid IL or missing references)
//IL_027d: Unknown result type (might be due to invalid IL or missing references)
//IL_027f: Unknown result type (might be due to invalid IL or missing references)
//IL_0284: Unknown result type (might be due to invalid IL or missing references)
//IL_0286: Unknown result type (might be due to invalid IL or missing references)
//IL_028d: Unknown result type (might be due to invalid IL or missing references)
//IL_0294: Unknown result type (might be due to invalid IL or missing references)
//IL_0299: Unknown result type (might be due to invalid IL or missing references)
//IL_02a0: Unknown result type (might be due to invalid IL or missing references)
//IL_02a7: Unknown result type (might be due to invalid IL or missing references)
//IL_02b9: Unknown result type (might be due to invalid IL or missing references)
//IL_02bd: Unknown result type (might be due to invalid IL or missing references)
//IL_02cc: Unknown result type (might be due to invalid IL or missing references)
//IL_0380: Unknown result type (might be due to invalid IL or missing references)
//IL_0385: Unknown result type (might be due to invalid IL or missing references)
//IL_0387: Unknown result type (might be due to invalid IL or missing references)
//IL_0389: Unknown result type (might be due to invalid IL or missing references)
//IL_038b: Unknown result type (might be due to invalid IL or missing references)
//IL_0390: Unknown result type (might be due to invalid IL or missing references)
//IL_043a: Unknown result type (might be due to invalid IL or missing references)
//IL_0441: Unknown result type (might be due to invalid IL or missing references)
//IL_0449: Unknown result type (might be due to invalid IL or missing references)
//IL_0450: Unknown result type (might be due to invalid IL or missing references)
//IL_0470: Unknown result type (might be due to invalid IL or missing references)
//IL_0490: Unknown result type (might be due to invalid IL or missing references)
//IL_04c7: Unknown result type (might be due to invalid IL or missing references)
//IL_04cf: Unknown result type (might be due to invalid IL or missing references)
//IL_04da: Unknown result type (might be due to invalid IL or missing references)
//IL_04df: Unknown result type (might be due to invalid IL or missing references)
//IL_04e6: Unknown result type (might be due to invalid IL or missing references)
//IL_04ed: Unknown result type (might be due to invalid IL or missing references)
List<string> list = new List<string> { first, word2, word3, word4 }.FindAll((string w) => !string.IsNullOrWhiteSpace(w));
int num = 0;
if (list.Count > 1)
{
if (int.TryParse(list[list.Count - 1], out var result))
{
num = result;
list.RemoveAt(list.Count - 1);
}
}
string text = string.Join(" ", list);
if (!Plugin.FindEnabled.Value)
{
ctx.Reply("Resource finding is turned off on this server.");
return;
}
if (Plugin.FindAdminOnly.Value && !ctx.IsAdmin)
{
ctx.Reply("Only admins can use .rmap find on this server.");
return;
}
ulong platformId = ctx.User.PlatformId;
if (!ctx.IsAdmin && LastFind.TryGetValue(platformId, out var value))
{
double num2 = (double)Plugin.FindCooldownSeconds.Value - (DateTime.UtcNow - value).TotalSeconds;
if (num2 > 0.0)
{
ctx.Reply($"Wait {Math.Ceiling(num2)}s before searching again.");
return;
}
}
LastFind[platformId] = DateTime.UtcNow;
int value2 = Plugin.FindMaxRange.Value;
if (num <= 0 || (value2 > 0 && num > value2))
{
num = ((value2 > 0) ? value2 : 500);
}
World val = NodeDumper.ServerWorld();
if (val == null)
{
ctx.Reply("The server world isn't ready yet.");
return;
}
EntityManager entityManager = val.EntityManager;
PrefabCollectionSystem existingSystemManaged = val.GetExistingSystemManaged<PrefabCollectionSystem>();
float3 val2 = NodeDumper.PositionOf(entityManager, ctx.Event.SenderCharacterEntity);
string[] terms = text.Split(' ', StringSplitOptions.RemoveEmptyEntries).Select(Normalize).ToArray();
List<(float, Entity)> list2 = new List<(float, Entity)>();
EntityQueryBuilder val3 = new EntityQueryBuilder(AllocatorHandle.op_Implicit((Allocator)2));
val3 = ((EntityQueryBuilder)(ref val3)).AddAll(ComponentType.ReadOnly(Il2CppType.Of<EntityCategory>()));
EntityQueryBuilder val4 = ((EntityQueryBuilder)(ref val3)).AddAll(ComponentType.ReadOnly(Il2CppType.Of<PrefabGUID>()));
EntityQuery val5 = ((EntityManager)(ref entityManager)).CreateEntityQuery(ref val4);
((EntityQueryBuilder)(ref val4)).Dispose();
NativeArray<Entity> val6 = ((EntityQuery)(ref val5)).ToEntityArray(AllocatorHandle.op_Implicit((Allocator)2));
try
{
Enumerator<Entity> enumerator = val6.GetEnumerator();
while (enumerator.MoveNext())
{
Entity current = enumerator.Current;
EntityCategory componentData = ((EntityManager)(ref entityManager)).GetComponentData<EntityCategory>(current);
if ((int)((EntityCategory)(ref componentData)).MainCategory == 1)
{
float3 val7 = NodeDumper.PositionOf(entityManager, current);
float num3 = math.distance(new float2(val7.x, val7.z), new float2(val2.x, val2.z));
if (!(num3 > (float)num) && Matches(entityManager, existingSystemManaged, current, terms))
{
list2.Add((num3, current));
}
}
}
}
finally
{
val6.Dispose();
((EntityQuery)(ref val5)).Dispose();
}
if (list2.Count == 0)
{
ctx.Reply($"No {text} within {num}m.");
return;
}
list2.Sort(((float dist, Entity entity) a, (float dist, Entity entity) b) => a.dist.CompareTo(b.dist));
(float, Entity) tuple = list2[0];
float item = tuple.Item1;
Entity item2 = tuple.Item2;
float3 val8 = NodeDumper.PositionOf(entityManager, item2);
string value3 = ((list2.Count > 1) ? $" {list2.Count - 1} more within {num}m." : "");
ctx.Reply($"Nearest {text}: {Math.Round(item)}m {Direction(val8.x - val2.x, val8.z - val2.z)} (x {Math.Round(val8.x)}, z {Math.Round(val8.z)}).{value3}");
if (mark)
{
SetMapMarker(entityManager, ctx.Event.SenderUserEntity, ctx.Event.SenderCharacterEntity, new float2(val8.x, val8.z));
ctx.Reply("Map marker placed. Open the map to follow its guide path.");
}
}
private static void SetMapMarker(EntityManager em, Entity user, Entity character, float2 position)
{
//IL_000f: Unknown result type (might be due to invalid IL or missing references)
//IL_0014: Unknown result type (might be due to invalid IL or missing references)
//IL_0020: Unknown result type (might be due to invalid IL or missing references)
//IL_0025: Unknown result type (might be due to invalid IL or missing references)
//IL_0031: Unknown result type (might be due to invalid IL or missing references)
//IL_0036: 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_0043: Unknown result type (might be due to invalid IL or missing references)
//IL_0046: Unknown result type (might be due to invalid IL or missing references)
//IL_004e: Unknown result type (might be due to invalid IL or missing references)
//IL_004f: 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_0057: Unknown result type (might be due to invalid IL or missing references)
//IL_005c: 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_0067: Unknown result type (might be due to invalid IL or missing references)
//IL_006f: Unknown result type (might be due to invalid IL or missing references)
//IL_0070: Unknown result type (might be due to invalid IL or missing references)
//IL_0075: Unknown result type (might be due to invalid IL or missing references)
Entity val = ((EntityManager)(ref em)).CreateEntity((ComponentType[])(object)new ComponentType[3]
{
ComponentType.ReadWrite(Il2CppType.Of<FromCharacter>()),
ComponentType.ReadWrite(Il2CppType.Of<SetMapMarkerEvent>()),
ComponentType.ReadWrite(Il2CppType.Of<ReceiveNetworkEventTag>())
});
((EntityManager)(ref em)).SetComponentData<FromCharacter>(val, new FromCharacter
{
User = user,
Character = character
});
((EntityManager)(ref em)).SetComponentData<SetMapMarkerEvent>(val, new SetMapMarkerEvent
{
Position = position
});
}
private static bool Matches(EntityManager em, PrefabCollectionSystem prefabs, Entity entity, string[] terms)
{
//IL_000d: 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)
//IL_0037: Unknown result type (might be due to invalid IL or missing references)
//IL_0038: Unknown result type (might be due to invalid IL or missing references)
List<NodeDumper.YieldRecord> list = NodeDumper.YieldsOf(em, entity, (PrefabGUID guid) => NameOf(prefabs, guid));
if (list == null || list.Count == 0)
{
return false;
}
string prefab = Normalize(NameOf(prefabs, ((EntityManager)(ref em)).GetComponentData<PrefabGUID>(entity)));
if (terms.All((string t) => prefab.Contains(t)))
{
return true;
}
foreach (NodeDumper.YieldRecord item2 in list)
{
string item = Normalize(item2.Item);
if (terms.All((string t) => item.Contains(t)))
{
return true;
}
}
return false;
}
private static string NameOf(PrefabCollectionSystem prefabs, PrefabGUID guid)
{
//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)
if (Names.TryGetValue(((PrefabGUID)(ref guid)).GuidHash, out var value))
{
return value;
}
PrefabLookupMap prefabLookupMap = prefabs._PrefabLookupMap;
if (!((PrefabLookupMap)(ref prefabLookupMap)).TryGetName(guid, ref value))
{
value = "";
}
Names[((PrefabGUID)(ref guid)).GuidHash] = value;
return value;
}
private static string Normalize(string s)
{
return s.ToLowerInvariant().Replace(" ", "").Replace("_", "")
.Replace("sulph", "sulf");
}
private static string Direction(float dx, float dz)
{
string[] obj = new string[8] { "north", "north-east", "east", "south-east", "south", "south-west", "west", "north-west" };
double num = (Math.Atan2(dx, dz) * 180.0 / Math.PI + 360.0) % 360.0;
return obj[(int)Math.Round(num / 45.0) % 8];
}
}
public static class DiscordPoster
{
private const long MaxUploadBytes = 10485760L;
private static readonly HttpClient Http = new HttpClient
{
Timeout = TimeSpan.FromSeconds(60.0)
};
public static string Post(string file, string uploadName, string caption)
{
string text = Plugin.DiscordWebhookUrl.Value.Trim();
if (text.Length == 0)
{
return null;
}
if (!text.StartsWith("https://discord.com/api/webhooks/") && !text.StartsWith("https://discordapp.com/api/webhooks/"))
{
return "Discord: the webhook link doesn't look like a Discord webhook, so nothing was posted.";
}
try
{
long length = new FileInfo(file).Length;
if (length <= 10485760)
{
using MultipartFormDataContent multipartFormDataContent = new MultipartFormDataContent();
multipartFormDataContent.Add(new StringContent(JsonSerializer.Serialize(new
{
content = caption
})), "payload_json");
ByteArrayContent byteArrayContent = new ByteArrayContent(File.ReadAllBytes(file));
byteArrayContent.Headers.ContentType = new MediaTypeHeaderValue("application/gzip");
multipartFormDataContent.Add(byteArrayContent, "files[0]", uploadName);
using HttpResponseMessage httpResponseMessage = Http.PostAsync(text, multipartFormDataContent).GetAwaiter().GetResult();
return httpResponseMessage.IsSuccessStatusCode ? "Posted to Discord." : $"Discord upload failed ({httpResponseMessage.StatusCode} {httpResponseMessage.ReasonPhrase}).";
}
return $"Discord: the file is {(double)length / 1048576.0:0.0} MB, over Discord's 10 MB limit, so it wasn't posted.";
}
catch (Exception ex)
{
return "Discord upload failed: " + ex.GetBaseException().Message;
}
}
}
public class DumpRunner : MonoBehaviour
{
private const float PollSeconds = 5f;
private float _nextPoll;
private float _nextDump = -1f;
private float _lastDump;
private int _scheduledRepeat;
private bool _dumpedOnce;
private bool _welcomeWarned;
public DumpRunner(IntPtr ptr)
: base(ptr)
{
}
private void Update()
{
//IL_0150: Unknown result type (might be due to invalid IL or missing references)
//IL_0157: Expected O, but got Unknown
//IL_004a: Unknown result type (might be due to invalid IL or missing references)
//IL_0050: Expected O, but got Unknown
//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
//IL_00b8: Expected O, but got Unknown
float realtimeSinceStartup = Time.realtimeSinceStartup;
NodeDumper.Tick();
if (realtimeSinceStartup < _nextPoll)
{
return;
}
_nextPoll = realtimeSinceStartup + 5f;
bool flag = default(bool);
if (_nextDump >= 0f)
{
try
{
Welcome.Poll(realtimeSinceStartup);
}
catch (Exception ex)
{
if (!_welcomeWarned)
{
ManualLogSource logger = Plugin.Logger;
BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(54, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Welcome message failed (further failures not logged): ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<Exception>(ex);
}
logger.LogWarning(val);
}
_welcomeWarned = true;
}
}
try
{
if (_nextDump < 0f)
{
if (NodeDumper.IsWorldReady())
{
_nextDump = realtimeSinceStartup + (float)Math.Max(0, Plugin.DumpDelaySeconds.Value);
ManualLogSource logger2 = Plugin.Logger;
BepInExInfoLogInterpolatedStringHandler val2 = new BepInExInfoLogInterpolatedStringHandler(51, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("Server world is ready. Dumping resource nodes in ");
((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<int>(Plugin.DumpDelaySeconds.Value);
((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("s.");
}
logger2.LogInfo(val2);
}
}
else
{
if (_dumpedOnce && Plugin.RepeatMinutes.Value != _scheduledRepeat)
{
Schedule(_lastDump);
}
if (!(realtimeSinceStartup < _nextDump))
{
NodeDumper.TryStart(null);
_dumpedOnce = true;
Schedule(realtimeSinceStartup);
}
}
}
catch (Exception ex2)
{
ManualLogSource logger3 = Plugin.Logger;
BepInExErrorLogInterpolatedStringHandler val3 = new BepInExErrorLogInterpolatedStringHandler(22, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val3).AppendLiteral("Resource dump failed: ");
((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<Exception>(ex2);
}
logger3.LogError(val3);
int value = Plugin.RepeatMinutes.Value;
_nextDump = ((value > 0 || !_dumpedOnce) ? (realtimeSinceStartup + (float)Math.Max(value, 5) * 60f) : float.MaxValue);
}
}
private void Schedule(float lastDump)
{
_lastDump = lastDump;
_scheduledRepeat = Plugin.RepeatMinutes.Value;
_nextDump = ((_scheduledRepeat > 0) ? (lastDump + (float)_scheduledRepeat * 60f) : float.MaxValue);
}
}
public static class MapZoneReader
{
public class MapZone
{
public string MapType;
public int2? StartChunk;
public int2? ChunkSize;
public float4x4 Projection;
}
public unsafe static List<MapZone> Read(EntityManager em)
{
//IL_012b: Unknown result type (might be due to invalid IL or missing references)
//IL_0132: Expected O, but got Unknown
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//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)
//IL_001a: 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_0029: Unknown result type (might be due to invalid IL or missing references)
//IL_002e: Unknown result type (might be due to invalid IL or missing references)
//IL_0033: Unknown result type (might be due to invalid IL or missing references)
//IL_0038: Unknown result type (might be due to invalid IL or missing references)
//IL_0045: Unknown result type (might be due to invalid IL or missing references)
//IL_004a: Unknown result type (might be due to invalid IL or missing references)
//IL_004e: Unknown result type (might be due to invalid IL or missing references)
//IL_0053: Unknown result type (might be due to invalid IL or missing references)
//IL_0058: Unknown result type (might be due to invalid IL or missing references)
//IL_005c: Unknown result type (might be due to invalid IL or missing references)
//IL_0061: Unknown result type (might be due to invalid IL or missing references)
//IL_006a: 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_0079: Unknown result type (might be due to invalid IL or missing references)
//IL_007b: Unknown result type (might be due to invalid IL or missing references)
//IL_0080: Unknown result type (might be due to invalid IL or missing references)
//IL_0085: Unknown result type (might be due to invalid IL or missing references)
//IL_008e: Unknown result type (might be due to invalid IL or missing references)
//IL_0090: Unknown result type (might be due to invalid IL or missing references)
//IL_009a: 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_00be: Unknown result type (might be due to invalid IL or missing references)
//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
//IL_00d6: 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_00e9: Unknown result type (might be due to invalid IL or missing references)
List<MapZone> list = new List<MapZone>();
try
{
EntityQueryBuilder val = new EntityQueryBuilder(AllocatorHandle.op_Implicit((Allocator)2));
val = ((EntityQueryBuilder)(ref val)).AddAll(ComponentType.ReadOnly(Il2CppType.Of<WorldZoneTextureProjectionMatrix>()));
EntityQueryBuilder val2 = ((EntityQueryBuilder)(ref val)).WithOptions((EntityQueryOptions)2);
EntityQuery val3 = ((EntityManager)(ref em)).CreateEntityQuery(ref val2);
((EntityQueryBuilder)(ref val2)).Dispose();
ComponentType val4 = ComponentType.ReadOnly(Il2CppType.Of<WorldZoneId>());
NativeArray<Entity> val5 = ((EntityQuery)(ref val3)).ToEntityArray(AllocatorHandle.op_Implicit((Allocator)2));
try
{
Enumerator<Entity> enumerator = val5.GetEnumerator();
while (enumerator.MoveNext())
{
Entity current = enumerator.Current;
MapZone mapZone = new MapZone
{
Projection = ((EntityManager)(ref em)).GetComponentData<WorldZoneTextureProjectionMatrix>(current).ProjectionMatrix
};
if (((EntityManager)(ref em)).HasComponent(current, val4))
{
WorldZoneId componentData = ((EntityManager)(ref em)).GetComponentData<WorldZoneId>(current);
mapZone.MapType = ((object)(*(MapType*)(&componentData.MapType))/*cast due to .constrained prefix*/).ToString();
mapZone.StartChunk = new int2((int)componentData.ZoneStartChunk.X, (int)componentData.ZoneStartChunk.Y);
mapZone.ChunkSize = componentData.ZoneChunkSize;
}
list.Add(mapZone);
}
}
finally
{
val5.Dispose();
((EntityQuery)(ref val3)).Dispose();
}
}
catch (Exception ex)
{
ManualLogSource logger = Plugin.Logger;
bool flag = default(bool);
BepInExWarningLogInterpolatedStringHandler val6 = new BepInExWarningLogInterpolatedStringHandler(90, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val6).AppendLiteral("Couldn't read the map projection; the viewer will need manual alignment for the game map. ");
((BepInExLogInterpolatedStringHandler)val6).AppendFormatted<string>(ex.Message);
}
logger.LogWarning(val6);
}
if (list.Count == 0)
{
Plugin.Logger.LogInfo((object)"No map projection found on the server.");
}
return list;
}
public static void Write(Utf8JsonWriter json, List<MapZone> zones)
{
//IL_0051: Unknown result type (might be due to invalid IL or missing references)
//IL_0056: Unknown result type (might be due to invalid IL or missing references)
//IL_0063: 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_00db: Unknown result type (might be due to invalid IL or missing references)
//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
//IL_0104: Unknown result type (might be due to invalid IL or missing references)
//IL_0111: Unknown result type (might be due to invalid IL or missing references)
//IL_0116: Unknown result type (might be due to invalid IL or missing references)
//IL_0093: Unknown result type (might be due to invalid IL or missing references)
//IL_0098: 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_00b1: Unknown result type (might be due to invalid IL or missing references)
//IL_0126: Unknown result type (might be due to invalid IL or missing references)
//IL_012b: Unknown result type (might be due to invalid IL or missing references)
//IL_0134: Unknown result type (might be due to invalid IL or missing references)
//IL_0141: Unknown result type (might be due to invalid IL or missing references)
//IL_014e: Unknown result type (might be due to invalid IL or missing references)
//IL_015b: Unknown result type (might be due to invalid IL or missing references)
json.WriteStartArray("mapZones");
foreach (MapZone zone in zones)
{
json.WriteStartObject();
if (zone.MapType != null)
{
json.WriteString("mapType", zone.MapType);
}
int2? startChunk = zone.StartChunk;
if (startChunk.HasValue)
{
int2 valueOrDefault = startChunk.GetValueOrDefault();
json.WriteStartArray("startChunk");
json.WriteNumberValue(valueOrDefault.x);
json.WriteNumberValue(valueOrDefault.y);
json.WriteEndArray();
}
startChunk = zone.ChunkSize;
if (startChunk.HasValue)
{
int2 valueOrDefault2 = startChunk.GetValueOrDefault();
json.WriteStartArray("chunkSize");
json.WriteNumberValue(valueOrDefault2.x);
json.WriteNumberValue(valueOrDefault2.y);
json.WriteEndArray();
}
json.WriteStartArray("projection");
float4[] array = (float4[])(object)new float4[4]
{
zone.Projection.c0,
zone.Projection.c1,
zone.Projection.c2,
zone.Projection.c3
};
foreach (float4 val in array)
{
json.WriteStartArray();
json.WriteNumberValue(val.x);
json.WriteNumberValue(val.y);
json.WriteNumberValue(val.z);
json.WriteNumberValue(val.w);
json.WriteEndArray();
}
json.WriteEndArray();
json.WriteEndObject();
}
json.WriteEndArray();
}
}
public static class NodeDumper
{
private sealed class DumpJob
{
private const double MillisecondsPerFrame = 5.0;
private readonly List<User> _requesters = new List<User>();
private readonly EntityManager _em;
private readonly PrefabCollectionSystem _prefabs;
private readonly Dictionary<int, string> _names = new Dictionary<int, string>();
private readonly HashSet<Entity> _regionMembers;
private readonly ChainReader _chains;
private readonly double? _serverTime;
private readonly ComponentType _autoChainType = ComponentType.ReadOnly(Il2CppType.Of<AutoChainInstanceData>());
private readonly ComponentType _disabledType = ComponentType.ReadOnly(Il2CppType.Of<Disabled>());
private readonly List<NodeRecord> _nodes = new List<NodeRecord>();
private readonly List<MapZoneReader.MapZone> _mapZones;
private readonly string _gameVersion = Application.version;
private readonly Stopwatch _clock = Stopwatch.StartNew();
private EntityQuery _query;
private NativeArray<Entity> _entities;
private int _next;
private Task<string> _write;
public void AddRequester(User user)
{
//IL_0007: 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_002d: Unknown result type (might be due to invalid IL or missing references)
if (!_requesters.Exists((User u) => u.PlatformId == user.PlatformId))
{
_requesters.Add(user);
}
}
public DumpJob()
{
//IL_001c: 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_002c: 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)
//IL_0074: Unknown result type (might be due to invalid IL or missing references)
//IL_0079: Unknown result type (might be due to invalid IL or missing references)
//IL_008c: Unknown result type (might be due to invalid IL or missing references)
//IL_009d: Unknown result type (might be due to invalid IL or missing references)
//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
//IL_00d1: 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_00eb: Unknown result type (might be due to invalid IL or missing references)
//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
//IL_0105: Unknown result type (might be due to invalid IL or missing references)
//IL_010a: 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_012e: 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_0147: Unknown result type (might be due to invalid IL or missing references)
//IL_014c: Unknown result type (might be due to invalid IL or missing references)
//IL_0151: Unknown result type (might be due to invalid IL or missing references)
//IL_011f: Unknown result type (might be due to invalid IL or missing references)
//IL_0124: Unknown result type (might be due to invalid IL or missing references)
World val = ServerWorld() ?? throw new InvalidOperationException("Server world not found.");
_em = val.EntityManager;
_prefabs = val.GetExistingSystemManaged<PrefabCollectionSystem>();
_regionMembers = CollectSpawnRegionMembers(_em);
_chains = new ChainReader(_em, _prefabs, NameOf);
_serverTime = ServerTimeOf(_em);
_mapZones = MapZoneReader.Read(_em);
EntityQueryBuilder val2 = new EntityQueryBuilder(AllocatorHandle.op_Implicit((Allocator)2));
val2 = ((EntityQueryBuilder)(ref val2)).AddAll(ComponentType.ReadOnly(Il2CppType.Of<EntityCategory>()));
EntityQueryBuilder val3 = ((EntityQueryBuilder)(ref val2)).AddAll(ComponentType.ReadOnly(Il2CppType.Of<PrefabGUID>()));
if (Plugin.IncludeDisabled.Value)
{
val3 = ((EntityQueryBuilder)(ref val3)).WithOptions((EntityQueryOptions)2);
}
_query = ((EntityManager)(ref _em)).CreateEntityQuery(ref val3);
((EntityQueryBuilder)(ref val3)).Dispose();
_entities = ((EntityQuery)(ref _query)).ToEntityArray(AllocatorHandle.op_Implicit((Allocator)4));
}
private string NameOf(PrefabGUID guid)
{
//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)
//IL_0026: Unknown result type (might be due to invalid IL or missing references)
if (_names.TryGetValue(((PrefabGUID)(ref guid)).GuidHash, out var value))
{
return value;
}
PrefabLookupMap prefabLookupMap = _prefabs._PrefabLookupMap;
if (!((PrefabLookupMap)(ref prefabLookupMap)).TryGetName(guid, ref value))
{
value = ((PrefabGUID)(ref guid)).GuidHash.ToString();
}
_names[((PrefabGUID)(ref guid)).GuidHash] = value;
return value;
}
public bool Step()
{
//IL_01a2: Unknown result type (might be due to invalid IL or missing references)
//IL_01a9: Expected O, but got Unknown
//IL_0142: Unknown result type (might be due to invalid IL or missing references)
//IL_0149: Expected O, but got Unknown
bool flag = default(bool);
try
{
if (_write == null)
{
ReadSlice();
if (_next < _entities.Length)
{
return false;
}
ReleaseEntities();
List<NodeRecord> nodes = _nodes;
ChainReader chains = (_chains.Broken ? null : _chains);
List<MapZoneReader.MapZone> zones = _mapZones;
string version = _gameVersion;
bool manual = _requesters.Count > 0;
_write = Task.Run(() => Write(nodes, chains, zones, version, manual));
return false;
}
if (!_write.IsCompleted)
{
return false;
}
string text = (_write.IsFaulted ? "Dump failed. The server log has the details." : $"{_write.Result} ({_clock.Elapsed.TotalSeconds:0.0}s)");
if (_write.IsFaulted)
{
ManualLogSource logger = Plugin.Logger;
BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(22, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Resource dump failed: ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<Exception>(_write.Exception?.GetBaseException());
}
logger.LogError(val);
}
else
{
Plugin.Logger.LogInfo((object)text);
}
Notify(text);
return true;
}
catch (Exception ex)
{
ManualLogSource logger2 = Plugin.Logger;
BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(22, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Resource dump failed: ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<Exception>(ex);
}
logger2.LogError(val);
ReleaseEntities();
Notify("Dump failed. The server log has the details.");
return true;
}
}
private void ReadSlice()
{
//IL_0025: 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_002c: 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)
//IL_0035: 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_0046: Unknown result type (might be due to invalid IL or missing references)
//IL_004a: 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_0050: Unknown result type (might be due to invalid IL or missing references)
//IL_0054: Unknown result type (might be due to invalid IL or missing references)
//IL_005a: Invalid comparison between Unknown and I4
//IL_0060: Unknown result type (might be due to invalid IL or missing references)
//IL_0065: 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)
//IL_006a: 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_0076: Unknown result type (might be due to invalid IL or missing references)
//IL_008a: Unknown result type (might be due to invalid IL or missing references)
//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
//IL_00aa: 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_00b6: 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_00bf: Unknown result type (might be due to invalid IL or missing references)
//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
//IL_00d1: 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_00f1: 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_0137: Unknown result type (might be due to invalid IL or missing references)
//IL_0139: Unknown result type (might be due to invalid IL or missing references)
Stopwatch stopwatch = Stopwatch.StartNew();
while (_next < _entities.Length && stopwatch.Elapsed.TotalMilliseconds < 5.0)
{
Entity val = _entities[_next++];
EntityManager em = _em;
if (!((EntityManager)(ref em)).Exists(val))
{
continue;
}
em = _em;
EntityCategory componentData = ((EntityManager)(ref em)).GetComponentData<EntityCategory>(val);
if ((int)((EntityCategory)(ref componentData)).MainCategory == 1)
{
em = _em;
PrefabGUID componentData2 = ((EntityManager)(ref em)).GetComponentData<PrefabGUID>(val);
ChainReader.ChainInfo? chain = _chains.Read(val);
List<NodeRecord> nodes = _nodes;
NodeRecord obj = new NodeRecord
{
Prefab = NameOf(componentData2),
Guid = ((PrefabGUID)(ref componentData2)).GuidHash,
Position = PositionOf(_em, val)
};
em = _em;
obj.Disabled = ((EntityManager)(ref em)).HasComponent(val, _disabledType);
obj.Source = SourceOf(val, chain, _regionMembers);
obj.Chain = chain;
obj.Yields = YieldsOf(_em, val, NameOf);
double? serverTime = _serverTime;
double? changeIn;
if (serverTime.HasValue)
{
double valueOrDefault = serverTime.GetValueOrDefault();
changeIn = NextChangeOf(_em, val, _autoChainType) - valueOrDefault;
}
else
{
changeIn = null;
}
obj.ChangeIn = changeIn;
nodes.Add(obj);
}
}
}
private void ReleaseEntities()
{
if (_entities.IsCreated)
{
_entities.Dispose();
}
((EntityQuery)(ref _query)).Dispose();
}
private void Notify(string message)
{
//IL_0010: 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_0032: Unknown result type (might be due to invalid IL or missing references)
//IL_0037: 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)
//IL_003e: Unknown result type (might be due to invalid IL or missing references)
foreach (User requester in _requesters)
{
FixedString512Bytes val = FixedString512Bytes.op_Implicit((message.Length > 500) ? message.Substring(0, 500) : message);
ServerChatUtils.SendSystemMessageToClient(_em, requester, ref val);
}
}
}
private class NodeRecord
{
public string Prefab;
public int Guid;
public float3 Position;
public bool Disabled;
public string Source;
public ChainReader.ChainInfo? Chain;
public double? ChangeIn;
public List<YieldRecord> Yields;
}
internal class YieldRecord
{
public string Item;
public int Amount;
}
private static bool _yieldsBroken;
private static bool _spawnRegionsBroken;
private static DumpJob _current;
public static bool Busy => _current != null;
internal static World ServerWorld()
{
Enumerator<World> enumerator = World.s_AllWorlds.GetEnumerator();
while (enumerator.MoveNext())
{
World current = enumerator.Current;
if (current.Name == "Server")
{
return current;
}
}
return null;
}
public static bool IsWorldReady()
{
World val = ServerWorld();
if (val == null || !val.IsCreated)
{
return false;
}
PrefabCollectionSystem existingSystemManaged = val.GetExistingSystemManaged<PrefabCollectionSystem>();
if (existingSystemManaged != null)
{
return existingSystemManaged.GameDataInitialized;
}
return false;
}
public static bool TryStart(User? requester)
{
//IL_0024: Unknown result type (might be due to invalid IL or missing references)
//IL_0029: Unknown result type (might be due to invalid IL or missing references)
//IL_002f: Unknown result type (might be due to invalid IL or missing references)
bool result = _current == null;
if (_current == null)
{
_current = new DumpJob();
}
if (requester.HasValue)
{
User valueOrDefault = requester.GetValueOrDefault();
_current.AddRequester(valueOrDefault);
}
return result;
}
public static void Tick()
{
if (_current != null && _current.Step())
{
_current = null;
}
}
private static double? NextChangeOf(EntityManager em, Entity node, ComponentType autoChainType)
{
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
//IL_0003: 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_0023: 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_000e: 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_003c: 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_0046: 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_0053: Unknown result type (might be due to invalid IL or missing references)
//IL_0054: Unknown result type (might be due to invalid IL or missing references)
//IL_0068: 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)
double nextTransitionAttempt;
if (((EntityManager)(ref em)).HasComponent(node, autoChainType))
{
nextTransitionAttempt = ((EntityManager)(ref em)).GetComponentData<AutoChainInstanceData>(node).NextTransitionAttempt;
}
else
{
if (!((EntityManager)(ref em)).HasComponent(node, ComponentType.ReadOnly(Il2CppType.Of<SpawnChainChild>())))
{
return null;
}
Entity spawnChain = ((EntityManager)(ref em)).GetComponentData<SpawnChainChild>(node).SpawnChain;
if (!((EntityManager)(ref em)).Exists(spawnChain) || !((EntityManager)(ref em)).HasComponent(spawnChain, autoChainType))
{
return null;
}
nextTransitionAttempt = ((EntityManager)(ref em)).GetComponentData<AutoChainInstanceData>(spawnChain).NextTransitionAttempt;
}
if (!(nextTransitionAttempt > 0.0))
{
return null;
}
return nextTransitionAttempt;
}
private static double? ServerTimeOf(EntityManager em)
{
//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_000b: Unknown result type (might be due to invalid IL or missing references)
//IL_0013: Unknown result type (might be due to invalid IL or missing references)
//IL_0018: Unknown result type (might be due to invalid IL or missing references)
//IL_001d: Unknown result type (might be due to invalid IL or missing references)
//IL_0022: Unknown result type (might be due to invalid IL or missing references)
//IL_0027: Unknown result type (might be due to invalid IL or missing references)
//IL_0032: Unknown result type (might be due to invalid IL or missing references)
//IL_0037: Unknown result type (might be due to invalid IL or missing references)
//IL_003c: Unknown result type (might be due to invalid IL or missing references)
//IL_008b: Unknown result type (might be due to invalid IL or missing references)
//IL_0092: Expected O, but got Unknown
//IL_0058: Unknown result type (might be due to invalid IL or missing references)
//IL_005d: Unknown result type (might be due to invalid IL or missing references)
try
{
EntityQueryBuilder val = new EntityQueryBuilder(AllocatorHandle.op_Implicit((Allocator)2));
EntityQueryBuilder val2 = ((EntityQueryBuilder)(ref val)).AddAll(ComponentType.ReadOnly(Il2CppType.Of<ServerTime>()));
EntityQuery val3 = ((EntityManager)(ref em)).CreateEntityQuery(ref val2);
((EntityQueryBuilder)(ref val2)).Dispose();
NativeArray<Entity> val4 = ((EntityQuery)(ref val3)).ToEntityArray(AllocatorHandle.op_Implicit((Allocator)2));
try
{
return (val4.Length > 0) ? new double?(((EntityManager)(ref em)).GetComponentData<ServerTime>(val4[0]).Time) : ((double?)null);
}
finally
{
val4.Dispose();
((EntityQuery)(ref val3)).Dispose();
}
}
catch (Exception ex)
{
ManualLogSource logger = Plugin.Logger;
bool flag = default(bool);
BepInExWarningLogInterpolatedStringHandler val5 = new BepInExWarningLogInterpolatedStringHandler(81, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val5).AppendLiteral("Couldn't read the server clock; the dump won't say when nodes are due to change. ");
((BepInExLogInterpolatedStringHandler)val5).AppendFormatted<string>(ex.Message);
}
logger.LogWarning(val5);
return null;
}
}
internal static float3 PositionOf(EntityManager em, Entity entity)
{
//IL_0002: 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_0027: Unknown result type (might be due to invalid IL or missing references)
//IL_002d: 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_001f: Unknown result type (might be due to invalid IL or missing references)
//IL_0047: Unknown result type (might be due to invalid IL or missing references)
//IL_003b: Unknown result type (might be due to invalid IL or missing references)
//IL_003c: 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)
if (((EntityManager)(ref em)).HasComponent(entity, ComponentType.ReadOnly(Il2CppType.Of<LocalToWorld>())))
{
LocalToWorld componentData = ((EntityManager)(ref em)).GetComponentData<LocalToWorld>(entity);
return ((LocalToWorld)(ref componentData)).Position;
}
if (((EntityManager)(ref em)).HasComponent(entity, ComponentType.ReadOnly(Il2CppType.Of<Translation>())))
{
return ((EntityManager)(ref em)).GetComponentData<Translation>(entity).Value;
}
return float3.zero;
}
private static string SourceOf(Entity entity, ChainReader.ChainInfo? chain, HashSet<Entity> regionMembers)
{
//IL_001f: Unknown result type (might be due to invalid IL or missing references)
if (chain.HasValue && chain.GetValueOrDefault().SpawnerDef >= 0)
{
return "randomizedSpawnChain";
}
if (regionMembers.Contains(entity))
{
return "spawnRegion";
}
if (chain.HasValue)
{
return "spawnChain";
}
return "fixed";
}
private static HashSet<Entity> CollectSpawnRegionMembers(EntityManager em)
{
//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
//IL_00ed: Expected O, but got Unknown
//IL_0010: 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_0023: 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_002d: 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_0037: Unknown result type (might be due to invalid IL or missing references)
//IL_003c: 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_004c: Unknown result type (might be due to invalid IL or missing references)
//IL_0051: Unknown result type (might be due to invalid IL or missing references)
//IL_0056: Unknown result type (might be due to invalid IL or missing references)
//IL_0059: Unknown result type (might be due to invalid IL or missing references)
//IL_005e: 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)
//IL_006d: 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_007b: Unknown result type (might be due to invalid IL or missing references)
//IL_0080: Unknown result type (might be due to invalid IL or missing references)
//IL_0084: Unknown result type (might be due to invalid IL or missing references)
//IL_0089: Unknown result type (might be due to invalid IL or missing references)
//IL_008f: Unknown result type (might be due to invalid IL or missing references)
//IL_0094: Unknown result type (might be due to invalid IL or missing references)
//IL_0096: Unknown result type (might be due to invalid IL or missing references)
//IL_009f: 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_00a6: Unknown result type (might be due to invalid IL or missing references)
//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
HashSet<Entity> hashSet = new HashSet<Entity>();
if (_spawnRegionsBroken)
{
return hashSet;
}
EntityQueryBuilder val = new EntityQueryBuilder(AllocatorHandle.op_Implicit((Allocator)2));
val = ((EntityQueryBuilder)(ref val)).AddAll(ComponentType.ReadOnly(Il2CppType.Of<SpawnRegion>()));
EntityQueryBuilder val2 = ((EntityQueryBuilder)(ref val)).WithOptions((EntityQueryOptions)2);
EntityQuery val3 = ((EntityManager)(ref em)).CreateEntityQuery(ref val2);
((EntityQueryBuilder)(ref val2)).Dispose();
NativeArray<Entity> val4 = ((EntityQuery)(ref val3)).ToEntityArray(AllocatorHandle.op_Implicit((Allocator)2));
try
{
Enumerator<Entity> enumerator = val4.GetEnumerator();
while (enumerator.MoveNext())
{
Entity current = enumerator.Current;
if (!((EntityManager)(ref em)).HasBuffer<SpawnRegionSpawnSlotEntry>(current))
{
continue;
}
Enumerator<SpawnRegionSpawnSlotEntry> enumerator2 = ((EntityManager)(ref em)).GetBuffer<SpawnRegionSpawnSlotEntry>(current, true).GetEnumerator();
while (enumerator2.MoveNext())
{
SpawnRegionSpawnSlotEntry current2 = enumerator2.Current;
if (current2.HasSpawned && current2.Entity != Entity.Null)
{
hashSet.Add(current2.Entity);
}
}
}
}
catch (Exception ex)
{
_spawnRegionsBroken = true;
ManualLogSource logger = Plugin.Logger;
bool flag = default(bool);
BepInExWarningLogInterpolatedStringHandler val5 = new BepInExWarningLogInterpolatedStringHandler(67, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val5).AppendLiteral("Couldn't read spawn regions; nodes from them will show as \"fixed\". ");
((BepInExLogInterpolatedStringHandler)val5).AppendFormatted<string>(ex.Message);
}
logger.LogWarning(val5);
}
finally
{
val4.Dispose();
((EntityQuery)(ref val3)).Dispose();
}
return hashSet;
}
internal static List<YieldRecord> YieldsOf(EntityManager em, Entity entity, Func<PrefabGUID, string> nameOf)
{
//IL_0088: Unknown result type (might be due to invalid IL or missing references)
//IL_008f: Expected O, but got Unknown
//IL_000c: 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)
//IL_0025: 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_002d: 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_0037: Unknown result type (might be due to invalid IL or missing references)
//IL_003c: Unknown result type (might be due to invalid IL or missing references)
//IL_0046: Unknown result type (might be due to invalid IL or missing references)
//IL_0048: Unknown result type (might be due to invalid IL or missing references)
//IL_0058: Unknown result type (might be due to invalid IL or missing references)
if (_yieldsBroken)
{
return null;
}
try
{
if (!((EntityManager)(ref em)).HasBuffer<YieldResourcesOnDamageTaken>(entity))
{
return null;
}
List<YieldRecord> list = new List<YieldRecord>();
Enumerator<YieldResourcesOnDamageTaken> enumerator = ((EntityManager)(ref em)).GetBuffer<YieldResourcesOnDamageTaken>(entity, true).GetEnumerator();
while (enumerator.MoveNext())
{
YieldResourcesOnDamageTaken current = enumerator.Current;
list.Add(new YieldRecord
{
Item = nameOf(current.ItemType),
Amount = current.Amount
});
}
return list;
}
catch (Exception ex)
{
_yieldsBroken = true;
ManualLogSource logger = Plugin.Logger;
bool flag = default(bool);
BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(54, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Couldn't read node yields; dumps will not list items. ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(ex.Message);
}
logger.LogWarning(val);
return null;
}
}
private static string OutputFolder()
{
string text = Plugin.OutputFolder.Value.Trim();
if (text.Length == 0)
{
return Path.Combine(Plugin.DataRoot, "ResourceMap");
}
if (text.StartsWith("\\") && !text.StartsWith("\\\\"))
{
text = "\\" + text;
}
return text;
}
private static void PruneOldDumps(string folder)
{
//IL_0065: Unknown result type (might be due to invalid IL or missing references)
//IL_006c: Expected O, but got Unknown
int value = Plugin.KeepDumps.Value;
if (value <= 0)
{
return;
}
string[] array = new string[2] { "nodes-????????-??????.json", "nodes-????????-??????.json.gz" };
bool flag = default(bool);
foreach (string searchPattern in array)
{
string[] files = Directory.GetFiles(folder, searchPattern);
Array.Sort(files, (IComparer<string>?)StringComparer.Ordinal);
for (int j = 0; j < files.Length - value; j++)
{
try
{
File.Delete(files[j]);
}
catch (Exception ex)
{
ManualLogSource logger = Plugin.Logger;
BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(27, 2, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Couldn't delete old dump ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(files[j]);
((BepInExLogInterpolatedStringHandler)val).AppendLiteral(": ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(ex.Message);
}
logger.LogWarning(val);
}
}
}
}
private static void Compress(string source, string target)
{
string text = target + ".tmp";
using (FileStream fileStream = File.OpenRead(source))
{
using FileStream stream = File.Create(text);
using GZipStream destination = new GZipStream(stream, CompressionLevel.Optimal);
fileStream.CopyTo(destination);
}
File.Move(text, target, overwrite: true);
}
private static string Write(List<NodeRecord> nodes, ChainReader chains, List<MapZoneReader.MapZone> mapZones, string gameVersion, bool manual)
{
string text = OutputFolder();
Directory.CreateDirectory(text);
DateTime now = DateTime.Now;
string text2 = Path.Combine(text, $"nodes-{now:yyyyMMdd-HHmmss}.json");
string text3 = text2 + ".tmp";
using (FileStream utf8Json = File.Create(text3))
{
using Utf8JsonWriter utf8JsonWriter = new Utf8JsonWriter((Stream)utf8Json, new JsonWriterOptions
{
Indented = false
});
utf8JsonWriter.WriteStartObject();
utf8JsonWriter.WriteString("plugin", "ResourceMap 1.0.2");
utf8JsonWriter.WriteString("gameVersion", gameVersion);
utf8JsonWriter.WriteString("dumpedAt", now.ToString("o"));
utf8JsonWriter.WriteNumber("count", nodes.Count);
utf8JsonWriter.WriteStartArray("nodes");
foreach (NodeRecord node in nodes)
{
utf8JsonWriter.WriteStartObject();
utf8JsonWriter.WriteString("prefab", node.Prefab);
utf8JsonWriter.WriteNumber("guid", node.Guid);
utf8JsonWriter.WriteNumber("x", MathF.Round(node.Position.x, 2));
utf8JsonWriter.WriteNumber("y", MathF.Round(node.Position.y, 2));
utf8JsonWriter.WriteNumber("z", MathF.Round(node.Position.z, 2));
utf8JsonWriter.WriteString("source", node.Source);
if (chains != null)
{
ChainReader.ChainInfo? chain = node.Chain;
if (chain.HasValue)
{
ChainReader.ChainInfo valueOrDefault = chain.GetValueOrDefault();
utf8JsonWriter.WriteNumber("spot", valueOrDefault.SpotId);
if (valueOrDefault.ChainDef >= 0)
{
utf8JsonWriter.WriteNumber("chain", valueOrDefault.ChainDef);
}
utf8JsonWriter.WriteNumber("stage", valueOrDefault.Element);
if (valueOrDefault.SpawnerDef >= 0)
{
utf8JsonWriter.WriteNumber("spawner", valueOrDefault.SpawnerDef);
}
if (valueOrDefault.SpawnerId >= 0)
{
utf8JsonWriter.WriteNumber("spawnerSpot", valueOrDefault.SpawnerId);
}
}
}
if (node.Disabled)
{
utf8JsonWriter.WriteBoolean("disabled", value: true);
}
double? changeIn = node.ChangeIn;
if (changeIn.HasValue)
{
double valueOrDefault2 = changeIn.GetValueOrDefault();
utf8JsonWriter.WriteNumber("changeIn", Math.Round(valueOrDefault2));
}
List<YieldRecord> yields = node.Yields;
if (yields != null && yields.Count > 0)
{
utf8JsonWriter.WriteStartArray("yields");
foreach (YieldRecord yield in node.Yields)
{
utf8JsonWriter.WriteStartObject();
utf8JsonWriter.WriteString("item", yield.Item);
utf8JsonWriter.WriteNumber("amount", yield.Amount);
utf8JsonWriter.WriteEndObject();
}
utf8JsonWriter.WriteEndArray();
}
utf8JsonWriter.WriteEndObject();
}
utf8JsonWriter.WriteEndArray();
if (chains != null)
{
WriteChains(utf8JsonWriter, chains);
}
if (mapZones.Count > 0)
{
MapZoneReader.Write(utf8JsonWriter, mapZones);
}
utf8JsonWriter.WriteEndObject();
}
bool flag = Plugin.DataRoot != Paths.BepInExRootPath;
string source = text3;
if (!flag)
{
File.Move(text3, text2);
source = text2;
string text4 = Path.Combine(text, "nodes-latest.json.tmp");
File.Copy(text2, text4, overwrite: true);
File.Move(text4, Path.Combine(text, "nodes-latest.json"), overwrite: true);
}
string text5 = Path.Combine(text, "nodes-latest.json.gz");
Compress(source, text5);
if (flag)
{
File.Copy(text5, text2 + ".gz", overwrite: true);
File.Delete(text3);
}
PruneOldDumps(text);
string text6 = $"Wrote {nodes.Count} resource nodes to {(flag ? (text2 + ".gz") : text2)}";
if (manual || Plugin.PostAutomaticDumps.Value)
{
string caption = $"Resource dump: {nodes.Count:N0} nodes · game {gameVersion} · {now:yyyy-MM-dd HH:mm}";
string text7 = DiscordPoster.Post(text5, Path.GetFileName(text2) + ".gz", caption);
if (text7 != null)
{
text6 = text6 + " " + text7;
}
}
return text6;
}
private static void WriteChains(Utf8JsonWriter json, ChainReader chains)
{
json.WriteStartArray("chains");
foreach (ChainReader.ChainDef chain in chains.Chains)
{
json.WriteStartObject();
if (chain.Name != null)
{
json.WriteString("name", chain.Name);
}
json.WriteNumber("main", chain.Main);
json.WriteStartArray("stages");
foreach (ChainReader.ChainElementDef element in chain.Elements)
{
json.WriteStartObject();
json.WriteString("name", element.Name);
if (element.Prefab != null)
{
json.WriteString("prefab", element.Prefab);
}
if (element.AfterSeconds > 0f)
{
json.WriteNumber("afterSeconds", MathF.Round(element.AfterSeconds, 1));
}
json.WriteEndObject();
}
json.WriteEndArray();
json.WriteEndObject();
}
json.WriteEndArray();
json.WriteStartArray("spawners");
foreach (ChainReader.SpawnerDef spawner in chains.Spawners)
{
json.WriteStartObject();
json.WriteString("name", spawner.Name);
json.WriteStartArray("options");
foreach (ChainReader.SpawnerOptionDef option in spawner.Options)
{
json.WriteStartObject();
json.WriteString("chainName", option.Chain);
if (option.ChainDef >= 0)
{
json.WriteNumber("chain", option.ChainDef);
}
json.WriteNumber("chance", MathF.Round(option.Chance, 4));
json.WriteEndObject();
}
json.WriteEndArray();
json.WriteEndObject();
}
json.WriteEndArray();
}
}
[BepInPlugin("community.vrising.resourcemap", "ResourceMap", "1.0.2")]
[BepInProcess("VRisingServer.exe")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class Plugin : BasePlugin
{
public const string Guid = "community.vrising.resourcemap";
public const string Name = "ResourceMap";
public const string Version = "1.0.2";
private const string VcfGuid = "gg.deca.VampireCommandFramework";
private const string ConfigFileName = "Prospector.cfg";
internal static Plugin Instance;
internal static ManualLogSource Logger;
internal static string DataRoot;
internal static ConfigFile Settings;
internal static ConfigEntry<int> DumpDelaySeconds;
internal static ConfigEntry<int> RepeatMinutes;
internal static ConfigEntry<bool> IncludeDisabled;
internal static ConfigEntry<string> OutputFolder;
internal static ConfigEntry<bool> FindEnabled;
internal static ConfigEntry<bool> FindAdminOnly;
internal static ConfigEntry<int> FindMaxRange;
internal static ConfigEntry<int> FindCooldownSeconds;
internal static ConfigEntry<string> WelcomeMessage;
internal static ConfigEntry<int> KeepDumps;
internal static ConfigEntry<string> DiscordWebhookUrl;
internal static ConfigEntry<bool> PostAutomaticDumps;
internal static bool CommandsAvailable;
public override void Load()
{
//IL_003f: Unknown result type (might be due to invalid IL or missing references)
//IL_0049: Expected O, but got Unknown
//IL_022b: Unknown result type (might be due to invalid IL or missing references)
//IL_0231: Expected O, but got Unknown
Instance = this;
Logger = ((BasePlugin)this).Log;
DataRoot = ResolveDataRoot();
string text = Path.Combine(DataRoot, "config", "Prospector.cfg");
MigrateOldConfig(text);
Settings = new ConfigFile(text, false, MetadataHelper.GetMetadata((object)this));
InstallBundledConfig();
DumpDelaySeconds = Settings.Bind<int>("Dump", "DelaySeconds", 60, "Seconds to wait after the world has loaded before the first dump, so spawned nodes have time to appear.");
RepeatMinutes = Settings.Bind<int>("Dump", "RepeatMinutes", 0, "Dump again every N minutes (0 = only once per server start). Admins can also dump any time with .rmap dump.");
IncludeDisabled = Settings.Bind<bool>("Dump", "IncludeDisabled", true, "Also record nodes the game has switched off for now (for example in an inactive area). They are flagged in the output.");
OutputFolder = Settings.Bind<string>("Output", "Folder", "", "Where dump files are written. Leave empty to use BepInEx/ResourceMap. A network share works, e.g. //nas/ResourceMap.");
KeepDumps = Settings.Bind<int>("Output", "KeepDumps", 10, "How many timestamped dumps to keep in the folder; older ones are deleted after each dump. 0 = keep all. nodes-latest.json is always kept.");
DiscordWebhookUrl = Settings.Bind<string>("Discord", "WebhookUrl", "", "Discord webhook link. When set, each dump's compressed copy (nodes-latest.json.gz) is posted to that channel. Keep it private: anyone with the link can post there. Leave empty to turn it off.");
PostAutomaticDumps = Settings.Bind<bool>("Discord", "PostAutomaticDumps", true, "Also post dumps made at server start and by RepeatMinutes. When false, only .rmap dump posts to Discord.");
WelcomeMessage = Settings.Bind<string>("Commands", "WelcomeMessage", "Type .rmap help to see the resource map commands.", "Private message each player gets shortly after joining. Leave empty to turn it off. Only sent when the chat commands are available.");
FindEnabled = Settings.Bind<bool>("Commands", "FindEnabled", true, "Allow the .rmap find chat command (needs VampireCommandFramework).");
FindAdminOnly = Settings.Bind<bool>("Commands", "FindAdminOnly", true, "Only admins can use .rmap find. Set to false to let every player use it.");
FindMaxRange = Settings.Bind<int>("Commands", "FindMaxRange", 300, "Furthest distance (in meters) .rmap find searches around the player. 0 = no limit.");
FindCooldownSeconds = Settings.Bind<int>("Commands", "FindCooldownSeconds", 10, "Seconds a player must wait between searches. Admins are exempt.");
if (((BaseChainloader<BasePlugin>)(object)IL2CPPChainloader.Instance).Plugins.ContainsKey("gg.deca.VampireCommandFramework"))
{
RegisterCommands();
CommandsAvailable = true;
((BasePlugin)this).Log.LogInfo((object)"Chat commands registered: .rmap help, .rmap find, .rmap mark, .rmap dump, .rmap reload");
}
else
{
((BasePlugin)this).Log.LogInfo((object)"VampireCommandFramework isn't installed, so chat commands are off.");
}
((BasePlugin)this).AddComponent<DumpRunner>();
ManualLogSource log = ((BasePlugin)this).Log;
bool flag = default(bool);
BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(48, 3, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("ResourceMap");
((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("1.0.2");
((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" loaded. First dump ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(DumpDelaySeconds.Value);
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("s after the world is ready.");
}
log.LogInfo(val);
}
private void InstallBundledConfig()
{
//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
//IL_00bf: Expected O, but got Unknown
//IL_0088: Unknown result type (might be due to invalid IL or missing references)
//IL_008e: Expected O, but got Unknown
bool flag = default(bool);
try
{
string configFilePath = Settings.ConfigFilePath;
string text = Path.Combine(Path.GetDirectoryName(typeof(Plugin).Assembly.Location) ?? "", "Prospector.cfg.template");
if ((!File.Exists(configFilePath) || !File.ReadAllText(configFilePath).Contains('=')) && File.Exists(text))
{
Directory.CreateDirectory(Path.GetDirectoryName(configFilePath));
File.Copy(text, configFilePath, overwrite: true);
Settings.Reload();
ManualLogSource log = ((BasePlugin)this).Log;
BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(42, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("First start: copied the bundled config to ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(configFilePath);
}
log.LogInfo(val);
}
}
catch (Exception ex)
{
ManualLogSource log2 = ((BasePlugin)this).Log;
BepInExWarningLogInterpolatedStringHandler val2 = new BepInExWarningLogInterpolatedStringHandler(58, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("Couldn't copy the bundled config; using defaults instead. ");
((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(ex.Message);
}
log2.LogWarning(val2);
}
}
private void MigrateOldConfig(string configPath)
{
//IL_008d: Unknown result type (might be due to invalid IL or missing references)
//IL_0094: Expected O, but got Unknown
//IL_0038: Unknown result type (might be due to invalid IL or missing references)
//IL_003e: Expected O, but got Unknown
bool flag = default(bool);
try
{
string text = Path.Combine(Path.GetDirectoryName(configPath), "community.vrising.resourcemap.cfg");
if (!File.Exists(configPath) && File.Exists(text))
{
File.Move(text, configPath);
ManualLogSource log = ((BasePlugin)this).Log;
BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(53, 2, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Renamed the config from ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(Path.GetFileName(text));
((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" to ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("Prospector.cfg");
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("; your settings are kept.");
}
log.LogInfo(val);
}
}
catch (Exception ex)
{
ManualLogSource log2 = ((BasePlugin)this).Log;
BepInExWarningLogInterpolatedStringHandler val2 = new BepInExWarningLogInterpolatedStringHandler(36, 2, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("Couldn't rename the old config to ");
((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>("Prospector.cfg");
((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(". ");
((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(ex.Message);
}
log2.LogWarning(val2);
}
}
private static string ResolveDataRoot()
{
string bepInExRootPath = Paths.BepInExRootPath;
string directoryName = Path.GetDirectoryName(bepInExRootPath.TrimEnd(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar));
string text = ((directoryName == null) ? null : Path.Combine(directoryName, "BepInEx"));
if (!string.Equals(Path.GetFileName(bepInExRootPath.TrimEnd(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar)), "BepInEx_Server", StringComparison.OrdinalIgnoreCase) || !Directory.Exists(text))
{
return bepInExRootPath;
}
return text;
}
private static void RegisterCommands()
{
Commands.Register();
}
}
public static class Welcome
{
private const float DelaySeconds = 10f;
private static readonly HashSet<ulong> Connected = new HashSet<ulong>();
private static readonly Dictionary<ulong, (float sendAt, User user)> Pending = new Dictionary<ulong, (float, User)>();
public static void Poll(float now)
{
//IL_000b: Unknown result type (might be due to invalid IL or missing references)
//IL_0010: 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_001c: 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_002a: Unknown result type (might be due to invalid IL or missing references)
//IL_002f: Unknown result type (might be due to invalid IL or missing references)
//IL_0034: 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)
//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_004e: Unknown result type (might be due to invalid IL or missing references)
//IL_0052: Unknown result type (might be due to invalid IL or missing references)
//IL_0057: Unknown result type (might be due to invalid IL or missing references)
//IL_005d: Unknown result type (might be due to invalid IL or missing references)
//IL_0062: Unknown result type (might be due to invalid IL or missing references)
//IL_0066: Unknown result type (might be due to invalid IL or missing references)
//IL_0068: 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_006f: Unknown result type (might be due to invalid IL or missing references)
//IL_00b1: 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_007d: Unknown result type (might be due to invalid IL or missing references)
//IL_0090: Unknown result type (might be due to invalid IL or missing references)
//IL_009e: Unknown result type (might be due to invalid IL or missing references)
//IL_0178: 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_019e: Unknown result type (might be due to invalid IL or missing references)
//IL_01a3: Unknown result type (might be due to invalid IL or missing references)
//IL_01a5: Unknown result type (might be due to invalid IL or missing references)
//IL_01a6: Unknown result type (might be due to invalid IL or missing references)
World val = NodeDumper.ServerWorld();
if (val == null)
{
return;
}
EntityManager entityManager = val.EntityManager;
EntityQueryBuilder val2 = new EntityQueryBuilder(AllocatorHandle.op_Implicit((Allocator)2));
EntityQueryBuilder val3 = ((EntityQueryBuilder)(ref val2)).AddAll(ComponentType.ReadOnly(Il2CppType.Of<User>()));
EntityQuery val4 = ((EntityManager)(ref entityManager)).CreateEntityQuery(ref val3);
((EntityQueryBuilder)(ref val3)).Dispose();
NativeArray<Entity> val5 = ((EntityQuery)(ref val4)).ToEntityArray(AllocatorHandle.op_Implicit((Allocator)2));
try
{
Enumerator<Entity> enumerator = val5.GetEnumerator();
while (enumerator.MoveNext())
{
Entity current = enumerator.Current;
User componentData = ((EntityManager)(ref entityManager)).GetComponentData<User>(current);
if (componentData.IsConnected)
{
if (Connected.Add(componentData.PlatformId))
{
Pending[componentData.PlatformId] = (now + 10f, componentData);
}
}
else
{
Connected.Remove(componentData.PlatformId);
Pending.Remove(componentData.PlatformId);
}
}
}
finally
{
val5.Dispose();
((EntityQuery)(ref val4)).Dispose();
}
string text = Plugin.WelcomeMessage.Value.Trim();
List<ulong> list = new List<ulong>();
foreach (var (item, tuple2) in Pending)
{
if (now >= tuple2.Item1)
{
list.Add(item);
}
}
foreach (ulong item3 in list)
{
User item2 = Pending[item3].user;
Pending.Remove(item3);
if (text.Length != 0 && Plugin.CommandsAvailable)
{
FixedString512Bytes val6 = FixedString512Bytes.op_Implicit(text);
ServerChatUtils.SendSystemMessageToClient(entityManager, item2, ref val6);
}
}
}
}
}