Welcome!

Join our community of MMO enthusiasts and game developers! By registering, you'll gain access to discussions on the latest developments in MMO server files and collaborate with like-minded individuals. Join us today and unlock the potential of MMO server development!

Join Today!

[Source] Directly loading .dec files (if available) in CabalMain

Newbie Spellweaver
Joined
Dec 14, 2019
Messages
30
Reaction score
233
Before opening any .enc file and trying to decode it, look for .dec file in the same directory which should be already decompressed and de-xored. Read that directly into memory if it exists, otherwise continue loading and decoding the regular .enc file.
This should simplify some development. No point encoding the files after every modification.

Using https://forum.ragezone.com/threads/clean-cabalmain-exe-v374-dll-source.1215044/ as a base; this goes to main.c:

C:
static int
readfile(const char *path, char **buf, size_t *len)
{
    FILE *fp;

    fp = fopen(path, "rb");
    if (!fp) {
        return -1;
    }

    fseek(fp, 0, SEEK_END);
    *len = ftell(fp);

    fseek(fp, 0, SEEK_SET);
    *buf = malloc(*len + 1);
    if (*buf == NULL) {
        return -1;
    }

    fread(*buf, 1, *len, fp);
    (*buf)[*len] = 0;
    fclose(fp);

    return 0;
}

static __cdecl void (*org_open_enc_file)(const char *filename, void **buf,
                                         size_t *len) = (void *)0x4559b0;
static __cdecl void
hooked_open_enc_file(const char *filename, void **buf, size_t *len)
{
    if (strlen(filename) > strlen(".dec")) {
        char new_filename[512];

        snprintf(new_filename, sizeof(new_filename), "%.*s.dec", strlen(filename) - 4,
                 filename);
        if (readfile(new_filename, (char **)buf, len) == 0) {
            fprintf(stderr, "Opened .dec instead of .enc! \"%s\"\n", new_filename);
            return;
        }
    }

    return org_open_enc_file(filename, buf, len);
}
PATCH_MEM(0x4074c3, 5, "jmp 0x%x", hooked_open_enc_file);
Opened .dec instead of .enc! "c:\path\to\cabal\Data\cabal.dec"
Opened .dec instead of .enc! "c:\path\to\cabal\Data\Language\English\language.dec"

Seems to work, haven't tested extensively.
 
Last edited by a moderator:
Back
Top