(Lua, ASMx86) Replication of Devil May Cry 4's debug functions for it's re-released version.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

d3dmenu.lua 7.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. local d3dmenu = {}
  2. -- append to display menu. D3D.destroyD3Dmenu()
  3. -- returns string representation of boolean.
  4. function d3dmenu.status_txt(bool)
  5. if bool then
  6. return "ON"
  7. end
  8. return "OFF"
  9. end
  10. --[[---------------------------------
  11. D3D Options Creation
  12. ---------------------------------]]--
  13. -- create a single new option for the menu.
  14. -- no return value
  15. function d3dmenu.new_option(id, label, index, th, h)
  16. OStrings[index] = id
  17. OLabels[index] = label
  18. OStates[index] = addresses.getMemoryRecordByDescription(OStrings[index]).Active
  19. Options[index] = h.createTextContainer(
  20. fmap,
  21. 0,
  22. 50 + (th * (index - 1)),
  23. OLabels[index]..d3dmenu.status_txt(OStates[index])
  24. )
  25. end
  26. -- default settings for options if file is not found.
  27. -- return memory record descriptions and menu labels.
  28. function d3dmenu.defaults()
  29. -- preset strings come from names of memory records
  30. local presets = {
  31. 'Disable Camera Events (No "Screen Blink", but Some Issues in Missions)',
  32. 'Auto-Skip Cutscenes (Checking This Enables Everything Under This Section)',
  33. 'Disable Bloody Palace Timer',
  34. 'No One Dies (Effect Takes Precedence Over Damage Modifiers)',
  35. 'No One Takes Damage',
  36. 'Enemy 1-Hit Kill',
  37. 'Allow Trick Down (Air) without DT',
  38. '"Berial Fire Lost" (Checking this Enables Everything Under This Section)'
  39. }
  40. local plabels = {
  41. "Disable Camera Events: ",
  42. "Auto-Skip Cutscenes: ",
  43. "Disable Bloody Palace Timer: ",
  44. "No One Dies: ",
  45. "No One Takes Damage: ",
  46. "Enemy 1-Hit Kill: ",
  47. "Vergil, No DT - Allow Trick Down: ",
  48. "Berial Fire Lost: "
  49. }
  50. -- both 'presets' and 'plabels' must be of the same length.
  51. presets.size = 8
  52. return presets, plabels
  53. end
  54. -- reads in the file and stores information as strings.
  55. -- parameter 'f' = file descriptor (Lua metatable).
  56. -- parameter 'sep' = separator.
  57. -- returns memory record description and menu labels.
  58. function d3dmenu.fromfile(f, sep)
  59. -- 'Outstrs' = output strings.
  60. -- 'Outlabels' = output labels.
  61. local Outstrs = {}
  62. local Outlabels = {}
  63. Outstrs.size = 0
  64. local sephit = false -- 'sephit' = separator hit,
  65. -- whether or not string 'sep' has been encountered.
  66. local index = 1 -- starting index for initialization of labels.
  67. for line in f:lines() do
  68. if (not sephit) and (line ~= sep) then
  69. -- current line is not 'sep' and 'sep' has never been encountered.
  70. -- check if current line is a description that exists in Cheat Table.
  71. Outstrs.size = Outstrs.size + 1
  72. Outstrs[Outstrs.size] = line
  73. elseif (not sephit) and line == sep then
  74. -- current line is 'sep', and 'sep' is encountered.
  75. sephit = true
  76. else
  77. -- current line is not 'sep' and 'sep' has been encountered.
  78. Outlabels[index] = line
  79. index = index + 1
  80. end --end if
  81. end --end for loop
  82. return Outstrs, Outlabels
  83. end
  84. -- create and bind d3dmenu options with CE memory records.
  85. -- global variables are declared here.
  86. -- no return value.
  87. function d3dmenu.init(hook)
  88. Options = {} --text containers
  89. Options.size = 0
  90. OLabels = {} --menu label
  91. OStates = {} --booleans
  92. OStrings = {} --identifying memory record descriptions
  93. addresses = getAddressList()
  94. local filename = TrainerOrigin.."d3dmenu-ops.txt"
  95. local file = io.open(filename, "r")
  96. local txt_height = fmap.Height
  97. -- these are lists of strings of the same length
  98. -- ids is the list with the 'size' attribute
  99. local ids = {} -- memory record descriptions
  100. local labels = {} -- menu label
  101. if file == nil then
  102. ids, labels = d3dmenu.defaults()
  103. else
  104. ids, labels = d3dmenu.fromfile(file, ":")
  105. end
  106. file:close()
  107. for i = 1, ids.size do
  108. d3dmenu.new_option(ids[i], labels[i], i, txt_height, hook)
  109. end
  110. Options.size = ids.size
  111. selected_option = 1
  112. end
  113. --[[---------------------------------
  114. D3D Menu Creation
  115. ---------------------------------]]--
  116. function d3dmenu.createD3Dmenu(CE_hook)
  117. background = createPicture()
  118. bitmap = background.getBitmap()
  119. bitmap.setHeight(1)
  120. bitmap.setWidth(1)
  121. canvas = bitmap.getCanvas()
  122. canvas.setPixel(0,0, 0xffffff) --White overlay
  123. bgtexture = CE_hook.createTexture(background)
  124. bgsprite = CE_hook.createSprite(bgtexture)
  125. bgsprite.Width = 200
  126. bgsprite.Height = 200
  127. bgsprite.X = 0 --centered horizontally
  128. bgsprite.Alphablend = 0.5
  129. highlight = createPicture()
  130. bitmap = highlight.getBitmap()
  131. bitmap.setHeight(1)
  132. bitmap.setWidth(1)
  133. canvas = bitmap.getCanvas()
  134. canvas.setPixel(0,0, 0x9FB4BA) --highlight color
  135. hltexture = CE_hook.createTexture(highlight)
  136. hlsprite = CE_hook.createSprite(hltexture)
  137. hlsprite.Visible = false --not yet
  138. hlsprite.X = 0 --line up with background
  139. hlsprite.Width = 200
  140. font = createFont()
  141. fmap = CE_hook.createFontmap(font)
  142. hlsprite.Height = fmap.Height
  143. hlsprite.Visible = true
  144. d3dmenu.init(CE_hook)
  145. end
  146. --[[---------------------------------
  147. D3D Menu Operations
  148. ---------------------------------]]--
  149. -- executes changes to game from menu options
  150. -- no return value
  151. -- accesses global 'Options', and everything related.
  152. function d3dmenu.execute_selected()
  153. OStates[selected_option] = not OStates[selected_option]
  154. addresses.getMemoryRecordByDescription(OStrings[selected_option]).Active = OStates[selected_option]
  155. Options[selected_option].Text = OLabels[selected_option]..d3dmenu.status_txt(OStates[selected_option])
  156. end
  157. -- called on the event of a mouse click
  158. -- no return value
  159. -- accesses and writes global 'selected_option'
  160. -- only accesses global 'Options'
  161. function d3dmenu.option_click(object, x, y)
  162. for i = 1, Options.size do
  163. --see which Option was clicked
  164. if (object == Options[i]) then
  165. selected_option = i
  166. d3dmenu.execute_selected()
  167. d3dmenu.highlight_selected()
  168. end
  169. end
  170. end
  171. -- toggle visibility of the menu
  172. -- no return value
  173. -- accesses and writes global 'bgsprite', 'hlsprite', 'Options'
  174. function d3dmenu.toggle_display()
  175. bgsprite.Visible = not bgsprite.Visible
  176. hlsprite.Visible = not hlsprite.Visible
  177. for i = 1, Options.size do
  178. Options[i].Visible = not Options[i].Visible
  179. end
  180. end
  181. -- move highlighter sprite over selected menu option
  182. -- no return value
  183. -- accesses global 'selected_option'
  184. function d3dmenu.highlight_selected()
  185. hlsprite.Y = 50 + (fmap.Height * (selected_option - 1))
  186. end
  187. -- removes all d3d render objects
  188. -- no return value
  189. -- accesses globals declared in menu creation.
  190. function d3dmenu.destroyD3Dmenu()
  191. --Clean up... everything.
  192. bgsprite.destroy()
  193. bgtexture.destroy()
  194. hlsprite.destroy()
  195. hltexture.destroy()
  196. background.destroy()
  197. highlight.destroy()
  198. bitmap.destroy()
  199. if Options ~= nil then
  200. for i = 1, Options.size do
  201. Options[i].destroy()
  202. end
  203. end
  204. fmap.destroy()
  205. font.destroy()
  206. canvas.destroy()
  207. end
  208. return d3dmenu