Dotsarecool

Memory to After Effects

Oct 4th, 2018 (edited)
1,505
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.55 KB | None | 0 0
  1. -- Script for extracting game data and outputting it into After Effects keyframe data format
  2. -- Written by Alex Losego
  3.  
  4. -- the filepath to save the csv file
  5.  
  6. local absolutefilepath = "C:\\Users\\Alex\\Documents\\output.csv"
  7.  
  8. -- the memory domain to use for memory addresses specified in the next array
  9.  
  10. local domain = "RAM"
  11.  
  12. -- the framerate of the source video this will be attached to
  13.  
  14. local framerate = 60.1
  15.  
  16. -- list of memory addresses to keep track of
  17. ---- array key is the name of the data
  18. ---- array value contains the type and address
  19. ------ type 't' can be 'u8' 's8' 'u16' 's16' for unsigned/signed 8-bit/16-bit value
  20. ------ address 'lo' is the memory address of value (the lower 8 bits for 16-bit)
  21. ------ address 'hi' is the memory address of higher 8 bits for 16-bit (need to be specified even if the 16 bits are contiguous)
  22.  
  23. local addresses = {
  24.     --loc_x = {t = "s8", lo = 0x1200},
  25.     --loc_y = {t = "s8", lo = 0x1204},
  26.     --loc_z = {t = "s8", lo = 0x1208},
  27.     --camera_x = {t = "s16", hi = 0x1B, lo = 0x1A},
  28.     --camera_y = {t = "s16", hi = 0x1D, lo = 0x1C},
  29.     --sprite_0 = {t = "u8", lo = 0x9E},
  30.     --sprite_1 = {t = "u8", lo = 0x9F},
  31. }
  32.  
  33. -- list of keyframes imported into After Effects
  34. ---- 'name' is the name of the keyframe
  35. ---- 't' is the type of keyframe: can be 'slider' (1D) or 'point' (2D) or '3dpoint' (3D)
  36. ---- 'x' is the name of the data given above for first dimension of keyframe
  37. ---- 'y' is the name of the data given above for second dimension of keyframe (point only)
  38. ---- 'z' is the name of the data given above for third dimension of keyframe (3d point only)
  39.  
  40. local keyframes = {
  41.     --{name = "location", t = "3dpoint", x = "loc_x", y = "loc_y", y = "loc_z"},
  42.     --{name = "camera", t = "point", x = "camera_x", y = "camera_y"},
  43.     --{name = "slot_0_sprite", t = "slider", x = "sprite_0"},
  44.     --{name = "slot_1_sprite", t = "slider", x = "sprite_1"},
  45. }
  46.  
  47.  
  48. -- don't need to change anything below this point
  49.  
  50. function done()
  51.     return movie.mode() == "FINISHED" or movie.mode() == "INACTIVE"
  52. end
  53.  
  54. -- Start Main --
  55.  
  56. console.writeline("Starting...")
  57. raw = {}
  58. memory.usememorydomain(domain);
  59.  
  60. repeat
  61.     emu.frameadvance()
  62.    
  63.     for k, v in pairs(addresses) do
  64.         val = 0;
  65.         if v.t == "u8" then
  66.             val = memory.readbyte(v.lo)
  67.         elseif v.t == "s8" then
  68.             val = memory.readbyte(v.lo)
  69.             if val >= 0x80 then
  70.                 val = val - 0x100
  71.             end
  72.         elseif v.t == "u16" then
  73.             val = 0x100*memory.readbyte(v.hi) + memory.readbyte(v.lo)
  74.         elseif v.t == "s16" then
  75.             val = 0x100*memory.readbyte(v.hi) + memory.readbyte(v.lo)
  76.             if val >= 0x8000 then
  77.                 val = val - 0x10000
  78.             end
  79.         end
  80.        
  81.         if raw[k] == nil then
  82.             raw[k] = {}
  83.         end
  84.        
  85.         table.insert(raw[k], val);
  86.     end
  87. until done()
  88.  
  89. file = io.open(absolutefilepath,"w")
  90. file:write("Adobe After Effects 8.0 Keyframe Data\n\n\n")
  91. file:write("\tUnits Per Second\t" .. framerate .. "\n")
  92. file:write("\tSource Width\t100\n")
  93. file:write("\tSource Height\t100\n")
  94. file:write("\tSource Pixel Aspect Ratio\t1\n")
  95. file:write("\tComp Pixel Aspect Ratio\t1\n\n")
  96.  
  97. for i = 1,#keyframes do
  98.     console.writeline("Writing keyframe data for "..keyframes[i].name..".")
  99.    
  100.     if keyframes[i].t == "slider" then
  101.         file:write("Effects\tSlider Control #"..i.."\tSlider#2\n\tFrame\n")
  102.         --
  103.         for j=1,#raw[keyframes[i].x] do
  104.             val = raw[keyframes[i].x][j]
  105.             if j > 1 and val == raw[keyframes[i].x][j-1] then
  106.                 -- unnecessary keyframe
  107.             else
  108.                 file:write("\t"..j.."\t"..val.."\n")
  109.             end
  110.         end
  111.         --
  112.         file:write("\n");
  113.     elseif keyframes[i].t == "point" then
  114.         file:write("Effects\tPoint Control #"..i.."\tPoint#2\n\tFrame\tX pixels\tY pixels\n")
  115.         --
  116.         for j=1,#raw[keyframes[i].x] do
  117.             valX = raw[keyframes[i].x][j]
  118.             valY = raw[keyframes[i].y][j]
  119.             if j > 1 and valX == raw[keyframes[i].x][j-1] and valY == raw[keyframes[i].y][j-1] then
  120.                 -- unnecessary keyframe
  121.             else
  122.                 file:write("\t"..j.."\t"..valX.."\t"..valY.."\n")
  123.             end
  124.         end
  125.         --
  126.         file:write("\n")
  127.     elseif keyframes[i].t == "3dpoint" then
  128.         file:write("Effects\t3D Point Control #"..i.."\t3D Point#2\n\tFrame\tX pixels\tY pixels\tZ pixels\n")
  129.         --
  130.         for j=1,#raw[keyframes[i].x] do
  131.             valX = raw[keyframes[i].x][j]
  132.             valY = raw[keyframes[i].y][j]
  133.             valZ = raw[keyframes[i].z][j]
  134.             if j > 1 and valX == raw[keyframes[i].x][j-1] and valY == raw[keyframes[i].y][j-1] and valZ == raw[keyframes[i].z][j-1] then
  135.                 -- unnecessary keyframe
  136.             else
  137.                 file:write("\t"..j.."\t"..valX.."\t"..valY.."\t"..valZ.."\n")
  138.             end
  139.         end
  140.         --
  141.         file:write("\n")
  142.     end
  143. end
  144.  
  145. file:write("\nEnd of Keyframe Data")
  146. file:close()
  147. console.writeline("Done.")
Add Comment
Please, Sign In to add comment