Decompiled source of PipShockLC v1.0.2

BepInEx/plugins/PipShockLC.dll

Decompiled 2 years ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Net.Http;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using GameNetcodeStuff;
using HarmonyLib;
using TMPro;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.SceneManagement;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("PipShockLC")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("PipShockLC")]
[assembly: AssemblyCopyright("Copyright ©  2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("027848e0-77ac-4cf1-9950-1b8f9237f583")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.6", FrameworkDisplayName = ".NET Framework 4.6")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace PipShockLC;

public static class Patches
{
	public static Harmony harmonyInstance;

	public static HarmonyMethod GetLocalPatch(string methodName)
	{
		//IL_0012: Unknown result type (might be due to invalid IL or missing references)
		//IL_0018: Expected O, but got Unknown
		return new HarmonyMethod(typeof(Patches).GetMethod(methodName, BindingFlags.Static | BindingFlags.NonPublic));
	}

	public static void ApplyPatches()
	{
		//IL_0011: Unknown result type (might be due to invalid IL or missing references)
		//IL_001b: Expected O, but got Unknown
		Console.WriteLine("Applying PipShock patches...");
		harmonyInstance = new Harmony("PipShockPatches");
		harmonyInstance.Patch((MethodBase)typeof(PlayerControllerB).GetMethod("DamagePlayer"), (HarmonyMethod)null, GetLocalPatch("NewDamagePlayer"), (HarmonyMethod)null, (HarmonyMethod)null);
		Console.WriteLine("PipShock patches applied!");
	}

	private static void NewDamagePlayer(int __0, bool __1, bool __2, CauseOfDeath __3, int __4, bool __5, Vector3 __6)
	{
		int num = Mathf.Clamp(__0, 0, 100);
		int num2 = (int)Math.Round((float)Plugin.strength / 100f * (float)num);
		Console.WriteLine("[BepInEx] [Harmony] - Shock strength: " + num2.ToString("000"));
		try
		{
			HttpClient httpClient = new HttpClient();
			httpClient.Timeout = new TimeSpan(3000000000L);
			HttpContent content = new FormUrlEncodedContent(new KeyValuePair<string, string>[1]
			{
				new KeyValuePair<string, string>("strength", num2.ToString("000"))
			});
			Uri requestUri = new Uri("http://192.168.86.96/shock");
			httpClient.PostAsync(requestUri, content);
		}
		catch (Exception ex)
		{
			Console.WriteLine(ex.ToString());
		}
	}
}
[BepInPlugin("com.beanbag.lethalcompany.pipshock", "PipShock Mod", "1.0.2")]
public class Plugin : BaseUnityPlugin
{
	public static int strength = 30;

	private void Awake()
	{
		Patches.ApplyPatches();
		Object.DontDestroyOnLoad((Object)(object)this);
		SceneManager.sceneLoaded += OnSceneLoaded;
		((BaseUnityPlugin)this).Logger.LogInfo((object)"Started PipShock Mod");
	}

	private void OnSceneLoaded(Scene scene, LoadSceneMode mode)
	{
		((BaseUnityPlugin)this).Logger.LogInfo((object)"RAHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH");
		if (((Scene)(ref scene)).name == "MainMenu")
		{
			((MonoBehaviour)this).StartCoroutine(MenuUISetup());
		}
	}

	private IEnumerator MenuUISetup()
	{
		Console.WriteLine("Started UISetup!");
		while ((Object)(object)GameObject.Find("Canvas/MenuContainer/SettingsPanel") == (Object)null)
		{
			((BaseUnityPlugin)this).Logger.LogInfo((object)"sex");
			yield return null;
		}
		GameObject canvas = GameObject.Find("Canvas");
		Console.WriteLine("1");
		Transform menuContainer = canvas.transform.Find("MenuContainer");
		Console.WriteLine("2");
		Transform settingsPanel = menuContainer.Find("SettingsPanel");
		Console.WriteLine("3");
		Transform originalFramerateCap = settingsPanel.Find("FramerateCap");
		Transform originalBrightnessSetting = settingsPanel.Find("BrightnessSetting");
		Transform originalDisplayHeader = settingsPanel.Find("Headers/Display");
		Console.WriteLine("4");
		Transform pipshockHeader = Object.Instantiate<Transform>(originalDisplayHeader, originalDisplayHeader.parent);
		((Object)pipshockHeader).name = "PipShock";
		((Component)pipshockHeader).GetComponent<RectTransform>().anchoredPosition = new Vector2(13f, 254f);
		TextMeshProUGUI headerLabel = ((Component)pipshockHeader).GetComponent<TextMeshProUGUI>();
		((TMP_Text)headerLabel).text = "Pip<color=yellow>Shock</color>";
		Console.WriteLine("5");
		Transform pipshockMode = Object.Instantiate<Transform>(originalFramerateCap, originalFramerateCap.parent);
		((Object)pipshockMode).name = "DamageMode";
		((Component)pipshockMode).GetComponent<RectTransform>().anchoredPosition = new Vector2(46.5f, 192.9129f);
		TextMeshProUGUI modeLabel = ((Component)pipshockMode.Find("Label2")).GetComponent<TextMeshProUGUI>();
		((TMP_Text)modeLabel).text = "Damage mode:";
		Object.Destroy((Object)(object)((Component)pipshockMode).GetComponent<SettingsOption>());
		TMP_Dropdown modeDropdown = ((Component)pipshockMode).GetComponent<TMP_Dropdown>();
		modeDropdown.ClearOptions();
		modeDropdown.AddOptions(new List<OptionData>
		{
			new OptionData("Shock"),
			new OptionData("Vibrate")
		});
		Console.WriteLine("6");
		Transform pipshockStrength = Object.Instantiate<Transform>(originalBrightnessSetting, originalBrightnessSetting.parent);
		((Object)pipshockStrength).name = "PipShockStrength";
		Object.Destroy((Object)(object)((Component)pipshockStrength).GetComponentInChildren<SettingsOption>());
		((Component)pipshockStrength).GetComponent<RectTransform>().anchoredPosition = new Vector2(31f, 135f);
		TextMeshProUGUI strengthLabel = ((Component)pipshockStrength.Find("Text (1)")).GetComponent<TextMeshProUGUI>();
		((TMP_Text)strengthLabel).text = "Max <color=red>strength</color>:";
		Object.Destroy((Object)(object)pipshockStrength.Find("Image"));
		Slider strengthSlider = ((Component)pipshockStrength).GetComponentInChildren<Slider>();
		strengthSlider.minValue = 0f;
		strengthSlider.maxValue = 100f;
		strengthSlider.onValueChanged = new SliderEvent();
		((UnityEvent<float>)(object)strengthSlider.onValueChanged).AddListener((UnityAction<float>)delegate(float f)
		{
			strength = (int)Math.Round(f);
			((TMP_Text)strengthLabel).text = $"Max <color=red>strength</color>: {(int)Math.Round(f)}";
		});
		strengthSlider.value = strength;
		Console.WriteLine("Finished UISetup!");
	}
}