using System;
using System.Collections;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text.Json;
using System.Text.Json.Serialization;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using BepInEx.Unity.IL2CPP.Utils.Collections;
using HarmonyLib;
using Il2CppInterop.Runtime;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppSystem;
using Microsoft.CodeAnalysis;
using ProjectM;
using ProjectM.CastleBuilding;
using ProjectM.Gameplay.Systems;
using ProjectM.Gameplay.WarEvents;
using ProjectM.Network;
using ProjectM.Physics;
using ProjectM.Scripting;
using ProjectM.Shared;
using ProjectM.Tiles;
using ScarletCore.Data;
using ScarletCore.Events;
using ScarletCore.Patches;
using ScarletCore.Services;
using ScarletCore.Systems;
using ScarletCore.Utils;
using Stunlock.Core;
using Stunlock.Network;
using Unity.Collections;
using Unity.Entities;
using Unity.Mathematics;
using Unity.Transforms;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("markvaaz")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Framework and utilities for all Scarlet mods in V Rising")]
[assembly: AssemblyFileVersion("1.3.11.0")]
[assembly: AssemblyInformationalVersion("1.3.11+9a7a38b9288c12fb8849ee699b0a30e3d644173f")]
[assembly: AssemblyProduct("ScarletCore")]
[assembly: AssemblyTitle("ScarletCore")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.3.11.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
internal sealed class NullableAttribute : Attribute
{
public readonly byte[] NullableFlags;
public NullableAttribute(byte P_0)
{
NullableFlags = new byte[1] { P_0 };
}
public NullableAttribute(byte[] P_0)
{
NullableFlags = P_0;
}
}
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
internal sealed class NullableContextAttribute : Attribute
{
public readonly byte Flag;
public NullableContextAttribute(byte P_0)
{
Flag = P_0;
}
}
[CompilerGenerated]
[Microsoft.CodeAnalysis.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 ScarletCore
{
public static class ECSExtensions
{
public delegate void WithRefHandler<T>(ref T item);
public static EntityManager EntityManager => GameSystems.Server.EntityManager;
public static void With<T>(this Entity entity, WithRefHandler<T> action) where T : struct
{
//IL_0001: 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_0016: Unknown result type (might be due to invalid IL or missing references)
//IL_0019: Unknown result type (might be due to invalid IL or missing references)
T item = entity.Read<T>();
action(ref item);
EntityManager entityManager = EntityManager;
((EntityManager)(ref entityManager)).SetComponentData<T>(entity, item);
}
public static void AddWith<T>(this Entity entity, WithRefHandler<T> action) where T : struct
{
//IL_0001: 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_000f: Unknown result type (might be due to invalid IL or missing references)
if (!entity.Has<T>())
{
entity.Add<T>();
}
entity.With(action);
}
public static void HasWith<T>(this Entity entity, WithRefHandler<T> action) where T : struct
{
//IL_0001: 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)
if (entity.Has<T>())
{
entity.With(action);
}
}
public static void Write<T>(this Entity entity, T componentData) where T : struct
{
//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)
EntityManager entityManager = EntityManager;
((EntityManager)(ref entityManager)).SetComponentData<T>(entity, componentData);
}
public static T Read<T>(this Entity entity) where T : struct
{
//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)
EntityManager entityManager = EntityManager;
return ((EntityManager)(ref entityManager)).GetComponentData<T>(entity);
}
public static DynamicBuffer<T> ReadBuffer<T>(this Entity entity) where T : struct
{
//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_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_0013: Unknown result type (might be due to invalid IL or missing references)
EntityManager entityManager = EntityManager;
return ((EntityManager)(ref entityManager)).GetBuffer<T>(entity, false);
}
public static DynamicBuffer<T> AddBuffer<T>(this Entity entity) where T : struct
{
//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_000f: 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)
EntityManager entityManager = EntityManager;
return ((EntityManager)(ref entityManager)).AddBuffer<T>(entity);
}
public static bool TryGetComponent<T>(this Entity entity, out T componentData) where T : struct
{
//IL_0008: 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)
componentData = default(T);
if (entity.Has<T>())
{
componentData = entity.Read<T>();
return true;
}
return false;
}
public static bool Has<T>(this Entity entity) where T : struct
{
//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_0010: Unknown result type (might be due to invalid IL or missing references)
EntityManager entityManager = EntityManager;
return ((EntityManager)(ref entityManager)).HasComponent(entity, new ComponentType(Il2CppType.Of<T>(), (AccessMode)0));
}
public static void Add<T>(this Entity entity) where T : struct
{
//IL_0001: 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_0013: 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_001d: Unknown result type (might be due to invalid IL or missing references)
if (!entity.Has<T>())
{
EntityManager entityManager = EntityManager;
((EntityManager)(ref entityManager)).AddComponent(entity, new ComponentType(Il2CppType.Of<T>(), (AccessMode)0));
}
}
public static void Remove<T>(this Entity entity) where T : struct
{
//IL_0001: 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_0010: 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_001a: Unknown result type (might be due to invalid IL or missing references)
if (entity.Has<T>())
{
EntityManager entityManager = EntityManager;
((EntityManager)(ref entityManager)).RemoveComponent(entity, new ComponentType(Il2CppType.Of<T>(), (AccessMode)0));
}
}
public static bool TryGetPlayer(this Entity entity, out Entity player)
{
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
//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_0018: Unknown result type (might be due to invalid IL or missing references)
//IL_0019: Unknown result type (might be due to invalid IL or missing references)
player = Entity.Null;
if (entity.Has<PlayerCharacter>())
{
player = entity;
return true;
}
return false;
}
public static bool IsPlayer(this Entity entity)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
if (entity.Has<PlayerCharacter>())
{
return true;
}
return false;
}
public static bool TryGetAttached(this Entity entity, out Entity attached)
{
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
//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_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_002a: 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)
attached = Entity.Null;
if (entity.TryGetComponent<Attach>(out Attach componentData) && componentData.Parent.Exists())
{
attached = componentData.Parent;
return true;
}
return false;
}
public static bool TryGetTeamEntity(this Entity entity, out Entity teamEntity)
{
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
//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_0019: 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_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_0032: Unknown result type (might be due to invalid IL or missing references)
teamEntity = Entity.Null;
if (entity.TryGetComponent<TeamReference>(out TeamReference componentData))
{
Entity value = componentData.Value._Value;
if (value.Exists())
{
teamEntity = value;
return true;
}
}
return false;
}
public static Entity GetUserEntity(this Entity entity)
{
//IL_0001: 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_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_0013: 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_0020: 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)
if (entity.TryGetComponent<PlayerCharacter>(out PlayerCharacter componentData))
{
return componentData.UserEntity;
}
if (entity.Has<User>())
{
return entity;
}
return Entity.Null;
}
public static bool Exists(this Entity entity)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0009: Unknown result type (might be due to invalid IL or missing references)
//IL_000e: Unknown result type (might be due to invalid IL or missing references)
//IL_0011: Unknown result type (might be due to invalid IL or missing references)
int result;
if (!entity.IsNull())
{
EntityManager entityManager = EntityManager;
result = (((EntityManager)(ref entityManager)).Exists(entity) ? 1 : 0);
}
else
{
result = 0;
}
return (byte)result != 0;
}
public static bool IsNull(this Entity entity)
{
//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)
Entity @null = Entity.Null;
return ((Entity)(ref @null)).Equals(entity);
}
public static bool IsDisabled(this Entity entity)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
return entity.Has<Disabled>();
}
public static PrefabGUID GetPrefabGuid(this Entity entity)
{
//IL_0001: 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_0016: 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_0019: Unknown result type (might be due to invalid IL or missing references)
if (entity.TryGetComponent<PrefabGUID>(out PrefabGUID componentData))
{
return componentData;
}
return PrefabGUID.Empty;
}
public static int GetGuidHash(this Entity entity)
{
//IL_0001: 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)
if (entity.TryGetComponent<PrefabGUID>(out PrefabGUID componentData))
{
return ((PrefabGUID)(ref componentData)).GuidHash;
}
PrefabGUID empty = PrefabGUID.Empty;
return ((PrefabGUID)(ref empty)).GuidHash;
}
public static Entity GetOwner(this Entity entity)
{
//IL_0001: 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_000c: Unknown result type (might be due to invalid IL or missing references)
//IL_0026: Unknown result type (might be due to invalid IL or missing references)
//IL_002b: Unknown result type (might be due to invalid IL or missing references)
//IL_001d: Unknown result type (might be due to invalid IL or missing references)
//IL_001e: Unknown result type (might be due to invalid IL or missing references)
//IL_0023: Unknown result type (might be due to invalid IL or missing references)
//IL_002e: Unknown result type (might be due to invalid IL or missing references)
if (entity.TryGetComponent<EntityOwner>(out EntityOwner componentData) && componentData.Owner.Exists())
{
return componentData.Owner;
}
return Entity.Null;
}
public static bool HasBuff(this Entity entity, PrefabGUID buffPrefabGuid)
{
//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_000c: Unknown result type (might be due to invalid IL or missing references)
ServerGameManager serverGameManager = GameSystems.ServerGameManager;
return ((ServerGameManager)(ref serverGameManager)).HasBuff(entity, ((PrefabGUID)(ref buffPrefabGuid)).ToIdentifier());
}
public static bool TryGetBuffer<T>(this Entity entity, out DynamicBuffer<T> dynamicBuffer) where T : struct
{
//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_001a: Unknown result type (might be due to invalid IL or missing references)
ServerGameManager serverGameManager = GameSystems.ServerGameManager;
if (((ServerGameManager)(ref serverGameManager)).TryGetBuffer<T>(entity, ref dynamicBuffer))
{
return true;
}
dynamicBuffer = default(DynamicBuffer<T>);
return false;
}
public static float3 AimPosition(this Entity entity)
{
//IL_0001: 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_000e: Unknown result type (might be due to invalid IL or missing references)
//IL_000f: Unknown result type (might be due to invalid IL or missing references)
//IL_0014: 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)
if (entity.TryGetComponent<EntityInput>(out EntityInput componentData))
{
return componentData.AimPosition;
}
return float3.zero;
}
public static float3 Position(this Entity entity)
{
//IL_0001: 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_000e: Unknown result type (might be due to invalid IL or missing references)
//IL_000f: Unknown result type (might be due to invalid IL or missing references)
//IL_0014: 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)
if (entity.TryGetComponent<Translation>(out Translation componentData))
{
return componentData.Value;
}
return float3.zero;
}
public static int2 GetTileCoord(this Entity entity)
{
//IL_0001: 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_000e: Unknown result type (might be due to invalid IL or missing references)
//IL_000f: Unknown result type (might be due to invalid IL or missing references)
//IL_0014: 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)
if (entity.TryGetComponent<TilePosition>(out TilePosition componentData))
{
return componentData.Tile;
}
return int2.zero;
}
public static int GetUnitLevel(this Entity entity)
{
//IL_0001: 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_000f: Unknown result type (might be due to invalid IL or missing references)
if (entity.TryGetComponent<UnitLevel>(out UnitLevel componentData))
{
return componentData.Level._Value;
}
return 0;
}
public static void Destroy(this Entity entity, bool immediate = false)
{
//IL_0001: 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_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)
if (entity.Exists())
{
if (immediate)
{
EntityManager entityManager = EntityManager;
((EntityManager)(ref entityManager)).DestroyEntity(entity);
}
else
{
DestroyUtility.Destroy(EntityManager, entity, (DestroyDebugReason)0, (string)null, 0);
}
}
}
public static void SetTeam(this Entity entity, Entity teamSource)
{
//IL_0001: 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_0011: 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_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_003d: 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_004e: 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_001b: Unknown result type (might be due to invalid IL or missing references)
if (entity.Has<Team>() && entity.Has<TeamReference>() && teamSource.TryGetComponent<Team>(out Team componentData) && teamSource.TryGetComponent<TeamReference>(out TeamReference componentData2))
{
Entity teamRefEntity = componentData2.Value._Value;
int teamId = componentData.Value;
entity.With<TeamReference>((WithRefHandler<TeamReference>)delegate(ref TeamReference teamReference)
{
//IL_0008: 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)
teamReference.Value._Value = teamRefEntity;
});
entity.With<Team>((WithRefHandler<Team>)delegate(ref Team team)
{
team.Value = teamId;
});
}
}
public static void SetPosition(this Entity entity, float3 position)
{
//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_000e: 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_0019: 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)
if (entity.Has<Translation>())
{
entity.With<Translation>((WithRefHandler<Translation>)delegate(ref Translation translation)
{
//IL_0003: 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)
translation.Value = position;
});
}
if (entity.Has<LastTranslation>())
{
entity.With<LastTranslation>((WithRefHandler<LastTranslation>)delegate(ref LastTranslation lastTranslation)
{
//IL_0003: 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)
lastTranslation.Value = position;
});
}
}
public static void SetFaction(this Entity entity, PrefabGUID factionPrefabGuid)
{
//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_000e: Unknown result type (might be due to invalid IL or missing references)
//IL_0019: Unknown result type (might be due to invalid IL or missing references)
if (entity.Has<FactionReference>())
{
entity.With<FactionReference>((WithRefHandler<FactionReference>)delegate(ref FactionReference factionReference)
{
//IL_0008: 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)
factionReference.FactionGuid._Value = factionPrefabGuid;
});
}
}
public static bool IsAllies(this Entity entity, Entity player)
{
//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)
ServerGameManager serverGameManager = GameSystems.ServerGameManager;
return ((ServerGameManager)(ref serverGameManager)).IsAllies(entity, player);
}
public static bool IsPlayerOwned(this Entity entity)
{
//IL_0001: 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_000f: Unknown result type (might be due to invalid IL or missing references)
if (entity.TryGetComponent<EntityOwner>(out EntityOwner componentData))
{
return componentData.Owner.IsPlayer();
}
return false;
}
public static Entity GetBuffTarget(this Entity entity)
{
//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_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_000f: Unknown result type (might be due to invalid IL or missing references)
return CreateGameplayEventServerUtility.GetBuffTarget(EntityManager, entity);
}
}
public static class PlayerDataExtensions
{
public static PlayerData GetPlayerData(this string playerName)
{
PlayerData playerData;
return PlayerService.TryGetByName(playerName, out playerData) ? playerData : null;
}
public static PlayerData GetPlayerData(this ulong playerId)
{
PlayerData playerData;
return PlayerService.TryGetById(playerId, out playerData) ? playerData : null;
}
public static PlayerData GetPlayerData(this Entity entity)
{
//IL_0001: 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_000c: 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_0032: 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_003a: 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_0048: Unknown result type (might be due to invalid IL or missing references)
PlayerData playerData;
if (entity.Has<User>())
{
return PlayerService.TryGetById(entity.Read<User>().PlatformId, out playerData) ? playerData : null;
}
if (entity.Has<PlayerCharacter>())
{
PlayerCharacter val = entity.Read<PlayerCharacter>();
User val2 = val.UserEntity.Read<User>();
PlayerData playerData2;
return PlayerService.TryGetById(val2.PlatformId, out playerData2) ? playerData2 : null;
}
return null;
}
public static PlayerData GetPlayerData(this NetworkId networkId)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
PlayerData playerData;
return PlayerService.TryGetByNetworkId(networkId, out playerData) ? playerData : null;
}
public static PlayerData GetPlayerData(this User user)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
PlayerData playerData;
return PlayerService.TryGetById(user.PlatformId, out playerData) ? playerData : null;
}
}
[BepInPlugin("markvaaz.ScarletCore", "ScarletCore", "1.3.11")]
public class Plugin : BasePlugin
{
private static Harmony _harmony;
public static Harmony Harmony => _harmony;
public static Plugin Instance { get; private set; }
public static ManualLogSource LogInstance { get; private set; }
public override void Load()
{
//IL_0020: Unknown result type (might be due to invalid IL or missing references)
//IL_0026: Expected O, but got Unknown
//IL_0072: Unknown result type (might be due to invalid IL or missing references)
//IL_007c: Expected O, but got Unknown
Instance = this;
LogInstance = ((BasePlugin)this).Log;
ManualLogSource log = ((BasePlugin)this).Log;
bool flag = default(bool);
BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(27, 2, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Plugin ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("markvaaz.ScarletCore");
((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" version ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("1.3.11");
((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" is loaded!");
}
log.LogInfo(val);
_harmony = new Harmony("markvaaz.ScarletCore");
_harmony.PatchAll(Assembly.GetExecutingAssembly());
((BasePlugin)this).Log.LogInfo((object)"ScarletCore event listener auto-initialization setup complete");
}
public override bool Unload()
{
Harmony harmony = _harmony;
if (harmony != null)
{
harmony.UnpatchSelf();
}
return true;
}
}
public static class MyPluginInfo
{
public const string PLUGIN_GUID = "markvaaz.ScarletCore";
public const string PLUGIN_NAME = "ScarletCore";
public const string PLUGIN_VERSION = "1.3.11";
}
}
namespace ScarletCore.Utils
{
public static class Log
{
private static readonly ConcurrentDictionary<Assembly, ManualLogSource> _assemblyLogCache = new ConcurrentDictionary<Assembly, ManualLogSource>();
private static ManualLogSource MLS
{
get
{
try
{
ManualLogSource callerLogSource = GetCallerLogSource();
if (callerLogSource != null)
{
return callerLogSource;
}
}
catch
{
}
return Plugin.LogInstance;
}
}
private static ManualLogSource GetCallerLogSource()
{
Assembly assembly = typeof(Log).Assembly;
StackFrame[] frames = new StackTrace(1, fNeedFileInfo: false).GetFrames();
if (frames == null)
{
return null;
}
StackFrame[] array = frames;
foreach (StackFrame stackFrame in array)
{
MethodBase method = stackFrame.GetMethod();
if (method == null)
{
continue;
}
Type declaringType = method.DeclaringType;
if (declaringType == null)
{
continue;
}
Assembly assembly2 = declaringType.Assembly;
if (!(assembly2 == assembly) && (assembly2.FullName == null || (!assembly2.FullName.StartsWith("System", StringComparison.Ordinal) && !assembly2.FullName.StartsWith("Microsoft", StringComparison.Ordinal))))
{
if (_assemblyLogCache.TryGetValue(assembly2, out var value))
{
return value;
}
ManualLogSource val = FindManualLogSourceInAssembly(assembly2);
_assemblyLogCache[assembly2] = val;
if (val != null)
{
return val;
}
}
}
return null;
}
private static ManualLogSource FindManualLogSourceInAssembly(Assembly asm)
{
try
{
Type[] types = asm.GetTypes();
foreach (Type type in types)
{
PropertyInfo property = type.GetProperty("LogInstance", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
if (property != null && property.PropertyType == typeof(ManualLogSource))
{
try
{
object? value = property.GetValue(null);
return (ManualLogSource)((value is ManualLogSource) ? value : null);
}
catch
{
}
}
FieldInfo fieldInfo = type.GetField("LogInstance", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic) ?? type.GetField("Logger", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
if (fieldInfo != null && fieldInfo.FieldType == typeof(ManualLogSource))
{
try
{
object? value2 = fieldInfo.GetValue(null);
return (ManualLogSource)((value2 is ManualLogSource) ? value2 : null);
}
catch
{
}
}
PropertyInfo[] properties = type.GetProperties(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
PropertyInfo[] array = properties;
foreach (PropertyInfo propertyInfo in array)
{
if (propertyInfo.PropertyType == typeof(ManualLogSource))
{
try
{
object? value3 = propertyInfo.GetValue(null);
return (ManualLogSource)((value3 is ManualLogSource) ? value3 : null);
}
catch
{
}
}
}
FieldInfo[] fields = type.GetFields(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
FieldInfo[] array2 = fields;
foreach (FieldInfo fieldInfo2 in array2)
{
if (fieldInfo2.FieldType == typeof(ManualLogSource))
{
try
{
object? value4 = fieldInfo2.GetValue(null);
return (ManualLogSource)((value4 is ManualLogSource) ? value4 : null);
}
catch
{
}
}
}
}
}
catch
{
}
return null;
}
public static void Debug(params object[] messages)
{
ManualLogSource mLS = MLS;
if (mLS != null)
{
mLS.LogDebug((object)string.Join(" ", messages));
}
}
public static void Info(params object[] messages)
{
ManualLogSource mLS = MLS;
if (mLS != null)
{
mLS.LogInfo((object)string.Join(" ", messages));
}
}
public static void Warning(params object[] messages)
{
ManualLogSource mLS = MLS;
if (mLS != null)
{
mLS.LogWarning((object)string.Join(" ", messages));
}
}
public static void Error(params object[] messages)
{
ManualLogSource mLS = MLS;
if (mLS != null)
{
mLS.LogError((object)string.Join(" ", messages));
}
}
public static void Fatal(params object[] messages)
{
ManualLogSource mLS = MLS;
if (mLS != null)
{
mLS.LogFatal((object)string.Join(" ", messages));
}
}
public static void LogLevel(LogLevel level, object message)
{
//IL_000c: Unknown result type (might be due to invalid IL or missing references)
ManualLogSource mLS = MLS;
if (mLS != null)
{
mLS.Log(level, message);
}
}
public static void Components(Entity entity)
{
//IL_0001: 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_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_0038: 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_0047: 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)
if (!entity.Exists())
{
Warning("Cannot log components for non-existing entity.");
return;
}
EntityManager entityManager = GameSystems.EntityManager;
Enumerator<ComponentType> enumerator = ((EntityManager)(ref entityManager)).GetComponentTypes(entity, (Allocator)2).GetEnumerator();
while (enumerator.MoveNext())
{
ComponentType current = enumerator.Current;
Info(current);
}
}
public static void Player(PlayerData playerData)
{
//IL_00db: Unknown result type (might be due to invalid IL or missing references)
//IL_01ef: Unknown result type (might be due to invalid IL or missing references)
//IL_022a: Unknown result type (might be due to invalid IL or missing references)
if (playerData == null)
{
Warning("PlayerData is null");
return;
}
Info("=== PlayerData Information ===");
Info(" Name: " + playerData.Name);
Info(" Cached Name: " + (playerData.CachedName ?? "null"));
Info($" Platform ID: {playerData.PlatformId}");
Info($" Network ID: {playerData.NetworkId}");
Info($" Is Online: {playerData.IsOnline}");
Info($" Is Admin: {playerData.IsAdmin}");
Info($" Connected Since: {playerData.ConnectedSince}");
Info(" Clan Name: " + (playerData.ClanName ?? "No Clan"));
Info($" User Entity: {playerData.UserEntity}");
Info($" Character Entity: {playerData.CharacterEntity}");
Info("==============================");
}
}
public static class MathUtility
{
public static float Distance(Entity A, Entity B)
{
//IL_0001: 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_0022: 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_0029: 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_0030: 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_0037: Unknown result type (might be due to invalid IL or missing references)
if (!A.Has<LocalTransform>() || !B.Has<LocalTransform>())
{
return float.MaxValue;
}
LocalTransform val = A.Read<LocalTransform>();
LocalTransform val2 = B.Read<LocalTransform>();
return math.distance(val.Position, val2.Position);
}
public static float Distance2D(Entity A, Entity B)
{
//IL_0001: 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_0025: Unknown result type (might be due to invalid IL or missing references)
//IL_0026: Unknown result type (might be due to invalid IL or missing references)
//IL_002b: 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_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_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_0041: 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_004d: 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_0058: 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)
if (!A.Has<LocalTransform>() || !B.Has<LocalTransform>())
{
return float.MaxValue;
}
LocalTransform val = A.Read<LocalTransform>();
LocalTransform val2 = B.Read<LocalTransform>();
float3 position = val.Position;
float3 position2 = val2.Position;
return math.distance(new float2(position.x, position.z), new float2(position2.x, position2.z));
}
public static float Distance(Entity entity, float3 position)
{
//IL_0001: 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_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_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_0024: Unknown result type (might be due to invalid IL or missing references)
if (!entity.Has<LocalTransform>())
{
return float.MaxValue;
}
LocalTransform val = entity.Read<LocalTransform>();
return math.distance(val.Position, position);
}
public static float Distance2D(Entity entity, float3 position)
{
//IL_0001: 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_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_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_0024: Unknown result type (might be due to invalid IL or missing references)
//IL_0025: Unknown result type (might be due to invalid IL or missing references)
//IL_002b: 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_003c: 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)
if (!entity.Has<LocalTransform>())
{
return float.MaxValue;
}
LocalTransform val = entity.Read<LocalTransform>();
float3 position2 = val.Position;
return math.distance(new float2(position2.x, position2.z), new float2(position.x, position.z));
}
public static float Distance(float3 positionA, float3 positionB)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
return math.distance(positionA, positionB);
}
public static float Distance2D(float3 positionA, float3 positionB)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0007: 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_0012: 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_001e: Unknown result type (might be due to invalid IL or missing references)
return math.distance(new float2(positionA.x, positionA.z), new float2(positionB.x, positionB.z));
}
public static bool IsInRange(Entity A, Entity B, float range)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
return Distance(A, B) <= range;
}
public static bool IsInRange2D(Entity A, Entity B, float range)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
return Distance2D(A, B) <= range;
}
public static bool IsInRange(Entity entity, float3 position, float range)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
return Distance(entity, position) <= range;
}
public static bool IsInRange2D(Entity entity, float3 position, float range)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
return Distance2D(entity, position) <= range;
}
public static bool IsInRange(float3 positionA, float3 positionB, float range)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
return Distance(positionA, positionB) <= range;
}
public static bool IsInRange2D(float3 positionA, float3 positionB, float range)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
return Distance2D(positionA, positionB) <= range;
}
public static float3 GetRandomPositionInRadius(float3 center, float radius)
{
//IL_0023: 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_0044: 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)
float num = Random.Range(0f, 2f * math.PI);
float num2 = Random.Range(0f, radius);
float num3 = center.x + num2 * math.cos(num);
float num4 = center.z + num2 * math.sin(num);
return new float3(num3, center.y, num4);
}
public static float3 GetRandomPositionInRing(float3 center, float minRadius, float maxRadius)
{
//IL_001f: 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_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_004c: 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)
float num = Random.Range(0f, 2f * math.PI);
float num2 = Random.Range(minRadius, maxRadius);
float num3 = center.x + num2 * math.cos(num);
float num4 = center.z + num2 * math.sin(num);
return new float3(num3, center.y, num4);
}
public static float3 GetRandomPositionAroundEntity(Entity entity, float radius)
{
//IL_0001: 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_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_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_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_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_002d: Unknown result type (might be due to invalid IL or missing references)
if (!entity.Has<LocalTransform>())
{
return float3.zero;
}
LocalTransform val = entity.Read<LocalTransform>();
return GetRandomPositionInRadius(val.Position, radius);
}
public static float3 GetRandomPositionAroundEntity(Entity entity, float minRadius, float maxRadius)
{
//IL_0001: 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_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_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_0026: 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_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_002e: Unknown result type (might be due to invalid IL or missing references)
if (!entity.Has<LocalTransform>())
{
return float3.zero;
}
LocalTransform val = entity.Read<LocalTransform>();
return GetRandomPositionInRing(val.Position, minRadius, maxRadius);
}
public static float NormalizeAngle(float angle)
{
while (angle < 0f)
{
angle += 2f * math.PI;
}
while (angle >= 2f * math.PI)
{
angle -= 2f * math.PI;
}
return angle;
}
public static float GetAngleBetween(float3 from, float3 to)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//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_0008: Unknown result type (might be due to invalid IL or missing references)
//IL_0009: Unknown result type (might be due to invalid IL or missing references)
//IL_000f: Unknown result type (might be due to invalid IL or missing references)
float3 val = to - from;
return math.atan2(val.z, val.x);
}
public static float GetAngleBetween(Entity from, Entity to)
{
//IL_0001: 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_0022: 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_002e: 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_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)
if (!from.Has<LocalTransform>() || !to.Has<LocalTransform>())
{
return 0f;
}
float3 position = from.Read<LocalTransform>().Position;
float3 position2 = to.Read<LocalTransform>().Position;
return GetAngleBetween(position, position2);
}
public static float3 Lerp(float3 from, float3 to, float t)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0002: 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_001b: Unknown result type (might be due to invalid IL or missing references)
return math.lerp(from, to, math.clamp(t, 0f, 1f));
}
public static float3 ClampPosition(float3 position, float3 minBounds, float3 maxBounds)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0007: 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_0018: 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_0024: 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_0035: 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_0046: Unknown result type (might be due to invalid IL or missing references)
//IL_004b: Unknown result type (might be due to invalid IL or missing references)
//IL_004e: Unknown result type (might be due to invalid IL or missing references)
return new float3(math.clamp(position.x, minBounds.x, maxBounds.x), math.clamp(position.y, minBounds.y, maxBounds.y), math.clamp(position.z, minBounds.z, maxBounds.z));
}
public static bool IsWithinBounds(float3 position, float3 minBounds, float3 maxBounds)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_000f: Unknown result type (might be due to invalid IL or missing references)
//IL_0015: 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_002b: 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_0039: Unknown result type (might be due to invalid IL or missing references)
//IL_003f: Unknown result type (might be due to invalid IL or missing references)
//IL_0047: Unknown result type (might be due to invalid IL or missing references)
//IL_004d: Unknown result type (might be due to invalid IL or missing references)
return position.x >= minBounds.x && position.x <= maxBounds.x && position.y >= minBounds.y && position.y <= maxBounds.y && position.z >= minBounds.z && position.z <= maxBounds.z;
}
public static float3 GetDirection(float3 from, float3 to)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//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_0008: Unknown result type (might be due to invalid IL or missing references)
//IL_0009: Unknown result type (might be due to invalid IL or missing references)
//IL_000a: Unknown result type (might be due to invalid IL or missing references)
//IL_000f: Unknown result type (might be due to invalid IL or missing references)
//IL_0012: Unknown result type (might be due to invalid IL or missing references)
float3 val = to - from;
return math.normalize(val);
}
public static float3 GetDirection(Entity from, Entity to)
{
//IL_0001: 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_0022: 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_002e: 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_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_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_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_0044: Unknown result type (might be due to invalid IL or missing references)
if (!from.Has<LocalTransform>() || !to.Has<LocalTransform>())
{
return float3.zero;
}
float3 position = from.Read<LocalTransform>().Position;
float3 position2 = to.Read<LocalTransform>().Position;
return GetDirection(position, position2);
}
public static float3 GetClosestPointOnLine(float3 point, float3 lineStart, float3 lineEnd)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//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_0008: Unknown result type (might be due to invalid IL or missing references)
//IL_0009: Unknown result type (might be due to invalid IL or missing references)
//IL_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_002b: 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_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_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_004b: Unknown result type (might be due to invalid IL or missing references)
//IL_004c: Unknown result type (might be due to invalid IL or missing references)
//IL_004f: 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_0059: 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_005d: Unknown result type (might be due to invalid IL or missing references)
float3 val = lineEnd - lineStart;
float num = math.length(val);
if (num == 0f)
{
return lineStart;
}
float3 val2 = val / num;
float3 val3 = point - lineStart;
float num2 = math.dot(val3, val2);
num2 = math.clamp(num2, 0f, num);
return lineStart + val2 * num2;
}
public static int2 WorldToGrid(float3 worldPosition, float gridSize = 1f)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_000f: Unknown result type (might be due to invalid IL or missing references)
//IL_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_0025: Unknown result type (might be due to invalid IL or missing references)
return new int2((int)math.floor(worldPosition.x / gridSize), (int)math.floor(worldPosition.z / gridSize));
}
public static float3 GridToWorld(int2 gridPosition, float gridSize = 1f, float yHeight = 0f)
{
//IL_0001: 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_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_002c: Unknown result type (might be due to invalid IL or missing references)
return new float3((float)gridPosition.x * gridSize + gridSize * 0.5f, yHeight, (float)gridPosition.y * gridSize + gridSize * 0.5f);
}
public static bool IsPointInCircle(float3 point, float3 circleCenter, float radius)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
return Distance2D(point, circleCenter) <= radius;
}
public static bool IsPointInRectangle(float3 point, float3 rectCenter, float2 rectSize)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//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_000f: 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_0021: Unknown result type (might be due to invalid IL or missing references)
//IL_0027: Unknown result type (might be due to invalid IL or missing references)
//IL_0038: 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)
//IL_0046: 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)
float2 val = rectSize * 0.5f;
float2 val2 = default(float2);
((float2)(ref val2))..ctor(math.abs(point.x - rectCenter.x), math.abs(point.z - rectCenter.z));
return val2.x <= val.x && val2.y <= val.y;
}
public static float3 RotatePointAround(float3 point, float3 pivot, float angleRadians)
{
//IL_000f: 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_0011: 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_0019: 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_002a: Unknown result type (might be due to invalid IL or missing references)
//IL_0030: Unknown result type (might be due to invalid IL or missing references)
//IL_0038: 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_0047: 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_004d: 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)
float num = math.cos(angleRadians);
float num2 = math.sin(angleRadians);
float3 val = point - pivot;
float3 val2 = default(float3);
((float3)(ref val2))..ctor(val.x * num - val.z * num2, val.y, val.x * num2 + val.z * num);
return val2 + pivot;
}
}
public static class RichTextFormatter
{
public static readonly string Red = "#ff0000";
public static readonly string Green = "#00ff00";
public static readonly string Blue = "#0000ff";
public static readonly string Yellow = "#ffff00";
public static readonly string Orange = "#ffa500";
public static readonly string Purple = "#800080";
public static readonly string Pink = "#ffc0cb";
public static readonly string White = "#ffffff";
public static readonly string Gray = "#808080";
public static readonly string Cyan = "#00ffff";
public static readonly string HighlightColor = "#a963ff";
public static readonly string HighlightErrorColor = "#ff4040";
public static readonly string HighlightWarningColor = "#ffff00";
public static readonly string TextColor = "#ffffff";
public static readonly string SuccessTextColor = "#9cff9c";
public static readonly string ErrorTextColor = "#ff8f8f";
public static readonly string WarningTextColor = "#ffff9e";
public static string Bold(this string text)
{
return "<b>" + text + "</b>";
}
public static string Italic(this string text)
{
return "<i>" + text + "</i>";
}
public static string Underline(this string text)
{
return "<u>" + text + "</u>";
}
public static string ToRed(this string text)
{
return "<color=red>" + text + "</color>";
}
public static string ToGreen(this string text)
{
return "<color=green>" + text + "</color>";
}
public static string ToBlue(this string text)
{
return "<color=blue>" + text + "</color>";
}
public static string ToYellow(this string text)
{
return "<color=yellow>" + text + "</color>";
}
public static string ToWhite(this string text)
{
return "<color=white>" + text + "</color>";
}
public static string ToBlack(this string text)
{
return "<color=black>" + text + "</color>";
}
public static string ToGray(this string text)
{
return "<color=#cccccc>" + text + "</color>";
}
public static string WithColor(this string text, string hex)
{
return $"<color={hex}>{text}</color>";
}
public static string Format(this string text, List<string> highlightColors = null)
{
if (highlightColors == null)
{
highlightColors = new List<string>(1) { HighlightColor };
}
return ApplyFormatting(text, TextColor, highlightColors);
}
public static string FormatError(this string text)
{
return ApplyFormatting(text, ErrorTextColor, new List<string>(1) { HighlightErrorColor });
}
public static string FormatWarning(this string text)
{
return ApplyFormatting(text, WarningTextColor, new List<string>(1) { HighlightWarningColor });
}
public static string FormatSuccess(this string text)
{
return ApplyFormatting(text, SuccessTextColor, new List<string>(1) { Green });
}
public static string FormatInfo(this string text)
{
return ApplyFormatting(text, TextColor, new List<string>(1) { Blue });
}
public static string FormatBackground(this string text, List<string> backgroundColors = null)
{
if (backgroundColors == null)
{
backgroundColors = new List<string>(1) { HighlightColor };
}
return ApplyBackgroundFormatting(text, backgroundColors);
}
public static string AsError(this string text)
{
return ("[ERROR] " + text).WithColor(Red);
}
public static string AsSuccess(this string text)
{
return ("[SUCCESS] " + text).WithColor(Green);
}
public static string AsWarning(this string text)
{
return ("[WARNING] " + text).WithColor(Yellow);
}
public static string AsInfo(this string text)
{
return ("[INFO] " + text).WithColor(Blue);
}
public static string AsAnnouncement(this string text)
{
return ("[ANNOUNCEMENT] " + text).WithColor(Orange);
}
public static string AsList(this string text)
{
return "[LIST] " + text;
}
public static string AsPlayerJoin(this string playerName)
{
return (playerName + " has joined the server!").WithColor(Green);
}
public static string AsPlayerLeave(this string playerName)
{
return (playerName + " has left the server").WithColor(Gray);
}
public static string AsPlayerDeath(this string victimName, string killerName = null)
{
return string.IsNullOrEmpty(killerName) ? (victimName + " has died").WithColor(Red) : (victimName + " was killed by " + killerName).WithColor(Red);
}
public static string AsProgressBar(this string label, int current, int max, int barLength = 20)
{
float num = (float)current / (float)max;
int num2 = (int)(num * (float)barLength);
int count = barLength - num2;
string value = new string('█', num2) + new string('░', count);
return $"{label}: [{value}] {current}/{max} ({num:P0})".WithColor(Cyan);
}
public static string AsBoxedTitle(this string title)
{
string value = new string('═', title.Length + 4);
return $"╔{value}╗\n║ {title} ║\n╚{value}╝";
}
public static string AsBoxedContent(this string content, string title)
{
int num = title.Length + 4;
string[] array = content.Split('\n');
string text = "";
string[] array2 = array;
foreach (string text2 in array2)
{
int count = Math.Max(0, num - text2.Length - 2);
text = text + "║ " + text2 + new string(' ', count) + " ║\n";
}
return text.TrimEnd('\n');
}
public static string AsSeparator(this char character, int length = 40)
{
return new string(character, length).WithColor(Gray);
}
public static string AsCountdown(this string action, int seconds)
{
if (seconds > 60)
{
int num = seconds / 60;
return $"{action} in {num} minute{((num != 1) ? "s" : "")}!".AsWarning();
}
if (seconds > 10)
{
return $"{action} in {seconds} seconds!".AsWarning();
}
if (seconds > 0)
{
return $"{action} in {seconds}!".AsError();
}
return (action + " NOW!").AsError();
}
private static string ApplyFormatting(string text, string baseColor, List<string> highlightColors)
{
string pattern = "\\*\\*(.*?)\\*\\*";
string pattern2 = "\\*(.*?)\\*";
string pattern3 = "__(.*?)__";
string pattern4 = "~(.*?)~";
string input = Regex.Replace(text, pattern, (Match m) => m.Groups[1].Value.Bold());
input = Regex.Replace(input, pattern2, (Match m) => m.Groups[1].Value.Italic());
input = Regex.Replace(input, pattern3, (Match m) => m.Groups[1].Value.Underline());
int highlightIndex = 0;
input = Regex.Replace(input, pattern4, delegate(Match m)
{
string text2;
if (highlightColors.Count > 0)
{
int index = Math.Min(highlightIndex, highlightColors.Count - 1);
text2 = highlightColors[index];
}
else
{
text2 = HighlightColor;
}
if (text2 == null)
{
text2 = HighlightColor;
}
highlightIndex++;
return m.Groups[1].Value.WithColor(text2);
});
return input.WithColor(baseColor);
}
private static string ApplyBackgroundFormatting(string text, List<string> backgroundColors)
{
string pattern = "\\^(.*?)\\^";
int backgroundIndex = 0;
return Regex.Replace(text, pattern, delegate(Match m)
{
string text2;
if (backgroundColors.Count > 0)
{
int index = Math.Min(backgroundIndex, backgroundColors.Count - 1);
text2 = backgroundColors[index];
}
else
{
text2 = HighlightColor;
}
if (text2 == null)
{
text2 = HighlightColor;
}
backgroundIndex++;
return $"<mark={text2}>{m.Groups[1].Value}</mark>";
});
}
}
public static class Symbols
{
public const string CHECK_MARK = "✓";
public const string REFERENCE_MARK = "※";
public const string WARNING = "⚠";
public const string NO_ENTRY = "⊘";
public const string STAR_FILLED = "★";
public const string STAR_OUTLINE = "☆";
public const string DIAMOND_BLACK = "❖";
public const string PLAY_BUTTON = "▶";
public const string ARROW_RIGHT = "→";
public const string ARROW_LEFT = "←";
public const string ARROW_UP = "↑";
public const string ARROW_DOWN = "↓";
public const string ARROW_CURVE_UP_RIGHT = "⤴";
public const string ARROW_RIGHTWARDS_DOUBLE = "⇨";
public const string THEREFORE = "∴";
public const string BECAUSE = "∵";
public const string NOT_EQUAL = "≠";
public const string IDENTICAL_TO = "≡";
public const string APPROXIMATELY_EQUAL = "≈";
public const string GREATER_THAN = "›";
public const string LESS_THAN = "‹";
public const string INFINITY = "∞";
public const string PLUS_MINUS = "±";
public const string MULTIPLICATION = "×";
public const string DIVISION = "÷";
public const string SQUARE_BULLET = "▪";
public const string SQUARE_BULLET_HOLLOW = "▫";
public const string SQUARE_BOX = "▣";
public const string SQUARE_BOX_FILLED = "■";
public const string CIRCLE_FILLED = "●";
public const string CIRCLE_EMPTY = "○";
public const string CIRCLE_TARGET = "◉";
public const string CIRCLE_HALVE_LEFT = "◐";
public const string DIAMOND_FILLED = "◆";
public const string DIAMOND_EMPTY = "◇";
public const string TRIANGLE_UP = "▲";
public const string TRIANGLE_DOWN = "▼";
public const string HOT_SPRINGS = "♨";
public const string SUN = "☀";
public const string CLOUD = "☁";
public const string EARTH = "♁";
public const string MUSIC_NOTE_SINGLE = "♪";
public const string MUSIC_NOTE_DOUBLE = "♫";
public const string MUSIC_SHARP = "♯";
public const string MUSIC_FLAT = "♭";
public const string MUSIC_NATURAL = "♮";
public const string CARD_SPADE = "♠";
public const string CARD_CLUB = "♣";
public const string CARD_HEART = "♥";
public const string CARD_DIAMOND = "♦";
public const string CHAIN_LINK = "⛓";
public const string BULLET_POINT = "•";
public const string MIDDLE_DOT = "·";
public const string RECYCLE = "♻";
public const string BOOST = "⤴";
public const string COIN = "◉";
public const string COST = "◉";
public const string VALUE = "◆";
public const string PRICE = "※";
public const string CIRCLED_1 = "①";
public const string CIRCLED_2 = "②";
public const string CIRCLED_3 = "③";
public const string SUPERSCRIPT_1 = "¹";
public const string SUPERSCRIPT_2 = "²";
public const string SUPERSCRIPT_3 = "³";
}
}
namespace ScarletCore.Systems
{
public readonly record struct ActionId(int Value)
{
private static int _nextId;
public static ActionId Next()
{
return new ActionId(Interlocked.Increment(ref _nextId));
}
}
public enum ActionType
{
OncePerFrame,
NextFrame,
RepeatingSeconds,
RepeatingFrames,
DelayedSeconds,
DelayedFrames
}
public class ScheduledAction
{
public Action<Action> ActionWithCancel { get; set; }
public Action Action { get; set; }
public ActionType Type { get; set; }
public float Interval { get; set; }
public float NextExecutionTime { get; set; }
public int FrameInterval { get; set; }
public int NextExecutionFrame { get; set; }
public int LastExecutionFrame { get; set; } = -1;
public bool IsActive { get; set; } = true;
public ActionId Id { get; set; }
public bool ShouldCancel { get; set; } = false;
public int MaxExecutions { get; set; } = -1;
public int ExecutionCount { get; set; } = 0;
public float MinInterval { get; set; } = 0f;
public float MaxInterval { get; set; } = 0f;
public ScheduledAction(Action action, ActionType type, float interval = 0f, int frameInterval = 0, ActionId id = default(ActionId), int maxExecutions = -1)
{
Action = action;
Type = type;
Interval = interval;
FrameInterval = frameInterval;
Id = ((id.Value == 0) ? ActionId.Next() : id);
MaxExecutions = maxExecutions;
InitializeTiming(type, interval, frameInterval);
}
public ScheduledAction(Action<Action> actionWithCancel, ActionType type, float interval = 0f, int frameInterval = 0, ActionId id = default(ActionId), int maxExecutions = -1)
{
ActionWithCancel = actionWithCancel;
Type = type;
Interval = interval;
FrameInterval = frameInterval;
Id = ((id.Value == 0) ? ActionId.Next() : id);
MaxExecutions = maxExecutions;
InitializeTiming(type, interval, frameInterval);
}
private void InitializeTiming(ActionType type, float interval, int frameInterval)
{
switch (type)
{
case ActionType.RepeatingSeconds:
case ActionType.DelayedSeconds:
NextExecutionTime = Time.time + interval;
break;
case ActionType.RepeatingFrames:
case ActionType.DelayedFrames:
NextExecutionFrame = Time.frameCount + frameInterval;
break;
case ActionType.NextFrame:
NextExecutionFrame = Time.frameCount + 1;
break;
}
}
}
public static class ActionScheduler
{
private static readonly List<ScheduledAction> _scheduledActions = new List<ScheduledAction>();
private static readonly List<ScheduledAction> _actionsToRemove = new List<ScheduledAction>();
private static readonly Dictionary<ActionId, ScheduledAction> _actionLookup = new Dictionary<ActionId, ScheduledAction>();
private static readonly List<ScheduledAction> _activeActions = new List<ScheduledAction>();
public static int Count => _scheduledActions.Count;
public static void UnregisterAssembly(Assembly assembly)
{
if (assembly == null)
{
return;
}
lock (_scheduledActions)
{
List<ScheduledAction> list = new List<ScheduledAction>();
foreach (ScheduledAction scheduledAction in _scheduledActions)
{
MethodInfo methodInfo = scheduledAction.Action?.Method ?? scheduledAction.ActionWithCancel?.Method;
if (methodInfo != null && methodInfo.DeclaringType != null && methodInfo.DeclaringType.Assembly == assembly)
{
list.Add(scheduledAction);
}
}
foreach (ScheduledAction item in list)
{
_scheduledActions.Remove(item);
_actionLookup.Remove(item.Id);
}
}
}
public static void Execute()
{
float time = Time.time;
int frameCount = Time.frameCount;
lock (_scheduledActions)
{
_activeActions.Clear();
_activeActions.AddRange(_scheduledActions);
}
foreach (ScheduledAction action in _activeActions)
{
bool flag;
lock (_scheduledActions)
{
flag = _scheduledActions.Contains(action);
}
if (!flag)
{
continue;
}
if (!action.IsActive || action.ShouldCancel)
{
if (action.ShouldCancel)
{
_actionsToRemove.Add(action);
}
continue;
}
bool flag2 = false;
bool flag3 = false;
switch (action.Type)
{
case ActionType.OncePerFrame:
if (action.LastExecutionFrame != frameCount)
{
flag2 = true;
action.LastExecutionFrame = frameCount;
}
break;
case ActionType.NextFrame:
if (frameCount >= action.NextExecutionFrame)
{
flag2 = true;
flag3 = true;
}
break;
case ActionType.RepeatingSeconds:
if (time >= action.NextExecutionTime)
{
flag2 = true;
if (action.MinInterval > 0f && action.MaxInterval > action.MinInterval)
{
action.NextExecutionTime = time + GetRandomInterval(action.MinInterval, action.MaxInterval);
}
else
{
action.NextExecutionTime = time + action.Interval;
}
}
break;
case ActionType.RepeatingFrames:
if (frameCount >= action.NextExecutionFrame)
{
flag2 = true;
action.NextExecutionFrame = frameCount + action.FrameInterval;
}
break;
case ActionType.DelayedSeconds:
if (time >= action.NextExecutionTime)
{
flag2 = true;
flag3 = true;
}
break;
case ActionType.DelayedFrames:
if (frameCount >= action.NextExecutionFrame)
{
flag2 = true;
flag3 = true;
}
break;
}
if (flag2)
{
try
{
if (action.ActionWithCancel != null)
{
action.ActionWithCancel(delegate
{
action.ShouldCancel = true;
});
}
else
{
action.Action?.Invoke();
}
action.ExecutionCount++;
if (action.MaxExecutions > 0 && action.ExecutionCount >= action.MaxExecutions)
{
flag3 = true;
}
}
catch (Exception value)
{
Log.Error($"Error executing scheduled action {action.Id}: {value}");
flag3 = true;
}
}
if (flag3)
{
_actionsToRemove.Add(action);
}
}
if (_actionsToRemove.Count <= 0)
{
return;
}
lock (_scheduledActions)
{
foreach (ScheduledAction item in _actionsToRemove)
{
_scheduledActions.Remove(item);
_actionLookup.Remove(item.Id);
}
}
_actionsToRemove.Clear();
}
private static void AddActionInternal(ScheduledAction scheduledAction)
{
lock (_scheduledActions)
{
_scheduledActions.Add(scheduledAction);
_actionLookup[scheduledAction.Id] = scheduledAction;
}
}
public static ActionId OncePerFrame(Action<Action> action, int maxExecutions = -1)
{
ScheduledAction scheduledAction = new ScheduledAction(action, ActionType.OncePerFrame, 0f, 0, default(ActionId), maxExecutions);
AddActionInternal(scheduledAction);
return scheduledAction.Id;
}
public static ActionId OncePerFrame(Action action, int maxExecutions = -1)
{
ScheduledAction scheduledAction = new ScheduledAction(action, ActionType.OncePerFrame, 0f, 0, default(ActionId), maxExecutions);
AddActionInternal(scheduledAction);
return scheduledAction.Id;
}
public static ActionId NextFrame(Action<Action> action)
{
ScheduledAction scheduledAction = new ScheduledAction(action, ActionType.NextFrame);
AddActionInternal(scheduledAction);
return scheduledAction.Id;
}
public static ActionId NextFrame(Action action)
{
ScheduledAction scheduledAction = new ScheduledAction(action, ActionType.NextFrame);
AddActionInternal(scheduledAction);
return scheduledAction.Id;
}
public static ActionId Repeating(Action<Action> action, float intervalSeconds, int maxExecutions = -1)
{
ScheduledAction scheduledAction = new ScheduledAction(action, ActionType.RepeatingSeconds, intervalSeconds, 0, default(ActionId), maxExecutions);
AddActionInternal(scheduledAction);
return scheduledAction.Id;
}
public static ActionId Repeating(Action action, float intervalSeconds, int maxExecutions = -1)
{
ScheduledAction scheduledAction = new ScheduledAction(action, ActionType.RepeatingSeconds, intervalSeconds, 0, default(ActionId), maxExecutions);
AddActionInternal(scheduledAction);
return scheduledAction.Id;
}
public static ActionId RepeatingFrames(Action<Action> action, int frameInterval, int maxExecutions = -1)
{
ScheduledAction scheduledAction = new ScheduledAction(action, ActionType.RepeatingFrames, 0f, frameInterval, default(ActionId), maxExecutions);
AddActionInternal(scheduledAction);
return scheduledAction.Id;
}
public static ActionId RepeatingFrames(Action action, int frameInterval, int maxExecutions = -1)
{
ScheduledAction scheduledAction = new ScheduledAction(action, ActionType.RepeatingFrames, 0f, frameInterval, default(ActionId), maxExecutions);
AddActionInternal(scheduledAction);
return scheduledAction.Id;
}
public static ActionId Delayed(Action<Action> action, float delaySeconds)
{
ScheduledAction scheduledAction = new ScheduledAction(action, ActionType.DelayedSeconds, delaySeconds);
AddActionInternal(scheduledAction);
return scheduledAction.Id;
}
public static ActionId Delayed(Action action, float delaySeconds)
{
ScheduledAction scheduledAction = new ScheduledAction(action, ActionType.DelayedSeconds, delaySeconds);
AddActionInternal(scheduledAction);
return scheduledAction.Id;
}
public static ActionId DelayedFrames(Action<Action> action, int delayFrames)
{
ScheduledAction scheduledAction = new ScheduledAction(action, ActionType.DelayedFrames, 0f, delayFrames);
AddActionInternal(scheduledAction);
return scheduledAction.Id;
}
public static ActionId DelayedFrames(Action action, int delayFrames)
{
ScheduledAction scheduledAction = new ScheduledAction(action, ActionType.DelayedFrames, 0f, delayFrames);
AddActionInternal(scheduledAction);
return scheduledAction.Id;
}
public static bool CancelAction(ActionId actionId)
{
lock (_scheduledActions)
{
if (_actionLookup.TryGetValue(actionId, out var value))
{
bool flag = _scheduledActions.Remove(value);
if (flag)
{
_actionLookup.Remove(actionId);
}
return flag;
}
return false;
}
}
public static void PauseAction(ActionId actionId)
{
lock (_scheduledActions)
{
if (_actionLookup.TryGetValue(actionId, out var value))
{
value.IsActive = false;
}
}
}
public static void ResumeAction(ActionId actionId)
{
lock (_scheduledActions)
{
if (_actionLookup.TryGetValue(actionId, out var value))
{
value.IsActive = true;
}
}
}
public static void ClearAllActions()
{
lock (_scheduledActions)
{
_scheduledActions.Clear();
_actionLookup.Clear();
}
_actionsToRemove.Clear();
}
public static int GetExecutionCount(ActionId actionId)
{
if (_actionLookup.TryGetValue(actionId, out var value))
{
return value.ExecutionCount;
}
return 0;
}
public static int GetMaxExecutions(ActionId actionId)
{
if (_actionLookup.TryGetValue(actionId, out var value))
{
return value.MaxExecutions;
}
return -1;
}
public static int GetRemainingExecutions(ActionId actionId)
{
if (_actionLookup.TryGetValue(actionId, out var value))
{
if (value.MaxExecutions <= 0)
{
return -1;
}
return Math.Max(0, value.MaxExecutions - value.ExecutionCount);
}
return -1;
}
public static ActionSequence CreateSequence()
{
return new ActionSequence();
}
public static bool CancelSequence(ActionId sequenceId)
{
return CancelAction(sequenceId);
}
public static ActionId RepeatingRandom(Action<Action> action, float minIntervalSeconds, float maxIntervalSeconds, int maxExecutions = -1)
{
ScheduledAction scheduledAction = new ScheduledAction(action, ActionType.RepeatingSeconds, GetRandomInterval(minIntervalSeconds, maxIntervalSeconds), 0, default(ActionId), maxExecutions);
scheduledAction.MinInterval = minIntervalSeconds;
scheduledAction.MaxInterval = maxIntervalSeconds;
AddActionInternal(scheduledAction);
return scheduledAction.Id;
}
public static ActionId RepeatingRandom(Action action, float minIntervalSeconds, float maxIntervalSeconds, int maxExecutions = -1)
{
ScheduledAction scheduledAction = new ScheduledAction(action, ActionType.RepeatingSeconds, GetRandomInterval(minIntervalSeconds, maxIntervalSeconds), 0, default(ActionId), maxExecutions);
scheduledAction.MinInterval = minIntervalSeconds;
scheduledAction.MaxInterval = maxIntervalSeconds;
AddActionInternal(scheduledAction);
return scheduledAction.Id;
}
private static float GetRandomInterval(float minInterval, float maxInterval)
{
return Random.Range(minInterval, maxInterval);
}
}
public class SequenceStep
{
public enum StepType
{
Action,
ActionWithCancel,
WaitSeconds,
WaitFrames,
WaitRandomSeconds
}
public StepType Type { get; set; }
public Action Action { get; set; }
public Action<Action> ActionWithCancel { get; set; }
public float WaitSeconds { get; set; }
public int WaitFrames { get; set; }
public float MinWaitSeconds { get; set; }
public float MaxWaitSeconds { get; set; }
}
public class ActionSequence
{
private readonly List<SequenceStep> _steps = new List<SequenceStep>();
private int _currentStepIndex = 0;
private float _waitUntilTime;
private int _waitUntilFrame;
private bool _isWaiting = false;
private bool _isCancelled = false;
private ActionId _actionId;
public int CurrentStepIndex => _currentStepIndex;
public int TotalSteps => _steps.Count;
public bool IsWaiting => _isWaiting;
public bool IsCancelled => _isCancelled;
public bool IsComplete => _currentStepIndex >= _steps.Count && !_isWaiting;
public ActionSequence Then(Action action)
{
_steps.Add(new SequenceStep
{
Type = SequenceStep.StepType.Action,
Action = action
});
return this;
}
public ActionSequence Then(Action<Action> action)
{
_steps.Add(new SequenceStep
{
Type = SequenceStep.StepType.ActionWithCancel,
ActionWithCancel = action
});
return this;
}
public ActionSequence ThenWait(float seconds)
{
_steps.Add(new SequenceStep
{
Type = SequenceStep.StepType.WaitSeconds,
WaitSeconds = seconds
});
return this;
}
public ActionSequence ThenWaitFrames(int frames)
{
_steps.Add(new SequenceStep
{
Type = SequenceStep.StepType.WaitFrames,
WaitFrames = frames
});
return this;
}
public ActionSequence ThenWaitRandom(float minSeconds, float maxSeconds)
{
_steps.Add(new SequenceStep
{
Type = SequenceStep.StepType.WaitRandomSeconds,
MinWaitSeconds = minSeconds,
MaxWaitSeconds = maxSeconds
});
return this;
}
public ActionId Execute()
{
_currentStepIndex = 0;
_isWaiting = false;
_isCancelled = false;
_actionId = ActionScheduler.OncePerFrame(delegate(Action cancel)
{
ExecuteNextStep(cancel);
});
return _actionId;
}
private void ExecuteNextStep(Action cancelSequence)
{
if (_isCancelled)
{
cancelSequence();
return;
}
if (_isWaiting)
{
SequenceStep sequenceStep = _steps[_currentStepIndex];
if (sequenceStep.Type == SequenceStep.StepType.WaitSeconds)
{
if (Time.time >= _waitUntilTime)
{
_isWaiting = false;
_currentStepIndex++;
}
}
else if (sequenceStep.Type == SequenceStep.StepType.WaitFrames)
{
if (Time.frameCount >= _waitUntilFrame)
{
_isWaiting = false;
_currentStepIndex++;
}
}
else if (sequenceStep.Type == SequenceStep.StepType.WaitRandomSeconds && Time.time >= _waitUntilTime)
{
_isWaiting = false;
_currentStepIndex++;
}
return;
}
if (_currentStepIndex >= _steps.Count)
{
cancelSequence();
return;
}
SequenceStep sequenceStep2 = _steps[_currentStepIndex];
try
{
switch (sequenceStep2.Type)
{
case SequenceStep.StepType.Action:
sequenceStep2.Action?.Invoke();
_currentStepIndex++;
break;
case SequenceStep.StepType.ActionWithCancel:
sequenceStep2.ActionWithCancel?.Invoke(delegate
{
_isCancelled = true;
});
_currentStepIndex++;
break;
case SequenceStep.StepType.WaitSeconds:
_waitUntilTime = Time.time + sequenceStep2.WaitSeconds;
_isWaiting = true;
break;
case SequenceStep.StepType.WaitFrames:
_waitUntilFrame = Time.frameCount + sequenceStep2.WaitFrames;
_isWaiting = true;
break;
case SequenceStep.StepType.WaitRandomSeconds:
{
float num = Random.Range(sequenceStep2.MinWaitSeconds, sequenceStep2.MaxWaitSeconds);
_waitUntilTime = Time.time + num;
_isWaiting = true;
break;
}
}
}
catch (Exception value)
{
Log.Error($"Error executing sequence step {_currentStepIndex}: {value}");
cancelSequence();
}
}
public void Cancel()
{
_isCancelled = true;
}
}
public readonly record struct CoroutineId(int Value)
{
private static int _nextId;
public static CoroutineId Next()
{
return new CoroutineId(Interlocked.Increment(ref _nextId));
}
}
public class ManagedCoroutine
{
public Coroutine Coroutine { get; set; }
public CoroutineId Id { get; set; }
public bool IsActive { get; set; } = true;
public string Name { get; set; }
public Action OnComplete { get; set; }
public int MaxExecutions { get; set; } = -1;
public int ExecutionCount { get; set; } = 0;
public bool IsPaused { get; set; } = false;
public DateTime? PausedAt { get; set; }
public ManagedCoroutine(Coroutine coroutine, CoroutineId id, string name = null, int maxExecutions = -1)
{
Coroutine = coroutine;
Id = id;
Name = name ?? $"Coroutine_{id.Value}";
MaxExecutions = maxExecutions;
}
}
public class CoroutineHandler
{
[CompilerGenerated]
private sealed class <>c__DisplayClass11_0
{
public bool shouldCancel;
internal void <RepeatingCoroutineWithCancelAndMax>b__0()
{
shouldCancel = true;
}
}
[CompilerGenerated]
private sealed class <>c__DisplayClass17_0
{
public bool shouldCancel;
internal void <FrameCoroutineWithCancelAndMax>b__0()
{
shouldCancel = true;
}
}
[CompilerGenerated]
private sealed class <>c__DisplayClass21_0
{
public bool shouldCancel;
internal void <RandomIntervalCoroutineWithCancelAndMax>b__0()
{
shouldCancel = true;
}
}
[CompilerGenerated]
private sealed class <FrameCoroutineWithCancelAndMax>d__17 : IEnumerator<object>, IEnumerator, IDisposable
{
private int <>1__state;
private object <>2__current;
public Action<Action> action;
public int frameInterval;
public int maxExecutions;
public CoroutineId id;
private <>c__DisplayClass17_0 <>8__1;
private Action <cancelAction>5__2;
private int <executionCount>5__3;
private int <i>5__4;
private ManagedCoroutine <managedCoroutine>5__5;
object IEnumerator<object>.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
object IEnumerator.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
[DebuggerHidden]
public <FrameCoroutineWithCancelAndMax>d__17(int <>1__state)
{
this.<>1__state = <>1__state;
}
[DebuggerHidden]
void IDisposable.Dispose()
{
<>8__1 = null;
<cancelAction>5__2 = null;
<managedCoroutine>5__5 = null;
<>1__state = -2;
}
private bool MoveNext()
{
int num = <>1__state;
if (num != 0)
{
if (num != 1)
{
return false;
}
<>1__state = -1;
<i>5__4++;
goto IL_008d;
}
<>1__state = -1;
<>8__1 = new <>c__DisplayClass17_0();
<>8__1.shouldCancel = false;
<cancelAction>5__2 = delegate
{
<>8__1.shouldCancel = true;
};
<executionCount>5__3 = 0;
goto IL_0124;
IL_008d:
if (<i>5__4 < frameInterval && !<>8__1.shouldCancel)
{
<>2__current = null;
<>1__state = 1;
return true;
}
if (!<>8__1.shouldCancel)
{
action?.Invoke(<cancelAction>5__2);
<executionCount>5__3++;
if (_managedCoroutines.TryGetValue(id, out <managedCoroutine>5__5))
{
<managedCoroutine>5__5.ExecutionCount = <executionCount>5__3;
}
<managedCoroutine>5__5 = null;
}
goto IL_0124;
IL_0124:
if (!<>8__1.shouldCancel && (maxExecutions < 0 || <executionCount>5__3 < maxExecutions))
{
<i>5__4 = 0;
goto IL_008d;
}
return false;
}
bool IEnumerator.MoveNext()
{
//ILSpy generated this explicit interface implementation from .override directive in MoveNext
return this.MoveNext();
}
[DebuggerHidden]
void IEnumerator.Reset()
{
throw new NotSupportedException();
}
}
[CompilerGenerated]
private sealed class <FrameCoroutineWithMax>d__16 : IEnumerator<object>, IEnumerator, IDisposable
{
private int <>1__state;
private object <>2__current;
public Action action;
public int frameInterval;
public int maxExecutions;
public CoroutineId id;
private int <executionCount>5__1;
private ManagedCoroutine <managedCoroutine>5__2;
private int <i>5__3;
object IEnumerator<object>.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
object IEnumerator.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
[DebuggerHidden]
public <FrameCoroutineWithMax>d__16(int <>1__state)
{
this.<>1__state = <>1__state;
}
[DebuggerHidden]
void IDisposable.Dispose()
{
<managedCoroutine>5__2 = null;
<>1__state = -2;
}
private bool MoveNext()
{
int num = <>1__state;
if (num != 0)
{
if (num != 1)
{
return false;
}
<>1__state = -1;
<i>5__3++;
goto IL_005f;
}
<>1__state = -1;
<executionCount>5__1 = 0;
goto IL_00c9;
IL_005f:
if (<i>5__3 < frameInterval)
{
<>2__current = null;
<>1__state = 1;
return true;
}
action?.Invoke();
<executionCount>5__1++;
if (_managedCoroutines.TryGetValue(id, out <managedCoroutine>5__2))
{
<managedCoroutine>5__2.ExecutionCount = <executionCount>5__1;
}
<managedCoroutine>5__2 = null;
goto IL_00c9;
IL_00c9:
if (maxExecutions < 0 || <executionCount>5__1 < maxExecutions)
{
<i>5__3 = 0;
goto IL_005f;
}
return false;
}
bool IEnumerator.MoveNext()
{
//ILSpy generated this explicit interface implementation from .override directive in MoveNext
return this.MoveNext();
}
[DebuggerHidden]
void IEnumerator.Reset()
{
throw new NotSupportedException();
}
}
[CompilerGenerated]
private sealed class <GenericCoroutine>d__7 : IEnumerator<object>, IEnumerator, IDisposable
{
private int <>1__state;
private object <>2__current;
public Action action;
public float delay;
object IEnumerator<object>.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
object IEnumerator.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
[DebuggerHidden]
public <GenericCoroutine>d__7(int <>1__state)
{
this.<>1__state = <>1__state;
}
[DebuggerHidden]
void IDisposable.Dispose()
{
<>1__state = -2;
}
private bool MoveNext()
{
//IL_0027: Unknown result type (might be due to invalid IL or missing references)
//IL_0031: Expected O, but got Unknown
switch (<>1__state)
{
default:
return false;
case 0:
<>1__state = -1;
<>2__current = (object)new WaitForSeconds(delay);
<>1__state = 1;
return true;
case 1:
<>1__state = -1;
action?.Invoke();
return false;
}
}
bool IEnumerator.MoveNext()
{
//ILSpy generated this explicit interface implementation from .override directive in MoveNext
return this.MoveNext();
}
[DebuggerHidden]
void IEnumerator.Reset()
{
throw new NotSupportedException();
}
}
[CompilerGenerated]
private sealed class <NextFrameCoroutine>d__23 : IEnumerator<object>, IEnumerator, IDisposable
{
private int <>1__state;
private object <>2__current;
public Action action;
object IEnumerator<object>.Current
{
[DebuggerHidden]
get
{
return <>2__c