FINDarkside / TLD-Save-Editor

Edit The Long Dark save files
http://www.moddb.com/mods/the-long-dark-save-editor-2/downloads
MIT License
75 stars 31 forks source link

Tipps & Hints for a rewrite :) #78

Open kkuez opened 2 years ago

kkuez commented 2 years ago

Hello Fin, I thought about rewriting your tool in java (thats my native language) and took a look over your fantastic project. As I dig a bit into the TLD save files and compared to your code, a it was clear here no clear json was used and b you went to decode the save file form CLZF, is that correct? I started fiddling around a bit with CLZF and the save and could not make out any success there. Can you give me a hint where to start the journey the best? Kind regards!

FINDarkside commented 2 years ago

Yeah you're correct the save file is CLZF compressed, then it's json for some part, until m_Dict field is an object which values are binary data stored as number array (lol). That binary data is again CLZF compressed and the output is json. After that everything should be json except that there's many places where instead of plain json the value is a string of serialized JSON, requiring you to deserialize stuff a lot of times.

If you're familiar with typescript, I have also set up working deserialization/serialization in ts, here: tldParser.ts, ObjectParser.ts. But I'm not really planning on working on that anymore, already did the interesting part of it, just can't bother to make the UI 😄

Let me know if you have any problems or questions!

FINDarkside commented 2 years ago

Oh and at least in one point the profile file was invalid json, which is why I do this when deserializing and this when serializing the file.

As for the stuff in Serialization folder it's all pretty much for being able to deserialize/serialize stuff without losing any fields I don't know about. Previously I was having the problem that I had to hardcode every single field in the game save and after update the editor would lose all the new fields it didn't know about. You'll probably run into the same issue unless you use some kind of fully dynamic serialize/deserialize (which I didn't want to do, since I wanted types for the save file).

kkuez commented 2 years ago

Hi Fin, Wow, what an awsome and heartwarmening answer, thank you a lot :) Thats what makes devolopers great, the will to share their knowledge (...and that they cba to do the UI stuff :D)!

With your tips on hand, Ill try to make the deserialization work today and the days after and will start to implement from there on. With TS I had contact within the company, but Im more of the backend kind, thus I doubt Ill be able to make much sense out of the project, but yepp, I already saw it and will use it as a ressource for sure :)

Thanks a lot again and if you really dont mind, I would like to contact you again when I need some council here and there? Cheers and have a nice day :)

kkuez commented 2 years ago

Hi once again Fin, ~~Tonight Ive been fiddling around with all that and your references already got me to a decent point. Now Im a bit confused with those binaries. Like you, I can see those annoying number arrays. You told me those contain actually "binary data" and that those are clzf encrypted too. Thats the point where I am a bit puzzled, let me begin before all that.~~

I wrote a small C# Program as there were no decent decryptors for java. It deencrypts the file well and gives me all contents as bytes. Those bytes I convert to chars and receive a well readable json. That json I parse to a map and yes, under the m_Dict-Node I have several entries with Lists of numbers. Now I COULD convert them to binary representations easily, but it would not do me any favour.

Whats the point to go here? How can I get a deencryptable representation? Looking forward to your answer and cheers, Marcel

EDIT: BLABLABAL Im stupid and already found out the puzzles solution myself :) Thank you nevertheless!

FINDarkside commented 2 years ago

Now I COULD convert them to binary representations easily, but it would not do me any favour.

That's what you should do, convert it to binary assuming that every value in the array is one byte. After that decompress it with CLZF and it'll be json. The save format doesn't make sense for sure, but it is what it is 😄 I remember once making an experiment where I removed all of this nested serialization and ended up shaving ~80% of the save size off without losing any data.

Thanks a lot again and if you really dont mind, I would like to contact you again when I need some council here and there?

I don't mind. You can also contact me on discord if you wish (FINDarkside#1337), but github is fine as well.

Cheers and have a nice day :)

You too :)

E: Ok I see you solved it, but I'll send this anyway since I wrote it already.