Updated to 17107 (AKI 2.3.0) + BepInEx conversion
This commit is contained in:
parent
5d8052674c
commit
d565244e76
21
README.md
21
README.md
@ -2,24 +2,27 @@
|
|||||||
|
|
||||||
Change the weather and time with GUI-based mod
|
Change the weather and time with GUI-based mod
|
||||||
|
|
||||||
### Controls
|
## Controls
|
||||||
|
|
||||||
In order to open panel, press keypad "Home" by default or open game console with tilde(~) and write "twc"
|
In order to open panel, press keypad "Home" by default or open game console with tilde(~) and write "twc"
|
||||||
|
|
||||||
You can change key in config.ini [[list of available keys]](https://docs.unity3d.com/ScriptReference/KeyCode.html)
|
You can change the key in the game menu, to open it, press F12 on your keyboard and expand SamSWAT.TimeWeatherChanger section. Press on the `Time Weather Panel Toggle Key` option and choose the key you like. If you launched the game with this mod at least once, you can find `com.samswat.timeweatherchanger.cfg` file in the `BepInEx/config/` and change keybind here too.
|
||||||
|
|
||||||
### How to install
|
## How to install
|
||||||
|
|
||||||
1. Download the latest release here: [link](https://dev.sp-tarkov.com/SamSWAT/TimeWeatherChanger/releases) -OR- build from source (instructions below)
|
1. Download the latest release here: [link](https://dev.sp-tarkov.com/SamSWAT/TimeWeatherChanger/releases) -OR- build from source (instructions below)
|
||||||
2. Simply drop the folder `SamSWAT-TWChanger` into your SPT-AKI `user/mods/` directory.
|
2. Extract the zip file `SamSWAT.TimeWeatherChanger` into your root SPT-AKI directory near `EscapeFromTarkov.exe`.
|
||||||
|
3. Inside `BepInEx/plugins` folder you should see `SamSWAT.TimeWeatherChanger.dll`
|
||||||
|
|
||||||
### Preview
|
## Preview
|
||||||
|
|
||||||
![preview](https://media.discordapp.net/attachments/891823733499629619/928128516720062495/unknown.png)
|
![preview](https://media.discordapp.net/attachments/891823733499629619/928128516720062495/unknown.png)
|
||||||
|
|
||||||
### How to build from source
|
## How to build from source
|
||||||
|
|
||||||
1. Download/clone this repository
|
1. Download/clone this repository
|
||||||
2. Build `SamSWAT.TimeWeatherChanger.csproj` - `SamSWAT.TimeWeatherChanger.dll` should appear in `bin\Debug` directory
|
2. VS2019 > File > Open solution > `SamSWAT.TimeWeatherChanger.sln`
|
||||||
3. Copy the .dll into the `mod/SamSWAT-TWChanger` folder and rename to `module.dll`
|
3. VS2019 > Build > Rebuild solution
|
||||||
4. That's it, you have a working release of this mod! Follow the `How to install` instructions on how to get the mod into your game
|
4. `SamSWAT.TimeWeatherChanger.dll` should appear in `bin\Debug` directory
|
||||||
|
5. Copy the .dll into the `BepInEx/plugins` folder
|
||||||
|
6. That's it, you have a working release of this mod.
|
@ -1,4 +0,0 @@
|
|||||||
[Config]
|
|
||||||
PanelToggleKey=Home
|
|
||||||
|
|
||||||
#list of available keys you can find at: https://docs.unity3d.com/ScriptReference/KeyCode.html
|
|
@ -1,8 +0,0 @@
|
|||||||
{
|
|
||||||
"name": "time_weather_changer",
|
|
||||||
"author": "SamSWAT",
|
|
||||||
"version": "2.0.0",
|
|
||||||
"license": "CC BY-NC 4.0",
|
|
||||||
"akiVersion": "2.2.2"
|
|
||||||
}
|
|
||||||
|
|
@ -1,17 +0,0 @@
|
|||||||
using UnityEngine;
|
|
||||||
|
|
||||||
namespace SamSWAT.TimeWeatherChanger
|
|
||||||
{
|
|
||||||
public class Program
|
|
||||||
{
|
|
||||||
public static GameObject Hook;
|
|
||||||
public static void Main(string[] args)
|
|
||||||
{
|
|
||||||
Debug.LogError("SamSWAT - Time and Weather Changer loaded");
|
|
||||||
|
|
||||||
Hook = new GameObject();
|
|
||||||
Hook.AddComponent<TimeWeatherController>();
|
|
||||||
Object.DontDestroyOnLoad(Hook);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -37,10 +37,20 @@
|
|||||||
<AssemblyOriginatorKeyFile>Key.snk</AssemblyOriginatorKeyFile>
|
<AssemblyOriginatorKeyFile>Key.snk</AssemblyOriginatorKeyFile>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<Reference Include="0Harmony">
|
||||||
|
<HintPath>References\0Harmony.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="Aki.Reflection, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||||
|
<SpecificVersion>False</SpecificVersion>
|
||||||
|
<HintPath>References\Aki.Reflection.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
<Reference Include="Assembly-CSharp, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
|
<Reference Include="Assembly-CSharp, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||||
<SpecificVersion>False</SpecificVersion>
|
<SpecificVersion>False</SpecificVersion>
|
||||||
<HintPath>References\Assembly-CSharp.dll</HintPath>
|
<HintPath>References\Assembly-CSharp.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
|
<Reference Include="BepInEx">
|
||||||
|
<HintPath>References\BepInEx.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
<Reference Include="Comfort, Version=1.0.0.4, Culture=neutral, processorArchitecture=MSIL">
|
<Reference Include="Comfort, Version=1.0.0.4, Culture=neutral, processorArchitecture=MSIL">
|
||||||
<SpecificVersion>False</SpecificVersion>
|
<SpecificVersion>False</SpecificVersion>
|
||||||
<HintPath>References\Comfort.dll</HintPath>
|
<HintPath>References\Comfort.dll</HintPath>
|
||||||
@ -56,14 +66,18 @@
|
|||||||
<SpecificVersion>False</SpecificVersion>
|
<SpecificVersion>False</SpecificVersion>
|
||||||
<HintPath>References\UnityEngine.IMGUIModule.dll</HintPath>
|
<HintPath>References\UnityEngine.IMGUIModule.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="UnityEngine.InputLegacyModule">
|
<Reference Include="UnityEngine.InputLegacyModule, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||||
|
<SpecificVersion>False</SpecificVersion>
|
||||||
<HintPath>References\UnityEngine.InputLegacyModule.dll</HintPath>
|
<HintPath>References\UnityEngine.InputLegacyModule.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="TimeWeatherController.cs" />
|
<Compile Include="TimeWeatherController.cs" />
|
||||||
<Compile Include="Program.cs" />
|
<Compile Include="TimeWeatherPlugin.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
|
<Compile Include="Utils\CursorSettings.cs" />
|
||||||
|
<Compile Include="Utils\GameConsole.cs" />
|
||||||
|
<Compile Include="Utils\Notifier.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="Key.snk" />
|
<None Include="Key.snk" />
|
||||||
|
@ -1,18 +1,12 @@
|
|||||||
using UnityEngine;
|
using Comfort.Common;
|
||||||
using System;
|
|
||||||
using System.IO;
|
|
||||||
using System.Collections;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using EFT;
|
using EFT;
|
||||||
using EFT.UI;
|
|
||||||
using EFT.Communications;
|
using EFT.Communications;
|
||||||
|
using EFT.UI;
|
||||||
using EFT.Weather;
|
using EFT.Weather;
|
||||||
using Comfort.Common;
|
using SamSWAT.TimeWeatherChanger.Utils;
|
||||||
using RegexCMD = GClass2285;
|
using System;
|
||||||
|
using UnityEngine;
|
||||||
using GameDateTime = GClass1246;
|
using GameDateTime = GClass1246;
|
||||||
using Notifier = GClass1680;
|
|
||||||
using CursorSettings = GClass2288;
|
|
||||||
using Random = UnityEngine.Random;
|
using Random = UnityEngine.Random;
|
||||||
|
|
||||||
namespace SamSWAT.TimeWeatherChanger
|
namespace SamSWAT.TimeWeatherChanger
|
||||||
@ -44,19 +38,10 @@ namespace SamSWAT.TimeWeatherChanger
|
|||||||
private static int targetTimeHours;
|
private static int targetTimeHours;
|
||||||
private static int targetTimeMinutes;
|
private static int targetTimeMinutes;
|
||||||
|
|
||||||
private static KeyCode ToggleKey = KeyCode.Home;
|
|
||||||
private static Dictionary<string, string> ini;
|
|
||||||
|
|
||||||
private static string modfolder;
|
|
||||||
private static string configpath;
|
|
||||||
|
|
||||||
void Start()
|
void Start()
|
||||||
{
|
{
|
||||||
modfolder = Path.Combine(Directory.GetParent(Application.dataPath).ToString(), "user/mods/SamSWAT-TWChanger");
|
|
||||||
configpath = Path.Combine(modfolder, "config.ini");
|
|
||||||
|
|
||||||
//Duplicate functionality of toggle key
|
//Duplicate functionality of toggle key
|
||||||
ConsoleScreen.Commands.AddCommand(new RegexCMD("twc", match =>
|
GameConsole.AddCommand("twc", match =>
|
||||||
{
|
{
|
||||||
gameWorld = Singleton<GameWorld>.Instance;
|
gameWorld = Singleton<GameWorld>.Instance;
|
||||||
if (gameWorld == null)
|
if (gameWorld == null)
|
||||||
@ -98,14 +83,11 @@ namespace SamSWAT.TimeWeatherChanger
|
|||||||
PreloaderUI.Instance.Console.AddLog(" Switching control panel...", "[TWChanger]:");
|
PreloaderUI.Instance.Console.AddLog(" Switching control panel...", "[TWChanger]:");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}));
|
});
|
||||||
|
|
||||||
//Load config
|
|
||||||
StartCoroutine(PreloaderUIWaiter());
|
|
||||||
}
|
}
|
||||||
public void Update()
|
public void Update()
|
||||||
{
|
{
|
||||||
if (Input.GetKeyDown(ToggleKey))
|
if (Input.GetKeyDown(TimeWeatherPlugin.TogglePanel.Value.MainKey))
|
||||||
{
|
{
|
||||||
//Obtaining current GameWorld for later time change
|
//Obtaining current GameWorld for later time change
|
||||||
gameWorld = Singleton<GameWorld>.Instance;
|
gameWorld = Singleton<GameWorld>.Instance;
|
||||||
@ -158,9 +140,9 @@ namespace SamSWAT.TimeWeatherChanger
|
|||||||
public void OnGUI()
|
public void OnGUI()
|
||||||
{
|
{
|
||||||
if (GUIStatus)
|
if (GUIStatus)
|
||||||
windowRect = GUI.Window(0, windowRect, WindowFunction, "Time & Weather Changer by SamSWAT v2.0");
|
windowRect = GUI.Window(0, windowRect, WindowFunction, "Time & Weather Changer by SamSWAT v2.2");
|
||||||
}
|
}
|
||||||
void WindowFunction(int windowID)
|
void WindowFunction(int TWCWindowID)
|
||||||
{
|
{
|
||||||
if (weatherdebug)
|
if (weatherdebug)
|
||||||
weatherdebugtex = "ON";
|
weatherdebugtex = "ON";
|
||||||
@ -512,56 +494,5 @@ namespace SamSWAT.TimeWeatherChanger
|
|||||||
weatherController.WeatherDebug.WindMagnitude = _windmagnitude;
|
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]);
|
|
||||||
|
|
||||||
//check 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("=");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
29
project/SamSWAT.TimeWeatherChanger/TimeWeatherPlugin.cs
Normal file
29
project/SamSWAT.TimeWeatherChanger/TimeWeatherPlugin.cs
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
using UnityEngine;
|
||||||
|
using BepInEx;
|
||||||
|
using BepInEx.Configuration;
|
||||||
|
|
||||||
|
namespace SamSWAT.TimeWeatherChanger
|
||||||
|
{
|
||||||
|
[BepInPlugin("com.samswat.timeweatherchanger", "SamSWAT.TimeWeatherChanger", "2.2.0")]
|
||||||
|
public class TimeWeatherPlugin : BaseUnityPlugin
|
||||||
|
{
|
||||||
|
public static GameObject Hook;
|
||||||
|
|
||||||
|
private const string SectionName = "Main";
|
||||||
|
internal static ConfigEntry<KeyboardShortcut> TogglePanel;
|
||||||
|
|
||||||
|
private void Awake()
|
||||||
|
{
|
||||||
|
Logger.LogInfo("Loading: SamSWAT-TimeWeatherChanger 2.2.0");
|
||||||
|
Hook = new GameObject("Time Weather Controller");
|
||||||
|
Hook.AddComponent<TimeWeatherController>();
|
||||||
|
DontDestroyOnLoad(Hook);
|
||||||
|
|
||||||
|
TogglePanel = Config.Bind(
|
||||||
|
SectionName,
|
||||||
|
"Time Weather Panel Toggle Key",
|
||||||
|
new KeyboardShortcut(KeyCode.Home),
|
||||||
|
"The keyboard shortcut that toggles control panel");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
23
project/SamSWAT.TimeWeatherChanger/Utils/CursorSettings.cs
Normal file
23
project/SamSWAT.TimeWeatherChanger/Utils/CursorSettings.cs
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
using Aki.Reflection.Utils;
|
||||||
|
using EFT.UI;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Reflection;
|
||||||
|
|
||||||
|
namespace SamSWAT.TimeWeatherChanger.Utils
|
||||||
|
{
|
||||||
|
static class CursorSettings
|
||||||
|
{
|
||||||
|
private static readonly MethodInfo setCursorMethod;
|
||||||
|
|
||||||
|
static CursorSettings()
|
||||||
|
{
|
||||||
|
var cursorType = PatchConstants.EftTypes.Single(x => x.GetMethod("SetCursor") != null);
|
||||||
|
setCursorMethod = cursorType.GetMethod("SetCursor");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void SetCursor(ECursorType type)
|
||||||
|
{
|
||||||
|
setCursorMethod.Invoke(null, new object[] { type });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
33
project/SamSWAT.TimeWeatherChanger/Utils/GameConsole.cs
Normal file
33
project/SamSWAT.TimeWeatherChanger/Utils/GameConsole.cs
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
using Aki.Reflection.Utils;
|
||||||
|
using EFT.UI;
|
||||||
|
using HarmonyLib;
|
||||||
|
using System;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Reflection;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
|
|
||||||
|
namespace SamSWAT.TimeWeatherChanger.Utils
|
||||||
|
{
|
||||||
|
static class GameConsole
|
||||||
|
{
|
||||||
|
private static readonly Type consoleCommandType;
|
||||||
|
private static readonly ConstructorInfo consoleCommandConstructor;
|
||||||
|
private static readonly MethodInfo consoleCommandsAddMethod;
|
||||||
|
private static readonly FieldInfo commandsField;
|
||||||
|
|
||||||
|
static GameConsole()
|
||||||
|
{
|
||||||
|
consoleCommandType = PatchConstants.EftTypes.Single(x => x.GetProperty("Regex") != null && x.GetMethod("TryExecute") != null);
|
||||||
|
consoleCommandConstructor = consoleCommandType.GetConstructor(new[] { typeof(string), typeof(Action<Match>) });
|
||||||
|
consoleCommandsAddMethod = AccessTools.Field(typeof(ConsoleScreen), nameof(ConsoleScreen.Commands)).FieldType.GetMethod("Add", new[] { consoleCommandType });
|
||||||
|
commandsField = AccessTools.Field(typeof(ConsoleScreen), nameof(ConsoleScreen.Commands));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void AddCommand(string regular, Action<Match> onExecute)
|
||||||
|
{
|
||||||
|
var commands = commandsField.GetValue(null);
|
||||||
|
var command = consoleCommandConstructor.Invoke(new object[] { regular, onExecute });
|
||||||
|
consoleCommandsAddMethod.Invoke(commands, new[] { command });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
31
project/SamSWAT.TimeWeatherChanger/Utils/Notifier.cs
Normal file
31
project/SamSWAT.TimeWeatherChanger/Utils/Notifier.cs
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
using Aki.Reflection.Utils;
|
||||||
|
using EFT.Communications;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Reflection;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace SamSWAT.TimeWeatherChanger.Utils
|
||||||
|
{
|
||||||
|
static class Notifier
|
||||||
|
{
|
||||||
|
private static readonly MethodInfo notifierMessageMethod;
|
||||||
|
private static readonly MethodInfo notifierWarningMessageMethod;
|
||||||
|
|
||||||
|
static Notifier()
|
||||||
|
{
|
||||||
|
var notifierType = PatchConstants.EftTypes.Single(x => x.GetMethod("DisplayMessageNotification") != null);
|
||||||
|
notifierMessageMethod = notifierType.GetMethod("DisplayMessageNotification");
|
||||||
|
notifierWarningMessageMethod = notifierType.GetMethod("DisplayWarningNotification");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void DisplayMessageNotification(string message, ENotificationDurationType duration = ENotificationDurationType.Default, ENotificationIconType iconType = ENotificationIconType.Default, Color? textColor = null)
|
||||||
|
{
|
||||||
|
notifierMessageMethod.Invoke(null, new object[] { message, duration, iconType, textColor });
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void DisplayWarningNotification(string message, ENotificationDurationType duration = ENotificationDurationType.Default)
|
||||||
|
{
|
||||||
|
notifierWarningMessageMethod.Invoke(null, new object[] { message, duration });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user