Beispiel #1
0
 private static unsafe Chunk HandleMver(ChunkHeader* header)
 {
     var mver = new MverChunk(header);
     if (mver.Version != Version)
         throw new WmoVersionException(Version, mver.Version);
     return mver;
 }
        internal unsafe StringReferenceChunk(ChunkHeader* header)
            : base(header)
        {
            var begin = (byte*)ChunkHeader.ChunkBegin(header);
            var end = begin + header->Size;
            var curBegin = begin;
            var cur = begin;
            Strings = new List<StringReference>();

            while(cur < end)
            {
                if (*cur == 0)
                {
                    var length = (int)(cur - curBegin);
                    if (length > 0)
                    {
                        Strings.Add(new StringReference
                        {
                            String = Marshal.PtrToStringAnsi((IntPtr)curBegin, length),
                            Offset = (int)(curBegin - begin)
                        });
                    }
                    curBegin = cur + 1;
                }
                cur++;
            }
        }
Beispiel #3
0
 internal unsafe MohdChunk(ChunkHeader* header)
     : base(header)
 {
     var mohd = (Mohd*)(header + 1);
     Bounds = mohd->bounds;
     GroupCount = mohd->groupCount;
     DoodadCount = mohd->doodadCount;
 }
Beispiel #4
0
        internal unsafe MapChunk(ChunkHeader* header)
            : base(header)
        {
            header->ValidateMagic("MCNK");

            var cur = (byte*)header + sizeof(ChunkHeader);
            ParseMcnkHeader(cur);

            Chunks = ChunkCollector.CreateChunks(cur + sizeof(McnkHeader), cur + header->Size, CreateChunks);
        }
Beispiel #5
0
        internal unsafe OffsetChunk(ChunkHeader* header)
            : base(header)
        {
            Offsets = new int[header->Size/sizeof(int)];
            var cur = (int*)ChunkHeader.ChunkBegin(header);

            for (var i = 0; i < Offsets.Length; i++)
            {
                Offsets[i] = *cur++;
            }
        }
Beispiel #6
0
 internal unsafe MliqChunk(ChunkHeader* header)
     : base(header)
 {
     var mliq = (Mliq*)ChunkHeader.ChunkBegin(header);
     Position = mliq->position;
     var entries = (HeightMapEntry*)(mliq + 1);
     var columns = mliq->vertexColumns;
     var rows = mliq->vertexRows;
     ParseHeightMap(entries, columns, rows);
     var flags = (byte*)(entries + columns*rows);
     ParseExistsTable(flags, columns - 1, rows - 1);
 }
Beispiel #7
0
 internal unsafe McvtChunk(ChunkHeader* header)
     : base(header)
 {
     header->ValidateMagic("MCVT");
     HeightMap = new float[NonDetailVertices, NonDetailVertices];
     var values = (float*)((byte*)header + sizeof(ChunkHeader));
     for (int r = 0; r < NonDetailVertices; r++)
     {
         for (int c = 0; c < NonDetailVertices; c++)
         {
             HeightMap[r, c] = values[r * ColumnsPerRow + c];
         }
     }
 }
Beispiel #8
0
 private unsafe Chunk CreateChunk(ChunkHeader* header)
 {
     switch (header->Magic)
     {
         case "MPHD":
             var mphd = new MphdChunk(header);
             Flags = mphd.Flags;
             return mphd;
         case "MAIN":
             _main = new MainChunk(header);
             return _main;
         case "MWMO":
             return new StringReferenceChunk(header);
         case "MODF":
             return new ModfChunk(header);
         default:
             return new Chunk(header);
     }
 }
Beispiel #9
0
 private unsafe Chunk CreateChunks(ChunkHeader* header)
 {
     switch (header->Magic)
     {
         case "MCVT":
             var mcvt = new McvtChunk(header);
             HeightMap = mcvt.HeightMap;
             _bounds.Maximum.Z += HeightMap.Cast<float>().Max();
             return mcvt;
         case "MCRD":
             var mcrd = new OffsetChunk(header);
             DoodadReferences = mcrd.Offsets;
             return mcrd;
         case "MCRW":
             var mcrw = new OffsetChunk(header);
             WmoReferences = mcrw.Offsets;
             return mcrw;
         default:
             return new Chunk(header);
     }
 }
Beispiel #10
0
 internal unsafe ModfChunk(ChunkHeader* header) : base(header)
 {
     var begin = (byte*)ChunkHeader.ChunkBegin(header);
     var end = begin + header->Size;
     Definitions = new List<IModelDefinition>(header->Size / sizeof(ModfEntry));
     
     for (var entry = (ModfEntry*)begin; entry < end; entry++)
     {
         Definitions.Add(new RootModelDefinition
         {
             Id = entry->uniqueId,
             ReferenceIndex = entry->mwidEntry,
             Position = new Vector3(
                 MapOriginOffset - entry->position.Z,
                 MapOriginOffset - entry->position.X,
                 entry->position.Y
             ),
             Rotation = entry->rotation,
             Scale = 1.0f,
             ExtraDoodadSetIndex = entry->doodadSet,
             Flags = entry->flags
         });
     }
 }
 internal unsafe ModelDefinitionChunk(ChunkHeader* header)
     : base(header)
 {
 }
Beispiel #12
0
 internal unsafe ModdChunk(ChunkHeader* header)
     : base(header)
 {
     ParseDefinitions((Modd*)ChunkHeader.ChunkBegin(header), header->Size/sizeof(Modd));
 }
Beispiel #13
0
 private unsafe Chunk HandleModd(ChunkHeader* header)
 {
     var modd = new ModdChunk(header);
     DoodadDefinitions = modd.Definitions;
     return modd;
 }
Beispiel #14
0
 internal unsafe ModsChunk(ChunkHeader* header)
     : base(header)
 {
     ParseSets((Mods*)ChunkHeader.ChunkBegin(header), header->Size / sizeof(Mods));
 }
Beispiel #15
0
 internal unsafe Chunk(ChunkHeader* header)
 {
     Magic = header->Magic;
     Size = header->Size;
 }
Beispiel #16
0
 private unsafe Chunk HandleMh2o(ChunkHeader* header)
 {
     _mh2o = new Mh2oChunk(header);
     return _mh2o;
 }
Beispiel #17
0
 private unsafe Chunk HandleModf(ChunkHeader* header)
 {
     _modf = new ModfChunk(header);
     WmoDefinitions = _modf.Definitions;
     return _modf;
 }
Beispiel #18
0
 private unsafe Chunk HandleMcnk(ChunkHeader* header)
 {
     var chunk = new MapChunk(header);
     MapChunks.Add(chunk);
     return chunk;
 }
Beispiel #19
0
 private unsafe Chunk CreateChunk(ChunkHeader* header)
 {
     switch (header->Magic)
     {
         case "MVER":
             return HandleMver(header);
         case "MH2O":
             return HandleMh2o(header);
         case "MCNK":
             return HandleMcnk(header);
         default:
             return new Chunk(header);
     }
 }
Beispiel #20
0
 private unsafe Chunk CreateChunk(ChunkHeader* header)
 {
     switch (header->Magic)
     {
         case "MVER":
             return HandleMver(header);
         case "MOHD":
             return _mohd = new MohdChunk(header);
         case "MODS":
             return HandleMods(header);
         case "MODN":
             return HandleModn(header);
         case "MODD":
             return HandleModd(header);
         default:
             return new Chunk(header);
     }
 }
Beispiel #21
0
 private unsafe Chunk HandleModn(ChunkHeader* header)
 {
     var modn = new StringReferenceChunk(header);
     DoodadReferences = modn.Strings;
     return modn;
 }
Beispiel #22
0
 private unsafe Chunk HandleMods(ChunkHeader* header)
 {
     var mods = new ModsChunk(header);
     DoodadSets = mods.DoodadSets;
     return mods;
 }
Beispiel #23
0
        private unsafe Chunk ExtendChunk(ChunkHeader* header)
        {
            if (header->Size == 0) return null;

            switch (header->Magic)
            {
                case "MVER":
                    HandleMver(header);
                    return null;
                case "MH2O":
                    return null;
                case "MCNK":
                    MapChunks[_mcnkCounter++].ParseOptionalData(header);
                    return null;
                case "MWID":
                    return new OffsetChunk(header);
                case "MMID":
                    return new OffsetChunk(header);
                case "MMDX":
                    return HandleMmdx(header);
                case "MWMO":
                    return HandleMwmo(header);
                case "MDDF":
                    return HandleMddf(header);
                case "MODF":
                    return HandleModf(header);
                default:
                    return new Chunk(header);
            }
        }
Beispiel #24
0
 internal unsafe MainChunk(ChunkHeader* header)
     : base(header)
 {
     ParseFlags((SMAreaInfo*)ChunkHeader.ChunkBegin(header));
 }
Beispiel #25
0
 private unsafe Chunk HandleMddf(ChunkHeader* header)
 {
     _mddf = new MddfChunk(header);
     DoodadDefinitions = _mddf.Definitions;
     return _mddf;
 }
Beispiel #26
0
 internal unsafe MovtChunk(ChunkHeader* header)
     : base(header)
 {
     ParseVertices((Vector3*)ChunkHeader.ChunkBegin(header), header->Size/sizeof(Vector3));
 }
Beispiel #27
0
 private unsafe Chunk HandleMmdx(ChunkHeader* header)
 {
     _mmdx = new StringReferenceChunk(header);
     DoodadReferences = _mmdx.Strings;
     return _mmdx;
 }
Beispiel #28
0
 internal unsafe MverChunk(ChunkHeader* header)
     : base(header)
 {
     Version = *(int*)(header + 1);
 }
Beispiel #29
0
 private unsafe Chunk HandleMwmo(ChunkHeader* header)
 {
     _mwmo = new StringReferenceChunk(header);
     WmoReferences = _mwmo.Strings;
     return _mwmo;
 }
Beispiel #30
0
 private unsafe Chunk HandleMogp(ChunkHeader* header)
 {
     _mogp = new MogpChunk(header);
     TriangleFlags = _mogp.TriangleFlags;
     Vertices = _mogp.Vertices;
     Triangles = _mogp.Triangles;
     Liquid = _mogp.Liquid;
     return _mogp;
 }