From SolarStrike wiki
Jump to: navigation, search


Code posted here is considered Public Domain unless otherwise noted. Be aware of this before posting your code! You may release your code here only under the following licenses: Public Domain, BSD, GPL, or LGPL.

Random hash generator[edit]



Description: Generates a random filled hash containing numbers and (capitol) letters. It will generate and return a hash that is 'len' characters long. If 'len' is not specified, then a 32 character hash will be assumed.

Purpose: Random hashes are, often, used in place of passwords. It is considered more secure than storing a reversible hash simply because it cannot be reversed (as it contains no real information). For example, after a successful login, a server might generate a random hash for that specific user. The client (user) will now use the random hash for future authentication instead of the password.

License: Public Domain

Author: "Elverion"

-- Generates a random hash with the specified length.
-- If length is less than or equal to zero, or unspecified, 32 bytes will be assumed.
function random_hash(len)
  if( len == nil or len <= 0 ) then len = 32; end;
  local holder = ""; -- a string for holding our hash temporarily

  -- create an array of all acceptable characters that can be put in our hash.
  local hash_chars = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E",
                "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T",
                "U", "V", "W", "X", "Y", "Z"};

  for i = 1, len do
    local index = math.random(1, #hash_chars);
    holder = holder .. hash_chars[index];

  return holder;

memory Write String[edit]

memoryWriteString(proc, address, msg)

Description: Enters a string into memory.

Purpose: So strings can be written. Be sure not to write a string that's greater than the strings allocated memory.

License: Public Domain

Author: "zerosignal"

function memoryWriteString(proc, address, msg)
  local l_msg_len = msg:len()
  local l_char = nil;
  for i=0, (l_msg_len-1) do
    l_char = msg:byte(i)
    --debug_message("char: " .. l_char);
    memoryWriteByte(proc, address + i, l_char)
  memoryWriteByte(proc, address + l_msg_len, 0)

Experience per Hour[edit]

Description: Estimates the total experience in a hour. Can be extended for Gold, Kills or anything else.

License: Public Domain

Author: "Elverion"

local expGained = 0;
local startTime = os.time();
local lastAnnounce = os.time();

local lastTotalExp = 0;
while(true) do
  local newTotalExp = memoryReadInt(proc, experienceaddr, experience_offset);
  if( newTotalExp > lastTotalExp ) then
    expGained = expGained + (newTotalExp - lastTotalExp);
    lastTotalExp = newTotalExp;

  -- has 10 seconds elapsed? update the exp/min
  if( os.difftime(os.time(), lastAnnounce) > 10 ) then
    local timeElapsed = os.difftime(os.time(), startTime);
    local expPerMin = 0;
    if( timeElapsed == 0 ) then timeElapsed = 1; end; -- prevent division by zero

    expPerMin = expGained/(timeElapsed/60.0);
    lastAnnounce = os.time();
    printf("Exp/min: %0.1f\n" expPerMin);