Decompiled source of ROZBUSHKA v1.0.3

ROZBUSHKA.dll

Decompiled 2 months ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Photon.Pun;
using PxntxrezStudio.TsarBomb;
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: AssemblyTitle("ROZBUSHKA")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ROZBUSHKA")]
[assembly: AssemblyCopyright("Copyright ©  2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("d30f6a92-013b-429a-be86-efabd9232eea")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
[BepInPlugin("m1.r0-ROZBUSHKA", "My Custom Tsar Bomb Patch", "1.0.0")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class ROZBUSHKA : BaseUnityPlugin
{
	internal static ManualLogSource log;

	public static ROZBUSHKA_Config configData { get; private set; }

	private void Awake()
	{
		//IL_0022: Unknown result type (might be due to invalid IL or missing references)
		//IL_0028: Expected O, but got Unknown
		configData = new ROZBUSHKA_Config();
		configData.Init(((BaseUnityPlugin)this).Config);
		Harmony val = new Harmony("m1.r0-ROZBUSHKA");
		val.PatchAll(Assembly.GetExecutingAssembly());
		log = Logger.CreateLogSource("ROZBUSHKA");
		log.LogInfo((object)"ROZBUSHKA loaded! --- Yippeee");
	}
}
public class ROZBUSHKA_Config
{
	public ConfigEntry<bool> IsSoundGlobal { get; set; }

	public ConfigEntry<float> FuseTimer { get; set; }

	public ConfigEntry<float> CooldownTimer { get; set; }

	public ConfigEntry<float> MinDistance { get; set; }

	public ConfigEntry<float> MaxDistance { get; set; }

	public ConfigEntry<bool> resetHitCounter { get; set; }

	public void Init(ConfigFile config)
	{
		//IL_0043: Unknown result type (might be due to invalid IL or missing references)
		//IL_0052: Expected O, but got Unknown
		//IL_004d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0057: Expected O, but got Unknown
		//IL_0082: Unknown result type (might be due to invalid IL or missing references)
		//IL_0091: Expected O, but got Unknown
		//IL_008c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0096: Expected O, but got Unknown
		//IL_00de: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ed: Expected O, but got Unknown
		//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f2: Expected O, but got Unknown
		//IL_011d: Unknown result type (might be due to invalid IL or missing references)
		//IL_012c: Expected O, but got Unknown
		//IL_0127: Unknown result type (might be due to invalid IL or missing references)
		//IL_0131: Expected O, but got Unknown
		IsSoundGlobal = config.Bind<bool>("Audio", "IsSoundGlobal", false, "If true, explosion warning sound is global instead of 3D spatial.");
		MinDistance = config.Bind<float>("Audio - Spatial", "MinDistance", 1f, new ConfigDescription("Below the MinDistance, audio is being played at full volume", (AcceptableValueBase)new AcceptableValueRange<float>(0f, 100f), Array.Empty<object>()));
		MaxDistance = config.Bind<float>("Audio - Spatial", "MaxDistance", 30f, new ConfigDescription("Above the MaxDistance, no audio is heard at all", (AcceptableValueBase)new AcceptableValueRange<float>(0f, 100f), Array.Empty<object>()));
		resetHitCounter = config.Bind<bool>("Explosion", "ResetHitCounter", true, "if true, after explosion you need to again accumulate maxHitCount hits for explosion. If false, each subsequent hit will cause explosion.");
		FuseTimer = config.Bind<float>("Explosion", "FuseTimer", 9f, new ConfigDescription("the ammount of seconds before the imminent DOOM", (AcceptableValueBase)new AcceptableValueRange<float>(0f, 100f), Array.Empty<object>()));
		CooldownTimer = config.Bind<float>("Explosion", "CooldownTimer", 3f, new ConfigDescription("timer after explosion, after which you can have another explosion.", (AcceptableValueBase)new AcceptableValueRange<float>(-1f, 100f), Array.Empty<object>()));
	}
}
[HarmonyPatch(typeof(BarrelValuableTsarBomb), "PotentialExplode")]
public class TsarBombPatch_PotentialExplode
{
	private static List<BarrelValuableTsarBomb> activatedInstances = new List<BarrelValuableTsarBomb>();

	private static bool Prefix(BarrelValuableTsarBomb __instance)
	{
		//IL_003d: Unknown result type (might be due to invalid IL or missing references)
		if (activatedInstances.Contains(__instance))
		{
			return false;
		}
		PhotonView component = ((Component)__instance).GetComponent<PhotonView>();
		if ((Object)(object)component == (Object)null)
		{
			component = ((Component)__instance).gameObject.AddComponent<PhotonView>();
			component.OwnershipTransfer = (OwnershipOption)1;
			PhotonNetwork.AllocateViewID(component);
		}
		TsarBombNetwork tsarBombNetwork = ((Component)__instance).GetComponent<TsarBombNetwork>() ?? ((Component)__instance).gameObject.AddComponent<TsarBombNetwork>();
		if (!PhotonNetwork.InRoom)
		{
			TsarBombNetwork.skipRPC = true;
		}
		else if (!PhotonNetwork.IsMasterClient)
		{
			return true;
		}
		int value = TsarBomb.ConfigData.MaxHitCount.Value;
		int valueOrDefault = (AccessTools.Field(typeof(BarrelValuableTsarBomb), "HitCount").GetValue(__instance) as int?).GetValueOrDefault();
		if (valueOrDefault >= value - 1)
		{
			activatedInstances.Add(__instance);
			tsarBombNetwork.BroadcastSoundRPC();
			((MonoBehaviour)__instance).StartCoroutine(DelayedExplode(__instance));
			if (ROZBUSHKA.configData.resetHitCounter.Value)
			{
				AccessTools.Field(typeof(BarrelValuableTsarBomb), "HitCount").SetValue(__instance, 0);
			}
			return false;
		}
		AccessTools.Field(typeof(BarrelValuableTsarBomb), "HitCount").SetValue(__instance, valueOrDefault + 1);
		return false;
	}

	private static IEnumerator DelayedExplode(BarrelValuableTsarBomb instance)
	{
		ROZBUSHKA.log.LogInfo((object)"Delaying explosion...");
		yield return (object)new WaitForSeconds(ROZBUSHKA.configData.FuseTimer.Value);
		ROZBUSHKA.log.LogInfo((object)"BOOOOOOOOOOOOOOOOOOOOOM . . . . . .");
		PhotonView view = ((Component)instance).GetComponent<PhotonView>();
		TsarBombNetwork net = ((Component)instance).GetComponent<TsarBombNetwork>();
		net.BroadcastExplosionRPC(view.ViewID, instance);
		yield return (object)new WaitForSeconds(ROZBUSHKA.configData.CooldownTimer.Value);
		ROZBUSHKA.log.LogInfo((object)"another explosions possible");
		activatedInstances.Remove(instance);
	}

	public static IEnumerator LoadAndPlaySound(string path, AudioSource source)
	{
		UnityWebRequest www = UnityWebRequestMultimedia.GetAudioClip("file://" + path, (AudioType)20);
		yield return www.SendWebRequest();
		if ((int)www.result == 2 || (int)www.result == 3)
		{
			Debug.LogError((object)www.error);
			yield break;
		}
		AudioClip clip = DownloadHandlerAudioClip.GetContent(www);
		if (!ROZBUSHKA.configData.IsSoundGlobal.Value)
		{
			source.spatialBlend = 1f;
			source.rolloffMode = (AudioRolloffMode)0;
			source.minDistance = ROZBUSHKA.configData.MinDistance.Value;
			source.maxDistance = ROZBUSHKA.configData.MaxDistance.Value;
		}
		source.clip = clip;
		source.Play();
	}
}
public class TsarBombNetwork : MonoBehaviourPun
{
	private readonly string path = Path.Combine(Paths.PluginPath, "m1r0-ROZBUSHKA", "hereComesThe.wav");

	public static bool skipRPC;

	[PunRPC]
	public void PlayTheRequestedMusic()
	{
		GameObject gameObject = ((Component)this).gameObject;
		AudioSource source = gameObject.GetComponent<AudioSource>() ?? gameObject.AddComponent<AudioSource>();
		((MonoBehaviour)this).StartCoroutine(TsarBombPatch_PotentialExplode.LoadAndPlaySound(path, source));
	}

	[PunRPC]
	public void Explode(int viewID)
	{
		PhotonView val = PhotonView.Find(viewID);
		if ((Object)(object)val == (Object)null)
		{
			ROZBUSHKA.log.LogError((object)$"PhotonView with ID {viewID} not found.");
			return;
		}
		BarrelValuableTsarBomb component = ((Component)val).GetComponent<BarrelValuableTsarBomb>();
		if ((Object)(object)component != (Object)null)
		{
			component.Explode();
		}
	}

	public void BroadcastSoundRPC()
	{
		if (skipRPC)
		{
			PlayTheRequestedMusic();
		}
		else
		{
			((MonoBehaviourPun)this).photonView.RPC("PlayTheRequestedMusic", (RpcTarget)0, Array.Empty<object>());
		}
	}

	public void BroadcastExplosionRPC(int viewID, BarrelValuableTsarBomb instance = null)
	{
		if (skipRPC)
		{
			if (instance != null)
			{
				instance.Explode();
			}
		}
		else
		{
			((MonoBehaviourPun)this).photonView.RPC("Explode", (RpcTarget)0, new object[1] { viewID });
		}
	}
}