Guest User

Untitled

a guest
May 23rd, 2018
566
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 45.09 KB | None | 0 0
  1. --------------------------------------------------------------------------------------
  2. -- New Super Mario Bros. DS Profile Lua Script
  3. --------------------------------------------------------------------------------------
  4. -- This script reads active frame data from all frame-executed processes, then outputs
  5. -- the info NUM_FRAMES_OBJ frames behind the actual read. NUM_FRAMES_OBJ is set to 3
  6. -- to match the info with the Nintendo DS displays. Only frame-executed processes are
  7. -- used/shown, thus if a frame-drawn process that has a sensor has not been frame-
  8. -- executed then it won't be visible (but the game will draw the process, if the game
  9. -- allows processes to be drawn without executed in the first place).
  10. --
  11. -- NUM_OBJ_ENTRIES is set to a high number to output as many processes as possible.
  12. -- The lower NUM_OBJ_ENTRIES is, the faster the script will run.
  13. --
  14. -- The info that is read is taken from the execution list, as the order of execution
  15. -- is key to synchronize a frame.
  16. -- The order of execution should usually be:
  17. -- PLAYER->ENEMY->PLATFORM/SOLID->CAMERA->LASTACTOR_STAGE(HITBOXes)
  18. --
  19. -- By Powerline and Treeki
  20. --------------------------------------------------------------------------------------
  21.  
  22. ---------------
  23. -- Constants --
  24. ---------------
  25. NUM_FRAMES_OBJ = 3 -- Number of frames to wait until the info will be drawn on screen. Default = 3.
  26.  
  27. NUM_OBJ_ENTRIES = 96 -- Number of visible info on screen. The lower the faster. Default = 96.
  28.  
  29. TOP_SCREEN_Y = -192 -- Offset of top screen to use when main screen is top screen.
  30. BOTTOM_SCREEN_Y = 0 -- Offset to bottom screen to use when main screen is bottom screen.
  31.  
  32. SHOW_HITBOX = 1 -- Set to 1 to show hitboxes.
  33. SHOW_PLATFORM = 1 -- Set to 1 to show platforms.
  34. SHOW_SOLID = 1 -- Set to 1 to show solids.
  35. SHOW_SENSOR = 1 -- Set to 1 to show sensors.
  36.  
  37. -- What color to draw info with:
  38. COLOR_HITBOX_IN = "#FF000080"
  39. COLOR_HITBOX_OUT = "#FF0000FF"
  40.  
  41. COLOR_PLATFORM = "#00FF00FF"
  42.  
  43. COLOR_SOLID_IN = "#0000FF80"
  44. COLOR_SOLID_OUT = "#0000FFFF"
  45.  
  46. COLOR_SENSOR_BELOW = "#6DF6FFFF"
  47. COLOR_SENSOR_ABOVE = "#66FD86FF"
  48. COLOR_SENSOR_LEFT = "#FFFF60FF"
  49. COLOR_SENSOR_RIGHT = "#FFFF60FF"
  50.  
  51. CameraAddress = 0
  52.  
  53. --------------------------------------------------------------------------------------
  54. -- GetActiveLCDY()
  55. --------------------------------------------------------------------------------------
  56. -- Reads POWERCNT register to find which screen is the main screen.
  57. --
  58. -- By Powerline
  59. --------------------------------------------------------------------------------------
  60. function GetActiveLCDY()
  61. if bit.band(0x8000, memory.readword(0x4000304)) > 0 then
  62. return TOP_SCREEN_Y
  63. end
  64.  
  65. return BOTTOM_SCREEN_Y
  66. end
  67.  
  68. --------------------------------------------------------------------------------------
  69. -- GetNextConnectHierarchyPtr()
  70. --------------------------------------------------------------------------------------
  71. -- Get the next connect hierarchy pointer in the hierarchy list. First travels the
  72. -- children, and then its siblings.
  73. --
  74. -- Takes an argument of the current hierarchy pointer, or 0 to start at the root.
  75. --
  76. -- Warning: Uses recursion to find the next parent's sibling's child (game might not
  77. -- use it)!
  78. --
  79. -- By Powerline
  80. --------------------------------------------------------------------------------------
  81. function GetNextConnectHierarchyPtr(pHierarchyConnect)
  82. if pHierarchyConnect > 0 then
  83. -- Either child or sibling
  84. pHierarchyConnectTmp = memory.readdword(pHierarchyConnect + 0x4)
  85.  
  86. if pHierarchyConnectTmp == 0 then
  87. pHierarchyConnectTmp = memory.readdword(pHierarchyConnect + 0xE)
  88.  
  89. if pHierarchyConnectTmp == 0 then
  90. pHierarchyConnect = 0
  91.  
  92. -- Recursive into the parent's sibling's child
  93. pHierarchyConnectTmp = memory.readdword(pHierarchyConnect + 0)
  94.  
  95. if pHierarchyConnectTmp == 0 then
  96. pHierarchyConnectTmp = memory.readdword(pHierarchyConnect + 0xE)
  97.  
  98. if pHierarchyConnectTmp == 0 then
  99. pHierarchyConnect = GetNextConnectPtr(pHierarchyConnectTmp)
  100. end
  101. end
  102. else
  103. -- Return next sibling if available
  104. pHierarchyConnect = pHierarchyConnectTmp
  105. end
  106. else
  107. -- Return next child if available
  108. pHierarchyConnect = pHierarchyConnectTmp
  109. end
  110. else
  111. -- Return root if available
  112. pHierarchyConnect = memory.readdword(0x208FB0C)
  113. end
  114.  
  115. return pHierarchyConnect
  116. end
  117.  
  118. --------------------------------------------------------------------------------------
  119. -- GetNextExecuteLinkPtr()
  120. --------------------------------------------------------------------------------------
  121. -- Get the next reordered execute link pointer in the list.
  122. --
  123. -- Takes an argument of the current link pointer, or 0 to start at the root.
  124. --
  125. -- By Powerline
  126. --------------------------------------------------------------------------------------
  127. function GetNextExecuteLinkPtr(pLinkExecute)
  128. if pLinkExecute > 0 then
  129. -- Return next link if available
  130. pLinkExecute = memory.readdword(pLinkExecute + 0x4)
  131. else
  132. -- Return root if available
  133. pLinkExecute = memory.readdword(0x208FB18)
  134. end
  135.  
  136. return pLinkExecute
  137. end
  138.  
  139. --------------------------------------------------------------------------------------
  140. -- GetNextDrawLinkPtr()
  141. --------------------------------------------------------------------------------------
  142. -- Get the next reordered draw link pointer in the list.
  143. --
  144. -- Takes an argument of the current link pointer, or 0 to start at the root.
  145. --
  146. -- By Powerline
  147. --------------------------------------------------------------------------------------
  148. function GetNextDrawLinkPtr(pLinkDraw)
  149. if pLinkDraw > 0 then
  150. -- Return next link if available
  151. pLinkDraw = memory.readdword(pLinkDraw + 0x4)
  152. else
  153. -- Return root if available
  154. pLinkDraw = memory.readdword(0x208FB38)
  155. end
  156.  
  157. return pLinkDraw
  158. end
  159.  
  160. --------------------------------------------------------------------------------------
  161. -- GetNextComplexColliderLinkPtr()
  162. --------------------------------------------------------------------------------------
  163. --
  164. -- By Treeki
  165. --------------------------------------------------------------------------------------
  166. function GetNextComplexColliderLinkPtr(pLinkComplexCollider)
  167. if pLinkComplexCollider > 0 then
  168. -- Return next link if available
  169. pLinkComplexCollider = memory.readdword(pLinkComplexCollider + 0xC)
  170. else
  171. -- Return root if available
  172. pLinkComplexCollider = memory.readdword(0x20CAAC8)
  173. end
  174.  
  175. return pLinkComplexCollider
  176. end
  177.  
  178. --------------------------------------------------------------------------------------
  179. -- GetNextClimbableColliderLinkPtr()
  180. --------------------------------------------------------------------------------------
  181. --
  182. -- By Treeki
  183. --------------------------------------------------------------------------------------
  184. function GetNextClimbableColliderLinkPtr(pLinkClimbableCollider)
  185. if pLinkClimbableCollider > 0 then
  186. -- Return next link if available
  187. pLinkClimbableCollider = memory.readdword(pLinkClimbableCollider + 0x8)
  188. else
  189. -- Return root if available
  190. pLinkClimbableCollider = memory.readdword(0x208AE64)
  191. end
  192.  
  193. return pLinkClimbableCollider
  194. end
  195.  
  196. --------------------------------------------------------------------------------------
  197. -- GetNextMiscColliderLinkPtr()
  198. --------------------------------------------------------------------------------------
  199. --
  200. -- By Treeki
  201. --------------------------------------------------------------------------------------
  202. function GetNextMiscColliderLinkPtr(pLinkMiscCollider)
  203. if pLinkMiscCollider > 0 then
  204. -- Return next link if available
  205. pLinkMiscCollider = memory.readdword(pLinkMiscCollider + 0x8)
  206. else
  207. -- Return root if available
  208. pLinkMiscCollider = memory.readdword(0x208AE94)
  209. end
  210.  
  211. return pLinkMiscCollider
  212. end
  213.  
  214. --------------------------------------------------------------------------------------
  215. -- GetNextSolidColliderLinkPtr()
  216. --------------------------------------------------------------------------------------
  217. --
  218. -- By Treeki
  219. --------------------------------------------------------------------------------------
  220. function GetNextSolidColliderLinkPtr(pLinkSolidCollider)
  221. if pLinkSolidCollider > 0 then
  222. -- Return next link if available
  223. pLinkSolidCollider = memory.readdword(pLinkSolidCollider + 0x4)
  224. else
  225. -- Return root if available
  226. pLinkSolidCollider = memory.readdword(0x20CABE8)
  227. end
  228.  
  229. return pLinkSolidCollider
  230. end
  231.  
  232. --------------------------------------------------------------------------------------
  233. -- Fix12ToFloat()
  234. --------------------------------------------------------------------------------------
  235. -- Converts n.12 fixed point into a floating point value
  236. --
  237. -- By Powerline
  238. --------------------------------------------------------------------------------------
  239. function Fix12ToFloat(fix12)
  240. return fix12 / 4096.0
  241. end
  242.  
  243. --------------------------------------------------------------------------------------
  244. -- CacheSetNow()
  245. --------------------------------------------------------------------------------------
  246. -- Sets the value stored in the cache now
  247. --
  248. -- By Powerline
  249. --------------------------------------------------------------------------------------
  250. function CacheSetNow(var, start, set)
  251. var[start + 0] = set
  252. end
  253.  
  254. --------------------------------------------------------------------------------------
  255. -- CacheGetNow()
  256. --------------------------------------------------------------------------------------
  257. -- Gets the value stored in the cache now
  258. --
  259. -- By Powerline
  260. --------------------------------------------------------------------------------------
  261. function CacheGetNow(var, start)
  262. return var[start + 0]
  263. end
  264.  
  265. --------------------------------------------------------------------------------------
  266. -- CacheGetObjLater()
  267. --------------------------------------------------------------------------------------
  268. -- Gets the value stored in the cache for later
  269. --
  270. -- By Powerline
  271. --------------------------------------------------------------------------------------
  272. function CacheGetObjLater(var, start)
  273. return var[start + (NUM_FRAMES_OBJ - 1)]
  274. end
  275.  
  276. --------------------------------------------------------------------------------------
  277. -- CacheVarFrameDown()
  278. --------------------------------------------------------------------------------------
  279. -- Caches a value downwards in an array
  280. --
  281. -- By Powerline
  282. --------------------------------------------------------------------------------------
  283. function CacheVarFrameDown(var, num, start)
  284. for a = 0, (num - 1) do
  285. b = a + 1
  286. var[start + a] = var[start + b]
  287. end
  288. end
  289.  
  290. --------------------------------------------------------------------------------------
  291. -- CacheVarFrameUp()
  292. --------------------------------------------------------------------------------------
  293. -- Caches a value upwards in an array
  294. --
  295. -- By Powerline
  296. --------------------------------------------------------------------------------------
  297. function CacheVarFrameUp(var, num, start)
  298. for a = (num - 2), 0, -1 do
  299. b = a + 1
  300. var[start + b] = var[start + a]
  301. end
  302. end
  303.  
  304. --------------------------------------------------------------------------------------
  305. -- CacheVarInit()
  306. --------------------------------------------------------------------------------------
  307. -- Initializes an array for cache
  308. --
  309. -- By Powerline
  310. --------------------------------------------------------------------------------------
  311. function CacheVarInit(var, num, entries)
  312. for a = 0, (num * entries) do
  313. var[a] = 0
  314. end
  315. end
  316.  
  317. -------------
  318. -- Globals --
  319. -------------
  320. f12CameraX = {}
  321. CacheVarInit(f12CameraX, NUM_FRAMES_OBJ, 1)
  322.  
  323. f12CameraY = {}
  324. CacheVarInit(f12CameraY, NUM_FRAMES_OBJ, 1)
  325.  
  326. f12ZoomXY = {}
  327. CacheVarInit(f12ZoomXY, NUM_FRAMES_OBJ, 1)
  328.  
  329. f12WrapX = {}
  330. CacheVarInit(f12WrapX, NUM_FRAMES_OBJ, 1)
  331.  
  332. pProfExecThis = {}
  333. CacheVarInit(pProfExecThis, NUM_FRAMES_OBJ, NUM_OBJ_ENTRIES)
  334.  
  335. wProfExecName = {}
  336. CacheVarInit(wProfExecName, NUM_FRAMES_OBJ, NUM_OBJ_ENTRIES)
  337.  
  338. bProfExecType = {}
  339. CacheVarInit(bProfExecType, NUM_FRAMES_OBJ, NUM_OBJ_ENTRIES)
  340.  
  341. if SHOW_HITBOX ~= 0 then
  342. bProfExecHitbox = {}
  343. CacheVarInit(bProfExecHitbox, NUM_FRAMES_OBJ, NUM_OBJ_ENTRIES)
  344. end
  345.  
  346. if SHOW_PLATFORM ~= 0 then
  347. bProfExecPlatform = {}
  348. CacheVarInit(bProfExecPlatform, NUM_FRAMES_OBJ, NUM_OBJ_ENTRIES)
  349. end
  350.  
  351. if SHOW_SOLID ~= 0 then
  352. bProfExecSolid = {}
  353. CacheVarInit(bProfExecSolid, NUM_FRAMES_OBJ, NUM_OBJ_ENTRIES)
  354. end
  355.  
  356. if SHOW_SENSOR ~= 0 then
  357. bProfExecSensor = {}
  358. CacheVarInit(bProfExecSensor, NUM_FRAMES_OBJ, NUM_OBJ_ENTRIES)
  359. end
  360.  
  361. f12ProfX = {}
  362. CacheVarInit(f12ProfX, NUM_FRAMES_OBJ, NUM_OBJ_ENTRIES)
  363.  
  364. f12ProfY = {}
  365. CacheVarInit(f12ProfY, NUM_FRAMES_OBJ, NUM_OBJ_ENTRIES)
  366.  
  367. if SHOW_HITBOX ~= 0 then
  368. f12ProfBBX = {}
  369. CacheVarInit(f12ProfBBX, NUM_FRAMES_OBJ, NUM_OBJ_ENTRIES)
  370.  
  371. f12ProfBBY = {}
  372. CacheVarInit(f12ProfBBY, NUM_FRAMES_OBJ, NUM_OBJ_ENTRIES)
  373.  
  374. f12ProfBBW = {}
  375. CacheVarInit(f12ProfBBW, NUM_FRAMES_OBJ, NUM_OBJ_ENTRIES)
  376.  
  377. f12ProfBBH = {}
  378. CacheVarInit(f12ProfBBH, NUM_FRAMES_OBJ, NUM_OBJ_ENTRIES)
  379.  
  380. f12ProfTrp0 = {}
  381. CacheVarInit(f12ProfTrp0, NUM_FRAMES_OBJ, NUM_OBJ_ENTRIES)
  382.  
  383. f12ProfTrp1 = {}
  384. CacheVarInit(f12ProfTrp1, NUM_FRAMES_OBJ, NUM_OBJ_ENTRIES)
  385.  
  386. f12ProfTrp2 = {}
  387. CacheVarInit(f12ProfTrp2, NUM_FRAMES_OBJ, NUM_OBJ_ENTRIES)
  388.  
  389. f12ProfTrp3 = {}
  390. CacheVarInit(f12ProfTrp3, NUM_FRAMES_OBJ, NUM_OBJ_ENTRIES)
  391.  
  392. bCollType = {}
  393. CacheVarInit(bCollType, NUM_FRAMES_OBJ, NUM_OBJ_ENTRIES)
  394. end
  395.  
  396. if SHOW_PLATFORM ~= 0 then
  397. f12PlatformLeftX = {}
  398. CacheVarInit(f12PlatformLeftX, NUM_FRAMES_OBJ, NUM_OBJ_ENTRIES)
  399.  
  400. f12PlatformLeftY = {}
  401. CacheVarInit(f12PlatformLeftY, NUM_FRAMES_OBJ, NUM_OBJ_ENTRIES)
  402.  
  403. f12PlatformRightX = {}
  404. CacheVarInit(f12PlatformRightX, NUM_FRAMES_OBJ, NUM_OBJ_ENTRIES)
  405.  
  406. f12PlatformRightY = {}
  407. CacheVarInit(f12PlatformRightY, NUM_FRAMES_OBJ, NUM_OBJ_ENTRIES)
  408.  
  409. f12PlatformRotation = {}
  410. CacheVarInit(f12PlatformRotation, NUM_FRAMES_OBJ, NUM_OBJ_ENTRIES)
  411. end
  412.  
  413. if SHOW_SOLID ~= 0 then
  414. f12SolidProfX = {}
  415. CacheVarInit(f12SolidProfX, NUM_FRAMES_OBJ, NUM_OBJ_ENTRIES)
  416.  
  417. f12SolidProfY = {}
  418. CacheVarInit(f12SolidProfY, NUM_FRAMES_OBJ, NUM_OBJ_ENTRIES)
  419.  
  420. f12SolidLeft = {}
  421. CacheVarInit(f12SolidLeft, NUM_FRAMES_OBJ, NUM_OBJ_ENTRIES)
  422.  
  423. f12SolidTop = {}
  424. CacheVarInit(f12SolidTop, NUM_FRAMES_OBJ, NUM_OBJ_ENTRIES)
  425.  
  426. f12SolidRight = {}
  427. CacheVarInit(f12SolidRight, NUM_FRAMES_OBJ, NUM_OBJ_ENTRIES)
  428.  
  429. f12SolidBottom = {}
  430. CacheVarInit(f12SolidBottom, NUM_FRAMES_OBJ, NUM_OBJ_ENTRIES)
  431. end
  432.  
  433. if SHOW_SENSOR ~= 0 then
  434. f12SensorProfX = {}
  435. CacheVarInit(f12SensorProfX, NUM_FRAMES_OBJ, NUM_OBJ_ENTRIES)
  436.  
  437. f12SensorProfY = {}
  438. CacheVarInit(f12SensorProfY, NUM_FRAMES_OBJ, NUM_OBJ_ENTRIES)
  439.  
  440. dwSensorBelowFlags = {}
  441. CacheVarInit(dwSensorBelowFlags, NUM_FRAMES_OBJ, NUM_OBJ_ENTRIES)
  442.  
  443. f12SensorBelowX = {}
  444. CacheVarInit(f12SensorBelowX, NUM_FRAMES_OBJ, NUM_OBJ_ENTRIES)
  445.  
  446. f12SensorBelowY = {}
  447. CacheVarInit(f12SensorBelowY, NUM_FRAMES_OBJ, NUM_OBJ_ENTRIES)
  448.  
  449. f12SensorBelowAt = {}
  450. CacheVarInit(f12SensorBelowAt, NUM_FRAMES_OBJ, NUM_OBJ_ENTRIES)
  451.  
  452. dwSensorAboveFlags = {}
  453. CacheVarInit(dwSensorAboveFlags, NUM_FRAMES_OBJ, NUM_OBJ_ENTRIES)
  454.  
  455. f12SensorAboveX = {}
  456. CacheVarInit(f12SensorAboveX, NUM_FRAMES_OBJ, NUM_OBJ_ENTRIES)
  457.  
  458. f12SensorAboveY = {}
  459. CacheVarInit(f12SensorAboveY, NUM_FRAMES_OBJ, NUM_OBJ_ENTRIES)
  460.  
  461. f12SensorAboveAt = {}
  462. CacheVarInit(f12SensorAboveAt, NUM_FRAMES_OBJ, NUM_OBJ_ENTRIES)
  463.  
  464. dwSensorAdjacentFlags = {}
  465. CacheVarInit(dwSensorAdjacentFlags, NUM_FRAMES_OBJ, NUM_OBJ_ENTRIES)
  466.  
  467. f12SensorAdjacentX = {}
  468. CacheVarInit(f12SensorAdjacentX, NUM_FRAMES_OBJ, NUM_OBJ_ENTRIES)
  469.  
  470. f12SensorAdjacentY = {}
  471. CacheVarInit(f12SensorAdjacentY, NUM_FRAMES_OBJ, NUM_OBJ_ENTRIES)
  472.  
  473. f12SensorAdjacentAt = {}
  474. CacheVarInit(f12SensorAdjacentAt, NUM_FRAMES_OBJ, NUM_OBJ_ENTRIES)
  475. end
  476.  
  477. -- Frame drawing
  478. nFrameRef = -1
  479. nFrameCurrent = 0
  480.  
  481. local function NSMBFrameTick()
  482. nFrameRef = nFrameRef + 1
  483.  
  484. -- memory.writedword(0x2107e44, 0xe12dff1e)
  485. -- memory.writedword(0x21b71c0, 0x6001c001)
  486. -- memory.writedword(0x21b71c4, -0x20000)
  487. -- memory.writedword(0x21b71c8, 0x20000)
  488. -- memory.writedword(0x21b71dc, 0x20000)
  489. -- memory.writedword(0x21b71d4, 0x10001)
  490. -- memory.writedword(0x21b71d8, 0x10000)
  491. end
  492.  
  493. emu.registerbefore(NSMBFrameTick)
  494.  
  495.  
  496.  
  497.  
  498.  
  499.  
  500. local function GetProfString(ProfName)
  501. if ProfName == 0x003 then return "STAGE"
  502. elseif ProfName == 0x015 then return "PLAYER"
  503. elseif ProfName == 0x13C then return "CAMERA"
  504. elseif ProfName == 0x145 then return "LASTACTOR_STAGE"
  505. end
  506.  
  507. return bit.tohex(ProfName, -3)
  508. end
  509.  
  510. collTypeNames = {
  511. [0] = 'Rect',
  512. [1] = 'Round',
  513. [2] = 'Trapezoid Verti',
  514. [3] = 'Trapezoid Horiz'
  515. }
  516.  
  517. local function GetHitboxString(zHitbox)
  518. if zHitbox > 0 then
  519. if zHitbox < 5 then
  520. return string.format("Hitbox %s", collTypeNames[zHitbox - 1])
  521. else
  522. return "Hitbox"
  523. end
  524. end
  525.  
  526. return ""
  527. end
  528.  
  529. local function GetPlatformString(zPlatform, zRotation)
  530. if zPlatform > 0 then return string.format("Platform:%ddeg", zRotation)
  531. end
  532.  
  533. return ""
  534. end
  535.  
  536. local function GetSolidString(zSolid)
  537. if zSolid > 0 then return string.format("Solid")
  538. end
  539.  
  540. return ""
  541. end
  542.  
  543.  
  544. MaxProcessed = 0
  545.  
  546. local function DoCacheDraw()
  547. TextLine = 0
  548. Processed = 0
  549.  
  550. f12ScreenWrapX = CacheGetObjLater(f12WrapX, 0)
  551. fCameraX = Fix12ToFloat(bit.band(f12ScreenWrapX, CacheGetObjLater(f12CameraX, 0)))
  552. fCameraY = Fix12ToFloat(CacheGetObjLater(f12CameraY, 0))
  553. fZoomXY = 1 / Fix12ToFloat(CacheGetObjLater(f12ZoomXY, 0))
  554.  
  555. for i = 0, (NUM_OBJ_ENTRIES - 1) do
  556. j = i * NUM_FRAMES_OBJ
  557.  
  558. bHitbox = 0
  559. bPlatform = 0
  560. bSolid = 0
  561. fDegRotation = 0
  562.  
  563. pPaintExecProf = CacheGetObjLater(pProfExecThis, j)
  564.  
  565. if pPaintExecProf > 0 then
  566.  
  567. if SHOW_HITBOX ~= 0 then
  568. -- Is this a hitbox?
  569. if CacheGetObjLater(bProfExecHitbox, j) > 0 then
  570.  
  571. bHitbox = 1 + CacheGetObjLater(bCollType, j)
  572.  
  573. -- Calculate hitbox screen position, counting for relative camera, zoom, and horizontal stage wrapping
  574. f12WrappedX = bit.band(f12ScreenWrapX, CacheGetObjLater(f12ProfX, j))
  575. fProcScreenX = (Fix12ToFloat(f12WrappedX) - fCameraX)
  576. fProcScreenY = (Fix12ToFloat(CacheGetObjLater(f12ProfY, j)) - fCameraY)
  577.  
  578. fBBOffsetX = Fix12ToFloat(CacheGetObjLater(f12ProfBBX, j))
  579. fBBOffsetY = Fix12ToFloat(CacheGetObjLater(f12ProfBBY, j))
  580.  
  581. fBBWidth = Fix12ToFloat(CacheGetObjLater(f12ProfBBW, j))
  582. fBBHeight = Fix12ToFloat(CacheGetObjLater(f12ProfBBH, j))
  583.  
  584. -- Let's draw trapezoids / Powerline
  585. if bHitbox >= 3 then
  586. fTpr0 = Fix12ToFloat(CacheGetObjLater(f12ProfTrp0, j))
  587. fTpr1 = Fix12ToFloat(CacheGetObjLater(f12ProfTrp1, j))
  588. fTpr2 = Fix12ToFloat(CacheGetObjLater(f12ProfTrp2, j))
  589. fTpr3 = Fix12ToFloat(CacheGetObjLater(f12ProfTrp3, j))
  590.  
  591. if bHitbox == 3 then -- Vertical
  592.  
  593. fTopLeftX = (fProcScreenX + fBBOffsetX - fBBWidth) * fZoomXY
  594. fTopLeftY = (fProcScreenY + fTpr1) * fZoomXY + 192
  595. fTopRightX = (fProcScreenX + fBBOffsetX + fBBWidth) * fZoomXY
  596. fTopRightY = (fProcScreenY + fTpr3) * fZoomXY + 192
  597.  
  598. fBottomLeftX = (fProcScreenX + fBBOffsetX - fBBWidth) * fZoomXY
  599. fBottomLeftY = (fProcScreenY + fTpr0) * fZoomXY + 192
  600. fBottomRightX = (fProcScreenX + fBBOffsetX + fBBWidth) * fZoomXY
  601. fBottomRightY = (fProcScreenY + fTpr2) * fZoomXY + 192
  602.  
  603. else -- Horizontal
  604.  
  605. fTopLeftX = (fProcScreenX + fTpr0) * fZoomXY
  606. fTopLeftY = (fProcScreenY + fBBOffsetY - fBBHeight) * fZoomXY + 192
  607. fTopRightX = (fProcScreenX + fTpr1) * fZoomXY
  608. fTopRightY = (fProcScreenY + fBBOffsetY - fBBHeight) * fZoomXY + 192
  609.  
  610.  
  611. fBottomLeftX = (fProcScreenX + fTpr2) * fZoomXY
  612. fBottomLeftY = (fProcScreenY + fBBOffsetY + fBBHeight) * fZoomXY + 192
  613. fBottomRightX = (fProcScreenX + fTpr3) * fZoomXY
  614. fBottomRightY = (fProcScreenY + fBBOffsetY + fBBHeight) * fZoomXY + 192
  615.  
  616. end
  617.  
  618. -- Top
  619. gui.line(
  620. fTopLeftX,
  621. GetActiveLCDY() + fTopLeftY,
  622. fTopRightX,
  623. GetActiveLCDY() + fTopRightY,
  624. COLOR_HITBOX_OUT)
  625.  
  626. -- Bottom
  627. gui.line(
  628. fBottomLeftX,
  629. GetActiveLCDY() + fBottomLeftY,
  630. fBottomRightX,
  631. GetActiveLCDY() + fBottomRightY,
  632. COLOR_HITBOX_OUT)
  633.  
  634. -- Left
  635. gui.line(
  636. fTopLeftX,
  637. GetActiveLCDY() + fTopLeftY,
  638. fBottomLeftX,
  639. GetActiveLCDY() + fBottomLeftY,
  640. COLOR_HITBOX_OUT)
  641.  
  642. -- Right
  643. gui.line(
  644. fTopRightX,
  645. GetActiveLCDY() + fTopRightY,
  646. fBottomRightX,
  647. GetActiveLCDY() + fBottomRightY,
  648. COLOR_HITBOX_OUT)
  649.  
  650. -- Let's draw a nice circle /Powerline
  651. elseif bHitbox == 2 then
  652. for a = 0, 32 do
  653. b = a * 0.196350 -- pi*2 / 32
  654. fRoundX2 = (fProcScreenX + fBBOffsetX + (math.cos(b) * fBBWidth)) * fZoomXY
  655. fRoundY2 = (fProcScreenY + fBBOffsetY + (math.sin(b) * fBBHeight)) * fZoomXY + 192
  656.  
  657. if a ~= 0 then
  658. gui.line(
  659. fRoundX1,
  660. GetActiveLCDY() + fRoundY1,
  661. fRoundX2,
  662. GetActiveLCDY() + fRoundY2,
  663. COLOR_HITBOX_OUT)
  664. end
  665.  
  666. fRoundX1 = fRoundX2
  667. fRoundY1 = fRoundY2
  668. end
  669. else
  670. fProcScreenX = (fProcScreenX + fBBOffsetX) * fZoomXY
  671. fProcScreenY = (fProcScreenY + fBBOffsetY) * fZoomXY
  672.  
  673. fProcScreenY = fProcScreenY + 192
  674.  
  675. fBBWidth = fBBWidth * fZoomXY
  676. fBBHeight = fBBHeight * fZoomXY
  677.  
  678. gui.box(
  679. fProcScreenX - fBBWidth,
  680. GetActiveLCDY() + fProcScreenY - fBBHeight,
  681. fProcScreenX + fBBWidth,
  682. GetActiveLCDY() + fProcScreenY + fBBHeight,
  683. COLOR_HITBOX_IN, COLOR_HITBOX_OUT)
  684. end
  685. end
  686. end
  687.  
  688. if SHOW_PLATFORM ~= 0 then
  689. -- Is this a platform?
  690. if CacheGetObjLater(bProfExecPlatform, j) > 0 then
  691.  
  692. -- Calculate platform screen position, counting for relative camera, zoom, and horizontal stage wrapping
  693. bPlatform = CacheGetObjLater(bProfExecPlatform, j)
  694.  
  695. fDegRotation = CacheGetObjLater(f12PlatformRotation, j) * 0.0054931640625
  696.  
  697. f12WrappedX = bit.band(f12ScreenWrapX, CacheGetObjLater(f12PlatformLeftX, j))
  698. f12WrappedX2 = bit.band(f12ScreenWrapX, CacheGetObjLater(f12PlatformRightX, j))
  699.  
  700. if f12WrappedX2 < f12WrappedX then
  701. f12WrappedX2 = f12WrappedX2 + (f12ScreenWrapX + 1)
  702. end
  703.  
  704. fLeftX = (Fix12ToFloat(f12WrappedX) - fCameraX) * fZoomXY
  705. fLeftY = (Fix12ToFloat(CacheGetObjLater(f12PlatformLeftY, j)) - fCameraY) * fZoomXY + 192
  706. fRightX = (Fix12ToFloat(f12WrappedX2) - fCameraX) * fZoomXY
  707. fRightY = (Fix12ToFloat(CacheGetObjLater(f12PlatformRightY, j)) - fCameraY) * fZoomXY + 192
  708.  
  709. gui.line(
  710. fLeftX,
  711. GetActiveLCDY() + fLeftY,
  712. fRightX,
  713. GetActiveLCDY() + fRightY,
  714. COLOR_PLATFORM)
  715. end
  716. end
  717.  
  718. if SHOW_SOLID ~= 0 then
  719. -- Is this a solid?
  720. if CacheGetObjLater(bProfExecSolid, j) > 0 then
  721.  
  722. bSolid = 1
  723.  
  724. -- Calculate hitbox screen position, counting for relative camera, zoom, and horizontal stage wrapping
  725. f12WrappedX = bit.band(f12ScreenWrapX, CacheGetObjLater(f12SolidProfX, j))
  726. fProcScreenX = (Fix12ToFloat(f12WrappedX) - fCameraX)
  727. fProcScreenY = (Fix12ToFloat(CacheGetObjLater(f12SolidProfY, j)) - fCameraY)
  728.  
  729. fBBLeft = (Fix12ToFloat(CacheGetObjLater(f12SolidLeft, j)) + fProcScreenX) * fZoomXY
  730. fBBTop = (Fix12ToFloat(CacheGetObjLater(f12SolidTop, j)) + fProcScreenY) * fZoomXY + 192
  731. fBBRight = (Fix12ToFloat(CacheGetObjLater(f12SolidRight, j)) + fProcScreenX) * fZoomXY
  732. fBBBottom = (Fix12ToFloat(CacheGetObjLater(f12SolidBottom, j)) + fProcScreenY) * fZoomXY + 192
  733.  
  734. gui.box(
  735. fBBLeft,
  736. GetActiveLCDY() + fBBTop,
  737. fBBRight,
  738. GetActiveLCDY() + fBBBottom,
  739. COLOR_SOLID_IN, COLOR_SOLID_OUT)
  740. end
  741. end
  742.  
  743. -- Sensors are drawn last to stay on top
  744. if SHOW_SENSOR ~= 0 then
  745. bSensorUses = CacheGetObjLater(bProfExecSensor, j)
  746.  
  747. -- Is this a sensor?
  748. if bSensorUses > 0 then
  749.  
  750. -- Draw below sensor?
  751. if bit.band(bSensorUses, 0x1) ~= 0 then
  752. dwSensorFlags = CacheGetObjLater(dwSensorBelowFlags, j)
  753.  
  754. if bit.band(dwSensorFlags, 0x1) == 0 then
  755.  
  756. -- Point sensor
  757. fPointX = (Fix12ToFloat(bit.band(f12ScreenWrapX, CacheGetObjLater(f12SensorProfX, j) + CacheGetObjLater(f12SensorBelowX, j))) - fCameraX) * fZoomXY
  758. fPointY = (Fix12ToFloat(CacheGetObjLater(f12SensorProfY, j) + CacheGetObjLater(f12SensorBelowY, j)) - fCameraY) * fZoomXY + 192
  759.  
  760. gui.pixel(
  761. fPointX,
  762. GetActiveLCDY() + fPointY,
  763. COLOR_SENSOR_BELOW)
  764. else
  765. -- Line sensor
  766. f12WrappedX = bit.band(f12ScreenWrapX, CacheGetObjLater(f12SensorProfX, j) + CacheGetObjLater(f12SensorBelowX, j))
  767. f12WrappedX2 = bit.band(f12ScreenWrapX, CacheGetObjLater(f12SensorProfX, j) + CacheGetObjLater(f12SensorBelowY, j))
  768.  
  769. if f12WrappedX2 < f12WrappedX then
  770. f12WrappedX2 = f12WrappedX2 + (f12ScreenWrapX + 1)
  771. end
  772.  
  773. fLineX1 = (Fix12ToFloat(f12WrappedX) - fCameraX) * fZoomXY
  774. fLineX2 = (Fix12ToFloat(f12WrappedX2) - fCameraX) * fZoomXY
  775. fLineY = (Fix12ToFloat(CacheGetObjLater(f12SensorProfY, j) + CacheGetObjLater(f12SensorBelowAt, j)) - fCameraY) * fZoomXY + 192
  776.  
  777. gui.line(
  778. fLineX1,
  779. GetActiveLCDY() + fLineY,
  780. fLineX2,
  781. GetActiveLCDY() + fLineY,
  782. COLOR_SENSOR_BELOW)
  783. end
  784. end
  785.  
  786. -- Draw above sensor?
  787. if bit.band(bSensorUses, 0x2) ~= 0 then
  788. dwSensorFlags = CacheGetObjLater(dwSensorAboveFlags, j)
  789.  
  790. if bit.band(dwSensorFlags, 0x1) == 0 then
  791.  
  792. -- Point sensor
  793. fPointX = (Fix12ToFloat(bit.band(f12ScreenWrapX, CacheGetObjLater(f12SensorProfX, j) + CacheGetObjLater(f12SensorAboveX, j))) - fCameraX) * fZoomXY
  794. fPointY = (Fix12ToFloat(CacheGetObjLater(f12SensorProfY, j) - CacheGetObjLater(f12SensorAboveY, j)) - fCameraY) * fZoomXY + 192
  795.  
  796. gui.pixel(
  797. fPointX,
  798. GetActiveLCDY() + fPointY,
  799. COLOR_SENSOR_ABOVE)
  800. else
  801. -- Line sensor
  802. f12WrappedX = bit.band(f12ScreenWrapX, CacheGetObjLater(f12SensorProfX, j) + CacheGetObjLater(f12SensorAboveX, j))
  803. f12WrappedX2 = bit.band(f12ScreenWrapX, CacheGetObjLater(f12SensorProfX, j) + CacheGetObjLater(f12SensorAboveY, j))
  804.  
  805. if f12WrappedX2 < f12WrappedX then
  806. f12WrappedX2 = f12WrappedX2 + (f12ScreenWrapX + 1)
  807. end
  808.  
  809. fLineX1 = (Fix12ToFloat(f12WrappedX) - fCameraX) * fZoomXY
  810. fLineX2 = (Fix12ToFloat(f12WrappedX2) - fCameraX) * fZoomXY
  811. fLineY = (Fix12ToFloat(CacheGetObjLater(f12SensorProfY, j) - CacheGetObjLater(f12SensorAboveAt, j)) - fCameraY) * fZoomXY + 192
  812.  
  813. gui.line(
  814. fLineX1,
  815. GetActiveLCDY() + fLineY,
  816. fLineX2,
  817. GetActiveLCDY() + fLineY,
  818. COLOR_SENSOR_ABOVE)
  819. end
  820. end
  821.  
  822. -- Draw adjacent sensor?
  823. if bit.band(bSensorUses, 0x4) ~= 0 then
  824. dwSensorFlags = CacheGetObjLater(dwSensorAdjacentFlags, j)
  825.  
  826. if bit.band(dwSensorFlags, 0x1) == 0 then
  827.  
  828. -- Point sensor
  829. fPointX = (Fix12ToFloat(bit.band(f12ScreenWrapX, CacheGetObjLater(f12SensorProfX, j) - CacheGetObjLater(f12SensorAdjacentX, j))) - fCameraX) * fZoomXY
  830. fPointX2 = (Fix12ToFloat(bit.band(f12ScreenWrapX, CacheGetObjLater(f12SensorProfX, j) + CacheGetObjLater(f12SensorAdjacentX, j))) - fCameraX) * fZoomXY
  831. fPointY = (Fix12ToFloat(CacheGetObjLater(f12SensorProfY, j) - CacheGetObjLater(f12SensorAdjacentY, j)) - fCameraY) * fZoomXY + 192
  832.  
  833. gui.pixel(
  834. fPointX,
  835. GetActiveLCDY() + fPointY,
  836. COLOR_SENSOR_LEFT)
  837.  
  838. gui.pixel(
  839. fPointX2,
  840. GetActiveLCDY() + fPointY,
  841. COLOR_SENSOR_RIGHT)
  842.  
  843. else
  844. -- Line sensor
  845. f12WrappedX = bit.band(f12ScreenWrapX, CacheGetObjLater(f12SensorProfX, j) - CacheGetObjLater(f12SensorAdjacentAt, j))
  846. f12WrappedX2 = bit.band(f12ScreenWrapX, CacheGetObjLater(f12SensorProfX, j) + CacheGetObjLater(f12SensorAdjacentAt, j))
  847.  
  848. if f12WrappedX2 < f12WrappedX then
  849. f12WrappedX2 = f12WrappedX2 + (f12ScreenWrapX + 1)
  850. end
  851.  
  852. fLineX1 = (Fix12ToFloat(f12WrappedX) - fCameraX) * fZoomXY
  853. fLineX2 = (Fix12ToFloat(f12WrappedX2) - fCameraX) * fZoomXY
  854. fLineY1 = (Fix12ToFloat(CacheGetObjLater(f12SensorProfY, j) - CacheGetObjLater(f12SensorAdjacentX, j)) - fCameraY) * fZoomXY + 192
  855. fLineY2 = (Fix12ToFloat(CacheGetObjLater(f12SensorProfY, j) - CacheGetObjLater(f12SensorAdjacentY, j)) - fCameraY) * fZoomXY + 192
  856.  
  857. gui.line(
  858. fLineX1,
  859. GetActiveLCDY() + fLineY1,
  860. fLineX1,
  861. GetActiveLCDY() + fLineY2,
  862. COLOR_SENSOR_LEFT)
  863.  
  864. gui.line(
  865. fLineX2,
  866. GetActiveLCDY() + fLineY1,
  867. fLineX2,
  868. GetActiveLCDY() + fLineY2,
  869. COLOR_SENSOR_RIGHT)
  870. end
  871. end
  872. end
  873. end
  874.  
  875. if pPaintExecProf ~= 0xDEAD0000 then
  876. if TextLine < (19 * 10) then
  877. gui.text(0, TextLine, string.format("%08X %01d %s %s%s%s", pPaintExecProf, CacheGetObjLater(bProfExecType, j), GetProfString(CacheGetObjLater(wProfExecName, j)), GetHitboxString(bHitbox), GetPlatformString(bPlatform, fDegRotation), GetSolidString(bSolid)), "#AAE000FF", "#000000FF")
  878.  
  879. if CacheGetObjLater(wProfExecName, j) == 0x13C then
  880. CameraAddress = pPaintExecProf
  881. end
  882.  
  883. end
  884.  
  885. if TextLine == (18 * 10) then
  886. gui.text(236, TextLine, "...", "#AAE000FF", "#000000FF")
  887. end
  888.  
  889. TextLine = TextLine + 10
  890. end
  891.  
  892. Processed = Processed + 1
  893. end
  894. end
  895.  
  896. if Processed > MaxProcessed then
  897. MaxProcessed = Processed
  898. end
  899.  
  900. gui.text(142, 0, string.format("Space used: %03d/%03d", MaxProcessed, NUM_OBJ_ENTRIES), "#000000FF", "#AAE000FF")
  901. end
  902.  
  903. offsetsForSensorClass = {
  904. 0x1D0, 0x608, 0x654, 0xC4C, 0x564, 0x42C, 0x5C0
  905. }
  906.  
  907. local function NSMBFrameDraw()
  908.  
  909. -- The emulator draws a new frame when redrawing is needed. We need to find out when it is actually the game that is drawing
  910. -- so that we can have the latest complete frame info stored to be shown later
  911. if nFrameRef == nFrameCurrent then
  912.  
  913. DoCacheDraw()
  914.  
  915. return
  916. end
  917.  
  918. nFrameCurrent = nFrameRef
  919.  
  920. -- Get the camera info for this frame to be shown NUM_FRAMES_OBJ frames later
  921. CacheVarFrameUp(f12CameraX, NUM_FRAMES_OBJ, 0)
  922. CacheSetNow(f12CameraX, 0, memory.readdwordsigned(CameraAddress + 0xD0))
  923.  
  924. CacheVarFrameUp(f12CameraY, NUM_FRAMES_OBJ, 0)
  925. CacheSetNow(f12CameraY, 0, -memory.readdwordsigned(CameraAddress + 0xD4))
  926.  
  927. CacheVarFrameUp(f12ZoomXY, NUM_FRAMES_OBJ, 0)
  928. CacheSetNow(f12ZoomXY, 0, memory.readdwordsigned(0x20CADB4))
  929.  
  930. CacheVarFrameUp(f12WrapX, NUM_FRAMES_OBJ, 0)
  931. CacheSetNow(f12WrapX, 0, memory.readdword(0x2085AA4))
  932.  
  933. -- Move all info one frame into the past so we can show it NUM_FRAMES_OBJ frames later
  934. for i = 0, NUM_OBJ_ENTRIES do
  935. j = i * NUM_FRAMES_OBJ
  936.  
  937. CacheVarFrameUp(pProfExecThis, NUM_FRAMES_OBJ, j)
  938.  
  939. CacheVarFrameUp(wProfExecName, NUM_FRAMES_OBJ, j)
  940.  
  941. CacheVarFrameUp(bProfExecType, NUM_FRAMES_OBJ, j)
  942.  
  943. if SHOW_HITBOX ~= 0 then
  944. CacheVarFrameUp(bProfExecHitbox, NUM_FRAMES_OBJ, j)
  945. end
  946.  
  947. if SHOW_PLATFORM ~= 0 then
  948. CacheVarFrameUp(bProfExecPlatform, NUM_FRAMES_OBJ, j)
  949. end
  950.  
  951. if SHOW_SOLID ~= 0 then
  952. CacheVarFrameUp(bProfExecSolid, NUM_FRAMES_OBJ, j)
  953. end
  954.  
  955. if SHOW_SENSOR ~= 0 then
  956. CacheVarFrameUp(bProfExecSensor, NUM_FRAMES_OBJ, j)
  957. end
  958.  
  959. CacheVarFrameUp(f12ProfX, NUM_FRAMES_OBJ, j)
  960.  
  961. CacheVarFrameUp(f12ProfY, NUM_FRAMES_OBJ, j)
  962.  
  963. if SHOW_HITBOX ~= 0 then
  964. CacheVarFrameUp(f12ProfBBX, NUM_FRAMES_OBJ, j)
  965.  
  966. CacheVarFrameUp(f12ProfBBY, NUM_FRAMES_OBJ, j)
  967.  
  968. CacheVarFrameUp(f12ProfBBW, NUM_FRAMES_OBJ, j)
  969.  
  970. CacheVarFrameUp(f12ProfBBH, NUM_FRAMES_OBJ, j)
  971.  
  972. CacheVarFrameUp(f12ProfTrp0, NUM_FRAMES_OBJ, j)
  973.  
  974. CacheVarFrameUp(f12ProfTrp1, NUM_FRAMES_OBJ, j)
  975.  
  976. CacheVarFrameUp(f12ProfTrp2, NUM_FRAMES_OBJ, j)
  977.  
  978. CacheVarFrameUp(f12ProfTrp3, NUM_FRAMES_OBJ, j)
  979.  
  980. CacheVarFrameUp(bCollType, NUM_FRAMES_OBJ, j)
  981. end
  982.  
  983. if SHOW_PLATFORM ~= 0 then
  984. CacheVarFrameUp(f12PlatformLeftX, NUM_FRAMES_OBJ, j)
  985.  
  986. CacheVarFrameUp(f12PlatformLeftY, NUM_FRAMES_OBJ, j)
  987.  
  988. CacheVarFrameUp(f12PlatformRightX, NUM_FRAMES_OBJ, j)
  989.  
  990. CacheVarFrameUp(f12PlatformRightY, NUM_FRAMES_OBJ, j)
  991.  
  992. CacheVarFrameUp(f12PlatformRotation, NUM_FRAMES_OBJ, j)
  993. end
  994.  
  995. if SHOW_SOLID ~= 0 then
  996. CacheVarFrameUp(f12SolidProfX, NUM_FRAMES_OBJ, j)
  997.  
  998. CacheVarFrameUp(f12SolidProfY, NUM_FRAMES_OBJ, j)
  999.  
  1000. CacheVarFrameUp(f12SolidLeft, NUM_FRAMES_OBJ, j)
  1001.  
  1002. CacheVarFrameUp(f12SolidTop, NUM_FRAMES_OBJ, j)
  1003.  
  1004. CacheVarFrameUp(f12SolidRight, NUM_FRAMES_OBJ, j)
  1005.  
  1006. CacheVarFrameUp(f12SolidBottom, NUM_FRAMES_OBJ, j)
  1007. end
  1008.  
  1009. if SHOW_SENSOR ~= 0 then
  1010. CacheVarFrameUp(f12SensorProfX, NUM_FRAMES_OBJ, j)
  1011.  
  1012. CacheVarFrameUp(f12SensorProfY, NUM_FRAMES_OBJ, j)
  1013.  
  1014. CacheVarFrameUp(dwSensorBelowFlags, NUM_FRAMES_OBJ, j)
  1015.  
  1016. CacheVarFrameUp(f12SensorBelowX, NUM_FRAMES_OBJ, j)
  1017.  
  1018. CacheVarFrameUp(f12SensorBelowY, NUM_FRAMES_OBJ, j)
  1019.  
  1020. CacheVarFrameUp(f12SensorBelowAt, NUM_FRAMES_OBJ, j)
  1021.  
  1022. CacheVarFrameUp(dwSensorAboveFlags, NUM_FRAMES_OBJ, j)
  1023.  
  1024. CacheVarFrameUp(f12SensorAboveX, NUM_FRAMES_OBJ, j)
  1025.  
  1026. CacheVarFrameUp(f12SensorAboveY, NUM_FRAMES_OBJ, j)
  1027.  
  1028. CacheVarFrameUp(f12SensorAboveAt, NUM_FRAMES_OBJ, j)
  1029.  
  1030. CacheVarFrameUp(dwSensorAdjacentFlags, NUM_FRAMES_OBJ, j)
  1031.  
  1032. CacheVarFrameUp(f12SensorAdjacentX, NUM_FRAMES_OBJ, j)
  1033.  
  1034. CacheVarFrameUp(f12SensorAdjacentY, NUM_FRAMES_OBJ, j)
  1035.  
  1036. CacheVarFrameUp(f12SensorAdjacentAt, NUM_FRAMES_OBJ, j)
  1037. end
  1038. end
  1039.  
  1040.  
  1041.  
  1042. -- Go through ordered execution list
  1043. pLinkExecute = GetNextExecuteLinkPtr(0)
  1044.  
  1045. j = 0
  1046. i = 0
  1047. while (pLinkExecute > 0) do
  1048. pProfExec = memory.readdword(pLinkExecute + 0x8)
  1049.  
  1050. CacheSetNow(pProfExecThis, j, pProfExec)
  1051.  
  1052. CacheSetNow(wProfExecName, j, memory.readword(pProfExec + 0xC))
  1053. CacheSetNow(bProfExecType, j, memory.readbyte(pProfExec + 0x12))
  1054.  
  1055. if SHOW_HITBOX ~= 0 then
  1056. CacheSetNow(bProfExecHitbox, j, 0)
  1057. end
  1058.  
  1059. if SHOW_PLATFORM ~= 0 then
  1060. CacheSetNow(bProfExecPlatform, j, 0)
  1061. end
  1062.  
  1063. if SHOW_SOLID ~= 0 then
  1064. CacheSetNow(bProfExecSolid, j, 0)
  1065. end
  1066.  
  1067. if SHOW_SENSOR ~= 0 then
  1068. CacheSetNow(bProfExecSensor, j, 0)
  1069. end
  1070.  
  1071. j = j + NUM_FRAMES_OBJ
  1072. i = i + 1
  1073.  
  1074. -- Find the next one
  1075. pLinkExecute = GetNextExecuteLinkPtr(pLinkExecute)
  1076. end
  1077.  
  1078. LastExecIndex = i
  1079.  
  1080. for i = LastExecIndex, NUM_OBJ_ENTRIES do
  1081. j = i * NUM_FRAMES_OBJ
  1082.  
  1083. CacheSetNow(pProfExecThis, j, 0)
  1084.  
  1085. if SHOW_HITBOX ~= 0 then
  1086. CacheSetNow(bProfExecHitbox, j, 0)
  1087. end
  1088.  
  1089. if SHOW_PLATFORM ~= 0 then
  1090. CacheSetNow(bProfExecPlatform, j, 0)
  1091. end
  1092.  
  1093. if SHOW_SOLID ~= 0 then
  1094. CacheSetNow(bProfExecSolid, j, 0)
  1095. end
  1096.  
  1097. if SHOW_SENSOR ~= 0 then
  1098. CacheSetNow(bProfExecSensor, j, 0)
  1099. end
  1100. end
  1101.  
  1102. if SHOW_HITBOX ~= 0 then
  1103. -- Go through all complex colliders
  1104. pCColl = GetNextComplexColliderLinkPtr(0)
  1105.  
  1106. j = 0
  1107. i = 0
  1108. while pCColl > 0 do
  1109. pCColProfThis = memory.readdword(pCColl + 0x4)
  1110.  
  1111. for k = 0, NUM_OBJ_ENTRIES do
  1112. l = k * NUM_FRAMES_OBJ
  1113.  
  1114. pProfExec = CacheGetNow(pProfExecThis, l)
  1115.  
  1116. if pProfExec > 0 then
  1117. if pProfExec == pCColProfThis then
  1118.  
  1119. -- Already had one before? Then find an empty slot
  1120. if CacheGetNow(bProfExecHitbox, l) > 0 then
  1121. for a = LastExecIndex, NUM_OBJ_ENTRIES do
  1122. b = a * NUM_FRAMES_OBJ
  1123.  
  1124. if CacheGetNow(pProfExecThis, b) == 0 then
  1125. l = b
  1126. CacheSetNow(pProfExecThis, l, 0xDEAD0000)
  1127.  
  1128. CacheSetNow(bProfExecHitbox, l, 1)
  1129.  
  1130. CacheSetNow(f12ProfX, l, memory.readdwordsigned(pCColProfThis + 0x60))
  1131. CacheSetNow(f12ProfY, l, -memory.readdwordsigned(pCColProfThis + 0x64))
  1132. CacheSetNow(f12ProfBBX, l, memory.readdwordsigned(pCColl + 0x14))
  1133. CacheSetNow(f12ProfBBY, l, -memory.readdwordsigned(pCColl + 0x18))
  1134. CacheSetNow(f12ProfBBW, l, memory.readdwordsigned(pCColl + 0x1C))
  1135. CacheSetNow(f12ProfBBH, l, memory.readdwordsigned(pCColl + 0x20))
  1136. CacheSetNow(f12ProfTrp0, l, memory.readdwordsigned(pCColl + 0x8C))
  1137. CacheSetNow(f12ProfTrp1, l, memory.readdwordsigned(pCColl + 0x90))
  1138. CacheSetNow(f12ProfTrp2, l, memory.readdwordsigned(pCColl + 0x94))
  1139. CacheSetNow(f12ProfTrp3, l, memory.readdwordsigned(pCColl + 0x98))
  1140.  
  1141. CacheSetNow(bCollType, l, memory.readbyte(pCColl + 0xAA))
  1142. break
  1143. end
  1144. end
  1145. end
  1146.  
  1147. CacheSetNow(bProfExecHitbox, l, 1)
  1148.  
  1149. CacheSetNow(f12ProfX, l, memory.readdwordsigned(pCColProfThis + 0x60))
  1150. CacheSetNow(f12ProfY, l, -memory.readdwordsigned(pCColProfThis + 0x64))
  1151. CacheSetNow(f12ProfBBX, l, memory.readdwordsigned(pCColl + 0x14))
  1152. CacheSetNow(f12ProfBBY, l, -memory.readdwordsigned(pCColl + 0x18))
  1153. CacheSetNow(f12ProfBBW, l, memory.readdwordsigned(pCColl + 0x1C))
  1154. CacheSetNow(f12ProfBBH, l, memory.readdwordsigned(pCColl + 0x20))
  1155. CacheSetNow(f12ProfTrp0, l, memory.readdwordsigned(pCColl + 0x8C))
  1156. CacheSetNow(f12ProfTrp1, l, memory.readdwordsigned(pCColl + 0x90))
  1157. CacheSetNow(f12ProfTrp2, l, memory.readdwordsigned(pCColl + 0x94))
  1158. CacheSetNow(f12ProfTrp3, l, memory.readdwordsigned(pCColl + 0x98))
  1159.  
  1160. CacheSetNow(bCollType, l, memory.readbyte(pCColl + 0xAA))
  1161. end
  1162. end
  1163. end
  1164.  
  1165. j = j + NUM_FRAMES_OBJ
  1166. i = i + 1
  1167.  
  1168. -- Find the next one
  1169. pCColl = GetNextComplexColliderLinkPtr(pCColl)
  1170. end
  1171. end
  1172.  
  1173. if SHOW_PLATFORM ~= 0 then
  1174. -- Go through all misc colliders
  1175. pBColl = GetNextMiscColliderLinkPtr(0)
  1176.  
  1177. j = 0
  1178. i = 0
  1179. while pBColl > 0 do
  1180. pBColProfThis = memory.readdword(pBColl + 0x4)
  1181.  
  1182. for k = 0, NUM_OBJ_ENTRIES do
  1183. l = k * NUM_FRAMES_OBJ
  1184.  
  1185. pProfExec = CacheGetNow(pProfExecThis, l)
  1186.  
  1187. if pProfExec > 0 then
  1188. if pProfExec == pBColProfThis then
  1189.  
  1190. -- Already had one before? Then find an empty slot
  1191. if CacheGetNow(bProfExecPlatform, l) > 0 then
  1192. for a = LastExecIndex, NUM_OBJ_ENTRIES do
  1193. b = a * NUM_FRAMES_OBJ
  1194.  
  1195. if CacheGetNow(pProfExecThis, b) == 0 then
  1196. l = b
  1197. CacheSetNow(pProfExecThis, l, 0xDEAD0000)
  1198.  
  1199. CacheSetNow(bProfExecPlatform, l, 1 + memory.readbyte(pBColl + 0x50))
  1200.  
  1201. CacheSetNow(f12PlatformRotation, l, memory.readword(pBColl + 0x4C))
  1202.  
  1203. CacheSetNow(f12PlatformLeftX, l, memory.readdwordsigned(pBColl + 0x24))
  1204. CacheSetNow(f12PlatformLeftY, l, -memory.readdwordsigned(pBColl + 0x28))
  1205. CacheSetNow(f12PlatformRightX, l, memory.readdwordsigned(pBColl + 0x18))
  1206. CacheSetNow(f12PlatformRightY, l, -memory.readdwordsigned(pBColl + 0x1C))
  1207. break
  1208. end
  1209. end
  1210. end
  1211.  
  1212. CacheSetNow(bProfExecPlatform, l, 1 + memory.readbyte(pBColl + 0x50))
  1213.  
  1214. CacheSetNow(f12PlatformRotation, l, memory.readword(pBColl + 0x4C))
  1215.  
  1216. CacheSetNow(f12PlatformLeftX, l, memory.readdwordsigned(pBColl + 0x24))
  1217. CacheSetNow(f12PlatformLeftY, l, -memory.readdwordsigned(pBColl + 0x28))
  1218. CacheSetNow(f12PlatformRightX, l, memory.readdwordsigned(pBColl + 0x18))
  1219. CacheSetNow(f12PlatformRightY, l, -memory.readdwordsigned(pBColl + 0x1C))
  1220. end
  1221. end
  1222. end
  1223.  
  1224. j = j + NUM_FRAMES_OBJ
  1225. i = i + 1
  1226.  
  1227. -- Find the next one
  1228. pBColl = GetNextMiscColliderLinkPtr(pBColl)
  1229. end
  1230. end
  1231.  
  1232. if SHOW_SOLID ~= 0 then
  1233. -- Go through all solid colliders
  1234. pSColl = GetNextSolidColliderLinkPtr(0)
  1235.  
  1236. j = 0
  1237. i = 0
  1238. while pSColl > 0 do
  1239. pSColProfThis = memory.readdword(pSColl + 0x0)
  1240.  
  1241. for k = 0, NUM_OBJ_ENTRIES do
  1242. l = k * NUM_FRAMES_OBJ
  1243.  
  1244. pProfExec = CacheGetNow(pProfExecThis, l)
  1245.  
  1246. if pProfExec > 0 then
  1247. if pProfExec == pSColProfThis then
  1248.  
  1249. -- Already had one before? Then find an empty slot
  1250. if CacheGetNow(bProfExecSolid, l) > 0 then
  1251. for a = LastExecIndex, NUM_OBJ_ENTRIES do
  1252. b = a * NUM_FRAMES_OBJ
  1253.  
  1254. if CacheGetNow(pProfExecThis, b) == 0 then
  1255. l = b
  1256. CacheSetNow(pProfExecThis, l, 0xDEAD0000)
  1257.  
  1258. CacheSetNow(bProfExecSolid, l, 1)
  1259.  
  1260. CacheSetNow(f12SolidProfX, l, memory.readdwordsigned(pSColl + 0x58))
  1261. CacheSetNow(f12SolidProfY, l, -memory.readdwordsigned(pSColl + 0x5C))
  1262.  
  1263. CacheSetNow(f12SolidLeft, l, memory.readdwordsigned(pSColl + 0x28))
  1264. CacheSetNow(f12SolidTop, l, -memory.readdwordsigned(pSColl + 0x2C))
  1265. CacheSetNow(f12SolidRight, l, -memory.readdwordsigned(pSColl + 0x34))
  1266. CacheSetNow(f12SolidBottom, l, -memory.readdwordsigned(pSColl + 0x38))
  1267. break
  1268. end
  1269. end
  1270. end
  1271.  
  1272. CacheSetNow(bProfExecSolid, l, 1)
  1273.  
  1274. CacheSetNow(f12SolidProfX, l, memory.readdwordsigned(pSColl + 0x58))
  1275. CacheSetNow(f12SolidProfY, l, -memory.readdwordsigned(pSColl + 0x5C))
  1276.  
  1277. CacheSetNow(f12SolidLeft, l, memory.readdwordsigned(pSColl + 0x28))
  1278. CacheSetNow(f12SolidTop, l, -memory.readdwordsigned(pSColl + 0x2C))
  1279. CacheSetNow(f12SolidRight, l, memory.readdwordsigned(pSColl + 0x34))
  1280. CacheSetNow(f12SolidBottom, l, -memory.readdwordsigned(pSColl + 0x38))
  1281. end
  1282. end
  1283. end
  1284.  
  1285. j = j + NUM_FRAMES_OBJ
  1286. i = i + 1
  1287.  
  1288. -- Find the next one
  1289. pSColl = GetNextSolidColliderLinkPtr(pSColl)
  1290. end
  1291. end
  1292.  
  1293. if SHOW_SENSOR ~= 0 then
  1294. -- Go through all sensors (might be multipe in one profile)
  1295. pDraw = GetNextDrawLinkPtr(0)
  1296.  
  1297. j = 0
  1298. i = 0
  1299. while pDraw > 0 do
  1300. pDrawThis = memory.readdword(pDraw + 0x8)
  1301.  
  1302. for zz, SensorOffset in pairs(offsetsForSensorClass) do
  1303. pSensorClass = pDrawThis + SensorOffset
  1304.  
  1305. if memory.readdword(pSensorClass) == 0x20C7008 then
  1306.  
  1307. pSensorProfThis = memory.readdword(pSensorClass + 0x4)
  1308.  
  1309. pBelow = memory.readdword(pSensorClass + 0x8)
  1310. pAbove = memory.readdword(pSensorClass + 0xC)
  1311. pAdjacent = memory.readdword(pSensorClass + 0x10)
  1312.  
  1313. f12SensorX = memory.readdwordsigned(pSensorProfThis + 0x60)
  1314. f12SensorY = -memory.readdwordsigned(pSensorProfThis + 0x64)
  1315.  
  1316. for k = 0, NUM_OBJ_ENTRIES do
  1317. l = k * NUM_FRAMES_OBJ
  1318.  
  1319. pProfExec = CacheGetNow(pProfExecThis, l)
  1320.  
  1321. if pProfExec > 0 then
  1322. if pProfExec == pSensorProfThis then
  1323.  
  1324. -- Already had one before? Then find an empty slot
  1325. if CacheGetNow(bProfExecSensor, l) > 0 then
  1326. for a = LastExecIndex, NUM_OBJ_ENTRIES do
  1327. b = a * NUM_FRAMES_OBJ
  1328.  
  1329. if CacheGetNow(pProfExecThis, b) == 0 then
  1330. l = b
  1331. CacheSetNow(pProfExecThis, l, 0xDEAD0000)
  1332.  
  1333. CacheSetNow(f12SensorProfX, l, f12SensorX)
  1334. CacheSetNow(f12SensorProfY, l, f12SensorY)
  1335.  
  1336. bSensorUses = 0
  1337.  
  1338. if pBelow > 0 then
  1339. -- Use below sensor for drawing
  1340. bSensorUses = bit.bor(bSensorUses, 0x1)
  1341.  
  1342. CacheSetNow(dwSensorBelowFlags, l, memory.readdword(pBelow + 0x0))
  1343. CacheSetNow(f12SensorBelowX, l, memory.readdword(pBelow + 0x4))
  1344. CacheSetNow(f12SensorBelowY, l, memory.readdword(pBelow + 0x8))
  1345. CacheSetNow(f12SensorBelowAt, l, memory.readdword(pBelow + 0xC))
  1346. end
  1347.  
  1348. if pAbove > 0 then
  1349. -- Use above sensor for drawing
  1350. bSensorUses = bit.bor(bSensorUses, 0x2)
  1351.  
  1352. CacheSetNow(dwSensorAboveFlags, l, memory.readdword(pAbove + 0x0))
  1353. CacheSetNow(f12SensorAboveX, l, memory.readdword(pAbove + 0x4))
  1354. CacheSetNow(f12SensorAboveY, l, memory.readdword(pAbove + 0x8))
  1355. CacheSetNow(f12SensorAboveAt, l, memory.readdword(pAbove + 0xC))
  1356. end
  1357.  
  1358. if pAdjacent > 0 then
  1359. -- Use adjacent sensor for drawing
  1360. bSensorUses = bit.bor(bSensorUses, 0x4)
  1361.  
  1362. CacheSetNow(dwSensorAdjacentFlags, l, memory.readdword(pAdjacent + 0x0))
  1363. CacheSetNow(f12SensorAdjacentX, l, memory.readdword(pAdjacent + 0x4))
  1364. CacheSetNow(f12SensorAdjacentY, l, memory.readdword(pAdjacent + 0x8))
  1365. CacheSetNow(f12SensorAdjacentAt, l, memory.readdword(pAdjacent + 0xC))
  1366. end
  1367.  
  1368. CacheSetNow(bProfExecSensor, l, bSensorUses)
  1369. break
  1370. end
  1371. end
  1372. end
  1373.  
  1374. CacheSetNow(f12SensorProfX, l, f12SensorX)
  1375. CacheSetNow(f12SensorProfY, l, f12SensorY)
  1376.  
  1377. bSensorUses = 0
  1378.  
  1379. if pBelow > 0 then
  1380. -- Use below sensor for drawing
  1381. bSensorUses = bit.bor(bSensorUses, 0x1)
  1382.  
  1383. CacheSetNow(dwSensorBelowFlags, l, memory.readdword(pBelow + 0x0))
  1384. CacheSetNow(f12SensorBelowX, l, memory.readdword(pBelow + 0x4))
  1385. CacheSetNow(f12SensorBelowY, l, memory.readdword(pBelow + 0x8))
  1386. CacheSetNow(f12SensorBelowAt, l, memory.readdword(pBelow + 0xC))
  1387. end
  1388.  
  1389. if pAbove > 0 then
  1390. -- Use above sensor for drawing
  1391. bSensorUses = bit.bor(bSensorUses, 0x2)
  1392.  
  1393. --memory.writedword(pAbove + 0x0, bit.band(memory.readdword(pAbove + 0x0), 0xFFFFFFFE))
  1394.  
  1395. CacheSetNow(dwSensorAboveFlags, l, memory.readdword(pAbove + 0x0))
  1396. CacheSetNow(f12SensorAboveX, l, memory.readdword(pAbove + 0x4))
  1397. CacheSetNow(f12SensorAboveY, l, memory.readdword(pAbove + 0x8))
  1398. CacheSetNow(f12SensorAboveAt, l, memory.readdword(pAbove + 0xC))
  1399. end
  1400.  
  1401. if pAdjacent > 0 then
  1402. -- Use adjacent sensor for drawing
  1403. bSensorUses = bit.bor(bSensorUses, 0x4)
  1404.  
  1405. --memory.writedword(pAdjacent + 0x0, bit.band(memory.readdword(pAdjacent + 0x0), 0xFFFFFFFE))
  1406.  
  1407.  
  1408. CacheSetNow(dwSensorAdjacentFlags, l, memory.readdword(pAdjacent + 0x0))
  1409. CacheSetNow(f12SensorAdjacentX, l, memory.readdword(pAdjacent + 0x4))
  1410. CacheSetNow(f12SensorAdjacentY, l, memory.readdword(pAdjacent + 0x8))
  1411. CacheSetNow(f12SensorAdjacentAt, l, memory.readdword(pAdjacent + 0xC))
  1412. end
  1413.  
  1414. CacheSetNow(bProfExecSensor, l, bSensorUses)
  1415. end
  1416. end
  1417. end
  1418. end
  1419. end
  1420.  
  1421. j = j + NUM_FRAMES_OBJ
  1422. i = i + 1
  1423.  
  1424. -- Find the next one
  1425. pDraw = GetNextDrawLinkPtr(pDraw)
  1426. end
  1427. end
  1428.  
  1429. DoCacheDraw()
  1430. end
  1431.  
  1432. -- Everything is delayed by 3 frames from gui.register() once the game has done a complete frame
  1433. gui.register(NSMBFrameDraw)
Advertisement
Add Comment
Please, Sign In to add comment