超级玩家
 
- 贡献度
- 63
- 金元
- 3698
- 积分
- 622
- 精华
- 0
- 注册时间
- 2022-1-11
|
本帖最后由 光烟雾 于 2025-12-29 16:42 编辑
-- 可以收动执行,工具放到菜单栏
-- 保存为lua文件如 batchoffset.lua,放到CE安装目录/autorun/ 文件夹下可实现菜单自动加载
-- 指针偏移批量修改工具
-- 适用于Cheat Engine Lua脚本
-- 定义创建工具窗口的函数
local function createPointerOffsetTool()
local f = createForm(true)
f.Caption = '指针偏移批量修改工具'
f.Width = 500 -- 增加宽度以适应新控件
f.Height = 250 -- 增加高度
f.Position = poDesktopCenter -- 窗口居中
-- 创建标签
local lblLayer = createLabel(f)
lblLayer.Caption = '指针层数:'
lblLayer.Left = 30
lblLayer.Top = 40
lblLayer.Font.Size = 10
local lblOperation = createLabel(f)
lblOperation.Caption = '操作类型:'
lblOperation.Left = 30
lblOperation.Top = 85
lblOperation.Font.Size = 10
local lblValue = createLabel(f)
lblValue.Caption = '修改值:'
lblValue.Left = 30
lblValue.Top = 130
lblValue.Font.Size = 10
-- 创建输入框
local edtLayer = createEdit(f)
edtLayer.Left = 180
edtLayer.Top = 35
edtLayer.Width = 200
edtLayer.Height = 30
edtLayer.Text = '1'
edtLayer.Font.Size = 10
-- 创建操作类型下拉框
local cmbOperation = createComboBox(f)
cmbOperation.Left = 180
cmbOperation.Top = 80
cmbOperation.Width = 200
cmbOperation.Height = 30
cmbOperation.Font.Size = 10
cmbOperation.Items.add('等于')
cmbOperation.Items.add('加')
cmbOperation.Items.add('减')
cmbOperation.ItemIndex = 0 -- 默认选择"等于"
local edtValue = createEdit(f)
edtValue.Left = 180
edtValue.Top = 125
edtValue.Width = 200
edtValue.Height = 30
edtValue.Text = '0'
edtValue.Font.Size = 10
-- 创建按钮
local btnApply = createButton(f)
btnApply.Caption = '应用修改'
btnApply.Left = 180
btnApply.Top = 170
btnApply.Width = 100
btnApply.Height = 35
btnApply.Font.Size = 10
-- 十六进制字符串转数字
local function hexToNumber(hexStr)
-- 移除空格
hexStr = string.gsub(hexStr, " ", "")
-- 如果字符串为空,返回0
if hexStr == "" then
return 0
end
-- 转换为数字,基数为16(十六进制)
local num = tonumber(hexStr, 16)
return num or 0 -- 如果转换失败,返回0
end
-- 应用修改的函数
local function applyChanges()
local list = getAddressList()
if list == nil or list.Count == 0 then
showMessage('地址列表为空!')
return
end
-- 获取输入的层数值(从1开始)
local layerInput = tonumber(edtLayer.Text)
if layerInput == nil or layerInput < 1 then
showMessage('层数必须为大于0的数字!')
return
end
-- 转换为程序内部使用的索引(从0开始)
local layerIndex = layerInput - 1
-- 获取操作类型
local operation = cmbOperation.Text
-- 获取输入的修改值
local changeValue = hexToNumber(edtValue.Text)
-- 记录修改的数量
local modifiedCount = 0
-- 遍历地址列表
for i = 0, list.Count - 1 do
local rec = list
-- 只修改选中的地址
if rec.Selected then
-- 检查指针层数是否足够
if rec.OffsetCount > layerIndex then
-- 获取当前偏移值
local currentOffset = rec.Offset[layerIndex]
-- 根据操作类型计算新的偏移值
local newOffset = currentOffset
if operation == '等于' then
newOffset = changeValue
elseif operation == '加' then
newOffset = currentOffset + changeValue
elseif operation == '减' then
newOffset = currentOffset - changeValue
end
-- 修改指定层的偏移值
rec.Offset[layerIndex] = newOffset
modifiedCount = modifiedCount + 1
end
end
end
-- 显示结果
if modifiedCount > 0 then
showMessage(string.format('成功修改了 %d 个选中地址第 %d 层的偏移值!\n操作类型:%s,修改值:%X',
modifiedCount, layerInput, operation, changeValue))
else
showMessage('没有选中任何地址,或选中的地址层数不足!')
end
end
-- 按钮点击事件
btnApply.OnClick = applyChanges
-- 输入框验证
edtLayer.OnChange = function(sender)
local text = sender.Text
-- 允许输入正整数,不允许0或负数
if not string.match(text, "^%d*$") then
sender.Text = sender.OldText or "1"
else
-- 如果是空字符串,则不允许,设置为1
if text == "" then
sender.Text = "1"
else
-- 检查是否大于0
local num = tonumber(text)
if num and num <= 0 then
sender.Text = "1"
else
sender.OldText = text
end
end
end
end
edtValue.OnChange = function(sender)
local text = sender.Text
-- 只允许十六进制字符(0-9, A-F, a-f)
local valid = string.match(text, "^[0-9A-Fa-f]*$")
if not valid then
sender.Text = sender.OldText or ""
else
sender.OldText = text
end
end
-- 添加快捷键支持
f.OnKeyDown = function(sender, key)
if key == 13 then -- 回车键
applyChanges()
elseif key == 27 then -- ESC键
f.close()
end
end
-- 窗体关闭事件
f.OnClose = function()
f.destroy()
end
-- 显示窗体
f.show()
end
-- 延迟1秒后执行,将工具添加到菜单
local timer = createTimer()
timer.Interval = 1000 -- 1秒
timer.OnTimer = function(t)
-- 停止定时器
t.destroy()
-- 查找"批量工具"菜单
local mainMenu = getMainForm().Menu
local batchToolsMenuItem = nil
-- 遍历主菜单查找"批量工具"
for i = 0, mainMenu.Items.Count - 1 do
local menuItem = mainMenu.Items
if menuItem.Caption == '批量工具' then
batchToolsMenuItem = menuItem
break
end
end
-- 如果没找到"批量工具"菜单,创建一个
if not batchToolsMenuItem then
batchToolsMenuItem = createMenuItem(MainForm.Menu)
batchToolsMenuItem.Caption = '批量工具'
mainMenu.Items.add(batchToolsMenuItem)
end
-- 创建工具菜单项
local pointerOffsetMenuItem = createMenuItem(batchToolsMenuItem)
pointerOffsetMenuItem.Caption = '指针偏移批量修改工具'
pointerOffsetMenuItem.OnClick = createPointerOffsetTool
-- 添加到批量工具菜单
batchToolsMenuItem.add(pointerOffsetMenuItem)
-- 可选:显示提示信息
-- showMessage('指针偏移批量修改工具已添加到菜单栏 批量工具 -> 指针偏移批量修改工具')
end |
|