From 40ea81db75352bf98e941f0e0cc2f28b01f5ea8a Mon Sep 17 00:00:00 2001 From: SamSWAT Date: Sat, 19 Mar 2022 00:06:24 +0300 Subject: [PATCH] make mod independend of EFT version --- .../TimeWeatherController.cs | 34 +++++++++++++++---- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/project/SamSWAT.TimeWeatherChanger/TimeWeatherController.cs b/project/SamSWAT.TimeWeatherChanger/TimeWeatherController.cs index bcfbf5d..648d493 100644 --- a/project/SamSWAT.TimeWeatherChanger/TimeWeatherController.cs +++ b/project/SamSWAT.TimeWeatherChanger/TimeWeatherController.cs @@ -5,8 +5,9 @@ using EFT.UI; using EFT.Weather; using SamSWAT.TimeWeatherChanger.Utils; using System; +using System.Linq; +using System.Reflection; using UnityEngine; -using GameDateTime = GClass1246; using Random = UnityEngine.Random; namespace SamSWAT.TimeWeatherChanger @@ -16,7 +17,11 @@ namespace SamSWAT.TimeWeatherChanger private static GameObject input; private static WeatherController weatherController; private static GameWorld gameWorld; - private static GameDateTime gameDateTime; + + private static Type gameDateTime; + private static MethodInfo CalculateTime; + private static MethodInfo ResetTime; + private static DateTime modifiedDateTime; private static DateTime currentDateTime; private static Rect windowRect = new Rect(50, 50, 460, 365); @@ -38,6 +43,13 @@ namespace SamSWAT.TimeWeatherChanger private static int targetTimeHours; private static int targetTimeMinutes; + private bool IsTargetMethod(MethodInfo mi) + { + var parameters = mi.GetParameters(); + return parameters.Length == 1 + && parameters[0].Name == "gameDateTime"; + } + void Start() { //Duplicate functionality of toggle key @@ -64,7 +76,11 @@ namespace SamSWAT.TimeWeatherChanger { input = GameObject.Find("___Input"); } - gameDateTime = gameWorld.GameDateTime; + + gameDateTime = gameWorld.GameDateTime.GetType(); + CalculateTime = gameDateTime.GetMethod("Calculate", BindingFlags.Public | BindingFlags.Instance); + ResetTime = gameDateTime.GetMethods(BindingFlags.Public | BindingFlags.Instance).Single(IsTargetMethod); + GUIStatus = !GUIStatus; Cursor.visible = GUIStatus; if (GUIStatus) @@ -113,8 +129,12 @@ namespace SamSWAT.TimeWeatherChanger { input = GameObject.Find("___Input"); } - //Getting class responsible for time in the current world for later use - gameDateTime = gameWorld.GameDateTime; + + //Getting type responsible for time in the current world for later use + gameDateTime = gameWorld.GameDateTime.GetType(); + CalculateTime = gameDateTime.GetMethod("Calculate", BindingFlags.Public | BindingFlags.Instance); + ResetTime = gameDateTime.GetMethods(BindingFlags.Public | BindingFlags.Instance).Single(IsTargetMethod); + GUIStatus = !GUIStatus; Cursor.visible = GUIStatus; if (GUIStatus) @@ -165,7 +185,7 @@ namespace SamSWAT.TimeWeatherChanger weatherdebug = GUI.Toggle(new Rect(33, 37, 110, 25), weatherdebug, "Weather debug"); GUI.Label(new Rect(74, 52, 110, 25), weatherdebugtex); - currentDateTime = gameDateTime.Calculate(); + currentDateTime = (DateTime)CalculateTime.Invoke(gameWorld.GameDateTime, null); GUI.Box(new Rect(160, 23, 285, 60), "Current time: " + currentDateTime.ToString("HH:mm:ss")); GUI.Label(new Rect(190, 42, 40, 20), "Hours"); @@ -180,7 +200,7 @@ namespace SamSWAT.TimeWeatherChanger { modifiedDateTime = currentDateTime.AddHours((double)targetTimeHours - currentDateTime.Hour); modifiedDateTime = modifiedDateTime.AddMinutes((double)targetTimeMinutes - currentDateTime.Minute); - gameDateTime.Reset(modifiedDateTime); + ResetTime.Invoke(gameWorld.GameDateTime, new object[] { modifiedDateTime }); Notifier.DisplayMessageNotification("Time was set to: " + modifiedDateTime.ToString("HH:mm")); Singleton.Instance.PlayUISound(EUISoundType.MenuInspectorWindowClose); }