private void BatchImportTranslationMenuItem_Click(object sender, RoutedEventArgs e)
        {
            string tag = ((MenuItem)sender)?.Tag as string;
            var    sfd = new SaveFileDialog
            {
                Filter   = GenerateFilters(false),
                FileName = "Select a file type and the folder which contains the translation files (the folder containing the 1st, 2nd and 3rd folder) and press Save",
                Title    = "Batch Import"
            };

            if (sfd.ShowDialog() == true)
            {
                // Path to the directory which contains all the translation files
                string dir = Path.GetDirectoryName(sfd.FileName);
                // Gets the index of the filetype
                int index = sfd.FilterIndex - 1;
                foreach (var entry in ScriptArchive.FileEntries)
                {
                    var script = new STSCFile();
                    using (var stream = ScriptArchive.GetFileStream(entry.FileName))
                        script.Load(stream);
                    // Path to the script file
                    string filepath = Path.ChangeExtension(Path.Combine(dir, entry.FileName), TranslationSTSCHandler.FileTypes[index].TypeExtension);
                    // Skip script if file does not exist
                    if (!File.Exists(filepath))
                    {
                        continue;
                    }
                    // Import translation
                    try
                    {
                        string data = "";
                        using (var stream = File.Open(filepath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
                            using (StreamReader reader = new StreamReader(stream))
                                data = reader.ReadToEnd();
                        TranslationSTSCHandler.ImportTranslation(index, script, data, !tag.Contains("nokey"), App.StringProcess);
                        // Save the script back into the archive
                        using (var stream = new MemoryStream())
                        {
                            script.Save(stream);
                            ScriptArchive.ReplaceFile(entry.FileName, stream.ToArray());
                        }
                    }
                    catch
                    {
                        MessageBox.Show("Failed to open file! Possible another program is using it.", "Import Error!", MessageBoxButton.OK, MessageBoxImage.Error);
                    }
                }
            }
            // Reload the current script
            if (ScriptListBox.SelectedIndex == -1)
            {
                return;
            }
            LoadScript(ScriptArchive.FileEntries[ScriptListBox.SelectedIndex].FileName);
        }
Esempio n. 2
0
        /// <summary>
        /// Builds and injects the modfied script into the game's memory
        /// </summary>
        /// <param name="file"></param>
        public void BuildAndInject(STSCFile file)
        {
            var interpreter = GetScriptInterpreter();

            using (var stream = new MemoryStream())
            {
                file.Save(stream);
                stream.Position = 0x3C;
                ProcessHandle.WriteBytes(interpreter.EntryPoint_addr, stream.CacheStream().ToArray());
            }
        }
        private void ImportTranslationWorkbookMenuItem_Click(object sender, RoutedEventArgs e)
        {
            string tag = ((MenuItem)sender)?.Tag as string;
            var    sfd = new OpenFileDialog
            {
                Filter   = "Excel Workbook(*.xlsx)|*.xlsx",
                FileName = "Script.xlsx",
                Title    = "Import Excel Workbook"
            };

            if (sfd.ShowDialog() == true)
            {
                var workbook = Workbook.Load(sfd.FileName);

                foreach (var entry in ScriptArchive.FileEntries)
                {
                    var script = new STSCFile();
                    using (var stream = ScriptArchive.GetFileStream(entry.FileName))
                        script.Load(stream);

                    try
                    {
                        var worksheet = workbook.Worksheets.FirstOrDefault(t => entry.FileName.Contains(t.SheetName));
                        var lines     = TranslationXLSXFile.ImportWorksheet(worksheet);
                        TranslationSTSCHandler.ImportTranslation(lines, script, !tag.Contains("nokey"), App.StringProcess);
                        // Save the script back into the archive
                        using (var stream = new MemoryStream())
                        {
                            script.Save(stream);
                            ScriptArchive.ReplaceFile(entry.FileName, stream.ToArray());
                        }
                    }
                    catch
                    {
                        MessageBox.Show("Failed to open file! Possible another program is using it.", "Import Error!", MessageBoxButton.OK, MessageBoxImage.Error);
                    }
                }
                // Reload the current script
                if (ScriptListBox.SelectedIndex == -1)
                {
                    return;
                }
                LoadScript(ScriptArchive.FileEntries[ScriptListBox.SelectedIndex].FileName);
            }
        }
Esempio n. 4
0
        private void BatchImportTranslationMenuItem_Click(object sender, RoutedEventArgs e)
        {
            string tag = ((MenuItem)sender)?.Tag as string;
            var    sfd = new SaveFileDialog
            {
                Filter   = GenerateFilters(false),
                FileName = "Select a file type and the folder which contains the translation files (the folder containing the 1st, 2nd and 3rd folder) and press Save",
                Title    = "Batch Import"
            };

            if (sfd.ShowDialog() == true)
            {
                // Path to the directory which contains all the translation files
                string dir = Path.GetDirectoryName(sfd.FileName);
                // Gets the index of the filetype
                int index = sfd.FilterIndex - 1;
                foreach (var entry in ScriptArchive.FileEntries)
                {
                    var script = new STSCFile();
                    using (var stream = ScriptArchive.GetFileStream(entry.FileName))
                        script.Load(stream);
                    // Path to the script file
                    string filepath = Path.ChangeExtension(Path.Combine(dir, entry.FileName), TranslationSTSCHandler.FileTypes[index].TypeExtension);
                    // Skip script if file does not exist
                    if (!File.Exists(filepath))
                    {
                        continue;
                    }
                    // Import translation
                    TranslationSTSCHandler.ImportTranslation(index, script, File.ReadAllText(filepath), !tag.Contains("nokey"));
                    // Save the script back into the archive
                    using (var stream = new MemoryStream())
                    {
                        script.Save(stream);
                        ScriptArchive.ReplaceFile(entry.FileName, stream.ToArray());
                    }
                }
            }
            // Reload the current script
            if (ScriptListBox.SelectedIndex == -1)
            {
                return;
            }
            LoadScript(ScriptArchive.FileEntries[ScriptListBox.SelectedIndex].FileName);
        }
Esempio n. 5
0
 static void Main(string[] args)
 {
     // Language
     CultureInfo.DefaultThreadCurrentCulture   = new CultureInfo("en-US");
     CultureInfo.DefaultThreadCurrentUICulture = new CultureInfo("en-US");
     if (args.Length == 0)
     {
         Console.WriteLine("Error: Not Enough Arguments!");
         Console.WriteLine("  STSCTool {.bin/.txt}");
         Console.ReadKey(true);
         return;
     }
     STSCMacros.Fill();
     for (int i = 0; i < args.Length; ++i)
     {
         var file = new STSCFile();
         if (Path.GetExtension(args[i]) == ".bin")
         {
             try
             {
                 file.Load(args[i]);
             }catch (STSCDisassembleException e)
             {
                 Console.WriteLine("Error: {0}.", e.Message);
                 Console.WriteLine("This usually means the Script is corrupt or one or more STSCFile's definitions are incorrect.");
                 Console.WriteLine("or the opcode being read is not yet implemented");
                 Console.WriteLine("Please check the output file for finding out what instruction went wrong.");
                 Console.WriteLine("Disassembler must abort now!");
                 Console.ReadKey(true);
             }
             File.WriteAllLines(Path.ChangeExtension(args[i], ".txt"), STSCTextHandler.ConvertToText(file), Encoding.UTF8);
         }
         else
         {
             STSCTextHandler.ConvertToObject(file, File.ReadAllLines(args[i], Encoding.UTF8));
             file.Save(Path.ChangeExtension(args[i], ".bin"));
         }
     }
 }