Decompiled source of PostChat v1.0.0

PostChat.dll

Decompiled a year ago
using System.Collections;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using UnityEngine;
using UnityEngine.Networking;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = "")]
[assembly: AssemblyCompany("PostChat")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Lethal Company mod to send outgoing messages to http server for ... reasons")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("PostChat")]
[assembly: AssemblyTitle("PostChat")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace PostChat
{
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "PostChat";

		public const string PLUGIN_NAME = "PostChat";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace PostChatPlugin
{
	[BepInPlugin("walksanator.PostChat", "Post Chat", "1.0.0")]
	public class PostChatPlugin : BaseUnityPlugin
	{
		internal static ManualLogSource Logger { get; private set; }

		internal static PostChatPlugin Instance { get; private set; }

		private void Awake()
		{
			Logger = ((BaseUnityPlugin)this).Logger;
			Instance = this;
			Logger.LogInfo((object)$"C# Instance {this} or {Instance}");
			Logger.LogInfo((object)"Post Chat: performing patches");
			Harmony.CreateAndPatchAll(typeof(PostChatPlugin), (string)null);
			Logger.LogInfo((object)"Plugin walksanator.PostChat is loaded!");
			Logger.LogInfo((object)$"Just Checking {Instance}");
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(HUDManager), "AddTextToChatOnServer")]
		private static void PostChatHttp(ref string chatMessage, ref int playerId)
		{
			Logger.LogInfo((object)("You SAID: " + chatMessage));
			Logger.LogInfo((object)$"C# Instance {Instance}");
			if ((Object)(object)Instance != (Object)null)
			{
				((MonoBehaviour)Instance).StartCoroutine(SendPostRequest(chatMessage));
				Logger.LogInfo((object)("Post SEND: " + chatMessage));
			}
			else
			{
				Logger.LogError((object)"Instance is null!");
			}
		}

		private static IEnumerator SendPostRequest(string message)
		{
			string url = "http://127.0.0.1:5000";
			Logger.LogInfo((object)"Building headers");
			UnityWebRequest request = UnityWebRequest.Post(url, message, "text/plain");
			Logger.LogInfo((object)"Build request");
			yield return request.SendWebRequest();
			Logger.LogInfo((object)"Post Request");
			if ((int)request.result != 1)
			{
				Debug.LogError((object)("Error: " + request.error));
			}
			else
			{
				Debug.Log((object)("Response: " + request.downloadHandler.text));
			}
		}
	}
}