Advertisement
Guest User

FM: Gun Hazard Helper Script

a guest
Mar 9th, 2016
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 10.33 KB | None | 0 0
  1. -- FM: Gun Hazard Helper Script
  2. -- Author: Omnigamer
  3. -- 3/9/16
  4.  
  5. function draw_cross(x_pos,y_pos, color)
  6.     gui.drawLine(x_pos-3,y_pos,x_pos+3,y_pos, color)
  7.     gui.drawLine(x_pos,y_pos-3,x_pos,y_pos+3, color)
  8. end
  9.  
  10. display_toggle = true;
  11. wait = 0;
  12. memory.usememorydomain("CARTROM")
  13.  
  14. while true do
  15.  
  16.     inputs = input.get();
  17.     if(wait>0) then
  18.         wait = wait -1;
  19.     end
  20.  
  21.     --Press D to toggle the display between % and raw Exp values
  22.     if(inputs["D"] ~= nil and wait == 0) then
  23.         display_toggle = not display_toggle;
  24.         wait = 20;
  25.     end
  26.  
  27.     if(mainmemory.read_u8(0x0114) ~= 0) then
  28.        
  29.         --Offset for current special weapon
  30.         alt_num = mainmemory.read_u8(0x1c9c);
  31.        
  32.         --IDs for weapon types
  33.         prime = 2*mainmemory.read_u8(0x00754E)
  34.         alt = 2*mainmemory.read_u8(0x00754F + alt_num)
  35.         ver = 2*mainmemory.read_u8(0x007548)
  36.         mech = 2*mainmemory.read_u8(0x00753d)
  37.         --xp = mainmemory.read_u32_le(0x001BBB)
  38.        
  39.         if(display_toggle == false) then
  40.             gui.drawText(0,23,string.format("GUN:%X",mainmemory.read_u16_le(prime + 0x73c6)))
  41.             gui.drawText(65,23,string.format("ALT:%X",mainmemory.read_u16_le(alt + 0x7402)))
  42.             gui.drawText(130,23,string.format("MEC:%X",mainmemory.read_u16_le(mech + 0x74ac)))
  43.             gui.drawText(195,23,string.format("VER:%X",mainmemory.read_u16_le(ver + 0x74B6)))
  44.         else
  45.             --temp secondary variables
  46.             gun = mainmemory.read_u16_le(prime + 0x73c6);
  47.             new_alt = mainmemory.read_u16_le(alt + 0x7402);
  48.             mec = mainmemory.read_u16_le(mech + 0x74ac)
  49.             new_ver = mainmemory.read_u16_le(ver + 0x74b6)
  50.                
  51.             --Special formatting rules for %s
  52.             if(gun >= 0xD666) then
  53.                 gui.drawText(0,23,string.format("GUN:120%%"))
  54.             elseif( gun >= 0x8000) then
  55.                 gui.drawText(0,23,string.format("GUN:100%%"))
  56.             else
  57.                 gui.drawText(0,23,string.format("GUN:%3.1f",gun/0x8000*100))
  58.             end
  59.            
  60.             if(new_alt >= 0xD666) then
  61.                 gui.drawText(65,23,string.format("ALT:120%%"))
  62.             elseif( new_alt >= 0x8000) then
  63.                 gui.drawText(65,23,string.format("ALT:100%%"))
  64.             else
  65.                 gui.drawText(65,23,string.format("ALT:%3.1f",new_alt/0x8000*100))
  66.             end
  67.            
  68.             if(mec >= 0xD666) then
  69.                 gui.drawText(130,23,string.format("MEC:120%%"))
  70.             elseif( mec >= 0x8000) then
  71.                 gui.drawText(130,23,string.format("MEC:100%%"))
  72.             else
  73.                 gui.drawText(130,23,string.format("MEC:%3.1f",mec/0x8000*100))
  74.             end    
  75.            
  76.             if(new_ver >= 0xD666) then
  77.                 gui.drawText(195,23,string.format("VER:120%%"))
  78.             elseif( new_ver >= 0x8000) then
  79.                 gui.drawText(195,23,string.format("VER:100%%"))
  80.             else
  81.                 gui.drawText(195,23,string.format("VER:%3.1f",new_ver/0x8000*100))
  82.             end
  83.         end
  84.        
  85.         for i = 0x08c0,0x09c0,0x40 do -- Your shots
  86.            
  87.             active = mainmemory.read_u8(i);
  88.             if((active ~=0)) then
  89.            
  90.                 x_coord = mainmemory.read_u16_le(i+0x16)
  91.                 y_coord = mainmemory.read_u16_le(i+0x1a)
  92.                
  93.                 hitbox_addr = mainmemory.read_u16_le(i+0x20)
  94.                
  95.                 hitbox_x = memory.read_s16_le(hitbox_addr+1+0x20000);
  96.                 hitbox_x2 = memory.read_s16_le(hitbox_addr+3+0x20000);
  97.                 hitbox_y = memory.read_s16_le(hitbox_addr+5+0x20000);
  98.                 hitbox_y2 = memory.read_s16_le(hitbox_addr+7+0x20000);
  99.                
  100.                 if(bit.band(mainmemory.read_u8(i+0xb),0x40)~=0) then
  101.                     hitbox_x = 0 - (hitbox_x + hitbox_x2+1);
  102.                 end
  103.                
  104.                 gui.drawRectangle(x_coord + hitbox_x,y_coord + hitbox_y,hitbox_x2, hitbox_y2,"white")
  105.                
  106.                 draw_cross(x_coord,y_coord, "white");
  107.  
  108.                 HP = mainmemory.read_u16_le(i+0x24)
  109.                
  110.                 --gui.drawText(x_coord-10,y_coord-20,string.format("%X", i));
  111.                 gui.drawText(x_coord-10,y_coord+10,string.format("%d", HP));
  112.                
  113.             end
  114.         end
  115.        
  116.         for i = 0x0a00,0x0b80,0x40 do -- Your alt shots
  117.            
  118.             active = mainmemory.read_u8(i);
  119.             if((active ~=0)) then
  120.            
  121.                 x_coord = mainmemory.read_u16_le(i+0x16)
  122.                 y_coord = mainmemory.read_u16_le(i+0x1a)
  123.                
  124.                 draw_cross(x_coord,y_coord, "white");
  125.                
  126.                 hitbox_addr = mainmemory.read_u16_le(i+0x20)
  127.                
  128.                 hitbox_x = memory.read_s16_le(hitbox_addr+1+0x20000);
  129.                 hitbox_x2 = memory.read_s16_le(hitbox_addr+3+0x20000);
  130.                 hitbox_y = memory.read_s16_le(hitbox_addr+5+0x20000);
  131.                 hitbox_y2 = memory.read_s16_le(hitbox_addr+7+0x20000);
  132.                
  133.                 if(bit.band(mainmemory.read_u8(i+0xb),0x40)~=0) then
  134.                     hitbox_x = 0 - (hitbox_x + hitbox_x2+1);
  135.                 end
  136.                
  137.                 gui.drawRectangle(x_coord + hitbox_x,y_coord + hitbox_y,hitbox_x2, hitbox_y2,"white")
  138.                
  139.                 HP = mainmemory.read_u16_le(i+0x24)
  140.                
  141.                 --gui.drawText(x_coord-10,y_coord-20,string.format("%X", i));
  142.                 gui.drawText(x_coord-10,y_coord+10,string.format("%d", HP));
  143.                
  144.             end
  145.         end
  146.        
  147.         for i = 0x0bc0,0x0dc0,0x40 do -- Enemy shots
  148.            
  149.             active = mainmemory.read_u8(i);
  150.             if((active ~=0)) then
  151.            
  152.                 x_coord = mainmemory.read_u16_le(i+0x16)
  153.                 y_coord = mainmemory.read_u16_le(i+0x1a)
  154.                
  155.                 draw_cross(x_coord,y_coord, "purple");
  156.                
  157.                 hitbox_addr = mainmemory.read_u16_le(i+0x20)
  158.                
  159.                 hitbox_x = memory.read_s16_le(hitbox_addr+1+0x20000);
  160.                 hitbox_x2 = memory.read_s16_le(hitbox_addr+3+0x20000);
  161.                 hitbox_y = memory.read_s16_le(hitbox_addr+5+0x20000);
  162.                 hitbox_y2 = memory.read_s16_le(hitbox_addr+7+0x20000);
  163.                
  164.                 if(bit.band(mainmemory.read_u8(i+0xb),0x40)~=0) then
  165.                     hitbox_x = 0 - (hitbox_x + hitbox_x2+1);
  166.                 end
  167.                
  168.                 gui.drawRectangle(x_coord + hitbox_x,y_coord + hitbox_y,hitbox_x2, hitbox_y2,"purple")
  169.                
  170.                 HP = mainmemory.read_u16_le(i+0x24)
  171.                
  172.                 --gui.drawText(x_coord-10,y_coord-20,string.format("%X", i));
  173.                 gui.drawText(x_coord-10,y_coord+10,string.format("%d", HP));
  174.                
  175.             end
  176.         end
  177.        
  178.         for i = 0x0e00,0x0e40,0x40 do -- Your mech/pilot
  179.            
  180.             active = mainmemory.read_u8(i);
  181.             if((active ~=0)) then
  182.            
  183.                 x_coord = mainmemory.read_u16_le(i+0x16)
  184.                 y_coord = mainmemory.read_u16_le(i+0x1a)
  185.                
  186.                 draw_cross(x_coord,y_coord, "blue");
  187.                
  188.                 hitbox_addr = mainmemory.read_u16_le(i+0x20)
  189.                
  190.                 hitbox_x = memory.read_s16_le(hitbox_addr+1+0x20000);
  191.                 hitbox_x2 = memory.read_s16_le(hitbox_addr+3+0x20000);
  192.                 hitbox_y = memory.read_s16_le(hitbox_addr+5+0x20000);
  193.                 hitbox_y2 = memory.read_s16_le(hitbox_addr+7+0x20000);
  194.                
  195.                 if(bit.band(mainmemory.read_u8(i+0xb),0x40)~=0) then
  196.                     hitbox_x = 0 - (hitbox_x + hitbox_x2+1);
  197.                 end
  198.                
  199.                 gui.drawRectangle(x_coord + hitbox_x,y_coord + hitbox_y,hitbox_x2, hitbox_y2,"blue")
  200.                
  201.                 HP = mainmemory.read_u16_le(i+0x24)
  202.                
  203.                 --gui.drawText(x_coord-10,y_coord-20,string.format("%X", i));
  204.                 gui.drawText(x_coord-10,y_coord+10,string.format("%d", HP));
  205.                
  206.             end
  207.         end
  208.        
  209.             for i = 0x0e80,0x0f00,0x40 do -- Allies
  210.            
  211.             active = mainmemory.read_u8(i);
  212.             if((active ~=0)) then
  213.            
  214.                 x_coord = mainmemory.read_u16_le(i+0x16)
  215.                 y_coord = mainmemory.read_u16_le(i+0x1a)
  216.                
  217.                 draw_cross(x_coord,y_coord, "green");
  218.                
  219.                 hitbox_addr = mainmemory.read_u16_le(i+0x20)
  220.                
  221.                 hitbox_x = memory.read_s16_le(hitbox_addr+1+0x20000);
  222.                 hitbox_x2 = memory.read_s16_le(hitbox_addr+3+0x20000);
  223.                 hitbox_y = memory.read_s16_le(hitbox_addr+5+0x20000);
  224.                 hitbox_y2 = memory.read_s16_le(hitbox_addr+7+0x20000);
  225.                
  226.                 if(bit.band(mainmemory.read_u8(i+0xb),0x40)~=0) then
  227.                     hitbox_x = 0 - (hitbox_x + hitbox_x2+1);
  228.                 end
  229.                
  230.                 gui.drawRectangle(x_coord + hitbox_x,y_coord + hitbox_y,hitbox_x2, hitbox_y2,"green")
  231.                
  232.                 HP = mainmemory.read_u16_le(i+0x24)
  233.                
  234.                 --gui.drawText(x_coord-10,y_coord-20,string.format("%X", i));
  235.                 gui.drawText(x_coord-10,y_coord+10,string.format("%d", HP));
  236.                
  237.             end
  238.         end
  239.        
  240.         for i = 0x0f40,0x10C0,0x40 do -- Enemies
  241.            
  242.             active = mainmemory.read_u8(i);
  243.             if((active ~=0)) then
  244.            
  245.                 x_coord = mainmemory.read_u16_le(i+0x16)
  246.                 y_coord = mainmemory.read_u16_le(i+0x1a)
  247.                
  248.                 draw_cross(x_coord,y_coord, "red");
  249.                
  250.                 hitbox_addr = mainmemory.read_u16_le(i+0x20)
  251.                
  252.                 hitbox_x = memory.read_s16_le(hitbox_addr+1+0x20000);
  253.                 hitbox_x2 = memory.read_s16_le(hitbox_addr+3+0x20000);
  254.                 hitbox_y = memory.read_s16_le(hitbox_addr+5+0x20000);
  255.                 hitbox_y2 = memory.read_s16_le(hitbox_addr+7+0x20000);
  256.                
  257.                 if(bit.band(mainmemory.read_u8(i+0xb),0x40)~=0) then
  258.                     hitbox_x = 0 - (hitbox_x + hitbox_x2+1);
  259.                 end
  260.                
  261.                 gui.drawRectangle(x_coord + hitbox_x,y_coord + hitbox_y,hitbox_x2, hitbox_y2,"red")
  262.                
  263.                 HP = mainmemory.read_u16_le(i+0x24)
  264.                
  265.                 --gui.drawText(x_coord-10,y_coord-20,string.format("%X", i));
  266.                 gui.drawText(x_coord-10,y_coord+10,string.format("%d", HP));
  267.                
  268.             end
  269.         end
  270.        
  271.         for i = 0x1100,0x1180,0x40 do --Props/turrets
  272.            
  273.             active = mainmemory.read_u8(i);
  274.             if((active ~=0)) then
  275.            
  276.                 x_coord = mainmemory.read_u16_le(i+0x16)
  277.                 y_coord = mainmemory.read_u16_le(i+0x1a)
  278.                
  279.                 draw_cross(x_coord,y_coord, "yellow");
  280.                
  281.                 hitbox_addr = mainmemory.read_u16_le(i+0x20)
  282.                
  283.                 hitbox_x = memory.read_s16_le(hitbox_addr+1+0x20000);
  284.                 hitbox_x2 = memory.read_s16_le(hitbox_addr+3+0x20000);
  285.                 hitbox_y = memory.read_s16_le(hitbox_addr+5+0x20000);
  286.                 hitbox_y2 = memory.read_s16_le(hitbox_addr+7+0x20000);
  287.                
  288.                 if(bit.band(mainmemory.read_u8(i+0xb),0x40)~=0) then
  289.                     hitbox_x = 0 - (hitbox_x + hitbox_x2+1);
  290.                 end
  291.                
  292.                 gui.drawRectangle(x_coord + hitbox_x,y_coord + hitbox_y,hitbox_x2, hitbox_y2,"yellow")
  293.                
  294.                 HP = mainmemory.read_u16_le(i+0x24)
  295.                
  296.                 gui.drawText(x_coord-10,y_coord-20,string.format("%X", i));
  297.                 gui.drawText(x_coord-10,y_coord+10,string.format("%d", HP));
  298.                
  299.             end
  300.         end
  301.        
  302.         for i = 0x11c0,0x1440,0x40 do --Misc stuff, loading zones
  303.            
  304.             active = mainmemory.read_u8(i);
  305.             if((active ~=0)) then
  306.            
  307.                 x_coord = mainmemory.read_u16_le(i+0x16)
  308.                 y_coord = mainmemory.read_u16_le(i+0x1a)
  309.                
  310.                 draw_cross(x_coord,y_coord, "black");
  311.                
  312.                 hitbox_addr = mainmemory.read_u16_le(i+0x20)
  313.                
  314.                 hitbox_x = memory.read_s16_le(hitbox_addr+1+0x20000);
  315.                 hitbox_x2 = memory.read_s16_le(hitbox_addr+3+0x20000);
  316.                 hitbox_y = memory.read_s16_le(hitbox_addr+5+0x20000);
  317.                 hitbox_y2 = memory.read_s16_le(hitbox_addr+7+0x20000);
  318.                
  319.                 if(bit.band(mainmemory.read_u8(i+0xb),0x40)~=0) then
  320.                     hitbox_x = 0 - (hitbox_x + hitbox_x2+1);
  321.                 end
  322.                
  323.                 gui.drawRectangle(x_coord + hitbox_x,y_coord + hitbox_y,hitbox_x2, hitbox_y2,"black")
  324.                
  325.                 --HP = mainmemory.read_u16_le(i+0x24)
  326.                
  327.                 gui.drawText(x_coord-10,y_coord-20,string.format("%X", i));
  328.                 --gui.drawText(x_coord-10,y_coord+10,string.format("%d", HP));
  329.                
  330.             end
  331.         end
  332.     end
  333.  
  334.     emu.frameadvance()
  335. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement