Example #1
0
        private List <string> GetAllNames()
        {
            List <string> uniqueNames = new List <string>();

            for (int i = 1; i < dataGridViewFiles.Rows.Count; i++)
            {
                string filename = dataGridViewFiles.Rows[i].Cells[0].Value?.ToString();
                if (Path.GetExtension(filename) != ".obj")
                {
                    continue;
                }

                string    filepath = Path.Combine(Application.StartupPath, "Data", "Obj", filename, filename);
                OBJHelper myHelper = new OBJHelper(File.ReadAllBytes(filepath));
                Dictionary <int, string> myNames = new Dictionary <int, string>();
                myHelper.Import();
                myNames = myHelper.actors;

                for (int ii = 0; ii < myNames.Count; ii++)
                {
                    if (uniqueNames.Contains(myNames[ii]) == false)
                    {
                        uniqueNames.Add(myNames[ii]);
                    }
                }
            }

            uniqueNames.Remove(null);
            return(uniqueNames);
        }
Example #2
0
 private void openFileDialog1_FileOk(object sender, CancelEventArgs e)
 {
     Editor = new OBJHelper(File.ReadAllBytes(openFileDialog1.FileName));
     listBox1.Items.Clear();
     foreach (string String in Editor.Import())
     {
         listBox1.Items.Add(String);
     }
 }
Example #3
0
        private void OBJEGUI_Load(object sender, EventArgs e)
        {
            if (arg1 != null && arg2 != null && arg3 != null)
            {
                if (arg1 == "-patch")
                {
                    List <String> StringList = new List <String>();
                    Editor = new OBJHelper(File.ReadAllBytes(arg2));
                    foreach (string String in Editor.Import())
                    {
                        StringList.Add(String);
                    }

                    StringList.Clear();
                    foreach (string line in File.ReadLines(arg3))
                    {
                        StringList.Add(line);
                    }

                    string[] Strings = new string[StringList.Count];
                    for (int i = 0; i < Strings.Length; i++)
                    {
                        Strings[i] = StringList[i].ToString();
                    }

                    File.WriteAllBytes(arg2, Editor.Export(Strings));
                }
                else if (arg1 == "-export")
                {
                    List <String> StringList = new List <String>();
                    Editor = new OBJHelper(File.ReadAllBytes(arg2));
                    foreach (string String in Editor.Import())
                    {
                        StringList.Add(String);
                    }
                    string[]     Strings  = new string[StringList.Count];
                    StreamWriter SaveFile = new StreamWriter(arg3);
                    for (int i = 0; i < Strings.Length; i++)
                    {
                        Strings[i] = StringList[i].ToString();
                        SaveFile.WriteLine(Strings[i]);
                    }
                    SaveFile.Close();
                }
                else
                {
                    MessageBox.Show("The first argument must be \"-patch\" or \"-export\" (without quotes).", "Argument error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                System.Windows.Forms.Application.ExitThread();
            }
        }
        public static void RepackObj(bool debugMode)
        {
            List <String> directories = new List <string>();

            directories.AddRange(Directory.GetDirectories(Path.Combine(Application.StartupPath, "Data", "Obj")).Select(Path.GetFileName));

            JObject mainFile = JObject.Parse(File.ReadAllText(mainFilePath));

            Dictionary <string, string> translatedNames = new Dictionary <string, string>(); // Dictionary with pairs of original and translated names

            if (mainFile["names"] != null)
            {
                foreach (JProperty name in mainFile["names"].Children().ToArray())
                {
                    if (name.Value.ToString() != "") // If a translation for that name exists
                    {
                        translatedNames.Add(name.Name, name.Value.ToString());
                    }
                }
            }

            foreach (string name in directories)
            {
                string    filepath      = Path.Combine(Application.StartupPath, "Data", "Obj", name, name);
                OBJHelper myHelper      = new OBJHelper(File.ReadAllBytes(filepath));
                string[]  scriptStrings = myHelper.Import();
                Dictionary <int, string> scriptNames = myHelper.actors;

                bool haveTranslation = mainFile[name] != null;
                for (int i = 0; i < scriptStrings.Length; i++)
                {
                    if (haveTranslation)
                    {
                        string translatedString = mainFile[name][i.ToString()].ToString();
                        if (translatedString != "")
                        {
                            scriptStrings[i] = translatedString;
                        }
                    }

                    if (scriptNames[i] != null && translatedNames.ContainsKey(scriptNames[i]))
                    {
                        scriptNames[i] = translatedNames[scriptNames[i]];
                    }
                }

                File.WriteAllBytes(Path.Combine(toolsDirectory, name), myHelper.Export(scriptStrings));

                Process myProc = new Process();
                myProc.StartInfo.FileName         = Path.Combine(toolsDirectory, "gzip.exe");
                myProc.StartInfo.Arguments        = "-n9 -f " + name; // Without -n9 the game will freeze
                myProc.StartInfo.WorkingDirectory = toolsDirectory;
                myProc.StartInfo.WindowStyle      = ProcessWindowStyle.Hidden;
                myProc.Start();
                myProc.WaitForExit();

                File.Delete(Path.Combine(toolsDirectory, name));

                File.Replace(Path.Combine(toolsDirectory, name + ".gz"), Application.StartupPath + File.ReadAllText(filepath + ".txt"), null);
            }

            if (debugMode)
            {
                File.Copy(Path.Combine(Application.StartupPath, "Data", "Debug", "_0000ESS1.obj.gz"), Path.Combine(Application.StartupPath, "Data", "DatWorker", "resource", "script", "_0000ESS1", "_0000ESS1.0001", "_0000ESS1.obj.gz"), true);     // This file enables debug mode
                File.Copy(Path.Combine(Application.StartupPath, "Data", "Debug", "STARTPOINT.obj.gz"), Path.Combine(Application.StartupPath, "Data", "DatWorker", "resource", "script", "STARTPOINT", "STARTPOINT.0001", "STARTPOINT.obj.gz"), true); // This is pretranslated debug menu
            }
            else
            {
                File.Copy(Path.Combine(Application.StartupPath, "Data", "Debug", "original_STARTPOINT.obj.gz"), Path.Combine(Application.StartupPath, "Data", "DatWorker", "resource", "script", "STARTPOINT", "STARTPOINT.0001", "STARTPOINT.obj.gz"), true); // Restore original debug menu
            }
        }
Example #5
0
        private void LoadFile(string filename)
        {
            if (currentFile != null)
            {
                SaveProgress();
            }

            currentFile = filename;
            string[] myStrings;
            Dictionary <int, string> myNames = new Dictionary <int, string>();

            if (Path.GetExtension(currentFile) == ".obj")
            {
                string    filepath = Path.Combine(Application.StartupPath, "Data", "Obj", currentFile, currentFile);
                OBJHelper myHelper = new OBJHelper(File.ReadAllBytes(filepath));
                myStrings = myHelper.Import();
                myNames   = myHelper.actors;
            }
            else // Else it is .txt file
            {
                string filepath = Path.Combine(Application.StartupPath, "Data", "Txt", currentFile, currentFile);
                myStrings = File.ReadAllLines(filepath, new UnicodeEncoding(false, false)); // Txt file has encoding UTF-16 LE (Unicode without BOM)
            }

            JObject mainFile        = JObject.Parse(File.ReadAllText(mainFilePath));
            bool    haveTranslation = false;

            if (mainFile[currentFile] != null)
            {
                haveTranslation = true;
            }

            dataGridViewStrings.Rows.Clear();
            for (int i = 0; i < myStrings.Length; i++)
            {
                string name       = "";
                string sentence   = "";
                string translated = "";
                if (myStrings[i].StartsWith("「") && myStrings[i].EndsWith("」"))
                {
                    name     = myNames[i];
                    sentence = myStrings[i].TrimStart('「').TrimEnd('」'); // Remove brackets from the beginning and end of the original sentence
                }
                else
                {
                    sentence = myStrings[i];
                }
                sentence = sentence.Replace("_", " ");

                if (haveTranslation)
                {
                    translated = mainFile[currentFile][i.ToString()].ToString();

                    if (translated.StartsWith("「") && translated.EndsWith("」"))
                    {
                        translated = translated.TrimStart('「').TrimEnd('」'); // Remove brackets from the beginning and end of the original sentence
                    }
                    if (translated.StartsWith("(") && translated.EndsWith(")"))
                    {
                        translated = translated.TrimStart('(').TrimEnd(')'); // Remove brackets from the beginning and end of the original sentence
                    }
                }

                dataGridViewStrings.Rows.Add(name, sentence, translated);
            }
        }