using UnityEngine; using System; using System.IO; using System.Collections; using System.Collections.Generic; using System.Linq; using EFT; using EFT.UI; using EFT.Communications; using EFT.Weather; using Comfort.Common; using RegexCMD = GClass2296; using GameDateTime = GClass1258; using Notifier = GClass1691; using CursorSettings = GClass2299; using Random = UnityEngine.Random; namespace SamSWAT.TimeWeatherChanger { public class TimeWeatherController : MonoBehaviour { private static GameObject input; private static WeatherController weatherController; private static GameWorld gameWorld; private static GameDateTime gameDateTime; private static DateTime modifiedDateTime; private static DateTime currentDateTime; private static Rect windowRect = new Rect(50, 50, 460, 365); private static bool GUIStatus = false; private static bool weatherdebug = false; private static float _clouddensity; private static float _fog; private static float _rain; private static float _lightningthunderprobability; private static float _temperature; private static float _windmagnitude; private static int _direction = 2; private static int topwinddirection = 2; private static WeatherDebug.Direction _winddirection; private static Vector2 _topwinddirection; private static string weatherdebugtex; private static int targetTimeHours; private static int targetTimeMinutes; private static KeyCode ToggleKey = KeyCode.Home; private static Dictionary ini; private static string modfolder = Path.Combine(Directory.GetParent(Application.dataPath).ToString(), "user/mods/SamSWAT-TWChanger"); private static string configpath = Path.Combine(modfolder, "config.ini"); void Start() { Debug.LogError("SamSWAT - Time and Weather Changer loaded"); //Duplicate functionality of toggle key ConsoleScreen.Commands.AddCommand(new RegexCMD("twc", match => { gameWorld = Singleton.Instance; if (gameWorld == null) { string log = "In order to change the weather, you have to go in a raid first."; Notifier.DisplayWarningNotification(log, ENotificationDurationType.Long); PreloaderUI.Instance.Console.AddLog(" " + log, "[TWChanger]:"); } else { if (GameObject.Find("Weather") == null) { string log = "An error occurred when executing command, seems like you are either in the hideout or factory."; Notifier.DisplayWarningNotification(log); PreloaderUI.Instance.Console.AddLog(" " + log, "[TWChanger]:"); } else { if (input == null) { input = GameObject.Find("___Input"); } gameDateTime = gameWorld.GameDateTime; GUIStatus = !GUIStatus; Cursor.visible = GUIStatus; if (GUIStatus) { CursorSettings.SetCursor(ECursorType.Idle); Cursor.lockState = CursorLockMode.None; Singleton.Instance.PlayUISound(EUISoundType.MenuContextMenu); } else { CursorSettings.SetCursor(ECursorType.Invisible); Cursor.lockState = CursorLockMode.Locked; Singleton.Instance.PlayUISound(EUISoundType.MenuDropdown); } input.SetActive(!GUIStatus); PreloaderUI.Instance.Console.AddLog(" Switching control panel...", "[TWChanger]:"); } } })); //Load config StartCoroutine(PreloaderUIWaiter()); } public void Update() { if (Input.GetKeyDown(ToggleKey)) { //Obtaining current GameWorld for later time change gameWorld = Singleton.Instance; //If GameWorld is null, it means that player currently is not in the raid. We notify the player with an error screen that he first needs to go in a raid if (gameWorld == null) { if (GameObject.Find("ErrorScreen")) PreloaderUI.Instance.CloseErrorScreen(); PreloaderUI.Instance.ShowErrorScreen("Time & Weather Changer Error", "In order to change the weather, you have to go in a raid first."); } else { //Looking for the weather GameObject to which the WeatherController script is attached. If it's null, means that the player is either in a hideout or factory where dynamic weather and time are not available if (GameObject.Find("Weather") == null) { //Notify player with bottom-right error popup Notifier.DisplayWarningNotification("An error occurred when opening weather panel, seems like you are either in the hideout or factory."); } else { //Caching input manager GameObject which script is responsible for reading the player inputs if (input == null) { input = GameObject.Find("___Input"); } //Getting class responsible for time in the current world for later use gameDateTime = gameWorld.GameDateTime; GUIStatus = !GUIStatus; Cursor.visible = GUIStatus; if (GUIStatus) { //Changing the default windows cursor to an EFT-style one and playing a sound when the menu appears CursorSettings.SetCursor(ECursorType.Idle); Cursor.lockState = CursorLockMode.None; Singleton.Instance.PlayUISound(EUISoundType.MenuContextMenu); } else { //Hiding cursor and playing a sound when the menu disappears CursorSettings.SetCursor(ECursorType.Invisible); Cursor.lockState = CursorLockMode.Locked; Singleton.Instance.PlayUISound(EUISoundType.MenuDropdown); } //Disabling the input manager so the player won't move input.SetActive(!GUIStatus); } } } } public void OnGUI() { if (GUIStatus) windowRect = GUI.Window(0, windowRect, WindowFunction, "Time & Weather Changer by SamSWAT v1.0"); } void WindowFunction(int windowID) { if (weatherdebug) weatherdebugtex = "ON"; else weatherdebugtex = "OFF"; //Caching WeatherController script for the first time if (weatherController == null) { weatherController = GameObject.Find("Weather").GetComponent(); } //Shit ton of different sliders and buttons GUI.DragWindow(new Rect(0, 0, 10000, 20)); //---------------------------------------------\\ GUI.Box(new Rect(15, 23, 140, 60), ""); weatherdebug = GUI.Toggle(new Rect(33, 37, 110, 25), weatherdebug, "Weather debug"); GUI.Label(new Rect(74, 52, 110, 25), weatherdebugtex); currentDateTime = gameDateTime.Calculate(); GUI.Box(new Rect(160, 23, 285, 60), "Current time: " + currentDateTime.ToString("HH:mm:ss")); GUI.Label(new Rect(190, 42, 40, 20), "Hours"); targetTimeHours = Mathf.RoundToInt(GUI.HorizontalSlider(new Rect(165, 60, 80, 15), targetTimeHours, 0, 23)); GUI.TextField(new Rect(248, 50, 20, 20), targetTimeHours.ToString()); GUI.Label(new Rect(295, 42, 50, 20), "Minutes"); targetTimeMinutes = Mathf.RoundToInt(GUI.HorizontalSlider(new Rect(272, 60, 90, 15), targetTimeMinutes, 0, 59)); GUI.TextField(new Rect(365, 50, 20, 20), targetTimeMinutes.ToString()); if (GUI.Button(new Rect(390, 40, 50, 30), "Set")) { modifiedDateTime = currentDateTime.AddHours((double)targetTimeHours - currentDateTime.Hour); modifiedDateTime = modifiedDateTime.AddMinutes((double)targetTimeMinutes - currentDateTime.Minute); gameDateTime.Reset(modifiedDateTime); Notifier.DisplayMessageNotification("Time was set to: " + modifiedDateTime.ToString("HH:mm")); Singleton.Instance.PlayUISound(EUISoundType.MenuInspectorWindowClose); } //---------------------------------------------\\ //---------------------------------------------\\ GUILayout.BeginArea(new Rect(15, 100, 140, 250)); GUILayout.BeginVertical(); GUILayout.Box("Cloud Density: " + Math.Round(_clouddensity * 1000) / 1000); _clouddensity = GUILayout.HorizontalSlider(_clouddensity, -1f, 1f); GUILayout.Box("Wind Magnitude: " + Math.Round(_windmagnitude * 100) / 100); _windmagnitude = GUILayout.HorizontalSlider(_windmagnitude, 0f, 1f); GUILayout.Box("Wind Direction: " + _winddirection.ToString()); _direction = Mathf.RoundToInt(GUILayout.HorizontalSlider(_direction, 1, 8)); _winddirection = (WeatherDebug.Direction)_direction; if (GUILayout.Button("Clear")) { _clouddensity = -0.7f; _fog = 0.004f; _lightningthunderprobability = 0f; _rain = 0f; _temperature = 22f; _direction = Random.Range(1, 8); _windmagnitude = 0f; topwinddirection = Random.Range(0, 5); } if (GUILayout.Button("Clear Wind")) { _clouddensity = -0.7f; _fog = 0.004f; _lightningthunderprobability = 0f; _rain = 0f; _temperature = 22f; _direction = Random.Range(1, 8); _windmagnitude = 0.4f; topwinddirection = Random.Range(0, 5); } if (GUILayout.Button("Clear Fog")) { _clouddensity = -0.4f; _fog = 0.02f; _lightningthunderprobability = 0f; _rain = 0f; _temperature = 22f; _direction = Random.Range(1, 8); _windmagnitude = 0f; topwinddirection = Random.Range(0, 5); } if (GUILayout.Button("Partly Cloud")) { _clouddensity = -0.2f; _fog = 0.004f; _lightningthunderprobability = 0f; _rain = 0f; _temperature = 22f; _direction = Random.Range(1, 8); _windmagnitude = 0f; topwinddirection = Random.Range(0, 5); } if (GUILayout.Button("Mostly Cloud")) { _clouddensity = 0f; _fog = 0.004f; _lightningthunderprobability = 0f; _rain = 0f; _temperature = 22f; _direction = Random.Range(1, 8); _windmagnitude = 0f; topwinddirection = Random.Range(0, 5); } GUILayout.EndVertical(); GUILayout.EndArea(); //---------------------------------------------\\ //---------------------------------------------\\ GUILayout.BeginArea(new Rect(160, 100, 140, 160)); GUILayout.BeginVertical(); GUILayout.Box("Fog: " + Math.Round(_fog * 1000) / 1000); _fog = GUILayout.HorizontalSlider(_fog, 0f, 0.35f); GUILayout.Box("Thunder prob: " + Math.Round(_lightningthunderprobability * 1000) / 1000); _lightningthunderprobability = GUILayout.HorizontalSlider(_lightningthunderprobability, 0f, 1f); if (GUILayout.Button("Randomize")) { float num = Random.Range(-1f, 1f); int num3; _rain = 0f; _clouddensity = num; if (num > 0.5f) { num3 = Random.Range(0, 5); _rain = Random.Range(0f, 1f); _fog = 0.004f; switch (num3) { case 0: break; case 1: _fog = 0.008f; goto IL_C5; case 2: _fog = 0.012f; goto IL_C5; case 3: _fog = 0.02f; goto IL_C5; case 4: _fog = 0.03f; goto IL_C5; default: goto IL_C5; } } _fog = Random.Range(0.003f, 0.006f); IL_C5: _direction = Random.Range(1, 8); topwinddirection = Random.Range(0, 5); _windmagnitude = Random.Range(0f, 1f); _lightningthunderprobability = Random.Range(0f, 1f); _temperature = Random.Range(-50f, 50f); } GUILayout.EndVertical(); GUILayout.EndArea(); //---------------------------------------------\\ //---------------------------------------------\\ GUILayout.BeginArea(new Rect(160, 229, 140, 160)); GUILayout.BeginVertical(); if (GUILayout.Button("Full Cloud")) { _clouddensity = 1f; _fog = 0.004f; _lightningthunderprobability = 0f; _rain = 0f; _temperature = 22f; _direction = Random.Range(1, 8); _windmagnitude = 0f; topwinddirection = Random.Range(0, 5); } if (GUILayout.Button("Cloud Wind")) { _clouddensity = 0.2f; _fog = 0.003f; _lightningthunderprobability = 0f; _rain = 0f; _temperature = 22f; _direction = Random.Range(1, 8); _windmagnitude = 0.66f; topwinddirection = Random.Range(0, 5); } if (GUILayout.Button("Cloud Fog")) { _clouddensity = 0.2f; _fog = 0.02f; _lightningthunderprobability = 0f; _rain = 0f; _temperature = 22f; _direction = Random.Range(1, 8); _windmagnitude = 0f; topwinddirection = Random.Range(0, 5); } if (GUILayout.Button("Thunder Cloud")) { _clouddensity = 1f; _fog = 0.004f; _lightningthunderprobability = 0.8f; _rain = 0f; _temperature = 22f; _direction = Random.Range(1, 8); _windmagnitude = 0.4f; topwinddirection = Random.Range(0, 5); } if (GUILayout.Button("Cloud Wind Rain")) { _clouddensity = 1f; _fog = 0.004f; _lightningthunderprobability = 0.5f; _rain = 0.8f; _temperature = 22f; _direction = Random.Range(1, 8); _windmagnitude = 0.6f; topwinddirection = Random.Range(0, 5); } GUILayout.EndVertical(); GUILayout.EndArea(); //---------------------------------------------\\ //---------------------------------------------\\ GUILayout.BeginArea(new Rect(305, 100, 140, 250)); GUILayout.BeginVertical(); GUILayout.Box("Rain: " + Math.Round(_rain * 1000) / 1000); _rain = GUILayout.HorizontalSlider(_rain, 0f, 1f); GUILayout.Box("Temperature: " + Math.Round(_temperature * 10) / 10); _temperature = GUILayout.HorizontalSlider(_temperature, -50f, 50f); GUILayout.Box("TopWind dir " + _topwinddirection.ToString()); topwinddirection = Mathf.RoundToInt(GUILayout.HorizontalSlider(topwinddirection, 1, 6)); switch (topwinddirection) { case 1: _topwinddirection = Vector2.down; break; case 2: _topwinddirection = Vector2.left; break; case 3: _topwinddirection = Vector2.one; break; case 4: _topwinddirection = Vector2.right; break; case 5: _topwinddirection = Vector2.up; break; case 6: _topwinddirection = Vector2.zero; break; } if (GUILayout.Button("Light Rain")) { _clouddensity = -0.1f; _fog = 0.004f; _lightningthunderprobability = 0f; _rain = 0.5f; _temperature = 22f; _direction = Random.Range(1, 8); _windmagnitude = 0f; topwinddirection = Random.Range(0, 5); } if (GUILayout.Button("Rain")) { _clouddensity = 0.05f; _fog = 0.004f; _lightningthunderprobability = 0.3f; _rain = 1f; _temperature = 22f; _direction = Random.Range(1, 8); _windmagnitude = 0.15f; topwinddirection = Random.Range(0, 5); } if (GUILayout.Button("Fog")) { _clouddensity = -0.4f; _fog = 0.1f; _lightningthunderprobability = 0f; _rain = 0f; _temperature = 22f; _direction = Random.Range(1, 8); _windmagnitude = 0f; topwinddirection = Random.Range(0, 5); } if (GUILayout.Button("Default")) { _clouddensity = -0.3f; _fog = 0.004f; _lightningthunderprobability = 0f; _rain = 0f; _temperature = 20f; _direction = 7; _windmagnitude = 0.75f; topwinddirection = 2; } if (GUILayout.Button("BSG Preset")) { _clouddensity = -0.371f; _fog = 0.009f; _lightningthunderprobability = 0f; _rain = 0f; _temperature = 0f; _direction = 8; _windmagnitude = 0.125f; topwinddirection = 2; } GUILayout.EndVertical(); GUILayout.EndArea(); //---------------------------------------------\\ if (!weatherdebug) GUI.Box(new Rect(10, 95, 440, 260), ""); //Writing all the parameters selected by the player to the WeatherDebug script weatherController.WeatherDebug.Enabled = weatherdebug; weatherController.WeatherDebug.CloudDensity = _clouddensity; weatherController.WeatherDebug.Fog = _fog; weatherController.WeatherDebug.LightningThunderProbability = _lightningthunderprobability; weatherController.WeatherDebug.Rain = _rain; weatherController.WeatherDebug.Temperature = _temperature; weatherController.WeatherDebug.TopWindDirection = _topwinddirection; weatherController.WeatherDebug.WindDirection = _winddirection; weatherController.WeatherDebug.WindMagnitude = _windmagnitude; } IEnumerator PreloaderUIWaiter() { //Waiting for preloader ui to load in case we need to show an error mesage if integrity of config.ini is compromised yield return new WaitUntil(() => PreloaderUI.Instantiated); if (File.Exists(configpath)) { //If the file exists, loading config values LoadConfig(); } else { //Message if there is no config.ini file in the mod folder, default home key will be used instead PreloaderUI.Instance.ShowErrorScreen("Time & Weather Changer Error", "Time & Weather Changer Error: \n \n Integrity compromised, config.ini is missing from the mod folder. \n Default \"Home\" key will be used."); Debug.LogError("Time & Weather Changer Error: Integrity compromised, config.ini is missing from the mod folder. Default \"Home\" key will be used."); } } private void LoadConfig() { //reading config.ini and separating line in it into dictionary where key=value so we will be able to use our prefered key ini = File.ReadLines(configpath).Where(IsConfigurationLine).Select(line => line.Split('=')).ToDictionary(line => line[0], line => line[1]); //checking if the line exists in the config file if (!ini.TryGetValue("PanelToggleKey", out var value)) { //Showing error message if there is no such line PreloaderUI.Instance.ShowErrorScreen("Time & Weather Changer Error", "Time & Weather Changer Error: \n \n Integrity compromised, config.ini is missing PanelToggleKey line. \n Default \"Home\" key will be used."); Debug.LogError("Time & Weather Changer Error: Integrity compromised, config.ini is missing PanelToggleKey line. Default \"Home\" key will be used."); ToggleKey = KeyCode.Home; } else { //If enum is good, replacing default one if (Enum.TryParse(value, out ToggleKey)) { Enum.TryParse(value, out ToggleKey); } else { //If not, showing error mesage PreloaderUI.Instance.ShowErrorScreen("Time & Weather Changer Error", "Time & Weather Changer Error: \n \n The key in config.ini is invalid, please compare it with the list of available keys at: \n https://docs.unity3d.com/ScriptReference/KeyCode.html \n \n Default \"Home\" key will be used."); Debug.LogError("Time & Weather Changer Error: The key in config.ini is invalid, please compare it with the list of available keys at: https://docs.unity3d.com/ScriptReference/KeyCode.html Default \"Home\" key will be used."); ToggleKey = KeyCode.Home; } } } private static bool IsConfigurationLine(string line) { //ignore [Config] and # commentary in the file return !line.StartsWith("#") && line.Contains("="); } } }