using System.Diagnostics;
using System.Linq;
using System.Net.Http;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Text;
using System.Threading.Tasks;
using Agents;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using HarmonyLib;
using Il2CppSystem.IO;
using SNetwork;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("MagicalAstrogy.GTFDGLAB")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("0.1.1.0")]
[assembly: AssemblyInformationalVersion("0.1.1")]
[assembly: AssemblyProduct("MagicalAstrogy.GTFDGLAB")]
[assembly: AssemblyTitle("MagicalAstrogy.GTFDGLAB")]
[assembly: AssemblyVersion("0.1.1.0")]
namespace MagicalAstrogy.GTFDGLAB;
public class ConfigManager
{
private static ConfigEntry<string> _baseUrl;
private static ConfigEntry<string> _clientId;
private static ConfigEntry<float> _timeMultiplier;
private static ConfigEntry<float> _strengthMultiplier;
private static ConfigEntry<bool> _sendWhenInfection;
public static string BaseUrl => _baseUrl.Value;
public static string ClientId => _clientId.Value;
public static float TimeMultiplier => _timeMultiplier.Value;
public static float StrengthMultiplier => _strengthMultiplier.Value;
public static bool SendWhenInfection => _sendWhenInfection.Value;
static ConfigManager()
{
//IL_0013: Unknown result type (might be due to invalid IL or missing references)
//IL_0019: Expected O, but got Unknown
string text = Path.Combine(Paths.ConfigPath, "GTFDGLab.cfg");
ConfigFile val = new ConfigFile(text, true);
_baseUrl = val.Bind<string>("Magical", "BaseUrl", "http://127.0.0.1:8920/", "Url address of service DG-Lab-Coyote-Game-Hub(https://github.com/hyperzlib/DG-Lab-Coyote-Game-Hub).");
_clientId = val.Bind<string>("Magical", "ClientId", "all", "Client id of service DG-Lab-Coyote-Game-Hub(https://github.com/hyperzlib/DG-Lab-Coyote-Game-Hub).");
_timeMultiplier = val.Bind<float>("Magical", "TimeMultiplier", 0.25f, "Ratio of damage received to duration.");
_strengthMultiplier = val.Bind<float>("Magical", "StrengthMultiplier", 1f, "Ratio of damage received to strength.");
_sendWhenInfection = val.Bind<bool>("Magical", "SendWhenInfection", true, "When taking damage from infection, a signal will be sent.");
}
}
[BepInPlugin("com.MagicalAstrogy.GTFDGLAB", "GTFDGLAB", "1.1.4")]
[BepInProcess("GTFO.exe")]
public class EntryPoint : BasePlugin
{
public const string GUID = "com.MagicalAstrogy.GTFDGLAB";
private bool once = false;
public override void Load()
{
//IL_0011: Unknown result type (might be due to invalid IL or missing references)
//IL_0017: Expected O, but got Unknown
Logger.LogInstance = ((BasePlugin)this).Log;
Harmony val = new Harmony("com.MagicalAstrogy.GTFDGLAB");
val.PatchAll();
Logger.Log("Patched: $" + string.Join(", ", from x in val.GetPatchedMethods().ToList()
select x.Name));
}
}
public static class DGLabHttpRequest
{
private static HttpClient _client = new HttpClient();
private static Task<HttpResponseMessage> _currentTask;
public static async void Fire(float strength, float duration)
{
string url = ConfigManager.BaseUrl + "api/game/" + ConfigManager.ClientId + "/fire";
string jsonContent = $"\r\n {{\r\n \"strength\": {strength},\r\n \"time\": {(int)(duration * 1000f)}\r\n }}";
HttpContent content = new StringContent(jsonContent, Encoding.UTF8, "application/json");
Task<HttpResponseMessage> response = _client.PostAsync(url, content);
if (_currentTask != null && _currentTask.IsCompleted)
{
Logger.Log(_currentTask.Result.Content?.ReadAsStringAsync()?.Result);
_currentTask = null;
}
if (_currentTask == null)
{
_currentTask = response;
}
}
}
[HarmonyPatch(typeof(Dam_PlayerDamageLocal), "ReceiveSetHealth")]
public static class OnInfectDamage
{
public static void Prefix(Dam_PlayerDamageLocal __instance, pSetHealthData data)
{
if (!((Agent)((Dam_PlayerDamageBase)__instance).Owner).IsLocallyOwned)
{
return;
}
float num = (((Dam_SyncedDamageBase)__instance).Health - ((SFloat16)(ref data.health)).Get(((Dam_SyncedDamageBase)__instance).HealthMax)) * 4f;
if (!(num > 0f) || !(num < 1f))
{
return;
}
Logger.Log($"Received Damage222 {num}");
if (num < 2f)
{
if (ConfigManager.SendWhenInfection)
{
DGLabHttpRequest.Fire(4f, 2f);
}
}
else
{
DGLabHttpRequest.Fire(num * ConfigManager.StrengthMultiplier, num * ConfigManager.TimeMultiplier);
}
}
}
[HarmonyPatch(typeof(Dam_PlayerDamageBase), "OnIncomingDamage")]
public static class OnLocalDamage
{
public static void Prefix(Dam_PlayerDamageBase __instance, float damage)
{
if (((Agent)__instance.Owner).IsLocallyOwned)
{
float num = damage * 4f;
if (num > 0f)
{
Logger.Log($"Received Damage333 {num}");
DGLabHttpRequest.Fire(num * ConfigManager.StrengthMultiplier, num * ConfigManager.TimeMultiplier);
}
}
}
}
public static class Logger
{
public static ManualLogSource LogInstance;
public static void Log(string format, params object[] args)
{
Log(string.Format(format, args));
}
public static void Log(string str)
{
ManualLogSource logInstance = LogInstance;
if (logInstance != null)
{
logInstance.Log((LogLevel)8, (object)str);
}
}
public static void Warning(string format, params object[] args)
{
Warning(string.Format(format, args));
}
public static void Warning(string str)
{
ManualLogSource logInstance = LogInstance;
if (logInstance != null)
{
logInstance.Log((LogLevel)4, (object)str);
}
}
public static void Error(string format, params object[] args)
{
Error(string.Format(format, args));
}
public static void Error(string str)
{
ManualLogSource logInstance = LogInstance;
if (logInstance != null)
{
logInstance.Log((LogLevel)2, (object)str);
}
}
}