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.

Need help extract mrg [??????]

Featured Replies

  • Author
  • Localization

bam_bam, posted Sun Sep 30, 2018 3:29 pm (38901)


Hi :)
I am not good at English, so I hope you look over some awkward expressions.

How can I unpack mrg file?

I know there is python tool already.
but It's not perfect and there is no repack function.

so I want a bms script for these file.
I will be very pleased if you help me.
Thanks to read.
  • Author
  • Localization

aluigi, posted Wed Oct 03, 2018 11:02 am (38970)


What's the name of the game?
  • Author
  • Localization

bam_bam, posted Wed Oct 03, 2018 12:39 pm (38984)


aluigi wrote:
What's the name of the game?


oh, sorry.
A title is ??????.
  • Author
  • Localization

aluigi, posted Wed Oct 03, 2018 1:13 pm (38988)


The HED file, which I expect contains information for extracting the data from the MRG file, is quite confusing.
In the MRG file I see only various "MZX0" strings.
What's the python script you are currently using?
  • Author
  • Localization

bam_bam, posted Wed Oct 03, 2018 1:18 pm (38990)


aluigi wrote:
The HED file, which I expect contains information for extracting the data from the MRG file, is quite confusing.
In the MRG file I see only various "MZX0" strings.
What's the python script you are currently using?


https://github.com/Hintay/PS-HuneX_Tools

I always appreciate your help :)
  • Author
  • Localization

aluigi, posted Wed Oct 03, 2018 1:52 pm (38993)


Try the following:
Code:
set MEMORY_FILE10 string "
// https://github.com/Hintay/PS-HuneX_Tools/blob/master/tools/mzx/decomp_mzx0.py
int mzx0_decompress(unsigned char *f, int fsz, unsigned char *dout, int exlen) {
    unsigned char   ringbuf[128];
    int ring_wpos = 0;
    int clear_count = 0;
    int offset = 0;
    int last1 = 0, last2 = 0;
    unsigned char   *max = f fsz;
    int i, k;

    for(i = 0; i < sizeof(ringbuf); i ) ringbuf[i] = 0;

    while(offset < exlen) {
        if(f >= max)
            break;
        if(clear_count <= 0) {
            clear_count = 0x1000;
            last1 = last2 = 0;
        }
        int flags = *f ;

        clear_count -= ((flags & 0x03) == 2) ? 1 : ((flags / 4) 1);

        if((flags & 0x03) == 0) {
            for(i = 0; i < ((flags / 4) 1); i ) {
                if(offset >= exlen) break;
                dout[offset  ] = last1;
                dout[offset 1] = last2;
                offset = 2;
            }

        } else if((flags & 0x03) == 1) {
            if(f >= max)
                break;
            k = *f ;
            k = 2 * (k 1);
            for(i = 0; i < ((flags / 4) 1); i ) {
                if(offset >= exlen) break;
                // read two previous bytes in sliding
                dout[offset] = dout[offset - k];
                offset = 1;
                dout[offset] = dout[offset - k];
                offset = 1;
            }
            last1 = dout[offset-2];
            last2 = dout[offset-1];

        } else if((flags & 0x03) == 2) {
            if(offset >= exlen) break;
            dout[offset  ] = last1 = ringbuf[2 * ((flags / 4))];
            dout[offset 1] = last2 = ringbuf[2 * ((flags / 4)) 1];
            offset = 2;

        } else {
            for(i = 0; i < ((flags / 4) 1); i ) {
                if(offset >= exlen) break;
                if(f >= max)
                    break;
                last1 = ringbuf[ring_wpos] = dout[offset] = *f ;
                ring_wpos = 1;
                offset = 1;
                last2 = ringbuf[ring_wpos] = dout[offset] = *f ;
                ring_wpos = 1;
                offset = 1;
                ring_wpos &= 0x7F;
            }
        }
    }
    return offset;
}
"
comtype calldll "MEMORY_FILE10 mzx0_decompress tcc RET #INPUT# #INPUT_SIZE# #OUTPUT# #OUTPUT_SIZE#"

#codepage 932
idstring "mrgd00"
get number_of_entries short
for i = 0 < number_of_entries
    get sector_offset short
    get offset short
    get sector_size_upper_boundary short
    get size short
    xmath OFFSET "(sector_offset * 0x800) offset"
    putarray 0 i OFFSET
next i
savepos BASE_OFF

    get OFFSET asize
    math OFFSET - BASE_OFF
    putarray 0 i OFFSET
sortarray 0 1

# the first file contains the names
math END_NAMES = 0
for i = 1 < number_of_entries
    if END_NAMES == 0
        getdstring NAME 32
        if NAME == ""
            math END_NAMES = 1
        else
            string NAME .
        endif
    else
        set NAME string ""
    endif
    getarray OFFSET 0 i
    math i 1
    getarray SIZE   0 i
    math SIZE - OFFSET
    math OFFSET BASE_OFF

    savepos TMP
    goto OFFSET
    getdstring SIGN 4
    if SIGN u== "MZX0"
        get XSIZE long
        math OFFSET 8
        math SIZE   - 8
        clog NAME OFFSET SIZE XSIZE
    else
        log NAME OFFSET SIZE
    endif
    goto TMP
next

Basically I ignore the *size fields because they look confusing and difficult to calculate, the only downside is that you are probably going to have few (less than 8) padding bytes at the end of each file.

The names are chaotic because there are less names available than files, I used a work-around.
  • Author
  • Localization

aluigi, posted Wed Oct 03, 2018 3:02 pm (38998)


I have updated the previous script for supporting the MZX compression (which will be natively available in the next quickbms).
  • Author
  • Localization

bam_bam, posted Thu Oct 04, 2018 12:46 pm (39050)


aluigi wrote:
I have updated the previous script for supporting the MZX compression (which will be natively available in the next quickbms).


It works well.
I don't know how to thank you.
I hope you always have a nice day!
  • Author
  • Localization

aluigi, posted Thu Oct 04, 2018 1:43 pm (39056)


Thanks to you for the new algorithm for quickbms :D
  • Author
  • Localization

aluigi, posted Fri Oct 05, 2018 9:25 am (39099)


Script updated.
Files decompressed with previous versions may be wrong.
  • Author
  • Localization

Nyanpasu, posted Wed Aug 04, 2021 7:07 am (65496)


Thanks
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.