🚀 Added (New Features)

• Random Offset feature: Applies random X/Y offset values on each set activation (both mouse buttons pressed)
• Each axis gets independent random values within configurable range (e.g., 0.003 and 0.008)
• New random values generated on every activation
• Toggle to enable/disable the feature

🛠️ Fixed (Bugs resolved)
• Replaced jitter system (burst/cooldown) with simpler random offset system

📂 File-Level Changes Summary
• ConfigLoader.cs: Added randomOffsetEnabled, randomOffsetMin, randomOffsetMax settings
• RecoilEngine.cs: Implemented random offset logic with activation detection
• MainWindow.xaml: Replaced Jitter Settings with Random Offset Settings UI
• MainWindow.xaml.cs: Updated LoadSettingsToUI, GenerateConfigContent, ResetSettings_Click
• helper.cs: Added ParseDoubleFromAssignment helper method
This commit is contained in:
TJhost
2026-09-03 16:00:27 -04:00
parent 86c231773d
commit ae3b4164f3
5 changed files with 96 additions and 85 deletions
+26 -38
View File
@@ -14,11 +14,10 @@ namespace Lua
private static extern short GetAsyncKeyState(int vKey);
private static readonly Random _rng = new Random();
private static bool _jitterActive = false;
private static int _jitterStart = 0;
private static int _lastJitterEnd = 0;
private static bool _wasBothDown = false;
private static double _randomOffsetX = 0;
private static double _randomOffsetY = 0;
private static double _remainderX, _remainderY;
private static double _jitterMultiplierX, _jitterMultiplierY;
public static bool CustomModeActive = false;
public static double CustomRecoilX = 0;
@@ -38,18 +37,24 @@ namespace Lua
{
while (!_cancellationSource.Token.IsCancellationRequested)
{
// FIX: Perform key checks once and reuse the results
bool leftDown = IsDown(VK_LBUTTON);
bool rightDown = IsDown(VK_RBUTTON);
if (window.IsRecoilEnabled && leftDown && rightDown)
bool bothDown = leftDown && rightDown;
// Detect new activation (transition from not both down to both down)
if (bothDown && !_wasBothDown)
{
OnSetActivated();
}
_wasBothDown = bothDown;
if (window.IsRecoilEnabled && bothDown)
{
HandleRecoilTick();
}
else
{
_remainderX = _remainderY = 0;
_jitterActive = false;
}
Thread.Sleep(2);
@@ -61,15 +66,23 @@ namespace Lua
}
}
private static void OnSetActivated()
{
if (!ConfigLoader.randomOffsetEnabled) return;
double range = ConfigLoader.randomOffsetMax - ConfigLoader.randomOffsetMin;
if (range <= 0) return;
_randomOffsetX = ConfigLoader.randomOffsetMin + _rng.NextDouble() * range;
_randomOffsetY = ConfigLoader.randomOffsetMin + _rng.NextDouble() * range;
}
private static void HandleRecoilTick()
{
try
{
int now = Environment.TickCount;
if (CustomModeActive)
{
HandleJitter(now);
ApplyRecoil((CustomRecoilX, CustomRecoilY));
return;
}
@@ -78,7 +91,6 @@ namespace Lua
if (!OperatorSets.mergedSets.TryGetValue(setName, out var recoil)) return;
HandleJitter(now);
ApplyRecoil(recoil);
}
catch (Exception ex)
@@ -87,34 +99,10 @@ namespace Lua
}
}
private static void HandleJitter(int now)
{
if (!ConfigLoader.jitterEnabled) return;
if (!_jitterActive && now - _lastJitterEnd >= ConfigLoader.jitterCooldown)
{
_jitterActive = true;
_jitterStart = now;
_jitterMultiplierX = (_rng.NextDouble() - 0.5) * 0.2;
_jitterMultiplierY = (_rng.NextDouble() - 0.5) * 0.2;
}
if (_jitterActive && now - _jitterStart >= ConfigLoader.jitterBurstTime)
{
_jitterActive = false;
_lastJitterEnd = now;
_jitterMultiplierX = _jitterMultiplierY = 0;
}
}
private static void ApplyRecoil((double recoilX, double recoilY) recoil)
{
double moveX = recoil.recoilX;
double moveY = recoil.recoilY;
moveX += recoil.recoilX * _jitterMultiplierX;
moveY += recoil.recoilY * _jitterMultiplierY;
double moveX = recoil.recoilX + _randomOffsetX;
double moveY = recoil.recoilY + _randomOffsetY;
if (ConfigLoader.debitFlag1)
{