Skip to content
View in the app

A better way to browse. Learn more.

ResHax

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.
Help us keep the site running.

My first quickBMS script

Featured Replies

  • Author
  • Localization

aluigi, posted Sun Jul 24, 2016 5:11 pm (15628)


The snippest of code I pasted loads GTA3.IMG if ARCHIVE_NUM is zero.
Have you read the ARCHIVE_NUM field from the index file?
  • Replies 108
  • Views 23
  • Created
  • Last Reply

Top Posters In This Topic

  • Author
  • Localization

AnonBaiter, posted Sun Jul 24, 2016 5:20 pm (15630)


Well, maybe I didn't actually "read" the field but both of these files look strikingly similar.

GTA3.IMG
Code:
00000000  56 45 52 32 58 3F 00 00 FE 00 00 00 02 00 00 00  VER2X?..?.......
00000010  6C 65 76 65 6C 6D 61 70 5F 73 74 72 65 61 6D 30  levelmap_stream0
00000020  2E 69 70 6C 00 00 B1 00 00 01 00 00 03 00 00 00  .ipl.. .........
00000030  6C 65 76 65 6C 6D 61 70 5F 73 74 72 65 61 6D 31  levelmap_stream1
00000040  2E 69 70 6C 00 00 B1 00 03 01 00 00 3B 00 00 00  .ipl.. .....;...
00000050  6C 65 76 65 6C 6D 61 70 5F 31 2E 63 6F 6C 00 00  levelmap_1.col..
00000060  AE 00 AF 00 B0 00 B1 00 3E 01 00 00 47 00 00 00  R.?.?. .>...G...
00000070  77 65 65 6D 61 70 2E 74 78 64 00 00 AC 00 AD 00  weemap.txd..?...
00000080  AE 00 AF 00 B0 00 B1 00 85 01 00 00 04 00 00 00  R.?.?. .:.......
00000090  62 72 69 64 67 65 5F 31 2E 64 66 66 00 00 AD 00  bridge_1.dff....
000000A0  AE 00 AF 00 B0 00 B1 00 89 01 00 00 02 00 00 00  R.?.?. .%.......
000000B0  64 5F 73 69 67 6E 2E 64 66 66 00 00 AC 00 AD 00  d_sign.dff..?...
000000C0  AE 00 AF 00 B0 00 B1 00 8B 01 00 00 01 00 00 00  R.?.?. .<.......
000000D0  64 5F 73 69 67 6E 30 31 2E 64 66 66 00 00 AD 00  d_sign01.dff....
000000E0  AE 00 AF 00 B0 00 B1 00 8C 01 00 00 02 00 00 00  R.?.?. .?.......
000000F0  68 65 6C 69 70 61 64 2E 64 66 66 00 AC 00 AD 00  helipad.dff.?...

GTA3_1.IMG
Code:
00000000  56 45 52 32 58 3F 00 00 FE 00 00 00 02 00 00 00  VER2X?..?.......
00000010  6C 65 76 65 6C 6D 61 70 5F 73 74 72 65 61 6D 30  levelmap_stream0
00000020  2E 69 70 6C 00 00 B1 00 00 01 00 00 03 00 00 00  .ipl.. .........
00000030  6C 65 76 65 6C 6D 61 70 5F 73 74 72 65 61 6D 31  levelmap_stream1
00000040  2E 69 70 6C 00 00 B1 00 03 01 00 00 3B 00 00 00  .ipl.. .....;...
00000050  6C 65 76 65 6C 6D 61 70 5F 31 2E 63 6F 6C 00 00  levelmap_1.col..
00000060  AE 00 AF 00 B0 00 B1 00 3E 01 00 00 47 00 00 00  R.?.?. .>...G...
00000070  77 65 65 6D 61 70 2E 74 78 64 00 00 AC 00 AD 00  weemap.txd..?...
00000080  AE 00 AF 00 B0 00 B1 00 85 01 00 00 04 00 00 00  R.?.?. .:.......
00000090  62 72 69 64 67 65 5F 31 2E 64 66 66 00 00 AD 00  bridge_1.dff....
000000A0  AE 00 AF 00 B0 00 B1 00 89 01 00 00 02 00 00 00  R.?.?. .%.......
000000B0  64 5F 73 69 67 6E 2E 64 66 66 00 00 AC 00 AD 00  d_sign.dff..?...
000000C0  AE 00 AF 00 B0 00 B1 00 8B 01 00 00 01 00 00 00  R.?.?. .<.......
000000D0  64 5F 73 69 67 6E 30 31 2E 64 66 66 00 00 AD 00  d_sign01.dff....
000000E0  AE 00 AF 00 B0 00 B1 00 8C 01 00 00 02 00 00 00  R.?.?. .?.......
000000F0  68 65 6C 69 70 61 64 2E 64 66 66 00 AC 00 AD 00  helipad.dff.?...

Which is why I assume they're duplicates.
  • Author
  • Localization

eatrawmeat391, posted Mon Jul 25, 2016 7:42 am (15646)


The GTA3_1.IMG is a duplicate of GTA3.IMG.If you have a PS2 version of GTA SA there is a file called 'FILELOAD.NM'.Open it in hex and search for 'GTA3_%d.IMG',replace it with just 'GTA3.IMG'.This will bypass the GTA3_1.IMG reading and you can safety delete GTA3_1.IMG.Just mod GTA3.IMG
  • Author
  • Localization

AnonBaiter, posted Tue Jul 26, 2016 5:34 am (15667)


...aaaand done. I'll consider that solution for when I actually feel like testing the game on an emulator or real hardware but for now I'll just release the script as is.
  • Author
  • Localization

AnonBaiter, posted Tue Jul 26, 2016 10:05 am (15679)


So far I'm working on a script focusing on the .bsa file.
Code:
goto 0
get FILES short
get DUMMY short
for i = 0 < FILES
   goto -18
   savepos OFFSET
   getdstring NAME 0xE
   get SIZE long
   math OFFSET - SIZE
   goto OFFSET
next i

The index itself is at the very end of the file, as you can see here:
Code:
00FFB5B0                    30 31 41 58 45 2E 43 46 41 00        01AXE.CFA.
00FFB5C0  00 00 00 00 E1 02 00 00 30 31 42 41 52 41 54 54  ....a...01BARATT
00FFB5D0  2E 43 46 41 00 00 D7 14 00 00 30 31 42 41 52 57  .CFA..?...01BARW
00FFB5E0  4C 4B 2E 43 46 41 00 00 E0 2A 00 00 30 31 42 41  LK.CFA..a*..01BA
00FFB5F0  58 45 2E 43 46 41 00 00 00 00 AD 04 00 00 30 31  XE.CFA........01
00FFB600  42 4D 41 43 45 2E 43 46 41 00 00 00              BMACE.CFA...

The problem though is that when I test the script on debug mode, it doesn't detect the next file:
Code:
- current_folder: E:\quickbms
- bms_folder:     E:\reverse.engineering.stuff
- exe_folder:     E:\quickbms
- file_folder:    E:\IBM - PC compatible (Non-Europe-CD)\ARENA_CD
- output_folder:  E:\quickbms
- temp_folder:    C:\Users\TCA\AppData\Local\Temp\
- open input file E:\IBM - PC compatible (Non-Europe-CD)\ARENA_CD\GLOBAL.BSA
- open script E:\reverse.engineering.stuff\bethesda_bsa.bms
- set output folder .

  offset   filesize   filename
--------------------------------------
. 01006146 getdstr NAME       "ZOMBIE6.CFA" 14
    5a 4f 4d 42 49 45 36 2e 43 46 41 00 00 00         ZOMBIE6.CFA...
. 01006154 get     SIZE       0x00000d6c 4
.
. 01006146 getdstr NAME       "ZOMBIE6.CFA" 14
    5a 4f 4d 42 49 45 36 2e 43 46 41 00 00 00         ZOMBIE6.CFA...
. 01006154 get     SIZE       0x00000d6c 4
.
. 01006146 getdstr NAME       "ZOMBIE6.CFA" 14
    5a 4f 4d 42 49 45 36 2e 43 46 41 00 00 00         ZOMBIE6.CFA...
. 01006154 get     SIZE       0x00000d6c 4
.
. 01006146 getdstr NAME       "ZOMBIE6.CFA" 14
    5a 4f 4d 42 49 45 36 2e 43 46 41 00 00 00         ZOMBIE6.CFA...
. 01006154 get     SIZE       0x00000d6c 4
.
. 01006146 getdstr NAME       "ZOMBIE6.CFA" 14
    5a 4f 4d 42 49 45 36 2e 43 46 41 00 00 00         ZOMBIE6.CFA...
. 01006154 get     SIZE       0x00000d6c 4
.
. 01006146 getdstr NAME       "ZOMBIE6.CFA" 14
    5a 4f 4d 42 49 45 36 2e 43 46 41 00 00 00         ZOMBIE6.CFA...
. 01006154 get     SIZE       0x00000d6c 4
.
. 01006146 getdstr NAME       "ZOMBIE6.CFA" 14
    5a 4f 4d 42 49 45 36 2e 43 46 41 00 00 00         ZOMBIE6.CFA...
. 01006154 get     SIZE       0x00000d6c 4
.
. 01006146 getdstr NAME       "ZOMBIE6.CFA" 14
    5a 4f 4d 42 49 45 36 2e 43 46 41 00 00 00         ZOMBIE6.CFA...
. 01006154 get     SIZE       0x00000d6c 4
.
. 01006146 getdstr NAME       "ZOMBIE6.CFA" 14
    5a 4f 4d 42 49 45 36 2e 43 46 41 00 00 00         ZOMBIE6.CFA...
. 01006154 get     SIZE       0x00000d6c 4
.
. 01006146 getdstr NAME       "ZOMBIE6.CFA" 14
    5a 4f 4d 42 49 45 36 2e 43 46 41 00 00 00         ZOMBIE6.CFA...
. 01006154 get     SIZE       0x00000d6c 4
.
. 01006146 getdstr NAME       "ZOMBIE6.CFA" 14
    5a 4f 4d 42 49 45 36 2e 43 46 41 00 00 00         ZOMBIE6.CFA...
. 01006154 get     SIZE       0x00000d6c 4
.
. 01006146 getdstr NAME       "ZOMBIE6.CFA" 14
    5a 4f 4d 42 49 45 36 2e 43 46 41 00 00 00         ZOMBIE6.CFA...
. 01006154 get     SIZE       0x00000d6c 4
.
. 01006146 getdstr NAME       "ZOMBIE6.CFA" 14
    5a 4f 4d 42 49 45 36 2e 43 46 41 00 00 00         ZOMBIE6.CFA...
. 01006154 get     SIZE       0x00000d6c 4
.
. 01006146 getdstr NAME       "ZOMBIE6.CFA" 14
    5a 4f 4d 42 49 45 36 2e 43 46 41 00 00 00         ZOMBIE6.CFA...
. 01006154 get     SIZE       0x00000d6c 4
.
. 01006146 getdstr NAME       "ZOMBIE6.CFA" 14
    5a 4f 4d 42 49 45 36 2e 43 46 41 00 00 00         ZOMBIE6.CFA...
. 01006154 get     SIZE       0x00000d6c 4
.
. 01006146 getdstr NAME       "ZOMBIE6.CFA" 14
    5a 4f 4d 42 49 45 36 2e 43 46 41 00 00 00         ZOMBIE6.CFA...
. 01006154 get     SIZE       0x00000d6c 4
.
. 01006146 getdstr NAME       "ZOMBIE6.CFA" 14
    5a 4f 4d 42 49 45 36 2e 43 46 41 00 00 00         ZOMBIE6.CFA...
. 01006154 get     SIZE       0x00000d6c 4
.
. 01006146 getdstr NAME       "ZOMBIE6.CFA" 14
    5a 4f 4d 42 49 45 36 2e 43 46 41 00 00 00         ZOMBIE6.CFA...
. 01006154 get     SIZE       0x00000d6c 4
.
. 01006146 getdstr NAME       "ZOMBIE6.CFA" 14
    5a 4f 4d 42 49 45 36 2e 43 46 41 00 00 00         ZOMBIE6.CFA...
. 01006154 get     SIZE       0x00000d6c 4
.
. 01006146 getdstr NAME       "ZOMBIE6.CFA" 14
    5a 4f 4d 42 49 45 36 2e 43 46 41 00 00 00         ZOMBIE6.CFA...
. 01006154 get     SIZE       0x00000d6c 4
.
. 01006146 getdstr NAME       "ZOMBIE6.CFA" 14
    5a 4f 4d 42 49 45 36 2e 43 46 41 00 00 00         ZOMBIE6.CFA...
. 01006154 get     SIZE       0x00000d6c 4
.
. 01006146 getdstr NAME       "ZOMBIE6.CFA" 14
    5a 4f 4d 42 49 45 36 2e 43 46 41 00 00 00         ZOMBIE6.CFA...
. 01006154 get     SIZE       0x00000d6c 4
.
. 01006146 getdstr NAME       "ZOMBIE6.CFA" 14
    5a 4f 4d 42 49 45 36 2e 43 46 41 00 00 00         ZOMBIE6.CFA...
. 01006154 get     SIZE       0x00000d6c 4
.
. 01006146 getdstr NAME       "ZOMBIE6.CFA" 14
    5a 4f 4d 42 49 45 36 2e 43 46 41 00 00 00         ZOMBIE6.CFA...
. 01006154 get     SIZE       0x00000d6c 4
.
. 01006146 getdstr NAME       "ZOMBIE6.CFA" 14
    5a 4f 4d 42 49 45 36 2e 43 46 41 00 00 00         ZOMBIE6.CFA...
. 01006154 get     SIZE       0x00000d6c 4
.
. 01006146 getdstr NAME       "ZOMBIE6.CFA" 14
    5a 4f 4d 42 49 45 36 2e 43 46 41 00 00 00         ZOMBIE6.CFA...
. 01006154 get     SIZE       0x00000d6c 4
.
. 01006146 getdstr NAME       "ZOMBIE6.CFA" 14
    5a 4f 4d 42 49 45 36 2e 43 46 41 00 00 00         ZOMBIE6.CFA...
. 01006154 get     SIZE       0x00000d6c 4
.
. 01006146 getdstr NAME       "ZOMBIE6.CFA" 14
    5a 4f 4d 42 49 45 36 2e 43 46 41 00 00 00         ZOMBIE6.CFA...
. 01006154 get     SIZE       0x00000d6c 4
.
. 01006146 getdstr NAME       "ZOMBIE6.CFA" 14
    5a 4f 4d 42 49 45 36 2e 43 46 41 00 00 00         ZOMBIE6.CFA...
. 01006154 get     SIZE       0x00000d6c 4
.
. 01006146 getdstr NAME       "ZOMBIE6.CFA" 14
    5a 4f 4d 42 49 45 36 2e 43 46 41 00 00 00         ZOMBIE6.CFA...
. 01006154 get     SIZE       0x00000d6c 4
.
. 01006146 getdstr NAME       "ZOMBIE6.CFA" 14
    5a 4f 4d 42 49 45 36 2e 43 46 41 00 00 00         ZOMBIE6.CFA...
. 01006154 get     SIZE       0x00000d6c 4
.
. 01006146 getdstr NAME       "ZOMBIE6.CFA" 14
    5a 4f 4d 42 49 45 36 2e 43 46 41 00 00 00         ZOMBIE6.CFA...
. 01006154 get     SIZE       0x00000d6c 4
.
. 01006146 getdstr NAME       "ZOMBIE6.CFA" 14
    5a 4f 4d 42 49 45 36 2e 43 46 41 00 00 00         ZOMBIE6.CFA...
. 01006154 get     SIZE       0x00000d6c 4
.
. 01006146 getdstr NAME       "ZOMBIE6.CFA" 14
    5a 4f 4d 42 49 45 36 2e 43 46 41 00 00 00         ZOMBIE6.CFA...
. 01006154 get     SIZE       0x00000d6c 4
.
. 01006146 getdstr NAME       "ZOMBIE6.CFA" 14
    5a 4f 4d 42 49 45 36 2e 43 46 41 00 00 00         ZOMBIE6.CFA...
. 01006154 get     SIZE       0x00000d6c 4
.
. 01006146 getdstr NAME       "ZOMBIE6.CFA" 14
    5a 4f 4d 42 49 45 36 2e 43 46 41 00 00 00         ZOMBIE6.CFA...
. 01006154 get     SIZE       0x00000d6c 4

Am I doing something wrong?
  • Author
  • Localization

aluigi, posted Tue Jul 26, 2016 11:11 am (15689)


You return ever to -0x18, that's an absolute offset and not a relative one.
Are you 100% sure that this format must be read from the end in that way?
  • Author
  • Localization

AnonBaiter, posted Tue Jul 26, 2016 11:12 am (15691)


Well, that's what I'm trying to do.
  • Author
  • Localization

aluigi, posted Tue Jul 26, 2016 11:16 am (15692)


Probably you have to find where the toc starts by doing: xmath INFO_OFF "ARCHIVE_SIZE - (FILES * (0xe 0x4))"
And then using the OFFSET 4 as starting offset for the files.
  • Author
  • Localization

AnonBaiter, posted Tue Jul 26, 2016 11:19 am (15693)


"OFFSET 4"... like this:
Code:
get FILES short
get DUMMY short
savepos INFO_OFF
xmath INFO_OFF "ARCHIVE_SIZE - (FILES * (0xe 0x4))"
for i = 0 < FILES
   goto -18
   savepos OFFSET
   log MEMORY_FILE OFFSET 4
...
  • Author
  • Localization

aluigi, posted Tue Jul 26, 2016 11:23 am (15695)


Because 4 is the sum of the 2 shorts you have read at the beginning.
  • Author
  • Localization

AnonBaiter, posted Tue Jul 26, 2016 11:31 am (15697)


I'm still clueless, do I have to use both the two shorts as the starting offset for the files? I'm still thinking on removing the "goto -18" line but...
  • Author
  • Localization

aluigi, posted Tue Jul 26, 2016 11:44 am (15698)


Listen, I don't have the file. I have only a bounch of minutes to read your post and giving a quick feedback.
For sure the "goto -0x18" in the loop is wrong because it returns ever at the same point.
  • Author
  • Localization

AnonBaiter, posted Tue Jul 26, 2016 11:48 am (15700)


Well, that about clears up the confusion.
Besides, to not waste anyone's time, I'll be providing a sample instead. Be warned though, because the .BSA file has an early version compared to the one I'm working on(Battlespire).

EDIT: Here.
  • Author
  • Localization

aluigi, posted Tue Jul 26, 2016 12:37 pm (15709)


Code:
get FILES short
savepos OFFSET
get INFO_OFF asize
xmath INFO_OFF "INFO_OFF - (FILES * (14 4))"
goto INFO_OFF
for i = 0 < FILES
    getdstring NAME 14
    get SIZE long
    log NAME OFFSET SIZE
    math OFFSET SIZE
next i
  • Author
  • Localization

AnonBaiter, posted Tue Jul 26, 2016 12:44 pm (15712)


Umm, thanks mate.

EDIT: I just found out that this script can also be used on .BS6 files. As in, ones whose structure are strikingly similar to the BSA archive file. But it's not saying much, really.
  • Author
  • Localization

AnonBaiter, posted Sat Aug 13, 2016 5:47 pm (16432)


So I'm trying to figure out a .DAT file. I want to find the offset/size based on these blocks:
Code:
00000000  10 00 00 00 10 00 00 00 00 00 00 00 02 00 00 00  ................
00000010  10 00 00 00 10 00 00 00 00 00 00 00 01 00 00 00  ................
00000020  10 00 00 00 10 00 00 00 00 00 00 00 04 00 00 00  ................
00000030  02 00 00 00 A0 05 00 00 00 00 00 00 00 00 00 00  ....?...........
The problem though is I'm not sure if these are alignment for the files or something else, but then again I'm planning on writing a script that can find the offsets of the files based on these blocks.

Also, on the other .DAT file, there are folders without any reference to the files themselves:
Code:
00000000  1D B2 C0 3B 01 00 01 00 15 00 10 40 01 00 00 00  .?A;.......@....
00000010  6E 6F 64 65 00 00 00 00 01 00 00 00 70 68 6F 74  node........phot
00000020  6F 00 00 00 5E 01 00 00 63 61 70 74 75 72 65 00  o...^...capture.
00000030  5B 02 00 00 6D 6F 62 69 6C 65 00 00 81 02 00 00  [...mobile......
00000040  66 30 30 61 00 00 00 00 97 02 00 00 66 30 31 61  f00a....-...f01a
00000050  00 00 00 00 C0 04 00 00 66 30 31 62 00 00 00 00  ....A...f01b....
00000060  D6 08 00 00 66 30 31 63 00 00 00 00 9E 0B 00 00  O...f01c....z...
00000070  66 30 31 64 00 00 00 00 4B 0F 00 00 66 30 31 65  f01d....K...f01e
00000080  00 00 00 00 B0 12 00 00 66 30 31 66 00 00 00 00  ....?...f01f....
00000090  0D 17 00 00 66 30 32 61 00 00 00 00 C3 1A 00 00  ....f02a....A...
000000A0  66 30 33 61 00 00 00 00 3F 1D 00 00 66 30 33 62  f03a....?...f03b
000000B0  00 00 00 00 61 20 00 00 66 30 34 61 00 00 00 00  ....a ..f04a....
000000C0  12 22 00 00 66 30 34 62 00 00 00 00 1A 26 00 00  ."..f04b.....&..
000000D0  66 30 34 63 00 00 00 00 71 2A 00 00 66 30 34 64  f04c....q*..f04d
000000E0  00 00 00 00 A9 2E 00 00 66 30 34 65 00 00 00 00  ....c...f04e....
000000F0  84 32 00 00 66 30 35 61 00 00 00 00 BC 36 00 00  "2..f05a....?6..
00000100  66 30 36 61 00 00 00 00 AB 38 00 00 00 00 00 00  f06a....<8......
00000110  00 00 00 00 00 00 00 00 DD 0D 67 8A 65 63 6D 3A  ........Y.gSecm:
However it does reference the offset of the filelist of these folders, and the filelist of a folder is as follows:
Code:
00000800  1B 00 00 00 02 00 00 7F 40 D8 0A 00 D8 CA 6A 13  [email protected].
00000810  00 00 00 00 D5 23 9A 13 80 41 00 00 05 B4 99 13  ....O#s.?A...?T.
00000820  00 A8 02 00 0B 25 74 13 00 55 03 00 DC 57 77 13  .?...%t..U..UWw.
00000830  00 C1 07 00 47 BE 01 13 00 23 08 00 D8 CA 6A 0E  .A..G?...#..OEj.
00000840  80 64 08 00 92 A6 A2 0E D0 76 08 00 24 BB 30 0E  ?d..'??.?v..$>0.
00000850  B0 7A 08 00 B3 B9 E4 0E C0 84 08 00 47 69 BB 0E  ?z..??a.A"..Gi>.
00000860  C0 B8 08 00 73 41 C1 0E C0 EB 08 00 D5 23 9A 0E  A?..sAA.Ae..O#s.
00000870  C0 1E 09 00 05 B4 99 0E 20 7A 09 00 17 CC CC 0E  A....?T. z...II.
00000880  50 11 0A 00 47 BE 01 0E E0 86 0A 00 A4 AA 01 0E  P...G?..a?..??..
00000890  F0 AE 0A 00 AF 47 A4 0E 10 BC 0A 00 13 C9 34 0E  ?R..?G?..?...E4.
000008A0  B0 CB 0A 00 12 C9 34 0E 10 CD 0A 00 11 C9 34 0E  ?E...E4..I...E4.
000008B0  70 CE 0A 00 D3 2D 33 0E D0 CF 0A 00 D2 2D 33 0E  pI..O-3.?I..O-3.
000008C0  A0 D2 0A 00 D1 2D 33 0E 70 D5 0A 00 00 00 00 7F  ?O..N-3.pO......
000008D0  40 D8 0A 00 00 00 00 00 00 00 00 00 0E 46 0C 1B  @O...........F..
000008E0  16 B5 D4 51 2F 0D DD 8D 0C 4F 1B 5C 25 B6 38 85  .?OQ/.Y..O.\%8:
Anyway, here's the script for that .DAT file I'm writing on(sample comes later):
Code:
get XOR long
get DUMMY1 long
get FOLDERS short
get DUMMY2 short
get DUMMY3 long

for FOLDER = 0 < FOLDERS
   getdstring NAME 0x8
   get OFFSET long
   math OFFSET * 0x800
   
   savepos TMP
   goto OFFSET
   
   string NAME /
   
   get FILES long
   get DUMMY long
   math FILES - 3
   for i = 0 < FILES
      get OFFSET long
      get SIZE long
      math SIZE / 0x1000
      putarray 0 i OFFSET
      putarray 1 i SIZE
      log NAME OFFSET SIZE
   next i
   
   goto TMP
next FOLDER
The game in which these .DAT files came from is Metal Gear Solid 2(original PS2 version).
  • Author
  • Localization

AnonBaiter, posted Sun Aug 14, 2016 3:43 pm (16461)


And here is an attached report of the script running in debug mode with an un-XORed file(FACE.DAT).
The second file only starts with the "0x00000000" offset, and when the script detects the files inside each folder it doesn't continue with the position that's been proposed(goto OFFSET). Rather, it goes right through the entire archive. Besides, I've been trying to come up with an solution for this(math OFFSET * 0x10) but what can I do?
  • Author
  • Localization

AnonBaiter, posted Sun Aug 14, 2016 10:52 pm (16462)


And now for something completely different...
Code:
get FILES long

math LAST_DISC_NUM = -1
math LAST_PART_NUM = -1
for i = 0 < FILES
   getdstring NAME 0xC
   get ZERO long
   get OFFSET long
   get SIZE long
   math OFFSET * 0x800
   math SIZE * 0x800
#   putarray 0 i NAME # for testing purposes
#   putarray 1 i OFFSET
#   putarray 2 i SIZE
   
   get TMP filename
   if PART_NUM != LAST_PART_NUM
      math LAST_PART_NUM == PART_NUM
      string TMP p "disc%d_%d.dat" DISC_NUM PART_NUM
   endif
   putarray 0 i TMP
   open FDSE TMP 1
   
   log NAME OFFSET SIZE
next i
So far it loaded only the first file(disc1_0.dat, disc2_0.dat), but it refuse to load the files that have the following numbers in their filenames(from disc1_1.dat to disc1_8.dat). Is there any solutions for this or has my question already get answered and I didn't pay attention to it?
  • Author
  • Localization

aluigi, posted Sun Aug 14, 2016 11:55 pm (16466)


You should remove that "if PART_NUM == 0" condition.
  • Author
  • Localization

AnonBaiter, posted Mon Aug 15, 2016 12:01 am (16467)


Well, I did what you said and...
Code:
- current_folder: E:\quickbms
- bms_folder:     E:\MGS2_SUBSTANCE
- exe_folder:     E:\quickbms
- file_folder:    E:\MGS2_SUBSTANCE\XBOX
- output_folder:  E:\quickbms
- temp_folder:    C:\Users\TCA\AppData\Local\Temp\
- open input file E:\MGS2_SUBSTANCE\XBOX\disc1_0.dat
- open script E:\MGS2_SUBSTANCE\mgs2_xbox.bms
- set output folder .

  offset   filesize   filename
--------------------------------------
. 00000000 get     FILES      0x00000004 4
. 00000004 getdstr NAME       "vox.dat" 12
    76 6f 78 2e 64 61 74 00 00 00 00 00               vox.dat.....
. 00000010 get     ZERO       0x00000000 4
. 00000014 get     OFFSET     0x00022ea0 4
. 00000018 get     SIZE       0x000a2960 4
. 0000001c get     TMP        "disc1_0.dat" -1000
. 00000000 putarr  TMP        "disc0_0.dat" 0:0
- enter in folder E:\MGS2_SUBSTANCE\XBOX
- open input file E:\MGS2_SUBSTANCE\XBOX\disc0_0.dat

- error in src\file.c line 243: fdnum_open()
Error: No such file or directory

Last script line before the error or that produced the error:
  22  open FDSE TMP 1
As you can see, I'm using two variables: one for the disc number("disc%d"), and one for the part number(_%d).
So I want the script to start detecting the "disk" archive files from the first number(1).

Maybe I'm just that incompetent...
  • Author
  • Localization

aluigi, posted Mon Aug 15, 2016 2:59 am (16472)


Ah now I get it, you check a PART_NUM variable that doesn't exist.
Same for DISC_NUM.
If you don't have these variables how you expect the script to open something?
  • Author
  • Localization

AnonBaiter, posted Mon Aug 15, 2016 3:16 am (16473)


Well, you have a point there. Silly me.
I'll think of another way to have these variables, but I'm afraid I'll just be running out of ideas(and sometimes overall competence) at this point. I'm open to all suggestions at the moment.
  • Author
  • Localization

aluigi, posted Mon Aug 15, 2016 4:06 am (16477)


Well, a suggestion... you have a ZERO field there, does it remain ZERO for all the entries or does it change?
  • Author
  • Localization

AnonBaiter, posted Mon Aug 15, 2016 4:11 am (16478)


The ZERO field was only added to make sure the "getdstring NAME 0xC" doesn't get in the way of detecting the wrong filenames(such as c.dat if set to "set NAME string"), so it remains unchanged for all entries. See here:
Code:
- current_folder: E:\quickbms
- bms_folder:     E:\MGS2_SUBSTANCE
- exe_folder:     E:\quickbms
- file_folder:    E:\MGS2_SUBSTANCE\XBOX
- output_folder:  E:\quickbms
- temp_folder:    C:\Users\TCA\AppData\Local\Temp\
- open input file E:\MGS2_SUBSTANCE\XBOX\disc1_0.dat
- open script E:\MGS2_SUBSTANCE\mgs2_xbox.bms
- set output folder .

  offset           filesize   filename
--------------------------------------
. 0000000000000000 get     FILES      0x0000000000000004 4
. 00000000 putarr  LAST_DISC_NUM 0xffffffffffffffff 0:0
. 00000000 putarr  LAST_PART_NUM 0xffffffffffffffff 1:0
. 0000000000000004 getdstr NAME       "vox.dat" 12
    76 6f 78 2e 64 61 74 00 00 00 00 00               vox.dat.....
. 0000000000000010 get     ZERO       0x0000000000000000 4
. 0000000000000014 get     OFFSET     0x0000000000022ea0 4
. 0000000000000018 get     SIZE       0x00000000000a2960 4
  0000000011750000 1363869696 vox.dat
.
. 0000000000000001
. 000000000000001c getdstr NAME       "codec.dat" 12
    63 6f 64 65 63 2e 64 61 74 00 00 00               codec.dat...
. 0000000000000028 get     ZERO       0x0000000000000000 4
. 000000000000002c get     OFFSET     0x00000000000c5800 4
. 0000000000000030 get     SIZE       0x0000000000006b78 4
  0000000062c00000 56344576   codec.dat
.
. 0000000000000002
. 0000000000000034 getdstr NAME       "face.dat" 12
    66 61 63 65 2e 64 61 74 00 00 00 00               face.dat....
. 0000000000000040 get     ZERO       0x0000000000000000 4
. 0000000000000044 get     OFFSET     0x00000000000cc378 4
. 0000000000000048 get     SIZE       0x0000000000003224 4
  00000000661bc000 26288128   face.dat
.
. 0000000000000003
. 000000000000004c getdstr NAME       "stage.dat" 12
    73 74 61 67 65 2e 64 61 74 00 00 00               stage.dat...
. 0000000000000058 get     ZERO       0x0000000000000000 4
. 000000000000005c get     OFFSET     0x00000000000cf59c 4
. 0000000000000060 get     SIZE       0x00000000000cab3d 4
  0000000067ace000 1700390912 stage.dat
.
. 0000000000000004

- 4 files found in 0 seconds
  coverage file 0     0%   100        187420672

---

- current_folder: E:\quickbms
- bms_folder:     E:\MGS2_SUBSTANCE
- exe_folder:     E:\quickbms
- file_folder:    E:\MGS2_SUBSTANCE\XBOX
- output_folder:  E:\quickbms
- temp_folder:    C:\Users\TCA\AppData\Local\Temp\
- open input file E:\MGS2_SUBSTANCE\XBOX\disc2_0.dat
- open script E:\MGS2_SUBSTANCE\mgs2_xbox.bms
- set output folder .

  offset           filesize   filename
--------------------------------------
. 0000000000000000 get     FILES      0x0000000000000003 4
. 00000000 putarr  LAST_DISC_NUM 0xffffffffffffffff 0:0
. 00000000 putarr  LAST_PART_NUM 0xffffffffffffffff 1:0
. 0000000000000004 getdstr NAME       "demo.dat" 12
    64 65 6d 6f 2e 64 61 74 00 00 00 00               demo.dat....
. 0000000000000010 get     ZERO       0x0000000000000000 4
. 0000000000000014 get     OFFSET     0x00000000000641e8 4
. 0000000000000018 get     SIZE       0x00000000000bc982 4
  00000000320f4000 1582043136 demo.dat
.
. 0000000000000001
. 000000000000001c getdstr NAME       "movie.dat" 12
    6d 6f 76 69 65 2e 64 61 74 00 00 00               movie.dat...
. 0000000000000028 get     ZERO       0x0000000000000000 4
. 000000000000002c get     OFFSET     0x0000000000120b6a 4
. 0000000000000030 get     SIZE       0x0000000000078c4e 4
  00000000905b5000 1013084160 movie.dat
.
. 0000000000000002
. 0000000000000034 getdstr NAME       "movievr.dat" 12
    6d 6f 76 69 65 76 72 2e 64 61 74 00               movievr.dat.
. 0000000000000040 get     ZERO       0x0000000000000000 4
. 0000000000000044 get     OFFSET     0x00000000001997b8 4
. 0000000000000048 get     SIZE       0x00000000000015e8 4
  00000000ccbdc000 11485184   movievr.dat
.
. 0000000000000003

- 3 files found in 0 seconds
  coverage file 0     0%   76         624287744
  • Author
  • Localization

AnonBaiter, posted Tue Sep 20, 2016 11:27 pm (17557)


All right, I decided to take another look at extracting MGS2 data by myself...
Anyway, what do you think about this script? Do you think it needs some work or something? Because personally I'm thinking about detecting the offset location of these files just by using these "findloc" functions...
Code:
# for use with PS2 version only(not tested with Substance yet)
# only the Japanese version was used

get FULLSIZE asize
#findloc START_OFFSET binary "\x10\x00\x00\x00\x10\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00" # for DEMO.DAT(original PS2 release)
#findloc START_OFFSET binary "\x10\x00\x00\x00\x10\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00" # for VOX.DAT(original PS2 release/The Document of Metal Gear Solid 2)
#findloc START_OFFSET binary "\x10\x00\x00\x00\x10\x00\x00\x00\x00\x00\x00\x00\x0e\x00\x00\x00" # for MOVIE.DAT/MOVIE2.DAT(The Document of Metal Gear Solid 2)

for
   findloc START_OFFSET binary "\x10\x00\x00\x00\x10\x00\x00\x00\x00\x00\x00\x00\x0f\x00\x00\x00" # for MOVIE.DAT(original PS2 release)
   goto START_OFFSET
   if START_OFFSET >= FULLSIZE
      cleanexit
   endif
   savepos OFFSET
   findloc ALIGNMENT binary "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x10\x00\x00\x00\x10\x00\x00\x00\x00\x00\x00\x00\x0f\x00\x00\x00"
   findloc END_OFFSET string START_OFFSET 0 ""
   if END_OFFSET == ""
      math END_OFFSET = FULLSIZE
   endif
   math END_OFFSET = ALIGNMENT
   /*
   xmath SIZE "START_OFFSET == END_OFFSET"
   goto END_OFFSET
   padding 16
   do
      getdstring TMP 16
   while TMP == START_OFFSET
   */
   savepos TMP
   putarray 0 i START_OFFSET
   putarray 1 i END_OFFSET
   string NAME p "d." i
   putarray 2 i NAME
   getarray SIZE 0 i
   if SIZE != 0
      log NAME OFFSET SIZE
   endif
next
Guest
This topic is now closed to further replies.

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.