Beispiel #1
0
        private static bool LoadFixedSoundInfos(ChunkReader chunkIO, ChunkId idOuter, Wad2 wad, Dictionary <long, WadSoundInfo> soundInfos)
        {
            if (idOuter != Wad2Chunks.FixedSoundInfos)
            {
                return(false);
            }

            var fixedSoundInfos = new SortedList <WadFixedSoundInfoId, WadFixedSoundInfo>();

            chunkIO.ReadChunks((id, chunkSize) =>
            {
                if (id != Wad2Chunks.FixedSoundInfo)
                {
                    return(false);
                }
                int soundId     = -1;
                int SoundInfoId = -1;
                chunkIO.ReadChunks((id2, chunkSize2) =>
                {
                    if (id2 == Wad2Chunks.FixedSoundInfoId)
                    {
                        soundId = chunkIO.ReadChunkInt(chunkSize2);
                    }
                    else if (id2 == Wad2Chunks.FixedSoundInfoSoundInfoId)
                    {
                        SoundInfoId = chunkIO.ReadChunkInt(chunkSize2);
                    }
                    else
                    {
                        return(false);
                    }
                    return(true);
                });
                if (soundId == -1 || SoundInfoId == -1)
                {
                    throw new Exception("Invalid fixed sound info.");
                }

                var Id = new WadFixedSoundInfoId(checked ((uint)soundId));
                fixedSoundInfos.Add(Id, new WadFixedSoundInfo(Id)
                {
                    SoundInfo = soundInfos[SoundInfoId]
                });
                return(true);
            });

            wad.FixedSoundInfosObsolete = fixedSoundInfos;
            return(true);
        }
Beispiel #2
0
 public WadFixedSoundInfo(WadFixedSoundInfoId id)
 {
     Id = id;
 }
Beispiel #3
0
        private static Wad2 LoadWad2(ChunkReader chunkIO, bool obsolete)
        {
            if (obsolete)
            {
                LEB128.ReadUInt(chunkIO.Raw);
            }
            var wad = new Wad2();

            Dictionary <long, WadTexture>   textures   = null;
            Dictionary <long, WadSample>    samples    = null;
            Dictionary <long, WadSoundInfo> soundInfos = null;
            Dictionary <long, WadSprite>    sprites    = null;

            wad.SoundSystem = SoundSystem.Dynamic;

            chunkIO.ReadChunks((id, chunkSize) =>
            {
                if (id == Wad2Chunks.GameVersion)
                {
                    wad.GameVersion = (TRVersion.Game)chunkIO.ReadChunkLong(chunkSize);
                    return(true);
                }
                else if (id == Wad2Chunks.SoundSystem)
                {
                    wad.SoundSystem = (SoundSystem)chunkIO.ReadChunkLong(chunkSize);
                    return(true);
                }
                else if (LoadTextures(chunkIO, id, wad, ref textures))
                {
                    return(true);
                }
                else if (LoadSamples(chunkIO, id, wad, ref samples, obsolete))
                {
                    return(true);
                }
                else if (LoadSoundInfos(chunkIO, id, wad, ref soundInfos, samples))
                {
                    return(true);
                }
                else if (LoadFixedSoundInfos(chunkIO, id, wad, soundInfos))
                {
                    return(true);
                }
                else if (LoadAdditionalSoundInfos(chunkIO, id, wad, soundInfos, samples))
                {
                    return(true);
                }
                else if (LoadSprites(chunkIO, id, wad, ref sprites))
                {
                    return(true);
                }
                else if (LoadSpriteSequences(chunkIO, id, wad, sprites))
                {
                    return(true);
                }
                else if (LoadMoveables(chunkIO, id, wad, soundInfos, textures))
                {
                    return(true);
                }
                else if (LoadStatics(chunkIO, id, wad, textures))
                {
                    return(true);
                }
                return(false);
            });

            if (obsolete)
            {
                foreach (KeyValuePair <long, WadSoundInfo> soundInfo in soundInfos)
                {
                    if (TrCatalog.IsSoundFixedByDefault(TRVersion.Game.TR4, checked ((uint)soundInfo.Key)))
                    {
                        var Id = new WadFixedSoundInfoId(checked ((uint)soundInfo.Key));
                        wad.FixedSoundInfosObsolete.Add(Id, new WadFixedSoundInfo(Id)
                        {
                            SoundInfo = soundInfo.Value
                        });
                    }
                }
            }

            // XML_SOUND_SYSTEM: Used for conversion of Wad2 to new sound system
            wad.AllLoadedSoundInfos = soundInfos;

            // Force wad to be xml wad in case there's no sound infos at all
            if (wad.SoundSystem != SoundSystem.Xml && wad.AllLoadedSoundInfos?.Count == 0)
            {
                wad.SoundSystem = SoundSystem.Xml;
            }

            return(wad);
        }