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?
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?