flowtsohg / mdx-m3-viewer

A WebGL viewer for MDX and M3 files used by the games Warcraft 3 and Starcraft 2 respectively.
MIT License
132 stars 47 forks source link

how can use War3Map make extract w3x file to a dir? #59

Closed qq1053831109 closed 3 years ago

qq1053831109 commented 3 years ago

how can use War3Map make extract w3x file to a dir?

flowtsohg commented 3 years ago

Typically if you are talking about a standard map that wasn't optimized/protected, you can loop over all of the internal files, get their buffers, and from there you are free to do whatever you want.

E.g.:

for (let name of map.getFileNames()) {
    let file = map.get(name);
    let buffer = file.arrayBuffer(); // an ArrayBuffer

    // Node
    fs.appendFile(name, Buffer.from(buffer));

    // Browser, e.g. file-saver on npm
    saveAs(new Blob([buffer], { type: 'application/octet-stream' }), name);
}

There's also getImportNames() if you only care about imports.

If the map is a modified one and, for instance, it lacks a listfile, the above would probably miss all files (I admit I don't remember everything about the MPQ code since I wrote it ages ago). If this situation is relevant to you and you still want to extract everything, I can add something, or show you how to do it.