Title: Programming question Post by: randomprofile on April 15, 2012, 03:20:51 AM So I've been programming for some time... and for as long as I have one thing still questions me... How are save files written and read. I've asked alot of people and I can't seem to get a straight answer. so maybe one of you or Paul knows... How does a game like Minecraft or Terreria store it's world data... I know it isn't binary since I've opened it plenty of times and found nothing :(
Title: Re: Programming question Post by: FutureB on April 15, 2012, 05:05:00 AM Im prity sure it saves it in some type of computer language or somewhere inside your computer or the server your joining.
Title: Re: Programming question Post by: pspeed on April 15, 2012, 09:17:18 AM So I've been programming for some time... and for as long as I have one thing still questions me... How are save files written and read. I've asked alot of people and I can't seem to get a straight answer. so maybe one of you or Paul knows... How does a game like Minecraft or Terreria store it's world data... I know it isn't binary since I've opened it plenty of times and found nothing :( It _IS_ binary. And there are as many types of binary files as there are types of files. Binary files can be viewed with an editor that can deal with binary and then you can see the raw byte values. Every application will store their data a little differently unless they are using a standard format. There are numerous articles on the web on how to read Minecraft chunks so I won't go into that here. If you view the raw bytes then sometimes you can reverse engineer the format... though if the format is compressed it will this difficult. For example, Mythruna run-length encodes its leaf data and I think I remember hearing that Minecraft gzips its chunks. (Mythruna will too someday on top of run-length encoding. It already does when sending files over the network but I like that I can dump and read the files from the command line with no special tools... because I know what I'm looking at.) In Unix or Windows with cygwin, there is a command called "dump" which will dump the raw contents of a file as both hex notation and characters. For example, I just dumped a Java .class file and it the beginning looks like: Code: build\classes\mythruna\BlockType.class: Addresses on the left, hex values in the middle, text view on the right. You can see Java's magic number as the first 4 bytes. Hex: CA FE BA BE... "cafe babe". This is a solid leaf file from Mythruna... so the RLE works really well: Code: ..\Mythruna\mythruna.db\node-0x0x0\10x10x0.leaf: The first byte in a leaf file is the format version... hex 2c... or 44 in this case. The next four bytes is the X location of the tile in "big endian" format. Then Y, then Z. Then you get the generation level as 4 bytes. Then the file version, and the branch number, both of those are 8 bytes each. X: 00 00 01 40 Y: 00 00 01 40 Z: 00 00 00 00 Generation level: 00 00 00 00 Version: 00 00 00 00 00 00 00 00 Branch: 00 00 00 00 00 00 00 00 Lit: 01 Empty cell count: 00 00 00 00 Solid cell count: 00 00 80 00 (32768... all cells filled) Cell data size: 00 00 00 06 (6 bytes) Light data size: 00 00 00 06 Then 6 bytes of block types and 6 bytes of light data. Since these are run-length encoded, a solid block (solid stone in this case since it is at the bottom of the world) is really short. Those 6 bytes in the first case... first two bytes indicate that there are 32767 (the top bit is the flag that indicates that this is a size and not data) the next two bytes is the type of block... 00 04 or stone. Then there is one more block (to make the full 32768 blocks). If you are curious, this is what the code to write a .leaf header looks like: Code: public void write( LeafInfo info, OutputStream out ) throws IOException The code that writes the data part of the file doesn't make as good an example because of the RLE. Title: Re: Programming question Post by: randomprofile on April 15, 2012, 05:10:07 PM Well... I was assuming something like this... but it's still way over my head...
Title: Re: Programming question Post by: pspeed on April 15, 2012, 05:21:49 PM Well... I was assuming something like this... but it's still way over my head... What language do you normally program in? Title: Re: Programming question Post by: randomprofile on April 15, 2012, 09:12:49 PM My favorite "language" isn't really a programming language but more of a scripting language. AU3 or autoit. I enjoy it's syntax, it's really powerful for a scripting language, it can do enough to satisfy me... I prefer it over C++
|