Register for your free account! | Forgot your password?

Go Back   elitepvpers > Coders Den > .NET Languages
You last visited: Today at 20:45

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



[C#] Special Chars

Discussion on [C#] Special Chars within the .NET Languages forum part of the Coders Den category.

Reply
 
Old   #1
 
elite*gold: 0
Join Date: Sep 2012
Posts: 51
Received Thanks: 32
[C#] Special Chars

I'm working with simplified chinese texts, slowly translating all I can for the game Heroes of Might and Magic online (from TQ).
My program reads text data from 2 files, 1 chinese and 1 english; replace strings if english available and saves to a new file.
With a few strings I got a problem: the game uses a special string to avoid empty Names, and the Encoding does not well with that, but all other texts are fine, either english or chinese.
Here is part of my code:
Code:
Encoding enc = Encoding.GetEncoding(54936);      //"GB18030" = Page Code 54936: Simplified Chinese
using (StreamWriter sw = new StreamWriter(filename, false, enc))
{
	foreach (KeyValuePair<UInt32, NpcX> NPC in this.NPCs)
	{
		sw.WriteLine("[" + NPC.Key.ToString() + "]");
		//Check if Name is empty, and replace to ASCII(165)
		sw.WriteLine("Name=" + NPC.Value.Name);
		sw.WriteLine("RaceId=" + NPC.Value.RaceId.ToString());
		sw.WriteLine("AddSize=" + NPC.Value.AddSize.ToString());
		sw.WriteLine("Scale=" + NPC.Value.Scale.ToString());
		sw.WriteLine("FixDir=" + NPC.Value.FixDir.ToString());
		sw.WriteLine("Dir=" + NPC.Value.Dir.ToString());
		sw.WriteLine("Look=" + NPC.Value.Look.ToString());
		sw.WriteLine("Head=" + NPC.Value.Head.ToString());
		sw.WriteLine("Hair=" + NPC.Value.Hair.ToString());
		sw.WriteLine("Armet=" + NPC.Value.Armet.ToString());
		sw.WriteLine("Armor=" + NPC.Value.Armor.ToString());
		sw.WriteLine("RWeapon=" + NPC.Value.RWeapon.ToString());
		sw.WriteLine("LWeapon=" + NPC.Value.LWeapon.ToString());
		sw.WriteLine("Misc=" + NPC.Value.Misc.ToString());
		sw.WriteLine("Mount=" + NPC.Value.Mount.ToString());
		sw.WriteLine("Effect=" + NPC.Value.Effect);
		sw.WriteLine("Note=" + NPC.Value.Note);
		sw.WriteLine("");
	}
}
I need to write 2 bytes with same value = 165 decimal (or 0xA1).
Any suggestion?
urgabel is offline  
Old 09/21/2012, 07:51   #2
 
ernilos's Avatar
 
elite*gold: 20
Join Date: Jan 2012
Posts: 766
Received Thanks: 645
Try Text.Encoding.UTF8
ernilos is offline  
Thanks
1 User
Old 09/21/2012, 16:34   #3
 
elite*gold: 0
Join Date: Sep 2012
Posts: 51
Received Thanks: 32
Quote:
Originally Posted by ernilos View Post
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
urgabel is offline  
Old 09/24/2012, 18:59   #4

 
x]vIrus[x's Avatar
 
elite*gold: 37
Join Date: Apr 2004
Posts: 2,154
Received Thanks: 250
what you do there is write 0xa1a1 have you tried writing (char)(short)0xa1a1?
just for the lulz
x]vIrus[x is offline  
Thanks
1 User
Old 09/26/2012, 01:42   #5
 
elite*gold: 0
Join Date: Sep 2012
Posts: 51
Received Thanks: 32
Quote:
Originally Posted by x]vIrus[x View Post
what you do there is write 0xa1a1 have you tried writing (char)(short)0xa1a1?
just for the lulz
Thanks for trying, even if already solved.
You cannot cast just 2 bytes to short (short is 32 bits) but also does not work if cast to Uint16.

I have tried several ways, including
Code:
sw.WriteLine((char) 0xa1a1);
and get in file 0x82 0x35 0xC2 0x30
I guess due to bad Encoding...

Anyway, the solution to write bytes with no encoding at all is to use a filestream.
urgabel is offline  
Reply


Similar Threads Similar Threads
Special Paket Chars
07/15/2011 - Wolfteam - 5 Replies
hei hab ne frage es gibt ja im shop die chars im special paket aber meine frage in dem paket sind ja auch schlecht teile dabei die nur 50 ap 1 tag kosten und ich hatte mir full cash mit allen teuren für 4600 ap gekauft und das kostet 4800 ap was ist das? danke schonmal im vorraus
Wolfteam Special Edition Chars
07/05/2011 - Wolfteam - 7 Replies
Hallo com, Ich richte mich heute einer Umfrage in der er darum geht, wo man am besten die S.e Chars herbekommt. Eure Meinung zählt! (Glücksrad,Glücksschmiede.....)
*Special* [WTS 4x ZSZC WATER CHARS] *Special*
02/05/2011 - Silkroad Online Trading - 0 Replies
WTS 4x Chars on Privat Server ZSZC WATER. Glavier,Blader,Bower & Sword Shield Nuker WTS via direct Bank-Transfer. Char One: - Glavier Lv105 FF (Ice 60 / Light 90 / Fire 100 / Heuskel 102) - Set FB +5 - Glavie +7 max. FB / Shield +5 Dress & Grap Pet moved to other char Silk removed
Suche Char --> muss fun machen :D trapsen oder special chars...
09/09/2010 - Diablo 2 - 9 Replies
:) Wie schon gesagt...suche ein Full Char, der erstens nicht normaler schitt is : Hammerdin, java, ww barb, tornadodudu, summoner... trap und alle anderen sind erwünscht :). muss sc Ladder europe sein! ;) equip und char stats da lassen! entweder direkt auch Preis, oder wir können ja mal drüber reden :D Preis = fgs greetz Sunny-xt :)
S/T> Chars + Items /// T> 4 x 80 t8,5 geared wow chars for full 2soc chars
09/03/2009 - Conquer Online 2 Trading - 1 Replies
Chars: 130/130/131 Warrior/Warrior/Water Items: Super +9 2 soc Spear Super +3 2xSDG coat Super +6 2xSDG bow Super +4 tower/fan Bunch of random bullshit items.



All times are GMT +1. The time now is 20:46.


Powered by vBulletin®
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2025 elitepvpers All Rights Reserved.