using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Text.RegularExpressions;
using BepInEx;
using BepInEx.Configuration;
using DataModel;
using HarmonyLib;
using ModdingTales;
using Newtonsoft.Json;
using Spaghet.Runtime;
using Unity.Mathematics;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("TemplatePlugin")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Nth Dimension")]
[assembly: AssemblyProduct("TemplatePlugin")]
[assembly: AssemblyCopyright("Copyright © 2025")]
[assembly: AssemblyTrademark("TemplatePlugin")]
[assembly: ComVisible(false)]
[assembly: Guid("c303405d-e66c-4316-9cdb-4e3ca15c6360")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace LordAshes;
[BepInPlugin("org.lordashes.plugins.relay", "Relay Plugin", "2.0.0.0")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class RelayPlugin : BaseUnityPlugin
{
internal class HideImplementation
{
public static Guid subscription;
public static void Start()
{
if (subscription != default(Guid))
{
LoggingPlugin.LogDebug("Unsubscribing From Hide Subscription");
AssetDataPlugin.Unsubscribe(subscription);
}
LoggingPlugin.LogDebug("Subscribing To Hide Request");
subscription = AssetDataPlugin.Subscribe("org.lordashes.plugins.relay.hide", (Action<DatumChange>)HideRequest);
}
public static void HideRequest(DatumChange change)
{
//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)
//IL_0062: Unknown result type (might be due to invalid IL or missing references)
//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
LoggingPlugin.LogDebug("Notification: [Hide]: " + JsonConvert.SerializeObject((object)change));
CreatureBoardAsset val = null;
CreaturePresenter.TryGetAsset(new CreatureGuid(change.source), ref val);
if ((Object)(object)val != (Object)null)
{
LoggingPlugin.LogDebug("Setting Creature " + val.Name + " (" + ((object)val.CreatureId/*cast due to .constrained prefix*/).ToString() + ") Hide State To " + (change.value.ToString() != "0"));
if (change.value.ToString() == "0")
{
CreatureManager.SetCreatureExplicitHideState(val.CreatureId, false);
}
else
{
CreatureManager.SetCreatureExplicitHideState(val.CreatureId, true);
}
}
}
}
public static class InteractionsImplementation
{
public class P3
{
public float x { get; set; }
public float y { get; set; }
public float z { get; set; }
public static P3 FromFloat3(float3 f3)
{
//IL_0007: 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_0021: Unknown result type (might be due to invalid IL or missing references)
return new P3
{
x = f3.x,
y = f3.y,
z = f3.z
};
}
public float3 ToFloat3()
{
//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 new float3(x, y, z);
}
public override string ToString()
{
return "(" + x + "," + y + "," + z + ")";
}
}
[HarmonyPatch(typeof(Zone), "SendScriptMessage")]
public static class PatchZoneSendScriptMessage
{
public static void Postfix(Zone __instance, in LocalMessageToScript message, ClientZoneData[] ____perClientZoneAssetData)
{
if (_LastObject != "")
{
string[] obj = new string[5] { "Object '", _LastObject, "' Has Changed To State '", null, null };
ushort expectededOpIndex = message.ExpectededOpIndex;
obj[3] = expectededOpIndex.ToString();
obj[4] = "'";
LoggingPlugin.LogDebug(string.Concat(obj));
string lastObject = _LastObject;
expectededOpIndex = message.ExpectededOpIndex;
AssetDataPlugin.SetInfo(lastObject, "org.lordashes.plugins.relay.interaction", expectededOpIndex.ToString(), false);
}
}
}
[HarmonyPatch(typeof(PlaceableHandle), "Interact")]
public static class PatchPlaceableHandleInteract
{
public static void Postfix(PlaceableHandle __instance, float3 pickPosition)
{
//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_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_003a: 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)
_LastClick = pickPosition;
float num = 999f;
string text = "";
foreach (KeyValuePair<string, P3> interactiveObject in interactiveObjects)
{
float num2 = Vector3.Distance(float3.op_Implicit(pickPosition), float3.op_Implicit(interactiveObject.Value.ToFloat3()));
LoggingPlugin.LogDebug("Analyzing '" + interactiveObject.Key + "' At " + interactiveObject.Value.ToString() + ", Dist: " + num2);
if ((double)num2 < 2.0)
{
LoggingPlugin.LogTrace("Might Be '" + interactiveObject.Key + "'");
if (num2 < num)
{
num = num2;
text = interactiveObject.Key;
}
}
}
if (num == 999f)
{
LoggingPlugin.LogDebug("Interaction: Not With A Monitoried Object");
_LastObject = "";
}
else
{
LoggingPlugin.LogDebug("Interaction: With '" + text + "'");
_LastObject = text;
}
}
}
public static Dictionary<string, P3> interactiveObjects = new Dictionary<string, P3>();
public static float3 _LastClick = float3.zero;
public static string _LastObject = "";
public static void Start()
{
try
{
string text = "org.lordashes.plugins.relay.Interaction." + ((object)Unsafe.As<CampaignGuid, CampaignGuid>(ref BoardSessionManager.CurrentBoardInfo.CampaignId)/*cast due to .constrained prefix*/).ToString() + "." + ((object)Unsafe.As<BoardGuid, BoardGuid>(ref BoardSessionManager.CurrentBoardInfo.Id)/*cast due to .constrained prefix*/).ToString() + ".json";
LoggingPlugin.LogDebug("Loading Object Interactions For '" + BoardSessionManager.CurrentBoardInfo.BoardName + "' (" + ((object)Unsafe.As<CampaignGuid, CampaignGuid>(ref BoardSessionManager.CurrentBoardInfo.CampaignId)/*cast due to .constrained prefix*/).ToString() + ":" + ((object)Unsafe.As<BoardGuid, BoardGuid>(ref BoardSessionManager.CurrentBoardInfo.Id)/*cast due to .constrained prefix*/).ToString() + ")");
if (File.Exists(text))
{
string text2 = File.ReadAllText(text, (CacheType)999);
interactiveObjects = JsonConvert.DeserializeObject<Dictionary<string, P3>>(text2);
return;
}
LoggingPlugin.LogDebug("Missing Object Interactions File 'org.lordashes.plugins.relay." + ((object)Unsafe.As<CampaignGuid, CampaignGuid>(ref BoardSessionManager.CurrentBoardInfo.CampaignId)/*cast due to .constrained prefix*/).ToString() + "." + ((object)Unsafe.As<BoardGuid, BoardGuid>(ref BoardSessionManager.CurrentBoardInfo.Id)/*cast due to .constrained prefix*/).ToString() + "'");
interactiveObjects = new Dictionary<string, P3>();
}
catch (Exception ex)
{
Reflection.CatchFullError(ex);
}
}
}
public static class Relayimplementation
{
public class Relay
{
public string trigger { get; set; }
public string condition { get; set; }
public string reaction { get; set; }
public float reactionDelay { get; set; } = 0f;
public string reactionAsset { get; set; }
public string reactionValue { get; set; }
public string description { get; set; } = "Relay";
}
public class Relays
{
public Dictionary<string, string> sources = new Dictionary<string, string>();
public List<Relay> relays = new List<Relay>();
public Dictionary<string, string> sinks = new Dictionary<string, string>();
}
private static Relays relays = null;
public static List<Guid> subscriptions = new List<Guid>();
public static void Start()
{
try
{
LoggingPlugin.LogTrace("Reading Relay Configuration");
string text = "org.lordashes.plugins.relay.Relay." + ((object)Unsafe.As<CampaignGuid, CampaignGuid>(ref BoardSessionManager.CurrentBoardInfo.CampaignId)/*cast due to .constrained prefix*/).ToString() + "." + ((object)Unsafe.As<BoardGuid, BoardGuid>(ref BoardSessionManager.CurrentBoardInfo.Id)/*cast due to .constrained prefix*/).ToString() + ".json";
if (File.Exists(text))
{
LoggingPlugin.LogDebug("Reading Relay Configuration '" + text + "' File");
relays = JsonConvert.DeserializeObject<Relays>(File.ReadAllText(text, (CacheType)999));
}
else
{
LoggingPlugin.LogDebug("Relay Configuration File '" + text + "' Mising");
}
LoggingPlugin.LogDebug("Unsubscribing To Relay Sources");
foreach (Guid subscription in subscriptions)
{
LoggingPlugin.LogTrace("Unsubscribing To Relay Sources " + subscription);
AssetDataPlugin.Unsubscribe(subscription);
}
subscriptions.Clear();
LoggingPlugin.LogDebug("Subscribing To Relay Sources");
foreach (KeyValuePair<string, string> source in relays.sources)
{
LoggingPlugin.LogDebug("Subscribing To Relay Sources " + source.Key + " (" + source.Value + ")");
subscriptions.Add(AssetDataPlugin.Subscribe(source.Value, (Action<DatumChange>)delegate(DatumChange change)
{
SubscriptionNotification(source.Key, change);
}));
}
}
catch (Exception ex)
{
Reflection.CatchFullError(ex);
}
}
public static void SubscriptionNotification(string name, DatumChange change)
{
//IL_0446: Unknown result type (might be due to invalid IL or missing references)
//IL_044b: Unknown result type (might be due to invalid IL or missing references)
//IL_04f9: Unknown result type (might be due to invalid IL or missing references)
//IL_04fe: Unknown result type (might be due to invalid IL or missing references)
//IL_0177: Unknown result type (might be due to invalid IL or missing references)
//IL_017c: Unknown result type (might be due to invalid IL or missing references)
//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
//IL_05b8: Unknown result type (might be due to invalid IL or missing references)
//IL_0655: Unknown result type (might be due to invalid IL or missing references)
//IL_061b: Unknown result type (might be due to invalid IL or missing references)
//IL_0620: Unknown result type (might be due to invalid IL or missing references)
//IL_06a4: Unknown result type (might be due to invalid IL or missing references)
//IL_0741: Unknown result type (might be due to invalid IL or missing references)
//IL_0707: Unknown result type (might be due to invalid IL or missing references)
//IL_070c: Unknown result type (might be due to invalid IL or missing references)
try
{
LoggingPlugin.LogDebug("Notification: [" + name + "]: " + JsonConvert.SerializeObject((object)change));
foreach (Relay item in relays.relays.Where((Relay r) => r.trigger == name))
{
LoggingPlugin.LogDebug("Evaluation: [" + name + "]: Condition: " + item.condition);
bool flag = true;
string reactionAsset = item.reactionAsset;
string text = ((item.reactionValue != null) ? item.reactionValue : "");
CreatureBoardAsset val = null;
try
{
CreaturePresenter.TryGetAsset(new CreatureGuid(change.source.ToString()), ref val);
}
catch
{
}
bool flag2 = (Object)(object)val != (Object)null && isPC(val);
if (item.condition != "")
{
string[] array = item.condition.Split(new char[1] { '|' });
if (array.Length == 1)
{
array = new string[2]
{
"{V}",
array[0]
};
}
array[0] = array[0].Replace("{?}", flag2 ? "T" : "F");
array[0] = array[0].Replace("{A}", ((object)change.action/*cast due to .constrained prefix*/).ToString());
array[0] = array[0].Replace("{K}", change.key.ToString());
array[0] = array[0].Replace("{N}", ((Object)(object)val != (Object)null) ? val.Name : change.source.ToString());
array[0] = array[0].Replace("{P}", change.previous.ToString());
array[0] = array[0].Replace("{S}", change.source.ToString());
array[0] = array[0].Replace("{V}", change.value.ToString());
Regex regex = new Regex(array[1]);
flag = regex.IsMatch(array[0]);
LoggingPlugin.LogTrace("Evaluation: [" + name + "]: Match: " + flag + ", Input: " + array[0] + ", Condition: " + array[1]);
if (flag)
{
MatchCollection matchCollection = regex.Matches(array[0]);
LoggingPlugin.LogTrace("Evaluation: [" + name + "]: Matches: " + ((matchCollection != null) ? matchCollection.Count.ToString() : "Null"));
int num = 0;
foreach (Match item2 in matchCollection)
{
num++;
LoggingPlugin.LogTrace("Evaluation: [" + name + "]: Replacing {" + num + "} With " + item2.Value.ToString());
text = text.Replace("{" + num + "}", item2.Value.ToString());
LoggingPlugin.LogTrace("Evaluation: [" + name + "]: Replacing $ Reference");
text = ((text.IndexOf("$") > -1) ? item2.Result(text) : text);
}
LoggingPlugin.LogTrace("Evaluation: [" + name + "]: Reaction: " + item.reaction + ", Request: " + text);
}
}
if (!flag)
{
continue;
}
text = text.Replace("{A}", ((object)change.action/*cast due to .constrained prefix*/).ToString());
text = text.Replace("{K}", change.key.ToString());
text = text.Replace("{N}", ((Object)(object)val != (Object)null) ? val.Name : change.source.ToString());
text = text.Replace("{P}", change.previous.ToString());
text = text.Replace("{S}", change.source.ToString());
text = text.Replace("{V}", change.value.ToString());
reactionAsset = reactionAsset.Replace("{A}", ((object)change.action/*cast due to .constrained prefix*/).ToString());
reactionAsset = reactionAsset.Replace("{K}", change.key.ToString());
reactionAsset = reactionAsset.Replace("{N}", ((Object)(object)val != (Object)null) ? val.Name : change.source.ToString());
reactionAsset = reactionAsset.Replace("{P}", change.previous.ToString());
reactionAsset = reactionAsset.Replace("{S}", change.source.ToString());
reactionAsset = reactionAsset.Replace("{V}", change.value.ToString());
string nameRef;
for (nameRef = GetFirstBracketValue(text); nameRef != null; nameRef = GetFirstBracketValue(text))
{
CreatureBoardAsset val2 = ((IEnumerable<CreatureBoardAsset>)(object)CreaturePresenter.GetTempReadOnlyViewOfAllCreatureAssets()).Where((CreatureBoardAsset cba) => cba.Name.ToLower() == nameRef.ToLower()).FirstOrDefault();
text = ((!((Object)(object)val2 != (Object)null)) ? text.Replace("{" + nameRef + "}", ((object)default(CreatureGuid)/*cast due to .constrained prefix*/).ToString()) : text.Replace("{" + nameRef + "}", ((object)val2.CreatureId/*cast due to .constrained prefix*/).ToString()));
}
for (nameRef = GetFirstBracketValue(reactionAsset); nameRef != null; nameRef = GetFirstBracketValue(reactionAsset))
{
CreatureBoardAsset val3 = ((IEnumerable<CreatureBoardAsset>)(object)CreaturePresenter.GetTempReadOnlyViewOfAllCreatureAssets()).Where((CreatureBoardAsset cba) => cba.Name.ToLower() == nameRef.ToLower()).FirstOrDefault();
reactionAsset = ((!((Object)(object)val3 != (Object)null)) ? reactionAsset.Replace("{" + nameRef + "}", ((object)default(CreatureGuid)/*cast due to .constrained prefix*/).ToString()) : reactionAsset.Replace("{" + nameRef + "}", ((object)val3.CreatureId/*cast due to .constrained prefix*/).ToString()));
}
LoggingPlugin.LogDebug("Requesting: [" + item.reaction + "]: Asset: " + reactionAsset + ", Sink: " + relays.sinks[item.reaction] + ", Request: " + text);
((MonoBehaviour)_self).StartCoroutine(Reaction(item.reactionDelay, reactionAsset, relays.sinks[item.reaction], text));
}
}
catch (Exception ex)
{
Reflection.CatchFullError(ex);
}
}
private static IEnumerator Reaction(float delay, string source, string key, string value)
{
LoggingPlugin.LogTrace("Delaying: Source: " + source + ", key: " + key + ", Value: " + value);
yield return (object)new WaitForSeconds(delay);
LoggingPlugin.LogTrace("Triggering: Source: " + source + ", key: " + key + ", Value: " + value);
AssetDataPlugin.SetInfo(source, key, value, false);
}
public static string GetFirstBracketValue(string input)
{
Match match = Regex.Match(input, "\\{(.{2,})\\}");
return match.Success ? match.Groups[1].Value : null;
}
public static bool isPC(CreatureBoardAsset cba)
{
//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_001f: Unknown result type (might be due to invalid IL or missing references)
foreach (PlayerGuid key in CampaignSessionManager.PlayersInfo.Keys)
{
if (CreatureManager.PlayerOwnsCreature(key, cba.CreatureId))
{
return true;
}
}
return false;
}
}
public const string Name = "Relay Plugin";
public const string Guid = "org.lordashes.plugins.relay";
public const string Version = "2.0.0.0";
public const string Author = "Lord Ashes";
public static RelayPlugin _self;
private void Awake()
{
//IL_001e: Unknown result type (might be due to invalid IL or missing references)
//IL_0039: Unknown result type (might be due to invalid IL or missing references)
//IL_003e: Unknown result type (might be due to invalid IL or missing references)
//IL_0061: Unknown result type (might be due to invalid IL or missing references)
//IL_0067: Expected O, but got Unknown
_self = this;
LoggingPlugin.SetLogLevel(((BaseUnityPlugin)this).Config.Bind<DiagnosticLevel>("Settings", "Diagnostic Level", (DiagnosticLevel)3, (ConfigDescription)null).Value);
Debug.Log((object)(((object)this).GetType().AssemblyQualifiedName + ": Active. (Diagnostic Mode = " + ((object)LoggingPlugin.GetLogLevel()/*cast due to .constrained prefix*/).ToString() + ")"));
Harmony val = new Harmony("org.lordashes.plugins.relay");
val.PatchAll();
BoardSessionManager.OnCurrentBoardChanged += delegate
{
Relayimplementation.Start();
InteractionsImplementation.Start();
};
Relayimplementation.Start();
InteractionsImplementation.Start();
HideImplementation.Start();
ModdingUtils.AddPluginToMenuList((BaseUnityPlugin)(object)this, "Lord Ashes'");
}
private void Update()
{
//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)
KeyboardShortcut val = new KeyboardShortcut((KeyCode)96, Array.Empty<KeyCode>());
if (((KeyboardShortcut)(ref val)).IsUp())
{
SystemMessage.AskForTextInput("Interactive Object:", "Name:", "Add", (Action<string>)delegate(string s)
{
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
InteractionsImplementation.interactiveObjects.Add(s, InteractionsImplementation.P3.FromFloat3(InteractionsImplementation._LastClick));
SystemMessage.DisplayInfoText("Added '" + s + "' At " + ((object)Unsafe.As<float3, float3>(ref InteractionsImplementation._LastClick)/*cast due to .constrained prefix*/).ToString(), 2.5f, 0f, (Action)null);
LoggingPlugin.LogInfo("File: org.lordashes.plugins.relay." + ((object)Unsafe.As<CampaignGuid, CampaignGuid>(ref BoardSessionManager.CurrentBoardInfo.CampaignId)/*cast due to .constrained prefix*/).ToString() + "." + ((object)Unsafe.As<BoardGuid, BoardGuid>(ref BoardSessionManager.CurrentBoardInfo.Id)/*cast due to .constrained prefix*/).ToString());
LoggingPlugin.LogInfo(JsonConvert.SerializeObject((object)InteractionsImplementation.interactiveObjects, (Formatting)1));
}, (Action)null, "Cancel", (Action)null, "Bob");
}
}
}