vcbfm

Castlevania: The Adventure_恶魔城:冒险_GBC_LUA

Oct 20th, 2024
45
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.97 KB | Source Code | 0 0
  1. --2024.09.24发布
  2. --首发 http://forum.cheatmaker.org/
  3. --显示血量
  4. --按下大键盘 1- 9 开启作弊.
  5.  
  6. -- 玩家地址信息
  7. local playerHPAddress = 0x519
  8. local playerXAddress = 0x50B
  9. local playerYAddress = 0x512
  10. local playerSubXAddress = 0x402
  11. local whipStatusAddress = 0x51C
  12. local playerSlotAddress = 0x500 -- 玩家槽地址
  13.  
  14. local cheatCodes = {
  15.     { code = "00B-348-195", name = "Don't Die From Falling Down A Pit" },  --不要因掉入坑而死
  16.     { code = "00A-CF8-3B7", name = "Don't Lose Weapon From Getting Hit" },  --不要因为被击中而丢失武器
  17.     { codes = {"002-71D-E62", "002-61D-A22"}, name = "Hit Anywhere" },  --全屏攻击.
  18.     { code = "FF7-3CE-E69", name = "Improve Speed Slightly" },  --速度可能略有提升?
  19.     { code = "C9A-8C8-E69", name = "Invincibility against Enemies" },  --无敌.
  20.     { codes = {"FA8-55E-919", "FA4-17D-C41", "FA4-27D-C41", "FA3-BDD-D59", "FA4-1FD-C41"}, name = "Invincibility Against Spikes" },     --对抗尖刺所向披靡
  21.     { codes = {"009-C9E-3B7", "CD9-BDE-4CA", "329-BEE-C42", "1A9-BFE-F77"}, name = "Jump In Midair" },  --按连发键的 跳进半空中.慎用.
  22.     { code = "006-94F-3B7", name = "Infinite lives" },  --无限生命数.
  23.     { code = "013-8CF-081", name = "Infinite Time" },   --无限时间.
  24. }
  25.  
  26. local activeCheats = {} -- 激活中的作弊列表
  27. local memoryType = emu.memType.gbWorkRam
  28. local enemyAddresses = {0x600, 0x620, 0x640, 0x660, 0x680, 0x6A0, 0x6C0, 0x6E0}
  29. local fontColor = 0x0FFFFFFF
  30. local bgColor = 0x0FB8DF8B
  31. local borderColor = 0x0F000000
  32. local padding = 1
  33.  
  34. -- 初始化变量
  35. local baseX = 0x59
  36. local whipStatusFrames = 0
  37. local lastWhipStatus = -1
  38. local cheatLog = "" -- 用于存储激活/禁用作弊信息
  39. local cheatLogFrames = 0 -- 用于跟踪作弊日志显示的帧数
  40.  
  41. -- 获取玩家信息函数
  42. local function getPlayerInfo()
  43.     local hp = emu.read(playerHPAddress, memoryType)
  44.     local x = emu.read(playerXAddress, memoryType)
  45.     local y = emu.read(playerYAddress, memoryType)
  46.     local subX = emu.read(playerSubXAddress, memoryType)
  47.     return hp, x, y, subX
  48. end
  49.  
  50. local function getTextBoxWidth(text)
  51.     local charWidth = 6 -- 调整字符宽度以适应菜单
  52.     return #text * charWidth + padding * 2
  53. end
  54.  
  55. local function toggleCheat(cheat)
  56.     if activeCheats[cheat.name] then
  57.         activeCheats[cheat.name] = nil
  58.         cheatLog = "Cheat disabled: " .. cheat.name
  59.         cheatLogFrames = 0 -- 重置帧计数器
  60.         emu.log(cheatLog)
  61.         emu.clearCheats()
  62.         for _, activeCheat in ipairs(cheatCodes) do
  63.             if activeCheats[activeCheat.name] then
  64.                 for _, code in ipairs(activeCheat.codes or {activeCheat.code}) do
  65.                     emu.addCheat(emu.cheatType.gbGameGenie, code)
  66.                 end
  67.             end
  68.         end
  69.     else
  70.  
  71.         activeCheats[cheat.name] = true
  72.         cheatLog = "Cheat activated: " .. cheat.name
  73.         cheatLogFrames = 0
  74.         emu.log(cheatLog)
  75.         for _, code in ipairs(cheat.codes or {cheat.code}) do
  76.             emu.addCheat(emu.cheatType.gbGameGenie, code)
  77.         end
  78.     end
  79. end
  80.  
  81. local function drawWhipStatus()
  82.     local playerSlotValue = emu.read(playerSlotAddress, memoryType)
  83.     if playerSlotValue == 0x0 then
  84.         return
  85.     end
  86.     local whipStatus = emu.read(whipStatusAddress, memoryType)
  87.     local whipString = ""
  88.     if whipStatus == 0x00 then
  89.         whipString = "普通鞭子"
  90.     elseif whipStatus == 0x01 then
  91.         whipString = "金属鞭子"
  92.     elseif whipStatus == 0x02 then
  93.         whipString = "火球鞭子"
  94.     else
  95.         whipString = "未知"
  96.     end
  97.     if whipStatus ~= lastWhipStatus then
  98.         whipStatusFrames = 0
  99.         lastWhipStatus = whipStatus
  100.     else
  101.         whipStatusFrames = whipStatusFrames + 1
  102.     end
  103.     if whipStatusFrames <= 100 then
  104.         local boxY = 131
  105.         local fixedBoxX = 66
  106.         emu.drawString(fixedBoxX, boxY, whipString, fontColor, 0x00000000)
  107.     end
  108. end
  109.  
  110.  
  111. local function drawPlayerHP(hp, playerX, playerY, subX)
  112.     local playerSlotValue = emu.read(playerSlotAddress, memoryType) -- 读取玩家槽地址的值
  113.     if playerSlotValue == 0x0 then
  114.         return
  115.     end
  116.     local hpString = tostring(hp)
  117.     local boxWidth = getTextBoxWidth(hpString)
  118.     local boxY = playerY - 40
  119.     local boxX = (subX <= 3 and playerX <= 0x58) and playerX - (boxWidth / 2) - 9 or baseX - (boxWidth / 2) - 9
  120.     emu.drawRectangle(boxX - 1, boxY - 1, boxWidth + 2, 9 + 2, borderColor, true)
  121.     emu.drawRectangle(boxX, boxY, boxWidth, 9, bgColor, true)
  122.     emu.drawString(boxX + padding, boxY + padding, hpString, fontColor, bgColor)
  123. end
  124.  
  125. local function drawPlayerHPFixed()
  126.     local playerSlotValue = emu.read(playerSlotAddress, memoryType) -- 读取玩家槽地址的值
  127.     if playerSlotValue == 0x0 then
  128.         return
  129.     end
  130.     local playerHP = emu.read(playerHPAddress, memoryType)
  131.     local hpString = tostring(playerHP)
  132.     local boxWidth = getTextBoxWidth(hpString)
  133.     local fixedBoxX = 5
  134.     local fixedBoxY = 132
  135.     emu.drawRectangle(fixedBoxX - 1, fixedBoxY - 1, boxWidth + 2, 9 + 2, borderColor, true)
  136.     emu.drawRectangle(fixedBoxX, fixedBoxY, boxWidth, 9, bgColor, true)
  137.     emu.drawString(fixedBoxX + padding, fixedBoxY + padding, hpString, fontColor, bgColor)
  138. end
  139.  
  140. local function drawEnemyHP()
  141.     local fixedBoxX = 5
  142.     local fixedBoxY = 120
  143.     for _, enemyAddress in ipairs(enemyAddresses) do
  144.         local enemyStatus = emu.read(enemyAddress, memoryType)
  145.         if enemyStatus == 0x80 then
  146.             local enemyHP = emu.read(enemyAddress + 0x19, memoryType)
  147.             if enemyHP ~= 0xFF and enemyHP ~= 0 then
  148.                 local hpString = tostring(enemyHP)
  149.                 local boxWidth = getTextBoxWidth(hpString)
  150.                 emu.drawRectangle(fixedBoxX - 1, fixedBoxY - 1, boxWidth + 2, 9 + 2, borderColor, true)
  151.                 emu.drawRectangle(fixedBoxX, fixedBoxY, boxWidth, 9, bgColor, true)
  152.                 emu.drawString(fixedBoxX + padding, fixedBoxY + padding, hpString, fontColor, bgColor)
  153.             end
  154.         end
  155.     end
  156. end
  157.  
  158. local function drawHPs()
  159.     local playerHP, playerX, playerY, playerSubX = getPlayerInfo()
  160.     drawPlayerHP(playerHP, playerX, playerY, playerSubX)
  161.     drawPlayerHPFixed()
  162.     drawEnemyHP()
  163.     drawWhipStatus()
  164.    
  165.  
  166.     if cheatLog ~= "" then
  167.         emu.drawString(5, 5, cheatLog, fontColor, 0x00000000,150)
  168.         cheatLogFrames = cheatLogFrames + 1 -- 增加帧计数器
  169.         if cheatLogFrames >= 100 then
  170.             cheatLog = ""
  171.         end
  172.     end
  173. end
  174.  
  175.  
  176. emu.addEventCallback(drawHPs, emu.eventType.endFrame)
  177.  
  178. local previousKeys = {}
  179. emu.addEventCallback(function()
  180.     for i = 1, #cheatCodes do
  181.         if emu.isKeyPressed(tostring(i)) and not previousKeys[i] then
  182.             toggleCheat(cheatCodes[i])
  183.         end
  184.     end
  185.     previousKeys = {}
  186.     for i = 1, #cheatCodes do
  187.         previousKeys[i] = emu.isKeyPressed(tostring(i))
  188.     end
  189. end, emu.eventType.inputPolled)
  190.  
Tags: game lua mesen2 GBC
Advertisement
Comments
Add Comment
Please, Sign In to add comment