Ejemplo n.º 1
0
    public object LoadAsset(AssetInfo info, AssetMapping mapping, IDictionary <string, string> extraPaths, TextWriter annotationWriter = null)
    {
        if (info == null)
        {
            throw new ArgumentNullException(nameof(info));
        }
        if (extraPaths == null)
        {
            throw new ArgumentNullException(nameof(extraPaths));
        }
        var generalConfig = Resolve <IGeneralConfig>();
        var jsonUtil      = Resolve <IJsonUtil>();

        using ISerializer s = Search(generalConfig, info, extraPaths, annotationWriter);
        if (s == null)
        {
            return(null);
        }

        if (s.BytesRemaining == 0) // Happens all the time when dumping, just return rather than throw to preserve perf.
        {
            return(new AssetNotFoundException($"Asset for {info.AssetId} found but size was 0 bytes.", info.AssetId));
        }

        var loader = _assetLoaderRegistry.GetLoader(info.File.Loader);

        if (loader == null)
        {
            throw new InvalidOperationException($"Could not instantiate loader \"{info.File.Loader}\" required by asset {info.AssetId}");
        }

        return(loader.Serdes(null, info, mapping, s, jsonUtil));
    }
Ejemplo n.º 2
0
        public object LoadAsset(AssetId key, SerializationContext context, Func <AssetId, SerializationContext, object> loaderFunc)
        {
            if (loaderFunc == null)
            {
                throw new ArgumentNullException(nameof(loaderFunc));
            }
            var generalConfig = (IGeneralConfig)loaderFunc(new AssetId(AssetType.GeneralConfig), context);
            var filename      = Path.Combine(generalConfig.BasePath, generalConfig.SavePath, $"SAVE.{key.Id:D3}");

            var loader = _assetLoaderRegistry.GetLoader <SavedGame>(FileFormat.SavedGame);

            using var stream = disk.OpenRead(filename);
            using var br     = new BinaryReader(stream);
            return(loader.Serdes(
                       null,
                       context.Mapping,
                       new AlbionReader(br, stream.Length), key, null));
        }
Ejemplo n.º 3
0
        object TryLoad(string dir, IGeneralConfig generalConfig, AssetInfo info, SerializationContext context)
        {
            using var s = Search(dir, generalConfig, info);
            if (s == null)
            {
                return(null);
            }

            if (s.BytesRemaining == 0) // Happens all the time when dumping, just return rather than throw to preserve perf.
            {
                return(new AssetNotFoundException($"Asset for {info.AssetId} found but size was 0 bytes.", info.AssetId));
            }

            var loader = _assetLoaderRegistry.GetLoader(info.File.Loader);

            if (loader == null)
            {
                throw new InvalidOperationException($"No loader for file type \"{info.File.Loader}\" required by asset {info.Name}");
            }

            return(loader.Serdes(null, info, context.Mapping, s));
        }