using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using ComputerysModdingUtilities;
using FishNet;
using FishNet.Object;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;
using UnityEngine.SceneManagement;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: StraftatMod(false)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: IgnoresAccessChecksTo("ComputerysModdingUtilities")]
[assembly: IgnoresAccessChecksTo("FishNet.Runtime")]
[assembly: AssemblyCompany("STRAFTATNuevasMecanicas")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.1.0")]
[assembly: AssemblyInformationalVersion("1.0.1+a29816c634164db880c6c9a228d36c8be21edfea")]
[assembly: AssemblyProduct("com.elneko.nuevasmecanicas")]
[assembly: AssemblyTitle("STRAFTATNuevasMecanicas")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.1.0")]
[module: UnverifiableCode]
[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 STRAFTATNuevasMecanicas
{
public class CrouchSoundTracker : MonoBehaviour
{
private FirstPersonController _fpc;
private NetworkObject _nob;
private float _crouchTimer;
private bool _soundsActive;
private float _clipTimer;
private void Start()
{
_fpc = ((Component)this).GetComponent<FirstPersonController>();
_nob = ((Component)this).GetComponent<NetworkObject>();
ManualLogSource log = Plugin.Log;
object arg = InstanceFinder.IsServer;
object arg2 = InstanceFinder.IsClient;
NetworkObject nob = _nob;
log.LogInfo((object)$"[CrouchSounds] Listo — IsServer:{arg} IsClient:{arg2} IsOwner:{((nob != null) ? new bool?(nob.IsOwner) : null)}");
}
private void Update()
{
if ((Object)(object)_fpc == (Object)null)
{
return;
}
if (!_fpc.isCrouching)
{
if (_crouchTimer > 0f || _soundsActive)
{
_crouchTimer = 0f;
_soundsActive = false;
_clipTimer = 0f;
}
return;
}
_crouchTimer += Time.deltaTime;
if (_crouchTimer < 3f)
{
return;
}
if (!_soundsActive)
{
_soundsActive = true;
PlayRandomTaunt();
return;
}
_clipTimer -= Time.deltaTime;
if (_clipTimer <= 0f)
{
PlayRandomTaunt();
}
}
private void PlayRandomTaunt()
{
AudioClip[] tauntClip = _fpc.tauntClip;
if (tauntClip == null || tauntClip.Length == 0)
{
return;
}
int num = Mathf.Min(tauntClip.Length, 9);
int num2 = Random.Range(0, num);
AudioClip val = tauntClip[num2];
if (!((Object)(object)val == (Object)null))
{
_clipTimer = val.length;
bool isServer = InstanceFinder.IsServer;
bool isClient = InstanceFinder.IsClient;
bool flag = (Object)(object)_nob != (Object)null && _nob.IsOwner;
if (isServer)
{
_fpc.PlaySoundObservers(num2);
}
else if (isClient && flag)
{
_fpc.PlaySoundServer(num2);
}
else
{
_fpc.audio.PlayOneShot(val);
}
Plugin.Log.LogInfo((object)$"[CrouchSounds] Sonido {num2 + 1}/9 '{((Object)val).name}' | isServer:{isServer} isClient:{isClient} isOwner:{flag}");
}
}
}
[HarmonyPatch(typeof(PlayerPickup), "SetObjectInHandServer")]
internal static class Patch_ExplosivePickup
{
private const int Odds = 13;
private const float CancelGrace = 0.15f;
private static bool _methodsLogged;
[HarmonyPrefix]
private static void Prefix(PlayerPickup __instance)
{
if (!_methodsLogged)
{
_methodsLogged = true;
MethodInfo[] methods = typeof(PlayerPickup).GetMethods(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
foreach (MethodInfo methodInfo in methods)
{
Plugin.Log.LogInfo((object)("[PlayerPickup.Method] " + methodInfo.Name));
}
}
PlayerHealth component = ((Component)__instance).GetComponent<PlayerHealth>();
if (!((Object)(object)component == (Object)null))
{
WeaponFuse component2 = ((Component)component).GetComponent<WeaponFuse>();
if ((Object)(object)component2 != (Object)null)
{
component2.RequestCancel();
}
}
}
[HarmonyPostfix]
private static void Postfix(PlayerPickup __instance)
{
if (Random.Range(0, 13) == 0)
{
PlayerHealth component = ((Component)__instance).GetComponent<PlayerHealth>();
if (!((Object)(object)component == (Object)null) && !component.isKilled && !((Object)(object)((Component)component).GetComponent<WeaponFuse>() != (Object)null))
{
FirstPersonController fpc = ((Component)__instance).GetComponent<FirstPersonController>() ?? ((Component)__instance).GetComponentInParent<FirstPersonController>() ?? ((Component)__instance).GetComponentInChildren<FirstPersonController>();
((Component)component).gameObject.AddComponent<WeaponFuse>().Arm(component, fpc, 0.15f);
Plugin.Log.LogInfo((object)"[ExplosivePickup] Mecha encendida");
}
}
}
}
public class WeaponFuse : MonoBehaviour
{
private const float ExplosionRadius = 5f;
private const float Duration = 0.5f;
private PlayerHealth _ph;
private FirstPersonController _fpc;
private Renderer[] _renderers;
private Color[] _origColors;
private float _elapsed;
private float _nextTick;
private float _cancelGrace;
private bool _cancelRequested;
public void Arm(PlayerHealth ph, FirstPersonController fpc, float cancelGrace)
{
_ph = ph;
_fpc = fpc;
_cancelGrace = cancelGrace;
}
public void RequestCancel()
{
_cancelRequested = true;
}
private void Start()
{
//IL_0081: Unknown result type (might be due to invalid IL or missing references)
//IL_0074: Unknown result type (might be due to invalid IL or missing references)
//IL_0086: Unknown result type (might be due to invalid IL or missing references)
Component val = (Component)(((Object)(object)_fpc != (Object)null) ? ((object)_fpc) : ((object)_ph));
_renderers = val.GetComponentsInChildren<Renderer>(false);
_origColors = (Color[])(object)new Color[_renderers.Length];
for (int i = 0; i < _renderers.Length; i++)
{
Renderer obj = _renderers[i];
Material val2 = ((obj != null) ? obj.material : null);
if (!((Object)(object)val2 == (Object)null))
{
_origColors[i] = (val2.HasProperty("_BaseColor") ? val2.GetColor("_BaseColor") : val2.color);
}
}
Plugin.Log.LogInfo((object)$"[WeaponFuse] Armada — {_renderers.Length} renderers");
}
private void Update()
{
//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)
//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)_ph == (Object)null || _ph.isKilled)
{
Cancel();
return;
}
if (_elapsed > _cancelGrace && _cancelRequested)
{
Plugin.Log.LogInfo((object)"[WeaponFuse] Cancelada — arma soltada");
Cancel();
return;
}
_elapsed += Time.deltaTime;
if (_elapsed >= _nextTick)
{
_nextTick = _elapsed + 0.2f;
PlayTick();
}
float num = Mathf.Clamp01(_elapsed / 0.5f);
for (int i = 0; i < _renderers.Length; i++)
{
Renderer obj = _renderers[i];
Material val = ((obj != null) ? obj.material : null);
if (!((Object)(object)val == (Object)null))
{
Color val3 = (val.color = Color.Lerp(_origColors[i], Color.red, num));
if (val.HasProperty("_BaseColor"))
{
val.SetColor("_BaseColor", val3);
}
}
}
if (!(_elapsed < 0.5f))
{
Plugin.Log.LogInfo((object)"[WeaponFuse] BOOM");
RestoreColors();
Object.Destroy((Object)(object)this);
Explode();
}
}
private void Cancel()
{
RestoreColors();
Object.Destroy((Object)(object)this);
}
private void PlayTick()
{
if ((Object)(object)_fpc?.audio == (Object)null)
{
return;
}
AudioClip[] tauntClip = _fpc.tauntClip;
if (tauntClip == null || tauntClip.Length == 0)
{
return;
}
AudioClip val = tauntClip[0];
for (int i = 1; i < Mathf.Min(tauntClip.Length, 9); i++)
{
if ((Object)(object)tauntClip[i] != (Object)null && tauntClip[i].length < val.length)
{
val = tauntClip[i];
}
}
_fpc.audio.PlayOneShot(val, 1f);
}
private void Explode()
{
//IL_0027: Unknown result type (might be due to invalid IL or missing references)
//IL_002c: Unknown result type (might be due to invalid IL or missing references)
//IL_0033: Unknown result type (might be due to invalid IL or missing references)
//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
//IL_0100: Unknown result type (might be due to invalid IL or missing references)
//IL_006d: Unknown result type (might be due to invalid IL or missing references)
//IL_0075: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)_ph == (Object)null || _ph.isKilled)
{
return;
}
Vector3 position = ((Component)_ph).transform.position;
HashSet<PlayerHealth> hashSet = new HashSet<PlayerHealth>();
Collider[] array = Physics.OverlapSphere(position, 5f);
for (int i = 0; i < array.Length; i++)
{
PlayerHealth componentInParent = ((Component)array[i]).GetComponentInParent<PlayerHealth>();
if (!((Object)(object)componentInParent == (Object)null) && !componentInParent.isKilled && hashSet.Add(componentInParent))
{
float num = Vector3.Distance(position, ((Component)componentInParent).transform.position);
float num2 = Mathf.Lerp(100f, 10f, num / 5f);
componentInParent.RemoveHealth(num2);
Plugin.Log.LogInfo((object)$"[ExplosivePickup] {((Object)componentInParent).name} — {num2:F1} daño");
}
}
if (!_ph.isKilled)
{
_ph.Explode(true, true, "", Vector3.up * 5f, 15f, position);
}
}
private void RestoreColors()
{
//IL_002a: 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)
for (int i = 0; i < _renderers.Length; i++)
{
Renderer obj = _renderers[i];
Material val = ((obj != null) ? obj.material : null);
if (!((Object)(object)val == (Object)null))
{
val.color = _origColors[i];
if (val.HasProperty("_BaseColor"))
{
val.SetColor("_BaseColor", _origColors[i]);
}
}
}
}
}
[BepInPlugin("STRAFTATNuevasMecanicas", "com.elneko.nuevasmecanicas", "1.0.1")]
public class Plugin : BaseUnityPlugin
{
private static readonly HashSet<string> _menuScenes = new HashSet<string> { "MainMenu", "Menu", "main_menu", "Loading" };
public static ManualLogSource Log { get; private set; } = null;
private void Awake()
{
//IL_001d: Unknown result type (might be due to invalid IL or missing references)
Log = ((BaseUnityPlugin)this).Logger;
((Object)((Component)this).gameObject).hideFlags = (HideFlags)61;
new Harmony("STRAFTATNuevasMecanicas").PatchAll();
SceneManager.sceneLoaded += OnSceneLoaded;
Log.LogInfo((object)"================================================");
Log.LogInfo((object)" com.elneko.nuevasmecanicas v1.0.1");
Log.LogInfo((object)"================================================");
}
private void OnSceneLoaded(Scene scene, LoadSceneMode mode)
{
if (!_menuScenes.Contains(((Scene)(ref scene)).name))
{
FirstPersonController[] array = Object.FindObjectsOfType<FirstPersonController>();
for (int i = 0; i < array.Length; i++)
{
AttachCrouchTracker(array[i]);
}
}
}
public static void AttachCrouchTracker(FirstPersonController fpc)
{
if ((Object)(object)((Component)fpc).GetComponent<CrouchSoundTracker>() == (Object)null)
{
((Component)fpc).gameObject.AddComponent<CrouchSoundTracker>();
}
if ((Object)(object)((Component)fpc).GetComponent<ZMarkTracker>() == (Object)null)
{
((Component)fpc).gameObject.AddComponent<ZMarkTracker>();
}
}
}
[HarmonyPatch(typeof(FirstPersonController), "Awake")]
internal static class Patch_FPCAwake
{
[HarmonyPostfix]
private static void Postfix(FirstPersonController __instance)
{
Plugin.AttachCrouchTracker(__instance);
}
}
public class ZMarkTracker : MonoBehaviour
{
private const float CooldownDuration = 5f;
private FirstPersonController _fpc;
private NetworkObject _nob;
private PlayerHealth _ph;
private bool _markActive;
private Vector3 _markPosition;
private GameObject _markVisual;
private float _cooldown;
private GUIStyle _hudStyle;
private void Start()
{
_fpc = ((Component)this).GetComponent<FirstPersonController>();
_nob = ((Component)this).GetComponent<NetworkObject>();
_ph = ((Component)this).GetComponent<PlayerHealth>();
}
private void Update()
{
if ((Object)(object)_ph != (Object)null && _ph.isKilled && _markActive)
{
ClearMark();
return;
}
if (_cooldown > 0f)
{
_cooldown -= Time.deltaTime;
}
if ((!((Object)(object)_nob != (Object)null) || _nob.IsOwner) && ((ButtonControl)Keyboard.current.zKey).wasPressedThisFrame)
{
if (_markActive)
{
Teleport();
}
else if (_cooldown <= 0f)
{
PlaceMark();
}
}
}
private void PlaceMark()
{
//IL_000c: Unknown result type (might be due to invalid IL or missing references)
//IL_0011: 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_005d: Unknown result type (might be due to invalid IL or missing references)
//IL_0062: Unknown result type (might be due to invalid IL or missing references)
//IL_0077: Unknown result type (might be due to invalid IL or missing references)
//IL_0081: Unknown result type (might be due to invalid IL or missing references)
//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
//IL_0107: Unknown result type (might be due to invalid IL or missing references)
//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
_markPosition = ((Component)_fpc).transform.position;
_markActive = true;
if ((Object)(object)_markVisual != (Object)null)
{
Object.Destroy((Object)(object)_markVisual);
}
_markVisual = GameObject.CreatePrimitive((PrimitiveType)0);
_markVisual.transform.position = _markPosition + Vector3.up * 0.1f;
_markVisual.transform.localScale = Vector3.one * 0.4f;
Object.Destroy((Object)(object)_markVisual.GetComponent<Collider>());
Material material = _markVisual.GetComponent<Renderer>().material;
material.color = Color.cyan;
if (material.HasProperty("_BaseColor"))
{
material.SetColor("_BaseColor", Color.cyan);
}
if (material.HasProperty("_EmissionColor"))
{
material.SetColor("_EmissionColor", Color.cyan);
material.EnableKeyword("_EMISSION");
}
Plugin.Log.LogInfo((object)$"[ZMark] Mark placed at {_markPosition}");
}
private void Teleport()
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_0061: Unknown result type (might be due to invalid IL or missing references)
//IL_0071: Unknown result type (might be due to invalid IL or missing references)
//IL_0047: Unknown result type (might be due to invalid IL or missing references)
Vector3 markPosition = _markPosition;
ClearMark();
_cooldown = 5f;
CharacterController component = ((Component)_fpc).GetComponent<CharacterController>();
if ((Object)(object)component != (Object)null && ((Collider)component).enabled)
{
((Collider)component).enabled = false;
((Component)_fpc).transform.position = markPosition;
((Collider)component).enabled = true;
}
else
{
((Component)_fpc).transform.position = markPosition;
}
Plugin.Log.LogInfo((object)$"[ZMark] Teleported to {markPosition}");
}
private void ClearMark()
{
_markActive = false;
if ((Object)(object)_markVisual != (Object)null)
{
Object.Destroy((Object)(object)_markVisual);
_markVisual = null;
}
}
private void OnGUI()
{
//IL_004b: Unknown result type (might be due to invalid IL or missing references)
//IL_0050: Unknown result type (might be due to invalid IL or missing references)
//IL_0058: Unknown result type (might be due to invalid IL or missing references)
//IL_005f: Unknown result type (might be due to invalid IL or missing references)
//IL_0066: Unknown result type (might be due to invalid IL or missing references)
//IL_006d: Unknown result type (might be due to invalid IL or missing references)
//IL_0077: Expected O, but got Unknown
//IL_007c: Expected O, but got Unknown
//IL_0087: Unknown result type (might be due to invalid IL or missing references)
//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
if ((!((Object)(object)_nob != (Object)null) || _nob.IsOwner) && (!((Object)(object)_ph != (Object)null) || !_ph.isKilled))
{
if (_hudStyle == null)
{
_hudStyle = new GUIStyle(GUI.skin.box)
{
fontSize = 15,
fontStyle = (FontStyle)1,
alignment = (TextAnchor)3,
padding = new RectOffset(10, 10, 6, 6)
};
_hudStyle.normal.textColor = Color.white;
}
string text = ((_cooldown > 0f) ? $"Mark ready in {Mathf.Ceil(_cooldown):0}s" : ((!_markActive) ? "Press Z to place a mark" : "Press Z to teleport"));
GUI.Box(new Rect(10f, (float)Screen.height - 44f, 230f, 34f), text, _hudStyle);
}
}
}
public static class PluginInfo
{
public const string PLUGIN_GUID = "STRAFTATNuevasMecanicas";
public const string PLUGIN_NAME = "com.elneko.nuevasmecanicas";
public const string PLUGIN_VERSION = "1.0.1";
}
}