Try these two functions. Just wrote them then in like 3min, haven't tested
them. It allows you to send wchar_t strings.

All it really does is substitutes 0x00 for 0xFF. So you loose the use of
0x00FF and 0xFFFF characters.

I think I forgot to check for wchar_t string ending in the Encode function,
but I'm sure you can do it.

~Haza


void NetSafe16Encode( wchar_t *in, char *out )
{
        char ZeroByte = (char)0xFF;

        int out_counter = 0;
        for(int i = 0; i < (sizeof(in)/sizeof(wchar_t)); i++)
        {
                // Use bit shifting operations to clean up data.
                char right = (char)((in[i] << 8) >> 8);
                if( right == (char)0x00 )
                        right = ZeroByte;

                char left = (char)(in[i] >> 8);
                if( left == (char)0x00 )
                        left = ZeroByte;

                out[out_counter] = left;
                out_counter++;
                out[out_counter] = right;
                out_counter++;
        }
}

void NetSafe16DeEncode( char *in, wchar_t *out )
{
        char ZeroByte = (char)0xFF;

        int out_counter = 0;
        for(int i = 0; i < sizeof(in); i++)
        {
                unsigned short left;
                if(in[i] == ZeroByte)
                        left = 0x0000;
                else
                        left = ((unsigned short)in[i]) << 8;

                i++;

                unsigned short right;
                if(in[i] == ZeroByte)
                        right = 0x0000;
                else
                        right = ((unsigned short)in[i]);

                wchar_t final = (wchar_t)(left + right);

                out[out_counter] = final;

                out_counter++;
        }
}


_______________________________________________
To unsubscribe, edit your list preferences, or view the list archives, please 
visit:
http://list.valvesoftware.com/mailman/listinfo/hlcoders

Reply via email to