コード例 #1
0
    public static Dictionary <int, string> ReadMesFile(this IFileSystem vfs, string path, bool withPatches = true)
    {
        Dictionary <int, string> result;

        {
            using var content = vfs.ReadFile(path);
            result            = MesFile.Read(path, content.Memory.Span);
        }

        if (withPatches)
        {
            var patchDir   = Path.ChangeExtension(path, ".d");
            var patchFiles = vfs.Search($"{patchDir}/*.mes").ToList();
            patchFiles.Sort(); // Apply natural sort
            foreach (var patchFile in patchFiles)
            {
                var patchContent = ReadMesFile(vfs, patchFile, false);
                Logger.Debug("Applying {0} patches from {1}", patchContent.Count, patchFile);
                foreach (var entry in patchContent)
                {
                    result[entry.Key] = entry.Value;
                }
            }
        }

        return(result);
    }
コード例 #2
0
    public static void Main(string[] args)
    {
        // When a debugger is attached, immediately rethrow unobserved exceptions from asynchronous tasks
        if (Debugger.IsAttached)
        {
            TaskScheduler.UnobservedTaskException += (_, eventArgs) =>
            {
                if (!eventArgs.Observed)
                {
                    throw eventArgs.Exception;
                }
            };
        }
        else
        {
            AppDomain.CurrentDomain.UnhandledException += HandleException;
        }

        if (JumpListHandler.Handle(args))
        {
            return;
        }

        if (args.Length > 0 && args[0] == "--extract-save")
        {
            ExtractSaveArchive.Main(args.Skip(1).ToArray());
            return;
        }

        if (args.Length == 2 && args[0] == "--mes-to-json")
        {
            var mesContent = MesFile.Read(args[1]);
            var newFile    = Path.ChangeExtension(args[1], ".json");
            var options    = new JsonSerializerOptions();
            options.WriteIndented = true;
            var jsonContent = JsonSerializer.Serialize(mesContent.ToDictionary(
                                                           kvp => kvp.Key.ToString(),
                                                           kvp => kvp.Value
                                                           ), options);
            File.WriteAllText(newFile, jsonContent);
            return;
        }

        if (args.Length > 0 && args[0] == "--dump-addresses")
        {
            var dumper = new AddressDumper();
            dumper.DumpAddresses();
            return;
        }

        string dataDir = null;

        if (args.Length > 0 && args[0] == "--data-dir")
        {
            dataDir = args[1];
        }

        using var startup = new GameStartup { DataFolder = dataDir };

        if (startup.Startup())
        {
            startup.EnterMainMenu();

            Globals.GameLoop.Run();
        }
    }