protected void DrawString(int a, byte[] msg)
{
var buf = new byte[270];
int i, c;
int fontHeight;
uint color;
ConvertMessageToString(msg, buf, 0);
_charset.Top = _string[a].Position.Y + ScreenTop;
_charset.StartLeft = _charset.Left = _string[a].Position.X;
_charset.Right = _string[a].Right;
_charset.Center = _string[a].Center;
_charset.SetColor(_string[a].Color);
_charset.DisableOffsX = _charset.FirstChar = true;
_charset.SetCurID(_string[a].Charset);
if (_game.Version >= 5)
Array.Copy(_charsetData[_charset.GetCurId()], CharsetColorMap, 4);
fontHeight = _charset.GetFontHeight();
if (Game.Version >= 4)
{
// trim from the right
int tmpPos = 0;
int spacePos = 0;
while (buf[tmpPos] != 0)
{
if (buf[tmpPos] == ' ')
{
if (spacePos == 0)
spacePos = tmpPos;
}
else
{
spacePos = 0;
}
tmpPos++;
}
if (spacePos != 0)
{
buf[spacePos] = 0;
}
}
if (_charset.Center)
{
_charset.Left -= _charset.GetStringWidth(a, buf, 0) / 2;
}
if (buf[0] == 0)
{
if (_game.Version >= 5)
{
buf[0] = (byte)' ';
buf[1] = 0;
}
else
{
_charset.Str.Left = _charset.Left;
_charset.Str.Top = _charset.Top;
_charset.Str.Right = _charset.Left;
_charset.Str.Bottom = _charset.Top;
}
}
for (i = 0; (c = buf[i++]) != 0;)
{
if (c == 0xFF || (_game.Version <= 6 && c == 0xFE))
{
c = buf[i++];
switch (c)
{
case 9:
case 10:
case 13:
case 14:
i += 2;
break;
case 1:
case 8:
if (_charset.Center)
{
_charset.Left = _charset.StartLeft - _charset.GetStringWidth(a, buf, i);
}
else
{
_charset.Left = _charset.StartLeft;
}
if ((Game.Platform != Platform.FMTowns) && (_string[0].Height != 0))
{
_nextTop += _string[0].Height;
}
else
{
_charset.Top += fontHeight;
}
break;
case 12:
color = (uint)(buf[i] + (buf[i + 1] << 8));
i += 2;
if (color == 0xFF)
_charset.SetColor(_string[a].Color);
else
_charset.SetColor((byte)color);
break;
}
}
else
{
//if ((c & 0x80) != 0 && _useCJKMode)
//{
// if (checkSJISCode(c))
// c += buf[i++] * 256;
//}
_charset.PrintChar(c, true);
_charset.BlitAlso = false;
}
}
if (a == 0)
{
_nextLeft = _charset.Left;
_nextTop = _charset.Top;
}
_string[a].Position = new Point(_charset.Str.Right, _string[a].Position.Y);
}