Ejemplo n.º 1
0
        /* Open Keycode Writer */
        private bool SetSelectedKeycode(string keycode)
        {
            try
            {
                //Rewrite code for UI (TEXT)
                for (int i = 0; i < Convert.ToInt32(KeycodeInfoArray()[2]); i++)
                {
                    for (int x = 0; x < localisationUtility.languageFolders.Length; x++)
                    {
                        LocalisedText text = localisationUtility.GetLocalisedString(KeycodeInfoArray()[3 + i], (LocalisationHandler.AYZ_Lang)x);
                        text.TextValue = text.TextValue.Replace(GetSelectedKeycode(), keycode);
                        localisationUtility.UpdateLocalisedString(text);
                    }
                }

                //Rewrite code in script (COMMANDS.PAK)
                byte[] commandsPAK = File.ReadAllBytes(GetCommandsPakPath());
                for (int i = 0; i < 4; i++)
                {
                    commandsPAK[GetCommandsPakOffset() + i] = BitConverter.GetBytes(keycode[i])[0];
                }
                File.WriteAllBytes(GetCommandsPakPath(), commandsPAK);

                return(true);
            }
            catch
            {
                return(false);
            }
        }
Ejemplo n.º 2
0
        /* Update string preview when an ID is selected */
        private void localisationTree_AfterSelect(object sender, TreeViewEventArgs e)
        {
            currentString = new LocalisedText();

            if (localisationTree.SelectedNode == null || localisationTree.SelectedNode.Tag.ToString() != "STRING")
            {
                stringOut.Text = "";
                return;
            }

            stringOut.Text = localisationUtility.GetLocalisedString(localisationTree.SelectedNode.Text, (LocalisationHandler.AYZ_Lang)selectedLanguage.SelectedIndex).TextValue;
            currentString  = new LocalisedText(stringOut.Text, localisationTree.SelectedNode.Text, localisationTree.SelectedNode.Parent.Text, selectedLanguage.SelectedItem.ToString());
        }
        /* Update a localised string */
        public bool UpdateLocalisedString(LocalisedText Text)
        {
            string textFilePath = textFolder + Text.Language + @"\" + Text.MissionID + ".TXT";

            string[]      textFile    = File.ReadAllLines(textFilePath);
            List <string> newTextFile = new List <string>();

            //Get up to our string
            for (int i = 0; i < textFile.Length; i++)
            {
                newTextFile.Add(textFile[i]);
                if (textFile[i] == "[" + Text.TextID + "]")
                {
                    break;
                }
            }

            //Write new content
            newTextFile.Add("{" + Text.TextValue + "}");

            //Continue down to end of file
            bool startAdding = false;

            for (int i = newTextFile.Count - 1; i < textFile.Length; i++)
            {
                if (!startAdding && textFile[i].Length > 0 && textFile[i].Substring(0, 1) == "[")
                {
                    startAdding = true;
                    newTextFile.Add("");
                }
                if (startAdding)
                {
                    newTextFile.Add(textFile[i]);
                }
            }

            //Write changes
            File.WriteAllLines(textFilePath, newTextFile, Encoding.Unicode);

            return(true);
        }
        /* Get a localised string from the game's string bank */
        public LocalisedText GetLocalisedString(string ID, AYZ_Lang Language)
        {
            //For each text bank, search for the requested ID and return its string
            foreach (string textFile in GetTextFiles(Language))
            {
                string[] textFileContent = File.ReadAllLines(textFile);
                for (int i = 0; i < textFileContent.Length; i++)
                {
                    if (textFileContent[i] == "[" + ID + "]")
                    {
                        LocalisedText theString = new LocalisedText();
                        theString.TextValue = "";
                        int stringIndex = 1;
                        while (theString.TextValue.Length == 0 || theString.TextValue.Substring(theString.TextValue.Length - 1) != "}")
                        {
                            string thisLine = textFileContent[i + stringIndex];
                            if (thisLine == "")
                            {
                                thisLine = "\r\n\r\n";
                            }
                            theString.TextValue += thisLine;
                            stringIndex++;
                        }
                        theString.TextValue = theString.TextValue.Substring(1, theString.TextValue.Length - 2);
                        theString.TextID    = ID;
                        theString.MissionID = Path.GetFileNameWithoutExtension(textFile);
                        theString.Language  = languageFolders[(int)Language];

                        return(theString);
                    }
                }
            }

            //Couldn't find string, this is probably a pretty big issue, so throw here.
            throw new InvalidOperationException("Requested to find localised string which does not exist! Fatal!");
        }
        /* Get all text IDs by language */
        public List <LocalisedText> GetAllIDs(AYZ_Lang Language)
        {
            List <LocalisedText> textIDs = new List <LocalisedText>();

            foreach (string textFile in GetTextFiles(Language))
            {
                string[] textFileContent = File.ReadAllLines(textFile);
                for (int i = 0; i < textFileContent.Length; i++)
                {
                    if (textFileContent[i].Length > 0 && textFileContent[i].Substring(0, 1) == "[")
                    {
                        LocalisedText stringID = new LocalisedText();
                        stringID.TextValue = "N/A";
                        stringID.TextID    = textFileContent[i].Substring(1, textFileContent[i].Length - 2);
                        stringID.MissionID = Path.GetFileNameWithoutExtension(textFile);
                        stringID.Language  = languageFolders[(int)Language];

                        textIDs.Add(stringID);
                    }
                }
            }

            return(textIDs);
        }