Пример #1
0
        static void ArgumentHandlerBinaryToJson(string[] args)
        {
            if (args.Length != 3)
            {
                throw new Exception($"Invalid number of arguments for {args[0]}");
            }

            var sourceRoot = new DirectoryInfo(args[1]);
            var targetRoot = new DirectoryInfo(args[2]);

            // Special cases: include only known valid TBLs, exclude known incompatible leftovers (TestData folder, EO3 seafaring, etc...)
            var binaryFiles = sourceRoot.EnumerateFiles("*", SearchOption.AllDirectories)
                              .Where(x => (x.Extension == ".tbl" && (x.Name.EndsWith("nametable.tbl") || x.Name == "skyitemname.tbl" || x.Name == "HiddenTreasureName.tbl")) || x.Extension == ".mbm")
                              .Where(x => !x.DirectoryName.Contains("TestData") && !x.Name.StartsWith("sea") && !x.Name.StartsWith("FacilityEntranceText"));

            /* TODOs:	Dungeon\floor_name.tbl -- fixed string lengths? (0x48 bytes SJIS text + 0x04 bytes unknown ID?)
             *			Event\npc_char.tbl -- has NPC names (Kirjonen, Wiglaf, etc), probably not needed?
             */

            foreach (var binaryFile in binaryFiles)
            {
                var relativePath   = GetRelativePath(binaryFile, sourceRoot);
                var outputFileInfo = new FileInfo(Path.Combine(targetRoot.FullName, relativePath, $"{Path.GetFileNameWithoutExtension(binaryFile.FullName)}.json"));

                if (CheckOkayToContinue(outputFileInfo))
                {
                    Console.WriteLine($"[*] Converting binary {binaryFile.Name} to JSON...");

                    outputFileInfo.Directory.Create();

                    Translation translationFile;
                    switch (binaryFile.Extension)
                    {
                    case ".tbl": translationFile = StringTableHandler.ImportBinary(binaryFile.FullName, relativePath); break;

                    case ".mbm": translationFile = MessageBinaryHandler.ImportBinary(binaryFile.FullName, relativePath); break;

                    default: throw new Exception($"Unrecognized file extension {binaryFile.Extension}");
                    }
                    translationFile.SerializeToFile(outputFileInfo.FullName);
                }
            }
        }
Пример #2
0
        static void ArgumentHandlerJsonToBinary(string[] args)
        {
            if (args.Length != 3)
            {
                throw new Exception($"Invalid number of arguments for {args[0]}");
            }

            var sourceRoot = new DirectoryInfo(args[1]);
            var targetRoot = new DirectoryInfo(args[2]);

            var jsonFiles = sourceRoot.EnumerateFiles("*.json", SearchOption.AllDirectories);

            foreach (var jsonFile in jsonFiles)
            {
                Translation translationFile = jsonFile.FullName.DeserializeFromFile <Translation>();

                if (ignoreUntranslatedFiles && !translationFile.Entries.Any(x => string.Compare(x.Original, x.Translation) != 0))
                {
                    Console.WriteLine($"[-] File {jsonFile.Name} has no translated entries, skipping...");
                    continue;
                }

                var relativePath   = GetRelativePath(jsonFile, sourceRoot);
                var outputFileInfo = new FileInfo(Path.Combine(targetRoot.FullName, translationFile.RelativePath));

                if (CheckOkayToContinue(outputFileInfo))
                {
                    Console.WriteLine($"[*] Converting JSON {jsonFile.Name} to binary...");

                    outputFileInfo.Directory.Create();

                    switch (translationFile.FileType)
                    {
                    case StringTableHandler.FileType: StringTableHandler.ExportBinary(translationFile, outputFileInfo.FullName); break;

                    case MessageBinaryHandler.FileType: MessageBinaryHandler.ExportBinary(translationFile, outputFileInfo.FullName); break;

                    default: throw new Exception($"Unrecognized translation type {translationFile.FileType}");
                    }
                }
            }
        }