Nicknine

Sonic and Knuckles Lock-on Builder

Jan 20th, 2026 (edited)
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.69 KB | None | 0 0
  1. import os
  2. import sys
  3.  
  4. def buildRom(bname,fname):
  5.     name,ext=os.path.splitext(os.path.basename(fname))
  6.  
  7.     # Read Sonic & Knuckles data.
  8.     f=open("%s.md" % bname,"rb")
  9.     data1=f.read()
  10.     f.close()
  11.  
  12.     # Open locked-on ROM.
  13.     f=open(fname,"rb")
  14.  
  15.     # Get file size.
  16.     f.seek(0x00,2)
  17.     size=f.tell()
  18.  
  19.     if size<0x200:
  20.         print("Not a Genesis/Mega Drive ROM")
  21.         return False
  22.  
  23.     f.seek(0x100)
  24.     testData=f.read(0x10)
  25.     if testData not in [b"SEGA MEGA DRIVE ",b"SEGA GENESIS    "]:
  26.         print("Not a Genesis/Mega Drive ROM")
  27.         return False
  28.  
  29.     # Round the size up to the next power of two to get the true ROM size.
  30.     romSize=1<<(size-1).bit_length()
  31.  
  32.     # Append the last 2 MiB from locked-on ROM.
  33.     f.seek(max(0x00,romSize-0x200000))
  34.     data2=f.read()
  35.     f.close()
  36.  
  37.     # Check if it's Sonic 2 and append 256 KiB patch ROM if needed.
  38.     isSonic2=False
  39.  
  40.     # Lock-on serials:
  41.     # "GM 00001051-00" # Sonic 2 REV00
  42.     # "GM 00001051-01" # Sonic 2 REV01
  43.     # "GM 00001051-02" # Sonic 2 REV02
  44.     # "GM MK-1079 -00" # Sonic 3
  45.     # Blue Spheres unlocking serials:
  46.     # "GM 00001009-0" # Sonic 1 REV00
  47.     # "GM 00004049-0" # Sonic 1 REV01
  48.     if (data2[0x180:0x18e] in [b"GM 00001051-00",b"GM 00001051-01",b"GM 00001051-02"]):
  49.         isSonic2=True
  50.         f=open("Sonic & Knuckles (World) (Lock-on).bin","rb")
  51.         datas2k=f.read()
  52.         f.close()
  53.  
  54.     f=open("%s + %s.md" % (bname,name),"wb")
  55.     f.write(data1)
  56.     f.write(data2)
  57.     if isSonic2: f.write(datas2k)
  58.     f.close()
  59.  
  60.     return True
  61.  
  62. if __name__=="__main__":
  63.     bname="Sonic & Knuckles (World)"
  64.     fname=sys.argv[1]
  65.     buildRom(bname,fname)
  66.  
Advertisement
Add Comment
Please, Sign In to add comment