This is a snippet I wrote for sourcepawn, but I won't use anymore.
Will convert Steam64 string to steam32 int
Don't even know if this will be of use for anyone.
This was built based on
this
PHP Code:
// 64 bit max is 19 numbers + 1 (for teminator)
#define MAX_STEAM64_LENGTH 20
// 11 numbers is the total numbers that the 32 bit can hold, lets make sure its less than that by 1.
// 10 + terminator
#define MAX_INTEGERS 11
stock bool GetSteam32FromSteam64(const char szSteam64Original[MAX_STEAM64_LENGTH], int &iSteam32)
{
char szSteam32[MAX_STEAM64_LENGTH];
char szSteam64[MAX_STEAM64_LENGTH];
// We don't want to actually edit the original string.
// We make a new string for the editing.
strcopy(szSteam64, sizeof szSteam64, szSteam64Original);
// Remove the first three numbers
ReplaceStringEx(szSteam64, sizeof(szSteam64), "765", "");
// Because pawn does not support numbers bigger than 2147483647, we will need to subtract using a combination of numbers.
// The combination can be
// 1 number to MAX_INTEGERS
char szSubtractionString[] = "61197960265728";
// First integer is the integer from szSteam64
// Second is from the subtraction string szSubtractionString
char szFirstInteger[MAX_INTEGERS], szSecondInteger[MAX_INTEGERS];
int iFirstInteger, iSecondInteger;
char szResultInt[MAX_INTEGERS];
// Ugly hack
// Make the strings 00000000000 so when we use StringToInt the zeroes won't affect the result
// sizeof - 1 because we need the last End of string (0) byte;
SetStringZeros(szFirstInteger, sizeof(szFirstInteger), sizeof(szFirstInteger) - 1);
SetStringZeros(szSecondInteger, sizeof(szSecondInteger), sizeof(szSecondInteger) - 1);
// Start from the end of the string, because subtraction should always start from the first number in the right.
int iResultInt;
int iSteam64Position = strlen(szSteam64);
int iIntegerPosition = strlen(szFirstInteger);
int iNumCount;
int iResultLen;
char szStringZeroes[MAX_INTEGERS];
while(--iSteam64Position > -1)
{
iIntegerPosition -= 1;
++iNumCount;
szFirstInteger[iIntegerPosition] = szSteam64[iSteam64Position];
szSecondInteger[iIntegerPosition] = szSubtractionString[iSteam64Position];
iFirstInteger = StringToInt(szFirstInteger);
iSecondInteger = StringToInt(szSecondInteger);
// Can we subtract without getting a negative number?
if(iFirstInteger >= iSecondInteger)
{
iResultInt = iFirstInteger - iSecondInteger;
// 69056897
PrintToServer("Subtract %s from %s = %d", szFirstInteger, szSecondInteger, iResultInt);
if(iResultInt)
{
IntToString(iResultInt, szResultInt, sizeof szResultInt);
if( iNumCount != (iResultLen = strlen(szResultInt) ) )
{
SetStringZeros(szStringZeroes, sizeof szStringZeroes, iNumCount - iResultLen);
}
else
{
szStringZeroes = "";
}
}
else
{
szResultInt = "";
SetStringZeros(szStringZeroes, sizeof szStringZeroes, iNumCount);
PrintToServer("String Zeroes: %s", szResultInt);
}
Format(szSteam32, sizeof szSteam32, "%s%s%s", szStringZeroes, szResultInt, szSteam32);
PrintToServer("Current Progress: %s", szSteam32);
// Reset our stuff.
SetStringZeros(szFirstInteger, sizeof(szFirstInteger), sizeof(szFirstInteger) - 1);
SetStringZeros(szSecondInteger, sizeof(szSecondInteger), sizeof(szSecondInteger) - 1);
iIntegerPosition = strlen(szFirstInteger);
iNumCount = 0;
}
if(iIntegerPosition - 1 < 0)
{
// We failed, and this calculation can not be done in pawn.
return false;
}
// if not, lets add more numbers.
}
iSteam32 = StringToInt(szSteam32);
return true;
}
void SetStringZeros(char[] szString, int iSize, int iNumZeros)
{
int i;
for(i = 0; i < iNumZeros && i < iSize; i++)
{
szString[i] = '0';
}
szString[i] = 0;
}
__________________