Drake53 / War3Net

A .NET implementation of Warcraft III related libraries.
MIT License
123 stars 27 forks source link

MapBuilder method 'AddFiles' fails to add files correctly. #40

Closed TheLazzoro closed 1 year ago

TheLazzoro commented 1 year ago

Firstly, this is not an issue when adding files from folder mode maps. This happens when adding files to the builder from a 'MpqArchive' like this:

var map = Map.Open(mapDir);
MapBuilder builder = new MapBuilder(map);
using (Stream s = new FileStream(mapDir, FileMode.Open))
{
    MpqArchive mpq = new MpqArchive(s);
    builder.AddFiles(mpq);
}

I don't know if this is the correct way to do it but I'm sort of stuck. I end up with green textures in most cases, but as you can see the bottom 'action bar' texture loads fine:

img

This doesn't seem to be exclusive to the file type, because all imported textures in this image are .tga files (don't judge, old map), while the loading screen is .dds which is also not present when loading. The output mpq also has hundreds of 'File000xxxx'.

I uploaded the map in question in case you want to test this: https://www.hiveworkshop.com/pastebin/2e34e565526802985f40f7c11146406d.27177

Drake53 commented 1 year ago

The issue is that you're adding MpqFiles to a new archive without their filenames. The way the library handles mpqfiles with unknown filenames could use improvements but basically the new archive has a larger hashtable (my lib defaults to filecount 8 or smth while world editor is more like 2), and to compensate it adds x entries per file to the hashtable (where x is the hashtable size multiplication, usually 4). The solution is simple, set loadListfile to true when opening the MpqArchive. Some notes about your code: