static void Main(string[] args) { PerfTracker.StartupEvent("Entered main"); Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); // Required for code page 850 support in .NET Core PerfTracker.StartupEvent("Registered encodings"); var commandLine = new CommandLineOptions(args); if (commandLine.Mode == ExecutionMode.Exit) { return; } var baseDir = FormatUtil.FindBasePath(); if (baseDir == null) { throw new InvalidOperationException("No base directory could be found."); } PerfTracker.StartupEvent($"Found base directory {baseDir}"); PerfTracker.StartupEvent("Registering asset manager"); var factory = new VeldridCoreFactory(); using var locatorRegistry = new AssetLocatorRegistry() .AddAssetLocator(new StandardAssetLocator()) .AddAssetLocator(new AssetConfigLocator()) .AddAssetLocator(new CoreSpriteLocator()) .AddAssetLocator(new MetaFontLocator(factory)) .AddAssetLocator(new NewStringLocator()) .AddAssetLocator(new SoundBankLocator()) .AddAssetLocator(new SavedGameLocator()) .AddAssetPostProcessor(new AlbionSpritePostProcessor()) .AddAssetPostProcessor(new ImageSharpPostProcessor()) .AddAssetPostProcessor(new InterlacedBitmapPostProcessor()) .AddAssetPostProcessor(new InventoryPostProcessor()) ; var assets = new AssetManager(); var services = new Container("Services", new StdioConsoleLogger(), new ClipboardManager(), new ImGuiConsoleLogger(), Settings.Load(baseDir), // Need to register settings first, as the AssetConfigLocator relies on it. locatorRegistry, assets); using var exchange = new EventExchange(new LogExchange()) .Register <ICoreFactory>(factory) .Attach(services); Engine.GlobalExchange = exchange; PerfTracker.StartupEvent("Registered asset manager"); PerfTracker.StartupEvent($"Running as {commandLine.Mode}"); switch (commandLine.Mode) { case ExecutionMode.Game: case ExecutionMode.GameWithSlavedAudio: Albion.RunGame(exchange, services, baseDir, commandLine); break; case ExecutionMode.AudioSlave: exchange.Attach(new AudioManager(true)); break; case ExecutionMode.Editor: break; // TODO case ExecutionMode.SavedGameTests: SavedGameTests.RoundTripTest(baseDir); break; case ExecutionMode.DumpData: PerfTracker.BeginFrame(); // Don't need to show verbose startup logging while dumping var tf = new TextFormatter(); exchange.Attach(tf); DumpType dumpTypes = DumpType.All; if (commandLine.GameModeArgument != null) { dumpTypes = 0; foreach (var t in commandLine.GameModeArgument.Split(' ', StringSplitOptions.RemoveEmptyEntries)) { dumpTypes |= Enum.Parse <DumpType>(t); } } if ((dumpTypes & DumpType.Characters) != 0) { Dump.CharacterSheets(assets, tf, baseDir); } if ((dumpTypes & DumpType.Chests) != 0) { Dump.Chests(assets, baseDir); } if ((dumpTypes & DumpType.CoreSprites) != 0) { Dump.CoreSprites(assets, baseDir); } if ((dumpTypes & DumpType.EventSets) != 0) { Dump.EventSets(assets, baseDir); } if ((dumpTypes & DumpType.Items) != 0) { Dump.ItemData(assets, baseDir); } if ((dumpTypes & DumpType.MapEvents) != 0) { Dump.MapEvents(assets, baseDir); } if ((dumpTypes & DumpType.Maps) != 0) { Dump.MapData(assets, tf, baseDir); } if ((dumpTypes & DumpType.Spells) != 0) { Dump.Spells(assets, tf, baseDir); } if ((dumpTypes & DumpType.ThreeDMaps) != 0) { Dump.ThreeDMapAndLabInfo(assets, baseDir); } break; case ExecutionMode.Exit: break; } }
static void Main(string[] args) { var baseDir = ConfigUtil.FindBasePath(); if (baseDir == null) { throw new InvalidOperationException("No base directory could be found."); } Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); // Required for code page 850 support in .NET Core var commands = ParseCommands(args.Skip(1)).ToList(); if (!commands.Any()) { PrintUsage(); return; } var filename = args[0]; var stream = File.OpenRead(filename); using var br = new BinaryReader(stream, Encoding.GetEncoding(850)); var generalConfig = GeneralConfig.Load(Path.Combine(baseDir, "data", "config.json"), baseDir); var settings = GeneralSettings.Load(generalConfig.ResolvePath("$(DATA)/settings.json")); var assets = new AssetManager(); var loaderRegistry = new AssetLoaderRegistry(); var locatorRegistry = new AssetLocatorRegistry(); var containerLoaderRegistry = new ContainerLoaderRegistry().AddLoader(new RawContainerLoader()) .AddLoader(new XldContainerLoader()) .AddLoader(new BinaryOffsetContainerLoader()) .AddLoader(new ItemListContainerLoader()) .AddLoader(new SpellListContainerLoader()) .AddLoader(new DirectoryContainerLoader()) ; var modApplier = new ModApplier() // Register post-processors for handling transformations of asset data that can't be done by UAlbion.Formats alone. .AddAssetPostProcessor(new AlbionSpritePostProcessor()) .AddAssetPostProcessor(new InventoryPostProcessor()) .AddAssetPostProcessor(new ItemNamePostProcessor()); var exchange = new EventExchange(new LogExchange()); exchange .Attach(settings) .Register <IGeneralConfig>(generalConfig) .Attach(loaderRegistry) .Attach(locatorRegistry) .Attach(containerLoaderRegistry) .Attach(modApplier) .Attach(assets) ; modApplier.LoadMods(generalConfig); var save = SavedGame.Serdes(null, AssetMapping.Global, new AlbionReader(br, stream.Length)); if (!VerifyRoundTrip(stream, save, AssetMapping.Global)) { return; } foreach (var command in commands) { command.Action(save); Console.WriteLine(); } }
static async Task <(EventExchange, IContainer)> SetupAssetSystem(string baseDir) { var generalConfigTask = Task.Run(() => { var result = GeneralConfig.Load(Path.Combine(baseDir, "data", "config.json"), baseDir); PerfTracker.StartupEvent("Loaded general config"); return(result); }); var settingsTask = Task.Run(() => { var result = GeneralSettings.Load(Path.Combine(baseDir, "data", "settings.json")); PerfTracker.StartupEvent("Loaded settings"); return(result); }); var coreConfigTask = Task.Run(() => { var result = CoreConfig.Load(Path.Combine(baseDir, "data", "core.json")); PerfTracker.StartupEvent("Loaded core config"); return(result); }); var gameConfigTask = Task.Run(() => { var result = GameConfig.Load(Path.Combine(baseDir, "data", "game.json")); PerfTracker.StartupEvent("Loaded game config"); return(result); }); var assets = new AssetManager(); var factory = new VeldridCoreFactory(); var loaderRegistry = new AssetLoaderRegistry(); var locatorRegistry = new AssetLocatorRegistry(); var containerLoaderRegistry = new ContainerLoaderRegistry().AddLoader(new RawContainerLoader()) .AddLoader(new XldContainerLoader()) .AddLoader(new BinaryOffsetContainerLoader()) .AddLoader(new ItemListContainerLoader()) .AddLoader(new SpellListContainerLoader()) .AddLoader(new DirectoryContainerLoader()) ; var modApplier = new ModApplier() // Register post-processors for handling transformations of asset data that can't be done by UAlbion.Formats alone. .AddAssetPostProcessor(new AlbionSpritePostProcessor()) .AddAssetPostProcessor(new ImageSharpPostProcessor()) .AddAssetPostProcessor(new InterlacedBitmapPostProcessor()) .AddAssetPostProcessor(new InventoryPostProcessor()) .AddAssetPostProcessor(new ItemNamePostProcessor()); var settings = await settingsTask.ConfigureAwait(false); var services = new Container("Services", settings, // Need to register settings first, as the AssetLocator relies on it. loaderRegistry, locatorRegistry, containerLoaderRegistry, new MetafontBuilder(factory), new StdioConsoleLogger(), // new ClipboardManager(), new ImGuiConsoleLogger(), new WordLookup(), new AssetLocator(), modApplier, assets); var generalConfig = await generalConfigTask.ConfigureAwait(false); using var exchange = new EventExchange(new LogExchange()).Register <IGeneralConfig>(generalConfig) .Register <ICoreFactory>(factory) .Attach(services); PerfTracker.StartupEvent("Registered asset services"); Engine.GlobalExchange = exchange; generalConfig.SetPath("LANG", settings.Language.ToString() .ToUpperInvariant()); // Ensure that the LANG path is set before resolving any assets modApplier.LoadMods(generalConfig); PerfTracker.StartupEvent("Loaded mods"); var coreConfig = await coreConfigTask.ConfigureAwait(false); var gameConfig = await gameConfigTask.ConfigureAwait(false); exchange // Need to load game config after mods so asset ids can be parsed. .Register(coreConfig) .Register(gameConfig); PerfTracker.StartupEvent("Loaded core and game config"); return(exchange, services); }