using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using HarmonyLib;
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("ThundergunRevised")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ThundergunRevised")]
[assembly: AssemblyCopyright("Copyright © 2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("5711e2a0-d5a7-4ddf-b8d4-00f355fe9397")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: NeutralResourcesLanguage("en-FI")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace BringBackDualGun;
[BepInPlugin("plonk.dualgun", "Bring back dual pistol", "1.1.0")]
public class WeaponMakerScript : BaseUnityPlugin
{
[HarmonyPatch]
public class Patches
{
private static bool IsDualGun(Revolver r)
{
bool? obj;
if (r == null)
{
obj = null;
}
else
{
Transform parent = ((Component)r).transform.parent;
obj = ((parent != null) ? new bool?(((Object)parent).name.Contains("Revolver Dual 1")) : null);
}
bool? flag = obj;
return flag.GetValueOrDefault();
}
[HarmonyPrefix]
[HarmonyPatch(typeof(Revolver), "Shoot")]
public static bool ShootPrefix(Revolver __instance, int shotType)
{
//IL_0089: Unknown result type (might be due to invalid IL or missing references)
//IL_0094: Unknown result type (might be due to invalid IL or missing references)
//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
if (!IsDualGun(__instance))
{
return true;
}
CameraController val = RV<CameraController>(__instance, "cc");
Animator val2 = RV<Animator>(__instance, "anim");
AudioSource val3 = RV<AudioSource>(__instance, "gunAud");
AudioClip[] array = RV<AudioClip[]>(__instance, "gunShots");
GameObject val4 = RV<GameObject>(__instance, "revolverBeam");
GameObject val5 = RV<GameObject>(__instance, "gunBarrel");
val.StopShake();
SetRV(__instance, "shootReady", value: false);
if (shotType == 1)
{
GameObject val6 = Object.Instantiate<GameObject>(val4, ((Component)val).transform.position, ((Component)val).transform.rotation);
RevolverBeam component = val6.GetComponent<RevolverBeam>();
component.sourceWeapon = MonoSingleton<GunControl>.Instance.currentWeapon;
component.alternateStartPoint = val5.transform.position;
val3.clip = array[Random.Range(0, array.Length)];
val3.Play();
}
val2.SetFloat("RandomChance", Random.Range(0f, 1f));
val2.SetTrigger((shotType == 1) ? "Shoot" : "ChargeShoot");
return false;
}
[HarmonyPrefix]
[HarmonyPatch(typeof(Revolver), "ThrowCoin")]
public static bool CoinPrefix(Revolver __instance)
{
//IL_0043: Unknown result type (might be due to invalid IL or missing references)
//IL_004e: Unknown result type (might be due to invalid IL or missing references)
//IL_0053: Unknown result type (might be due to invalid IL or missing references)
//IL_005e: Unknown result type (might be due to invalid IL or missing references)
//IL_008a: Unknown result type (might be due to invalid IL or missing references)
//IL_0094: Unknown result type (might be due to invalid IL or missing references)
//IL_0099: Unknown result type (might be due to invalid IL or missing references)
//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
if (!IsDualGun(__instance))
{
return true;
}
Animator val = RV<Animator>(__instance, "anim");
GameObject val2 = RV<GameObject>(__instance, "coin");
CameraController val3 = RV<CameraController>(__instance, "cc");
GameObject val4 = Object.Instantiate<GameObject>(val2, ((Component)val3).transform.position + ((Component)val3).transform.forward, ((Component)val3).transform.rotation);
val4.GetComponent<Coin>().sourceWeapon = MonoSingleton<GunControl>.Instance.currentWeapon;
val4.GetComponent<Rigidbody>().AddForce(((Component)val3).transform.forward * 20f + Vector3.up * 15f, (ForceMode)2);
val.SetTrigger("ThrowCoin");
return false;
}
[HarmonyPostfix]
[HarmonyPatch(typeof(Revolver), "Update")]
public static void UpdatePostfix(Revolver __instance)
{
if (!IsDualGun(__instance))
{
return;
}
float num = RV<float>(__instance, "pierceCharge");
if (num > 0f && MonoSingleton<InputManager>.Instance.InputSource.Fire2.IsPressed)
{
SetRV(__instance, "pierceCharge", Mathf.MoveTowards(num, 100f, Time.deltaTime * 50f));
}
for (int i = 0; i < 6; i++)
{
Transform child = ((Component)__instance).transform.parent.GetChild(i);
if (((Component)child).gameObject.activeSelf)
{
}
}
}
[HarmonyPrefix]
[HarmonyPatch(typeof(GunControl), "SwitchWeapon", new Type[]
{
typeof(int),
typeof(List<GameObject>),
typeof(bool),
typeof(bool),
typeof(bool)
})]
public static void SwitchPatch()
{
canswitchstate = true;
}
}
public static GameObject bluetc;
public static GameObject greentc;
public static AssetBundle tcbundle;
private static bool candoshit;
private static bool canswitchstate;
private static bool tcenabled_val = true;
private static int lrevtype_val = 1;
private static int rrevtype_val = 3;
private static int slotpos_val = 3;
public static void SendHudMessage(string msg, int delay, bool silent)
{
MonoSingleton<HudMessageReceiver>.Instance.SendHudMessage(msg, "", "", delay, silent, false, true);
}
public static T FetchFromBundle<T>(string name, bool autofill = false) where T : Object
{
if (!autofill)
{
return tcbundle.LoadAsset<T>(name);
}
return tcbundle.LoadAsset<T>("assets/formods/bringbackdualpistol/" + name);
}
public void Awake()
{
if ((Object)(object)tcbundle == (Object)null)
{
tcbundle = AssetBundle.LoadFromFile(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "bringbackdualgun"));
}
}
public void Start()
{
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
new Harmony("plonk.dualgun").PatchAll();
}
public void Update()
{
if (!candoshit && SceneHelper.CurrentScene == "Main Menu")
{
if ((Object)(object)tcbundle != (Object)null)
{
candoshit = true;
}
else
{
SendHudMessage("Bring Back Dual Gun: asset bundle missing!", 0, silent: true);
}
}
if (!candoshit || SceneHelper.CurrentScene == "Main Menu" || !tcenabled_val)
{
return;
}
if ((Object)(object)bluetc == (Object)null)
{
bluetc = MakeGun();
return;
}
if (bluetc.activeSelf && canswitchstate)
{
FistControl instance = MonoSingleton<FistControl>.Instance;
instance.forceNoHold++;
canswitchstate = false;
}
if (!bluetc.activeSelf && !canswitchstate)
{
FistControl instance2 = MonoSingleton<FistControl>.Instance;
instance2.forceNoHold--;
canswitchstate = true;
}
((Component)bluetc.transform.GetChild(1)).gameObject.SetActive(lrevtype_val == 1);
((Component)bluetc.transform.GetChild(3)).gameObject.SetActive(lrevtype_val == 2);
((Component)bluetc.transform.GetChild(5)).gameObject.SetActive(lrevtype_val == 3);
((Component)bluetc.transform.GetChild(0)).gameObject.SetActive(rrevtype_val == 1);
((Component)bluetc.transform.GetChild(2)).gameObject.SetActive(rrevtype_val == 2);
((Component)bluetc.transform.GetChild(4)).gameObject.SetActive(rrevtype_val == 3);
List<GameObject> list = MonoSingleton<GunControl>.Instance.slots[0];
if ((Object)(object)list[Mathf.Min(slotpos_val, list.Count - 1)] != (Object)(object)bluetc)
{
RemoveGun();
Object.Destroy((Object)(object)bluetc);
bluetc = null;
}
}
public static GameObject MakeGun(int slot = 1)
{
GameObject val = WeaponMakerScript.FetchFromBundle<GameObject>("revolver dual 1.prefab", autofill: true);
if ((Object)(object)val == (Object)null)
{
return null;
}
GameObject val2 = Object.Instantiate<GameObject>(val);
val2.transform.SetParent(((Component)MonoSingleton<GunControl>.Instance).transform, false);
GunControl instance = MonoSingleton<GunControl>.Instance;
if (slotpos_val > instance.slots[slot - 1].Count - 1)
{
instance.slots[slot - 1].Add(val2);
}
else
{
instance.slots[slot - 1].Insert(slotpos_val, val2);
}
instance.allWeapons.Add(val2);
instance.slotDict.Add(val2, slot - 1);
val2.SetActive(false);
return val2;
}
private static T RV<T>(object target, string field)
{
FieldInfo field2 = target.GetType().GetField(field, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
return (field2 == null) ? default(T) : ((T)field2.GetValue(target));
}
private static void SetRV<T>(object target, string field, T value)
{
FieldInfo field2 = target.GetType().GetField(field, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
if (field2 != null)
{
field2.SetValue(target, value);
}
}
private static void RemoveGun()
{
if (!((Object)(object)bluetc == (Object)null))
{
MonoSingleton<GunControl>.Instance.slots[0].Remove(bluetc);
MonoSingleton<GunControl>.Instance.allWeapons.Remove(bluetc);
MonoSingleton<GunControl>.Instance.slotDict.Remove(bluetc);
}
}
}