SHARE
TWEET

scdSplit.py

Soneek Jul 10th, 2015 331 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Written by soneek [github.com/soneek]
  2. # Specifically written for Kingdom Hearts 1.5 HD ReMIX
  3. # Not guaranteed to work elsewhere
  4.  
  5. import string
  6. import struct
  7. import sys
  8.  
  9. def readSeek(f, offset, size):
  10.         f.seek(offset)
  11.         return f.read(size)
  12.  
  13. def writeSeek(f, offset, data):
  14.         f.seek(offset)
  15.         return f.write(data)   
  16.  
  17. if len(sys.argv) != 2:
  18.         print "Usage:\n\t" + sys.argv[0] + " song.scd"
  19.         sys.exit()
  20.        
  21. scd = open(sys.argv[1], "rb")
  22. scdSize = struct.unpack(">I", readSeek(scd, 0x14, 4))[0]
  23.  
  24. trackCount = struct.unpack(">H", readSeek(scd, 0x34, 2))[0]
  25. print trackCount
  26. trackOffsetOffset = 0x40 + struct.unpack(">H", readSeek(scd, 0xe, 2))[0]
  27. if trackCount > 1:
  28.         for i in range(0, trackCount):
  29.                 trackOffset = struct.unpack(">I", readSeek(scd, trackOffsetOffset + i * 4, 4))[0]
  30.                 if i == trackCount - 1:
  31.                         trackSize = scdSize - trackOffset
  32.                 else:
  33.                         trackSize = struct.unpack(">I", readSeek(scd, trackOffsetOffset + (i+1) * 4, 4))[0] - trackOffset
  34.                 print hex(trackOffset)
  35.                 outName = string.replace(sys.argv[1], ".scd", "_" + str(i) + ".scd")
  36.                 outscd = open(outName, "wb")
  37.                 outscd.write(readSeek(scd, 0, 0x34))
  38.                 outscd.write(struct.pack(">H", 1))
  39.                 outscd.write(readSeek(scd, 0x36, 0x3a))
  40.                 outscd.write(struct.pack(">IIII", 0x80, 0, 0, 0))
  41.                 outscd.write(readSeek(scd, trackOffset, trackSize))
  42.                 trackSize = outscd.tell()
  43.                 writeSeek(outscd, 0x14, struct.pack(">I", trackSize))
  44.                 outscd.close()
  45. scd.close()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top