Skip to content

Commit

Permalink
Rectify encoding issues with wacky ingame language
Browse files Browse the repository at this point in the history
Thanks for reporting, Asia81.
  • Loading branch information
kwsch committed Apr 21, 2015
1 parent 67b7392 commit e5b18c7
Showing 1 changed file with 33 additions and 4 deletions.
37 changes: 33 additions & 4 deletions pk3DS/Subforms/xytext.cs
Expand Up @@ -68,6 +68,8 @@ private void exportTextFile(string fileName, bool newline)
.Replace("\\n", " ")
.Replace("\\c", "")
.Replace("\\r", "")
.Replace("\\\\", "\\")
.Replace("\\[", "[")
: line);
}
}
Expand Down Expand Up @@ -114,9 +116,11 @@ private bool importTextFile(string fileName)
"When exporting text, do not remove newline formatting."); return false; }

// All Text Lines received. Store all back.
for (int i = 0; i < files.Length; i++)
File.WriteAllBytes(files[i], getBytesForFile(textLines[i]));

try {
for (int i = 0; i < files.Length; i++)
File.WriteAllBytes(files[i], getBytesForFile(textLines[i]));
}
catch { return false; }
return true;
}
private void changeEntry(object sender, EventArgs e)
Expand Down Expand Up @@ -270,6 +274,10 @@ internal static string[] getStringsFromFile(string path)
{
case '\n': s += "\\n";
break;
case '\\': s += "\\\\";
break;
case '[': s += "\\[";
break;
case 0x10: decryptVar(data, ref offset, ref s, ref c, ref k);
break;
case 0xE07F: s += (char)0x202F; // nbsp
Expand Down Expand Up @@ -468,7 +476,28 @@ internal static void encryptVar(BinaryWriter bw, string line, ref int i, ref ush
bw.Write(encryptU16(1, ref key));
bw.Write(encryptU16(0xBE01, ref key));
}
else { throw new Exception("Invalid terminated line"); }
else if (line[i + 1] == '\\') // Not Formatting
{
i++;
bw.Write(encryptU16('\\', ref key));
}
else if (line[i + 1] == '[') // Not Variable
{
i++;
bw.Write(encryptU16('[', ref key));
}
else
{
if (DialogResult.Yes != Util.Prompt(
MessageBoxButtons.YesNo,
"Encoding Error - Please Resolve:",
String.Format("File: {3}{0}Char: {1}{0}Line:{0}{2}", Environment.NewLine, line[i+1], line, i),
"Treat as literal '\\'?"))
throw new Exception("Invalid terminated line: " + line);

i++;
bw.Write(encryptU16('\\', ref key));
}
else if (val == '[') // Special Variable
{
int bracket = line.Substring(i + 1).IndexOf(']');
Expand Down

0 comments on commit e5b18c7

Please sign in to comment.