Advertisement
Nicknine

PACTOOL

Aug 12th, 2022 (edited)
1,060
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 20.28 KB | None | 0 0
  1. tempclut = [(0, 0, 0, 255), (1, 1, 1, 255), (2, 2, 2, 255), (3, 3, 3, 255), (4, 4, 4, 255), (5, 5, 5, 255), (6, 6, 6, 255), (7, 7, 7, 255), (8, 8, 8, 255), (9, 9, 9, 255), (10, 10, 10, 255), (11, 11, 11, 255), (12, 12, 12, 255), (13, 13, 13, 255), (14, 14, 14, 255), (15, 15, 15, 255), (16, 16, 16, 255), (17, 17, 17, 255), (18, 18, 18, 255), (19, 19, 19, 255), (20, 20, 20, 255), (21, 21, 21, 255), (22, 22, 22, 255), (23, 23, 23, 255), (24, 24, 24, 255), (25, 25, 25, 255), (26, 26, 26, 255), (27, 27, 27, 255), (28, 28, 28, 255), (29, 29, 29, 255), (30, 30, 30, 255), (31, 31, 31, 255), (32, 32, 32, 255), (33, 33, 33, 255), (34, 34, 34, 255), (35, 35, 35, 255), (36, 36, 36, 255), (37, 37, 37, 255), (38, 38, 38, 255), (39, 39, 39, 255), (40, 40, 40, 255), (41, 41, 41, 255), (42, 42, 42, 255), (43, 43, 43, 255), (44, 44, 44, 255), (45, 45, 45, 255), (46, 46, 46, 255), (47, 47, 47, 255), (48, 48, 48, 255), (49, 49, 49, 255), (50, 50, 50, 255), (51, 51, 51, 255), (52, 52, 52, 255), (53, 53, 53, 255), (54, 54, 54, 255), (55, 55, 55, 255), (56, 56, 56, 255), (57, 57, 57, 255), (58, 58, 58, 255), (59, 59, 59, 255), (60, 60, 60, 255), (61, 61, 61, 255), (62, 62, 62, 255), (63, 63, 63, 255), (64, 64, 64, 255), (65, 65, 65, 255), (66, 66, 66, 255), (67, 67, 67, 255), (68, 68, 68, 255), (69, 69, 69, 255), (70, 70, 70, 255), (71, 71, 71, 255), (72, 72, 72, 255), (73, 73, 73, 255), (74, 74, 74, 255), (75, 75, 75, 255), (76, 76, 76, 255), (77, 77, 77, 255), (78, 78, 78, 255), (79, 79, 79, 255), (80, 80, 80, 255), (81, 81, 81, 255), (82, 82, 82, 255), (83, 83, 83, 255), (84, 84, 84, 255), (85, 85, 85, 255), (86, 86, 86, 255), (87, 87, 87, 255), (88, 88, 88, 255), (89, 89, 89, 255), (90, 90, 90, 255), (91, 91, 91, 255), (92, 92, 92, 255), (93, 93, 93, 255), (94, 94, 94, 255), (95, 95, 95, 255), (96, 96, 96, 255), (97, 97, 97, 255), (98, 98, 98, 255), (99, 99, 99, 255), (100, 100, 100, 255), (101, 101, 101, 255), (102, 102, 102, 255), (103, 103, 103, 255), (104, 104, 104, 255), (105, 105, 105, 255), (106, 106, 106, 255), (107, 107, 107, 255), (108, 108, 108, 255), (109, 109, 109, 255), (110, 110, 110, 255), (111, 111, 111, 255), (112, 112, 112, 255), (113, 113, 113, 255), (114, 114, 114, 255), (115, 115, 115, 255), (116, 116, 116, 255), (117, 117, 117, 255), (118, 118, 118, 255), (119, 119, 119, 255), (120, 120, 120, 255), (121, 121, 121, 255), (122, 122, 122, 255), (123, 123, 123, 255), (124, 124, 124, 255), (125, 125, 125, 255), (126, 126, 126, 255), (127, 127, 127, 255), (128, 128, 128, 255), (129, 129, 129, 255), (130, 130, 130, 255), (131, 131, 131, 255), (132, 132, 132, 255), (133, 133, 133, 255), (134, 134, 134, 255), (135, 135, 135, 255), (136, 136, 136, 255), (137, 137, 137, 255), (138, 138, 138, 255), (139, 139, 139, 255), (140, 140, 140, 255), (141, 141, 141, 255), (142, 142, 142, 255), (143, 143, 143, 255), (144, 144, 144, 255), (145, 145, 145, 255), (146, 146, 146, 255), (147, 147, 147, 255), (148, 148, 148, 255), (149, 149, 149, 255), (150, 150, 150, 255), (151, 151, 151, 255), (152, 152, 152, 255), (153, 153, 153, 255), (154, 154, 154, 255), (155, 155, 155, 255), (156, 156, 156, 255), (157, 157, 157, 255), (158, 158, 158, 255), (159, 159, 159, 255), (160, 160, 160, 255), (161, 161, 161, 255), (162, 162, 162, 255), (163, 163, 163, 255), (164, 164, 164, 255), (165, 165, 165, 255), (166, 166, 166, 255), (167, 167, 167, 255), (168, 168, 168, 255), (169, 169, 169, 255), (170, 170, 170, 255), (171, 171, 171, 255), (172, 172, 172, 255), (173, 173, 173, 255), (174, 174, 174, 255), (175, 175, 175, 255), (176, 176, 176, 255), (177, 177, 177, 255), (178, 178, 178, 255), (179, 179, 179, 255), (180, 180, 180, 255), (181, 181, 181, 255), (182, 182, 182, 255), (183, 183, 183, 255), (184, 184, 184, 255), (185, 185, 185, 255), (186, 186, 186, 255), (187, 187, 187, 255), (188, 188, 188, 255), (189, 189, 189, 255), (190, 190, 190, 255), (191, 191, 191, 255), (192, 192, 192, 255), (193, 193, 193, 255), (194, 194, 194, 255), (195, 195, 195, 255), (196, 196, 196, 255), (197, 197, 197, 255), (198, 198, 198, 255), (199, 199, 199, 255), (200, 200, 200, 255), (201, 201, 201, 255), (202, 202, 202, 255), (203, 203, 203, 255), (204, 204, 204, 255), (205, 205, 205, 255), (206, 206, 206, 255), (207, 207, 207, 255), (208, 208, 208, 255), (209, 209, 209, 255), (210, 210, 210, 255), (211, 211, 211, 255), (212, 212, 212, 255), (213, 213, 213, 255), (214, 214, 214, 255), (215, 215, 215, 255), (216, 216, 216, 255), (217, 217, 217, 255), (218, 218, 218, 255), (219, 219, 219, 255), (220, 220, 220, 255), (221, 221, 221, 255), (222, 222, 222, 255), (223, 223, 223, 255), (224, 224, 224, 255), (225, 225, 225, 255), (226, 226, 226, 255), (227, 227, 227, 255), (228, 228, 228, 255), (229, 229, 229, 255), (230, 230, 230, 255), (231, 231, 231, 255), (232, 232, 232, 255), (233, 233, 233, 255), (234, 234, 234, 255), (235, 235, 235, 255), (236, 236, 236, 255), (237, 237, 237, 255), (238, 238, 238, 255), (239, 239, 239, 255), (240, 240, 240, 255), (241, 241, 241, 255), (242, 242, 242, 255), (243, 243, 243, 255), (244, 244, 244, 255), (245, 245, 245, 255), (246, 246, 246, 255), (247, 247, 247, 255), (248, 248, 248, 255), (249, 249, 249, 255), (250, 250, 250, 255), (251, 251, 251, 255), (252, 252, 252, 255), (253, 253, 253, 255), (254, 254, 254, 255), (255, 255, 255, 255)]
  2. from operator import itemgetter
  3. import struct, os
  4. from PIL import Image
  5.  
  6.  
  7. BANK = 0x800
  8. VRAMSIZ = 0x64000
  9. ZONELIMIT = 0x4A800
  10.  
  11. RGBAMO = 40
  12. RGBEND = 0x776D800
  13. RGBSIZ = 0x96000
  14.  
  15. EMUEND = 0x756E800
  16. EMUSIZ = 0x181D60
  17. #EMUSIZ = 0x1FEB20
  18.  
  19. OUT = "ex/"
  20. INFILE = "DEMO.PAC"
  21.  
  22. RATELIST = {
  23.     0x7800: 12000,
  24.     0x7F00: 11714,
  25.  
  26. }
  27.  
  28.  
  29.  
  30. def mdir(directory):
  31.   if not os.path.exists(directory):
  32.     os.makedirs(directory)
  33.  
  34. def getB(number=1):
  35.     return int.from_bytes(rom.read(number), byteorder='little')
  36.  
  37. def roundUp(num):
  38.     out = BANK - (num % BANK)
  39.     if out == BANK:
  40.         out = 0
  41.     return out
  42.  
  43. def align(num):
  44.     o = 4 - (num % 4)
  45.     if o == 4:
  46.         return 0
  47.     return o
  48.  
  49. def genVRAM(name):
  50.     o = open(name, "wb+")
  51.     o.write(bytes([0]*0x100000))
  52.     return o
  53.  
  54. def c2a(x,y):
  55.     #coordinate to adress
  56.     return (y << 11) + (x << 1)
  57.  
  58. def w2c(word):
  59.     #word to coords
  60.     return (int((bin(word)[2:].zfill(16))[10:], 2) << 4 , int((bin(word)[2:].zfill(16))[1:10], 2))
  61.  
  62. def getGFX(size, alloc):
  63.     skip = alloc-size
  64.     o = rom.read(size)
  65.     rom.read(skip)
  66.     return o
  67.  
  68. def draw(what, where, x=0,y=0,w=0,h=0):
  69.     if x|y|w|h == 0:
  70.         where.write(what)
  71.         return
  72.  
  73.     where.seek(c2a(x,y))
  74.     w = w << 1
  75.     for r in range(0, h*w, w):
  76.         where.write(what[r:r+w])
  77.         where.seek(-w+0x800, 1)
  78.     return
  79.  
  80. def getPalette(adr, infile):
  81.     #print("gonna get pal from 0x{:X}".format(adr))
  82.     infile.seek(adr)
  83.     words = struct.unpack("<256H",infile.read(0x200))
  84.     rgbas = []
  85.     for num in range(0,len(words)):
  86.         _R = ((words[num] & 0x1F)) * 8
  87.         _G = ((words[num] & 0x3E0) >> 5) * 8
  88.         _B = ((words[num] & 0x7C00) >> 10) * 8
  89.         if (words[num] == 0):
  90.             _A = 0
  91.         else:
  92.             _A = 0xFF
  93.         rgbas.append((_R,_G,_B,_A))
  94.     return rgbas
  95.  
  96. def picture(name, nul, bpp, tp, x, y, w, h, clutW, vram):
  97.     if clutW == 0xFFFF:
  98.         clut_pool[clutW] = tempclut
  99.         print("NOTICE ",name)
  100.     if clutW not in clut_pool:
  101.         #print("{:08X} not seen, adding".format(clutW))
  102.         clut_pool[clutW] = getPalette(c2a(*w2c(clutW)), vram)
  103.  
  104.  
  105.     #print(name, nul, bpp, tp, x, y, w, h, clutW)
  106.  
  107.     tpx = tp & 0xF
  108.     #print("tpx<<7:",tpx << 7,"x",x)
  109.     tpy = (tp >> 4) << 19
  110.     pixels = []
  111.     canvas = Image.new("RGBA", (w, h))
  112.     if bpp == 0:
  113.         w >>= 1
  114.         vram.seek(tpy + (tpx << 7)+(x>>1) + (y << 11))
  115.     else:
  116.         vram.seek(tpy + (tpx << 7)+x + (y << 11))
  117.  
  118.     for r in range(0, h):
  119.         if bpp == 4:
  120.             for c in range(0, w):
  121.                 idx = ord(vram.read(1))
  122.                 pixels.append(clut_pool[clutW][idx])
  123.             vram.seek(-w+0x800, 1)
  124.         elif bpp == 0:
  125.             for c in range(0, w):
  126.                 idx = ord(vram.read(1))
  127.                 pixels.append(clut_pool[clutW][idx&0xF])
  128.                 pixels.append(clut_pool[clutW][idx>>4])
  129.             vram.seek(-w+0x800, 1)
  130.  
  131.     canvas.putdata(pixels)
  132.  
  133.     return canvas
  134.  
  135. def testADPCM():
  136.     rom.seek(-4, 1)
  137.     rta = rom.tell()
  138.     amask = 0xFFFF0F80FFFF00EE
  139.     #         00001FC0000080FF
  140.     #         0000DFEB00008CEE
  141.     #         00005FCD0000A5FF
  142.     #         0000DFEB000000FF
  143.     #         00001FC0000080FF
  144.     arslt = 0x00000F80000000EE
  145.     first = False
  146.     pcmque = []
  147.     while True:
  148.         esniff = getB(4)
  149.         if first:
  150.             if esniff == 0xFFFFFFFF:
  151.                 #print("ADPCM MATCH!!")
  152.                 adpcm = True
  153.                 break
  154.         pcm1, pcm2, pcm_adr, pcm_size = struct.unpack("<HHII", rom.read(0xC))
  155.         sniff = getB(8)
  156.         if sniff & amask == arslt:
  157.             print("    adr {:08X} size {:08X}".format(pcm_adr, pcm_size))
  158.             pcmque.append((pcm_adr, pcm_size))
  159.             first = True
  160.             continue
  161.         else:
  162.             print("False positive. Not ADPCM!")
  163.             if first:
  164.                 print("WEIRD THO")
  165.             adpcm = False
  166.             break
  167.  
  168.     rom.seek(rta)
  169.     return adpcm
  170.  
  171. def getADPCMlist():
  172.     adpcmlist = []
  173.  
  174.     while True:
  175.         sniff = getB(4)
  176.         if sniff == 0xFFFFFFFF:
  177.             break
  178.         else:
  179.             rom.seek(-4,1)
  180.  
  181.         _ = {}
  182.         _["u0"], _["u1"], _["u2"], _["rate"], _["adr"], _["size"], _["u4"], _["u5"] = struct.unpack("<HHHHIIII", rom.read(0x18))
  183.         adpcmlist.append(_)
  184.  
  185.     return adpcmlist
  186.  
  187. def getRGB():
  188.     o = []
  189.     for p in range(0, RGBSIZ>>1):
  190.         _ = getB(2)
  191.         b = ((_ >> 10) & 0x1F) << 3
  192.         g = ((_ >>  5) & 0x1F) << 3
  193.         r = ((_ >>  0) & 0x1F) << 3
  194.         o.append((r,g,b,255))
  195.     return o
  196.  
  197. with open(INFILE, "rb") as rom:
  198.     mdir(OUT)
  199.     fidx = 0
  200.  
  201.     while True:
  202.         print("\n")
  203.         root = rom.tell()
  204.         check = getB(4)
  205.  
  206.         if check == 0x001F0001:
  207.             VRAMFOLDER = OUT+"{:03d}_VRAM/".format(fidx)
  208.             mdir(VRAMFOLDER)
  209.             print("VRAM at 0x{:X}".format(root))
  210.             both = 0
  211.  
  212.             while True:
  213.                 root = rom.tell()-4
  214.                 amount = getB(4)
  215.                 bonus1 = getB(4)
  216.                 bonus2 = getB(4)
  217.  
  218.                 if bonus1 > 5:
  219.                     print("V case at {:08X}".format(root))
  220.                     #V case
  221.                     vram = genVRAM("tempVRAM.BIN")
  222.                     gfx_queue = []
  223.                     crd_queue = []
  224.                     for i in range(0, amount):
  225.                         crd_queue.append(struct.unpack("<HHHH", rom.read(0x8)))
  226.                         gfx_queue.append(struct.unpack("<II", rom.read(0x8)))
  227.  
  228.                     rom.seek(roundUp(rom.tell()), 1)
  229.                     for i in range(0, amount):
  230.                         gfx = getGFX(*gfx_queue[i])
  231.                         crd = crd_queue[i]
  232.                         draw(gfx, vram, *crd)
  233.                         #draw(gfx, shard) < coming
  234.  
  235.                     with open(VRAMFOLDER+"{:03d}.vram".format(fidx), "wb") as temp:
  236.                         vram.seek(0)
  237.                         temp.write(vram.read())
  238.  
  239.                     both += 1
  240.  
  241.  
  242.                 else:
  243.                     print("N case at {:08X}".format(root))
  244.                     #N case
  245.                     pic_queue = []
  246.                     for i in range(0, amount):
  247.                         fname, nul, page, x, y, w, h, clutW = struct.unpack("<8sI6H", rom.read(0x18))
  248.                         tp = page & 0x1F
  249.                         bpp = page >> 5
  250.                         name = fname.decode("utf-8").rstrip('\x00')
  251.                         pic_queue.append((name, nul, bpp, tp, x, y, w, h, clutW))
  252.                         #print(name, "{:08X}".format(clutW))
  253.                         #print("{:16s}\t{:08X} {:04X} {:04X} {:04X} {:04X} {:04X} {:04X}".format(name,nul, id1, id2, id3, id4, id5, id6))
  254.                     if rom.tell() % BANK == 0:
  255.                         print("CLASH! +1")
  256.                         rom.read(1)
  257.                     both += 1
  258.  
  259.                 print("case ends at {:08X}".format(rom.tell()))
  260.  
  261.                 rom.seek(roundUp(rom.tell()), 1)
  262.                 if both == 2:
  263.                     break
  264.                 check = getB(4)
  265.  
  266.             clut_pool = {}
  267.             for pic in pic_queue:
  268.                 picture(*pic, vram).save(VRAMFOLDER+pic[0]+".PNG")
  269.  
  270.  
  271.         elif check == 0x00010003:
  272.             print("LIST at 0x{:X}".format(root))
  273.             LISTFOLDER = OUT+"{:03d}_LIST/".format(fidx)
  274.             curf = LISTFOLDER
  275.             mdir(curf)
  276.  
  277.             amo = getB(4)
  278.             if amo == 0:
  279.                 rom.seek(roundUp(rom.tell()), 1)
  280.                 continue
  281.  
  282.             entryque = []
  283.             for i in range(0,amo):
  284.                 _foname, findex, _finame, fadr, fsize = struct.unpack("<4sI16sII", rom.read(0x20))
  285.  
  286.                 try:
  287.                     foname = _foname.decode("utf-8").rstrip('\x00')
  288.                 except UnicodeDecodeError:
  289.                     fonum = "{:08X}".format(struct.unpack("<I", _foname)[0])
  290.                     if fonum == "000000FD":
  291.                         foname = "PRM"
  292.                     else:
  293.                         foname = fonum#str(_foname)
  294.  
  295.                 try:
  296.                     finame = _finame.decode("utf-8").rstrip('\x00')
  297.                 except UnicodeDecodeError:
  298.                     finame = "{:08X}".format(struct.unpack("<I", _finame)[0])#str(_finame)
  299.  
  300.                 if finame == " ":
  301.                     finame = "NONAME.non"
  302.                 if "." not in finame:
  303.                     finame += ".s3d"
  304.                 estr = "{:8s} {:12s} {:08X}".format(foname,finame,findex)
  305.                 entryque.append([fadr, estr, fsize, foname, finame])
  306.  
  307.             for ofile in range(0,len(entryque)):
  308.                 cf = entryque[ofile]
  309.                 fo_outname = curf+cf[3]+"/"
  310.                 mdir(fo_outname)
  311.                 with open(fo_outname+cf[4], "wb") as fout:
  312.                     rom.seek(root+cf[0])
  313.                     fout.write(rom.read(cf[2]))
  314.  
  315.             rom.seek(root + sorted(entryque)[-1][0])
  316.             rom.read(sorted(entryque)[-1][2])
  317.             rom.seek(roundUp(rom.tell()), 1)
  318.  
  319.         elif check == 0x00010002:
  320.             print("12QU at 0x{:X}".format(root))
  321.             ONETWOFOLDER = OUT+"{:03d}_ONTW/".format(fidx)
  322.             curf = ONETWOFOLDER
  323.             mdir(curf)
  324.  
  325.             amo = getB(4)
  326.             onetwoque = []
  327.             for i in range(0,amo):
  328.                 _foname, sfindex, _finame, fadr, fsize = struct.unpack("<4s4s16sII", rom.read(0x20))
  329.                 try:
  330.                     foname = _foname.decode("utf-8").rstrip('\x00')
  331.                 except UnicodeDecodeError:
  332.                     foname = "{:08X}".format(struct.unpack("<I", _foname)[0])#str(_foname)
  333.  
  334.                 try:
  335.                     finame = _finame.decode("utf-8").rstrip('\x00')
  336.                 except UnicodeDecodeError:
  337.                     finame = "{:08X}".format(struct.unpack("<I", _finame)[0])#str(_finame)
  338.  
  339.                 try:
  340.                     sfindex = sfindex.decode("utf-8").rstrip('\x00')
  341.                 except UnicodeDecodeError:
  342.                     sfindex = "{:08X}".format(struct.unpack("<I", sfindex)[0])#str(_finame)
  343.  
  344.                 if finame == " ":
  345.                     finame = "NONAME"
  346.                 estr = "{:8s} {:12s} {:08X}".format(foname,finame,findex)
  347.                 onetwoque.append([fadr, estr, fsize, foname, sfindex, finame])
  348.  
  349.             for ofile in range(0,len(onetwoque)):
  350.                 cf = onetwoque[ofile]
  351.                 fo_outname = curf+cf[3]+"/"
  352.                 mdir(fo_outname)
  353.                 fo_subname = fo_outname+cf[4]+"/"
  354.                 mdir(fo_subname)
  355.                 with open(fo_subname+cf[5], "wb") as fout:
  356.                     rom.seek(root+cf[0])
  357.                     fout.write(rom.read(cf[2]))
  358.  
  359.             rom.seek(root + sorted(onetwoque)[-1][0])
  360.             rom.read(sorted(onetwoque)[-1][2])
  361.             rom.seek(roundUp(rom.tell()), 1)
  362.  
  363.         elif check == 0xFFFF0001:
  364.             rom.seek(-4,1)
  365.             local_rta = rom.tell()
  366.             print("FF01 at 0x{:X}".format(root))
  367.             rest = 0x10
  368.             while True:
  369.                 rom.read(1)
  370.                 rom.seek(roundUp(rom.tell()), 1)
  371.                 rom.seek(-rest,1)
  372.                 zcheck = sum(struct.unpack("<{:d}B".format(rest), rom.read(rest)))
  373.                 if zcheck == 0:
  374.                     print("    That's probably all... End at 0x{:X}".format(rom.tell()))
  375.                     new_rta = rom.tell()
  376.                     local_size = new_rta-local_rta
  377.                     rom.seek(local_rta)
  378.                     FF01FOLDER = OUT+"{:03d}_FF01/".format(fidx)
  379.                     mdir(FF01FOLDER)
  380.                     with open(FF01FOLDER+"FF01.bin", "wb") as ff01:
  381.                         ff01.write(rom.read(local_size))
  382.                     rom.seek(new_rta)
  383.                     break
  384.                 else:
  385.                     print("    ...")
  386.                     continue
  387.  
  388.         elif root == EMUEND:
  389.             print("Emulated data at 0x{:X}".format(root))
  390.             EMUFOLDER = OUT+"{:03d}_EMUD/".format(fidx)
  391.             mdir(EMUFOLDER)
  392.             with open(EMUFOLDER+"EMUD.bin", "wb") as emud:
  393.                 emud.write(rom.read(EMUSIZ))
  394.             print("         done at 0x{:X}".format(rom.tell()))
  395.             rom.seek(roundUp(rom.tell()), 1)
  396.             print("               > 0x{:X}".format(rom.tell()))
  397.  
  398.  
  399.         elif root == RGBEND:
  400.             RGBFOLDER = OUT+"{:03d}_RGBD/".format(fidx)
  401.             mdir(RGBFOLDER)
  402.             for img in range(0, RGBAMO):
  403.                 print("RGB {:3d} at 0x{:X}".format(img, rom.tell()))
  404.                 canvas = Image.new("RGBA", (640,480))
  405.                 canvas.putdata(getRGB())
  406.                 canvas.save(RGBFOLDER+"{:03d}.png".format(img))
  407.             break
  408.  
  409.         else:
  410.             print("unknown check {:08X} at 0x{:08X}".format(check, root))
  411.  
  412.             print("1. Testing for ADPCM...")
  413.             adpcm = testADPCM()
  414.             if adpcm:
  415.                 pcmlist = getADPCMlist()
  416.                 rom.seek(roundUp(rom.tell()), 1)
  417.                 pcmroot = rom.tell()
  418.                 pcmcount = 0
  419.  
  420.                 SOUNDFOLDER = OUT+"{:03d}_APCM/".format(fidx)
  421.                 mdir(SOUNDFOLDER)
  422.                 #with open(SOUNDFOLDER+"manifest.txt", "w") as pcm_manifest:
  423.                 #    for snd in pcmlist:
  424.                 #        with open(SOUNDFOLDER+"{:04d}.adpcm".format(pcmcount), "wb") as sout:
  425.                 #            pcm_manifest.write("{:04d}.adpcm: {:d}Hz\n".format(pcmcount, RATELIST[snd["rate"]]))
  426.                 #            rom.seek(pcmroot + snd["adr"])
  427.                 #            sout.write(rom.read(snd["size"]))
  428.                 #        pcmcount += 1
  429.  
  430.                 with open(SOUNDFOLDER+"{:03d}.vca".format(fidx), "wb") as sout:
  431.                     rom.seek(root)
  432.                     sout.write(rom.read(pcmroot-root))
  433.  
  434.                 with open(SOUNDFOLDER+"{:03d}.vcb".format(fidx), "wb") as sout:
  435.                     l = max(pcmlist, key=itemgetter('adr'))
  436.                     rom.seek(pcmroot + l["adr"])
  437.                     rom.read(l["size"])
  438.                     pcmend = rom.tell()
  439.  
  440.                     rom.seek(pcmroot)
  441.                     sout.write(rom.read(pcmend-pcmroot))
  442.  
  443.                 l = max(pcmlist, key=itemgetter('adr'))
  444.                 rom.seek(pcmroot + l["adr"])
  445.                 rom.read(l["size"])
  446.                 print("ADPCMs done at 0x{:X}".format(rom.tell()))
  447.                 rom.seek(roundUp(rom.tell()), 1)
  448.                 print("  continued to 0x{:X}".format(rom.tell()))
  449.  
  450.             else:
  451.                 print("idk. halt 0x{:08X}".format(root))
  452.                 #rom.read(4)
  453.                 #rom.seek(roundUp(rom.tell()), 1)
  454.                 break
  455.  
  456.         fidx += 1
  457.  
  458. #                                                 X        Y       hw       hg   bytesz   allocc
  459. #0200 0000 0190 00A3 0001FD60 00020000  /       512        0      400      163   130400   131072
  460. #0300 00A3 007A 0014 00001310 00001800  /       768      163      122       20     4880     6144
  461.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement