Advertisement
Guest User

Untitled

a guest
Dec 25th, 2014
266
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 9.50 KB | None | 0 0
  1. --$D27C -> $D27D    -   Minimum camera Y position
  2. --$D27E -> $D27F  - Maximum camera Y position
  3. --$D280 -> $D281    -   Minimum camera X position
  4. --$D282 -> $D283    -   Maximum camera X position
  5. --$D2AD         -   Current level
  6. --$D2AE         -   Current Act
  7. local level = 1
  8. local act = 1
  9.  
  10. local height_multiplier = 0
  11.  
  12. local last_screenshot_x = 8978978979879879
  13. local screenshot_width = 160 - 32
  14. local screenshot_height = 144 - 40
  15. local fixed_cam_y = (screenshot_height*height_multiplier)+8
  16. local fixed_cam_x = 0
  17.  
  18. local cam_lock = 0
  19. local pos_lock = 0
  20.  
  21. shift_x = 200;
  22.  
  23. local address = {
  24.     cam_x           = 0xD288,
  25.     cam_y           = 0xD28A,
  26.     invulnerability = 0xD3A1,
  27.     flight_gauge    = 0xD3AF,
  28.     fade1           = 0x1499,
  29.     fade2           = 0x149A,
  30.  
  31.     tails           = 0xD500,
  32.     objects         = 0xD500
  33. }
  34. local offset = {
  35.     flags1    = 0x03,
  36.     flags2    = 0x04,
  37.     x         = 0x11,
  38.     y         = 0x14,
  39.     spd_sub_x = 0x16,
  40.     spd_x     = 0x17,
  41.     spd_sub_y = 0x18,
  42.     spd_y     = 0x19,
  43.     scr_x     = 0x1A,
  44.     scr_y     = 0x1C,
  45.     hp        = 0x26,
  46.     size_x    = 0x2c,
  47.     size_y    = 0x2d
  48. }
  49. local value = {
  50.     objects_num     = 24,
  51.     tails_hb_size_x = 20,
  52.     tails_hb_size_y = 13,
  53.     tails_hb_color  = 0xFFFFFFFF,
  54.     inv_color       = 0xFFFFFF00,
  55.     bomb_hb_size    = 16,
  56.     bomb_hb_color   = 0xFFFF0000,
  57.     enemy_hb_size   = 16,
  58.     enemy_hb_color  = 0xFFFFFFFF,
  59.     hb_transparency = 25,
  60.     cam_off_x       = 0, --48
  61.     cam_off_y       = 0, --24
  62.     slot_size       = 0x40
  63. }
  64.  
  65. local fixed_x = mainmemory.read_u16_le(address.tails+offset.x)
  66. local fixed_y = mainmemory.read_u16_le(address.tails+offset.y)
  67.  
  68. function GetGlobalValues()
  69.     -- Camera Position
  70.     value.cam_x             = mainmemory.read_u16_le(address.cam_x)
  71.     value.cam_y             = mainmemory.read_u16_le(address.cam_y)
  72.     value.fade1             = mainmemory.readbyte(address.fade1)
  73.     value.fade2             = mainmemory.readbyte(address.fade2)
  74.     level = mainmemory.readbyte(0xD2AD)
  75.     act = mainmemory.readbyte(0xD2AE)
  76. end
  77.  
  78. function GetObjectValues(obj_value,slot_n)
  79.         obj_value.slot_offset = slot_n * value.slot_size
  80.         obj_value.obj_id      = mainmemory.readbyte(address.objects+obj_value.slot_offset)
  81.         obj_value.flags2      = mainmemory.readbyte(address.objects+offset.flags2+obj_value.slot_offset)
  82.         obj_value.hp          = string.format("%x",(mainmemory.read_s8(address.objects+offset.hp+obj_value.slot_offset)))
  83.         obj_value.x           = mainmemory.read_u16_le(address.objects+offset.x+obj_value.slot_offset)
  84.         obj_value.y           = mainmemory.read_u16_le(address.objects+offset.y+obj_value.slot_offset)
  85.         obj_value.hb_size_x   = mainmemory.readbyte(address.objects+offset.size_x+obj_value.slot_offset)
  86.         obj_value.hb_size_y   = mainmemory.readbyte(address.objects+offset.size_y+obj_value.slot_offset)
  87.         obj_value.rel_x       = obj_value.x-value.cam_x - value.cam_off_x
  88.         obj_value.rel_y       = obj_value.y-value.cam_y - value.cam_off_y
  89.         obj_value.hb_rel_x    = obj_value.rel_x
  90.         obj_value.hb_rel_y    = obj_value.rel_y
  91.         obj_value.spd_x       = mainmemory.read_s16_le(address.objects+offset.spd_x+obj_value.slot_offset)
  92.         obj_value.spd_y       = mainmemory.read_s16_le(address.objects+offset.spd_y+obj_value.slot_offset)
  93. end
  94.  
  95.  
  96. function ObjectInformation()
  97.     local   count = 0
  98.     for slot_n = 0,value.objects_num-1 do
  99.         local obj_value = {}
  100.         local color_to_use
  101.         GetObjectValues(obj_value,slot_n)
  102.  
  103.         if true then
  104.             color_to_use = value.enemy_hb_color
  105.  
  106.             -- object hitbox
  107.             gui.drawBox(obj_value.hb_rel_x-obj_value.hb_size_x-1,
  108.                         obj_value.hb_rel_y,
  109.                         obj_value.hb_rel_x+obj_value.hb_size_x,
  110.                         obj_value.hb_rel_y-obj_value.hb_size_y,
  111.                         color_to_use,
  112.                         color_to_use-0xcc000000)
  113.  
  114.             -- object hp
  115.             gui.text(obj_value.hb_rel_x,obj_value.hb_rel_y,obj_value.obj_id..":"..obj_value.hp)
  116.  
  117.             -- position axis
  118.             local AXIS_COLOUR           = 0xFFFFFF
  119.             local AXIS_SIZE             = 2
  120.             gui.drawLine(obj_value.hb_rel_x, obj_value.hb_rel_y-AXIS_SIZE, obj_value.hb_rel_x, obj_value.hb_rel_y+AXIS_SIZE, AXIS_COLOUR)
  121.             gui.drawLine(obj_value.hb_rel_x-AXIS_SIZE, obj_value.hb_rel_y, obj_value.hb_rel_x+AXIS_SIZE, obj_value.hb_rel_y, AXIS_COLOUR)
  122.  
  123.         end -- if end
  124.  
  125.     end -- for end
  126. end
  127.  
  128.  
  129. local level_pressed    = 0
  130. local act_pressed      = 0
  131. local cam_lock_pressed = 0
  132. local pos_lock_pressed = 0
  133.  
  134. event.onframeend( function()
  135.     GetGlobalValues()
  136.  
  137.     -- manual tails movement
  138.     local keys = input.get()
  139.     local manual_spd = 1
  140.     if keys.J then
  141.         fixed_x = fixed_x-manual_spd
  142.     end
  143.     if keys.L then
  144.         fixed_x = fixed_x+manual_spd
  145.     end
  146.     if keys.I then
  147.         fixed_y = fixed_y-manual_spd
  148.     end
  149.     if keys.K then
  150.         fixed_y = fixed_y+manual_spd
  151.     end
  152.  
  153. --  if (((value.cam_x%screenshot_width) == 0) and (last_screenshot_x ~= value.cam_x) and (cam_lock ~= 0)) then
  154. --      last_screenshot_x = value.cam_x
  155. --      gui.savescreenshot()
  156. --  end
  157.  
  158.     -- for vertical levels
  159. --  if (((value.cam_y%screenshot_height) == 0) and (last_screenshot_x ~= value.cam_y)) then
  160. --      last_screenshot_x = value.cam_y
  161. --      gui.savescreenshot()
  162. --  end
  163.  
  164.     if cam_lock == 0 then
  165.         height_multiplier = math.floor(math.abs((fixed_y-72) / 104))
  166.     end
  167. --  if keys.X and height_pressed == 0 then
  168. --      height_multiplier = height_multiplier + 1
  169. --      fixed_cam_y = (screenshot_height*height_multiplier)+8
  170. --      height_pressed = 1
  171. --  end
  172. --  if keys.Z and height_pressed == 0 then
  173. --      height_multiplier = height_multiplier - 1
  174. --      fixed_cam_y = (screenshot_height*height_multiplier)+8
  175. --      height_pressed = 1
  176. --  end
  177. --  if ((not keys.X) and (not keys.Z)) then
  178. --      height_pressed = 0
  179. --  end
  180.  
  181.     if keys.H and level_pressed == 0 then
  182.         level = level + 1
  183.         level_pressed = 1
  184.     end
  185.     if keys.F and level_pressed == 0 then
  186.         level = level - 1
  187.         level_pressed = 1
  188.     end
  189.     if ((not keys.H) and (not keys.F)) then level_pressed = 0 end
  190.     if keys.T and act_pressed == 0 then
  191.         act = act + 1
  192.         act_pressed = 1
  193.     end
  194.     if keys.G and act_pressed == 0 then
  195.         act = act - 1
  196.         act_pressed = 1
  197.     end
  198.     if ((not keys.T) and (not keys.G)) then act_pressed = 0 end
  199.  
  200.     if keys.C and cam_lock_pressed == 0 then
  201.         if cam_lock ~= 0 then cam_lock = 0
  202.         else
  203.             cam_lock = 1
  204.             height_multiplier = math.floor(math.abs((fixed_y-72) / 104))
  205.             fixed_cam_y = (screenshot_height*height_multiplier)+8
  206.         end
  207.         cam_lock_pressed = 1
  208.     end
  209.     if (not keys.C) then
  210.         cam_lock_pressed = 0
  211.     end
  212.     if keys.X and pos_lock_pressed == 0 then
  213.         if pos_lock ~= 0 then pos_lock = 0
  214.         else
  215.             pos_lock = 1
  216.         end
  217.         pos_lock_pressed = 1
  218.     end
  219.     if (not keys.X) then
  220.         pos_lock_pressed = 0
  221.     end
  222.     if pos_lock == 0 then
  223.         fixed_x = mainmemory.read_u16_le(address.tails+offset.x)
  224.         fixed_y = mainmemory.read_u16_le(address.tails+offset.y)
  225.     end
  226.  
  227.     if keys.M then
  228.         os.execute('del /Q shots')
  229.     end
  230.  
  231. --[[
  232.     -- cheats
  233.     memory.writeword(address.tails+offset.hp,0x20)
  234.     memory.writebyte(0xd3a1, 0xff)
  235.     if pos_lock ~= 0 then memory.writeword(0xd511, fixed_x) end
  236.     if pos_lock ~= 0 then memory.writeword(0xd514, fixed_y) end
  237.     if cam_lock ~= 0 then memory.writeword(address.cam_y, fixed_cam_y) end
  238.     memory.writebyte(0xd506, 0)
  239. ]]
  240. end)
  241.  
  242. --memory.registerwrite(address.cam_x, 2, function()
  243. --  memory.writeword(address.cam_x, fixed_cam_x)
  244. --end)
  245.  
  246. --[[
  247. memory.registerwrite(address.cam_y, 2, function()
  248.     if cam_lock ~= 0 then memory.writeword(address.cam_y, fixed_cam_y) end
  249. end)
  250.  
  251. memory.registerwrite(address.tails+offset.x, 2, function()
  252.     if pos_lock ~= 0 then memory.writeword(address.tails+offset.x, fixed_x) end
  253. end)
  254.  
  255. memory.registerwrite(address.tails+offset.y, 2, function()
  256.     if pos_lock ~= 0 then memory.writeword(address.tails+offset.y, fixed_y) end
  257. end)
  258.  
  259. -- animation
  260. memory.registerwrite(0xD506, 1, function()
  261.     memory.writebyte(0xD506, 0)
  262. end)
  263.  
  264. memory.registerwrite(0xD2AD, 1, function()
  265.     memory.writebyte(0xD2AD, level)
  266. end)
  267.  
  268. memory.registerwrite(0xD2AE, 1, function()
  269.     memory.writebyte(0xD2AE, act)
  270. end)
  271. ]]
  272.  
  273.  
  274. while true do
  275. --  memory.writebyte(0xD2AD, level)
  276. --  memory.writebyte(0xD2AE, act)
  277. --gui.register(function()
  278.     GetGlobalValues()
  279. --  ObjectInformation()
  280.  
  281. --[[
  282.     local x_coord = 0
  283.     for i = 0,40 do
  284.         x_coord = (screenshot_width*i) - value.cam_x + 32
  285.         if i==0 then x_coord = 0 end
  286.         gui.drawLine(x_coord,
  287.                      0,
  288.                      x_coord,
  289.                      144,
  290.                      "red")
  291.     end
  292.  
  293.     local displ = 5
  294.     for i = 0,40 do
  295.         gui.drawLine(0,
  296.                      (40+32+screenshot_height*i) - value.cam_y - value.cam_off_y,
  297.                      160,
  298.                      (40+32+screenshot_height*i) - value.cam_y - value.cam_off_y,
  299.                      "red")
  300.         for j = 0,40 do
  301.             x_coord = (48+screenshot_width*j) - value.cam_x - value.cam_off_x + displ + 32
  302.             if j==0 then x_coord = x_coord - 32 end
  303.             gui.text(
  304.             x_coord,
  305.             (40+32+screenshot_height*i) - value.cam_y - value.cam_off_y + displ,
  306.             i..":"..j)
  307.         end
  308.     end
  309. ]]
  310.  
  311.     local gui_x, gui_y = 40,2
  312.     local cam_lock_str = ""
  313.     local pos_lock_str = ""
  314.     if cam_lock ~= 0 then cam_lock_str = "*" end
  315.     if pos_lock ~= 0 then pos_lock_str = "+" end
  316.     gui.text(gui_x, gui_y+ 0, "lvl: "..  level.."-"..act)
  317.     gui.text(gui_x, gui_y+ 8, "pos: "..  fixed_x..":"..fixed_y)
  318.     gui.text(gui_x, gui_y+16, "cam: "..  value.cam_x..":"..value.cam_y-8)
  319.     gui.text(gui_x, gui_y+24, "hgt: "..  height_multiplier .." "..cam_lock_str..pos_lock_str)
  320. --end)
  321.     client.screenshot("full/" .. string.format("%05d",emu.framecount()) .. ".png")
  322.     --local file = io.open("txt/" .. string.format("%05d",emu.framecount()) .. ".txt", "w")
  323.     --file:write(level .. "\n" .. act .. "\n" .. value.cam_x .. "\n" .. (value.cam_y-8) .. "\n" .. value.fade1 .. "\n" .. value.fade2 .. "\n")
  324.     --file:close()
  325.     emu.frameadvance()
  326. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement