English Amiga Board


Go Back   English Amiga Board > Coders > Coders. Language > Coders. C/C++

 
 
Thread Tools
Old 05 May 2024, 18:17   #1
Darasco
Registered User
 
Join Date: Feb 2022
Location: san fernando
Posts: 8
Centurion packer

Hello, good afternoon. I am trying to translate the centurion game. There are several compressed files supposedly in lzw. I have got a decompressor made in C, that works. But, the files need to be compressed again. Using the same algorithm would it be possible to make a compressor? thanks for the help. I will leave an example file and the code.
Attached Files
File Type: 7z extract.7z (636 Bytes, 15 views)
File Type: 7z SCOUT.7z (2.4 KB, 14 views)
Darasco is offline  
Old 05 May 2024, 18:48   #2
jotd
This cat is no more
 
jotd's Avatar
 
Join Date: Dec 2004
Location: FRANCE
Age: 52
Posts: 8,303
In a compressor/decompressor algorithm, the decompressor is the easy part. Writing the compressor is not easy and there are several possiblities to compute the dictionary, not just one. Did you write the decompressor yourself?
jotd is offline  
Old 05 May 2024, 18:58   #3
Darasco
Registered User
 
Join Date: Feb 2022
Location: san fernando
Posts: 8
I didn't do it. I just looked it up. But I haven't found a compressor. Ok, thanks anyway.
Darasco is offline  
Old 05 May 2024, 19:04   #4
paraj
Registered User
 
paraj's Avatar
 
Join Date: Feb 2017
Location: Denmark
Posts: 1,146
It shouldn't be too bad of such a simple encoding. You can probably adapt an existing encoder quite easily. If you you're not pressed for size, start out with just a really stupid one that encodes everything as literals.
paraj is offline  
Old 05 May 2024, 19:11   #5
Darasco
Registered User
 
Join Date: Feb 2022
Location: san fernando
Posts: 8
mmm. thanks. i'll try a couple of things.
Darasco is offline  
Old 05 May 2024, 21:07   #6
paraj
Registered User
 
paraj's Avatar
 
Join Date: Feb 2017
Location: Denmark
Posts: 1,146
Like this I mean (terrible code, but should decompress to the same thing):
Code:
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>

uint8_t outbuf[1024*1024];
uint8_t* mode_ptr = &outbuf[0];
int mode_cnt = 0;
size_t outbuf_pos = 1;

int main(int argc, char* argv[])
{
    if (argc != 3) {
        fprintf(stderr, "Usage: %s in out\n", argv[0]);
        return 1;
    }

    FILE* in = fopen(argv[1], "rb");
    if (!in) {
        fprintf(stderr, "Could not open %s\n", argv[1]);
        return -1;
    }
    uint8_t* data;
    uint32_t data_len;

    fseek(in, 0, SEEK_END);
    data_len = (uint32_t)ftell(in);
    fseek(in, 0, SEEK_SET);
    data = (uint8_t*)malloc(data_len); // Let's assume this works
    fread(data, data_len, 1, in);
    fclose(in);

    FILE* out = fopen(argv[2], "wb");
    if (!out) {
        fprintf(stderr, "Could not create %s\n", argv[2]);
        return -1;
    }
    fputc((data_len>>24)&0xff, out);
    fputc((data_len>>16)&0xff, out);
    fputc((data_len>>8)&0xff, out);
    fputc((data_len>>0)&0xff, out);

    for (uint32_t i = 0; i < data_len; ++i) {
        if (mode_cnt == 8) {
            mode_cnt = 0;
            mode_ptr = &outbuf[outbuf_pos++];
        }
        *mode_ptr = *mode_ptr << 1 | 1;
        ++mode_cnt;
        outbuf[outbuf_pos++] = data[i];
    }

    fwrite(outbuf, outbuf_pos, 1, out);
    fclose(out);
    return 0;
}
paraj is offline  
Old 05 May 2024, 22:04   #7
Darasco
Registered User
 
Join Date: Feb 2022
Location: san fernando
Posts: 8
Thank you very much. I'll try it right now. Anyway I've tested adding a fake header to the decompressed file and it seems to read it, although the texts don't match where they should be, but it reads it for sure.

Last edited by Darasco; 05 May 2024 at 22:56.
Darasco is offline  
Old 05 May 2024, 22:15   #8
Darasco
Registered User
 
Join Date: Feb 2022
Location: san fernando
Posts: 8
It workssss!!!. there are no words to thank you
Darasco is offline  
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Similar Threads
Thread Thread Starter Forum Replies Last Post
Is there a better packer than arjm7? leonard Coders. Asm / Hardware 70 04 January 2024 20:22
old soundeditors and pt-packer Promax request.Apps 7 14 July 2010 13:21
Unofficial version of Centurion PL, needing WHDLoad support... Shoonay project.WHDLoad 1 04 August 2008 23:15
req: Centurion Defender Of Rome Whdfied AMIGAZ request.Old Rare Games 5 17 August 2006 00:33
Centurion - how to speak? Shoonay support.Games 2 29 April 2005 21:22

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 12:30.

Top

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Page generated in 0.13185 seconds with 16 queries