[Release] Getting/Writing correct strings

09/11/2011 01:11 12tails#1
Yo... simple way to fix chat/name strings:

BTW: I dunno if it was already posted here... so if it was ... sorry for the inconvenience :]

Code:
    public class StringPacker
    {
        public static string GetString(byte[] array, int offset, int count)
        {
            string pszWords = "";
            for (int x = offset; x < offset + count; x++)
            {
                if (x >= array.Length)
                    break;
                if (array[x] < 128)
                    pszWords += Convert.ToChar(array[x]);
                else
                    pszWords += Encoding.Unicode.GetString(
                        new byte[2] { array[x], 0 });
            }
            return pszWords;
        }
    }
excample using it on chat:
Code:
            int iPos = 26;
            pszSpeaker = StringPacker.GetString(iMsg, iPos, iMsg[25]); iPos = 27 + pszSpeaker.Length;
            pszHearer = StringPacker.GetString(iMsg, iPos, iMsg[iPos - 1]); iPos = 29 + pszSpeaker.Length + pszHearer.Length;
            pszWords = StringPacker.GetString(iMsg, iPos, iMsg[iPos - 1]);
example to write:

Code:
                    for (int i = 0; i < Args.Length; i++)
                        Buffer[(ushort)(i + Offset)] = (byte)Args[i];
cya!
09/11/2011 02:03 .Beatz#2
Good release... As always 12tails ;)
09/11/2011 08:55 Spirited#3
That... is so incredibly inefficient...
This thread needs to be deleted... that's such a bad example...
09/11/2011 16:33 pro4never#4
Why not just reverse the netStringPacker from euds source?... Makes it way, way simpler.

Example usages...

Code:
public string Speaker
        {
            get
            {
                string value;
                return StringPacker.GetString(0, out value) ? value : null;
            }
            set { StringPacker.SetString(0, value); }
        }

        public string Hearer
        {
            get
            {
                string value;
                return StringPacker.GetString(1, out value) ? value : null;
            }
            set { StringPacker.SetString(1, value); }
        }

        public string Emotion
        {
            get
            {
                string value;
                return StringPacker.GetString(2, out value) ? value : null;
            }
            set { StringPacker.SetString(2, value); }
        }

        public string Words
        {
            get
            {
                string value;
                return StringPacker.GetString(3, out value) ? value : null;
            }
            set { StringPacker.SetString(3, value); }
        }
It's lovely.


Tq strings have a counted number of strings. Net string packer is their own code they wrote to manage this system storing each string as its own string offset which lets you easily read, write or modify these strings.

Euds source is wonderful for finding all sorts of things like that.
09/11/2011 16:56 12tails#5
i'm checking it right now :]