Пример #1
0
        bool IPackageLoader.TryParsePackage(Stream s, string filename, FS context, out IReadOnlyPackage package)
        {
            if (!filename.EndsWith(".bag", StringComparison.InvariantCultureIgnoreCase))
            {
                package = null;
                return(false);
            }

            // A bag file is always accompanied with an .idx counterpart
            // For example: audio.bag requires the audio.idx file
            var             indexFilename = Path.ChangeExtension(filename, ".idx");
            List <IdxEntry> entries       = null;

            try
            {
                // Build the index and dispose the stream, it is no longer needed after this
                using (var indexStream = context.Open(indexFilename))
                    entries = new IdxReader(indexStream).Entries;
            }
            catch
            {
                package = null;
                return(false);
            }

            package = new BagFile(s, entries, filename);
            return(true);
        }
Пример #2
0
        bool IPackageLoader.TryParsePackage(Stream s, string filename, FS context, out IReadOnlyPackage package)
        {
            if (!filename.EndsWith(".pak", StringComparison.InvariantCultureIgnoreCase))
            {
                package = null;
                return(false);
            }

            package = new PakFile(s, filename);
            return(true);
        }
Пример #3
0
        bool IPackageLoader.TryParsePackage(Stream s, string filename, FS context, out IReadOnlyPackage package)
        {
            // Take a peek at the file signature
            var signature = s.ReadASCII(4);

            s.Position -= 4;

            if (signature != "BIGF")
            {
                package = null;
                return(false);
            }

            package = new BigFile(s, filename);
            return(true);
        }
Пример #4
0
            public IReadOnlyPackage OpenPackage(string filename, FS context)
            {
                IReadOnlyPackage package;
                var childStream = GetStream(filename);

                if (childStream == null)
                {
                    return(null);
                }

                if (context.TryParsePackage(childStream, filename, out package))
                {
                    return(package);
                }

                childStream.Dispose();
                return(null);
            }
Пример #5
0
        bool IPackageLoader.TryParsePackage(Stream s, string filename, FS context, out IReadOnlyPackage package)
        {
            if (!filename.EndsWith(".mix", StringComparison.InvariantCultureIgnoreCase))
            {
                package = null;
                return(false);
            }

            // Load the global mix database
            Stream mixDatabase;
            var    allPossibleFilenames = new HashSet <string>();

            if (context.TryOpen("global mix database.dat", out mixDatabase))
            {
                using (var db = new XccGlobalDatabase(mixDatabase))
                    foreach (var e in db.Entries)
                    {
                        allPossibleFilenames.Add(e);
                    }
            }

            package = new MixFile(s, filename, allPossibleFilenames);
            return(true);
        }
Пример #6
0
 public IReadOnlyPackage OpenPackage(string filename, FS context)
 {
     // Not implemented
     return(null);
 }
Пример #7
0
        public ModData(Manifest mod, InstalledMods mods, bool useLoadScreen = false)
        {
            Languages = new string[0];

            //local copy of the manifest
            Manifest       = new Manifest(mod.Id, mod.Package);
            ObjectCreator  = new ObjectCreator(Manifest, mods);
            PackageLoaders = ObjectCreator.GetLoaders <IPackageLoader>(Manifest.PackageFormats, "package");
            ModFiles       = new FileSystem.FileSystem(mods, PackageLoaders);
            ModFiles.LoadFromManifest(Manifest);
            Manifest.LoadCustomData(ObjectCreator);
            if (useLoadScreen)
            {
                LoadScreen = ObjectCreator.CreateObject <ILoadScreen>(Manifest.LoadScreen.Value);
                LoadScreen.Init(this, Manifest.LoadScreen.ToDictionary(my => my.Value));
                LoadScreen.Display();
            }

            WidgetLoader = new WidgetLoader(this);
            MapCache     = new MapCache(this);

            SoundLoaders  = ObjectCreator.GetLoaders <ISoundLoader>(Manifest.SoundFormats, "sound");
            SpriteLoaders = ObjectCreator.GetLoaders <ISpriteLoader>(Manifest.SpriteFormats, "sprite");

            var sequenceFormat = Manifest.Get <SpriteSequenceFormat>();
            var sequenceLoader = ObjectCreator.FindType(sequenceFormat.Type + "Loader");
            var sequenceCtor   = sequenceLoader != null?sequenceLoader.GetConstructor(new[] { typeof(ModData) }) : null;

            if (sequenceLoader == null || !sequenceLoader.GetInterfaces().Contains(typeof(ISpriteSequenceLoader)) || sequenceCtor == null)
            {
                throw new InvalidOperationException("Unable to find a sequence loader for type '{0}'.".F(sequenceFormat.Type));
            }
            SpriteSequenceLoader = (ISpriteSequenceLoader)sequenceCtor.Invoke(new[] { this });
            SpriteSequenceLoader.OnMissingSpriteError = s => { Console.WriteLine(s); };

            var modelFormat = Manifest.Get <ModelSequenceFormat>();
            var modelLoader = ObjectCreator.FindType(modelFormat.Type + "Loader");
            var modelCtor   = modelLoader != null?modelLoader.GetConstructor(new[] { typeof(ModData) }) : null;

            if (modelCtor == null || !modelLoader.GetInterfaces().Contains(typeof(IModelSequenceLoader)) || modelCtor == null)
            {
                throw new InvalidOperationException("Unable to find a model loader for type '{0}'".F(modelFormat.Type));
            }



            ModelSequenceLoader = (IModelSequenceLoader)modelCtor.Invoke(new[] { this });
            ModelSequenceLoader.OnMissingModelError = s => { };

            defaultRules = Exts.Lazy(() => Ruleset.LoadDefaults(this));

            //地形贴片集
            defaultTileSets = Exts.Lazy(() =>
            {
                var items = new Dictionary <string, TileSet>();
                foreach (var file in Manifest.TileSets)
                {
                    var t = new TileSet(DefaultFileSystem, file);
                    items.Add(t.Id, t);
                }
                return((IReadOnlyDictionary <string, TileSet>)(new ReadOnlyDictionary <string, TileSet>(items)));
            });

            //序列集
            defaultSequences = Exts.Lazy(() => {
                var items = DefaultTileSets.ToDictionary(t => t.Key, t => new SequenceProvider(DefaultFileSystem, this, t.Value, null));
                return((IReadOnlyDictionary <string, SequenceProvider>)(new ReadOnlyDictionary <string, SequenceProvider>(items)));
            });

            initialThreadId = System.Threading.Thread.CurrentThread.ManagedThreadId;
        }