Skip to content

Instantly share code, notes, and snippets.

@McTwist
McTwist / uint.cs
Last active January 16, 2019 14:13
Unsigned Integer safe arithmetic operators
// ================
// Unsigned Integer safe arithemtic operators
// ================
// Author: McTwist
// Description: Safely operates unsigned integer numbers together
// License: Free to use
// ================
// Safely add two values together like they are unsigned
// Algorithm: https://forum.blockland.us/index.php?topic=248922.msg7177640#msg7177640
@McTwist
McTwist / isaac.cs
Last active February 16, 2018 10:20
ISAAC fast cryptographic random number generator
// ================
// ISAAC fast cryptographic random number generator
// ================
// Author: McTwist
// Description: Generates cryptographic safe random numbers
// License: Free to use
// Source: http://www.burtleburtle.net/bob/rand/isaacafa.html
// ================
// Init vars
@McTwist
McTwist / echos.cs
Last active November 15, 2017 12:46
A secure way to echo out strings in TorqueScript larger than 4095 characters
// Echo a huge string in a safe way
// Note: It will try to make the output consistent, but too long chunks with
// no newline will break the consistency
function echos(%str)
{
// Maximum amount of characters that can be output with normal echo
%max = 4095;
%len = strlen(%str);
for (%i = 0; %i < %len; %i += getMin(%size + 1, %max))
{

Keybase proof

I hereby claim:

  • I am mctwist on github.
  • I am mctwist (https://keybase.io/mctwist) on keybase.
  • I have a public key ASC5PRJewudjFa2Z5InRBTqnsBW5l0ueJlqTTvOfcI6Z2wo

To claim this, I am signing this object:

@McTwist
McTwist / num2str.cs
Created August 16, 2017 00:10
Correctly converts a number in TorqueScript to a string
// Converts a number to a string correctly
function num2str(%num)
{
if (mAbs(%num) < 1000000)
return "" @ %num;
if (%num < 0)
{
%neg = true;
%num = -%num;
}
@McTwist
McTwist / saver.cs
Created November 25, 2016 06:46
A saving system for Blockland where each user is his own file
// --------------------------
// Name: Saver
// Description: Database System
// Version: 1.5a
// Author: McTwist
// Copyright: Free for all
// License: Do not change anything
// --------------------------
// Notes
// No saving system is the same, but all saving systems is the other one alike.
@McTwist
McTwist / clone.cs
Last active March 1, 2018 23:48
Clones an object
// Clone current object
function SimObject::clone(%this, %name)
{
%this = %this.getID();
%oldName = %this.getName();
%name = %name !$= "" ? %name : %oldName;
%this.setName(__CLONE_OBJECT__);
%obj = new (%this.getClassName())(%name : __CLONE_OBJECT__);
%this.setName(%oldName);
return %obj;
@McTwist
McTwist / bind.cs
Last active November 14, 2017 09:59
Binds a key to a function
// Create a possible bind to a function. This will place it in respective division.
// If division and name is the same, it will replace the function.
function CreateBind(%division, %name, %cmd)
{
if (%name $= "" || %cmd $= "")
return;
%remapid = $remapCount;
%new = true;
@McTwist
McTwist / ini.cs
Created January 4, 2016 10:26
Parsing INI in TorqueScript
// ================
// INI Parser
// ================
// Author: McTwist
// Version: 1.0
// Description: Parses ini code in an easy way
// License: Free to use
// ================
// INI reading
@McTwist
McTwist / math.cs
Last active August 21, 2017 21:13
Simple math library for handling large numbers in TorqueScript
// ====================== //
// McTwist's Math library //
// ====================== //
// Version: 0.5 (prototype)
// Integer allowed only(Unless function tells otherwise)
// Note: Library is for demonstration only. Be aware that it might not be
// correct and performance may be horrible on some methods.
function Math::onAdd(%this)
{