Advertisement
benstephens56

CTM File Explanation

Jan 18th, 2022 (edited)
413
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.23 KB | None | 0 0
  1. Files that have the .ctm extension are Citra movie files, used for storing input data. This input data can be used to perfectly recreate gameplay and is most commonly known to be used for the creation of Tool Assisted Speedruns (TAS). As far as I am aware there is no thorough explanation or notes on how .ctm files are structured other than in the source code for Citra in the directory citra/src/core/movie.cpp. Because of this, I have gone through and learned how the file format is structured using the source code and will explain my findings.
  2.  
  3. .ctm files always begin with a 256 byte header. I will be explaining the current canary version of .ctm files here as they are mostly the same besides storing some extra information. The header data is structured as follows:
  4.  
  5. 1.) 0x00 -> Filetype identifier. These 4 bytes will always be 43 54 4D 1B. In ascii, this says "CTM 0x1B" to ensure that this is indeed
  6. a CTM file
  7. 2.) 0x04 -> ROM ID. These 8 bytes tell the movie file which game the movie file is associated with. This data is read in little endian
  8. meaning it is interpreted from right to left. The remaining header data will be in little endian. This data is also
  9. interpreted in hex.
  10. 3.) 0x0C -> Revision git hash. These 20 bytes show what version of Citra the movie was created with.
  11. 4.) 0x20 -> System clock init time. These 8 bytes show time at which the movie file was created. This time is determined by the 3DS
  12. clock setting.
  13. 5.) 0x28 -> Movie ID. These 8 are a unique ID generated for every movie. These ID help keep savestates separate for each movie file.
  14. 6.) 0x30 -> Movie author. These 32 bytes show the author of the movie as inputted during movie creation.
  15. 7.) 0x50 -> Record count. These 4 bytes show how many rerecords have been performed for this movie.
  16. 8.) 0x54 -> Input poll count. These 4 bytes show how many times Citra has pulled for button and circle pad inputs during the length of
  17. the movie. This count is how Citra keeps track of how long the movie is.
  18. 9.) 0x5C -> Padding. These 164 bytes are just used to get the header to 256 bytes. These should all be 00.
  19.  
  20. Here's an image to help visualize the structure: https://imgur.com/YtJnt3K.png
  21.  
  22. After the data associated with the header comes the actual input data for the movie starting at 0x100. Input data is unfortunately not stored in a format that is very easy to view or edit manually. Input data is stored in 7 byte chunks that are associated with the various controller states. These states are:
  23. 00 -> PadAndCircle: The data associated with button and circle pad inputs
  24. 01 -> Touch: Touchscreen inputs
  25. 02 -> Accelerometer: Accelerometer data
  26. 03 -> Gyroscope: Gyro data
  27. 04 -> IrRst (debreciated???): Data associated with the the extra inputs for the circle pad pro (C Stick, ZL, ZR)
  28. 05 -> ExtraHidResponse: Data associated with the the extra inputs for the New 3DS or circle pad pro (C Stick, ZL, ZR)
  29.  
  30. Each 7 byte chunk begins with 1 byte that specifies the controller state. For example, if the controller state is the touch screen, the data chunk will begin with 01. The following 6 bytes specify the actual input data such as where on the touch screen is being touched. The tricky part is that these data chunks are recorded as Citra is polling for the various types of information. Because all of these different controller states are not polled at the same rates, these data chunks are not in a consistent order. This also means that input data for any of the given controller states will be polled multiple times on any given frame. This makes syncing a movie very consistent based on my testing but makes hex editing very challenging. The various polling rates are as follows
  31. PadAndCircle = 234 ticks/second
  32. Touch = 234 ticks/second
  33. Accelerometer = 105 ticks/second
  34. Gyroscope = 101 ticks/second
  35. IrRst = ??? (I believe that movie files always use ExtraHidResponse instead of this)
  36. ExtraHidResponse = Different depending on the game
  37.  
  38. This image contains a diagram that explains how the data is structured for each controller state: https://imgur.com/cYfAU7w.png
  39.  
  40. I have created a template file that works with 010 Editor, a robust hex editor software, that helps to easily parse CTM files. More details here: https://github.com/benstephens56/Citra-Movie-File-Parser
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement