-- ================= 工具:安全创建圆角背景 ================= local function makeRoundBg(color, radius) local d = nil pcall(function() local GD = luajava.bindClass("android.graphics.drawable.GradientDrawable") if GD then d = GD() d:setShape(0) d:setColor(color) d:setCornerRadius(radius) end end) return d end local bg = makeRoundBg(-1, 40) -- 白色圆角 local btnBg = makeRoundBg(-12627531, 24) -- 靛蓝圆角 -- ================= 改车牌 ================= function main() while true do local prompt = gg.prompt( {"请输入旧车牌:", "请输入新车牌:"}, {[1] = "", [2] = ""}, {[1] = "text", [2] = "text"} ) if prompt == nil then gg.toast("脚本已退出") return end local oldText = prompt[1] local newText = prompt[2] if oldText == "" or newText == "" then gg.toast("文本不能为空,请重新输入") else gg.setVisible(false) gg.setRanges( gg.REGION_JAVA_HEAP | gg.REGION_C_HEAP | gg.REGION_C_ALLOC | gg.REGION_C_DATA | gg.REGION_C_BSS | gg.REGION_PPSSPP | gg.REGION_ANONYMOUS ) gg.clearResults() -- 搜索时也需使用相同的类型常量 gg.searchNumber(";" .. oldText, gg.TYPE_WORD) local count = gg.getResultsCount() if count == 0 then gg.toast("未找到: " .. oldText) else gg.getResults(count) -- 先加载结果到列表 -- 将 TYPE_UNICODE 替换为环境中有效的类型常量 gg.editAll(";" .. newText, gg.TYPE_WORD) gg.toast("成功替换 " .. count .. " 处") end gg.clearResults() gg.setVisible(true) end end end -- ================= 改金币 ================= function changeCoin() local dataType = gg.TYPE_DWORD local searchVal, replaceVal local inputOk = false while not inputOk do local prompt = gg.prompt( {"原有的数量 (点取消退出):", "替换的数量:"}, {"", ""}, {"number", "number"} ) if not prompt then gg.toast("已取消") return end local input1 = prompt[1] and prompt[1]:match("^%s*(.-)%s*$") or "" local input2 = prompt[2] and prompt[2]:match("^%s*(.-)%s*$") or "" if input1 == "" or input2 == "" then gg.alert("❌ 提示:不能为空!\n请重新输入。") else searchVal = tonumber(input1) replaceVal = tonumber(input2) if not searchVal or not replaceVal then gg.alert("❌ 提示:请输入有效的数字!") else inputOk = true end end end gg.setVisible(false) gg.clearResults() local searchSuccess = pcall(function() gg.searchNumber(searchVal, dataType) end) if not searchSuccess then gg.alert("搜索失败,请检查游戏是否运行或数值是否正确。") else local count = gg.getResultsCount() if count > 0 then local results = gg.getResults(count) for _, v in ipairs(results) do v.value = replaceVal v.freeze = true v.freezeType = gg.FREEZE_NORMAL end local writeSuccess = pcall(function() gg.setValues(results) gg.addListItems(results) end) if writeSuccess then gg.toast("✅ 成功替换并冻结 " .. count .. " 个地址") else gg.toast("⚠️ 写入内存失败,可能地址已失效") end else gg.toast("❌ 未找到数值:" .. searchVal) end end gg.clearResults() gg.setVisible(true) end -- ================= 菜单构建 ================= local menu local function buildLayout(useDrawable) local bgProp = useDrawable and bg or "#FFFFFF" local btnProp = useDrawable and btnBg or "#FF3F51B5" return { FrameLayout, layout_width = "300dp", layout_height = "330dp", background = bgProp, { LinearLayout, orientation = "vertical", layout_width = "match_parent", layout_height = "wrap_content", layout_gravity = "center", layout_marginLeft = "20dp", layout_marginRight = "20dp", { TextView, text = "斩泪内置V:1.0.0", textSize = "18sp", textColor = "#FF3F51B5", gravity = "center", layout_width = "match_parent", layout_height = "wrap_content", layout_marginTop = "8dp", layout_marginBottom = "4dp" }, { TextView, text = "作者QQ: 2518579189", textSize = "13sp", textColor = "#FF888888", gravity = "center", layout_width = "match_parent", layout_height = "wrap_content", layout_marginBottom = "16dp" }, { Button, text = "选择进程", textSize = "16sp", textColor = "#FFFFFF", background = btnProp, layout_width = "match_parent", layout_height = "48dp", layout_marginBottom = "12dp", onClick = function(v) pcall(function() gg.setProcessX() end) gg.toast("若无效,请在 GG 主界面手动选择进程") end }, { Button, text = "自改车牌", textSize = "16sp", textColor = "#FFFFFF", background = btnProp, layout_width = "match_parent", layout_height = "48dp", layout_marginBottom = "12dp", onClick = function(v) changePlate() end }, { Button, text = "自改金币", textSize = "16sp", textColor = "#FFFFFF", background = btnProp, layout_width = "match_parent", layout_height = "48dp", onClick = function(v) changeCoin() end }, }, { Button, text = "×", textSize = "20sp", textColor = "#000000", background = "#00000000", layout_width = "40dp", layout_height = "40dp", layout_gravity = "bottom|right", onClick = function(v) if menu then pcall(function() menu:setVisibility(8) end) pcall(function() menu.dismiss() end) pcall(function() menu:Hide() end) pcall(function() menu:hide() end) end end }, } end -- ================= 环境检测 & 显示 ================= if not luajava or not luajava.loadlayout then gg.alert( "当前环境不支持 luajava.loadlayout,\n" .. "无法显示自定义悬浮菜单。\n\n" .. "请使用支持 luajava 的 GG 版本或定制框架。" ) return end -- 先试 Drawable 背景,失败降级为颜色字符串 local ok, err = pcall(function() menu = luajava.loadlayout(buildLayout(true)) end) if not ok then ok, err = pcall(function() menu = luajava.loadlayout(buildLayout(false)) end) end if not ok then gg.alert("菜单加载失败:\n" .. tostring(err)) return end if menu == nil then gg.alert("loadlayout 返回了空对象,未创建菜单。") return end -- 尝试多种显示 API(不同框架封装不同) local shown = false if type(menu.show) == "function" then if pcall(function() menu:show() end) then shown = true end end if not shown and type(menu.Show) == "function" then if pcall(function() menu:Show() end) then shown = true end end if not shown and type(menu.setVisibility) == "function" then if pcall(function() menu:setVisibility(0) end) then shown = true end end if not shown then gg.toast("菜单已创建,但未能自动显示。\n请检查框架是否提供 show() 方法") end