using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security.Cryptography;
using System.Text;
using BepInEx;
using BepInEx.Configuration;
using Bounce.ManagedCollections;
using Bounce.Singletons;
using GameChat.UI;
using HarmonyLib;
using Newtonsoft.Json;
using TMPro;
using Unity.Mathematics;
using UnityEngine;
using UnityEngine.SceneManagement;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("ProximityRollerPlugin")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ProximityRollerPlugin")]
[assembly: AssemblyCopyright("Copyright © 2023")]
[assembly: AssemblyTrademark("ProximityRollerPlugin")]
[assembly: ComVisible(false)]
[assembly: Guid("c303405d-e66c-4316-9cdb-4e3ca15c6360")]
[assembly: AssemblyFileVersion("2.1.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("2.1.0.0")]
namespace LordAshes;
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInPlugin("org.lordashes.plugins.proximityroller", "Proximity Roller Plug-In", "2.1.0.0")]
public class ProximityRollerPlugin : BaseUnityPlugin
{
public class Patches
{
[HarmonyPatch(typeof(DiceManager), "SendDiceResult")]
private static class PatchSendDiceResult
{
public static bool Prefix(bool isGmOnly, ref RollResults rollResultData)
{
//IL_002b: Unknown result type (might be due to invalid IL or missing references)
//IL_0030: Unknown result type (might be due to invalid IL or missing references)
//IL_0035: 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_0042: 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_004e: Unknown result type (might be due to invalid IL or missing references)
//IL_0053: Unknown result type (might be due to invalid IL or missing references)
//IL_006e: 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_00cb: Unknown result type (might be due to invalid IL or missing references)
//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
//IL_00dc: Expected O, but got Unknown
if (showSummary.Value && storeResult)
{
List<RollResultsGroup> list = new List<RollResultsGroup>();
Enumerator<RollResultsGroup> enumerator = rollResultData.ResultsGroups.GetEnumerator();
try
{
while (enumerator.MoveNext())
{
RollResultsGroup current = enumerator.Current;
list.Add(new RollResultsGroup("_" + current.Name, current.Result));
Debug.Log((object)("Proximity Roller Plug-In: Modified Group Name To _" + current.Name + " (Summary: " + showSummary.Value + ")"));
}
}
finally
{
((IDisposable)enumerator).Dispose();
}
rollResultData = new RollResults(rollResultData.RollId, rollResultData.ClientId, new BList<RollResultsGroup>(list));
}
return true;
}
}
[HarmonyPatch(typeof(UIDiceRollResult), "DisplayResult")]
private static class PatchDisplayResult
{
public static bool Prefix(RollResults rollResultData, ClientGuid sender)
{
//IL_004c: 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)
if (showSummary.Value && rollResultData != null && rollResultData.ResultsGroups != null && rollResultData.ResultsGroups.Length > 0 && rollResultData.ResultsGroups[0].Name != null && rollResultData.ResultsGroups[0].Name.StartsWith("_"))
{
Debug.Log((object)"Proximity Roller Plug-In: Supressing DisplayResult");
return false;
}
return true;
}
}
[HarmonyPatch(typeof(UIChatMessageManager), "AddDiceResultMessage")]
private static class PatchAddDiceResultMessage
{
public static bool Prefix(RollResults diceResult, ResultsOrigin origin, ClientGuid sender, bool hidden)
{
//IL_004c: 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)
if (showSummary.Value && diceResult != null && diceResult.ResultsGroups != null && diceResult.ResultsGroups.Length > 0 && diceResult.ResultsGroups[0].Name != null && diceResult.ResultsGroups[0].Name.StartsWith("_"))
{
Debug.Log((object)"Proximity Roller Plug-In: Supressing AddDiceResultMessage");
return false;
}
return true;
}
}
[HarmonyPatch(typeof(DiceManager), "ThrowDice")]
private static class PatchThrowDice
{
public static bool Prefix(RollId rollId, float3 velocity)
{
//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_0089: Unknown result type (might be due to invalid IL or missing references)
//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
//IL_01c5: Unknown result type (might be due to invalid IL or missing references)
//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
//IL_012b: Unknown result type (might be due to invalid IL or missing references)
//IL_0140: Unknown result type (might be due to invalid IL or missing references)
//IL_0161: Unknown result type (might be due to invalid IL or missing references)
//IL_016b: Unknown result type (might be due to invalid IL or missing references)
//IL_017d: Unknown result type (might be due to invalid IL or missing references)
//IL_0191: Unknown result type (might be due to invalid IL or missing references)
//IL_01ed: Unknown result type (might be due to invalid IL or missing references)
//IL_01f2: Unknown result type (might be due to invalid IL or missing references)
//IL_0224: Unknown result type (might be due to invalid IL or missing references)
//IL_0239: Unknown result type (might be due to invalid IL or missing references)
//IL_025a: Unknown result type (might be due to invalid IL or missing references)
//IL_0264: Unknown result type (might be due to invalid IL or missing references)
//IL_0276: Unknown result type (might be due to invalid IL or missing references)
//IL_028a: Unknown result type (might be due to invalid IL or missing references)
if (Input.GetKey((KeyCode)304) && !storeResult)
{
storeResult = true;
Debug.Log((object)("Proximity Roller Plug-In: Throwing Dice In Proximity To " + ((object)(RollId)(ref rollId)).ToString()));
Die[] array = Resources.FindObjectsOfTypeAll<Die>();
Die val = array.Where((Die d) => d.RollId.AsLong == rollId.AsLong).ElementAt(0);
Die[] array2 = array;
RollId rollId2;
foreach (Die val2 in array2)
{
if (val2.RollId.AsLong != rollId.AsLong && val2.RollId.AsLong != 0L && Vector3.Distance(((Component)val).gameObject.transform.position, ((Component)val2).gameObject.transform.position) < proximity.Value)
{
rollId2 = val2.RollId;
Debug.Log((object)("Proximity Roller Plug-In: Throwing Die " + ((object)(RollId)(ref rollId2)).ToString()));
((Component)val2).gameObject.transform.position = new Vector3(((Component)val2).gameObject.transform.position.x, ((Component)val).gameObject.transform.position.y + raise.Value, ((Component)val2).gameObject.transform.position.z);
PhotonSimpleSingletonBehaviour<DiceManager>.Instance.ThrowDice(val2.RollId, new float3(0f, 1f, 0f));
}
}
Die[] array3 = array;
foreach (Die val3 in array3)
{
if (val3.RollId.AsLong == rollId.AsLong)
{
rollId2 = val3.RollId;
Debug.Log((object)("Proximity Roller Plug-In: Throwing Die " + ((object)(RollId)(ref rollId2)).ToString()));
((Component)val3).gameObject.transform.position = new Vector3(((Component)val3).gameObject.transform.position.x, ((Component)val).gameObject.transform.position.y + raise.Value, ((Component)val3).gameObject.transform.position.z);
PhotonSimpleSingletonBehaviour<DiceManager>.Instance.ThrowDice(val3.RollId, new float3(0f, 1f, 0f));
}
}
Debug.Log((object)"Proximity Roller Plug-In: Starting Cooldown");
if (showSummary.Value)
{
((MonoBehaviour)_self).StartCoroutine(cooldown(resultCollectionTime.Value));
}
else
{
storeResult = false;
}
}
return true;
}
}
public static bool storeResult;
}
public static class Utility
{
public static bool isBoardLoaded()
{
return SimpleSingletonBehaviour<CameraController>.HasInstance && SingletonStateMBehaviour<BoardSessionManager, State<BoardSessionManager>>.HasInstance && !BoardSessionManager.IsLoading;
}
public static bool StrictKeyCheck(KeyboardShortcut check)
{
//IL_002e: 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_003f: Unknown result type (might be due to invalid IL or missing references)
if (!((KeyboardShortcut)(ref check)).IsUp())
{
return false;
}
KeyCode[] array = new KeyCode[6];
RuntimeHelpers.InitializeArray(array, (RuntimeFieldHandle)/*OpCode not supported: LdMemberToken*/);
KeyCode[] array2 = (KeyCode[])(object)array;
foreach (KeyCode val in array2)
{
if (Input.GetKey(val) != ((KeyboardShortcut)(ref check)).Modifiers.Contains(val))
{
return false;
}
}
return true;
}
public static Guid GuidFromString(string input)
{
using MD5 mD = MD5.Create();
byte[] b = mD.ComputeHash(Encoding.Default.GetBytes(input));
return new Guid(b);
}
public static GameObject GetBaseLoader(CreatureGuid cid)
{
//IL_0004: Unknown result type (might be due to invalid IL or missing references)
try
{
CreatureBoardAsset val = null;
CreaturePresenter.TryGetAsset(cid, ref val);
if ((Object)(object)val != (Object)null)
{
Transform match = null;
Traverse(((Component)val).transform, "BaseLoader", 0, 10, ref match);
if ((Object)(object)match != (Object)null)
{
Debug.Log((object)("Proximity Roller Plugin: Base Loader '" + ((Object)match.GetChild(0)).name + "' Found"));
return ((Component)match.GetChild(0)).gameObject;
}
Debug.LogWarning((object)"Proximity Roller Plugin: Could Not Find Base Loader");
return null;
}
return null;
}
catch
{
return null;
}
}
public static GameObject GetAssetLoader(CreatureGuid cid)
{
//IL_0004: Unknown result type (might be due to invalid IL or missing references)
try
{
CreatureBoardAsset val = null;
CreaturePresenter.TryGetAsset(cid, ref val);
if ((Object)(object)val != (Object)null)
{
Transform match = null;
Traverse(((Component)val).transform, "AssetLoader", 0, 10, ref match);
if ((Object)(object)match != (Object)null)
{
Debug.Log((object)("Proximity Roller Plugin: Asset Loader '" + ((Object)match.GetChild(0)).name + "' Found"));
return ((Component)match.GetChild(0)).gameObject;
}
Debug.LogWarning((object)"Proximity Roller Plugin: Could Not Find Asset Loader");
return null;
}
return null;
}
catch
{
return null;
}
}
public static void Traverse(Transform root, string seek, int depth, int depthMax, ref Transform match)
{
try
{
if ((Object)(object)match != (Object)null)
{
return;
}
if (((Object)root).name == seek)
{
match = root;
return;
}
foreach (Transform item in ExtensionMethods.Children(root))
{
if (depth < depthMax)
{
Traverse(item, seek, depth + 1, depthMax, ref match);
}
}
}
catch
{
}
}
public static float ParseFloat(string value)
{
return float.Parse(value, CultureInfo.InvariantCulture);
}
public static string GetCreatureName(string nameBlock)
{
if (nameBlock == null)
{
return "(Unknown)";
}
if (!nameBlock.Contains("<size=0>"))
{
return nameBlock;
}
return nameBlock.Substring(0, nameBlock.IndexOf("<size=0>")).Trim();
}
public static void PostOnMainPage(MemberInfo plugin)
{
SceneManager.sceneLoaded += delegate(Scene scene, LoadSceneMode mode)
{
//IL_0072: Unknown result type (might be due to invalid IL or missing references)
//IL_0079: Expected O, but got Unknown
try
{
if (((Scene)(ref scene)).name == "UI")
{
TextMeshProUGUI uITextByName = GetUITextByName("BETA");
if (Object.op_Implicit((Object)(object)uITextByName))
{
((TMP_Text)uITextByName).text = "INJECTED BUILD - unstable mods";
}
}
else
{
TextMeshProUGUI uITextByName2 = GetUITextByName("TextMeshPro Text");
if (Object.op_Implicit((Object)(object)uITextByName2))
{
BepInPlugin val = (BepInPlugin)Attribute.GetCustomAttribute(plugin, typeof(BepInPlugin));
if (((TMP_Text)uITextByName2).text.EndsWith("</size>"))
{
((TMP_Text)uITextByName2).text = ((TMP_Text)uITextByName2).text + "\n\nMods Currently Installed:\n";
}
TextMeshProUGUI val2 = uITextByName2;
((TMP_Text)val2).text = ((TMP_Text)val2).text + "\nLord Ashes' " + val.Name + " - " + val.Version;
}
}
}
catch (Exception ex)
{
Debug.Log((object)ex);
}
};
}
private static TextMeshProUGUI GetUITextByName(string name)
{
TextMeshProUGUI[] array = Object.FindObjectsOfType<TextMeshProUGUI>();
for (int i = 0; i < array.Length; i++)
{
if (((Object)array[i]).name == name)
{
return array[i];
}
}
return null;
}
}
private class SimpleDiceResult
{
public string name { get; set; }
public string roll { get; set; }
public string results { get; set; }
}
public const string Name = "Proximity Roller Plug-In";
public const string Guid = "org.lordashes.plugins.proximityroller";
public const string Version = "2.1.0.0";
private static ConfigEntry<float> proximity;
private static ConfigEntry<float> raise;
private static ConfigEntry<bool> showSummary;
private static ConfigEntry<float> resultCollectionTime;
private static ConfigEntry<bool> showTotal;
private static BaseUnityPlugin _self;
private static List<SimpleDiceResult> stack = new List<SimpleDiceResult>();
private void Awake()
{
//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
//IL_00dc: Expected O, but got Unknown
Debug.Log((object)("Proximity Roller Plugin: " + ((object)this).GetType().AssemblyQualifiedName + " Active."));
_self = (BaseUnityPlugin)(object)this;
proximity = ((BaseUnityPlugin)this).Config.Bind<float>("Settings", "Affected Dice Distance", 5f, (ConfigDescription)null);
raise = ((BaseUnityPlugin)this).Config.Bind<float>("Settings", "Affected Dice Raise", 5f, (ConfigDescription)null);
showSummary = ((BaseUnityPlugin)this).Config.Bind<bool>("Settings", "Show Summary", true, (ConfigDescription)null);
resultCollectionTime = ((BaseUnityPlugin)this).Config.Bind<float>("Settings", "Collection Time", 1f, (ConfigDescription)null);
showTotal = ((BaseUnityPlugin)this).Config.Bind<bool>("Settings", "Show Total", true, (ConfigDescription)null);
SymbioteApiPlugin.Initialized((Action)delegate
{
SymbioteApiPlugin.Subscribe(new List<string> { "rollResults" }, (Action<string>)rollResultCallback);
});
Harmony val = new Harmony("org.lordashes.plugins.proximityroller");
val.PatchAll();
Utility.PostOnMainPage(((object)this).GetType());
}
public static void Summarize(bool setting)
{
showSummary.Value = setting;
Debug.Log((object)("Proximity Roller Plug-In: Summary Function Set To " + setting));
}
private void rollResultCallback(string evt)
{
if (!showSummary.Value)
{
return;
}
Debug.Log((object)("Proximity Roller Plug-In: Event: " + evt));
if (Patches.storeResult)
{
evt = evt.Substring(evt.IndexOf("\"payload\":") + "\"payload\":".Length);
SimpleDiceResult simpleDiceResult = new SimpleDiceResult();
simpleDiceResult.name = "";
if (evt.IndexOf("\"name\":\"") > -1)
{
simpleDiceResult.name = evt.Substring(evt.IndexOf("\"name\":\"") + "\"name\":\"".Length).Trim();
simpleDiceResult.name = simpleDiceResult.name.Substring(0, simpleDiceResult.name.IndexOf("\"")).Substring(1);
}
string text = evt.Substring(evt.IndexOf("\"results\":") + "\"results\":".Length).Trim();
text = (simpleDiceResult.results = text.Substring(0, text.IndexOf("}")));
simpleDiceResult.roll = text.Split(new char[1] { ',' }).Length.ToString();
if (evt.IndexOf("\"kind\":\"") > -1)
{
string text3 = evt.Substring(evt.IndexOf("\"kind\":\"") + "\"kind\":\"".Length).Trim();
simpleDiceResult.roll += text3.Substring(0, text3.IndexOf("\""));
}
else
{
simpleDiceResult.roll += "d20";
}
if (evt.IndexOf("\"operator\":\"") > -1)
{
string text4 = evt.Substring(evt.IndexOf("\"operator\":\"") + "\"operator\":\"".Length).Trim();
simpleDiceResult.roll += text4.Substring(0, text4.IndexOf("\""));
}
else
{
simpleDiceResult.roll += "+";
}
if (evt.IndexOf("\"value\":") > -1)
{
string text5 = evt.Substring(evt.IndexOf("\"value\":") + "\"value\":".Length).Trim();
simpleDiceResult.roll += text5.Substring(0, text5.IndexOf("}"));
}
else
{
simpleDiceResult.roll += "0";
}
stack.Add(simpleDiceResult);
Debug.Log((object)("Proximity Roller Plug-In: Stack: " + JsonConvert.SerializeObject((object)stack)));
}
}
public static IEnumerator cooldown(float waitTime)
{
yield return (object)new WaitForSeconds(1f);
while ((from d in Object.FindObjectsOfType<Die>()
where d.IsRolling
select d).Count() > 0)
{
Debug.Log((object)"Proximity Roller Plug-In: Dice Still Rolling");
yield return (object)new WaitForSeconds(1f);
}
yield return (object)new WaitForSeconds(resultCollectionTime.Value);
Patches.storeResult = false;
Debug.Log((object)"Proximity Roller Plug-In: Cooldown Complete. Sending Combined Results");
string js2 = "TS.extra.sendSimpleDiceResult([";
int total = 0;
foreach (SimpleDiceResult result in stack)
{
js2 = js2 + "{'name': '" + result.name + "', 'roll': '" + result.roll + "', 'results': " + result.results + "},";
result.roll = result.roll.Replace("[", "").Replace("]", "");
if (result.roll.Contains("+"))
{
total += int.Parse(result.roll.Substring(result.roll.IndexOf("+") + 1));
}
if (result.roll.Contains("-"))
{
total += int.Parse(result.roll.Substring(result.roll.IndexOf("-")));
}
string[] array = result.results.Replace("[", "").Replace("]", "").Split(new char[1] { ',' });
foreach (string value in array)
{
total += int.Parse(value);
}
}
if (showTotal.Value)
{
js2 = js2 + "{'name': 'Total', 'roll': '1D20+0', 'results': [" + total + "]},";
}
js2 = js2.Substring(0, js2.Length - 1);
js2 += "],false,false);";
SymbioteApiPlugin.Symbiote_API(js2);
Debug.Log((object)"Proximity Roller Plug-In: Clearing Collection Stack");
stack.Clear();
}
}