Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #This script will generate dat files that allow offline play of premium modules for the game Neverwinter Nights.
- #YOU MUST ONLY USE THIS SCRIPT TO GENERATE DATS FOR PREMIUM MODULES THAT YOU LEGALLY OWN!
- import os, sys
- from binascii import unhexlify
- try:
- from Crypto.Cipher import Blowfish
- except ImportError:
- print 'You must have PyCrypto installed to use this script.'
- print "\nIf you're on Windows, the easiest way to get it is to grab an installer from:"
- print 'http://www.voidspace.org.uk/python/modules.shtml#pycrypto'
- sys.exit()
- #These are only part of the key used to decrypt the module.
- #The game generates the last 16 bytes of the key from the MD5 hash over the NWM file for the module.
- #Once you have the full key, you can decrypt the HAK with Blowfish in ECB mode, ignoring the first 8 bytes of the file.
- keys = [
- [unhexlify('5CA883CE6D9C843BDEA1D7857887FD0DD79742389353CD3DEC03CE150948D79B86201921C26E42EE'), "Neverwinter Nights - Kingmaker.dat"],
- [unhexlify('ECBF9A7539E46510CAA1B63A76A250DDE206EA39200FBCC75D03D6B27583EF08A7FD68DB33AA69A1'), "Neverwinter Nights - ShadowGuard.dat"],
- [unhexlify('72A38B0C496353327D869C3D488477BDBB7C48DC33454078AF2664967F804467F7DA0874F4D87C2D'), "Neverwinter Nights - Witch's Wake.dat"],
- [unhexlify('9437DD56EDD9F0419128C2D54F97E85D954241B5A3A203B6088BC1C7CBEED8D9834E9FAB69416CFC'), "Neverwinter Nights - Pirates of the Sword Coast.dat"],
- [unhexlify('1DEA5E040B43F22F239004385CA1189CFFB1B186E669678E2908944C08220A8C9DC5FEE22784E7D3'), "Neverwinter Nights - Wyvern Crown of Cormyr.dat"],
- [unhexlify('8A835A2D01105CBECE2CD069B848C9BEAA7E57BDAB94CE0D0910BD578D1A0D35C98490FA7B653297'), "Neverwinter Nights - Infinite Dungeons.dat"]
- ]
- if len(sys.argv) < 2:
- print 'Usage: %s *Key1*' % (os.path.basename(sys.argv[0]))
- print 'Example: %s ABCDE-FGHIJ-KLMNO-PQRST-UVWXY-ZABCD-EFGHI' % (os.path.basename(sys.argv[0]))
- print '\nTo find your CD key, look in "nwncdkey.ini" in the game folder.'
- print 'You want the key listed as "Key1".'
- print'\nYOU MUST ONLY USE THIS SCRIPT TO GENERATE DATS\nFOR PREMIUM MODULES THAT YOU LEGALLY OWN!'
- sys.exit()
- cdKey = sys.argv[1].upper()
- cdKey = cdKey.replace('-','')
- if len(cdKey) != 35:
- print 'The CD key(minus dashes) should be 35 characters long'
- sys.exit()
- cdKey = cdKey + b'\x00' * (56-len(cdKey)) #Pad the CD key on the right with 0x00 to 56 bytes to get the encryption key for the dat.
- cipher = Blowfish.new(cdKey, Blowfish.MODE_ECB)
- print '\nModules:'
- for idx, key in enumerate(keys):
- print '[%u] %s' % (idx+1, key[1][:-4])
- print '[q] quit'
- print'\nYOU MUST ONLY USE THIS SCRIPT TO GENERATE DATS\nFOR PREMIUM MODULES THAT YOU LEGALLY OWN!\n'
- while(1):
- inp = raw_input("Module choice: ")
- try:
- mnum = int(inp)-1
- except ValueError:
- if inp == 'q':
- sys.exit()
- continue
- if (mnum < 0) or (mnum > 5):
- continue
- buff = b'\x01' #Pointer to key data(just this 1 byte)
- buff += keys[mnum][0] #Key data
- buff += b'\x00' * (1024-1-len(buff)) #Rest of the file can be whatever, it's not checked by the game.
- buff += b'\x28' #Hardcoded check in the game for 0x28 here
- if len(buff) != 1024:
- print 'Error'
- sys.exit()
- with open(keys[mnum][1], 'wb') as fh:
- fh.write(cipher.encrypt(buff))
- print 'Created "%s"' % (keys[mnum][1])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement