Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

HI I WAS BABIED MY ENTIRE LIFE

Name: Anonymous 2008-02-07 14:01

I'm pretty new to programming, and I've only worked with .NET thusfar. My friend wants me to hack some code into a C# game client. I extracted the source with Reflector and made the changes, but there is one unsafe bit I cannot get to compile, having never worked with C++ or any languages that use pointers:

        public static unsafe void Append(string value, ref uint crc)
        {
            if (m_Table == null)
            {
                m_Table = GenerateTable();
            }
            fixed (uint* numRef = m_Table)
            {
                fixed (char* str = ((char*) value))
                {
                    char* chPtr = str;
                    byte* numPtr = (byte*) chPtr;
                    byte* numPtr2 = numPtr + (value.Length * 2);
                    while (numPtr < numPtr2)
                    {
                        numPtr++;
                        uint index = (crc & 0xff) ^ numPtr[0];
                        crc = crc >> 8;
                        crc ^= numRef[index];
                    }
                }
            }
        }

I know it doesn't work because it's trying to cast a string to a char*, but I don't know how exactly to get this entire block working. I assume I need to convert the string into an array of char POINTERS (somehow :<) and go from there.

Can anyone help?

Name: Anonymous 2008-02-07 14:03

>>1
Your code is O(∞), please read SICP and come back.

Name: Anonymous 2008-02-07 14:05

O MEME SPAMS WASNT EXPECTIN THAT

Name: Anonymous 2008-02-07 14:15

>>3
>>2 is sound advice, by the way, there is a loop in your code.

Name: Anonymous 2008-02-07 14:18

Is there any way I can fix it without reading the entirety of SICP?

;/

Name: Anonymous 2008-02-07 14:43

>>1
Did you compile with /unsafe?

Name: Anonymous 2008-02-07 14:46

Yes. The problem is the implicit cast from string to char*. I know I need to convert the string to a char array, and while I have some understanding of how to do it normally, I don't have any idea how to do it whilst working with pointers.

Name: Anonymous 2008-02-07 14:48

>>7
I see no implicit cast like that, just an explicit one. Which line are you referring to, and what errors are you getting?

Name: Anonymous 2008-02-07 14:50

I meant explicit. Sorry.

fixed (char* str = ((char*) value))

...is the bit that is causing the error, which reads as follows:

Error    4    Cannot convert type 'string' to 'char*'    C:\Documents and Settings\Owner\My Documents\Source\Network\CENSORED\Hash.cs    39    36    Network

Name: Anonymous 2008-02-07 14:52

Easy solution, convert the code into a less S&M language.

Name: Anonymous 2008-02-07 14:54

I am just trying to get a Reflector-extracted program to compile for a friend, not looking to go all-out.

Name: Anonymous 2008-02-07 14:55

>>9
Try fixed (char* str = ((char*) value.toCharArray())) instead

Name: Anonymous 2008-02-07 15:05

Tried that earlier, and got this error:

Error    4    Cannot convert type 'char[]' to 'char*'    C:\Documents and Settings\Owner\My Documents\Source\Network\Sallos\Hash.cs    39    37    Network

Name: Anonymous 2008-02-07 15:33

Try an implicit cast, see what it does: fixed (char* str = value)

Name: Anonymous 2008-02-07 15:55

>>14
Thank you.

Name: Anonymous 2008-02-07 17:27

DON'T HELP HIM

Name: Anonymous 2008-02-07 17:43

>>16
Too late

Name: Anonymous 2008-02-07 18:07

HELP HIM

Name: Anonymous 2008-02-07 23:15

HURT HIM

Don't change these.
Name: Email:
Entire Thread Thread List