SHARE
TWEET

Final Fantasy VI - ACK palette swapper

MaKiPL Nov 14th, 2018 90 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import sys
  2. import struct
  3.  
  4. #this is script to swap the colours in place especially made for use with Final Fantasy VI tiles
  5.  
  6. PaletteStartOriginal = 0x33;
  7. PaletteStartReplace = 0x60 #the first palette to inject into first 15 colours
  8. PaletteShift = 48 #0x90 - 0x60
  9. ColoursToProcess = 13 #because (0x2D0 - 0x60)/PaletteShift
  10.  
  11. def replaceBytes(FirstAddress, SecondAddresss):
  12.     SecondaryWriteBuffer[FirstAddress] = OriginalBuffer[SecondAddresss] #I'm doing this extremely easy way just to show step-by-step-by
  13.     SecondaryWriteBuffer[FirstAddress+1] = OriginalBuffer[SecondAddresss+1]
  14.     SecondaryWriteBuffer[FirstAddress+2] = OriginalBuffer[SecondAddresss+2]
  15.     #we just copied OriginalBuffer at address two (i.e. 0x90) to writeBuffer at location of first address. Now we rotate the buffers and do the opposite
  16.     SecondaryWriteBuffer[SecondAddresss] = OriginalBuffer[FirstAddress]
  17.     SecondaryWriteBuffer[SecondAddresss+1] = OriginalBuffer[FirstAddress+1]
  18.     SecondaryWriteBuffer[SecondAddresss+2] = OriginalBuffer[FirstAddress+2]
  19.     #that's all, we just changed in place the colours at FirstAddress and SecondAddresss
  20.  
  21.  
  22. FileStream = open(sys.argv[1], 'rb') #we are opening the file given on commandline parameter. rb stands for 'read binary'
  23. OriginalBuffer = FileStream.read() #we are now reading FULL content of the file into OriginalBuffer array
  24. FileStream.close() #we don't need this file anymore locked as stream
  25. SecondaryWriteBuffer = list(OriginalBuffer) #we have to do a copy- swapping values on one buffer is problematic. It's simplier this way
  26. for i in range(0,ColoursToProcess):
  27.     replaceBytes(PaletteStartOriginal+ (i*3), PaletteStartReplace + (i*PaletteShift)) #i*3 because the first 0x33 is changing by 3, and i*48 because we replace every 15 colour
  28. FileWrite = open(sys.argv[1] + "_swapped", 'wb') #we appended a _swapped to filename and opened in WriteBinary mode
  29. FileWrite.write(''.join(SecondaryWriteBuffer)) #here's the trick. Normally a string is immutable, so we cast it to list and then join an empty string with every element of the list
  30. FileWrite.close() #and we close the file so it's accesible outside the program
  31. exit() #good bye!
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