Settings File
This commit is contained in:
parent
4b90db389d
commit
685a3f4f41
@ -1,9 +1,19 @@
|
|||||||
using Microsoft.Win32;
|
using Microsoft.Win32;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
namespace OpenCS2hock;
|
namespace OpenCS2hock;
|
||||||
|
|
||||||
public static class Installer
|
public static class Installer
|
||||||
{
|
{
|
||||||
|
public static Settings GetSettings(string? path = null)
|
||||||
|
{
|
||||||
|
string settingsFilePath = path ?? "config.json";
|
||||||
|
if (!File.Exists(settingsFilePath))
|
||||||
|
File.WriteAllText(settingsFilePath, JsonConvert.SerializeObject(new Settings(), Formatting.Indented));
|
||||||
|
|
||||||
|
return JsonConvert.DeserializeObject<Settings>(File.ReadAllText(settingsFilePath));
|
||||||
|
}
|
||||||
|
|
||||||
public static void InstallGsi()
|
public static void InstallGsi()
|
||||||
{
|
{
|
||||||
string installLocation = Path.Combine(GetInstallDirectory(), "game\\csgo\\cfg\\gamestate_integration_opencs2hock.cfg");
|
string installLocation = Path.Combine(GetInstallDirectory(), "game\\csgo\\cfg\\gamestate_integration_opencs2hock.cfg");
|
||||||
|
@ -4,9 +4,11 @@ public class OpenCS2hock
|
|||||||
{
|
{
|
||||||
private GSIServer GSIServer { get; init; }
|
private GSIServer GSIServer { get; init; }
|
||||||
private List<Shocker> _shockers = new();
|
private List<Shocker> _shockers = new();
|
||||||
|
private readonly Settings _settings;
|
||||||
|
|
||||||
public OpenCS2hock()
|
public OpenCS2hock(string? settingsPath = null)
|
||||||
{
|
{
|
||||||
|
_settings = Installer.GetSettings(settingsPath);
|
||||||
Installer.InstallGsi();
|
Installer.InstallGsi();
|
||||||
this.GSIServer = new GSIServer(3000);
|
this.GSIServer = new GSIServer(3000);
|
||||||
this.GSIServer.OnMessage += OnGSIMessage;
|
this.GSIServer.OnMessage += OnGSIMessage;
|
||||||
|
68
OpenCS2hock/Settings.cs
Normal file
68
OpenCS2hock/Settings.cs
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
namespace OpenCS2hock;
|
||||||
|
|
||||||
|
public struct Settings
|
||||||
|
{
|
||||||
|
public OpenShockSettings OpenShockSettings = new()
|
||||||
|
{
|
||||||
|
Endpoint = "https://api.shocklink.net",
|
||||||
|
ApiKey = "",
|
||||||
|
Shockers = Array.Empty<string>()
|
||||||
|
};
|
||||||
|
|
||||||
|
public short FixedIntensity = 30;
|
||||||
|
public short FixedDuration = 1000;
|
||||||
|
|
||||||
|
public Range IntensityRange = new ()
|
||||||
|
{
|
||||||
|
Min = 0,
|
||||||
|
Max = 100
|
||||||
|
};
|
||||||
|
|
||||||
|
public Range DurationRange = new()
|
||||||
|
{
|
||||||
|
Min = 1000,
|
||||||
|
Max = 2000
|
||||||
|
};
|
||||||
|
|
||||||
|
public Actions Actions = new()
|
||||||
|
{
|
||||||
|
OnKill = "Nothing",
|
||||||
|
OnDeath = "Shock",
|
||||||
|
OnRoundStart = "Vibrate",
|
||||||
|
OnRoundEnd = "Nothing",
|
||||||
|
OnRoundWin = "Beep",
|
||||||
|
OnRoundLoss = "Nothing"
|
||||||
|
};
|
||||||
|
|
||||||
|
public Settings()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
internal Shocker.ControlAction StringToAction(string str)
|
||||||
|
{
|
||||||
|
return str.ToLower() switch
|
||||||
|
{
|
||||||
|
"shock" => Shocker.ControlAction.Shock,
|
||||||
|
"vibrate" => Shocker.ControlAction.Vibrate,
|
||||||
|
"beep" => Shocker.ControlAction.Beep,
|
||||||
|
_ => Shocker.ControlAction.Nothing
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public struct OpenShockSettings
|
||||||
|
{
|
||||||
|
public string Endpoint, ApiKey;
|
||||||
|
public string[] Shockers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public struct Range
|
||||||
|
{
|
||||||
|
public short Min, Max;
|
||||||
|
}
|
||||||
|
|
||||||
|
public struct Actions
|
||||||
|
{
|
||||||
|
public string OnKill, OnDeath, OnRoundStart, OnRoundEnd, OnRoundWin, OnRoundLoss;
|
||||||
|
}
|
@ -7,7 +7,7 @@ public abstract class Shocker
|
|||||||
protected readonly string Endpoint;
|
protected readonly string Endpoint;
|
||||||
protected string[] ShockerIds;
|
protected string[] ShockerIds;
|
||||||
|
|
||||||
public enum ControlAction { Beep, Vibrate, Shock }
|
public enum ControlAction { Beep, Vibrate, Shock, Nothing }
|
||||||
|
|
||||||
public abstract void Control(ControlAction action, byte intensity, short duration, string? shockerId = null);
|
public abstract void Control(ControlAction action, byte intensity, short duration, string? shockerId = null);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user