Advertisement
fig02

mm us lua

Feb 26th, 2022
1,941
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.06 KB | None | 0 0
  1. -- Decompiled using luadec 2.2 rev: 895d923 for Lua 5.1 from https://github.com/viruscamp/luadec
  2. -- Command line: 06_Unzse0.727.lua
  3.  
  4. -- params : ...
  5. -- function num : 0
  6. HookFunc_AfterInst = function(addr, instr)
  7.   -- function num : 0_0
  8.  
  9.   -- EffectSs_Spawn
  10.   if addr == 0x800B054C and instr == 0xC040B22 then
  11.     -- change a0 when calling ZeldaArena_MallocR to a large number so the malloc fails
  12.     n64GPRWrite32(4, 0x800000)
  13.   else if addr == 0x800B0554 and instr == 0x8FA30028 then
  14.       -- read vramStart instead of loadedRamAddr when checking for early return
  15.       -- change the malloc destination to vram instead of ram
  16.       local v1 = n64GPRRead32(3)
  17.       local vramStart = n64MemRead32(v1 + 8)
  18.       n64GPRWrite32(2, vramStart)
  19.   else
  20.     do
  21.       -- Actor_LoadOverlay, hook on load allocType
  22.       if addr == 0x800BAD20 and instr == 0x9462001C then
  23.         -- these first two lines are doing nothing as far as I can tell
  24.         local v1 = n64GPRRead32(3)
  25.         n64MemRead16(v1 + 0x1C, 2)
  26.         -- make every actor load as ALLOCTYPE_PERMANENT
  27.         n64GPRWrite32(v0, 2)
  28.       else
  29.         do
  30.           -- ZeldaArena_MallocR call in the ALLOCTYPE_PERMANENT block
  31.           -- change alloc size to be too large for it to work
  32.           if addr == 0x800BAD7C and instr == 0xC040B22 then
  33.             n64GPRWrite32(4, 0x800000)
  34.           else
  35.             -- change the malloc destination to vram instead of ram
  36.             if addr == 0x800BAD84 and instr == 0x8FA30024 then
  37.               local v1 = n64GPRRead32(3)
  38.               local vramStart = n64MemRead32(v1 + 8)
  39.               n64GPRWrite32(2, vramStart)
  40.             else
  41.               do
  42.                 -- anti-epilepsy freeze flash when killing enemies
  43.                 if addr == 0x80167AE0 and instr == 0x304B0001 then
  44.                   local l_1_7 = n64GPRRead32(2)
  45.                   local l_1_8 = (bit.band)(l_1_7, 3)
  46.                   n64GPRWrite32(11, l_1_8)
  47.                 else
  48.                   do
  49.                     -- equivalent of oot's `Environment_GetPixelDepth`
  50.                     -- could be motion blur related
  51.                     -- i dont know what n64WaitGTaskDone does
  52.                     if addr == 0x80178A54 and instr == 0x3C0F8020 then
  53.                       n64WaitGTaskDone()
  54.                     end
  55.                     return
  56.                   end
  57.                 end
  58.               end
  59.             end
  60.           end
  61.         end
  62.       end
  63.     end
  64.   end
  65.   end
  66. end
  67.  
  68. BeforGTask = function()
  69.   -- function num : 0_1
  70.   n64ResetParameter("FramesPerGTask")
  71.   -- check address of graphics context (??????????)
  72.   -- this should always be the same
  73.   -- guess they thought it was an identifier for the current gamestate
  74.   if n64MemRead32(0x803E6B20) == 0x801F9CB8 then
  75.     local frameRate = 0
  76.     local gamestateMain = n64MemRead32(0x803E6B20 + 4)
  77.     -- check if main is Play_Main
  78.     if gamestateMain == 0x80168F64 then
  79.       frameRate = 2
  80.       local pauseState = n64MemRead16(0x803E6B20 + 0x16F1C)
  81.       if pauseState ~= 0 then
  82.         -- set 60 fps if pause/game over is not open (i think???)
  83.         frameRate = 0
  84.       end
  85.       local csCtx = 0x803E6B20 + 0x1F24
  86.       local sceneCsCount = n64MemRead32(csCtx)
  87.       if sceneCsCount == 0x05(000000) then
  88.         local csSegment = n64MemRead32(csCtx + 4)
  89.         local numCommands = n64MemRead32(csSegment)
  90.         local csLength = n64MemRead32(csSegment + 4)
  91.         local cmd1 = n64MemRead32(csSegment + 8)
  92.         local cmd1_data = n64MemRead32(csSegment + 12)
  93.         -- checking for cutscene 0 in termina field: giants cutscene
  94.         -- lag toward the end of the cutscene to sync with music
  95.         if numCommands == 12 and csLength == 1626 and cmd1 == 90 and cmd1_data == 5684 then
  96.           local frameNum = n64MemRead16(csCtx + 16)
  97.           if frameNum >= 1120 and frameNum <= 1616 then
  98.             frameRate = 3
  99.           end
  100.         end
  101.       end
  102.     end
  103.     do
  104.       do
  105.         do
  106.           n64SetParameter("FramesPerGTask", frameRate)
  107.           -- this is combination of scene number and scene config
  108.           -- scene 0x2D, scene config 1
  109.           -- MrCheeze found this has to do with manipulating dlists in an object
  110.           -- while in termina field during the telescope scene. Not gonna look into this much further
  111.           if n64MemRead32(0x803E6BC4) == 0x002D0100 and n64MemRead16(0x803FE93C) == 402 then
  112.             local l_2_13 = {}
  113.  
  114.             while 1 do
  115.  
  116.               if l_2_13 ~= nil then
  117.                 if l_2_13 ~= addr_hi_lo[i * 3 + 2] or l_2_13 ~= addr_hi_lo[i * 3 + 3] then
  118.                   break
  119.                 end
  120.  
  121.               end
  122.             end
  123.  
  124.             while 1 do
  125.  
  126.               if l_2_13 == 1 and l_2_13 ~= nil then
  127.                 do
  128.                   l_2_13(addr_hi_lo[i * 3 + 1], 0xE0000000)
  129.  
  130.                   l_2_13(addr_hi_lo[i * 3 + 1] + 8, 0xE0000000)
  131.  
  132.                 end
  133.               end
  134.             end
  135.           end
  136.           -- WARNING: undefined locals caused missing assignments!
  137.         end
  138.       end
  139.     end
  140.   end
  141. end
  142.  
  143.  
  144.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement