Compare commits
No commits in common. "master" and "3.2" have entirely different histories.
@ -1,10 +1,4 @@
|
|||||||
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
|
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
|
||||||
<s:Boolean x:Key="/Default/AddReferences/RecentPaths/=C_003A_005CUsers_005CGlax_005CRiderProjects_005CCShocker_005CCShocker_005Cbin_005CDebug_005Cnet7_002E0_005CCShocker_002Edll/@EntryIndexedValue">True</s:Boolean>
|
<s:Boolean x:Key="/Default/AddReferences/RecentPaths/=C_003A_005CUsers_005CGlax_005CRiderProjects_005CCShocker_005CCShocker_005Cbin_005CDebug_005Cnet7_002E0_005CCShocker_002Edll/@EntryIndexedValue">True</s:Boolean>
|
||||||
<s:String x:Key="/Default/Environment/AssemblyExplorer/XmlDocument/@EntryValue"><AssemblyExplorer>
|
|
||||||
<Assembly Path="C:\Users\Glax\RiderProjects\CShocker\CShocker\bin\Debug\net7.0\CShocker.dll" />
|
|
||||||
</AssemblyExplorer></s:String>
|
|
||||||
<s:String x:Key="/Default/Environment/UnitTesting/UnitTestSessionStore/Sessions/=b6376c03_002D06ba_002D424d_002Db00f_002Dbee38277f47a/@EntryIndexedValue"><SessionState ContinuousTestingMode="0" Name="All tests from Solution" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session">
|
|
||||||
<Solution />
|
|
||||||
</SessionState></s:String>
|
|
||||||
|
|
||||||
<s:Boolean x:Key="/Default/ResxEditorPersonal/Initialized/@EntryValue">True</s:Boolean></wpf:ResourceDictionary>
|
<s:Boolean x:Key="/Default/ResxEditorPersonal/Initialized/@EntryValue">True</s:Boolean></wpf:ResourceDictionary>
|
@ -1,7 +1,4 @@
|
|||||||
using CShocker.Devices.Abstract;
|
using CShocker.Shockers.Abstract;
|
||||||
using CShocker.Devices.Additional;
|
|
||||||
using CShocker.Shockers.Abstract;
|
|
||||||
using CShocker.Shockers.Additional;
|
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
@ -11,25 +8,20 @@ public struct Configuration
|
|||||||
{
|
{
|
||||||
public LogLevel LogLevel = LogLevel.Information;
|
public LogLevel LogLevel = LogLevel.Information;
|
||||||
|
|
||||||
public List<ShockerAction> ShockerActions { get; init; }
|
public List<Shocker> Shockers = new();
|
||||||
|
|
||||||
public List<Api> Apis { get; init; }
|
public List<ShockerAction> ShockerActions = new ();
|
||||||
|
|
||||||
public Dictionary<int, Shocker> Shockers { get; init; }
|
|
||||||
|
|
||||||
public Configuration()
|
public Configuration()
|
||||||
{
|
{
|
||||||
ShockerActions = new ();
|
|
||||||
Apis = new();
|
|
||||||
Shockers = new();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
{
|
{
|
||||||
return $"Loglevel: {Enum.GetName(typeof(LogLevel), LogLevel)}\n" +
|
return $"Loglevel: {Enum.GetName(typeof(LogLevel), LogLevel)}\n" +
|
||||||
$"Apis:\n{string.Join("\n---\n", Apis)}\n" +
|
$"Shockers: {string.Join("\n---", Shockers)}\n" +
|
||||||
$"Shockers:\n{string.Join("\n---\n", Shockers)}\n" +
|
$"Actions: {string.Join("\n---", ShockerActions)}";
|
||||||
$"Actions:\n{string.Join("\n---\n", ShockerActions)}\n";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static Configuration GetConfigurationFromFile(string? path = null, ILogger? logger = null)
|
internal static Configuration GetConfigurationFromFile(string? path = null, ILogger? logger = null)
|
||||||
@ -39,9 +31,11 @@ public struct Configuration
|
|||||||
if (!File.Exists(settingsFilePath))
|
if (!File.Exists(settingsFilePath))
|
||||||
c = Setup.Run().SaveConfiguration();
|
c = Setup.Run().SaveConfiguration();
|
||||||
else
|
else
|
||||||
c = JsonConvert.DeserializeObject<Configuration>(File.ReadAllText(settingsFilePath), new ApiJsonConverter(), new ShockerJsonConverter());
|
c = JsonConvert.DeserializeObject<Configuration>(File.ReadAllText(settingsFilePath), new CShocker.Shockers.ShockerJsonConverter());
|
||||||
if (!c.ConfigurationValid())
|
if (!c.ConfigurationValid())
|
||||||
throw new Exception("Configuration validation failed.");
|
throw new Exception("Configuration validation failed.");
|
||||||
|
foreach (Shocker cShocker in c.Shockers)
|
||||||
|
cShocker.SetLogger(logger);
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
65
OpenCS2hock/Logger.cs
Normal file
65
OpenCS2hock/Logger.cs
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
|
namespace OpenCS2hock;
|
||||||
|
|
||||||
|
public class Logger : ILogger
|
||||||
|
{
|
||||||
|
private LogLevel _enabledLoglevel;
|
||||||
|
private readonly ConsoleColor _defaultForegroundColor = Console.ForegroundColor;
|
||||||
|
private readonly ConsoleColor _defaultBackgroundColor = Console.BackgroundColor;
|
||||||
|
|
||||||
|
public Logger(LogLevel logLevel = LogLevel.Trace)
|
||||||
|
{
|
||||||
|
_enabledLoglevel = logLevel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void UpdateLogLevel(LogLevel logLevel)
|
||||||
|
{
|
||||||
|
this._enabledLoglevel = logLevel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception? exception, Func<TState, Exception?, string> formatter)
|
||||||
|
{
|
||||||
|
if (!IsEnabled(logLevel))
|
||||||
|
return;
|
||||||
|
Console.ForegroundColor = ForegroundColorForLogLevel(logLevel);
|
||||||
|
Console.BackgroundColor = BackgroundColorForLogLevel(logLevel);
|
||||||
|
Console.Write(logLevel.ToString()[..3].ToUpper());
|
||||||
|
Console.ResetColor();
|
||||||
|
// ReSharper disable once LocalizableElement
|
||||||
|
Console.Write($" [{DateTime.UtcNow:HH:mm:ss.fff}] ");
|
||||||
|
Console.WriteLine(formatter.Invoke(state, exception));
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool IsEnabled(LogLevel logLevel)
|
||||||
|
{
|
||||||
|
return logLevel >= _enabledLoglevel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public IDisposable? BeginScope<TState>(TState state) where TState : notnull
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private ConsoleColor ForegroundColorForLogLevel(LogLevel logLevel)
|
||||||
|
{
|
||||||
|
return logLevel switch
|
||||||
|
{
|
||||||
|
LogLevel.Error or LogLevel.Critical => ConsoleColor.Black,
|
||||||
|
LogLevel.Debug => ConsoleColor.Black,
|
||||||
|
LogLevel.Information => ConsoleColor.White,
|
||||||
|
_ => _defaultForegroundColor
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
private ConsoleColor BackgroundColorForLogLevel(LogLevel logLevel)
|
||||||
|
{
|
||||||
|
return logLevel switch
|
||||||
|
{
|
||||||
|
LogLevel.Error or LogLevel.Critical => ConsoleColor.Red,
|
||||||
|
LogLevel.Debug => ConsoleColor.Yellow,
|
||||||
|
LogLevel.Information => ConsoleColor.Black,
|
||||||
|
_ => _defaultBackgroundColor
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
@ -1,6 +1,7 @@
|
|||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using CS2GSI;
|
using CS2GSI;
|
||||||
using GlaxLogger;
|
using CShocker.Ranges;
|
||||||
|
using CShocker.Shockers.Abstract;
|
||||||
using CS2Event = CS2GSI.CS2Event;
|
using CS2Event = CS2GSI.CS2Event;
|
||||||
|
|
||||||
namespace OpenCS2hock;
|
namespace OpenCS2hock;
|
||||||
@ -34,43 +35,75 @@ public class OpenCS2hock
|
|||||||
this._logger?.Log(LogLevel.Information, "Setting up EventHandlers...");
|
this._logger?.Log(LogLevel.Information, "Setting up EventHandlers...");
|
||||||
foreach (ShockerAction shockerAction in this._configuration.ShockerActions)
|
foreach (ShockerAction shockerAction in this._configuration.ShockerActions)
|
||||||
{
|
{
|
||||||
switch (shockerAction.TriggerEvent)
|
foreach (string shockerId in shockerAction.ShockerIds)
|
||||||
|
{
|
||||||
|
Shocker shocker = this._configuration.Shockers.First(s => s.ShockerIds.Contains(shockerId));
|
||||||
|
switch (shockerAction.TriggerEvent)
|
||||||
{
|
{
|
||||||
case CS2Event.OnKill: this._cs2GSI.OnKill += args => EventHandler(args, shockerAction); break;
|
case CS2Event.OnKill: this._cs2GSI.OnKill += args => EventHandler(args, shockerId, shocker, shockerAction); break;
|
||||||
case CS2Event.OnHeadshot: this._cs2GSI.OnHeadshot += args => EventHandler(args, shockerAction); break;
|
case CS2Event.OnHeadshot: this._cs2GSI.OnHeadshot += args => EventHandler(args, shockerId, shocker, shockerAction); break;
|
||||||
case CS2Event.OnDeath: this._cs2GSI.OnDeath += args => EventHandler(args, shockerAction); break;
|
case CS2Event.OnDeath: this._cs2GSI.OnDeath += args => EventHandler(args, shockerId, shocker, shockerAction); break;
|
||||||
case CS2Event.OnFlashed: this._cs2GSI.OnFlashed += args => EventHandler(args, shockerAction); break;
|
case CS2Event.OnFlashed: this._cs2GSI.OnFlashed += args => EventHandler(args, shockerId, shocker, shockerAction); break;
|
||||||
case CS2Event.OnBurning: this._cs2GSI.OnBurning += args => EventHandler(args, shockerAction); break;
|
case CS2Event.OnBurning: this._cs2GSI.OnBurning += args => EventHandler(args, shockerId, shocker, shockerAction); break;
|
||||||
case CS2Event.OnSmoked: this._cs2GSI.OnSmoked += args => EventHandler(args, shockerAction); break;
|
case CS2Event.OnSmoked: this._cs2GSI.OnSmoked += args => EventHandler(args, shockerId, shocker, shockerAction); break;
|
||||||
case CS2Event.OnRoundStart: this._cs2GSI.OnRoundStart += args => EventHandler(args,shockerAction); break;
|
case CS2Event.OnRoundStart: this._cs2GSI.OnRoundStart += args => EventHandler(args, shockerId, shocker, shockerAction); break;
|
||||||
case CS2Event.OnRoundOver: this._cs2GSI.OnRoundOver += args => EventHandler(args, shockerAction); break;
|
case CS2Event.OnRoundOver: this._cs2GSI.OnRoundOver += args => EventHandler(args, shockerId, shocker, shockerAction); break;
|
||||||
case CS2Event.OnRoundWin: this._cs2GSI.OnRoundWin += args => EventHandler(args, shockerAction); break;
|
case CS2Event.OnRoundWin: this._cs2GSI.OnRoundWin += args => EventHandler(args, shockerId, shocker, shockerAction); break;
|
||||||
case CS2Event.OnRoundLoss: this._cs2GSI.OnRoundLoss += args => EventHandler(args, shockerAction); break;
|
case CS2Event.OnRoundLoss: this._cs2GSI.OnRoundLoss += args => EventHandler(args, shockerId, shocker, shockerAction); break;
|
||||||
case CS2Event.OnDamageTaken: this._cs2GSI.OnDamageTaken += args => EventHandler(args, shockerAction); break;
|
case CS2Event.OnDamageTaken: this._cs2GSI.OnDamageTaken += args => EventHandler(args, shockerId, shocker, shockerAction); break;
|
||||||
case CS2Event.OnMatchStart: this._cs2GSI.OnMatchStart += args => EventHandler(args, shockerAction); break;
|
case CS2Event.OnMatchStart: this._cs2GSI.OnMatchStart += args => EventHandler(args, shockerId, shocker, shockerAction); break;
|
||||||
case CS2Event.OnMatchOver: this._cs2GSI.OnMatchOver += args => EventHandler(args, shockerAction); break;
|
case CS2Event.OnMatchOver: this._cs2GSI.OnMatchOver += args => EventHandler(args, shockerId, shocker, shockerAction); break;
|
||||||
case CS2Event.OnMoneyChange: this._cs2GSI.OnMoneyChange += args => EventHandler(args, shockerAction); break;
|
case CS2Event.OnMoneyChange: this._cs2GSI.OnMoneyChange += args => EventHandler(args, shockerId, shocker, shockerAction); break;
|
||||||
case CS2Event.OnHealthChange: this._cs2GSI.OnHealthChange += args => EventHandler(args, shockerAction); break;
|
case CS2Event.OnHealthChange: this._cs2GSI.OnHealthChange += args => EventHandler(args, shockerId, shocker, shockerAction); break;
|
||||||
case CS2Event.OnArmorChange: this._cs2GSI.OnArmorChange += args => EventHandler(args, shockerAction); break;
|
case CS2Event.OnArmorChange: this._cs2GSI.OnArmorChange += args => EventHandler(args, shockerId, shocker, shockerAction); break;
|
||||||
case CS2Event.OnHelmetChange: this._cs2GSI.OnHelmetChange += args => EventHandler(args, shockerAction); break;
|
case CS2Event.OnHelmetChange: this._cs2GSI.OnHelmetChange += args => EventHandler(args, shockerId, shocker, shockerAction); break;
|
||||||
case CS2Event.OnEquipmentValueChange: this._cs2GSI.OnEquipmentValueChange += args => EventHandler(args, shockerAction); break;
|
case CS2Event.OnEquipmentValueChange: this._cs2GSI.OnEquipmentValueChange += args => EventHandler(args, shockerId, shocker, shockerAction); break;
|
||||||
case CS2Event.OnTeamChange: this._cs2GSI.OnTeamChange += args => EventHandler(args, shockerAction); break;
|
case CS2Event.OnTeamChange: this._cs2GSI.OnTeamChange += args => EventHandler(args, shockerId, shocker, shockerAction); break;
|
||||||
case CS2Event.OnPlayerChange: this._cs2GSI.OnPlayerChange += args => EventHandler(args, shockerAction); break;
|
case CS2Event.OnPlayerChange: this._cs2GSI.OnPlayerChange += args => EventHandler(args, shockerId, shocker, shockerAction); break;
|
||||||
case CS2Event.OnHalfTime: this._cs2GSI.OnHalfTime += args => EventHandler(args, shockerAction); break;
|
case CS2Event.OnHalfTime: this._cs2GSI.OnHalfTime += args => EventHandler(args, shockerId, shocker, shockerAction); break;
|
||||||
case CS2Event.OnFreezeTime: this._cs2GSI.OnFreezeTime += args => EventHandler(args, shockerAction); break;
|
case CS2Event.OnFreezeTime: this._cs2GSI.OnFreezeTime += args => EventHandler(args, shockerId, shocker, shockerAction); break;
|
||||||
case CS2Event.OnBombPlanted: this._cs2GSI.OnBombPlanted += args => EventHandler(args, shockerAction); break;
|
case CS2Event.OnBombPlanted: this._cs2GSI.OnBombPlanted += args => EventHandler(args, shockerId, shocker, shockerAction); break;
|
||||||
case CS2Event.OnBombDefused: this._cs2GSI.OnBombDefused += args => EventHandler(args, shockerAction); break;
|
case CS2Event.OnBombDefused: this._cs2GSI.OnBombDefused += args => EventHandler(args, shockerId, shocker, shockerAction); break;
|
||||||
case CS2Event.OnBombExploded: this._cs2GSI.OnBombExploded += args => EventHandler(args, shockerAction); break;
|
case CS2Event.OnBombExploded: this._cs2GSI.OnBombExploded += args => EventHandler(args, shockerId, shocker, shockerAction); break;
|
||||||
case CS2Event.AnyEvent: this._cs2GSI.AnyEvent += args => EventHandler(args, shockerAction); break;
|
case CS2Event.AnyEvent: this._cs2GSI.AnyEvent += args => EventHandler(args, shockerId, shocker, shockerAction); break;
|
||||||
case CS2Event.AnyMessage: this._cs2GSI.AnyMessage += args => EventHandler(args, shockerAction); break;
|
case CS2Event.AnyMessage: this._cs2GSI.AnyMessage += args => EventHandler(args, shockerId, shocker, shockerAction); break;
|
||||||
default: this._logger?.Log(LogLevel.Debug, $"CS2Event {nameof(shockerAction.TriggerEvent)} unknown."); break;
|
default: this._logger?.Log(LogLevel.Debug, $"CS2Event {nameof(shockerAction.TriggerEvent)} unknown."); break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void EventHandler(CS2EventArgs cs2EventArgs, ShockerAction shockerAction)
|
private void EventHandler(CS2EventArgs cs2EventArgs, string shockerId, Shocker shocker, ShockerAction shockerAction)
|
||||||
{
|
{
|
||||||
this._logger?.Log(LogLevel.Information, $"Action {shockerAction}\nEventArgs: {cs2EventArgs}");
|
this._logger?.Log(LogLevel.Information, $"Shocker: {shocker}\nID: {shockerId}\nAction: {shockerAction}\nEventArgs: {cs2EventArgs}");
|
||||||
shockerAction.Execute(_configuration.Shockers, cs2EventArgs);
|
shocker.Control(shockerAction.Action, shockerId,
|
||||||
|
GetIntensity(shockerAction.ValueFromInput, shockerAction.TriggerEvent, cs2EventArgs, shockerId));
|
||||||
|
}
|
||||||
|
|
||||||
|
private int GetIntensity(bool valueFromInput, CS2Event cs2Event, CS2EventArgs eventArgs, string shockerId)
|
||||||
|
{
|
||||||
|
return valueFromInput
|
||||||
|
? IntensityFromCS2Event(cs2Event, eventArgs, shockerId)
|
||||||
|
: this._configuration.Shockers.First(shocker => shocker.ShockerIds.Contains(shockerId))
|
||||||
|
.IntensityRange.GetRandomRangeValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
private int IntensityFromCS2Event(CS2Event cs2Event, CS2EventArgs eventArgs, string shockerId)
|
||||||
|
{
|
||||||
|
IntensityRange configuredRangeForShocker = this._configuration.Shockers
|
||||||
|
.First(shocker => shocker.ShockerIds.Contains(shockerId))
|
||||||
|
.IntensityRange;
|
||||||
|
return cs2Event switch
|
||||||
|
{
|
||||||
|
CS2Event.OnDamageTaken => MapInt(eventArgs.ValueAsOrDefault<int>(), 0, 100, configuredRangeForShocker.Min, configuredRangeForShocker.Max),
|
||||||
|
CS2Event.OnArmorChange => MapInt(eventArgs.ValueAsOrDefault<int>(), 0, 100, configuredRangeForShocker.Min, configuredRangeForShocker.Max),
|
||||||
|
_ => configuredRangeForShocker.GetRandomRangeValue()
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
private int MapInt(int input, int fromLow, int fromHigh, int toLow, int toHigh)
|
||||||
|
{
|
||||||
|
int mappedValue = (input - fromLow) * (toHigh - toLow) / (fromHigh - fromLow) + toLow;
|
||||||
|
return mappedValue;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -11,8 +11,7 @@
|
|||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="CS2GSI" Version="1.0.7" />
|
<PackageReference Include="CS2GSI" Version="1.0.7" />
|
||||||
<PackageReference Include="CShocker" Version="2.3.1" />
|
<PackageReference Include="CShocker" Version="1.3.6" />
|
||||||
<PackageReference Include="GlaxLogger" Version="1.0.6" />
|
|
||||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
using GlaxLogger;
|
using Microsoft.Extensions.Logging;
|
||||||
using Microsoft.Extensions.Logging;
|
|
||||||
|
|
||||||
namespace OpenCS2hock;
|
namespace OpenCS2hock;
|
||||||
|
|
||||||
|
@ -1,12 +1,8 @@
|
|||||||
using System.Runtime.InteropServices;
|
using System.Text.RegularExpressions;
|
||||||
using System.Runtime.Versioning;
|
|
||||||
using System.Text.RegularExpressions;
|
|
||||||
using CShocker.Devices.Abstract;
|
|
||||||
using CShocker.Devices.Additional;
|
|
||||||
using CShocker.Devices.APIs;
|
|
||||||
using CShocker.Ranges;
|
using CShocker.Ranges;
|
||||||
using CShocker.Shockers;
|
using CShocker.Shockers;
|
||||||
using CShocker.Shockers.Abstract;
|
using CShocker.Shockers.Abstract;
|
||||||
|
using CShocker.Shockers.APIS;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using CS2Event = CS2GSI.CS2Event;
|
using CS2Event = CS2GSI.CS2Event;
|
||||||
|
|
||||||
@ -20,13 +16,36 @@ public static class Setup
|
|||||||
Console.Clear();
|
Console.Clear();
|
||||||
Console.WriteLine("Running first-time setup.");
|
Console.WriteLine("Running first-time setup.");
|
||||||
Configuration c = new();
|
Configuration c = new();
|
||||||
|
|
||||||
|
Console.WriteLine("First adding APIs:");
|
||||||
|
Console.WriteLine("Press Enter.");
|
||||||
|
while (Console.ReadKey().Key != ConsoleKey.Enter)
|
||||||
|
{//NYAA
|
||||||
|
}
|
||||||
|
|
||||||
AddApisWorkflow(ref c);
|
bool addShocker = true;
|
||||||
|
while (c.Shockers.Count < 1 || addShocker)
|
||||||
|
{
|
||||||
|
Console.Clear();
|
||||||
|
AddShockerApi(ref c);
|
||||||
|
Console.WriteLine("Add another Shocker-API (Y/N):");
|
||||||
|
addShocker = Console.ReadKey().Key == ConsoleKey.Y;
|
||||||
|
}
|
||||||
|
|
||||||
Console.Clear();
|
Console.Clear();
|
||||||
|
Console.WriteLine("Now adding Actions:");
|
||||||
AddActionsWorkflow(ref c);
|
Console.WriteLine("Press Enter.");
|
||||||
|
while (Console.ReadKey().Key != ConsoleKey.Enter)
|
||||||
|
{//NYAA
|
||||||
|
}
|
||||||
|
bool addAction = true;
|
||||||
|
while (c.ShockerActions.Count < 1 || addAction)
|
||||||
|
{
|
||||||
|
Console.Clear();
|
||||||
|
AddAction(ref c);
|
||||||
|
Console.WriteLine("Add another Action (Y/N):");
|
||||||
|
addAction = Console.ReadKey().Key == ConsoleKey.Y;
|
||||||
|
}
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -36,139 +55,129 @@ public static class Setup
|
|||||||
while (pressedKey is not ConsoleKey.X && pressedKey is not ConsoleKey.Q)
|
while (pressedKey is not ConsoleKey.X && pressedKey is not ConsoleKey.Q)
|
||||||
{
|
{
|
||||||
Console.Clear();
|
Console.Clear();
|
||||||
Console.WriteLine("Config Edit Mode.\n");
|
Console.WriteLine("Config Edit Mode.");
|
||||||
|
Console.WriteLine("What do you want to edit?");
|
||||||
Console.WriteLine("1) LogLevel");
|
Console.WriteLine("1) LogLevel");
|
||||||
Console.WriteLine("2) Add API");
|
Console.WriteLine("2) Shocker-APIs");
|
||||||
Console.WriteLine("3) Refresh Shockers (OpenShock)");
|
Console.WriteLine("3) Event Actions");
|
||||||
Console.WriteLine("4) Add Action");
|
|
||||||
Console.WriteLine("\nq) Quit Edit Mode");
|
Console.WriteLine("\nq) Quit Edit Mode");
|
||||||
pressedKey = Console.ReadKey().Key;
|
pressedKey = Console.ReadKey().Key;
|
||||||
switch (pressedKey)
|
switch (pressedKey)
|
||||||
{
|
{
|
||||||
case ConsoleKey.D1:
|
case ConsoleKey.D1:
|
||||||
|
Console.WriteLine("New LogLevel:");
|
||||||
string[] levels = Enum.GetNames<LogLevel>();
|
string[] levels = Enum.GetNames<LogLevel>();
|
||||||
|
for(int i = 0; i < levels.Length; i++)
|
||||||
|
Console.WriteLine($"{i}) {levels[i]}");
|
||||||
int selected;
|
int selected;
|
||||||
do
|
while (!int.TryParse(Console.ReadKey().KeyChar.ToString(), out selected) || selected < 0 ||
|
||||||
{
|
selected >= levels.Length)
|
||||||
Console.Clear();
|
{//NYAA
|
||||||
Console.WriteLine("New LogLevel:");
|
}
|
||||||
for (int i = 0; i < levels.Length; i++)
|
|
||||||
Console.WriteLine($"{i}) {levels[i]}");
|
|
||||||
} while (!int.TryParse(Console.ReadKey().KeyChar.ToString(), out selected) || selected < 0 || selected >= levels.Length);
|
|
||||||
Console.WriteLine();//NewLine after Input
|
|
||||||
c.LogLevel = Enum.Parse<LogLevel>(levels[selected]);
|
c.LogLevel = Enum.Parse<LogLevel>(levels[selected]);
|
||||||
break;
|
break;
|
||||||
case ConsoleKey.D2:
|
case ConsoleKey.D2:
|
||||||
AddApisWorkflow(ref c);
|
bool addShocker = true;
|
||||||
|
while (c.Shockers.Count < 1 || addShocker)
|
||||||
|
{
|
||||||
|
Console.Clear();
|
||||||
|
AddShockerApi(ref c);
|
||||||
|
Console.WriteLine("Add another Shocker-API (Y/N):");
|
||||||
|
addShocker = Console.ReadKey().Key == ConsoleKey.Y;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case ConsoleKey.D3:
|
case ConsoleKey.D3:
|
||||||
// ReSharper disable once PossibleInvalidCastExceptionInForeachLoop Only returning OpenShockApi Objects
|
bool addAction = true;
|
||||||
foreach (OpenShockApi api in c.Apis.Where(a => a is OpenShockApi))
|
while (c.ShockerActions.Count < 1 || addAction)
|
||||||
{
|
{
|
||||||
Configuration configuration = c;
|
Console.Clear();
|
||||||
foreach(OpenShockShocker s in api.GetShockers().Where(s => !configuration.Shockers.ContainsValue(s)))
|
AddAction(ref c);
|
||||||
c.Shockers.Add(c.Shockers.Any() ? c.Shockers.Keys.Max() + 1 : 0, s);
|
Console.WriteLine("Add another Action (Y/N):");
|
||||||
|
addAction = Console.ReadKey().Key == ConsoleKey.Y;
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
|
||||||
case ConsoleKey.D4:
|
|
||||||
AddActionsWorkflow(ref c);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
c.SaveConfiguration();
|
c.SaveConfiguration();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void AddApisWorkflow(ref Configuration c)
|
|
||||||
{
|
|
||||||
Console.WriteLine("Adding APIs.");
|
|
||||||
bool addApis = true;
|
|
||||||
while (c.Apis.Count < 1 || addApis)
|
|
||||||
{
|
|
||||||
Console.Clear();
|
|
||||||
AddShockerApi(ref c);
|
|
||||||
Console.WriteLine("Add another Api (Y/N):");
|
|
||||||
addApis = Console.ReadKey().Key == ConsoleKey.Y;
|
|
||||||
Console.WriteLine();//NewLine after Input
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void AddActionsWorkflow(ref Configuration c)
|
|
||||||
{
|
|
||||||
Console.WriteLine("Adding Actions.");
|
|
||||||
bool addAction = true;
|
|
||||||
while (c.ShockerActions.Count < 1 || addAction)
|
|
||||||
{
|
|
||||||
Console.Clear();
|
|
||||||
AddAction(ref c);
|
|
||||||
Console.WriteLine("Add another Action (Y/N):");
|
|
||||||
addAction = Console.ReadKey().Key == ConsoleKey.Y;
|
|
||||||
Console.WriteLine();//NewLine after Input
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void AddShockerApi(ref Configuration c)
|
private static void AddShockerApi(ref Configuration c)
|
||||||
{
|
{
|
||||||
Console.WriteLine("Select API:");
|
Console.WriteLine("Select API:");
|
||||||
Console.WriteLine("1) OpenShock (HTTP)");
|
Console.WriteLine("1) OpenShock (HTTP)");
|
||||||
Console.WriteLine("2) OpenShock (Serial Windows Only)");
|
Console.WriteLine("2) OpenShock (Serial)");
|
||||||
Console.WriteLine("3) PiShock (HTTP) NotImplemented"); //TODO
|
Console.WriteLine("3) PiShock (HTTP)");
|
||||||
Console.WriteLine("4) PiShock (Serial Windows Only) NotImplemented"); //TODO
|
Console.WriteLine("4) PiShock (Serial) NotImplemented"); //TODO
|
||||||
char selectedChar = Console.ReadKey().KeyChar;
|
string? selectedChar = Console.ReadLine();
|
||||||
int selected;
|
int selected;
|
||||||
while (!int.TryParse(selectedChar.ToString(), out selected) || selected < 1 || selected > 4)
|
while (!int.TryParse(selectedChar, out selected) || selected < 1 || selected > 3)
|
||||||
selectedChar = Console.ReadKey().KeyChar;
|
selectedChar = Console.ReadLine();
|
||||||
Console.WriteLine();//NewLine after Input
|
|
||||||
|
|
||||||
string apiUri, apiKey;
|
string apiUri, apiKey;
|
||||||
Api? api = null;
|
Shocker newShocker;
|
||||||
|
DurationRange durationRange;
|
||||||
|
IntensityRange intensityRange;
|
||||||
|
List<string> shockerIds = new();
|
||||||
switch (selected)
|
switch (selected)
|
||||||
{
|
{
|
||||||
case 1: //OpenShock (HTTP)
|
case 1: //OpenShock (HTTP)
|
||||||
apiUri = QueryString("OpenShock API-Endpoint (https://api.shocklink.net):", "https://api.shocklink.net");
|
apiUri = QueryString("OpenShock API-Endpoint (https://api.shocklink.net):", "https://api.shocklink.net");
|
||||||
apiKey = QueryString("OpenShock API-Key:","");
|
apiKey = QueryString("OpenShock API-Key:","");
|
||||||
api = new OpenShockHttp(apiKey, apiUri);
|
intensityRange = GetIntensityRange();
|
||||||
foreach(OpenShockShocker shocker in ((OpenShockHttp)api).GetShockers())
|
durationRange = GetDurationRange();
|
||||||
c.Shockers.Add(c.Shockers.Any() ? c.Shockers.Keys.Max() + 1 : 0, shocker);
|
newShocker = new OpenShockHttp(shockerIds, intensityRange, durationRange, apiKey, apiUri);
|
||||||
goto default;
|
newShocker.ShockerIds.AddRange(((OpenShockHttp)newShocker).GetShockers());
|
||||||
|
break;
|
||||||
case 2: //OpenShock (Serial)
|
case 2: //OpenShock (Serial)
|
||||||
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
|
||||||
throw new PlatformNotSupportedException("Serial is only supported on Windows.");
|
|
||||||
apiUri = QueryString("OpenShock API-Endpoint (https://api.shocklink.net):", "https://api.shocklink.net");
|
apiUri = QueryString("OpenShock API-Endpoint (https://api.shocklink.net):", "https://api.shocklink.net");
|
||||||
apiKey = QueryString("OpenShock API-Key:","");
|
apiKey = QueryString("OpenShock API-Key:","");
|
||||||
SerialPortInfo serialPort = SelectSerialPort();
|
intensityRange = GetIntensityRange();
|
||||||
api = new OpenShockSerial(serialPort, apiKey, apiUri);
|
durationRange = GetDurationRange();
|
||||||
foreach (OpenShockShocker shocker in ((OpenShockSerial)api).GetShockers())
|
SerialShocker.SerialPortInfo serialPort = SelectSerialPort();
|
||||||
c.Shockers.Add(c.Shockers.Any() ? c.Shockers.Keys.Max() + 1 : 0, shocker);
|
newShocker = new OpenShockSerial(new Dictionary<string, OpenShockSerial.ShockerModel>(), intensityRange,
|
||||||
goto default;
|
durationRange, serialPort);
|
||||||
case 3: //PiShock (HTTP)
|
foreach (KeyValuePair<string, OpenShockSerial.ShockerModel> kv in ((OpenShockSerial)newShocker)
|
||||||
goto default;
|
.GetShockers(apiUri, apiKey))
|
||||||
case 4: //PiShock (Serial)
|
{
|
||||||
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
newShocker.ShockerIds.Add(kv.Key);
|
||||||
throw new PlatformNotSupportedException("Serial is only supported on Windows.");
|
((OpenShockSerial)newShocker).Model.Add(kv.Key, kv.Value);
|
||||||
goto default;
|
}
|
||||||
default:
|
|
||||||
if (api is null)
|
|
||||||
throw new NotImplementedException();
|
|
||||||
c.Apis.Add(api);
|
|
||||||
break;
|
break;
|
||||||
|
case 3: //PiShock (HTTP)
|
||||||
|
apiUri = QueryString("PiShock API-Endpoint (https://do.pishock.com/api/apioperate):", "https://do.pishock.com/api/apioperate");
|
||||||
|
apiKey = QueryString("PiShock API-Key:","");
|
||||||
|
string username = QueryString("Username:","");
|
||||||
|
string shareCode = QueryString("Sharecode:","");
|
||||||
|
Console.WriteLine("Shocker IDs associated with this API:");
|
||||||
|
shockerIds = AddShockerIds();
|
||||||
|
intensityRange = GetIntensityRange();
|
||||||
|
durationRange = GetDurationRange();
|
||||||
|
|
||||||
|
newShocker = new PiShockHttp(shockerIds, intensityRange, durationRange, apiKey, username, shareCode, apiUri);
|
||||||
|
break;
|
||||||
|
// ReSharper disable thrice RedundantCaseLabel
|
||||||
|
case 4: //PiShock (Serial)
|
||||||
|
default:
|
||||||
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
c.Shockers.Add(newShocker);
|
||||||
}
|
}
|
||||||
|
|
||||||
[SupportedOSPlatform("windows")]
|
private static SerialShocker.SerialPortInfo SelectSerialPort()
|
||||||
private static SerialPortInfo SelectSerialPort()
|
|
||||||
{
|
{
|
||||||
List<SerialPortInfo> serialPorts = SerialHelper.GetSerialPorts();
|
List<SerialShocker.SerialPortInfo> serialPorts = SerialShocker.GetSerialPorts();
|
||||||
|
|
||||||
|
for(int i = 0; i < serialPorts.Count; i++)
|
||||||
|
Console.WriteLine($"{i}) {serialPorts[i]}");
|
||||||
|
|
||||||
int selectedPort;
|
Console.WriteLine($"Select Serial Port [0-{serialPorts.Count-1}]:");
|
||||||
do
|
string? selectedPortStr = Console.ReadLine();
|
||||||
|
int selectedPort = -1;
|
||||||
|
while (!int.TryParse(selectedPortStr, out selectedPort) || selectedPort < 0 || selectedPort > serialPorts.Count - 1)
|
||||||
{
|
{
|
||||||
Console.Clear();
|
|
||||||
for(int i = 0; i < serialPorts.Count; i++)
|
|
||||||
Console.WriteLine($"{i}) {serialPorts[i]}");
|
|
||||||
Console.WriteLine($"Select Serial Port [0-{serialPorts.Count-1}]:");
|
Console.WriteLine($"Select Serial Port [0-{serialPorts.Count-1}]:");
|
||||||
} while (!int.TryParse(Console.ReadLine(), out selectedPort) || selectedPort < 0 || selectedPort >= serialPorts.Count);
|
selectedPortStr = Console.ReadLine();
|
||||||
Console.WriteLine();//NewLine after Input
|
}
|
||||||
|
|
||||||
return serialPorts[selectedPort];
|
return serialPorts[selectedPort];
|
||||||
}
|
}
|
||||||
@ -176,82 +185,21 @@ public static class Setup
|
|||||||
private static void AddAction(ref Configuration c)
|
private static void AddAction(ref Configuration c)
|
||||||
{
|
{
|
||||||
CS2Event triggerEvent = GetTrigger();
|
CS2Event triggerEvent = GetTrigger();
|
||||||
int shockerId = GetShockerId(c.Shockers);
|
Console.WriteLine("Shocker IDs to trigger when Event occurs:");
|
||||||
|
List<string> shockerIds = GetShockerIds(c.Shockers);
|
||||||
ControlAction action = GetControlAction();
|
ControlAction action = GetControlAction();
|
||||||
bool useEventArgsValue = QueryBool("Try using EventArgs to control Intensity (within set limits)?", false);
|
bool useEventArgsValue = QueryBool("Try using EventArgs to control Intensity (within set limits)?", "false");
|
||||||
IntegerRange intensityRange = GetIntegerRange(0, 100, "%");
|
|
||||||
IntegerRange durationRange = GetIntegerRange(0, 30000, "ms");
|
|
||||||
|
|
||||||
c.ShockerActions.Add(new(triggerEvent, shockerId, action, useEventArgsValue, intensityRange, durationRange));
|
c.ShockerActions.Add(new ShockerAction(triggerEvent, shockerIds, action, useEventArgsValue));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int GetShockerId(Dictionary<int, Shocker> shockersDict)
|
private static bool QueryBool(string queryString, string defaultResult)
|
||||||
{
|
{
|
||||||
List<Shocker> shockers = shockersDict.Values.ToList();
|
string value = QueryString(queryString, defaultResult);
|
||||||
int selectedShockerIndex;
|
bool ret;
|
||||||
do
|
while (bool.TryParse(value, out ret))
|
||||||
{
|
value = QueryString(queryString, defaultResult);
|
||||||
Console.Clear();
|
return ret;
|
||||||
Console.WriteLine("Select Shocker:");
|
|
||||||
for (int i = 0; i < shockers.Count; i++)
|
|
||||||
Console.WriteLine($"{i}) {shockers[i]}");
|
|
||||||
} while (!int.TryParse(Console.ReadLine(), out selectedShockerIndex) || selectedShockerIndex < 0 || selectedShockerIndex > shockersDict.Count);
|
|
||||||
Console.WriteLine();//NewLine after Input
|
|
||||||
|
|
||||||
Shocker shocker = shockers[selectedShockerIndex];
|
|
||||||
|
|
||||||
return shockersDict.First(s => s.Value == shocker).Key;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static IntegerRange GetIntegerRange(int min, int max, string? unit = null)
|
|
||||||
{
|
|
||||||
Regex rangeRex = new (@"([0-9]{1,5})\-([0-9]{1,5})");
|
|
||||||
|
|
||||||
string intensityRangeStr;
|
|
||||||
do
|
|
||||||
{
|
|
||||||
intensityRangeStr = QueryString($"Range ({min}-{max}) {(unit is null ? "" : $"in {unit}")}:", "0-100");
|
|
||||||
} while (!rangeRex.IsMatch(intensityRangeStr));
|
|
||||||
return new IntegerRange(short.Parse(rangeRex.Match(intensityRangeStr).Groups[1].Value), short.Parse(rangeRex.Match(intensityRangeStr).Groups[2].Value));
|
|
||||||
}
|
|
||||||
|
|
||||||
private static CS2Event GetTrigger()
|
|
||||||
{
|
|
||||||
string[] eventNames = Enum.GetNames(typeof(CS2Event));
|
|
||||||
|
|
||||||
int selectedIndex;
|
|
||||||
do
|
|
||||||
{
|
|
||||||
Console.Clear();
|
|
||||||
Console.WriteLine("Select CS2 Trigger-Event:");
|
|
||||||
for (int i = 0; i < eventNames.Length; i++)
|
|
||||||
Console.WriteLine($"{i}) {eventNames[i]}");
|
|
||||||
} while (!int.TryParse(Console.ReadLine(), out selectedIndex) || selectedIndex < 0 || selectedIndex >= eventNames.Length);
|
|
||||||
|
|
||||||
return Enum.Parse<CS2Event>(eventNames[selectedIndex]);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static ControlAction GetControlAction()
|
|
||||||
{
|
|
||||||
string[] actionNames = Enum.GetNames(typeof(ControlAction));
|
|
||||||
int selectedIndex;
|
|
||||||
do
|
|
||||||
{
|
|
||||||
Console.Clear();
|
|
||||||
Console.WriteLine("Select Action:");
|
|
||||||
for (int i = 0; i < actionNames.Length; i++)
|
|
||||||
Console.WriteLine($"{i}) {actionNames[i]}");
|
|
||||||
} while (!int.TryParse(Console.ReadLine(), out selectedIndex) || selectedIndex < 0 || selectedIndex >= actionNames.Length);
|
|
||||||
|
|
||||||
return Enum.Parse<ControlAction>(actionNames[selectedIndex]);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static bool QueryBool(string queryString, bool defaultResult)
|
|
||||||
{
|
|
||||||
Console.WriteLine(queryString);
|
|
||||||
char userInput = Console.ReadKey().KeyChar;
|
|
||||||
Console.WriteLine();//NewLine after Input
|
|
||||||
return bool.TryParse(userInput.ToString(), out bool ret) ? ret : defaultResult;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static string QueryString(string queryString, string defaultResult)
|
private static string QueryString(string queryString, string defaultResult)
|
||||||
@ -260,4 +208,102 @@ public static class Setup
|
|||||||
string? userInput = Console.ReadLine();
|
string? userInput = Console.ReadLine();
|
||||||
return userInput?.Length > 0 ? userInput : defaultResult;
|
return userInput?.Length > 0 ? userInput : defaultResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static IntensityRange GetIntensityRange()
|
||||||
|
{
|
||||||
|
Regex intensityRangeRex = new (@"([0-9]{1,3})\-(1?[0-9]{1,2})");
|
||||||
|
string intensityRangeStr = "";
|
||||||
|
while(!intensityRangeRex.IsMatch(intensityRangeStr))
|
||||||
|
intensityRangeStr = QueryString("Intensity Range (0-100) in %:", "0-100");
|
||||||
|
short min = short.Parse(intensityRangeRex.Match(intensityRangeStr).Groups[1].Value);
|
||||||
|
short max = short.Parse(intensityRangeRex.Match(intensityRangeStr).Groups[2].Value);
|
||||||
|
return new IntensityRange(min, max);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static DurationRange GetDurationRange()
|
||||||
|
{
|
||||||
|
Regex intensityRangeRex = new (@"([0-9]{1,4})\-([0-9]{1,5})");
|
||||||
|
string intensityRangeStr = "";
|
||||||
|
while(!intensityRangeRex.IsMatch(intensityRangeStr))
|
||||||
|
intensityRangeStr = QueryString("Duration Range (500-30000) in ms:", "500-30000");
|
||||||
|
short min = short.Parse(intensityRangeRex.Match(intensityRangeStr).Groups[1].Value);
|
||||||
|
short max = short.Parse(intensityRangeRex.Match(intensityRangeStr).Groups[2].Value);
|
||||||
|
return new DurationRange(min, max);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static List<string> AddShockerIds()
|
||||||
|
{
|
||||||
|
List<string> ids = new();
|
||||||
|
bool addAnother = true;
|
||||||
|
while (ids.Count < 1 || addAnother)
|
||||||
|
{
|
||||||
|
string id = QueryString("Shocker ID:", "");
|
||||||
|
while (id.Length < 1)
|
||||||
|
id = QueryString("Shocker ID:", "");
|
||||||
|
|
||||||
|
ids.Add(id);
|
||||||
|
|
||||||
|
Console.WriteLine("Add another ID? (Y/N):");
|
||||||
|
addAnother = Console.ReadKey().Key == ConsoleKey.Y;
|
||||||
|
}
|
||||||
|
return ids;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static List<string> GetShockerIds(List<Shocker> shockers)
|
||||||
|
{
|
||||||
|
List<string> ids = new();
|
||||||
|
bool addAnother = true;
|
||||||
|
while (ids.Count < 1 || addAnother)
|
||||||
|
{
|
||||||
|
Console.WriteLine("Select Shocker API:");
|
||||||
|
for(int i = 0; i < shockers.Count; i++)
|
||||||
|
Console.WriteLine($"{i}) {shockers[i]}");
|
||||||
|
|
||||||
|
int selectedShocker;
|
||||||
|
while (!int.TryParse(Console.ReadLine(), out selectedShocker) || selectedShocker < 0 || selectedShocker >= shockers.Count)
|
||||||
|
Console.WriteLine("Select Shocker API:");
|
||||||
|
|
||||||
|
Console.WriteLine("Select Shocker:");
|
||||||
|
for (int i = 0; i < shockers[selectedShocker].ShockerIds.Count; i++)
|
||||||
|
Console.WriteLine($"{i}) {shockers[selectedShocker].ShockerIds[i]}");
|
||||||
|
|
||||||
|
int selectedIndex;
|
||||||
|
while (!int.TryParse(Console.ReadLine(), out selectedIndex) || selectedIndex < 0 || selectedIndex >= shockers[selectedShocker].ShockerIds.Count)
|
||||||
|
Console.WriteLine("Select Shocker:");
|
||||||
|
|
||||||
|
ids.Add(shockers[selectedShocker].ShockerIds[selectedIndex]);
|
||||||
|
|
||||||
|
Console.WriteLine("Add another ID? (Y/N):");
|
||||||
|
addAnother = Console.ReadKey().Key == ConsoleKey.Y;
|
||||||
|
}
|
||||||
|
return ids;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static CS2Event GetTrigger()
|
||||||
|
{
|
||||||
|
string[] names = Enum.GetNames(typeof(CS2Event));
|
||||||
|
Console.WriteLine("Select CS2 Trigger-Event:");
|
||||||
|
for (int i = 0; i < names.Length; i++)
|
||||||
|
Console.WriteLine($"{i}) {names[i]}");
|
||||||
|
|
||||||
|
int selectedIndex;
|
||||||
|
while (!int.TryParse(Console.ReadLine(), out selectedIndex))
|
||||||
|
Console.WriteLine("Select CS2 Trigger-Event:");
|
||||||
|
|
||||||
|
return Enum.Parse<CS2Event>(names[selectedIndex]);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static ControlAction GetControlAction()
|
||||||
|
{
|
||||||
|
string[] names = Enum.GetNames(typeof(ControlAction));
|
||||||
|
Console.WriteLine("Select Action:");
|
||||||
|
for (int i = 0; i < names.Length; i++)
|
||||||
|
Console.WriteLine($"{i}) {names[i]}");
|
||||||
|
|
||||||
|
int selectedIndex;
|
||||||
|
while (!int.TryParse(Console.ReadLine(), out selectedIndex))
|
||||||
|
Console.WriteLine("Select Action:");
|
||||||
|
|
||||||
|
return Enum.Parse<ControlAction>(names[selectedIndex]);
|
||||||
|
}
|
||||||
}
|
}
|
@ -1,7 +1,5 @@
|
|||||||
using CS2GSI;
|
using CS2GSI;
|
||||||
using CShocker.Devices.Additional;
|
using CShocker.Shockers;
|
||||||
using CShocker.Ranges;
|
|
||||||
using CShocker.Shockers.Abstract;
|
|
||||||
|
|
||||||
namespace OpenCS2hock;
|
namespace OpenCS2hock;
|
||||||
|
|
||||||
@ -9,55 +7,22 @@ public struct ShockerAction
|
|||||||
{
|
{
|
||||||
public CS2Event TriggerEvent;
|
public CS2Event TriggerEvent;
|
||||||
// ReSharper disable thrice FieldCanBeMadeReadOnly.Global JsonDeserializer will throw a fit
|
// ReSharper disable thrice FieldCanBeMadeReadOnly.Global JsonDeserializer will throw a fit
|
||||||
public int ShockerId;
|
public List<string> ShockerIds;
|
||||||
public ControlAction Action;
|
public ControlAction Action;
|
||||||
public bool ValueFromInput;
|
public bool ValueFromInput;
|
||||||
public IntegerRange IntensityRange, DurationRange;
|
|
||||||
|
|
||||||
public ShockerAction(CS2Event trigger, int shockerId, ControlAction action, bool valueFromInput, IntegerRange intensityRange, IntegerRange durationRange)
|
public ShockerAction(CS2Event trigger, List<string> shockerIds, ControlAction action, bool valueFromInput = false)
|
||||||
{
|
{
|
||||||
this.TriggerEvent = trigger;
|
this.TriggerEvent = trigger;
|
||||||
this.ShockerId = shockerId;
|
this.ShockerIds = shockerIds;
|
||||||
this.Action = action;
|
this.Action = action;
|
||||||
this.ValueFromInput = valueFromInput;
|
this.ValueFromInput = valueFromInput;
|
||||||
this.IntensityRange = intensityRange;
|
|
||||||
this.DurationRange = durationRange;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Execute(Dictionary<int, Shocker> shockers, CS2EventArgs cs2EventArgs)
|
|
||||||
{
|
|
||||||
if (!shockers.ContainsKey(ShockerId))
|
|
||||||
return;
|
|
||||||
int intensity = ValueFromInput ? IntensityFromCS2Event(cs2EventArgs) : RandomValueFromRange(IntensityRange);
|
|
||||||
int duration = RandomValueFromRange(DurationRange);
|
|
||||||
shockers[ShockerId].Control(Action, intensity, duration);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static int RandomValueFromRange(IntegerRange range)
|
|
||||||
{
|
|
||||||
return Random.Shared.Next(range.Min, range.Max);
|
|
||||||
}
|
|
||||||
|
|
||||||
private int IntensityFromCS2Event(CS2EventArgs cs2EventArgs)
|
|
||||||
{
|
|
||||||
return TriggerEvent switch
|
|
||||||
{
|
|
||||||
CS2Event.OnDamageTaken => MapInt(cs2EventArgs.ValueAsOrDefault<int>(), 0, 100, IntensityRange.Min, IntensityRange.Max),
|
|
||||||
CS2Event.OnArmorChange => MapInt(cs2EventArgs.ValueAsOrDefault<int>(), 0, 100, IntensityRange.Min, IntensityRange.Max),
|
|
||||||
_ => RandomValueFromRange(IntensityRange)
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
private int MapInt(int input, int fromLow, int fromHigh, int toLow, int toHigh)
|
|
||||||
{
|
|
||||||
int mappedValue = (input - fromLow) * (toHigh - toLow) / (fromHigh - fromLow) + toLow;
|
|
||||||
return mappedValue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
{
|
{
|
||||||
return $"Trigger Event: {Enum.GetName(typeof(CS2Event), this.TriggerEvent)}\n" +
|
return $"Trigger Event: {Enum.GetName(typeof(CS2Event), this.TriggerEvent)}\n" +
|
||||||
$"ShockerId: {ShockerId}\n" +
|
$"ShockerIds: {string.Join(", ", ShockerIds)}\n" +
|
||||||
$"Action: {Enum.GetName(typeof(ControlAction), this.Action)}\n" +
|
$"Action: {Enum.GetName(typeof(ControlAction), this.Action)}\n" +
|
||||||
$"ValueFromInput: {ValueFromInput}";
|
$"ValueFromInput: {ValueFromInput}";
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user