• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!

WTGUtils - Reading and Writing WTG Files

Status
Not open for further replies.

EdgeOfChaos

E

EdgeOfChaos

This is a project I've been doing to modify wtg files. It's in Java.
There's no "runnable" part of it yet, so it won't have any interest to non-programmers yet. But the implications are huge. If we have a WTG writer, we are one step closer to being able to make our own World Editor completely external to Blizzard's. If there is sufficient interest, I will also create utils for the rest of the world editor files that are not already done, like war3map.doo.
Currently I'm only focusing on the reading bit, but once this is working it would not be significantly more work to add writing.

Github repo: GitHub - griggszm/WTGUtils: Utility for .w3g file read/write
Feel free to clone it down and look at it, or contribute if you so care to.
WTG reading is almost working, I believe..
 

EdgeOfChaos

E

EdgeOfChaos

I never knew about a binary reader, but it doesn't look any better than my current method. Almost everyone I've found recommends reading into a byte array. And either way you're going to be doing byte operations. This sort of detail can be switched out anytime later if we want to.

Anyways using this way, there is one IO operation at the beginning to read a byte array, then the file is released. The other way, the file would be in use all the time.
 
Level 29
Joined
Jul 29, 2007
Messages
5,174
A binary reader doesn't have to act on a file, it can work with a buffer of bytes exactly like you do, but it does it natively without you needing to redefine the size of a 4 byte inetger (it's 4).
Maybe Java doesn't have any nice binary reader, I don't know. They usually have a pretty simple API, like "getInt32" "getUint32" etc.

Java:
private char readChar(int start) {
     byte[] charBytes = readBytes(start,start+ CHAR_BYTE_LENGTH);
     return byteArrayToChar(charBytes);
}

...and the rest, you are going through a whole hoop just to get a few bytes.
 
Last edited:

EdgeOfChaos

E

EdgeOfChaos

I can't find any good binary reader (that does that functionality. All the binary readers I find are for reading into byte array). Besides mine is tested/working, so even if it does define a couple extra constants I don't think it's a big deal.

If someone finds me one that works with my implementation, it would be simple to add it in.
 

EdgeOfChaos

E

EdgeOfChaos

Data Parser implementation has been changed to use ByteBuffer
 

EdgeOfChaos

E

EdgeOfChaos

I haven't started writing yet. Reading is also not yet done, but it's almost there.

I'll add support for other sources after reading's fully functional.
 

EdgeOfChaos

E

EdgeOfChaos

Nice, that's a lot of formats!
The wtg isn't in that wc3libs, because the format was not specified until very recently.
This should be the first utils for wtgs (besides ofc the triggerviewer).
I did ask Ralle for help when I got stuck before and he helped me with the format :p
There are still several things I don't understand about the ROC version, but TFT is reading fine. ROC seems to be reading DoNothing for every single internal loop function, so clearly I'm missing something. All other ROC stuff reads correctly besides loops. Still a WIP though.
 
Last edited by a moderator:
Status
Not open for further replies.
Top