Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ADT does not handle offsets correctly #14

Open
wachag opened this issue Apr 18, 2022 · 8 comments
Open

ADT does not handle offsets correctly #14

wachag opened this issue Apr 18, 2022 · 8 comments

Comments

@wachag
Copy link

wachag commented Apr 18, 2022

When an ADT file is parsed, this call throws an invalid chunk exception, failing to load ADT

MapChunkOffsets = br.ReadIFFChunk<TerrainMapChunkOffsets>();

@Nihlus
Copy link
Collaborator

Nihlus commented Apr 18, 2022

This library is pretty much on ice at the moment; I don't have time to actively maintain and develop it. It needs a lot of updates and modernization, and I'm afraid I won't be able to take care of this issue any time soon :(

@maltesermailo
Copy link

To comment on this, ADT Offsets are relative to their reading location in MHDR, which in case map chunk offsets in each ADT File is 0x14. Easy way to fix this would be to just get the current position in the reader and add the offset to it, thereby fixing this problem.

I mean, most people of us are probably gonna use this to edit ADT and WDT files rather than the rest, so if someone could throw in a Push-Request, that would fix it.(I can't do it since I can't compile the library without some modifications(Disabling FxCopAnalyzer, idk what is happening there))

@wachag
Copy link
Author

wachag commented Apr 26, 2022

I already have it fixed on my side, + 8 offset is required for current chunk offset.
Unfortunately, I have other issues with mcnk too, I want to fix them before a PR

@maltesermailo
Copy link

@wachag +8 can't be the offset. It was +20 for most ADT files I tested. Might be different across several versions in which case, you'd have to use my approach by reading the start of the MHDR section(After the signature and size parameter, but before the Flags since thats data) and saving that location.

@wachag
Copy link
Author

wachag commented Apr 27, 2022

It is:

'''
Works like this:

        // In all ADT files, the version chunk and header chunk are at the beginning of the file,
        // with the header following the version. From them, the rest of the chunks can be
        // seeked to and read.

        // Read Version Chunk
        Version = br.ReadIFFChunk<TerrainVersion>();
        long globalOffset = br.BaseStream.Position + 8;
        // Read the header chunk
        Header = br.ReadIFFChunk<TerrainHeader>();

        if (Header.MapChunkOffsetsOffset > 0)
        {
            br.BaseStream.Position = globalOffset + Header.MapChunkOffsetsOffset;
            MapChunkOffsets = br.ReadIFFChunk<TerrainMapChunkOffsets>();
        }

'''

@wachag
Copy link
Author

wachag commented Apr 27, 2022

Of course, I am relative to the MHDR, +8 is because how the chunk reading is organized in the lib

@wachag
Copy link
Author

wachag commented Apr 28, 2022

For similar reasons, from MCNK offsets we need to subtract 8.
Baked shadow chunks have a bit of an issue too, fixing those too.

@wachag
Copy link
Author

wachag commented Apr 28, 2022

In MapChunkHeader.cs these are incorrectly read (stream position will be wrong after these):
LowResTextureMap = br.ReadUInt16();
PredTex = br.ReadUInt32();
NoEffectDoodad = br.ReadUInt32();

https://wowdev.wiki/ADT/v18#MCNK_chunk

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants