using BepInEx; using BepInEx.Configuration; using Comfort.Common; using EFT; using EFT.AssetsManager; using System; using System.Linq; using UnityEngine; namespace SamSWAT.HelmetLights { [BepInPlugin("com.samswat.helmetlights", "SamSWAT.HelmetLights", "1.0.0")] public class Plugin : BaseUnityPlugin { private static GameObject _flashlight; private static GameObject[] _modes; private static int _currentMode = 1; internal static ConfigEntry HeadlightToggleKey; internal static ConfigEntry HeadlightModeKey; private void Awake() { HeadlightToggleKey = Config.Bind( "Main Settings", "Helmet Light Toggle", new KeyboardShortcut(KeyCode.Y), "Key for helmet light toggle"); HeadlightModeKey = Config.Bind( "Main Settings", "Helmet Light Mode", new KeyboardShortcut(KeyCode.Y, KeyCode.LeftShift), "Key for helemt light mode change"); } private void Update() { var gameWorld = Singleton.Instance; if (gameWorld == null || gameWorld.RegisteredPlayers == null) { return; } if (_flashlight != null && _flashlight.GetComponent().IsInPool) { _flashlight = null; _currentMode = 1; } if (HeadlightToggleKey.Value.IsUp() && PlayerHasFlashlight()) ToggleLight(); if (HeadlightModeKey.Value.IsUp() && PlayerHasFlashlight()) ChangeMode(); } private void ToggleLight() { _modes[0].SetActive(!_modes[0].activeSelf); _modes[_currentMode].SetActive(!_modes[_currentMode].activeSelf); } private void ChangeMode() { if (_modes[0].activeSelf == false) { if (_currentMode < _modes.Length - 1) { _modes[_currentMode].SetActive(!_modes[_currentMode].activeSelf); _currentMode++; _modes[_currentMode].SetActive(!_modes[_currentMode].activeSelf); } else { _modes[_currentMode].SetActive(!_modes[_currentMode].activeSelf); _currentMode = 1; _modes[_currentMode].SetActive(!_modes[_currentMode].activeSelf); } } } private bool PlayerHasFlashlight() { if (_flashlight == null) { Player player = Singleton.Instance.RegisteredPlayers.Find(p => p.IsYourPlayer); _flashlight = player.GetComponentInChildren()?.gameObject; if (_flashlight == null) return false; _modes = Array.ConvertAll(_flashlight.GetComponentsInChildren(true), y => y.gameObject).Where(x => x.name.Contains("mode_")).ToArray(); return true; } else { return true; } } } }