-
Notifications
You must be signed in to change notification settings - Fork 377
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
256 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
.history | ||
/test/ | ||
~*.doc? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,156 @@ | ||
-- 用户配置 | ||
UserConfig = { | ||
-- 基础力度 | ||
power = 5, | ||
-- 启动控制 (scrolllock, capslock, numlock) | ||
startControl = "capslock", | ||
-- 随机偏差范围 (不要设置为0,偏差值越小越容易被检测) | ||
randomDeviation = 1, | ||
-- 屏幕分辨率 | ||
screenResolution = { | ||
width = 2560, | ||
height = 1440 | ||
} | ||
} | ||
|
||
-- 开发时使用的工具 | ||
-- dofile("E:\\Lynch Bel\\github\\Soldier76\\tools\\console.lua") | ||
|
||
-- 运行缓存 | ||
RunningCache = { | ||
-- 偏差像素 (± userConfig.randomDeviation) | ||
deviationPX = 0, | ||
-- 累计偏差像素 | ||
deviationCounterPX = 0, | ||
-- 上一次的 Y 轴位置 | ||
lastY = 0 | ||
} | ||
|
||
-- 是否启动 | ||
function IsStart () | ||
return IsKeyLockOn(UserConfig.startControl) | ||
end | ||
|
||
-- 判断是否按下 | ||
function IsPressed (key) | ||
if type(key) == "number" then | ||
return IsMouseButtonPressed(key) | ||
elseif type(key) == "string" then | ||
return IsModifierPressed(key) | ||
else | ||
return false | ||
end | ||
end | ||
|
||
-- 四舍五入 | ||
function Round (num) return math.floor(num + 0.5) end | ||
|
||
-- 获取随机力度 (px) | ||
function GetRandomPower () | ||
return UserConfig.power + RunningCache.deviationPX + Round(RunningCache.deviationCounterPX / 50) | ||
end | ||
|
||
-- 主体功能 (压枪循环) | ||
function Main (event, arg, family) | ||
if event == "MOUSE_BUTTON_PRESSED" and arg == 1 and family == "mouse" then | ||
-- 启动前先获取一次 Y 轴位置 | ||
local x, y = GetMousePosition() | ||
RunningCache.lastY = y | ||
ClearLog() | ||
|
||
while (IsStart() and IsPressed(1) and IsPressed(3)) do | ||
-- while (IsStart() and IsPressed(1)) do | ||
-- ConsoleLog("-------------------------------") | ||
-- 调整偏差 ± userConfig.randomDeviation (px) | ||
RunningCache.deviationPX = math.max( | ||
-UserConfig.randomDeviation, | ||
math.min( | ||
UserConfig.randomDeviation, | ||
RunningCache.deviationPX + math.random(-1, 1) -- 随机偏差 ±1 | ||
) | ||
) | ||
-- ConsoleLog(table.concat({ "随机偏差: ", RunningCache.deviation, "px" })) | ||
|
||
-- 力度/移动距离 (px) (基础 + 偏差) | ||
local powerPX = GetRandomPower() | ||
-- ConsoleLog(table.concat({ "力度/移动距离: ", power, "px" })) | ||
|
||
-- 移动鼠标 | ||
MoveMouseRelative(0, powerPX) | ||
|
||
Sleep(math.random(15, 17)) | ||
|
||
-- 获取鼠标位置 | ||
local x, y = GetMousePosition() | ||
-- ConsoleLog(table.concat({ "x: ", x, ", y: ", y })) | ||
|
||
-- 实际移动像素 | ||
local movedPX = Round((y - RunningCache.lastY) / 65535 * UserConfig.screenResolution.height + 1) | ||
|
||
-- 偏差像素 | ||
local deviationCounterPX = movedPX - powerPX | ||
-- ConsoleLog({ "偏差像素: ", deviationCounterPX }) | ||
|
||
-- 累计偏差像素 | ||
RunningCache.deviationCounterPX = RunningCache.deviationCounterPX + deviationCounterPX | ||
-- ConsoleLog({ "累计偏差像素:", RunningCache.deviationCounterPX }) | ||
|
||
-- 记录 Y 轴位置 | ||
RunningCache.lastY = y | ||
|
||
-- 预计下一次移动的距离 (px) | ||
local nextUnitDistance = GetRandomPower() | ||
-- ConsoleLog(table.concat({ "预计下一次移动的距离: ", nextUnitDistance, "px" })) | ||
|
||
-- 底部安全距离 | ||
local safeDistance = (nextUnitDistance + UserConfig.randomDeviation) / UserConfig.screenResolution.height * 65535 | ||
-- ConsoleLog(table.concat({ "底部安全距离: ", safeDistance, "px" })) | ||
|
||
-- 当鼠标移到底部,距离底部小于安全距离时,调整到顶部 (小于安全距离会影响下一次计算) | ||
if (y >= 65535 - safeDistance) then | ||
MoveMouseTo(x, 1) | ||
RunningCache.lastY = 1 | ||
end | ||
|
||
-- ClearLog() | ||
-- ConsoleLog(RunningCache) | ||
end | ||
|
||
-- 重置缓存 | ||
RunningCache.deviationPX = 0 | ||
RunningCache.deviationCounterPX = 0 | ||
|
||
-- -- 重置鼠标位置 | ||
-- PressAndReleaseKey('tab') | ||
-- PressAndReleaseKey('tab') | ||
end | ||
end | ||
|
||
-- 入口函数 | ||
function OnEvent (event, arg, family) | ||
-- 与 IsMouseButtonPressed 方法统一 | ||
if arg == 2 then arg = 3 elseif arg == 3 then arg = 2 end | ||
|
||
-- 未启动直接跳过 (安全锁,防止脚本进入死循环后无法退出) | ||
if not IsStart() then return end | ||
|
||
-- 进入压枪循环 | ||
Main(event, arg, family) | ||
|
||
-- 释放所有占用的按键 | ||
if event == "PROFILE_DEACTIVATED" then | ||
EnablePrimaryMouseButtonEvents(false) | ||
ReleaseKey("lshift") | ||
ReleaseKey("lctrl") | ||
ReleaseKey("lalt") | ||
ReleaseKey("rshift") | ||
ReleaseKey("rctrl") | ||
ReleaseKey("ralt") | ||
-- ClearLog() | ||
end | ||
end | ||
|
||
-- 启用鼠标按键 1 事件报告 | ||
EnablePrimaryMouseButtonEvents(true) | ||
-- 设置随机数种子 | ||
math.randomseed(GetRunningTime()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
--[[ | ||
* 打印 table | ||
* @param {any} val 传入值 | ||
* @return {str} 格式化后的文本 | ||
]] | ||
function PrintTable (val) | ||
|
||
local function loop (val, keyType, _indent) | ||
_indent = _indent or 1 | ||
keyType = keyType or "string" | ||
local res = "" | ||
local indentStr = " " -- 缩进空格 | ||
local indent = string.rep(indentStr, _indent) | ||
local end_indent = string.rep(indentStr, _indent - 1) | ||
local putline = function (...) | ||
local arr = { res, ... } | ||
for i = 1, #arr do | ||
if type(arr[i]) ~= "string" then arr[i] = tostring(arr[i]) end | ||
end | ||
res = table.concat(arr) | ||
end | ||
|
||
if type(val) == "table" then | ||
putline("{ ") | ||
|
||
if #val > 0 then | ||
local index = 0 | ||
local block = false | ||
|
||
for i = 1, #val do | ||
local n = val[i] | ||
if type(n) == "table" or type(n) == "function" then | ||
block = true | ||
break | ||
end | ||
end | ||
|
||
if block then | ||
for i = 1, #val do | ||
local n = val[i] | ||
index = index + 1 | ||
if index == 1 then putline("\n") end | ||
putline(indent, loop(n, type(i), _indent + 1), "\n") | ||
if index == #val then putline(end_indent) end | ||
end | ||
else | ||
for i = 1, #val do | ||
local n = val[i] | ||
index = index + 1 | ||
putline(loop(n, type(i), _indent + 1)) | ||
end | ||
end | ||
|
||
else | ||
putline("\n") | ||
for k, v in pairs(val) do | ||
putline(indent, k, " = ", loop(v, type(k), _indent + 1), "\n") | ||
end | ||
putline(end_indent) | ||
end | ||
|
||
putline("}, ") | ||
elseif type(val) == "string" then | ||
val = string.gsub(val, "\a", "\\a") -- 响铃(BEL) | ||
val = string.gsub(val, "\b", "\\b") -- 退格(BS),将当前位置移到前一列 | ||
val = string.gsub(val, "\f", "\\f") -- 换页(FF),将当前位置移到下页开头 | ||
val = string.gsub(val, "\n", "\\n") -- 换行(LF),将当前位置移到下一行开头 | ||
val = string.gsub(val, "\r", "\\r") -- 回车(CR),将当前位置移到本行开头 | ||
val = string.gsub(val, "\t", "\\t") -- 水平指标(HT),(调用下一个TAB位置) | ||
val = string.gsub(val, "\v", "\\v") -- 垂直指标(VT) | ||
putline("\"", val, "\", ") | ||
elseif type(val) == "boolean" then | ||
putline(val and "true, " or "false, ") | ||
elseif type(val) == "function" then | ||
putline(tostring(val), ", ") | ||
elseif type(val) == "nil" then | ||
putline("nil, ") | ||
else | ||
putline(val, ", ") | ||
end | ||
|
||
return res | ||
end | ||
|
||
local res = loop(val) | ||
res = string.gsub(res, ",(%s*})", "%1") | ||
res = string.gsub(res, ",(%s*)$", "%1") | ||
res = string.gsub(res, "{%s+}", "{}") | ||
|
||
return res | ||
end | ||
|
||
function ConsoleLog (...) | ||
local arr = {...} | ||
for i = 1, #arr do OutputLogMessage(PrintTable(arr[i]) .. "\n") end | ||
end |