Register - Login
Views: 99793883
Main - Memberlist - Active users - Calendar - Wiki - IRC Chat - Online users
Ranks - Rules/FAQ - Stats - Latest Posts - Color Chart - Smilies
05-03-22 05:07:19 AM
Jul - General Game/ROM Hacking - LZ77 stuff New poll - New thread - New reply
Next newer thread | Next older thread
Ninji

Birdo
Why did my user title say I'm a toaster anyway
Level: 88


Posts: 162/2014
EXP: 6638524
For next: 12140

Since: 07-26-07

Pronouns: he/him or they/them
From: Glasgow, Scotland

Since last post: 113 days
Last activity: 6 days

Posted on 02-19-09 05:34:25 PM Link | Quote
Okay so, I got bored and I was messing around with NSMB again, inspired by the latest re-ban of Mega Moron.

I'm not going to make any new tools or anything, I'm working on something rather random and stupid (you'll see soon enough) but I need one thing I don't have.

I can decompress LZ77 files, but I can't recompress them.

I tried translating the VB function for it from the Elitemap code to Python, but it just stays stuck in an infinite loop, and the code is too complex for me to understand. I'm not sure if it even worked in the first place.

Is there an easier way to do this?



____________________
GUESS WHAT MEGA-MARIO? I'm not ROM hacking any more. So leave me alone and stop emailing me okay?! · Hacking Tools: Nitro Explorer · NARC Explorer
GuyPerfect
Catgirl
Level: 68


Posts: 554/1096
EXP: 2665652
For next: 63148

Since: 07-23-07


Since last post: 1.7 years
Last activity: 219 days

Posted on 02-19-09 05:59:41 PM Link | Quote
Originally posted by Treeki
Is there an easier way to do this?
One of the best pieces of programming advice you'll ever encounter: Avoid magic wands. Don't reach for someone else's code unless you understand how to write it yourself; it'll save you trouble down the road, AND you'll be able to do it yourself!

LZ77 has a simple procedure:

* Is the next piece of data raw or encoded?

* If it is raw...
* Read from the input buffer 1 byte to the end of the output buffer
* If it is encoded...
* Read from the input buffer the Distance and Length values
* Go back Distance bytes into the output buffer and read Length bytes
from there onto the end of the output buffer
* Go back to the first step


Usually, the structure of an LZ77 stream contains a header byte, which describes the next 8 chunks of data as being either 0 - Raw or 1 - Encoded. When 8 chunks are read, there's another header byte and so-on. Find out how the Distance/Length pairs are stored (usually 2 bytes; 12-4 bits) and you should be pretty good on your way to writing a compressor.

As a bare minimum, a compressed LZ77 stream needs to include the original data size prior to compression so the decompressor knows when to stop.

Also note that Length can be greater than Distance. It is a common mistake to forget this, and it often results in compressed data being larger than it needs to be.
Ninji

Birdo
Why did my user title say I'm a toaster anyway
Level: 88


Posts: 164/2014
EXP: 6638524
For next: 12140

Since: 07-26-07

Pronouns: he/him or they/them
From: Glasgow, Scotland

Since last post: 113 days
Last activity: 6 days

Posted on 02-19-09 06:47:42 PM Link | Quote
Thanks for the help. I couldn't figure out how to make it actually compress the file (or rather, too lazy to ) but I managed to make my file into a LZ77 format file, which although isn't much compression (the file is bigger than the original) works fine in the game.

____________________
GUESS WHAT MEGA-MARIO? I'm not ROM hacking any more. So leave me alone and stop emailing me okay?! · Hacking Tools: Nitro Explorer · NARC Explorer
Hectamatatortron
Member
Level: 35


Posts: 111/232
EXP: 258215
For next: 21721

Since: 09-19-07


Since last post: 7.2 years
Last activity: 5.3 years

Posted on 02-20-09 03:57:02 AM Link | Quote
Is the intent of this project to compress data in the LZ77 format that is decompressed by the GBA and NDS's SWIs?

I have some Java code I can help you port for that purpose as a part of a GBA ROM editor I've written.

Unfortunately, I don't know enough about how it works to write it on my own (that is, if I wanted to optimize the code, I wouldn't know where to start; really, though, it's probably as optimal as it gets). I do know the format of LZ77 compression, however. Not that it matters; I just ported a friend's code from C# to Java as his tool that the code was for was also for hacking GBA ROMs.

____________________
Erika
Catgirl
미안합니다
Level: 68


Posts: 469/1088
EXP: 2637491
For next: 91309

Since: 07-19-07


Since last post: 9.5 years
Last activity: 9.3 years

Posted on 02-20-09 04:26:19 PM Link | Quote
Originally posted by Treeki
I tried translating the VB function for it from the Elitemap code to Python, but it just stays stuck in an infinite loop, and the code is too complex for me to understand. I'm not sure if it even worked in the first place.
Just for future reference, no, the code probably doesn't/didn't/barely worked in the first place if that's where you're getting it from
Next newer thread | Next older thread
Jul - General Game/ROM Hacking - LZ77 stuff New poll - New thread - New reply


Rusted Logic

Acmlmboard - commit 47be4dc [2021-08-23]
©2000-2022 Acmlm, Xkeeper, Kaito Sinclaire, et al.

31 database queries, 1 query cache hits.
Query execution time: 0.085374 seconds
Script execution time: 0.008494 seconds
Total render time: 0.093868 seconds