using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using System.Text.RegularExpressions;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using HarmonyLib;
using Il2CppInterop.Runtime.InteropTypes;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppSystem;
using Microsoft.CodeAnalysis;
using Quantum.Commands;
using UISystem;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;
using UnityEngine.UI;
using WildSkies.Gameplay.Items;
using WildSkies.Mediators;
using WildSkies.Service;
using Wildskies.UI.Hud;
using Wildskies.UI.Panel;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("SimpleChat")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyCopyright("Nines (Natives)")]
[assembly: AssemblyFileVersion("1.1.5.0")]
[assembly: AssemblyInformationalVersion("1.1.5")]
[assembly: AssemblyProduct("SimpleChat")]
[assembly: AssemblyTitle("SimpleChat")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.1.5.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 SimpleChat
{
[BepInPlugin("SimpleChat", "SimpleChat", "1.1.5")]
public class Plugin : BasePlugin
{
internal static ManualLogSource Log;
internal static Harmony harmonyInstance;
private static LargeMessageService largeMessageService = null;
private static readonly Action<LargeMessageType, Il2CppStructArray<byte>> OnLargeMessageReceived = Action<LargeMessageType, Il2CppStructArray<byte>>.op_Implicit((Action<LargeMessageType, Il2CppStructArray<byte>>)delegate(LargeMessageType messageType, Il2CppStructArray<byte> messageContents)
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
//IL_0002: Invalid comparison between Unknown and I4
if ((int)messageType == -1)
{
ShowNotification(Encoding.UTF8.GetString(Il2CppArrayBase<byte>.op_Implicit((Il2CppArrayBase<byte>)(object)messageContents)));
}
});
private static Dictionary<string, MethodInfo> _commands = null;
private static bool _enableChatKey = true;
private static readonly PanelEvent OnPanelHidden = PanelEvent.op_Implicit((Action<UIPanelType>)delegate
{
IUIService val = SceneContextInstaller.ResolveObject<IUIService>();
if (val != null)
{
UIPanelManager panelManager = val.PanelManager;
panelManager.PanelHidden -= OnPanelHidden;
if (!val.PanelManager.IsPanelShowing())
{
PanelEvent panelHidden = val.PanelManager.PanelHidden;
if (panelHidden != null)
{
panelHidden.Invoke((UIPanelType)0);
}
}
}
});
public override void Load()
{
//IL_0015: Unknown result type (might be due to invalid IL or missing references)
//IL_001b: Expected O, but got Unknown
Log = ((BasePlugin)this).Log;
ManualLogSource log = Log;
bool flag = default(bool);
BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(18, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Plugin ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("SimpleChat");
((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" is loaded!");
}
log.LogInfo(val);
harmonyInstance = Harmony.CreateAndPatchAll(typeof(Plugin), (string)null);
}
public override bool Unload()
{
SessionService_Disconnect();
Harmony obj = harmonyInstance;
if (obj != null)
{
obj.UnpatchSelf();
}
return true;
}
private static void ShowNotification(string text)
{
if (string.IsNullOrEmpty(text))
{
return;
}
IUIService _uiService = SceneContextInstaller.ResolveObject<IUIService>();
if (_uiService == null)
{
return;
}
Action<HudElement> action = delegate(HudElement hudElement)
{
//IL_008b: Unknown result type (might be due to invalid IL or missing references)
//IL_0090: Unknown result type (might be due to invalid IL or missing references)
if (!((Object)(object)hudElement == (Object)null))
{
_uiService.HUDManager.HudElementLoaded(hudElement, (IPayload)null, (Action)null);
NotificationHud val = ((Il2CppObjectBase)hudElement).Cast<NotificationHud>();
NotificationPopupObject notificationPopup = val.GetNotificationPopup();
notificationPopup._icon.sprite = notificationPopup._fallbackIcon;
float durationRemaining = (notificationPopup._displayDuration = val._viewModel.PopupDisplayDuration * 3f);
notificationPopup._durationRemaining = durationRemaining;
notificationPopup._fadeOutSpeedModifier = val._viewModel.PopupDisplayFadeSpeedMultiplier;
notificationPopup._callback = val.OnPopupExpired;
((Graphic)notificationPopup._background).color = Color32.op_Implicit(val._viewModel.UiColourData.GetRarityColour((InventoryRarityType)0));
((Component)notificationPopup._shineAnimator).gameObject.SetActive(false);
notificationPopup._message.text = text;
val._currentNotification = notificationPopup;
val._activeNotifications.Enqueue(val._currentNotification);
}
};
if (_uiService.HUDManager._hudElementsInMemory.ContainsKey((UIHudType)14))
{
action(_uiService.HUDManager._hudElementsInMemory[(UIHudType)14]);
}
else
{
_uiService.HUDManager.LoadHudElement((UIHudType)14, Action<HudElement>.op_Implicit(action));
}
}
[HarmonyPatch(typeof(UIInputMediator), "Update")]
[HarmonyPrefix]
private static void UIInputMediator_Update(UIInputMediator __instance)
{
//IL_0099: Unknown result type (might be due to invalid IL or missing references)
//IL_009e: Unknown result type (might be due to invalid IL or missing references)
//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
if (!__instance._ui.IsServiceReady || __instance._sceneService.AreWeLoadingOrInLobby() || __instance._ui.PanelManager.IsPanelShowing((UIPanelType)3) || __instance._ui.PanelManager.IsPanelShowing((UIPanelType)25))
{
return;
}
if (_enableChatKey && ((ButtonControl)Keyboard.current.enterKey).wasPressedThisFrame)
{
_enableChatKey = false;
__instance._ui.PanelManager.ShowPanelAsync((UIPanelType)16, ((Il2CppObjectBase)new PopupPanelPayload
{
ShowInputField = true,
CloseOnConfirm = true,
HeaderText = "Chat",
ConfirmAction = Action<string>.op_Implicit((Action<string>)delegate(string input)
{
if (largeMessageService != null)
{
if (input.StartsWith("!"))
{
if (_commands == null)
{
_commands = new Dictionary<string, MethodInfo>(StringComparer.OrdinalIgnoreCase);
string copyright = typeof(Plugin).GetTypeInfo().Assembly.GetCustomAttribute<AssemblyCopyrightAttribute>().Copyright;
foreach (object item in from x in ((BaseChainloader<BasePlugin>)(object)IL2CPPChainloader.Instance).Plugins
where x.Value.Instance?.GetType().GetTypeInfo().Assembly.GetCustomAttribute<AssemblyCopyrightAttribute>()?.Copyright == copyright
select x.Value.Instance into x
orderby (!(x is Plugin)) ? 1 : 0
select x)
{
foreach (TypeInfo item2 in item.GetType().GetTypeInfo().DeclaredNestedTypes.Where((TypeInfo x) => x.IsClass && x.Name.EndsWith("SimpleChatCommands")))
{
string text = Regex.Replace(item2.Name, "SimpleChatCommands$", "");
MethodInfo[] methods = item2.GetMethods(BindingFlags.DeclaredOnly | BindingFlags.Static | BindingFlags.Public);
foreach (MethodInfo methodInfo in methods)
{
_commands.TryAdd((string.IsNullOrEmpty(text) ? "" : (text + ".")) + methodInfo.Name, methodInfo);
}
}
}
}
string[] arguments = Regex.Split(input, "(?<=^[^\"]*(?:\"[^\"]*\"[^\"]*)*) (?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)");
string text2 = Regex.Replace(arguments[0], "^!", "");
_commands.TryGetValue(text2, out var value);
if (value == null)
{
ShowNotification("Command '" + text2 + "' was not found.");
}
else if (value.GetParameters().Length > arguments.Length - 1)
{
ShowNotification($"Syntax for '{text2}' is '!{(text2 + " " + string.Join(" ", (from x in value.GetParameters()
select x.Name).ToList())).Trim()}'.");
}
else
{
List<object> list = null;
try
{
list = value.GetParameters().Aggregate(new List<object>(), delegate(List<object> a, ParameterInfo b)
{
string text5 = arguments[a.Count + 1];
a.Add((b.ParameterType == typeof(string)) ? Regex.Replace(text5, "^\"([^\"]*)\"$", "$1") : TypeDescriptor.GetConverter(b.ParameterType).ConvertFrom(text5));
return a;
});
}
catch
{
ShowNotification("Invalid arguments.");
}
if (list != null)
{
string text3 = (string)value.Invoke(null, list.ToArray());
if (text3 != null)
{
ShowNotification((text3 == "") ? ("Command '" + text2 + "' executed successfully.") : text3);
}
}
}
}
else
{
string text4 = "[" + __instance._localPlayerService.LocalPlayer.PlayerNetwork.CharacterName + "] " + input;
largeMessageService.SendMessage((LargeMessageType)(-1), Il2CppStructArray<byte>.op_Implicit(Encoding.UTF8.GetBytes(text4)));
ShowNotification(text4);
}
}
})
}).Cast<IPayload>(), (Action)null);
UIPanelManager panelManager = __instance._ui.PanelManager;
panelManager.PanelHidden += OnPanelHidden;
}
if (!__instance._ui.PanelManager.IsPanelShowing((UIPanelType)16) && !((ButtonControl)Keyboard.current.enterKey).wasPressedThisFrame)
{
_enableChatKey = true;
}
}
[HarmonyPatch(typeof(NetworkService), "StartNewSession")]
[HarmonyPostfix]
private static void NetworkService_StartNewSession()
{
SessionService_Disconnect();
LargeMessageCommands.GetLargeMessageService(ref largeMessageService);
LargeMessageService obj = largeMessageService;
obj.MessageReceived += OnLargeMessageReceived;
}
[HarmonyPatch(typeof(SessionService), "Disconnect")]
[HarmonyPrefix]
private static void SessionService_Disconnect()
{
if (largeMessageService != null)
{
LargeMessageService obj = largeMessageService;
obj.MessageReceived -= OnLargeMessageReceived;
largeMessageService = null;
}
}
}
public static class MyPluginInfo
{
public const string PLUGIN_GUID = "SimpleChat";
public const string PLUGIN_NAME = "SimpleChat";
public const string PLUGIN_VERSION = "1.1.5";
}
}