make mod independend of EFT version

This commit is contained in:
SamSWAT 2022-03-19 00:06:24 +03:00
parent d565244e76
commit 40ea81db75

View File

@ -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<GUISounds>.Instance.PlayUISound(EUISoundType.MenuInspectorWindowClose);
}