using System;
using System.Diagnostics;
using System.Net.Http;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Web;
using BepInEx;
using GuysNight.LethalCompanyMod.Terminal.Cowsay.Models;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using TerminalApi;
using TerminalApi.Classes;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("GuysNight.LethalCompanyMod.Terminal.Cowsay")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Add a new terminal command to display a cow telling you a random Chuck Norris joke.")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+1b464a45c149a3bf844cfc1597f729bcaa1fd303")]
[assembly: AssemblyProduct("GuysNight.LethalCompanyMod.Terminal.Cowsay")]
[assembly: AssemblyTitle("GuysNight.LethalCompanyMod.Terminal.Cowsay")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
internal sealed class NullableAttribute : Attribute
{
public readonly byte[] NullableFlags;
public NullableAttribute(byte P_0)
{
NullableFlags = new byte[1] { P_0 };
}
public NullableAttribute(byte[] P_0)
{
NullableFlags = P_0;
}
}
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
internal sealed class NullableContextAttribute : Attribute
{
public readonly byte Flag;
public NullableContextAttribute(byte P_0)
{
Flag = P_0;
}
}
}
namespace GuysNight.LethalCompanyMod.Terminal.Cowsay
{
[BepInPlugin("GuysNight.LethalCompanyMod.Terminal.Cowsay", "GuysNight.LethalCompanyMod.Terminal.Cowsay", "1.0.0")]
[BepInDependency("atomic.terminalapi", "1.5.0")]
public class Plugin : BaseUnityPlugin
{
private const string ChuckNorrisApiUrl = "https://api.chucknorris.io/jokes/random";
private const string CowsayApiUrl = "https://cowsay.morecode.org/say";
private static readonly HttpClient HttpClient = new HttpClient();
private void Awake()
{
//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_0021: 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_003e: Unknown result type (might be due to invalid IL or missing references)
//IL_0050: Expected O, but got Unknown
Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), (string)null);
TerminalApi.AddCommand("cowsay", new CommandInfo
{
Category = "other",
Description = "Displays a cow telling you a random Chuck Norris joke.",
DisplayTextSupplier = GetCowsayChuckNorris,
Title = "Cowsay"
}, (string)null, true);
}
private string GetCowsayChuckNorris()
{
HttpResponseMessage result = HttpClient.GetAsync("https://api.chucknorris.io/jokes/random").GetAwaiter().GetResult();
if (!result.IsSuccessStatusCode)
{
((BaseUnityPlugin)this).Logger.LogWarning((object)$"Chuck Norris API did not return a successful status code. Returned {result.StatusCode} with content {result.Content.ReadAsStringAsync().GetAwaiter().GetResult()}");
return "An error occurred. Please try again later.";
}
string result2 = result.Content.ReadAsStringAsync().GetAwaiter().GetResult();
ChuckNorrisResponse chuckNorrisResponse = JsonUtility.FromJson<ChuckNorrisResponse>(result2);
((BaseUnityPlugin)this).Logger.LogDebug((object)("Chuck Norris API response is '" + result2 + "'"));
if (chuckNorrisResponse == null)
{
((BaseUnityPlugin)this).Logger.LogWarning((object)("Chuck Norris response could not be deserialized. The response was " + result2));
return "An error occurred. Please try again later.";
}
((BaseUnityPlugin)this).Logger.LogDebug((object)("Chuck Norris API deserialized response's value property is '" + chuckNorrisResponse.value + "'"));
HttpResponseMessage result3 = HttpClient.GetAsync("https://cowsay.morecode.org/say?format=text&message=" + HttpUtility.UrlEncode(chuckNorrisResponse.value)).GetAwaiter().GetResult();
if (!result3.IsSuccessStatusCode)
{
((BaseUnityPlugin)this).Logger.LogWarning((object)$"Cowsay API did not return a successful status code. Returned {result3.StatusCode} with content {result3.Content.ReadAsStringAsync().GetAwaiter().GetResult()}");
return "An error occurred. Please try again later.";
}
return result3.Content.ReadAsStringAsync().GetAwaiter().GetResult();
}
}
public static class PluginInfo
{
public const string PLUGIN_GUID = "GuysNight.LethalCompanyMod.Terminal.Cowsay";
public const string PLUGIN_NAME = "GuysNight.LethalCompanyMod.Terminal.Cowsay";
public const string PLUGIN_VERSION = "1.0.0";
}
}
namespace GuysNight.LethalCompanyMod.Terminal.Cowsay.Models
{
[Serializable]
public class ChuckNorrisResponse
{
public string[] categories;
public DateTime created_at;
public string icon_url;
public string id;
public DateTime updated_at;
public string url;
public string value;
}
}