diff --git a/Live/CWX_AlarmChanger/AlarmChanger.cs b/Live/CWX_AlarmChanger/AlarmChanger.cs new file mode 100644 index 0000000..6da7835 --- /dev/null +++ b/Live/CWX_AlarmChanger/AlarmChanger.cs @@ -0,0 +1,25 @@ +using BepInEx; +using UnityEngine; + + +namespace CWX_AlarmChanger +{ + [BepInPlugin("com.cwx.alarmchanger", "cwx-alarmchanger", "1.0.0")] + public class AlarmChanger : BaseUnityPlugin + { + public static GameObject CWX_GameObject; + public static AlarmChangerScript CWX_Component; + + public void Awake() + { + CWX_GameObject = new GameObject("CWX_GameObject"); + DontDestroyOnLoad(CWX_GameObject); + CWX_Component = CWX_GameObject.AddComponent(); + } + + public void Start() + { + new AlarmChangerPatch().Enable(); + } + } +} diff --git a/Live/CWX_AlarmChanger/AlarmChangerPatch.cs b/Live/CWX_AlarmChanger/AlarmChangerPatch.cs new file mode 100644 index 0000000..47448b4 --- /dev/null +++ b/Live/CWX_AlarmChanger/AlarmChangerPatch.cs @@ -0,0 +1,26 @@ +using Aki.Reflection.Patching; +using Comfort.Common; +using EFT; +using System.Reflection; + +namespace CWX_AlarmChanger +{ + public class AlarmChangerPatch : ModulePatch + { + protected override MethodBase GetTargetMethod() + { + return typeof(GameWorld).GetMethod("OnGameStarted", BindingFlags.Public | BindingFlags.Instance); + } + + [PatchPostfix] + public static void PatchPostFix() + { + var gameWorld = Singleton.Instance; + + if (gameWorld != null && gameWorld.MainPlayer.Location.ToLower() == "rezervbase") + { + AlarmChanger.CWX_Component.SetSounds(); + } + } + } +} diff --git a/Live/CWX_AlarmChanger/AlarmChangerScript.cs b/Live/CWX_AlarmChanger/AlarmChangerScript.cs new file mode 100644 index 0000000..2ee88cc --- /dev/null +++ b/Live/CWX_AlarmChanger/AlarmChangerScript.cs @@ -0,0 +1,71 @@ +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using System; +using EFT.Interactive; +using UnityEngine.Networking; +using UnityEngine; +using System.Linq; + +namespace CWX_AlarmChanger +{ + public class AlarmChangerScript : MonoBehaviour + { + private List _clips = new List(); + + public void Start() + { + LoadAudioFilePaths(); + } + + public void SetSounds() + { + if (_clips.Count <= 0) return; + + var subscribers = FindObjectsOfType().Where(x => x.name.Contains("Siren_")).ToList(); + + foreach (var sub in subscribers) + { + sub.Sounds[0].Clip = _clips[UnityEngine.Random.Range(0, _clips.Count)]; + } + } + + private void LoadAudioFilePaths() + { + var AudioFiles = Directory.GetFiles(AppDomain.CurrentDomain.BaseDirectory + "/BepInEx/plugins/CWX_AlarmChanger/Sounds/"); + foreach (var File in AudioFiles) + { + LoadAudioClip(File); + } + } + + private async void LoadAudioClip(string path) + { + var audioClip = await RequestAudioClip(path); + + _clips.Add(audioClip); + } + + private async Task RequestAudioClip(string path) + { + + UnityWebRequest www = UnityWebRequestMultimedia.GetAudioClip(path, AudioType.WAV); + + var sendWeb = www.SendWebRequest(); + + while (!sendWeb.isDone) + { + await Task.Yield(); + } + + if (www.isNetworkError || www.isHttpError) + { + return null; + } + + AudioClip audioclip = DownloadHandlerAudioClip.GetContent(www); + + return audioclip; + } + } +} \ No newline at end of file diff --git a/Live/CWX_AlarmChanger/CWX_AlarmChanger.csproj b/Live/CWX_AlarmChanger/CWX_AlarmChanger.csproj new file mode 100644 index 0000000..336293d --- /dev/null +++ b/Live/CWX_AlarmChanger/CWX_AlarmChanger.csproj @@ -0,0 +1,37 @@ + + + + net472 + + + + + ..\..\..\Shared\Aki.Reflection.dll + + + ..\..\..\Shared\Assembly-CSharp.dll + + + ..\..\..\Shared\BepInEx.dll + + + ..\..\..\Shared\Comfort.dll + + + ..\..\..\Shared\UnityEngine.dll + + + ..\..\..\Shared\UnityEngine.AudioModule.dll + + + ..\..\..\Shared\UnityEngine.CoreModule.dll + + + ..\..\..\Shared\UnityEngine.UnityWebRequestAudioModule.dll + + + ..\..\..\Shared\UnityEngine.UnityWebRequestModule.dll + + + + diff --git a/Live/CWX_DebuggingTool/BotmonClass.cs b/Live/CWX_DebuggingTool/BotmonClass.cs index e382722..3d61cf6 100644 --- a/Live/CWX_DebuggingTool/BotmonClass.cs +++ b/Live/CWX_DebuggingTool/BotmonClass.cs @@ -5,6 +5,8 @@ using System; using System.Collections.Generic; using System.Linq; using UnityEngine; +using System.Reflection; +using CWX_DebuggingTool.Models; namespace CWX_DebuggingTool { @@ -16,11 +18,12 @@ namespace CWX_DebuggingTool private GUIStyle _textStyle; private Player _player; private Dictionary> _zoneAndPlayers = new Dictionary>(); + private Dictionary _playerRoleAndDiff = new Dictionary(); private List _zones; private GameWorld _gameWorld; private IBotGame _botGame; private Rect _rect; - private String _content = ""; + private string _content = ""; private Vector2 _guiSize; private float _distance; @@ -87,25 +90,35 @@ namespace CWX_DebuggingTool { foreach (var player in _gameWorld.AllPlayers) { - if (!player.IsYourPlayer) - { - var theirZone = player.AIData.BotOwner.BotsGroup.BotZone.NameZone; + if (player.IsYourPlayer) continue; - _zoneAndPlayers[theirZone].Add(player); - } + _playerRoleAndDiff.Add(player.ProfileId, GetBotRoleAndDiffClass(player.Profile.Info)); + + var theirZone = player.AIData.BotOwner.BotsGroup.BotZone.NameZone; + + _zoneAndPlayers[theirZone].Add(player); } } // Sub to Event to get and add Bot when they spawn _botGame.BotsController.BotSpawner.OnBotCreated += owner => { - Player player = owner.GetPlayer; - var theirZone = player.AIData.BotOwner.BotsGroup.BotZone.NameZone; - - _zoneAndPlayers[theirZone].Add(player); + var player = owner.GetPlayer; + _zoneAndPlayers[player.AIData.BotOwner.BotsGroup.BotZone.NameZone].Add(player); + _playerRoleAndDiff.Add(player.ProfileId, GetBotRoleAndDiffClass(player.Profile.Info)); }; } + public BotRoleAndDiffClass GetBotRoleAndDiffClass(InfoClass info) + { + var settings = info.GetType().GetField("Settings", BindingFlags.Public | BindingFlags.Instance).GetValue(info); + + var role = settings.GetType().GetField("Role", BindingFlags.Instance | BindingFlags.Public).GetValue(settings).ToString(); + var diff = settings.GetType().GetField("BotDifficulty", BindingFlags.Instance | BindingFlags.Public).GetValue(settings).ToString(); + + return new BotRoleAndDiffClass(string.IsNullOrEmpty(role) ? "" : role, string.IsNullOrEmpty(diff) ? "" : diff); + } + public void OnGUI() { // set basics on GUI @@ -131,26 +144,22 @@ namespace CWX_DebuggingTool } // If Mode Greater than or equal to 2 show total for each zone - if (Mode >= 2) + if (Mode >= 2 && _zoneAndPlayers != null) { - if (_zoneAndPlayers != null) + foreach (var zone in _zoneAndPlayers) { - foreach (var zone in _zoneAndPlayers) - { - if (_zoneAndPlayers[zone.Key].FindAll(x => x.HealthController.IsAlive).Count > 0) - { - _content += $"{zone.Key} = {_zoneAndPlayers[zone.Key].FindAll(x => x.HealthController.IsAlive).Count}\n"; + if (_zoneAndPlayers[zone.Key].FindAll(x => x.HealthController.IsAlive).Count <= 0) continue; - // If Mode Greater than or equal to 3 show Bots individually also - if (Mode >= 3) - { - foreach (var player in _zoneAndPlayers[zone.Key].Where(player => player.HealthController.IsAlive)) - { - _distance = Vector3.Distance(player.Position, _player.Position); - _content += $"> [{_distance:n2}m] [{player.Profile.Info.Settings.Role}] [{player.Profile.Side}] [{player.Profile.Info.Settings.BotDifficulty}] {player.Profile.Nickname}\n"; - } - } - } + _content += $"{zone.Key} = {_zoneAndPlayers[zone.Key].FindAll(x => x.HealthController.IsAlive).Count}\n"; + + // If Mode Greater than or equal to 3 show Bots individually also + if (Mode < 3) continue; + + foreach (var player in _zoneAndPlayers[zone.Key].Where(player => player.HealthController.IsAlive)) + { + _distance = Vector3.Distance(player.Position, _player.Position); + _content += $"> [{_distance:n2}m] [{_playerRoleAndDiff.First(x => x.Key == player.ProfileId).Value.Role}] " + + $"[{player.Profile.Side}] [{_playerRoleAndDiff.First(x => x.Key == player.ProfileId).Value.Difficulty}] {player.Profile.Nickname}\n"; } } } diff --git a/Live/CWX_DebuggingTool/DebuggingTool.cs b/Live/CWX_DebuggingTool/DebuggingTool.cs index 8269d31..8c240b2 100644 --- a/Live/CWX_DebuggingTool/DebuggingTool.cs +++ b/Live/CWX_DebuggingTool/DebuggingTool.cs @@ -51,7 +51,7 @@ namespace CWX_DebuggingTool { var gameWorld = Singleton.Instance; - var btmInstance = gameWorld.GetOrAddComponent(); + var btmInstance = gameWorld.gameObject.AddComponent(); btmInstance.Mode = option; } diff --git a/Live/CWX_DebuggingTool/Models/BotRoleAndDiffClass.cs b/Live/CWX_DebuggingTool/Models/BotRoleAndDiffClass.cs new file mode 100644 index 0000000..752dd56 --- /dev/null +++ b/Live/CWX_DebuggingTool/Models/BotRoleAndDiffClass.cs @@ -0,0 +1,14 @@ +namespace CWX_DebuggingTool.Models +{ + public class BotRoleAndDiffClass + { + public BotRoleAndDiffClass(string role = "", string difficulty = "") + { + Role = role; + Difficulty = difficulty; + } + + public string Role { get; set; } + public string Difficulty { get; set; } + } +} \ No newline at end of file diff --git a/Live/CWX_Mods.sln b/Live/CWX_Mods.sln index 54c654a..1c34947 100644 --- a/Live/CWX_Mods.sln +++ b/Live/CWX_Mods.sln @@ -11,11 +11,13 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CWX_DeSharpener", "CWX_DeSh EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CWX_MasterKey", "CWX_MasterKey\CWX_MasterKey.csproj", "{40BE277F-55BE-4579-9535-D1F5ED9CC549}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CWX_DebuggingTool", "CWX_DebuggingTool\CWX_DebuggingTool.csproj", "{E439D92F-26FD-42A2-9EA5-38A318EB5403}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CWX_DebuggingTool", "CWX_DebuggingTool\CWX_DebuggingTool.csproj", "{E439D92F-26FD-42A2-9EA5-38A318EB5403}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CWX_ColourAdderPrePatch", "CWX_ColourAdderPrePatch\CWX_ColourAdderPrePatch.csproj", "{B0AE824D-7308-47DD-B0BF-08D48B33CBD7}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CWX_ColourAdderPrePatch", "CWX_ColourAdderPrePatch\CWX_ColourAdderPrePatch.csproj", "{B0AE824D-7308-47DD-B0BF-08D48B33CBD7}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CWX_ColourAdderPatcher", "CWX_ColourAdderPatcher\CWX_ColourAdderPatcher.csproj", "{6D696C6A-011B-4D53-8D97-D62105B20E0E}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CWX_ColourAdderPatcher", "CWX_ColourAdderPatcher\CWX_ColourAdderPatcher.csproj", "{6D696C6A-011B-4D53-8D97-D62105B20E0E}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CWX_AlarmChanger", "CWX_AlarmChanger\CWX_AlarmChanger.csproj", "{518D3743-AE98-41CD-8A6A-7B537C3FC293}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -51,6 +53,10 @@ Global {6D696C6A-011B-4D53-8D97-D62105B20E0E}.Debug|Any CPU.Build.0 = Debug|Any CPU {6D696C6A-011B-4D53-8D97-D62105B20E0E}.Release|Any CPU.ActiveCfg = Release|Any CPU {6D696C6A-011B-4D53-8D97-D62105B20E0E}.Release|Any CPU.Build.0 = Release|Any CPU + {518D3743-AE98-41CD-8A6A-7B537C3FC293}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {518D3743-AE98-41CD-8A6A-7B537C3FC293}.Debug|Any CPU.Build.0 = Debug|Any CPU + {518D3743-AE98-41CD-8A6A-7B537C3FC293}.Release|Any CPU.ActiveCfg = Release|Any CPU + {518D3743-AE98-41CD-8A6A-7B537C3FC293}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE