So basically, here's the problem: I'm trying to read a save file for a game that I didn't make myself. I have been able to read in things such as strings and boolean variables (simply by using Unicode chars to compare to the strings). However, I come across problems when I try to read little-endian encoded 32-bit integers. Here's the code I have right now:

Code: Select all
private int littleEndianToDecimal(string hexStart)
{
int result = 0;
char[] hex = hexStart.ToCharArray();
uint[] dec = new uint[4];
for (int iii = 0; iii < dec.Length; iii++)
dec[iii] = hex[iii];
MessageBox.Show(dec[0].ToString() + " " + dec[1].ToString() + " " + dec[2].ToString() + " " +
dec[3].ToString());
if (dec[3] < 128)
result = (int)(dec[3] * 16777216 + dec[2] * 65536 + dec[1] * 256 + dec[0]);
else
{
uint[] invDec = new uint[4];
for (int iii = 0; iii < invDec.Length; iii++)
invDec[iii] = (~(uint)dec[iii]) + 1;
result = -1 * (int)(invDec[3] * 16777216 + invDec[2] * 65536 + invDec[1] * 256 + invDec[0]);
}
MessageBox.Show(result.ToString());
return result;
}



The string "hexStart" contains the characters I scan in. The idea is to convert them to their Unicode hex values, so becomes FF or 255. However, upon casting it to an integer, for some reason values such as FF become 65533 and whatnot, rather than their default Unicode hex values. Also, the message boxes are only in there for debugging purposes and will not be included in the final version.

If anyone has any ideas on why this isn't working or any sort of script that will accomplish the same task in a better manner, the help would be much appreciated. Thanks!