Advertisement
exodus122

ganonfloor_dolphin.lua

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