예제 #1
0
        public object LoadAsset(AssetKey key, string name, Func <AssetKey, string, object> loaderFunc)
        {
            if (key.Type == AssetType.CoreSpriteConfig)
            {
                var settings = Resolve <ISettings>();
                return(CoreSpriteConfig.Load(settings.BasePath));
            }

            var generalConfig    = (GeneralConfig)loaderFunc(new AssetKey(AssetType.GeneralConfig), "GeneralConfig");
            var coreSpriteConfig = (CoreSpriteConfig)loaderFunc(new AssetKey(AssetType.CoreSpriteConfig), "CoreSpriteConfig");

            var exePath = Path.Combine(generalConfig.BasePath, generalConfig.ExePath);

            if (key.Type == AssetType.CoreGraphics)
            {
                return(CoreSpriteLoader.Load((CoreSpriteId)key.Id, exePath, coreSpriteConfig));
            }

            if (key.Type == AssetType.CoreGraphicsMetadata)
            {
                return(CoreSpriteLoader.GetConfig((CoreSpriteId)key.Id, exePath, coreSpriteConfig, out _));
            }

            throw new InvalidOperationException("CoreSpriteLocator called with an invalid type");
        }
예제 #2
0
        public static AlbionSprite Load(CoreSpriteId id, string exePath, CoreSpriteConfig config)
        {
            var resource = GetConfig(id, exePath, config, out var file);
            var bytes    = LoadSection(file, resource);

            return(new AlbionSprite
            {
                Name = $"Core.{id}",
                Width = resource.Width,
                Height = resource.Height,
                UniformFrames = true,
                Frames = new[] { new AlbionSprite.Frame(0, 0, resource.Width, resource.Height) },
                PixelData = bytes
            });
        }
예제 #3
0
        static void Main()
        {
            var baseDir     = FormatUtil.FindBasePath();
            var config      = FullAssetConfig.Load(baseDir);
            var outpathPath = Path.Combine(baseDir, @"Formats/AssetIds");
            var xldPattern  = new Regex(@"([0-9]+).XLD$");

            var enums = new Dictionary <string, EnumData>();

            foreach (var xld in config.Xlds.Values)
            {
                if (string.IsNullOrEmpty(xld.EnumName))
                {
                    continue;
                }

                int offset = 0;
                var match  = xldPattern.Match(xld.Name);
                if (match.Success)
                {
                    offset = 100 * int.Parse(match.Groups[1].Value);
                }

                if (!enums.ContainsKey(xld.EnumName))
                {
                    enums[xld.EnumName] = new EnumData {
                        Name = xld.EnumName
                    }
                }
                ;
                var e = enums[xld.EnumName];

                foreach (var o in xld.Assets.Values.OrderBy(x => x.Id))
                {
                    var id = offset + o.Id;
                    e.Entries.Add(string.IsNullOrEmpty(o.Name)
                        ? new EnumEntry {
                        Name = $"Unknown{id}", Value = id
                    }
                        : new EnumEntry {
                        Name = Sanitise(o.Name), Value = id
                    });
                }
            }

            ItemConfig itemConfig = ItemConfig.Load(baseDir);

            enums["ItemId"] = new EnumData {
                Name = "ItemId"
            };
            foreach (var item in itemConfig.Items)
            {
                enums["ItemId"].Entries.Add(string.IsNullOrEmpty(item.Value.Name)
                    ? new EnumEntry {
                    Name = $"Unknown{item.Key}", Value = item.Key
                }
                    : new EnumEntry {
                    Name = Sanitise(item.Value.Name), Value = item.Key
                });
            }

            CoreSpriteConfig coreSpriteConfig = CoreSpriteConfig.Load(baseDir);

            enums["CoreSpriteId"] = new EnumData {
                Name = "CoreSpriteId"
            };
            foreach (var item in coreSpriteConfig.CoreSpriteIds)
            {
                enums["CoreSpriteId"].Entries.Add(new EnumEntry {
                    Name = Sanitise(item.Value), Value = item.Key
                });
            }

            foreach (var e in enums.Values)
            {
                var duplicateNames = e.Entries.GroupBy(x => x.Name).Where(x => x.Count() > 1).ToList();
                var counters       = duplicateNames.ToDictionary(x => x.Key, x => 1);

                foreach (var o in e.Entries)
                {
                    if (!counters.ContainsKey(o.Name))
                    {
                        continue;
                    }
                    var name = o.Name;

                    o.Name = name + counters[name];
                    counters[name]++;
                }
            }

            foreach (var e in enums.Values)
            {
                File.WriteAllText(Path.Combine(outpathPath, e.Name + ".cs"),
                                  $@"// Note: This file was automatically generated using Tools/GenerateEnums.
// No changes should be made to this file by hand. Instead, the relevant json 
// files should be modified and then GenerateEnums should be used to regenerate
// the various ID enums.

namespace UAlbion.Formats.AssetIds
{{
    public enum {e.Name}
    {{
" +
                                  string.Join(Environment.NewLine, e.Entries.Select(x => $"        {x.Name} = {x.Value},"))
                                  + @"
    }
}");
            }
        }
    }
예제 #4
0
        public static CoreSpriteConfig.BinaryResource GetConfig(CoreSpriteId id, string exePath, CoreSpriteConfig config, out string filename)
        {
            if (!Directory.Exists(exePath))
            {
                throw new InvalidOperationException($"Search directory {exePath} does not exist");
            }

            foreach (var file in Directory.EnumerateFiles(exePath, "*.*", SearchOption.AllDirectories))
            {
                if (!file.EndsWith(".exe", StringComparison.InvariantCultureIgnoreCase))
                {
                    continue;
                }

                var hash = GetHash(file);
                if (config.Hashes.TryGetValue(hash, out var resources))
                {
                    filename = file;
                    return(resources[(int)id]);
                }
            }

            throw new FileNotFoundException("No suitable main.exe file could be found.");
        }