actioninja / refpack-rs

Rust crate for decompressing and compressing data in the RefPack format used by many EA games of the early 2000s
Mozilla Public License 2.0
6 stars 1 forks source link

SimCity 4 Encoding Format? #5

Closed lingeringwillx closed 1 year ago

lingeringwillx commented 1 year ago

https://github.com/actioninja/refpack-rs/blob/624e7bf975ad66a35753decfffac317d57162860/src/data/control/mode/simcity_4.rs#L17

Have you confirmed that SimCity 4 does use this encoding? I think you got this info from the simswiki, but implementations that I've seen use the same format as The Sims 2's.

Examples:

https://github.com/memo33/jDBPFX/blob/master/src/jdbpfx/util/DBPFPackager.java

https://github.com/0xC0000054/DBPFSharp/blob/main/src/DBPFSharp/QfsCompression.cs

actioninja commented 1 year ago

Bitmasked nonsense is such a pain in the ass to read I just assumed that the niotso and simswiki were accurate on this.

I actually converted the old jdbpf library to git and reuploaded it here:

https://github.com/actioninja/JDBPF/blob/90644a3286580aa7676779a2d2e5a3c9de9a31ff/src/ssp/dbpf/converter/DBPFPackager.java#L485C8-L485C8

int offset = (int) (((control1 & 0x10) << 12) + (control2 << 8) + (control3) + 1);
long numberToCopyFromOffset = ((control1 & 0x0C) << 6) + (control4) + 5;

looks like qfs is the same:

plainCount = (controlByte1 & 3);
copyCount = ((controlByte1 & 0x0C) << 6) + controlByte4 + 5;
copyOffset = (((controlByte1 & 0x10) << 12) + (controlByte2 << 8)) + controlByte3 + 1;

You actually don't even really need to properly figure out what this is doing, you can see the length pulls from two bytes and the offset pulls from 3 which corresponds to the reference implementation.

Good catch, I really need to just start making my own reference of info for data formats on this stuff because the scattered info I find keeps having inaccuracies in ways like this.

actioninja commented 1 year ago

Might actually be worth reducing the complexity of the code here if it's all standardized, hmm

lingeringwillx commented 1 year ago

Might actually be worth reducing the complexity of the code here if it's all standardized, hmm

Yes. It seems that the encoding is the same for all games. It's just that there is a variety of headers. I think later games like The Sims 3 and Spore have a special mode where they only encode shorts or something like that.