Please disclose if any significant portion of your mod was created using AI tools by adding the 'AI Generated' category. Failing to do so may result in the mod being removed from Thunderstore.
Decompiled source of PiShock v1.1.0
PiShock/PiShock.dll
Decompiled 2 years agousing System; using System.Diagnostics; using System.Net.Http; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Versioning; using System.Text; using System.Threading.Tasks; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using GameNetcodeStuff; using HarmonyLib; using Microsoft.CodeAnalysis; using Newtonsoft.Json; using PiShock.Patches; using Unity.Netcode; using UnityEngine; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)] [assembly: AssemblyTitle("PiShockMod")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("PiShockMod")] [assembly: AssemblyCopyright("Copyright © 2024")] [assembly: AssemblyTrademark("")] [assembly: ComVisible(false)] [assembly: Guid("3fc9a04f-6d2d-4ab4-80aa-4a6f5a54e823")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")] [assembly: AssemblyVersion("1.0.0.0")] [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 PiShock { internal class PiShockAPI { private string apiEndpoint = "https://do.pishock.com/api/apioperate/"; public string username { private get; set; } public string apiKey { private get; set; } public string code { private get; set; } public string senderName { private get; set; } public async Task SendHttp(int op, int intensity, int duration) { HttpClient client = new HttpClient(); try { var requestData = new { Username = username, Name = senderName, Code = code, Intensity = intensity, Duration = duration, APIKey = apiKey, Op = op }; var requestDataBeep = new { Username = username, Name = senderName, Code = code, Duration = duration, APIKey = apiKey, Op = op }; string jsonBody = ""; string operation = ""; switch (op) { case 0: jsonBody = JsonConvert.SerializeObject((object)requestData); operation = "shock"; break; case 1: jsonBody = JsonConvert.SerializeObject((object)requestData); operation = "vibrate"; break; case 2: jsonBody = JsonConvert.SerializeObject((object)requestDataBeep); operation = "beep"; break; } HttpContent content = (HttpContent)new StringContent(jsonBody, Encoding.UTF8, "application/json"); try { HttpResponseMessage response = await client.PostAsync(apiEndpoint, content); if (response.IsSuccessStatusCode) { PiShockPlugin.Instance.OnSuccess(operation, intensity, duration); return; } string responseContent = await response.Content.ReadAsStringAsync(); PiShockPlugin.Instance.OnError(response.StatusCode, response.ReasonPhrase, responseContent); } finally { ((IDisposable)content)?.Dispose(); } } finally { ((IDisposable)client)?.Dispose(); } } public async Task Shock(int intensity, int duration) { await SendHttp(0, intensity, duration); } public async Task Vibrate(int intensity, int duration) { await SendHttp(1, intensity, duration); } public async Task Beep(int duration) { await SendHttp(2, 0, duration); } } [BepInPlugin("PiShock", "PiShock", "1.1.0")] public class PiShockPlugin : BaseUnityPlugin { private const string modGUID = "PiShock"; private const string modName = "PiShock"; private const string modVersion = "1.1.0"; private readonly Harmony harmony = new Harmony("PiShock"); internal readonly string pishockLogId = "PiShock (Lethal company)"; internal static PiShockPlugin Instance; internal ManualLogSource mls; internal ConfigEntry<string> PiShockUsername; internal ConfigEntry<string> PiShockAPIKey; internal ConfigEntry<string> PiShockShockerShareCode; internal ConfigEntry<bool> shockOnDeath; internal ConfigEntry<bool> shockOnDamage; internal ConfigEntry<bool> shockOnFired; internal ConfigEntry<bool> shockBasedOnHealth; internal ConfigEntry<int> maxIntensity; internal ConfigEntry<int> minIntensity; internal ConfigEntry<int> intensityDeath; internal ConfigEntry<int> intensityFired; internal ConfigEntry<int> duration; internal ConfigEntry<int> durationDeath; internal ConfigEntry<int> durationFired; internal ConfigEntry<bool> testMode; internal ConfigEntry<bool> vibrateOnly; internal ConfigEntry<bool> enableInterval; internal ConfigEntry<int> interval; internal DateTime lastShock; private bool DidDeath = false; private bool DidFired = false; private void Awake() { //IL_0131: Unknown result type (might be due to invalid IL or missing references) //IL_013b: Expected O, but got Unknown //IL_0164: Unknown result type (might be due to invalid IL or missing references) //IL_016e: Expected O, but got Unknown //IL_0198: Unknown result type (might be due to invalid IL or missing references) //IL_01a2: Expected O, but got Unknown //IL_01cc: Unknown result type (might be due to invalid IL or missing references) //IL_01d6: Expected O, but got Unknown //IL_01ff: Unknown result type (might be due to invalid IL or missing references) //IL_0209: Expected O, but got Unknown //IL_0232: Unknown result type (might be due to invalid IL or missing references) //IL_023c: Expected O, but got Unknown //IL_0265: Unknown result type (might be due to invalid IL or missing references) //IL_026f: Expected O, but got Unknown mls = Logger.CreateLogSource("PiShock"); mls.LogMessage((object)"PiShock 1.1.0 - by TRIPPYTRASH"); PiShockUsername = ((BaseUnityPlugin)this).Config.Bind<string>("PiShock API Authentication", "PiShockUsername", "", (ConfigDescription)null); PiShockAPIKey = ((BaseUnityPlugin)this).Config.Bind<string>("PiShock API Authentication", "PiShockAPIKey", "", (ConfigDescription)null); PiShockShockerShareCode = ((BaseUnityPlugin)this).Config.Bind<string>("PiShock API Authentication", "PiShockShockerCode", "", "The share code for your PiShock shocker"); shockOnDamage = ((BaseUnityPlugin)this).Config.Bind<bool>("Shocking Events", "shockOnDamage", true, "Get shocked when you take damage"); shockOnDeath = ((BaseUnityPlugin)this).Config.Bind<bool>("Shocking Events", "shockOnDeath", true, "Get shocked when you die"); shockOnFired = ((BaseUnityPlugin)this).Config.Bind<bool>("Shocking Events", "shockOnFired", true, "Get shocked when you do not reach the quota"); shockBasedOnHealth = ((BaseUnityPlugin)this).Config.Bind<bool>("Shocking Events", "shockBasedOnHealth", false, "Enable to calculate shock intensity based on remaining health instead of the damage taken (shockOnDeath must be enabled)"); minIntensity = ((BaseUnityPlugin)this).Config.Bind<int>("Intensity Sliders", "minimum", 1, new ConfigDescription("Minimum intensity of shock/vibration", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 100), Array.Empty<object>())); maxIntensity = ((BaseUnityPlugin)this).Config.Bind<int>("Intensity Sliders", "maximum", 5, new ConfigDescription("Maximum intensity of shock/vibration", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 100), Array.Empty<object>())); intensityDeath = ((BaseUnityPlugin)this).Config.Bind<int>("Intensity Sliders", "intensityDeath", 10, new ConfigDescription("Intensity of shock/vibration when you die", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 100), Array.Empty<object>())); intensityFired = ((BaseUnityPlugin)this).Config.Bind<int>("Intensity Sliders", "intensityFired", 10, new ConfigDescription("Intensity of shock/vibration when you do not reach the quota", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 100), Array.Empty<object>())); duration = ((BaseUnityPlugin)this).Config.Bind<int>("Durations Sliders", "duration", 1, new ConfigDescription("General duration of shock/vibration", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 10), Array.Empty<object>())); durationDeath = ((BaseUnityPlugin)this).Config.Bind<int>("Durations Sliders", "durationDeath", 1, new ConfigDescription("Duration of shock/vibration when you die", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 10), Array.Empty<object>())); durationFired = ((BaseUnityPlugin)this).Config.Bind<int>("Durations Sliders", "durationFired", 2, new ConfigDescription("Duration of shock/vibration when you do not reach the quota", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 10), Array.Empty<object>())); testMode = ((BaseUnityPlugin)this).Config.Bind<bool>("Misc", "testMode", false, "Only beeps and a test beep upon launch"); vibrateOnly = ((BaseUnityPlugin)this).Config.Bind<bool>("Misc", "vibrateOnly", false, "Use vibration instead of shock"); enableInterval = ((BaseUnityPlugin)this).Config.Bind<bool>("Misc", "enableInterval", true, "Should there be a delay between shocks? (makes constant damage like bees bearable)"); interval = ((BaseUnityPlugin)this).Config.Bind<int>("Misc", "damageInterval", 10, "Interval between damage shocks (enable interval must = true)"); lastShock = DateTime.Now; mls.LogMessage((object)("Running for user: " + PiShockUsername.Value)); harmony.PatchAll(typeof(PiShockPlugin)); harmony.PatchAll(typeof(PlayerControllerBPatch)); harmony.PatchAll(typeof(StartOfRoundPatch)); if ((Object)(object)Instance == (Object)null) { Instance = this; } if (testMode.Value) { DoOperation(0, 1); } } public void OnSuccess(string operation, int intensity, int duration) { if (operation == "beep") { mls.LogMessage((object)$"Sent {operation} to {PiShockUsername.Value} for {duration} second(s)"); return; } mls.LogMessage((object)$"Sent {operation} {intensity} to {PiShockUsername.Value} for {duration} second(s)"); } public void OnError(object StatusCode, object ReasonPhrase, object responseContent) { mls.LogWarning((object)$"Error: {StatusCode} = {ReasonPhrase}"); mls.LogWarning((object)$"Response Content: {responseContent}"); } internal void DoDamage(int dmg, int health) { TimeSpan timeSpan = DateTime.Now - lastShock; if (enableInterval.Value && timeSpan < TimeSpan.FromSeconds(interval.Value)) { ((BaseUnityPlugin)this).Logger.LogDebug((object)("Didn't shock due to interval. LastShock; " + lastShock.ToLongTimeString())); return; } int intensity = Mathf.Clamp(dmg, minIntensity.Value, maxIntensity.Value); int num = 100 - health; int intensity2 = Mathf.Clamp(num, minIntensity.Value, maxIntensity.Value); if (shockBasedOnHealth.Value) { mls.LogInfo((object)("Shocking based on health for " + intensity2)); DoOperation(intensity2, duration.Value); } else if (shockOnDamage.Value) { mls.LogInfo((object)("Shocking based on damage for " + intensity)); DoOperation(intensity, duration.Value); } lastShock = DateTime.Now; } internal void DoDeath() { if (!DidDeath && shockOnDeath.Value) { ((BaseUnityPlugin)this).Logger.LogInfo((object)"Death shock"); DoOperation(intensityDeath.Value, durationDeath.Value); DidDeath = true; Task.Run(async delegate { await Task.Delay(20000); DidDeath = false; }); } } internal void DoFired() { if (!DidFired) { Task.Run(async delegate { await Task.Delay(15000); mls.LogInfo((object)"Fired Shock"); DoOperation(intensityFired.Value, durationFired.Value); }); DidFired = true; Task.Run(async delegate { await Task.Delay(durationFired.Value * 1000); DidFired = false; }); } } private async void DoOperation(int intensity, int duration) { mls.LogDebug((object)"Running DoOperation for shocker code"); PiShockAPI user = new PiShockAPI { username = PiShockUsername.Value, apiKey = PiShockAPIKey.Value, code = PiShockShockerShareCode.Value, senderName = pishockLogId }; if (testMode.Value) { await user.Beep(1); } else if (vibrateOnly.Value) { await user.Vibrate(intensity, duration); mls.LogDebug((object)"VIB ONLY"); } else { await user.Shock(intensity, duration); } } } } namespace PiShock.Patches { internal class PlayerControllerBPatch { [HarmonyPatch(typeof(PlayerControllerB), "KillPlayer")] [HarmonyPostfix] private static void DeathPatch(ref PlayerControllerB __instance) { if (((NetworkBehaviour)__instance).IsOwner) { PiShockPlugin.Instance.DoDeath(); } } [HarmonyPatch(typeof(PlayerControllerB), "DamagePlayer")] [HarmonyPostfix] private static void DamagePatch(int ___health, int damageNumber) { PiShockPlugin.Instance.DoDamage(damageNumber, ___health); } } internal class StartOfRoundPatch { [HarmonyPatch(typeof(StartOfRound), "FirePlayersAfterDeadlineClientRpc")] [HarmonyPostfix] private static void FirePlayersAfterDeadlinePatch() { PiShockPlugin.Instance.DoFired(); } } }