REIMPORT MEMORY_FILE WORK-AROUND ???

Extraction and unpacking of game archives and compression, encryption, obfuscation, decoding of unknown files
cornel
Posts: 30
Joined: Sun Feb 25, 2018 4:27 pm

REIMPORT MEMORY_FILE WORK-AROUND ???

Post by cornel »

"Do you want to use the experimental reimporting of chunked MEMORY_FILE?"

I get this option when trying to reimport modified wav files (with the same size or smaller) into a (Star Wars TFU) pcd file...

Why doesn't QuickBMS simply reimport?
aluigi
Site Admin
Posts: 12984
Joined: Wed Jul 30, 2014 9:32 pm

Re: REIMPORT MEMORY_FILE WORK-AROUND ???

Post by aluigi »

Because reimporting is not guaranteed if memory_files are used.
The code is correct but users reported problems when reimporting files with scripts that use memory_files so I decided to warn the user about the experimental nature of the feature.
cornel
Posts: 30
Joined: Sun Feb 25, 2018 4:27 pm

Re: REIMPORT MEMORY_FILE WORK-AROUND ???

Post by cornel »

What are memory_files? I am reimporting audio files.
aluigi
Site Admin
Posts: 12984
Joined: Wed Jul 30, 2014 9:32 pm

Re: REIMPORT MEMORY_FILE WORK-AROUND ???

Post by aluigi »

MEMORY_FILEs are buffers, some fake files that exist only in memory and are used as temporary places where storing information and files for editing them or as "headers" for giving a format to raw files.
In the past I used them a lot for building files that were stored in chunked mode (basically a file divided in small pieces that must be reassembled in memory and then dumped to disk) inside the archive but now I try to avoid this technique when I can.
cornel
Posts: 30
Joined: Sun Feb 25, 2018 4:27 pm

Re: REIMPORT MEMORY_FILE WORK-AROUND ???

Post by cornel »

I see. Would it be possible to extract the chunks as they are (and then modify them as they are and reimport them as they are), instead of interpreting and reconstructing the final memory file?
aluigi
Site Admin
Posts: 12984
Joined: Wed Jul 30, 2014 9:32 pm

Re: REIMPORT MEMORY_FILE WORK-AROUND ???

Post by aluigi »

It's possible to update the script, maybe.
Remember that chunked files in reimport mode are ever a doubt even if dumped directly to disk for various technical reasons.
What's the exact script you are using?
cornel
Posts: 30
Joined: Sun Feb 25, 2018 4:27 pm

Re: REIMPORT MEMORY_FILE WORK-AROUND ???

Post by cornel »

aluigi
Site Admin
Posts: 12984
Joined: Wed Jul 30, 2014 9:32 pm

Re: REIMPORT MEMORY_FILE WORK-AROUND ???

Post by aluigi »

please use ever the official links when possible (I replaced the code with the link for you).

Let's try the following modified script:

Code: Select all

open FDDE pcd 0
open FDDE pcp 1

get UNK long 0
get UNK long 0
get FILES long 0
get XML long 0
xmath NAMEOFF "(0x1c * FILES) + 0x10 + XML"
for i = 1 <= FILES
   get CRC long 0
   get OFFSET long 0
   get OFFSET2 long 0
   get SIZE long 0
   get FFFF long 0
   get UNK long 0
   get ZERO long 0
   savepos MYOFF 0
   goto NAMEOFF 0
   get NAMEL long 0
   getDstring NAME NAMEL 0
   string NAME += ".wav"
   savepos NAMEOFF 0
   xmath SIZE "SIZE - (OFFSET2 - OFFSET)"
   goto OFFSET 1
   get CODEC short 1
   if CODEC == 2
      callfunction msadpcm 1
   elif CODEC == 1
      callfunction pcm 1
   else
      print "error: unknown codec"
   endif
   goto MYOFF 0
next i

startfunction msadpcm
   putVarChr MEMORY_FILE 78 0
   log MEMORY_FILE 0 0
   set MEMORY_FILE binary "\x52\x49\x46\x46\x00\x00\x00\x00\x57\x41\x56\x45\x66\x6d\x74\x20\x32\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x64\x61\x74\x61\x00\x00\x00\x00"
   get RIFFSIZE asize MEMORY_FILE
   math RIFFSIZE + SIZE
   math RIFFSIZE -= 8
   get CHANNELS short 1
   get FREQUENCY long 1
   get BPS long 1
   get ALIGN short 1
   get UNKNOWN1 long 1
   get UNKNOWN2 long 1
   get UNKNOWN3 long 1
   get UNKNOWN4 long 1
   get UNKNOWN5 long 1
   get UNKNOWN6 long 1
   get UNKNOWN7 long 1
   get UNKNOWN8 long 1
   get UNKNOWN9 long 1
   putVarChr MEMORY_FILE 4 RIFFSIZE long
   putVarChr MEMORY_FILE 22 CHANNELS short
   putVarChr MEMORY_FILE 24 FREQUENCY long
   putVarChr MEMORY_FILE 28 BPS long
   putVarChr MEMORY_FILE 32 ALIGN short
   putVarChr MEMORY_FILE 34 UNKNOWN1 long
   putVarChr MEMORY_FILE 38 UNKNOWN2 long
   putVarChr MEMORY_FILE 42 UNKNOWN3 long
   putVarChr MEMORY_FILE 46 UNKNOWN4 long
   putVarChr MEMORY_FILE 50 UNKNOWN5 long
   putVarChr MEMORY_FILE 54 UNKNOWN6 long
   putVarChr MEMORY_FILE 58 UNKNOWN7 long
   putVarChr MEMORY_FILE 62 UNKNOWN8 long
   putVarChr MEMORY_FILE 66 UNKNOWN9 long
   putVarChr MEMORY_FILE 74 SIZE long
   get FULLSIZE asize MEMORY_FILE
   log NAME 0 FULLSIZE MEMORY_FILE
      append
      log NAME OFFSET2 SIZE 1
   append
endfunction

startfunction pcm
   putVarChr MEMORY_FILE 44 0
   log MEMORY_FILE 0 0
   set MEMORY_FILE binary "\x52\x49\x46\x46\x00\x00\x00\x00\x57\x41\x56\x45\x66\x6d\x74\x20\x10\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x64\x61\x74\x61\x00\x00\x00\x00"
   get RIFFSIZE asize MEMORY_FILE
   math RIFFSIZE + SIZE
   math RIFFSIZE -= 8
   get CHANNELS short 1
   get FREQUENCY long 1
   get BPS long 1
   get ALIGN short 1
   get BITS short 1
   putVarChr MEMORY_FILE 4 RIFFSIZE long
   putVarChr MEMORY_FILE 22 CHANNELS short
   putVarChr MEMORY_FILE 24 FREQUENCY long
   putVarChr MEMORY_FILE 28 BPS long
   putVarChr MEMORY_FILE 32 ALIGN short
   putVarChr MEMORY_FILE 34 BITS short
   putVarChr MEMORY_FILE 40 SIZE long
   get FULLSIZE asize MEMORY_FILE
   log NAME 0 FULLSIZE MEMORY_FILE
      append
      log NAME OFFSET2 SIZE 1
   append
endfunction
cornel
Posts: 30
Joined: Sun Feb 25, 2018 4:27 pm

Re: REIMPORT MEMORY_FILE WORK-AROUND ???

Post by cornel »

Reimport gives an error...
aluigi
Site Admin
Posts: 12984
Joined: Wed Jul 30, 2014 9:32 pm

Re: REIMPORT MEMORY_FILE WORK-AROUND ???

Post by aluigi »

try with the following line at the beginning of the script as suggested (the script is a header builder indeed):

Code: Select all

quickbmsver "-."
cornel
Posts: 30
Joined: Sun Feb 25, 2018 4:27 pm

Re: REIMPORT MEMORY_FILE WORK-AROUND ???

Post by cornel »

Now there's no error message, but the injected audio file is ignored by the game and the original audio is playing.
When extracted, the modified audio file is indeed present in the pcd container file, but it turns out to be a blank (no sound) wav file, so somehow the injecting process erases the audio data from the file...
aluigi
Site Admin
Posts: 12984
Joined: Wed Jul 30, 2014 9:32 pm

Re: REIMPORT MEMORY_FILE WORK-AROUND ???

Post by aluigi »

I will check the method again for quickbms 0.8.5 but I'm quite sure it worked perfectly when I implemented it