I'm working on a short plugin that translates a huge 64bit number into two other values by bit shifting. The process works great on a scientific calculator, but I have been unable to accomplish the task using Sourcemod.
The test code I developed will freeze the server and the client without providing any errors. I believe the number I'm using is too large for the '[EXTENSION] BigInteger compute with large numbers' that I installed. Link:
https://forums.alliedmods.net/showthread.php?t=233938
Goal:
Given an input number of 5848670506169059306
It should produce a lowseed value of: 2021836778
It should also produce a highseed value of: 1361749718
Basically this is what I'm trying to achieve:
PHP Code:
seed := 5848670506169059306
high := seed >> 32
low := (seed << 32) >> 32
fmt.Println("Seed is: ", seed)
fmt.Println("Seed low is: ", low)
fmt.Println("Seed high is: ", high)
However, that's not easy to do in Sourcemod. If the number is in fact too large for the BigInteger extension, how can I achieve the desired results without the extension?
Sourcemod code so far:
PHP Code:
#include <bigint>
#pragma semicolon 1
#pragma newdecls required
#define PLUGIN_VERSION "1.0"
public Plugin myinfo =
{
name = "[TF2] Test of seed import and translation",
author = "PC Gamer",
description = "Test importing large number with BigInt",
version = PLUGIN_VERSION,
url = "www.sourcemod.com"
}
public void OnPluginStart()
{
RegConsoleCmd("sm_seed", Command_TestBigInt);
}
public Action Command_TestBigInt(int client, int args)
{
char arg1[32];
if (args < 1)
{
ReplyToCommand(client, "seed <seed number>");
ReplyToCommand(client, "Example: seed 5848670506169059306");
return Plugin_Handled;
}
GetCmdArg(1, arg1, sizeof(arg1));
Handle hBigInt = BigInt_CreateFromString(arg1);
Handle hNewBigIntLow = BigInt_BitShiftRight(BigInt_BitShiftLeft(hBigInt, 32), 32);
Handle hNewBigIntHigh = BigInt_BitShiftLeft(hBigInt, 32);
int lowseed = BigInt_ToInt(hNewBigIntLow); //expected result 2021836778
int highseed = BigInt_ToInt(hNewBigIntHigh); //expected result: 1361749718
PrintToChat(client, "Input seed provided by client: %s", arg1);
PrintToChat(client, "Seed translates into: lowseed: %i, highseed: %i", lowseed, highseed);
delete hBigInt;
delete hNewBigIntLow;
delete hNewBigIntHigh;
return Plugin_Handled;
}