Quote:
Originally Posted by go for it
if you got bit more of time please pm me or something letting me know bit more about encoding  thanks bud
|
When you read or write Strings (or chars), plain ASCII uses 1 byte (8 bits) for every char. With 1 byte you can represent 256 possible chars. First 128 are common (and english uses just that), and last 128 was used in past to represent different languages signs. For example:
- spanish "ñ" "Ñ" or "á" "é"...
- french "ç" "Ç" or "à" "è" ...
- german "ß" "ö" "ü"
Each code from 128 to 255 represents different chars depending on the language, so we need to use the appropriate PageCode to read not plain text; otherwise we will read weird symbols instead of the correct text.
Modern software uses UTF encoding (Universal character set Transformation Format), by using more than 1 byte to represent each character except the common ones (the first 128 from ASCII). There are several implementations of UTF (UTF7, UTF8, UTF16...), each one using different amount of data for each character. UTF8 is the most commonly used.
As our beloved games from TQ does not use UTF, we need to know if the files we want to use are just plain ASCII text (in case of english / international clients) or certain language. I'm playing Heroes of Might and Magic Online, which uses Simplified Chinese encoding; that means some text is readable (english one) and some text (chinese text) needs to be read with the right encoding ("GB18030" = Page Code 54936).
I saw a Conquer ItemType.dat file and found no weird text, all is plain ASCII, but it could depend on the client you use.
To avoid extra effort in programming, I declare 2 encoders as constants, and never use fixed encodings in my code; I use these constants. That way is a lot easier to extend the code usage in case I need to replace the encoding.
Code:
public static Encoding enc = Encoding.GetEncoding(54936);
public static Encoding asciiEnc = Encoding.ASCII;
If I need to read plain text, I use
asciiEnc; if I need to read chinese text, I use
enc.
I'm not sure what could I tell more, but ask anything you need...
EDIT: I almost forgot something that gave me headaches: In TextBox or Label you can use only plain text. To see another texts you need to use RichTextBox. The debugger in Visual Studio does not show rich text, so I thought for a long time my code was not working well...