Advertisement
MrCheeze

OoT NSO Lua - 06_UCZLJ2.308.lua

Jul 14th, 2024
1,042
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.68 KB | None | 0 0
  1. function GameBegin()
  2.     --this memory is write by a unknown rsp task in trueboot, the task set some memory value
  3.     --without this, fishing in the game will very difficult
  4.     n64MemWrite32(0x802fb1f4, 0xad090010);
  5.     n64MemWrite32(0x802fe1c0, 0xad170014);
  6.     return
  7. end
  8.  
  9. function FrameBegin()
  10.     --menu speed up
  11.     n64MemWrite8(0x801DAE8B, 0x02)
  12.     n64DarkSwitchOff()
  13.     return
  14. end
  15.  
  16. function BeforeVIFrameEnd()
  17.     local addr_game = 0x801c8d60;
  18.     local addr_demo_play = 0x801caac4;
  19.     local addr_game_info_mode = 0x8011BFDC;
  20.    
  21.     local gameinfo_mode = n64MemRead32(addr_game_info_mode);
  22.     local func_exec = n64MemRead32(addr_game + 4);
  23.    
  24.     --NN_LOG(string.format("BeforGTask %d 0x%x\n", gameinfo_mode, func_exec));
  25.     n64ResetParameter("VISync");
  26.     if (gameinfo_mode == 0 --0 normal game
  27.         and func_exec == 0x8009d1b8 --this is gameplay
  28.     ) then
  29.         n64SetParameter("VISync", 1);
  30.     end
  31.     return
  32. end
  33.  
  34. function BeforGTask()
  35.     --NN_LOG("before g Task\n");
  36.     --in ending_demo scene switch will have gtask per frame begin first 2frames
  37.     --this will cause lag
  38.     --set 3frames per g task will avoid that
  39.     n64ResetParameter("FramesPerGTask");
  40.     local addr_game = 0x801c8d60;
  41.     local addr_demo_play = 0x801caac4;
  42.     local addr_game_info_mode = 0x8011BFDC;
  43.    
  44.     local gameinfo_mode = n64MemRead32(addr_game_info_mode);
  45.     local func_exec = n64MemRead32(addr_game + 4);
  46.    
  47.     --NN_LOG(string.format("BeforGTask %d 0x%x\n", gameinfo_mode, func_exec));
  48.     if (gameinfo_mode == 3 --3 is ending staff
  49.         and func_exec == 0x8009d1b8 --this is gameplay
  50.     ) then
  51.         --NN_LOG("this is ending staff\n");
  52.         local demoplay_framecnt = n64MemRead16(addr_demo_play + 0x10);
  53.         local addr_demo_data = n64MemRead32(addr_demo_play + 0x4);
  54.         local addr_xx = addr_demo_data + 8;
  55.         while(true) do
  56.             local flag = n64MemRead32(addr_xx);
  57.             --NN_LOG(string.format("flag is 0x%x\n", flag));
  58.             if(flag == 0x000003e8) then
  59.                 break;
  60.             elseif(flag == 0x00000001 or flag == 0x00000002) then
  61.                 addr_xx = addr_xx + 0xC;
  62.                 while(true) do
  63.                     local test_value = n64MemRead8(addr_xx);
  64.                     addr_xx = addr_xx + 0x10;
  65.                     if(test_value == 0xFF) then
  66.                         break;
  67.                     end
  68.                 end
  69.             elseif(flag == 0x0000002D) then
  70.                 addr_xx = addr_xx + 0x10;
  71.             elseif(flag >= 0x00000004 and flag <= 0x000003E7) then
  72.                 local num = n64MemRead32(addr_xx + 4);
  73.                 addr_xx = addr_xx + 0x8 + num *0x30;
  74.             else
  75.                 --NN_LOG(string.format("flag is 0x%x\n", flag));
  76.                 break;
  77.             end
  78.         end
  79.         addr_xx = addr_xx + 0x8;
  80.         local some_no = n64MemRead16(addr_xx);
  81.         local maxframe = n64MemRead16(addr_xx + 2);
  82.         --NN_LOG(string.format("gameinfomode 0x%x func_exec 0x%x\n", gameinfo_mode, func_exec));
  83.         --NN_LOG(string.format("staff 0x%x 0x%x 0x%x\n", some_no, maxframe, demoplay_framecnt));
  84.         local framepertask = 2;
  85.         if(some_no == 0x37) then
  86.             if(maxframe == 0xC3) then
  87.                 n64MemWrite16(addr_xx+2, 0xC3 + 0x6);
  88.             end
  89.         elseif(some_no == 0x38)  then
  90.             if(maxframe == 0xDC) then
  91.                 n64MemWrite16(addr_xx+2, 0xDC + 0x7);
  92.             end
  93.         elseif(some_no == 0x39)  then
  94.             if(maxframe == 0xF0) then
  95.                 n64MemWrite16(addr_xx+2, 0xF0 + 0x7);
  96.             end
  97.         elseif(some_no == 0x3A)  then
  98.             if(maxframe == 0x118) then
  99.                 n64MemWrite16(addr_xx+2, 0x118 + 0x8);
  100.             end
  101.         elseif(some_no == 0x3B)  then
  102.             if(maxframe == 0x118) then
  103.                 n64MemWrite16(addr_xx+2, 0x118 + 0x8);
  104.             end
  105.         elseif(some_no == 0x3D)  then
  106.             if(maxframe == 0x140) then
  107.                 n64MemWrite16(addr_xx+2, 0x140 + 0x8);
  108.             end
  109.         elseif(some_no == 0x3F)  then
  110.             if(maxframe == 0x104) then
  111.                 n64MemWrite16(addr_xx+2, 0x104 + 0x8);
  112.             end
  113.         elseif(some_no == 0x40)  then
  114.             if(maxframe == 0xDC) then
  115.                 n64MemWrite16(addr_xx+2, 0xDC + 0x8);
  116.             end
  117.         elseif(some_no == 0x4a)  then
  118.             if(maxframe == 0xFF) then
  119.                 n64MemWrite16(addr_xx+2, 0xFF + 0x8);
  120.             end
  121.         elseif(some_no == 0x4b)  then
  122.             if(demoplay_framecnt < 0x18) then
  123.                 framepertask = 3;
  124.             else
  125.                 framepertask = 4;
  126.             end
  127.             if(maxframe == 0x98) then
  128.                 n64MemWrite16(addr_xx+2, 0x98 + 0x9);
  129.             end
  130.         elseif(some_no == 0x4C)  then
  131.             if(demoplay_framecnt < 0xA) then
  132.                 framepertask = 5;
  133.             elseif(demoplay_framecnt < 0x1F) then
  134.                 framepertask = 4;
  135.             elseif(demoplay_framecnt < 0x7A) then
  136.                 framepertask = 3;
  137.             elseif(demoplay_framecnt < 0xE0) then
  138.                 local b = bit.band(demoplay_framecnt, 0x1)
  139.                 if(b == 0) then
  140.                     framepertask = 3;
  141.                 else
  142.                     framepertask = 2;
  143.                 end
  144.             else
  145.                 local b = bit.band(demoplay_framecnt, 0x1)
  146.                 if(b == 0) then
  147.                     framepertask = 3;
  148.                 else
  149.                     framepertask = 2;
  150.                 end
  151.             end        
  152.         elseif(some_no == 0x4E)  then
  153.             local b = math.modf(demoplay_framecnt, 5);
  154.             if(b < 3) then
  155.                 framepertask = 3;
  156.             else
  157.                 framepertask = 2;
  158.             end
  159.             if(maxframe == 0x9D) then
  160.                 n64MemWrite16(addr_xx+2, 0x9D + 0x10);
  161.             end
  162.         elseif(some_no == 0x4D)  then
  163.             if(demoplay_framecnt < 0xB0) then
  164.                 framepertask = 2;
  165.             else
  166.                 framepertask = 3;
  167.             end
  168.             if(maxframe == 0x127) then
  169.                 n64MemWrite16(addr_xx+2, 0x127 + 0x8);
  170.             end
  171.         elseif(some_no == 0x46)  then
  172.             if(maxframe == 0x237) then
  173.                 n64MemWrite16(addr_xx+2, 0x237 + 0x10);
  174.             end
  175.         end    
  176.         n64SetParameter("FramesPerGTask", framepertask);
  177.     end
  178.     return
  179. end
  180.  
  181.  
  182. function HookFunc_AfterInst(pc, inst)
  183.     if(pc == 0x8009bbb0 and inst ==0x8fa40040) then
  184.       if( n64GPRRead32(9) == 0x2873e0) then
  185.       ------nPc=0x8009bbb0 , nInst=0x8fa40040
  186.         --NN_LOG("m34 ride in fire-------------------------\n")
  187.         --n64DarkSwitchOn(116,800)
  188.         end
  189.     end
  190.        
  191.     if(pc == 0x801ea304 and inst ==0x8fbf0014) then
  192.     ------- nPc=0x801ea304 , nInst=0x8fbf0014
  193.         --NN_LOG("m39 white flashs while attacking---------------\n")
  194.         --n64DarkSwitchOn(86,50)
  195.     end
  196.        
  197.     if(pc == 0x8004fa0c and inst ==0x8caf0018) then
  198.     ----nPc=0x8004fa0c , nInst=0x8caf0018
  199.         --NN_LOG("m40  white flashs while attacking---------------\n")
  200.         --n64DarkSwitchOn(87,40)
  201.     end
  202.      
  203.     if(pc == 0x8009c3b0 and inst ==0x3c010001) then
  204.         --NN_LOG("m57 m56 white flashs---------------\n")
  205.         --n64DarkSwitchOn(21,8)
  206.     end
  207.        
  208.     if(pc == 0x802126e0 and inst ==0xafa40000) then
  209.         --NN_LOG("m53 bomb---------------\n")
  210.         --n64DarkSwitchOn(21,80)
  211.     end
  212.      
  213.         if(pc == 0x8009c3a4 and inst == 0x304f0001) then
  214.     ---000a0142h: 1C 24 31 C2 00 FF 18 40 00 0D 30 4F 00 01   the last instruct is ANDI 0x01.  
  215.         NN_LOG("m39 white flashs while attacking----------the last instruct is ANDI 0x01.   -----\n")
  216.         local t2 = n64GPRRead32(2)
  217.         local t15 = bit.band(t2, 0x03)
  218.         n64GPRWrite32(15, t15)
  219.     end
  220.      
  221.     --dynamic code hack
  222.     if(pc == 0x8001BB20 and inst ==0x0C019CBE) then
  223.         --NN_LOG("effect malloc\n")
  224.         --set big memory size to let malloc fail
  225.         n64GPRWrite32(0x04, 0x800000)
  226.     elseif(pc == 0x8001BB28 and inst ==0x8FA30028) then
  227.         --NN_LOG("after effect malloc\n")
  228.         --set a malloc return value to segment start
  229.         local v1 = n64GPRRead32(0x03)
  230.         local addr = n64MemRead32(v1 + 8)
  231.         n64GPRWrite32(0x2, addr)
  232.     elseif(pc == 0x800257C4 and inst ==0x9602001C) then
  233.         --NN_LOG("actor load flags\n")
  234.         --set all actor flag to 2(not free after dead)
  235.         n64GPRWrite32(0x02, 0x2)
  236.     end
  237.      
  238.     return
  239. end  
  240.      
  241. function HookFunc_BeforeInst(pc, inst)
  242.     if(pc == 0x8002580C and inst ==0x0C019CBE) then
  243.         --NN_LOG("actor malloc\n")
  244.         --set big memory size to let malloc fail
  245.         n64GPRWrite32(0x07, 0x800000)
  246.     elseif(pc == 0x80025814 and inst ==0x10000004) then
  247.         --NN_LOG("after actor malloc\n")
  248.         --set a malloc return value to segment start
  249.         local s0 = n64GPRRead32(0x10)
  250.         local addr = n64MemRead32(s0 + 8)
  251.         n64GPRWrite32(0x2, addr)
  252.     end
  253.     return
  254. end  
  255.      
  256. function RomPatch()
  257.     --BTS MCat bug No.221
  258.     n64RomWrite8(0x175c39b, 0x3e)
  259.     return
  260. end  
  261.      
  262.      
  263.      
  264.      
  265.      
  266.      
  267.      
  268.      
  269.      
  270.      
  271.      
  272.      
  273.      
  274.      
  275.      
  276.      
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement