PHP Code:
#!/usr/bin/python
import struct
import cStringIO
import os
import time
import zlib
def Main(OldVer, NewVer):
#Read old Nexon Patcher
PrintLog('%sto%s - Reading manualpatch.base file' % (OldVer, NewVer))
Base = openfile('manualpatch.base', 'rb')
BaseData = CheckBase(Base.read(), OldVer, NewVer)
Base.close()
#Read the patch data
PrintLog('%sto%s - Reading the patch data' % (OldVer, NewVer))
Patch = openfile(OldVer + 'to' + NewVer + '.patch', 'rb')
PatchData = CheckZLIB(Patch.read(), OldVer, NewVer)
PatchSize = len(PatchData)
Patch.close()
#Read the patch text file
PrintLog('%sto%s - Reading the notice file' % (OldVer, NewVer))
Notice = cStringIO.StringIO('Created by Fiel - Southperry.net\r\nPatch 0.%s' % RemoveZeros(NewVer))
NoticeData = Notice.read()
NoticeSize = len(NoticeData)
Notice.close()
#Constructing the ManualPatcher
PrintLog('%sto%s - Creating the Manual Patcher' % (OldVer, NewVer))
ManualPatcher = openfile(OldVer + 'to' + NewVer + '.exe', 'wb')
ManualPatcher.write(BaseData)
ManualPatcher.write(PatchData)
ManualPatcher.write(NoticeData)
ManualPatcher.write(struct.pack('L', PatchSize))
ManualPatcher.write(struct.pack('L', NoticeSize))
ManualPatcher.write(struct.pack('BBBB', 0xF3, 0xFB, 0xF7, 0xF2))
ManualPatcher.close()
PrintLog('%sto%s - Manual Patcher created successfully!' % (OldVer, NewVer))
def PrintError(StringError):
f = open('PatcherLog.txt', 'a')
f.write('%s : ERROR - %s\n' % (time.strftime('%x (%H:%M)'),StringError))
f.close()
exit(-1)
def PrintLog(StringLog):
f = openfile('PatcherLog.txt', 'a')
f.write('%s : %s\n' % (time.strftime('%x (%H:%M)'),StringLog))
f.close()
def openfile(FileName, OpenType):
try:
f = open(FileName, OpenType)
except IOError:
PrintError('File %s does not exist. Please make sure the file is in all lowercase letters.' % (FileName))
return f
def RemoveZeros(string):
if string[0] == '0':
string = RemoveZeros(string[1:])
return string
def CheckBase(BaseFile, OldVer, NewVer):
if hex(struct.unpack('H', BaseFile[0:2])[0]) == '0xda78':
BaseFile = zlib.decompress(BaseFile)
crc = zlib.crc32(BaseFile)
PrintLog('%sto%s - Checking the manualpatch.base file for the correct version.' % (OldVer, NewVer))
if crc != 562146221:
PrintError('manualpatch.base file is the wrong version. Please download the newest version from southperry.net/manualpatch.base')
else:
return BaseFile
def CheckZLIB(PatchFile, OldVer, NewVer):
text = PatchFile[16:len(PatchFile)]
PrintLog('%sto%s - Checking the *.patch file for errors' % (OldVer, NewVer))
try:
zlib.decompress(text)
except:
PrintError('%sto%s.patch is corrupt.' % (OldVer, NewVer))
return PatchFile
def FindPatches():
patchnames = []
ManualPatchBase = 0
for file in os.listdir('.'):
if file[-6:] == '.patch':
x = file.replace('.patch','')
x = x.split('to')
if len(x) != 2:
PrintError("Patch file name '%s' is incorrect. It must be in the format 'XtoY.patch' where X is your current version and Y is the version you're patching to." % file)
PrintLog('Found patch file %s' % file)
patchnames.append(x)
elif file == 'manualpatch.base':
ManualPatchBase = 1
if patchnames == []:
PrintError('There are no *.patch files in your current directory.')
if ManualPatchBase == 0:
PrintError('manualpatch.base does not exist. Please download it from southperry.net/manualpatch.base to your current directory')
return patchnames
Versions = FindPatches()
for OldVer, NewVer in Versions:
Main(OldVer, NewVer)
Bookmarks