using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using BepInEx;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using ProjectM;
using ProjectM.Gameplay.Systems;
using ScarletCore;
using ScarletCore.Data;
using ScarletCore.Services;
using ScarletCore.Systems;
using ScarletCore.Utils;
using ScarletSigns.Service;
using Stunlock.Core;
using Unity.Collections;
using Unity.Entities;
using Unity.Mathematics;
using VampireCommandFramework;
[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("ScarletSigns")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Scarlet Template")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+03d4dd40c2f448159d6ccb95c8fac7e2469fcfe6")]
[assembly: AssemblyProduct("ScarletSigns")]
[assembly: AssemblyTitle("ScarletSigns")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.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.Module, AllowMultiple = false, Inherited = false)]
internal sealed class RefSafetyRulesAttribute : Attribute
{
public readonly int Version;
public RefSafetyRulesAttribute(int P_0)
{
Version = P_0;
}
}
}
namespace ScarletSigns
{
internal static class IdHelper
{
public static string GetId(this Entity entity)
{
//IL_0001: 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_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_0047: Unknown result type (might be due to invalid IL or missing references)
if (!entity.HasId())
{
return null;
}
DynamicBuffer<UserMapZonePackedRevealElement> val = ECSExtensions.ReadBuffer<UserMapZonePackedRevealElement>(entity);
if (val.Length == 0)
{
return null;
}
byte[] array = new byte[val.Length];
for (int i = 0; i < val.Length; i++)
{
array[i] = val[i].PackedPixel;
}
return Encoding.UTF8.GetString(array).TrimEnd('\0');
}
public static void SetId(this Entity entity, string id)
{
//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_0018: 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_0026: 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_0059: Unknown result type (might be due to invalid IL or missing references)
//IL_0068: Unknown result type (might be due to invalid IL or missing references)
if (ECSExtensions.Exists(entity) && !ECSExtensions.Has<PlayerCharacter>(entity))
{
if (!ECSExtensions.Has<UserMapZonePackedRevealElement>(entity))
{
ECSExtensions.AddBuffer<UserMapZonePackedRevealElement>(entity);
}
byte[] bytes = Encoding.UTF8.GetBytes(id);
DynamicBuffer<UserMapZonePackedRevealElement> val = ECSExtensions.ReadBuffer<UserMapZonePackedRevealElement>(entity);
val.Clear();
foreach (byte packedPixel in bytes)
{
val.Add(new UserMapZonePackedRevealElement
{
PackedPixel = packedPixel
});
}
}
}
public static bool HasId(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_0011: 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)
if (!ECSExtensions.Exists(entity) || !ECSExtensions.Has<UserMapZonePackedRevealElement>(entity) || ECSExtensions.Has<PlayerCharacter>(entity))
{
return false;
}
return ECSExtensions.ReadBuffer<UserMapZonePackedRevealElement>(entity).Length > 0;
}
public static bool IdEquals(this Entity entity, string id)
{
//IL_0001: 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)
if (!entity.HasId())
{
return false;
}
return entity.GetId() == id;
}
public static bool IdEqualsAny(this Entity entity, params string[] ids)
{
//IL_0001: 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.HasId())
{
return false;
}
foreach (string text in ids)
{
if (entity.GetId() == text)
{
return true;
}
}
return false;
}
}
[BepInPlugin("ScarletSigns", "ScarletSigns", "1.0.0")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
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 static Settings Settings { get; private set; }
public static Database Database { 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
//IL_0096: Unknown result type (might be due to invalid IL or missing references)
//IL_00a0: Expected O, but got Unknown
//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
//IL_00b0: 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>("ScarletSigns");
((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" version ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("1.0.0");
((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" is loaded!");
}
log.LogInfo(val);
_harmony = new Harmony("ScarletSigns");
_harmony.PatchAll(Assembly.GetExecutingAssembly());
Settings = new Settings("ScarletSigns", (BasePlugin)(object)Instance);
Database = new Database("ScarletSigns");
CommandRegistry.RegisterAll();
GameSystems.OnInitialize((Action)OnInitialize);
}
private void OnInitialize()
{
SignService.Initialize();
}
public override bool Unload()
{
Harmony harmony = _harmony;
if (harmony != null)
{
harmony.UnpatchSelf();
}
CommandRegistry.UnregisterAssembly();
return true;
}
}
public static class MyPluginInfo
{
public const string PLUGIN_GUID = "ScarletSigns";
public const string PLUGIN_NAME = "ScarletSigns";
public const string PLUGIN_VERSION = "1.0.0";
}
}
namespace ScarletSigns.Service
{
public static class SignService
{
public static readonly PrefabGUID HorsePrefab = new PrefabGUID(1149585723);
public static readonly PrefabGUID SignpostPrefab = new PrefabGUID(314589946);
public static readonly PrefabGUID InvisibilityBuff = new PrefabGUID(1160901934);
public static readonly PrefabGUID ImmaterialBuff = new PrefabGUID(1360141727);
public const string Style = "<size={0}><color={1}>{2}";
public const string SignId = "ScarletSign";
public static readonly List<Entity> Signs = new List<Entity>();
public static void Initialize()
{
LoadSigns();
}
public static void LoadSigns()
{
//IL_002d: Unknown result type (might be due to invalid IL or missing references)
//IL_0032: Unknown result type (might be due to invalid IL or missing references)
//IL_0037: Unknown result type (might be due to invalid IL or missing references)
//IL_003c: Unknown result type (might be due to invalid IL or missing references)
//IL_0041: Unknown result type (might be due to invalid IL or missing references)
//IL_0046: Unknown result type (might be due to invalid IL or missing references)
//IL_0048: Unknown result type (might be due to invalid IL or missing references)
//IL_0068: Unknown result type (might be due to invalid IL or missing references)
Signs.Clear();
NativeArray<Entity> val = EntityLookupService.Query((EntityQueryOptions)2, new Type[2]
{
typeof(Mountable),
typeof(UserMapZonePackedRevealElement)
});
try
{
Enumerator<Entity> enumerator = val.GetEnumerator();
while (enumerator.MoveNext())
{
Entity current = enumerator.Current;
string id = current.GetId();
if (!(id != "ScarletSign"))
{
Signs.Add(current);
}
}
}
finally
{
val.Dispose();
}
}
public static bool Create(string name, float3 position, float fontSize, string color = "white", bool showSignPost = false)
{
//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_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_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_0040: Unknown result type (might be due to invalid IL or missing references)
//IL_0045: Unknown result type (might be due to invalid IL or missing references)
//IL_004b: Unknown result type (might be due to invalid IL or missing references)
//IL_005c: Unknown result type (might be due to invalid IL or missing references)
//IL_0079: Unknown result type (might be due to invalid IL or missing references)
//IL_006c: Unknown result type (might be due to invalid IL or missing references)
//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
//IL_0112: Unknown result type (might be due to invalid IL or missing references)
//IL_0117: Unknown result type (might be due to invalid IL or missing references)
//IL_0128: Unknown result type (might be due to invalid IL or missing references)
//IL_012d: Unknown result type (might be due to invalid IL or missing references)
//IL_013e: Unknown result type (might be due to invalid IL or missing references)
//IL_014a: Unknown result type (might be due to invalid IL or missing references)
//IL_0156: Unknown result type (might be due to invalid IL or missing references)
//IL_016f: Unknown result type (might be due to invalid IL or missing references)
//IL_017b: Unknown result type (might be due to invalid IL or missing references)
string text = FormatString(name, fontSize, color);
Entity horse = SpawnerService.ImmediateSpawn(HorsePrefab, position, 0f, 0f, 0f, default(Entity));
horse.SetId("ScarletSign");
if (ECSExtensions.Has<SnapToHeight>(horse))
{
ECSExtensions.Remove<SnapToHeight>(horse);
}
ECSExtensions.HasWith<Interactable>(horse, (WithRefHandler<Interactable>)delegate(ref Interactable interactable)
{
interactable.Disabled = true;
});
ECSExtensions.HasWith<NameableInteractable>(horse, (WithRefHandler<NameableInteractable>)delegate(ref NameableInteractable nameable)
{
//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)
nameable.Name = new FixedString64Bytes(text);
});
ECSExtensions.AddWith<Immortal>(horse, (WithRefHandler<Immortal>)delegate(ref Immortal immortal)
{
immortal.IsImmortal = true;
});
ECSExtensions.With<DynamicCollision>(horse, (WithRefHandler<DynamicCollision>)delegate(ref DynamicCollision dynamicCollision)
{
dynamicCollision.Immobile = true;
});
BuffService.TryApplyBuff(horse, InvisibilityBuff, -1f);
BuffService.TryApplyBuff(horse, ImmaterialBuff, -1f);
ECSExtensions.Remove<SnapToHeight>(horse);
ECSExtensions.Remove<DisableWhenNoPlayersInRange>(horse);
ECSExtensions.Add<PreventDisableWhenNoPlayersInRange>(horse);
ActionScheduler.DelayedFrames((Action)delegate
{
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
//IL_0008: Unknown result type (might be due to invalid IL or missing references)
TeleportService.TeleportToPosition(horse, position, true);
}, 10);
Signs.Add(horse);
return true;
}
public static Entity Get(float3 position, float distance = 2f)
{
//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_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)
//IL_001e: 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_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_0053: Unknown result type (might be due to invalid IL or missing references)
foreach (Entity sign in Signs)
{
if (math.distance(ECSExtensions.Position(sign), position) < distance)
{
return sign;
}
}
return Entity.Null;
}
public static Entity Rename(float3 position, string newName, float distance = 2f, float fontSize = 25f, string color = "white")
{
//IL_0007: 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_000f: 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_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_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_004b: Unknown result type (might be due to invalid IL or missing references)
Entity val = Get(position, distance);
if (!ECSExtensions.Exists(val))
{
return Entity.Null;
}
string text = FormatString(newName, fontSize, color);
ECSExtensions.HasWith<NameableInteractable>(val, (WithRefHandler<NameableInteractable>)delegate(ref NameableInteractable nameable)
{
//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)
nameable.Name = new FixedString64Bytes(text);
});
return val;
}
public static string FormatString(string name, float fontSize, string color)
{
return TruncateToByteLimit("<size={0}><color={1}>{2}".Replace("{0}", fontSize.ToString()).Replace("{1}", color).Replace("{2}", name)
.Replace("\\n", "\n"), 61);
}
public static bool Remove(float3 position, float distance = 2f)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0003: Unknown result type (might be due to invalid IL or missing references)
//IL_0008: Unknown result type (might be due to invalid IL or missing references)
//IL_000c: Unknown result type (might be due to invalid IL or missing references)
//IL_0011: Unknown result type (might be due to invalid IL or missing references)
//IL_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_001d: 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_003e: 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_0044: Unknown result type (might be due to invalid IL or missing references)
//IL_0057: Unknown result type (might be due to invalid IL or missing references)
//IL_0064: Unknown result type (might be due to invalid IL or missing references)
Enumerator<Entity> enumerator = EntityLookupService.GetAllEntitiesInRadius(position, distance).GetEnumerator();
while (enumerator.MoveNext())
{
Entity current = enumerator.Current;
if (ECSExtensions.Exists(current) && current.IdEquals("ScarletSign"))
{
float num = math.distance(ECSExtensions.Position(current), position);
if (!(num > distance))
{
ECSExtensions.Destroy(current, false);
Signs.Remove(current);
return true;
}
}
}
return false;
}
private static string TruncateToByteLimit(string input, int maxBytes)
{
if (string.IsNullOrEmpty(input))
{
return input;
}
Encoding uTF = Encoding.UTF8;
if (uTF.GetByteCount(input) <= maxBytes)
{
return input;
}
string text = input;
while (uTF.GetByteCount(text) > maxBytes && text.Length > 0)
{
string text2 = text;
text = text2.Substring(0, text2.Length - 1);
}
return text;
}
}
}
namespace ScarletSigns.Patches
{
[HarmonyPatch]
public static class BuffSpawnPatch
{
public static readonly PrefabGUID DownedHorseBuff = new PrefabGUID(-266455478);
[HarmonyPatch(typeof(DownedEventSystem), "OnUpdate")]
[HarmonyPrefix]
public static void Prefix(ref DownedEventSystem __instance)
{
//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_000c: Unknown result type (might be due to invalid IL or missing references)
//IL_0011: Unknown result type (might be due to invalid IL or missing references)
//IL_0016: Unknown result type (might be due to invalid IL or missing references)
//IL_001a: Unknown result type (might be due to invalid IL or missing references)
//IL_001f: Unknown result type (might be due to invalid IL or missing references)
//IL_0024: Unknown result type (might be due to invalid IL or missing references)
//IL_0029: Unknown result type (might be due to invalid IL or missing references)
//IL_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_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_0038: 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_004a: Unknown result type (might be due to invalid IL or missing references)
//IL_0064: Unknown result type (might be due to invalid IL or missing references)
//IL_0066: Unknown result type (might be due to invalid IL or missing references)
//IL_0071: Unknown result type (might be due to invalid IL or missing references)
EntityQuery downedEventQuery = __instance._DownedEventQuery;
Enumerator<Entity> enumerator = ((EntityQuery)(ref downedEventQuery)).ToEntityArray(AllocatorHandle.op_Implicit((Allocator)2)).GetEnumerator();
while (enumerator.MoveNext())
{
Entity current = enumerator.Current;
Entity entity = ECSExtensions.Read<DownedEvent>(current).Entity;
if (ECSExtensions.Has<Mountable>(entity) && entity.HasId() && entity.IdEquals("ScarletSign"))
{
BuffService.TryRemoveBuff(entity, DownedHorseBuff);
ECSExtensions.HasWith<Health>(entity, (WithRefHandler<Health>)delegate(ref Health health)
{
//IL_0003: 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)
health.Value = ModifiableFloat.op_Implicit(health.MaxHealth);
health.MaxRecoveryHealth = ModifiableFloat.op_Implicit(health.MaxHealth);
});
}
}
}
}
}
namespace ScarletSigns.Commands
{
[CommandGroup("sign", null)]
public static class Commands
{
[Command("create", null, null, null, null, true)]
public static void CreateSign(ChatCommandContext context, string text, string color = "white", float fontSize = 18f)
{
//IL_0002: 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)
PlayerData playerData = PlayerDataExtensions.GetPlayerData(context.User);
if (playerData == null)
{
context.Reply(RichTextFormatter.FormatError("Player data not found."));
return;
}
SignService.Create(text, playerData.Position, fontSize, color);
context.Reply(RichTextFormatter.FormatSuccess("Sign created successfully."));
}
[Command("rename", null, null, null, null, true)]
public static void RenameSign(ChatCommandContext context, string newName, string color = "white", float fontSize = 18f)
{
//IL_0002: 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_0037: Unknown result type (might be due to invalid IL or missing references)
PlayerData playerData = PlayerDataExtensions.GetPlayerData(context.User);
if (playerData == null)
{
context.Reply(RichTextFormatter.FormatError("Player data not found."));
return;
}
SignService.Rename(playerData.Position, newName, 2f, fontSize, color);
context.Reply(RichTextFormatter.FormatSuccess("Sign renamed successfully."));
}
[Command("remove", null, null, null, null, true)]
public static void Remove(ChatCommandContext context, float radius = 1f)
{
//IL_0002: 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)
PlayerData playerData = PlayerDataExtensions.GetPlayerData(context.User);
if (playerData == null)
{
context.Reply(RichTextFormatter.FormatError("Player data not found."));
return;
}
if (!SignService.Remove(playerData.Position, radius))
{
context.Reply(RichTextFormatter.FormatError("No sign found nearby to remove."));
}
context.Reply(RichTextFormatter.FormatSuccess("Sign removed successfully."));
}
}
}