Quote:
Originally Posted by ernilos
Try Text.Encoding.UTF8
|
There are lots of strings in chinese (still untranslated), and the game does not handle UTF, it reads strings with ANSI codepage "GB18030".
The problem is there are lots of decorative NPCs with special name displayed in game as empty name, but the string in file cannot be empty or the game does not play.
I could assign somtehing like "Unnamed", but it is so ugly...
What I need to write is exactly these 2 bytes with value 161, but I don't know how to do while using "GB18030" codepage.
If I don't use "GB18030" for the StreamWriter, the text in the file becomes corrupted when read by the game.
I've found a solution:
Code:
Encoding enc = Encoding.GetEncoding(54936); //"GB18030" = Page Code 54936: Simplified Chinese
if (File.Exists(filename)) // Delete the file if it exists.
{
File.Delete(filename);
}
using (FileStream fs = File.Create(filename)) //Create the file.
using (StreamWriter sw = new StreamWriter(fs, enc))
{
foreach (KeyValuePair<UInt32, NpcX> NPC in this.NPCs)
{
sw.WriteLine("[" + NPC.Key.ToString() + "]");
if (NPC.Value.Name == "") //Default empty name
{
sw.Write("Name=");
sw.Flush();
fs.Flush();
fs.WriteByte(161);
fs.WriteByte(161);
fs.Flush();
sw.Flush();
sw.WriteLine(); //End the line
}
else
{
sw.WriteLine("Name=" + NPC.Value.Name);
}
sw.WriteLine("RaceId=" + NPC.Value.RaceId.ToString());
sw.WriteLine("AddSize=" + NPC.Value.AddSize.ToString());
Using streamwriter to write text (with encoding) and filestream to write raw bytes.
Gracias por intentarlo