Settings File

This commit is contained in:
glax 2024-01-14 00:07:55 +01:00
parent 4b90db389d
commit 685a3f4f41
4 changed files with 82 additions and 2 deletions

View File

@ -1,9 +1,19 @@
using Microsoft.Win32;
using Newtonsoft.Json;
namespace OpenCS2hock;
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()
{
string installLocation = Path.Combine(GetInstallDirectory(), "game\\csgo\\cfg\\gamestate_integration_opencs2hock.cfg");

View File

@ -4,9 +4,11 @@ public class OpenCS2hock
{
private GSIServer GSIServer { get; init; }
private List<Shocker> _shockers = new();
private readonly Settings _settings;
public OpenCS2hock()
public OpenCS2hock(string? settingsPath = null)
{
_settings = Installer.GetSettings(settingsPath);
Installer.InstallGsi();
this.GSIServer = new GSIServer(3000);
this.GSIServer.OnMessage += OnGSIMessage;

68
OpenCS2hock/Settings.cs Normal file
View 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;
}

View File

@ -7,7 +7,7 @@ public abstract class Shocker
protected readonly string Endpoint;
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);