Decompiled source of DoubleBroSeven Trained v2.0.0

UMM/Mods/007_Patch/DoubleBroSevenTrained.dll

Decompiled 3 days ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using HarmonyLib;
using Networking;
using TFBGames.Systems;
using UnityEngine;
using UnityModManagerNet;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("DoubleBroSevenTrained")]
[assembly: AssemblyCompany("https://github.com/Gorzontrok/Mods-Broforce/")]
[assembly: AssemblyProduct("DoubleBroSevenTrained")]
[assembly: AssemblyCopyright("Copyright © Gorzontrok 2025")]
[assembly: ComVisible(false)]
[assembly: Guid("59c1b0b9-ccb8-40e8-b3de-7ec10a40514a")]
[assembly: AssemblyFileVersion("2.0.0.0")]
[assembly: AssemblyVersion("2.0.0.0")]
namespace DoubleBroSevenTrained;

[HarmonyPatch(typeof(DoubleBroSeven))]
public class DoubleBroSevenPatches
{
	public static bool NotEnabled => !Mod.Enabled;

	public static ModConfigs MSettings => Mod.ModSettings;

	public static VanillaConfigs VSettings => Mod.VanillaSettings;

	[HarmonyPatch("Awake")]
	[HarmonyPrefix]
	private static void Awake(DoubleBroSeven __instance)
	{
		if (!NotEnabled)
		{
			if (VSettings.useMaxAmmo == Its.Yes)
			{
				((TestVanDammeAnim)__instance).originalSpecialAmmo = VSettings.maxAmmo;
			}
			else if (MSettings.useTearGas)
			{
				((TestVanDammeAnim)__instance).originalSpecialAmmo = 5;
			}
			((TestVanDammeAnim)__instance).useNewPushingFrames = VSettings.usePushingAnimation;
			((TestVanDammeAnim)__instance).useNewLadderClimbingFrames = VSettings.useLadderClimbingAnimation;
			((TestVanDammeAnim)__instance).useLadderClimbingTransition = VSettings.useLadderClimbingTransitionAnimation;
			((Component)__instance).gameObject.AddComponent<Trained007>();
		}
	}

	[HarmonyPatch("UseSpecial")]
	[HarmonyPrefix]
	private static bool NewThrowTearGas(DoubleBroSeven __instance)
	{
		//IL_0029: Unknown result type (might be due to invalid IL or missing references)
		//IL_002e: Unknown result type (might be due to invalid IL or missing references)
		//IL_002f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0031: Invalid comparison between Unknown and I4
		//IL_013c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0182: Unknown result type (might be due to invalid IL or missing references)
		//IL_009d: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
		if (NotEnabled || !MSettings.useTearGas)
		{
			return true;
		}
		DoubleBroSevenSpecialType fieldValue = HarmonyExtensions.GetFieldValue<DoubleBroSevenSpecialType>((object)__instance, "currentSpecialType");
		if ((int)fieldValue != 5)
		{
			return true;
		}
		Networking.RPC<float>(PID.TargetAll, (RpcSignature<float>)((TestVanDammeAnim)__instance).PlayThrowLightSound, 0.5f, false);
		if (((NetworkObject)__instance).IsMine)
		{
			if (((TestVanDammeAnim)__instance).IsDucking && ((TestVanDammeAnim)__instance).down)
			{
				ProjectileController.SpawnGrenadeOverNetwork(__instance.tearGasGrenade, (MonoBehaviour)(object)__instance, ((BroforceObject)__instance).X + Mathf.Sign(((Component)__instance).transform.localScale.x) * VSettings.spawnTearGasPositionAtFeet.x, ((BroforceObject)__instance).Y + VSettings.spawnTearGasPositionAtFeet.y, 0.001f, 0.011f, Mathf.Sign(((Component)__instance).transform.localScale.x) * VSettings.spawnTearGasPositionAtFeetForce.x, VSettings.spawnTearGasPositionAtFeetForce.y, ((NetworkedUnit)__instance).playerNum, 1f);
			}
			else
			{
				ProjectileController.SpawnGrenadeOverNetwork(__instance.tearGasGrenade, (MonoBehaviour)(object)__instance, ((BroforceObject)__instance).X + Mathf.Sign(((Component)__instance).transform.localScale.x) * VSettings.spawnTearGasPosition.x, ((BroforceObject)__instance).Y + VSettings.spawnTearGasPosition.y, 0.001f, 0.011f, Mathf.Sign(((Component)__instance).transform.localScale.x) * VSettings.spawnTearGasPositionForce.x, VSettings.spawnTearGasPositionForce.y, ((NetworkedUnit)__instance).playerNum, 1f);
			}
		}
		int specialAmmo = ((TestVanDammeAnim)__instance).SpecialAmmo;
		((TestVanDammeAnim)__instance).SpecialAmmo = specialAmmo - 1;
		return false;
	}

	[HarmonyPatch("FireWeapon")]
	[HarmonyPrefix]
	private static bool NewShooting(DoubleBroSeven __instance, float x, float y, float xSpeed, float ySpeed)
	{
		if (NotEnabled || MSettings.hasDrunkShooting == Its.No)
		{
			return true;
		}
		if (HarmonyExtensions.GetInt((object)__instance, "martinisDrunk") >= VSettings.drunkAt)
		{
			float num = Random.Range(MSettings.drunkShootingAdditionalYSpeedRange.x, MSettings.drunkShootingAdditionalYSpeedRange.y);
			((TestVanDammeAnim)__instance).gunSprite.SetLowerLeftPixel(96f, 32f);
			EffectsController.CreateMuzzleFlashEffect(x, y, -25f, xSpeed * VSettings.muzzleFlashI.x, ySpeed * VSettings.muzzleFlashI.y, ((Component)__instance).transform);
			ProjectileController.SpawnProjectileLocally(((Unit)__instance).projectile, (MonoBehaviour)(object)__instance, x, y, xSpeed, ySpeed + num, ((NetworkedUnit)__instance).playerNum);
			return false;
		}
		return true;
	}

	[HarmonyPatch(typeof(PlayerHUD), "Awake")]
	[HarmonyPostfix]
	private static void AddTearGasToHUD(PlayerHUD __instance)
	{
		if (!NotEnabled && MSettings.useTearGas)
		{
			List<Material> list = __instance.doubleBroGrenades.ToList();
			list.Add(Mod.TearGasMaterial);
			__instance.doubleBroGrenades = list.ToArray();
		}
	}

	[HarmonyPatch("UseSpecial")]
	[HarmonyPostfix]
	private static void PutBalaclavaOnAvatar(DoubleBroSeven __instance)
	{
		//IL_0024: Unknown result type (might be due to invalid IL or missing references)
		//IL_0029: Unknown result type (might be due to invalid IL or missing references)
		//IL_002a: Unknown result type (might be due to invalid IL or missing references)
		//IL_002c: Invalid comparison between Unknown and I4
		if (NotEnabled || !MSettings.showBalaclavaOnAvatar)
		{
			return;
		}
		DoubleBroSevenSpecialType fieldValue = HarmonyExtensions.GetFieldValue<DoubleBroSevenSpecialType>((object)__instance, "currentSpecialType");
		if ((int)fieldValue == 1)
		{
			Trained007 component = ((Component)__instance).GetComponent<Trained007>();
			if ((Object)(object)component != (Object)null)
			{
				component.SetBalaclava(((TestVanDammeAnim)__instance).player.hud, Mod.AvatarBalaclavaTexture);
			}
		}
	}

	[HarmonyPatch("StopUsingSpecialRPC")]
	[HarmonyPrefix]
	private static void RemoveBalaclavaFromAvatar(DoubleBroSeven __instance)
	{
		//IL_0024: Unknown result type (might be due to invalid IL or missing references)
		//IL_0029: Unknown result type (might be due to invalid IL or missing references)
		//IL_002a: Unknown result type (might be due to invalid IL or missing references)
		//IL_002d: Invalid comparison between Unknown and I4
		if (NotEnabled || !MSettings.showBalaclavaOnAvatar)
		{
			return;
		}
		DoubleBroSevenSpecialType fieldValue = HarmonyExtensions.GetFieldValue<DoubleBroSevenSpecialType>((object)__instance, "currentSpecialType");
		if ((int)fieldValue == 100)
		{
			Trained007 component = ((Component)__instance).GetComponent<Trained007>();
			if ((Object)(object)component != (Object)null)
			{
				component.RemoveBalaclava(((TestVanDammeAnim)__instance).player.hud);
			}
		}
	}

	[HarmonyPatch("AnimateActualIdleFrames")]
	[HarmonyPrefix]
	private static bool AnimateActualIdleFrames(DoubleBroSeven __instance)
	{
		if (NotEnabled)
		{
			return true;
		}
		Traverse val = Traverse.Create((object)__instance);
		try
		{
			if (HarmonyExtensions.GetInt((object)val, "martinisDrunk") >= VSettings.drunkAt && HarmonyExtensions.GetInt((object)val, "gunFrame") <= 0 && !((TestVanDammeAnim)__instance).fire)
			{
				HarmonyExtensions.CallMethod((object)val, "SetSpriteOffset", new object[2] { 0f, 0f });
				HarmonyExtensions.CallMethod((object)val, "DeactivateGun", new object[0]);
				HarmonyExtensions.SetFieldValue<float>((object)val, "frameRate", 0.0333f);
				int num = (int)VSettings.drunkAnimationPosition.x + ((Unit)__instance).frame / 4 % VSettings.drunkAnimationMaxFrame;
				TestVanDammeAnimExtensions.SetSpriteLowerLeftPixel((TestVanDammeAnim)(object)__instance, num, (int)VSettings.drunkAnimationPosition.y);
			}
			else
			{
				AnimateActualIdleFramesBase((BroBase)(object)__instance);
			}
			return false;
		}
		catch (Exception str)
		{
			Main.Log(str);
		}
		return true;
	}

	[MethodImpl(MethodImplOptions.NoInlining)]
	[HarmonyPatch(typeof(BroBase), "AnimateActualIdleFrames")]
	[HarmonyReversePatch(/*Could not decode attribute arguments.*/)]
	private static void AnimateActualIdleFramesBase(BroBase __instance)
	{
		Main.Log($"Test: {__instance}");
	}

	[HarmonyPatch("AnimateInseminationFrames")]
	[HarmonyPrefix]
	private static bool AnimateInseminationFrames(DoubleBroSeven __instance)
	{
		if (NotEnabled)
		{
			return true;
		}
		int num = (int)VSettings.inseminationAnimation.x + HarmonyExtensions.CallMethod<int>((object)__instance, "CalculateInseminationFrame", new object[0]);
		TestVanDammeAnimExtensions.SetSpriteLowerLeftPixel((TestVanDammeAnim)(object)__instance, num, (int)VSettings.inseminationAnimation.y);
		return false;
	}

	[HarmonyPatch("SetBalaclavaTime")]
	[HarmonyPrefix]
	private static bool SetBalaclavaTime(DoubleBroSeven __instance, float time)
	{
		if (NotEnabled || VSettings.changeBalaclavaTime == Its.No)
		{
			return true;
		}
		HarmonyExtensions.SetFieldValue<float>((object)__instance, "balaclavaTime", VSettings.balaclavaTime);
		return false;
	}
}
internal static class Main
{
	internal static ModEntry mod;

	internal static bool enabled;

	internal static Settings settings;

	internal static Mod bfMod;

	private static bool Load(ModEntry modEntry)
	{
		//IL_0054: Unknown result type (might be due to invalid IL or missing references)
		//IL_005a: Expected O, but got Unknown
		modEntry.OnToggle = OnToggle;
		modEntry.OnGUI = OnGUI;
		modEntry.OnSaveGUI = OnSaveGUI;
		settings = ModSettings.Load<Settings>(modEntry);
		mod = modEntry;
		try
		{
			Harmony val = new Harmony(modEntry.Info.Id);
			Assembly executingAssembly = Assembly.GetExecutingAssembly();
			val.PatchAll(executingAssembly);
		}
		catch (Exception ex)
		{
			mod.Logger.Log(ex.ToString());
		}
		bfMod = new Mod();
		return true;
	}

	private static void OnGUI(ModEntry modEntry)
	{
		Extensions.Draw<Settings>(settings, modEntry);
		GUILayout.Space(10f);
		GUILayout.BeginHorizontal((GUILayoutOption[])(object)new GUILayoutOption[0]);
		if (GUILayout.Button("Reset Vanilla Configs to default", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(false) }))
		{
			settings.vanillaConfigs = new VanillaConfigs();
		}
		if (GUILayout.Button("Reset Mod Configs to default", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(false) }))
		{
			settings.modConfigs = new ModConfigs();
		}
		GUILayout.EndHorizontal();
	}

	private static bool OnToggle(ModEntry modEntry, bool value)
	{
		enabled = value;
		return true;
	}

	private static void OnSaveGUI(ModEntry modEntry)
	{
		((ModSettings)settings).Save(modEntry);
	}

	public static void Log(object str)
	{
		mod.Logger.Log(str.ToString());
	}
}
public class Mod
{
	private static Material _tearGasMaterial;

	private static Texture _avatarBalaclavaTexture;

	public static Mod Instance { get; private set; }

	public static ModConfigs ModSettings => Main.settings.modConfigs;

	public static VanillaConfigs VanillaSettings => Main.settings.vanillaConfigs;

	public static bool Enabled => Main.enabled;

	public static Material TearGasMaterial
	{
		get
		{
			if ((Object)(object)_tearGasMaterial == (Object)null)
			{
				_tearGasMaterial = GameSystems.ResourceManager.LoadAssetSync<Material>("sharedtextures:GrenadeTearGas");
			}
			return _tearGasMaterial;
		}
		set
		{
			_tearGasMaterial = value;
		}
	}

	public static Texture AvatarBalaclavaTexture
	{
		get
		{
			if ((Object)(object)_avatarBalaclavaTexture == (Object)null)
			{
				_avatarBalaclavaTexture = (Texture)(object)LoadTexture("avatar_balaclava.png");
			}
			return _avatarBalaclavaTexture;
		}
		set
		{
			_avatarBalaclavaTexture = value;
		}
	}

	public Mod()
	{
		Instance = this;
	}

	private static Texture2D LoadTexture(string name)
	{
		//IL_0023: Unknown result type (might be due to invalid IL or missing references)
		//IL_0029: Expected O, but got Unknown
		string path = Path.Combine(Main.mod.Path, name);
		Texture2D val = null;
		if (File.Exists(path))
		{
			val = new Texture2D(2, 2, (TextureFormat)5, false);
			ImageConversion.LoadImage(val, File.ReadAllBytes(path));
			((Texture)val).filterMode = (FilterMode)0;
			val.Apply();
		}
		return val;
	}
}
public enum Its
{
	No,
	Yes
}
public class Settings : ModSettings, IDrawable
{
	[Draw("Mod Settings", Box = true)]
	public ModConfigs modConfigs = new ModConfigs();

	[Draw("Vanilla Settings", Collapsible = true)]
	[Space(10f)]
	public VanillaConfigs vanillaConfigs = new VanillaConfigs();

	public override void Save(ModEntry modEntry)
	{
		ModSettings.Save<Settings>(this, modEntry);
	}

	public void OnChange()
	{
	}
}
[DrawFields(/*Could not decode attribute arguments.*/)]
public class ModConfigs
{
	[Draw("Use Tear Gas")]
	public bool useTearGas = true;

	[Draw("Show Balaclava On Avatar")]
	public bool showBalaclavaOnAvatar = true;

	[Draw(/*Could not decode attribute arguments.*/)]
	public Its hasDrunkShooting = Its.No;

	[Draw("Angle Range", Precision = 2, VisibleOn = "hasDrunkShooting|Yes")]
	public Vector2 drunkShootingAdditionalYSpeedRange = new Vector2(-25f, 25f);
}
[DrawFields(/*Could not decode attribute arguments.*/)]
public class VanillaConfigs
{
	[Draw(Precision = 2, Label = "Muzzle Flash I")]
	public Vector2 muzzleFlashI = new Vector2(0.01f, 0.01f);

	[Header("Animation")]
	[Space(5f)]
	[Draw("Use Pushing Animation")]
	public bool usePushingAnimation = false;

	[Draw("Use Ladder Climbing Animation")]
	public bool useLadderClimbingAnimation = false;

	[Draw("Use Ladder Transition Animation")]
	public bool useLadderClimbingTransitionAnimation = false;

	[Draw(/*Could not decode attribute arguments.*/)]
	public Vector2 inseminationAnimation = new Vector2(24f, 6f);

	[Header("Specials")]
	[Space(5f)]
	[Draw(/*Could not decode attribute arguments.*/)]
	public Its useMaxAmmo = Its.No;

	[Draw(/*Could not decode attribute arguments.*/)]
	public int maxAmmo = 2;

	[Header("Tear Gas")]
	[Space(5f)]
	[Draw("Spawn Tear Gas Offset", Precision = 2)]
	public Vector2 spawnTearGasPosition = new Vector2(6f, 10f);

	[Draw("Spawn Tear Gas Force", Precision = 2)]
	public Vector2 spawnTearGasPositionForce = new Vector2(200f, 150f);

	[Draw("Spawn Tear Gas At Feet Offset", Precision = 2)]
	public Vector2 spawnTearGasPositionAtFeet = new Vector2(6f, 3f);

	[Draw("Spawn Tear Gas At Feet Force", Precision = 2)]
	public Vector2 spawnTearGasPositionAtFeetForce = new Vector2(30f, 70f);

	[Header("Martinis")]
	[Space(5f)]
	[Draw(/*Could not decode attribute arguments.*/)]
	public int drunkAt = 2;

	[Draw(/*Could not decode attribute arguments.*/)]
	public Vector2 drunkAnimationPosition = new Vector2(25f, 7f);

	[Draw("Drunk Animation Max Frames")]
	public int drunkAnimationMaxFrame = 7;

	[Header("Balaclava")]
	[Draw(/*Could not decode attribute arguments.*/)]
	public Its changeBalaclavaTime = Its.No;

	[Draw(Label = "Balaclava Time", VisibleOn = "changeBalaclavaTime|Yes")]
	public float balaclavaTime = 5f;
}
public class Trained007 : MonoBehaviour
{
	public Texture originalTex;

	public void SetBalaclava(PlayerHUD hud, Texture avatar)
	{
		if (!((Object)(object)avatar == (Object)null))
		{
			originalTex = hud.avatar.meshRender.material.mainTexture;
			hud.avatar.meshRender.material.mainTexture = avatar;
		}
	}

	public void RemoveBalaclava(PlayerHUD hud)
	{
		if (!((Object)(object)originalTex == (Object)null))
		{
			hud.avatar.meshRender.material.mainTexture = originalTex;
		}
	}
}