Пример #1
0
        static void Main(string[] args)
        {
            // TODO: Use console parser nuget to make this less shitty.
            #if DEBUG
            var file = File.ReadAllBytes("OPEN_1.MES");
            var pathName = "OPEN_1.MES";
            #else
            if (!ArgumentParser(args))
            {
                return;
            }
            var file = File.ReadAllBytes(args[0]);
            var pathName = args[0];
            #endif
            //TranslatorFile(args);
            //return;

            var japaneseEncoding = Encoding.GetEncoding(932);
            var bytesForCole = japaneseEncoding.GetBytes("真剣");
            var omgnew = new Byte[] {186, 37};
            foreach (var position in file.Locate(omgnew))
            {
                //var encodedName = japaneseEncoding.GetBytes(TextTools.FullWidthConvertor("Cougar"));
                //file = TextTools.ReplaceText(file, encodedName, position, position + bytesForCole.Length);
                Console.WriteLine(position);
            }

            var dialogs = TextTools.ParseDialogList(file);
            dialogs.RemoveAll(node => node == null);
            var test = dialogs.Where(node => node.Character == Characters.JackOrSheila);

            var newFile = file;
            var additionalDialogs = 0;
            for (var i = 0; i < dialogs.Count; i++)
            {
                if (dialogs[i] == null)
                {
                    continue;
                }
                var newDialogs = TextTools.ParseDialogList(newFile);
                newDialogs.RemoveAll(node => node == null);

                // Don't allow changing the initial line.
                if (i != 0)
                {
                    var insertDialog = true;
                    while (insertDialog)
                    {
                        Console.WriteLine("Insert New Line?");
                        var response = Console.ReadKey();
                        Console.Write(Environment.NewLine);
                        if (response.Key == ConsoleKey.Y)
                        {
                            var dialog = new DialogBlob();
                            Console.WriteLine("Character? 1. Cole 2. Doc 3. Other");
                            response = Console.ReadKey();
                            Console.Write(Environment.NewLine);
                            switch (response.Key)
                            {
                                case ConsoleKey.NumPad1:
                                    dialog.Character = Characters.Cole;
                                    break;
                                case ConsoleKey.NumPad2:
                                    dialog.Character = Characters.Doc;
                                    break;
                                case ConsoleKey.NumPad3:
                                    dialog.Character = Characters.JackOrSheila;
                                    break;
                                default:
                                    dialog.Character = Characters.Cole;
                                    break;
                            }
                            Console.Write("New Dialog: ");
                            var brandNewDialog = Console.ReadLine();
                            var newEncodedText = japaneseEncoding.GetBytes(TextTools.FullWidthConvertor(brandNewDialog));
                            newEncodedText = TextTools.Combine(new[] { Convert.ToByte('\x26'), Convert.ToByte('\xBA'), Convert.ToByte(dialog.Character) }, newEncodedText, new[] { Convert.ToByte('\xBA'), Convert.ToByte('\x26')});
                            var lastDialog = newDialogs[i + additionalDialogs - 1];
                            dialog.StartIndex = lastDialog.EndIndex;
                            dialog.EndIndex = dialog.StartIndex + newEncodedText.Length;
                            newFile = TextTools.AddText(newFile, newEncodedText, dialog.StartIndex);
                            newDialogs = TextTools.ParseDialogList(newFile);
                            newDialogs.RemoveAll(node => node == null);
                            additionalDialogs++;
                        }
                        else
                        {
                            insertDialog = false;
                        }
                    }
                }

                Console.WriteLine("Character Name: " + Enum.GetName(typeof(Characters), dialogs[i].Character));
                Console.WriteLine("Dialog: " + dialogs[i].Dialog + Environment.NewLine);
                Console.Write("New Dialog: ");
                var newDialog = Console.ReadLine();
                Console.WriteLine(Environment.NewLine);

                if (string.IsNullOrEmpty(newDialog)) continue;

                var encodedText = japaneseEncoding.GetBytes(TextTools.FullWidthConvertor(newDialog));
                encodedText = TextTools.Combine(encodedText, new[] { Convert.ToByte('\xBA') });
                //encodedText = TextTools.Combine( encodedText, new[] { Convert.ToByte('\xBA'), Convert.ToByte('\x26'), Convert.ToByte('\xBA'), Convert.ToByte('\x25')}, encodedText, new [] { Convert.ToByte('\xBA') });
                newFile = TextTools.ReplaceText(newFile, encodedText, newDialogs[i + additionalDialogs].StartIndex, newDialogs[i + additionalDialogs].EndIndex);
            }

            var newFileName = Path.GetFileNameWithoutExtension(pathName) + "_EDIT.MES";
            //var newFileName = "OPEN_1_EDIT.MES";
            File.WriteAllBytes(newFileName, newFile);
            Console.WriteLine($"Done! Add edit {newFileName} to its original name and replace it on the FDI disk.");
            Console.ReadKey();
        }
 private static DialogBlob ParseDialog(byte[] file, int dialogIndex)
 {
     var dialog = new DialogBlob();
     switch ((Characters)file[dialogIndex + 1])
     {
         case Characters.Cole:
             dialog.Character = Characters.Cole;
             break;
         case Characters.Doc:
             dialog.Character = Characters.Doc;
             break;
         case Characters.JackOrSheila:
             dialog.Character = Characters.JackOrSheila;
             break;
         default:
             return null;
     }
     var endIndex = Array.IndexOf(file, Convert.ToByte('\x26'), dialogIndex);
     var dialogBytes = file.Slice(dialogIndex, endIndex);
     dialog.DialogBytes = dialogBytes;
     dialog.StartIndex = dialogIndex + 2; // The start of the actual dialog.
     dialog.EndIndex = endIndex;
     dialog.Dialog = DecodeText(dialogBytes);
     return dialog;
 }