Exemple #1
0
        private unsafe int ReadData(byte *buf, int bufSize)
        {
            if (string.IsNullOrWhiteSpace(DataFileName))
            {
                DataFileName = Path.Combine(Memory.FF8DIRdata, "Sound", "audio.dat");
            }

            bufSize = Math.Min(bufSize, (int)DataSize);

            if (bufSize == 0)
            {
                return(ffmpeg.AVERROR_EOF);
            }
            Stream     s;
            ArchiveZzz other;

            switch (Target)
            {
            case TargetFile.SoundDat:
                if (File.Exists(DataFileName))
                {
                    s = new FileStream(DataFileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
                }
                else
                {
                    other = (ArchiveZzz)ArchiveZzz.Load(Memory.Archives.ZZZ_OTHER);
                    s     = new MemoryStream(other.GetBinaryFile("audio.dat", true), false);
                }
                break;

            case TargetFile.OtherZzz:
                other = (ArchiveZzz)ArchiveZzz.Load(Memory.Archives.ZZZ_OTHER);
                s     = other.OpenStream();
                break;

            default:
                throw new ArgumentOutOfRangeException(
                          $"{nameof(BufferData)}::{nameof(ReadData)}::{nameof(Target)} Value out of range! Target = {{{Target}}}");
            }

            // binaryReader disposes of fs
            if (s == null)
            {
                throw new NullReferenceException($"{nameof(BufferData)}::{nameof(ReadData)} stream is null");
            }
            using (BinaryReader br = new BinaryReader(s))
            {
                s.Seek(DataSeekLoc, SeekOrigin.Begin);
                using (UnmanagedMemoryStream ums = new UnmanagedMemoryStream(buf, bufSize, bufSize, FileAccess.Write))
                {
                    // copy public buffer data to buf
                    ums.Write(br.ReadBytes(bufSize), 0, bufSize);
                    DataSeekLoc    += bufSize;
                    _totalReadData += bufSize;
                    DataSize       -= bufSize;

                    return(bufSize);
                }
            }
        }
Exemple #2
0
            private Files()
            {
                if (_files != null)
                {
                    return;
                }
                if (Extensions == null)
                {
                    Extensions = new [] { ".avi", ".mkv", ".mp4", ".bik" }
                }
                ;
                ArchiveZzz a = (ArchiveZzz)ArchiveZzz.Load(Memory.Archives.ZZZ_OTHER);

                if (a != null)
                {
                    string[] listOfFiles = a.GetListOfFiles();
                    _files = (from file in listOfFiles
                              from extension in Extensions
                              where file.EndsWith(extension, StringComparison.OrdinalIgnoreCase)
                              orderby Path.GetFileNameWithoutExtension(file)
                              select file).ToList();
                    Zzz = true;
                }
                else
                {
                    //Gather all movie files.
                    Directories d = Directories.Instance;
                    _files = (from directory in d
                              where Directory.Exists(directory)
                              from file in Directory.GetFiles(directory, "*", SearchOption.AllDirectories)
                              from extension in Extensions
                              where file.EndsWith(extension, StringComparison.OrdinalIgnoreCase)
                              orderby Path.GetFileNameWithoutExtension(file)
                              select file).ToList();
                }

                //Remove duplicate movies ignoring extension that have same name.
                (from s1 in _files.Select((value, key) => new { Key = key, Value = value })
                 from s2 in _files.Select((value, key) => new { Key = key, Value = value })
                 where s1?.Value != null
                 where s2?.Value != null
                 where s1.Key < s2.Key
                 where Path.GetFileNameWithoutExtension(s1.Value ?? throw new NullReferenceException($"{nameof(Files)}::{s1} value cannot be null")).Equals(Path.GetFileNameWithoutExtension(s2.Value), StringComparison.OrdinalIgnoreCase)
                 orderby s2.Key descending
                 select s2.Key).ForEach(key => _files.RemoveAt(key));

                foreach (string s in _files)
                {
                    Memory.Log.WriteLine($"{nameof(Movie)} :: {nameof(Files)} :: {s} ");
                }
            }
Exemple #3
0
            public static void Init()
            {
                Memory.Log.WriteLine($"{nameof(Archive)}::{nameof(Init)}");
                Archive parent = new Archive(FF8DIR);

                ZZZ_MAIN  = new Archive("main.zzz", true, parent);
                ZZZ_OTHER = new Archive("other.zzz", true, parent);
                A_BATTLE  = new Archive("battle", FF8DIRdata_lang, ZZZ_MAIN);
                A_FIELD   = new Archive("field", FF8DIRdata_lang, ZZZ_MAIN);
                A_MAGIC   = new Archive("magic", FF8DIRdata_lang, ZZZ_MAIN);
                A_MAIN    = new Archive("main", FF8DIRdata_lang, ZZZ_MAIN);
                A_MENU    = new Archive("menu", FF8DIRdata_lang, ZZZ_MAIN);
                A_WORLD   = new Archive("world", FF8DIRdata_lang, ZZZ_MAIN);
                A_MOVIES  = new Archive("movies", FF8DIRdata_lang, ZZZ_OTHER, FF8DIRdata);

                /*var aw =*/
                ArchiveZzz.Load(ZZZ_MAIN);  //try to load main.zzz also caches it.
                                            //This actually slows things down. I thought it might be a good idea but at least now we know.
                                            //MergeArchiveToZzz(aw); // try to merge all the file maps into the zzz map. Since all the binary data is in there.
                                            /*aw = */
                ArchiveZzz.Load(ZZZ_OTHER); //try to load other.zzz also caches it.
            }
Exemple #4
0
        public static void Init()
        {
            Memory.Log.WriteLine($"{nameof(Music)} :: {nameof(Init)}");
            // PC 2000 version has an CD audio track for eyes on me. I don't think we can play that.
            const MusicId unkPrefix         = (MusicId)999;
            const MusicId altLoserPrefix    = (MusicId)512;
            const MusicId loserPrefix       = (MusicId)0;
            const MusicId eyesOnMePrefix    = (MusicId)513;
            const MusicId altEyesOnMePrefix = (MusicId)22;

            string[] ext = { ".ogg", ".sgt", ".wav", ".mp3" };
            //Roses and Wine V07 moves most of the sgt files to dmusic_backup
            //it leaves a few files behind. I think because RaW doesn't replace everything.
            //ogg files stored in:
            string RaW_ogg_pt = Extended.GetUnixFullPath(Path.Combine(Memory.FF8DIR, "RaW", "GLOBAL", "Music"));
            // From what I gather the OGG files and the sgt files have the same numerical prefix. I
            // might try to add the functionality to the debug screen monday.

            string dmusic_pt    = Extended.GetUnixFullPath(Path.Combine(Memory.FF8DIRdata, "Music", "dmusic_backup"));
            string music_pt     = Extended.GetUnixFullPath(Path.Combine(Memory.FF8DIRdata, "Music", "dmusic"));
            string music_wav_pt = Extended.GetUnixFullPath(Path.Combine(Memory.FF8DIRdata, "Music"));

            // goal of dicmusic is to be able to select a track by prefix. it adds an list of files
            // with the same prefix. so you can later on switch out which one you want.
            AddMusicPath(RaW_ogg_pt);
            AddMusicPath(music_wav_pt);
            AddMusicPath(dmusic_pt);
            AddMusicPath(music_pt);
            if (!Memory.dicMusic.ContainsKey(eyesOnMePrefix) && Memory.dicMusic.ContainsKey(altEyesOnMePrefix))
            {
                Memory.dicMusic.Add(eyesOnMePrefix, Memory.dicMusic[altEyesOnMePrefix]);
            }
            ArchiveBase a = ArchiveZzz.Load(Memory.Archives.ZZZ_OTHER);

            string[] list = a?.GetListOfFiles();
            if (list != null && list.Length > 0)
            {
                ZZZ = true;
                foreach (string m in list.Where(x => ext.Any(y => x.EndsWith(y, StringComparison.OrdinalIgnoreCase))))
                {
                    AddMusic(m);
                }
            }
            void AddMusicPath(string p)
            {
                if (!string.IsNullOrWhiteSpace(p) && Directory.Exists(p))
                {
                    foreach (string m in Directory.GetFiles(p).Where(x => ext.Any(y => x.EndsWith(y, StringComparison.OrdinalIgnoreCase))))
                    {
                        AddMusic(m);
                    }
                }
            }

            void AddMusic(string m)
            {
                if (ushort.TryParse(Path.GetFileName(m).Substring(0, 3), out ushort key))
                {
                    //mismatched prefix's go here
                    if ((MusicId)key == altLoserPrefix)
                    {
                        key = (ushort)loserPrefix; //loser.ogg and sgt don't match.
                    }
                }
                else if (m.IndexOf("eyes_on_me", StringComparison.OrdinalIgnoreCase) >= 0)
                {
                    key = (ushort)eyesOnMePrefix;
                }
                else
                {
                    key = (ushort)unkPrefix;
                }

                if (!Memory.dicMusic.ContainsKey((MusicId)key))
                {
                    Memory.dicMusic.Add((MusicId)key, new List <string> {
                        m
                    });
                }
                else
                {
                    Memory.dicMusic[(MusicId)key].Add(m);
                }
            }
        }