Advertisement
exodus122

ganonfloor_dolphin.lua

Jan 20th, 2024 (edited)
1,158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.28 KB | None | 0 0
  1. -- modified version of MrCheeze's lua script which was for bizhawk
  2. -- https://github.com/MrCheeze/zelda64-ganonfloor
  3. -- this version is used with Dolphin 5.0-14344 and Cheat Engine lua engine
  4. -- oot version 1.2
  5.  
  6. ramStart = readPointer("Dolphin.exe+0xC4DC70")+0xE74000
  7.  
  8. function to_signed_32(num)
  9.     if num > 2147483648 then
  10.         num = num - (2 * 2147483648)
  11.         return num
  12.     else return num
  13.     end
  14. end
  15.  
  16. function to_signed_16(num)
  17.     if num > 32768 then
  18.         num = num - (2 * 32768)
  19.         return num
  20.     else return num
  21.     end
  22. end
  23.  
  24. function read_u32_be(addr)
  25.     val = readInteger(ramStart+addr)
  26.     return ((val & 0xFF) << 24)
  27.            | ((val & 0xFF00) << 8)
  28.            | ((val >> 8) & 0xFF00)
  29.            | ((val >> 24) & 0xFF);
  30. end
  31.  
  32. function read_s32_be(addr)
  33.     val = readInteger(ramStart+addr)
  34.     newval = ((val & 0xFF) << 24)
  35.            | ((val & 0xFF00) << 8)
  36.            | ((val >> 8) & 0xFF00)
  37.            | ((val >> 24) & 0xFF);
  38.     return to_signed_32(newval)
  39. end
  40.  
  41. function read_u16_be(addr)
  42.     val = readSmallInteger(ramStart+addr)
  43.     return ((val & 0xFF) << 8)
  44.            | ((val >> 8) & 0xFF);
  45. end
  46.  
  47. function read_s16_be(addr)
  48.     val = readSmallInteger(ramStart+addr)
  49.     newval = ((val & 0xFF) << 8)
  50.            | ((val >> 8) & 0xFF);
  51.     return to_signed_16(newval)
  52. end
  53.  
  54. function readbyte(addr)
  55.     return readBytes(ramStart+addr, 1)
  56. end
  57.  
  58. addr_colCtx = 0x1C9520 -- NTSC 1.2
  59. addr_exitList = 0x1DAB64 -- NTSC 1.2
  60.  
  61. exitList = read_u32_be(addr_exitList)
  62.  
  63. colCtx_colHeader = read_u32_be(addr_colCtx)
  64. colCtx_lookupTbl = read_u32_be(addr_colCtx+0x40)
  65. colCtx_polyNodes_tbl = read_u32_be(addr_colCtx+0x48)
  66. colCtx_polyNodes_polyCheckTbl = read_u32_be(addr_colCtx+0x4C)
  67. colCtx_dyna_polyList = read_u32_be(addr_colCtx+0x50+0x13F0)
  68. colCtx_dyna_vtxList = read_u32_be(addr_colCtx+0x50+0x13F4)
  69.  
  70. colCtx_colHeader_vtxList = read_u32_be(colCtx_colHeader - 0x80000000 + 0x10)
  71. colCtx_colHeader_polyList = read_u32_be(colCtx_colHeader - 0x80000000 + 0x18)
  72. colCtx_colHeader_surfaceTypeList = read_u32_be(colCtx_colHeader - 0x80000000 + 0x1C)
  73.  
  74. lookup_entry_count = read_s32_be(addr_colCtx+0x1C)*read_s32_be(addr_colCtx+0x20)*read_s32_be(addr_colCtx+0x24)
  75.  
  76. already_dumped_node_indexes = {}
  77.  
  78. dyna_polyListMax = read_u32_be(addr_colCtx + 0x50 + 0x1408)
  79. dyna_vtxListMax = read_u32_be(addr_colCtx + 0x50 + 0x140C)
  80.  
  81. dyna_polyCount = 0
  82. dyna_vtxCount = 0
  83.  
  84. for i=0,49 do
  85.     if (bAnd(read_u16_be(addr_colCtx + 0x50 + 0x138C + 2*i), 0x0001)) ~= 0 then
  86.         -- bgActor #i is in use
  87.         bgActor_colHeader = read_u32_be(addr_colCtx + 0x50 + 0x4 + 0x64*i + 4)
  88.        
  89.         bgActor_vtxCount = read_u16_be(bgActor_colHeader - 0x80000000 + 0xC)
  90.         dyna_vtxCount = dyna_vtxCount + bgActor_vtxCount
  91.  
  92.         bgActor_polyCount = read_u16_be(bgActor_colHeader - 0x80000000 + 0x14)
  93.         dyna_polyCount = dyna_polyCount + bgActor_polyCount
  94.     end
  95. end
  96.  
  97. print(string.format("%08X colCtx_dyna_vtxList (used=%d/%d)", colCtx_dyna_vtxList, dyna_vtxCount, dyna_vtxListMax))
  98. if dyna_vtxCount>dyna_vtxListMax then
  99.     vtx_overflow_start = colCtx_dyna_vtxList + 6*dyna_vtxListMax
  100.     vtx_overflow_end = colCtx_dyna_vtxList + 6*dyna_vtxCount
  101.     print(string.format("!!! dyna vtxList overflow into %08X-%08X !!!", vtx_overflow_start, vtx_overflow_end))
  102. end
  103. print(string.format("%08X colCtx_dyna_polyList (used=%d/%d)", colCtx_dyna_polyList, dyna_polyCount, dyna_polyListMax))
  104. if dyna_polyCount>dyna_polyListMax then
  105.     poly_overflow_start = colCtx_dyna_polyList + 0x10*dyna_polyListMax
  106.     poly_overflow_end = colCtx_dyna_polyList + 0x10*dyna_polyCount
  107.     print(string.format("!!! dyna polyList overflow into %08X-%08X !!!", poly_overflow_start, poly_overflow_end))
  108. end
  109. print(string.format("%08X colCtx_polyNodes_polyCheckTbl", colCtx_polyNodes_polyCheckTbl))
  110. print(string.format("%08X colCtx_polyNodes_tbl", colCtx_polyNodes_tbl))
  111. print(string.format("%08X colCtx_lookupTbl", colCtx_lookupTbl))
  112. print(string.format("%08X exitList", exitList))
  113. print(string.format("%08X colCtx_colHeader_surfaceTypeList", colCtx_colHeader_surfaceTypeList))
  114. print(string.format("%08X colCtx_colHeader_polyList", colCtx_colHeader_polyList))
  115. print(string.format("%08X colCtx_colHeader_vtxList", colCtx_colHeader_vtxList))
  116. print(string.format("%08X colCtx_colHeader", colCtx_colHeader))
  117.  
  118. for i=0,lookup_entry_count-1 do
  119.     for j=0,1 do -- include floors and walls, but not ceilings
  120.        
  121.         nodeIndex = read_u16_be(colCtx_lookupTbl - 0x80000000 + 6*i + 2*j)
  122.        
  123.         while nodeIndex ~= 0xFFFF and not already_dumped_node_indexes[nodeIndex] do
  124.             polyId = read_u16_be(colCtx_polyNodes_tbl - 0x80000000 + 4*nodeIndex)
  125.             polySurfaceTypeId = read_u16_be(colCtx_colHeader_polyList - 0x80000000 + 0x10*polyId)
  126.             surfaceExitIndex = bAnd(readbyte(colCtx_colHeader_surfaceTypeList - 0x80000000 + 8*polySurfaceTypeId + 2), 0x1F)
  127.            
  128.             if (surfaceExitIndex ~= 0) then
  129.            
  130.                 exitValue = read_u16_be(exitList - 0x80000000 + 2*(surfaceExitIndex-1))
  131.            
  132.                 polyVertIdA = bAnd(read_u16_be(colCtx_colHeader_polyList - 0x80000000 + 0x10*polyId + 2), 0x1FFF)
  133.                 polyVertIdB = bAnd(read_u16_be(colCtx_colHeader_polyList - 0x80000000 + 0x10*polyId + 4), 0x1FFF)
  134.                 polyVertIdC = read_u16_be(colCtx_colHeader_polyList - 0x80000000 + 0x10*polyId + 6)
  135.                
  136.                 vertAX = read_s16_be(colCtx_colHeader_vtxList - 0x80000000 + 6*polyVertIdA + 0)
  137.                 vertAY = read_s16_be(colCtx_colHeader_vtxList - 0x80000000 + 6*polyVertIdA + 2)
  138.                 vertAZ = read_s16_be(colCtx_colHeader_vtxList - 0x80000000 + 6*polyVertIdA + 4)
  139.                 vertBX = read_s16_be(colCtx_colHeader_vtxList - 0x80000000 + 6*polyVertIdB + 0)
  140.                 vertBY = read_s16_be(colCtx_colHeader_vtxList - 0x80000000 + 6*polyVertIdB + 2)
  141.                 vertBZ = read_s16_be(colCtx_colHeader_vtxList - 0x80000000 + 6*polyVertIdB + 4)
  142.                 vertCX = read_s16_be(colCtx_colHeader_vtxList - 0x80000000 + 6*polyVertIdC + 0)
  143.                 vertCY = read_s16_be(colCtx_colHeader_vtxList - 0x80000000 + 6*polyVertIdC + 2)
  144.                 vertCZ = read_s16_be(colCtx_colHeader_vtxList - 0x80000000 + 6*polyVertIdC + 4)
  145.                
  146.                 print(string.format("exit %04X - nodeIndex %04X polyId %04X surfaceType %04X - (%d,%d,%d), (%d,%d,%d), (%d,%d,%d)", exitValue, nodeIndex, polyId, polySurfaceTypeId, vertAX,vertAY,vertAZ, vertBX,vertBY,vertBZ, vertCX,vertCY,vertCZ))
  147.             end
  148.            
  149.             already_dumped_node_indexes[nodeIndex] = true
  150.            
  151.             nodeIndex = read_u16_be(colCtx_polyNodes_tbl - 0x80000000 + 4*nodeIndex + 2)
  152.         end
  153.     end
  154. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement