Add project files.

This commit is contained in:
JJ
2025-11-22 14:21:26 -05:00
parent bbc518324b
commit 9e9dd5f57c
18 changed files with 1555 additions and 0 deletions
+112
View File
@@ -0,0 +1,112 @@
// ConfigLoader.cs
using System;
using System.Globalization;
using System.IO;
using System.Runtime.Remoting.Messaging;
namespace Lua
{
internal static class ConfigLoader
{
// Basic flags / settings
public static bool debitFlag1 = false;
public static bool betaTest = false;
public static bool ttsEnabled = true;
// Key codes (default values)
public static int nextSetKey = 0x05; // XBUTTON1
public static int prevSetKey = 0x06; // XBUTTON2
public static int refreshKey = 0x50; // P
public static int switchSideKey = 0x4D; // M
// Favorites and user
public static string favoriteAttackers = null;
public static string favoriteDefenders = null;
public static string userName = null;
// Jitter config
public static bool jitterEnabled = false;
public static int jitterBurstTime = 1800; // milliseconds
public static int jitterCooldown = 3000; // milliseconds
// Console text color
public static ConsoleColor textColor = ConsoleColor.Magenta;
/// <summary>
/// Load defaults and then attempt to read init.config from working directory.
/// </summary>
public static void LoadInitConfig()
{
// reset to defaults
debitFlag1 = false;
betaTest = false;
ttsEnabled = true;
favoriteAttackers = null;
favoriteDefenders = null;
userName = null;
jitterEnabled = false;
jitterBurstTime = 1800;
jitterCooldown = 3000;
textColor = ConsoleColor.Magenta;
SetConsoleColor();
if (!File.Exists("init.config")) return;
var lines = Helper.ReadLinesSafe("init.config");
foreach (var raw in lines)
{
if (string.IsNullOrWhiteSpace(raw)) continue;
var line = raw.Trim();
// ignore comments
if (line.StartsWith("--") || line.StartsWith("#")) continue;
if (Helper.ParseBoolFromAssignment(line, "debitFlag1", out var b1))
debitFlag1 = b1;
else if (Helper.ParseBoolFromAssignment(line, "betaTest", out var b2))
betaTest = b2;
else if (Helper.ParseBoolFromAssignment(line, "ttsEnabled", out var b3))
ttsEnabled = b3;
else if (Helper.ParseIntFromAssignment(line, "nextSetKey", out var i1))
nextSetKey = i1;
else if (Helper.ParseIntFromAssignment(line, "prevSetKey", out var i2))
prevSetKey = i2;
else if (Helper.ParseIntFromAssignment(line, "refreshKey", out var i3))
refreshKey = i3;
else if (Helper.ParseIntFromAssignment(line, "switchSideKey", out var i4))
switchSideKey = i4;
else if (Helper.ParseStringFromAssignment(line, "favoriteAttackers", out var s1))
favoriteAttackers = s1;
else if (Helper.ParseStringFromAssignment(line, "favoriteDefenders", out var s2))
favoriteDefenders = s2;
else if (Helper.ParseStringFromAssignment(line, "userName", out var s3))
userName = s3;
else if (Helper.ParseBoolFromAssignment(line, "jitterEnabled", out var jb))
jitterEnabled = jb;
else if (Helper.ParseIntFromAssignment(line, "jitterBurstTime", out var jbT))
jitterBurstTime = jbT;
else if (Helper.ParseIntFromAssignment(line, "jitterCooldown", out var jbC))
jitterCooldown = jbC;
else if (Helper.ParseConsoleColorFromAssignment(line, "textColor", out var col))
textColor = col;
}
// Re-apply color in case it was changed by config
SetConsoleColor();
}
private static void SetConsoleColor()
{
try
{
Console.ForegroundColor = textColor;
}
catch
{
// ignore if console doesn't support color
}
}
}
}