Convert old MexScript to BMSScript ?

Doubts, help and support about QuickBMS and other game research tools
aluigi
Site Admin
Posts: 12984
Joined: Wed Jul 30, 2014 9:32 pm

Re: Convert old MexScript to BMSScript ?

Post by aluigi »

No idea, maybe they are sprites or something like that... not my field
Tgames
Posts: 81
Joined: Mon Apr 01, 2019 10:49 am

Re: Convert old MexScript to BMSScript ?

Post by Tgames »

No problem ;)

Here a C code i have adapted to work to extract every voices from Dune (Mega CD Version).

Code: Select all

#include "stdio.h"

int ConvertToWav()
{
    FILE    *file, *wav;
    int     read = EOF, write, i = 0;
    int    wavheader[] = {
        0x52, 0x49, 0x46, 0x46, 0x04, 0x09, 0x42, 0x13, 0x57, 0x41,
      0x56, 0x45, 0x66, 0x6D, 0x74, 0x20, 0x10, 0x00, 0x00, 0x00,
      0x01, 0x00, 0x01, 0x00, 0xCE, 0x56, 0x00, 0x00, 0x9C, 0xAD,
      0x00, 0x00, 0x02, 0x00, 0x10, 0x00, 0x64, 0x61, 0x74, 0x61,
      0xE0, 0x08, 0x42, 0x13, 0x00
            };

    printf("Dune PCM Dumper to Wav Converted Modified by Tgames V1.0\n");
    file = fopen("DUNE.DAT", "r");
    if(!file)
    {
        printf("Could not open DUNE.DAT, please copy it in this folder and restart\n");
        return(0);
    }
    wav = fopen("DUNEMGCD_PCM.wav", "w");
    if(!wav)
    {
        fclose(file);
        printf("Could not create output file\n");
        return(0);
    }

    do
    {
        write = wavheader[i++];
        if(write != 0xFF)
            fputc(write, wav);
    }
    while(write != 0xFF);

    printf("Writing to DUNEMGCD_PCM.wav\n");
    do
    {
        read = fgetc(file);
        if(read != EOF)
        {
            if(read < 0x80)
                write = 0x80 - read;
            else
                write = read;

            if(write == 0xFF)       
            {
                int skip = 0;

                do
                {
                    read = fgetc(file);
                    skip ++;
                }
                while(skip < 12 && read != EOF);
            }
            else
                    fputc(write, wav);
        }
    }
    while(read != EOF);

    fclose(wav);
    fclose(file);
    printf("Conversion complete\n");
    return(1);
}

int main()
{
    if(!ConvertToWav())
        return(1);

    return(0);
}


But it just make a full WAV file and not cut every voices one by one (like a BMS Script do)

Theses Voices (after the C Script) are :

Encoding: Unsigned 8-bit PCM
Bytes order : "Endianness"
22222Hz Mono

Are you sure Dune Mega CD have no header ? It can helps us, because it's really painful to cut every voices in my export xD.
We have everything thanks to this C code, but really really long to cut every voices one by one :mrgreen:

Dune Mega CD : https://we.tl/t-AC7iGRP2Ew
aluigi
Site Admin
Posts: 12984
Joined: Wed Jul 30, 2014 9:32 pm

Re: Convert old MexScript to BMSScript ?

Post by aluigi »

There are only zeroes at the beginning and 'P's at the end.
No structure.
Tgames
Posts: 81
Joined: Mon Apr 01, 2019 10:49 am

Re: Convert old MexScript to BMSScript ?

Post by Tgames »

Arf bad :(

And in my export, can a BMS Script auto split each voices ?

Here is my full export of all voices :

https://we.tl/t-Fq7MHjODmG

There is a separator sound between each voices.
aluigi
Site Admin
Posts: 12984
Joined: Wed Jul 30, 2014 9:32 pm

Re: Convert old MexScript to BMSScript ?

Post by aluigi »

Those separators you see are the 'P's I said before.
Every file is aligned to 2048 bytes and the 'P's are used for padding.
The index file contains both offsets and sizes, without them it's just a waste of time.

You can use this script on DUNE.DAT and it will use the 'P's for dumping the files separately:

Code: Select all

for
    savepos OFFSET
    findloc EOF binary "PPPPPPPP"
    if OFFSET == EOF
        break
    endif
    math SIZE = EOF
    math SIZE - OFFSET
    log "" OFFSET SIZE
    math EOF x 0x800
    goto EOF
next
Tgames
Posts: 81
Joined: Mon Apr 01, 2019 10:49 am

Re: Convert old MexScript to BMSScript ?

Post by Tgames »

Thanks for the script !

It's possible to include the convert of each files generated or i can just convert them with the C code ?

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

Re: Convert old MexScript to BMSScript ?

Post by aluigi »

I think it's more easy if you use that tool, once the files are extracted you can mass converting them on the fly.
aluigi
Site Admin
Posts: 12984
Joined: Wed Jul 30, 2014 9:32 pm

Re: Convert old MexScript to BMSScript ?

Post by aluigi »

Obviously that C code needs some edits, the filename for sure.
I also suggest EVER to use "wb" instead "w" with fopen.
Tgames
Posts: 81
Joined: Mon Apr 01, 2019 10:49 am

Re: Convert old MexScript to BMSScript ?

Post by Tgames »

Thanks for all your answers :)
Can you write what i need to change on the C code (if you can, otherwhise i will search myself don't worry).
aluigi
Site Admin
Posts: 12984
Joined: Wed Jul 30, 2014 9:32 pm

Re: Convert old MexScript to BMSScript ?

Post by aluigi »

That C code is super bugged
aluigi
Site Admin
Posts: 12984
Joined: Wed Jul 30, 2014 9:32 pm

Re: Convert old MexScript to BMSScript ?

Post by aluigi »

Really it doesn't work at all.
The result is garbage.
Acewell
Posts: 706
Joined: Fri Aug 08, 2014 1:06 am

Re: Convert old MexScript to BMSScript ?

Post by Acewell »

Tgames wrote:Thanks for the fix for the first script...

um, you're welcome? :roll:
the spiderman mexscript was also incomplete...
Tgames
Posts: 81
Joined: Mon Apr 01, 2019 10:49 am

Re: Convert old MexScript to BMSScript ?

Post by Tgames »

I used this code to convert the audio to something readable aLuigi :

http://junkerhq.net/Snatcher/PCM2WAV/

Thanks Acewell for the Spider Man Extract code but i got an error when trying to extract a package :/
aluigi
Site Admin
Posts: 12984
Joined: Wed Jul 30, 2014 9:32 pm

Re: Convert old MexScript to BMSScript ?

Post by aluigi »

Something readable? I hear only noise which means that it uses a specific codec and the trick used in that C code doesn't work.

Anyway the following is the script, once you have the codec code it's easy to put it in the convert() function:

Code: Select all

set MEMORY_FILE10 string "
int convert(unsigned char *data, int size, unsigned char *wav) {
    int read, write, i = 0, x = 0;
    while(i < size) {
        read = data[i++];
        {
            if(read < 0x80)
                write = 0x80 - read;
            else
                write = read;

            if(write == 0xFF)       
            {
                i += 12;
            }
            else
                    wav[x++] = write;
        }
    }
    return x;
}
"

for i = 0
    savepos OFFSET
    findloc EOF binary "PPPPPPPP"
    if OFFSET == EOF
        break
    endif
    math SIZE = EOF
    math SIZE - OFFSET

    string NAME p "%d.wav" i
    #log NAME OFFSET SIZE
    callfunction DUMP

    math EOF x 0x800
    goto EOF
next i

startfunction DUMP
    log MEMORY_FILE2 0 0
    putvarchr MEMORY_FILE2 SIZE 0

    log MEMORY_FILE OFFSET SIZE
    calldll MEMORY_FILE10 "convert" "tcc" SIZE MEMORY_FILE SIZE MEMORY_FILE2

    math CODEC = 1
    math BITS = 16
    math CHANNELS = 1
    math FREQUENCY = 22050

    math BLKALIGN = BITS
    math BLKALIGN / 8
    math BLKALIGN * CHANNELS
    math AVGBYTES = FREQUENCY
    math AVGBYTES * BLKALIGN

    log MEMORY_FILE 0 0
    putdstring "RIFF" 4 MEMORY_FILE
    put 0 long          MEMORY_FILE
    putdstring "WAVE" 4 MEMORY_FILE

    # "fmt "
    putdstring "fmt " 4 MEMORY_FILE
    put 0 long          MEMORY_FILE
    put CODEC short     MEMORY_FILE # wFormatTag: Microsoft PCM Format (0x0001)
    put CHANNELS short  MEMORY_FILE # wChannels
    put FREQUENCY long  MEMORY_FILE # dwSamplesPerSec
    put AVGBYTES long   MEMORY_FILE # dwAvgBytesPerSec
    put BLKALIGN short  MEMORY_FILE # wBlockAlign
    put BITS short      MEMORY_FILE # wBitsPerSample
    get MEM_SIZE asize MEMORY_FILE
    math RIFFTMP = MEM_SIZE
    math RIFFTMP - 0x14
    putvarchr MEMORY_FILE 0x10 RIFFTMP long

    # "data"
    putdstring "data" 4 MEMORY_FILE
    put SIZE long       MEMORY_FILE

    get MEM_SIZE asize MEMORY_FILE
    math RIFFTMP = SIZE
    math RIFFTMP + MEM_SIZE
    math RIFFTMP - 8
    putvarchr MEMORY_FILE 4 RIFFTMP long

    log NAME 0 MEM_SIZE MEMORY_FILE
    append
    log NAME 0 SIZE MEMORY_FILE2
    append
endfunction
Tgames
Posts: 81
Joined: Mon Apr 01, 2019 10:49 am

Re: Convert old MexScript to BMSScript ?

Post by Tgames »

This is the original code of the PCM Extractor tool :

http://junkerhq.net/Snatcher/PCM2WAV/Sn ... CM2WAV.zip

1) Just rename any .meg to « PCMLD_01.BIN »
2) Throw this file into spcm2wav.exe
3) It will generate a file « Snatcher_PCM.wav »
4) Open this file with Audacity in « Raw Mode »
5) Set values to :
Encoding: Unsigned 8-bit PCM
Bytes order : "big endian"
22222Hz Mono
6) That’s all, the audio is correct, just remove 1 second at the beginning
7) It can be exported to WAV

But Indeed the original source code seems a bit buggy !

By following theses step it's work on each files but indeed the code is buggy :/

Thanks a lot for the script !
But it's seems to do nothing on .meg files.
Tgames
Posts: 81
Joined: Mon Apr 01, 2019 10:49 am

Re: Convert old MexScript to BMSScript ?

Post by Tgames »

The correct values for all .meg (after conversion) are :

Encoding: Unsigned 8-bit PCM
Bytes order : "big endian"
22222Hz Mono
Tgames
Posts: 81
Joined: Mon Apr 01, 2019 10:49 am

Re: Convert old MexScript to BMSScript ?

Post by Tgames »

Here is a english sample converted to .VOC with correct values taken from the Mega CD version :

https://we.tl/t-gLY8d05ks0

All voices are in the same values :

Encoding: Unsigned 8-bit PCM
Bytes order : "big endian"
22222Hz Mono
aluigi
Site Admin
Posts: 12984
Joined: Wed Jul 30, 2014 9:32 pm

Re: Convert old MexScript to BMSScript ?

Post by aluigi »

endianess doesn't exist in 8bits, frequency is 22050 as stated in the script (why it should be 22222???).
For setting 8 bits it's enough to use BITS = 8 in the script where it's currently 16

Those audio files are "Megative Voice File" while the others are different things.
Tgames
Posts: 81
Joined: Mon Apr 01, 2019 10:49 am

Re: Convert old MexScript to BMSScript ?

Post by Tgames »

It's big endian.

I badly translated to english "Gros boutisme" in french ^^

It's really 22222hz ! We are sure about that, because in all Dune port it's 22222hz.

And we have a 1:1 comparaison between english voices from the Mega CD and PC in 22222hz it's totally identical.
aluigi
Site Admin
Posts: 12984
Joined: Wed Jul 30, 2014 9:32 pm

Re: Convert old MexScript to BMSScript ?

Post by aluigi »

Interesting that thing of the sample rate, developers are crazy :)

Now the main question remains: we have DUNE.DAT but where are the other files and executables that contain the index?