Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Sapp and Phasor Compatibility Module
- -- Created by Wizard
- -- Add this line to the end of your script to use this module:
- -- _G = require"PhasorSappCompatibility"
- local sapp_version = "1.7.0.0"
- local phasor_version = 200
- _SERVERAPP = cb and say_all and "Sapp" or getrandomnumber and isinvehicle and "Phasor" --or error("Dafuq? What server app are you using?") -- easiest way
- _GAME = _SERVERAPP == "Sapp" and halo_type or readbyte and readbyte(0x630E78) == 7 and "PC" or "CE" -- skillz
- local _G = _G -- so the main script can't change this.
- -- Localized functions.
- local random, abs = math.random, abs
- local type = type
- local clock, time = os.clock, os.time
- local concat = table.concat
- local gmatch, char, byte, match, find, format, lower, sub, gsub = string.gmatch, string.char, string.byte, string.match, string.find, string.format, string.lower, string.sub, string.gsub
- local orig_xpcall = xpcall
- local real_register_callback = register_callback
- -- Lua Version Compatibility Definitions.
- bit = not bit32 and require"bit" or bit32
- bit32 = bit32 or bit
- getfenv = getfenv or function(f)
- f = (type(f) == 'function' and f or debug.getinfo(f + 1, 'f').func)
- local name, val
- local up = 0
- repeat
- up = up + 1
- name, val = debug.getupvalue(f, up)
- until name == '_ENV' or name == nil
- return val
- end
- math.atan = math.atan or math.atan2
- math.atan2 = math.atan2 or math.atan
- math.ldexp = math.ldexp or function(x, exp) return x * 2.0^exp end
- math.log10 = math.log10 or function(num) return math.log(num, 10) end
- package.loaders = package.loaders or package.searchers
- package.searchers = package.loaders
- load = load or loadstring
- loadstring = loadstring or load
- table.maxn = table.maxn or (
- function(t)
- local maxval = 0
- for key,value in next,t do
- if type(key) == "number" and key > maxval then
- maxval = key
- end
- end
- return maxval
- end
- )
- setfenv = setfenv or function(f, t)
- f = (type(f) == 'function' and f or debug.getinfo(f + 1, 'f').func)
- local name
- local up = 0
- repeat
- up = up + 1
- name = debug.getupvalue(f, up)
- until name == '_ENV' or name == nil
- if name then
- debug.upvaluejoin(f, up, function() return name end, 1) -- use unique upvalue
- debug.setupvalue (f, up, t)
- end
- end
- table.getn = table.getn or function(t) return rawlen(t) end
- table.unpack = table.unpack or unpack
- unpack = unpack or table.unpack
- xpcall = _SERVERAPP == "Sapp" and function(f, msgh, ...) local args = {...} return orig_xpcall(function() f(unpack(args)) end, msgh) end or xpcall
- local function WriteLog(filename, logStr)
- local file = assert(io.open(filename, "a"))
- file:write(string.format("%s\t%s\n", os.date "%Y/%m/%d %H:%M:%S", logStr))
- file:close()
- end
- local function ypcall(func, ...)
- if type(func) ~= "function" then
- return nil
- end
- local success,result1,result2 = xpcall(func, function(err) print(debug.traceback(err)) end, ...)
- if success == false and type(result1) == "string" then
- local err = "Error in " .. result1
- WriteLog(getprofilepath() .. "\\logs\\ScriptLogs.log", err)
- hprintf(err)
- pcall(OnError, result1)
- end
- return result1, result2
- end
- -- Private variables.
- local prevent_join = {}
- local player_scores = {}
- local timers = {}
- local svcmd_echo
- local dont_doublecall_onvehicleeject
- local dont_doublecall_onvehicleentry
- local safe_read_val = false
- local safe_write_val = false
- cb = cb or {
- EVENT_TICK = 1,
- EVENT_ALIVE = 2,
- EVENT_AREA_ENTER = 3,
- EVENT_AREA_EXIT = 4,
- EVENT_PRESPAWN = 5,
- EVENT_SPAWN = 6,
- EVENT_KILL = 7,
- EVENT_DIE = 8,
- EVENT_SNAP = 9,
- EVENT_WARP = 10,
- EVENT_WEAPON_PICKUP = 11,
- EVENT_WEAPON_DROP = 12,
- EVENT_VEHICLE_ENTER = 13,
- EVENT_VEHICLE_EXIT = 14,
- EVENT_BETRAY = 15,
- EVENT_SUICIDE = 16,
- EVENT_SCORE = 17,
- EVENT_TEAM_SWITCH = 18,
- EVENT_JOIN = 19,
- EVENT_LEAVE = 20,
- EVENT_CAMP = 21,
- EVENT_LOGIN = 22,
- EVENT_GAME_START = 23,
- EVENT_GAME_END = 24,
- EVENT_CHAT = 25,
- EVENT_COMMAND = 26,
- EVENT_ECHO = 27,
- EVENT_OBJECT_SPAWN = 28,
- }
- local phasorEvents = {
- OnScriptLoad = OnScriptLoad or true,
- OnNewGame = OnNewGame or true,
- OnGameEnd = OnGameEnd or true,
- OnServerChat = OnServerChat or true,
- OnServerCommandAttempt = OnServerCommandAttempt or true,
- OnServerCommand = OnServerCommand or true,
- OnNameRequest = OnNameRequest or true,
- OnBanCheck = OnBanCheck or true,
- OnPlayerJoin = OnPlayerJoin or true,
- OnPlayerLeave = OnPlayerLeave or true,
- OnPlayerKill = OnPlayerKill or true,
- OnKillMultiplier = OnKillMultiplier or true,
- OnPlayerSpawn = OnPlayerSpawn or true,
- OnPlayerSpawnEnd = OnPlayerSpawnEnd or true,
- OnWeaponAssignment = OnWeaponAssignment or true,
- OnWeaponReload = OnWeaponReload or true,
- OnObjectCreationAttempt = OnObjectCreationAttempt or true,
- OnObjectCreation = OnObjectCreation or true,
- OnObjectInteraction = OnObjectInteraction or true,
- OnTeamDecision = OnTeamDecision or true,
- OnTeamChange = OnTeamChange or true,
- OnDamageLookup = OnDamageLookup or true,
- OnDamageApplication = OnDamageApplication or true,
- OnVehicleEntry = OnVehicleEntry or true,
- OnVehicleEject = OnVehicleEject or true,
- }
- local events
- events = {
- [cb.EVENT_TICK] = {
- register = function(funcname)
- if _SERVERAPP == "Phasor" then
- -- This won't work if you want to literally use it for like checking if someone is crouched (actually, it might depending on how Phasor timers work), but should imitate the behavior well enough
- local tick_id = registertimer(33, "__tick_event")
- function __tick_event(id)
- if tick_id ~= id then return false end
- ypcall(_G[funcname])
- return true
- end
- else
- function __clientupdate_event()
- local playerId, playerObjId, m_playerObj, weaponObjId, m_weaponObj, weapstate
- for playerIndex = 1,16 do
- playerId = to_real_index(playerIndex)
- if playerId == -1 then goto continue end
- playerObjId = getplayerobjectid(playerId)
- m_playerObj = get_object_memory(playerObjId)
- if m_playerObj == 0 then goto continue end
- if OnClientUpdate then OnClientUpdate(playerId, playerObjId) end
- if not OnWeaponReload then goto continue end
- weaponObjId = read_dword(m_playerObj + 0x118)
- m_weaponObj = get_object_memory(weaponObjId)
- if m_weaponObj == 0 then goto continue end
- weapstate = read_byte(m_weaponObj + 0x238)
- if weapstate == 5 or weapstate == 6 then
- OnWeaponReload(playerId, weaponObjId) -- Not possible to block this yet.
- end
- ::continue::
- end
- ypcall(_G[funcname])
- end
- real_register_callback(cb.EVENT_TICK, "__clientupdate_event")
- end
- end
- },
- [cb.EVENT_ALIVE] = {
- register = function(funcname)
- if _SERVERAPP == "Phasor" then
- local __alive_id = registertimer(1000, "__alivetimer")
- function __alivetimer(id)
- if __alive_id ~= id then return false end
- for playerId = 0,15 do
- if getplayer(playerId) and getobject(getplayerobjectid(playerId)) then
- ypcall(_G[funcname], playerIndex)
- end
- end
- return true
- end
- else
- real_register_callback(cb.EVENT_ALIVE, funcname)
- end
- end,
- },
- [cb.EVENT_AREA_ENTER] = {
- register = function(funcname)
- if _SERVERAPP == "Phasor" then
- events[cb.EVENT_AREA_ENTER][1] = funcname
- else
- real_register_callback(cb.EVENT_AREA_ENTER, funcname)
- end
- end
- },
- [cb.EVENT_AREA_EXIT] = {
- register = function(funcname)
- if _SERVERAPP == "Phasor" then
- events[cb.EVENT_AREA_EXIT][1] = funcname
- else
- real_register_callback(cb.EVENT_AREA_EXIT, funcname)
- end
- end
- },
- [cb.EVENT_PRESPAWN] = {
- register = function(funcname)
- if _SERVERAPP == "Phasor" then
- function OnPlayerSpawn(playerId, playerObjId)
- playerObjId = playerObjId or getplayerobjectid(playerId)
- if __orig_spawn_event then __orig_spawn_event(playerId, playerObjId) end
- local playerIndex = resolveplayer(playerId)
- if events[cb.EVENT_WEAPON_PICKUP][1] then
- local m_playerObj = getobject(playerObjId)
- for slot = 0,3 do
- if getobject(readdword(m_playerObj + 0x2F8+slot*4)) then
- ypcall(_G[events[cb.EVENT_WEAPON_PICKUP][1]], playerIndex, slot+1, 1)
- end
- end
- end
- ypcall(_G[funcname], playerIndex)
- end
- else
- function __onspawn_event(playerIndex)
- if prevent_join[playerIndex] then
- return nil
- end
- local playerId = to_real_index(playerIndex)
- local playerObjId = getplayerobjectid(playerId)
- ypcall(phasorEvents.OnPlayerSpawn, playerId, playerObjId)
- if phasorEvents.OnWeaponAssignment then
- local m_playerObj = get_object_memory(playerObjId)
- local m_weaponObj, mapId, result, weaponObjId
- for slot = 0,3 do
- weaponObjId = read_dword(m_playerObj + 0x2F8 + slot*4)
- m_weaponObj = get_object_memory(weaponObjId)
- mapId = m_weaponObj and read_dword(m_weaponObj)
- if mapId then
- result = ypcall(phasorEvents.OnWeaponAssignment, playerId, playerObjId, slot, mapId)
- if result == false then
- destroy_object(weaponObjId)
- elseif tonumber(result) then
- destroy_object(weaponObjId)
- assign_weapon(playerIndex, spawn_object("", "", 1, 2, 3, 0, tonumber(result)))
- end
- end
- end
- end
- end
- real_register_callback(cb.EVENT_PRESPAWN, "__onspawn_event")
- end
- end,
- },
- [cb.EVENT_SPAWN] = {
- register = function(funcname)
- if _SERVERAPP == "Phasor" then
- function OnPlayerSpawnEnd(playerId, playerObjId)
- ypcall(phasorEvents.OnPlayerSpawnEnd, playerId, playerObjId)
- ypcall(_G[funcname], resolveplayer(playerId))
- end
- else
- function __onspawnend_event(playerIndex)
- if prevent_join[playerIndex] then
- return nil
- end
- local playerId = to_real_index(playerIndex)
- ypcall(phasorEvents.OnPlayerSpawnEnd, playerId, getplayerobjectid(playerId))
- ypcall(_G[funcname], playerIndex)
- end
- real_register_callback(cb.EVENT_SPAWN, "__onspawnend_event")
- end
- end
- },
- [cb.EVENT_KILL] = {
- dependencies = {cb.EVENT_DIE},
- register = function(funcname)
- if _SERVERAPP == "Phasor" then
- events[cb.EVENT_KILL][1] = funcname
- else
- real_register_callback(cb.EVENT_KILL, funcname)
- end
- end,
- },
- [cb.EVENT_DIE] = {
- register = function(funcname)
- if _SERVERAPP == "Phasor" then
- function OnPlayerKill(killerPlayerId, victimPlayerId, mode)
- ypcall(phasorEvents.OnPlayerKill, killerPlayerId, victimPlayerId, mode)
- local killerPlayerIndex, victimPlayerIndex = killerPlayerId and resolveplayer(killerPlayerId), resolveplayer(victimPlayerId)
- if mode == 5 then
- ypcall(_G[events[cb.EVENT_BETRAY][1]], killerPlayerIndex, victimPlayerIndex)
- elseif mode == 6 then
- ypcall(_G[events[cb.EVENT_SUICIDE][1]], victimPlayerIndex)
- end
- ypcall(_G[events[cb.EVENT_DIE][1]], victimPlayerIndex)
- if killerPlayerId then
- ypcall(_G[events[cb.EVENT_KILL][1]], killerPlayerId, victimPlayerId)
- end
- end
- else
- -- Broken: Falling kill vs server kill.
- function __kill_event(victim, killer)
- if prevent_join[playerIndex] then
- return nil
- end
- local mode
- local kteam, vteam
- local victimPlayerId = to_real_index(victim) -- should always be valid
- local killerPlayerId = to_real_index(killer)
- killerPlayerId = killerPlayerId ~= -1 and killerPlayerId or nil
- if killer == "-1" then
- mode = 1 -- Server kill OR FALL DAMAGE since that's broken
- elseif killer == "guardians" then
- mode = 2 -- Guardian kill
- elseif killer == 0 then
- mode = 3 -- Killed by a vehicle
- else
- goto finishRemaining
- end
- goto OnPlayerKillCall
- ::finishRemaining::
- kteam = killerPlayerId and getteam(killerPlayerId)
- vteam = getteam(victimPlayerId)
- if victimPlayerId == killerPlayerId then
- mode = 6 -- Suicide
- elseif victimPlayerId ~= killerPlayerId and vteam ~= kteam then
- mode = 4 -- Killed by another player.
- if OnKillMultiplier then
- local multiplier = 0
- local m_kplayer = get_player(killer)
- local multikill = read_word(m_kplayer + 0x98)
- local spree = read_word(m_kplayer + 0x96)
- if multikill == 2 or multikill == 16 then
- multiplier = 7 -- Double Kill.
- elseif multikill == 3 or multikill == 15 then
- multiplier = 9 -- Triple Kill.
- elseif spree == 5 then
- multiplier = 11 -- Killing Spree.
- elseif spree == 10 or (spree ~= 0 and spree % 5 == 0) then
- multiplier = 12 -- Running Riot.
- elseif multikill >= 4 then
- multiplier = 10 -- Killtacular.
- else
- goto OnPlayerKillCall
- end
- OnKillMultiplier(killerPlayerId, multiplier)
- end
- elseif victimPlayerId ~= killerPlayerId and vteam == kteam then
- mode = 5 -- Betrayed
- end
- ::OnPlayerKillCall::
- if ypcall(phasorEvents.OnPlayerKill, killerPlayerId, victimPlayerId, mode) == false then
- -- thanks 002 for the silent kill code
- local m_player = get_player(victim)
- timer(0, "__ResetPlayerKill", m_player, read_word(m_player + 0xD4))
- write_word(m_player + 0xD4, 0xFFFF)
- end
- ypcall(_G[funcname], victim, killer)
- end
- function __ResetPlayerKill(m_player, old_value)
- write_word(m_player + 0xD4, old_value)
- return false
- end
- real_register_callback(cb.EVENT_DIE, "__kill_event")
- end
- end
- },
- [cb.EVENT_SNAP] = {
- register = function(funcname)
- if _SERVERAPP == "Phasor" then
- events[cb.EVENT_SNAP][1] = funcname
- else
- real_register_callback(cb.EVENT_SNAP, funcname)
- end
- end
- },
- [cb.EVENT_WARP] = {
- register = function(funcname)
- if _SERVERAPP == "Phasor" then
- events[cb.EVENT_WARP][1] = funcname
- else
- real_register_callback(cb.EVENT_WARP, funcname)
- end
- end
- },
- [cb.EVENT_WEAPON_PICKUP] = {
- dependencies = {cb.EVENT_PRESPAWN},
- register = function(funcname)
- local weapons = {[0]={}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}}
- local playerObjId, m_playerObj, weaponObjId, thisWeaponEntry, frags, plasmas, playerIndex
- local pickup_id = registertimer(500, "__weaponCheckTimer")
- function __weaponCheckTimer(id, count)
- if pickup_id ~= id then return false end
- for playerId = 0,15 do
- if not getplayer(playerId) then
- goto resetweapons
- end
- playerObjId = getplayerobjectid(playerId)
- m_playerObj = getobject(playerObjId)
- if not m_playerObj then
- goto resetweapons
- end
- playerIndex = resolveplayer(playerId)
- thisWeaponEntry = weapons[playerId]
- for slot = 1,4 do
- weaponObjId = readdword(m_playerObj + 0x2F8 + (slot-1)*4)
- if thisWeaponEntry[slot] ~= weaponObjId then
- if thisWeaponEntry[slot] then
- if weaponObjId ~= 0xFFFFFFFF then
- ypcall(_G[events[cb.EVENT_WEAPON_DROP][1]], playerIndex, slot, 1)
- elseif thisWeaponEntry[slot] ~= 0xFFFFFFFF then
- ypcall(_G[events[cb.EVENT_WEAPON_DROP][1]], playerIndex, slot, 1)
- ypcall(_G[funcname], playerIndex, slot, 1)
- else
- ypcall(_G[funcname], playerIndex, slot, 1)
- end
- end
- thisWeaponEntry[slot] = weaponObjId
- end
- end
- frags = readbyte(m_playerObj + 0x31E)
- if thisWeaponEntry[5] ~= frags then
- if thisWeaponEntry[5] then
- for i = (thisWeaponEntry[5] or 0),frags do
- ypcall(_G[funcname], playerIndex, 2, 2)
- end
- end
- thisWeaponEntry[5] = frags
- end
- plasmas = readbyte(m_playerObj + 0x31F)
- if thisWeaponEntry[6] ~= plasmas then
- if thisWeaponEntry[6] then
- for i = (thisWeaponEntry[6] or 0),plasmas do
- ypcall(_G[funcname], playerIndex, 2, 2)
- end
- end
- thisWeaponEntry[6] = plasmas
- end
- goto continue
- ::resetweapons::
- thisWeaponEntry = weapons[playerId]
- if next(thisWeaponEntry) then
- for slot = 1,6 do
- thisWeaponEntry[slot] = nil
- end
- end
- ::continue::
- end
- ::endFunc::
- return true
- end
- end
- },
- [cb.EVENT_WEAPON_DROP] = {
- dependencies = {cb.EVENT_WEAPON_PICKUP},
- register = function(funcname)
- if _SERVERAPP == "Phasor" then
- events[cb.EVENT_WEAPON_DROP][1] = funcname
- else
- real_register_callback(cb.EVENT_WEAPON_DROP, funcname)
- end
- end
- },
- [cb.EVENT_VEHICLE_ENTER] = {
- register = function(funcname)
- if _SERVERAPP == "Phasor" then
- function OnVehicleEntry(playerId, __, seat)
- ypcall(phasorEvents.OnVehicleEntry, playerId, __, seat)
- ypcall(_G[funcname], resolveplayer(playerId), seat)
- end
- else
- -- Hacky: Player can drive the vehicle for a whole 2 seconds before the script can eject them.
- function __vehicleentry_event(playerIndex, seat)
- if prevent_join[playerIndex] then
- return nil
- end
- local vehicleObjId = read_dword(get_dynamic_player(playerIndex) + 0x11C)
- if ypcall(phasorEvents.OnVehicleEntry, to_real_index(playerIndex), vehicleObjId, seat, read_dword(get_object_memory(vehicleObjId)), true) == false then
- timer(2000, "__prevententry", playerIndex)
- else
- ypcall(_G[funcname], playerIndex, seat)
- end
- function __prevententry(playerIndex)
- dont_doublecall_onvehicleeject = true
- exit_vehicle(playerIndex)
- dont_doublecall_onvehicleeject = false
- return false
- end
- end
- real_register_callback(cb.EVENT_VEHICLE_ENTER, "__vehicleentry_event")
- end
- end
- },
- [cb.EVENT_VEHICLE_EXIT] = {
- register = function(funcname)
- if _SERVERAPP == "Phasor" then
- function OnVehicleEject(playerId)
- ypcall(phasorEvents.OnVehicleEject, playerId)
- ypcall(_G[funcname], resolveplayer(playerId))
- end
- else
- -- Broken: No way to determine if the player is being forcibly ejected or not.
- -- Hacky: Puts player back in vehicle after 1 second.
- function __vehicleexit_event(playerIndex)
- if prevent_join[playerIndex] then
- return nil
- end
- local m_playerObj = get_dynamic_player(playerIndex)
- local seat = read_word(m_playerObj + 0x120)
- if ypcall(phasorEvents.OnVehicleEject, to_real_index(playerIndex), seat) == false then
- timer(1000, "__preventejection", vehicleObjId, playerIndex, read_word(m_playerObj + 0x120))
- else
- ypcall(_G[funcname], playerIndex)
- end
- end
- function __preventejection(vehicleObjId, playerIndex, seat)
- dont_doublecall_onvehicleentry = true
- enter_vehicle(vehicleObjId, playerIndex, seat)
- dont_doublecall_onvehicleentry = false
- return false
- end
- real_register_callback(cb.EVENT_VEHICLE_EXIT, "__vehicleexit_event")
- end
- end
- },
- [cb.EVENT_BETRAY] = {
- dependencies = {cb.EVENT_DIE},
- register = function(funcname)
- if _SERVERAPP == "Phasor" then
- events[cb.EVENT_BETRAY][1] = funcname
- else
- real_register_callback(cb.EVENT_BETRAY, funcname)
- end
- end
- },
- [cb.EVENT_SUICIDE] = {
- dependencies = {cb.EVENT_DIE},
- register = function(funcname)
- if _SERVERAPP == "Phasor" then
- events[cb.EVENT_SUICIDE][1] = funcname
- else
- real_register_callback(cb.EVENT_SUICIDE, funcname)
- end
- end
- },
- [cb.EVENT_SCORE] = {
- register = function(funcname)
- local function getscore(playerId)
- if gametype == 1 then
- return readshort(getplayer(playerId) + 0xC8)
- elseif gametype == 2 then
- return readint((_GAME == "PC" and 0x63A0E8 or 0x5BE108) + 0x40+playerId*4)
- elseif gametype == 3 then
- return readint((_GAME == "PC" and 0x639E58 or 0x5BDE78) + 0x84+playerId*4)
- elseif gametype == 4 then
- return readshort(getplayer(playerId) + 0xC4)
- elseif gametype == 5 then
- return readshort(getplayer(playerId) + 0xC6)
- end
- end
- local score_timer_id = registertimer(1000, "__OnPlayerScoreCheck")
- function __OnPlayerScoreCheck(id, count)
- if score_timer_id ~= id then return false end
- for playerId = 0,15 do
- if getplayer(playerId) then
- local score = getscore(playerId)
- if score ~= player_scores[playerId] then
- ypcall(_G[funcname], resolveplayer(playerId))
- player_scores[playerId] = score
- end
- end
- end
- return true
- end
- end
- },
- [cb.EVENT_TEAM_SWITCH] = {
- register = function(funcname)
- if _SERVERAPP == "Phasor" then
- function OnTeamChange(playerId, old_team, new_team, relevant)
- ypcall(phasorEvents.OnTeamChange, playerId, old_team, new_team, relevant)
- ypcall(_G[funcname], resolveplayer(playerId))
- end
- else
- function __teamchange_event(playerIndex)
- local playerId = to_real_index(playerIndex)
- local new_team = getteam(playerId)
- local old_team = abs(old_team - 1)
- -- Broken: No way to check if this can be blocked (team switch in escape menu) vs command-executed.
- -- A solution is to assume it always can be blocked and use our method of blocking it.
- if ypcall(phasorEvents.OnTeamChange, playerId, old_team, new_team, false) == false then
- write_byte(get_player(playerIndex) + 0x20, old_team)
- end
- ypcall(_G[funcname], playerIndex)
- end
- real_register_callback(cb.EVENT_TEAM_SWITCH, "__teamchange_event")
- end
- end
- },
- [cb.EVENT_JOIN] = {
- register = function(funcname)
- if _SERVERAPP == "Phasor" then
- function OnPlayerJoin(playerId)
- ypcall(phasorEvents.OnPlayerJoin, playerId)
- ypcall(_G[funcname], resolveplayer(playerId))
- end
- else
- -- Broken: No way to change name OnNameRequest
- -- Hacky: Player is banned onplayerjoin, so they will still enter the server for a brief minute.
- function __onjoin_event(playerIndex)
- local team = get_var(playerIndex, "$team")
- local new_team = tonumber(ypcall(phasorEvents.OnTeamDecision, team))
- if new_team and team ~= new_team then
- write_byte(get_player(playerIndex) + 0x20, new_team)
- end
- local hash = get_var(playerIndex, "$hash")
- if ypcall(phasorEvents.OnNameRequest, hash, get_var(playerIndex, "$name")) == false then
- write_word(get_player(playerIndex) + 0x2C, 0x7FFF) -- Don't let them spawn.
- local msg = "Your name is not allowed in this server. Please leave and change it."
- say(msg, playerIndex)
- rprint(msg, playerIndex)
- prevent_join[playerIndex] = true -- Prevents the player from spawning, etc in scripts code.
- end
- if ypcall(phasorEvents.OnBanCheck, hash, get_var(playerIndex, "$ip")) == false then
- execute_command("sv_ban " .. playerIndex .. " 1s")
- prevent_join[playerIndex] = true -- Prevents the player from spawning, etc in scripts code.
- end
- if prevent_join[playerIndex] then
- return nil
- end
- ypcall(phasorEvents.OnPlayerJoin, to_real_index(playerIndex), new_team)
- ypcall(_G[funcname], playerIndex)
- end
- real_register_callback(cb.EVENT_JOIN, "__onjoin_event")
- end
- end
- },
- [cb.EVENT_LEAVE] = {
- register = function(funcname)
- if _SERVERAPP == "Phasor" then
- function OnPlayerLeave(playerId)
- ypcall(phasorEvents.OnPlayerLeave, playerId)
- ypcall(_G[funcname], resolveplayer(playerId))
- end
- else
- function __playerleave_event(playerIndex)
- if prevent_join[playerIndex] then
- prevent_join[playerIndex] = nil
- return nil
- end
- ypcall(phasorEvents.OnPlayerLeave, to_real_index(playerIndex))
- ypcall(_G[funcname], playerIndex)
- end
- real_register_callback(cb.EVENT_LEAVE, "__playerleave_event")
- end
- end
- },
- [cb.EVENT_CAMP] = {
- register = function(funcname)
- if _SERVERAPP == "Phasor" then
- events[cb.EVENT_WARP][1] = funcname
- else
- real_register_callback(cb.EVENT_WARP, funcname)
- end
- end
- },
- [cb.EVENT_LOGIN] = {
- register = function(funcname)
- if _SERVERAPP == "Phasor" then
- events[cb.EVENT_WARP][1] = funcname
- else
- real_register_callback(cb.EVENT_WARP, funcname)
- end
- end
- },
- [cb.EVENT_GAME_START] = {
- register = function(funcname)
- if _SERVERAPP == "Phasor" then
- function OnNewGame(map)
- ypcall(phasorEvents.OnNewGame, map)
- ypcall(_G[funcname])
- end
- else
- function __newgame_event()
- ypcall(phasorEvents.OnNewGame, get_var(0, "$map"))
- ypcall(_G[funcname])
- end
- real_register_callback(cb.EVENT_GAME_START, "__newgame_event")
- end
- end
- },
- [cb.EVENT_GAME_END] = {
- register = function(funcname)
- if _SERVERAPP == "Phasor" then
- local ongameend_called
- function OnGameEnd(mode)
- ypcall(phasorEvents.OnGameEnd, mode)
- if not ongameend_called then
- ypcall(_G[funcname])
- ongameend_called = true
- end
- end
- else
- -- I don't even need to explain how hacky this is, but suprisingly it works perfectly.
- function __gameend_event()
- OnGameEnd(1)
- ypcall(_G[funcname])
- function __OnGameEndTimer1() OnGameEnd(2) end
- function __OnGameEndTimer2() OnGameEnd(3) end
- timer(7000, "__OnGameEndTimer1")
- timer(12000, "__OnGameEndTimer2")
- end
- real_register_callback(cb.EVENT_GAME_END, "__gameend_event")
- end
- end
- },
- [cb.EVENT_CHAT] = {
- register = function(funcname)
- if _SERVERAPP == "Phasor" then
- function OnServerChat(playerId, chattype, message)
- if playerId and chattype ~= 4 then
- local response = ypcall(phasorEvents.OnServerChat, playerId, chattype, message)
- response = response ~= false and ypcall(_G[funcname], to_player_index(playerId), message)
- end
- end
- else
- -- Broken: No way to modify messages
- -- Broken: No way to determine what TYPE of message is being passed.
- function __serverchat_event(playerIndex, message)
- if message:sub(1, 5) ~= "/lead" and message:sub(1, 5) ~= "\\lead" then
- local response = ypcall(phasorEvents.OnServerChat, to_real_index(playerIndex), 0, message)
- response = response ~= false and ypcall(_G[funcname], playerIndex, message)
- end
- end
- real_register_callback(cb.EVENT_CHAT, "__serverchat_event")
- end
- end
- },
- [cb.EVENT_COMMAND] = {
- register = function(funcname)
- local function respond(message)
- if env == 0 then
- cprint(message)
- elseif env == 1 then
- rprint(playerIndex, message)
- elseif env == 2 then
- say(playerIndex, message)
- elseif getplayer(playerId) then
- sendconsoletext(playerId, message)
- else
- hprintf(message)
- end
- end
- if _SERVERAPP == "Phasor" then
- local sappattemptcalled = true
- function OnServerCommandAttempt(playerId, command, password)
- local respond = respond
- local result = ypcall(phasorEvents.OnServerCommandAttempt, playerId, command, password)
- local playerIndex = resolveplayer(playerId)
- local result2 = ypcall(_G[funcname], playerIndex, command, playerId and 1 or 0, password)
- sappattemptcalled = true
- if result ~= false then
- return result or result2
- end
- return false
- end
- local __orig_command_event = __OnServerCommand
- function OnServerCommand(playerId, command)
- local respond = respond
- local result = ypcall(phasorEvents.OnServerCommand, playerId, command)
- if sappattemptcalled then
- sappattemptcalled = nil
- return result
- end
- local playerIndex = resolveplayer(playerId)
- ypcall(_G[funcname], playerIndex, command, playerId and 1 or 0, _GAME == "PC" and read_string(0x69BA5C8) or read_string(0x61FC8C8))
- end
- else
- function __command_event(playerIndex, command, env, rcon)
- local respond = respond
- local playerId = to_real_index(playerIndex) or -1
- playerId = playerId ~= -1 and playerId or nil
- local result
- if env == 1 then
- if _GAME == "PC" and read_string(0x69BA5C8) == rcon or read_string(0x61FC8C8) == rcon then
- result = ypcall(phasorEvents.OnServerCommand, playerId, command)
- elseif ypcall(phasorEvents.OnServerCommandAttempt, playerId, command, rcon) then
- result = ypcall(phasorEvents.OnServerCommand, playerId, command)
- end
- else
- result = ypcall(OnServerCommand, playerId, command)
- end
- if result ~= false then
- return result or ypcall(_G[funcname], playerIndex, command, env, rcon)
- end
- end
- real_register_callback(cb.EVENT_COMMAND, "__command_event")
- end
- end
- },
- [cb.EVENT_ECHO] = {
- register = function(funcname)
- if _SERVERAPP == "Phasor" then
- events[cb.EVENT_ECHO][1] = funcname
- else
- function __echo_event(playerIndex, output)
- ypcall(_G[funcname], playerIndex, output)
- if svcmd_echo then
- svcmd_echo = svcmd_echo .. "\n" .. output
- end
- end
- real_register_callback(cb.EVENT_ECHO, "__echo_event")
- end
- end
- },
- [cb.EVENT_OBJECT_SPAWN] = {
- register = function(funcname)
- if _SERVERAPP == "Phasor" then
- function OnObjectCreationAttempt(mapId, parentObjId, playerId)
- ypcall(phasorEvents.OnObjectCreationAttempt, mapId, parentObjId, playerId)
- ypcall(_G[funcname], resolveplayer(playerId), mapId, parentObjId, readword(0x4005062C + 0x32) * 0x10000 + readword(0x4005062C + 0x2C))
- end
- else
- function __objectcreate_event(playerIndex, mapId, parentObjId, objectId)
- if prevent_join[playerIndex] then
- return nil
- end
- local playerId = to_real_index(playerIndex)
- playerId = playerId ~= -1 and playerId or nil
- local response = ypcall(phasorEvents.OnObjectCreationAttempt, mapId, parentObjId, playerId)
- if response ~= false then -- don't call onobjectcreation if the attempt was terminated.
- response = ypcall(phasorEvents.OnObjectCreation, objectId) ~= false and tonumber(response)
- end
- if response ~= false then
- local response2 = ypcall(_G[funcname], playerIndex, mapId, parentObjId, objectId)
- if response2 ~= false then
- response = response2 or response
- else
- response = false
- end
- end
- if response then
- return true,response
- elseif response ~= false and not playerId and parentObjId ~= 0xFFFFFFFF then
- local response2 = ypcall(phasorEvents.OnWeaponAssignment, playerId, parentObjId, 0, mapId)
- if response2 ~= false then
- response = response2 or response
- else
- response = false
- end
- end
- return response
- end
- real_register_callback(cb.EVENT_OBJECT_SPAWN, "__objectcreate_event")
- end
- end
- },
- }
- --[==[local eventsMT = {
- __call = function(self, a,b,c,d,e,f,g)
- for i = 1,#self do
- _G[self[i]](a,b,c,d,e,f,g)
- end
- end
- }
- for k,v in next,events do
- setmetatable(v, eventsMT)
- end]==]
- -- Private functions
- function events:Create(event, funcname)
- funcname = funcname ~= "##INTERNAL_ONLY##" and funcname
- -- Register our event.
- self[#self+1] = funcname
- self.register(funcname)
- -- Create dependencies.
- local dependencies = self.dependencies
- local dependency, dependencyEvent
- local newBlankFuncStr
- if dependencies then
- for i = 1,#dependencies do dependency = dependencies[i]
- dependencyEvent = events[dependency]
- -- Only create the event dependency if it isn't already created.
- if not dependencyEvent[1] then
- newBlankFuncStr = "__" .. funcname
- events.Create(dependencyEvent, dependency, newBlankFuncStr)
- _G[newBlankFuncStr] = function() end
- end
- end
- end
- end
- local function registerPhasorEvents()
- -- bool OnObjectInteraction (halo::s_player &player, halo::ident objid, halo::ident mapid)
- -- Called when a player interacts with an object (ie stands on it)
- -- bool OnDamageLookup (halo::s_damage_info *dmg, void *metaData, halo::ident receiver, halo::damage_script_options &out)
- -- Called when the server needs to apply damage to an object.
- -- bool OnDamageApplication (const halo::s_damage_info *dmg, halo::ident receiver, const halo::s_hit_info *hit, bool backtap)
- -- Called when the server is about to apply damage to an object.
- local nonexistant_func = "##INTERNAL_ONLY##"
- register_callback(cb.EVENT_ECHO, nonexistant_func)
- if OnServerChat then
- register_callback(cb.EVENT_CHAT, nonexistant_func)
- end
- if OnTeamDecision or OnNameRequest or OnBanCheck or OnPlayerJoin then
- register_callback(cb.EVENT_JOIN, nonexistant_func)
- end
- if OnWeaponReload or OnClientUpdate then
- register_callback(cb.EVENT_TICK, nonexistant_func)
- end
- if OnGameEnd then
- register_callback(cb.EVENT_GAME_END, nonexistant_func)
- end
- if OnNewGame then
- register_callback(cb.EVENT_GAME_START, nonexistant_func)
- end
- if OnKillMultiplier or OnPlayerKill then
- register_callback(cb.EVENT_DIE, nonexistant_func)
- end
- if OnObjectCreation or OnObjectCreationAttempt or OnWeaponAssignment then
- register_callback(cb.EVENT_OBJECT_SPAWN, nonexistant_func)
- end
- if OnPlayerLeave then
- register_callback(cb.EVENT_LEAVE, nonexistant_func)
- end
- if OnPlayerSpawn or OnWeaponAssignment then
- register_callback(cb.EVENT_PRESPAWN, nonexistant_func)
- end
- if OnPlayerSpawnEnd then
- register_callback(cb.EVENT_SPAWN, nonexistant_func)
- end
- if OnServerCommand or OnServerCommandAttempt then
- register_callback(cb.EVENT_COMMAND, nonexistant_func)
- end
- if OnTeamChange then
- register_callback(cb.EVENT_TEAM_SWITCH, nonexistant_func)
- end
- if OnVehicleEntry then
- register_callback(cb.EVENT_VEHICLE_ENTER, nonexistant_func)
- end
- if OnVehicleEject then
- register_callback(cb.EVENT_VEHICLE_EXIT, nonexistant_func)
- end
- end
- local __say = say
- local kill = kill
- local function trim(str)
- return gsub(str, "^[%c%s]*(.-)[%c%s]*$", "%1") or str
- end
- -- Definitions for All Phasor Functions
- GetRequiredVersion = GetRequiredVersion or function() return phasor_version end
- required_version = phasor_version
- applycamo = applycamo or ( -- Good
- function(playerId, duration)
- local playerIndex = to_player_index(playerId)
- assert(playerIndex ~= 0, "invalid player id")
- camo(playerIndex, duration * 30)
- end
- )
- applydmg = applydmg -- Not in Sapp.
- applydmgtag = applydmgtag -- Not in Sapp.
- assignweapon = assignweapon or ( -- Good
- function(playerId, objectId)
- local playerIndex = to_player_index(playerId)
- assert(playerIndex ~= 0, "invalid player id")
- return assign_weapon(objectId, playerIndex)
- end
- )
- changeteam = changeteam or ( -- Good
- function(playerId, bKill)
- local playerIndex = to_player_index(playerId)
- assert(playerIndex ~= 0, "invalid player id")
- local m_player = get_player(playerIndex)
- local team = read_byte(m_player + 0x20)
- local new_team = abs(team - 1)
- if not OnTeamChange2 or OnTeamChange2(playerId, team, new_team, true) ~= false then
- write_byte(m_player + 0x20, new_team)
- if bKill then kill(playerIndex) end
- end
- end
- )
- createobject = createobject or ( -- Good
- function(mapId, parentObjId, respawn_time, bRecycle, x, y, z)
- local objectId = spawn_object("", "", x, y, z, 0, mapId)
- return objectId ~= 0 and objectId or nil
- end
- )
- destroyobject = destroyobject or ( -- Good
- function(objectId)
- assert(getobject(objectId), "invalid object id")
- destroy_object(objectId)
- end
- )
- entervehicle = entervehicle or ( -- Good
- function(playerId, objectId, seat)
- local playerIndex = to_player_index(playerId)
- assert(playerIndex ~= 0, "invalid player id")
- assert(getobject(objectId), "invalid object id")
- return enter_vehicle(objectId, playerIndex, seat) or nil
- end
- )
- exitvehicle = exitvehicle or ( -- Good
- function(playerId)
- local playerIndex = to_player_index(playerId)
- assert(playerIndex ~= 0, "invalid player id")
- exit_vehicle(playerIndex)
- end
- )
- gethash = gethash or ( -- Good
- function(playerId)
- local playerIndex = to_player_index(playerId)
- assert(playerIndex ~= 0, "invalid player id")
- local result = get_var(playerIndex, "$hash")
- return result ~= 0 and result or nil
- end
- )
- getip = getip or ( -- Good
- function(playerId)
- local playerIndex = to_player_index(playerId)
- assert(playerIndex ~= 0, "invalid player id")
- local network_machine_pointer = _GAME == "PC" and 0x745BA0 or 0x6C7980
- local network_pointer = read_dword(read_dword(read_dword(read_dword(network_machine_pointer) + 0xAA0 + read_byte(get_player(playerIndex) + 0x64)*4)))
- assert(network_pointer ~= 0, "'getip' cannot be used in OnPlayerLeave or EVENT_LEAVE")
- return format("%i.%i.%i.%i", read_byte(network_pointer), read_byte(network_pointer + 0x1), read_byte(network_pointer + 0x2), read_byte(network_pointer + 0x3)) -- Player's IP Address (127.0.0.1 if host)
- end
- )
- getname = getname or ( -- Good
- function(playerId)
- local playerIndex = to_player_index(playerId)
- assert(playerIndex ~= 0, "invalid player id")
- local result = get_var(playerIndex, "$name")
- return result ~= 0 and result or nil
- end
- )
- getobject = getobject or ( -- Good
- function(objectId)
- local m_object = get_object_memory(objectId)
- return m_object ~= 0 and m_object or nil
- end
- )
- getobjectcoords = getobjectcoords or ( -- Good
- function(objectId)
- local m_object = get_object_memory(objectId)
- assert(m_object ~= 0, "invalid object id")
- local m_vehicleObj = get_object_memory(read_dword(m_object + 0x11C))
- if m_vehicleObj ~= 0 then
- m_object = m_vehicleObj
- end
- return read_vector3d(m_object + 0x5C)
- end
- )
- getplayer = getplayer or ( -- Good
- function(playerId)
- playerId = tonumber(playerId)
- if not playerId then
- return nil
- end
- local playerIndex = to_player_index(playerId)
- if prevent_join[playerIndex] then return nil end
- local result = get_player(to_player_index(playerId))
- return result ~= 0 and read_dword(result) ~= 0 and result or nil
- end
- )
- getplayerobjectid = getplayerobjectid or ( -- Good
- function(playerId)
- local playerIndex = to_player_index(playerId)
- assert(playerIndex ~= 0, "invalid player id")
- return read_dword(get_player(playerIndex) + 0x34)
- end
- )
- getport = getport or ( -- Good
- function(playerId)
- local playerIndex = to_player_index(playerId)
- assert(playerIndex ~= 0, "invalid player id")
- return read_word(read_dword(read_dword(read_dword(read_dword(_GAME == "PC" and 0x745BA0 or 0x6C7980) + 0xAA0 + read_byte(get_player(playerIndex) + 0x64)*4))) + 0x4)
- end
- )
- getprofilepath = getprofilepath or ( -- Good
- function()
- return (_GAME == "PC" and read_string(0x635610) or read_string(0x5B9630) or "") .. "\\"
- end
- )
- getrandomnumber = getrandomnumber or rand or math.randomseed(clock() + time()) and random(1,2) and random(3,5) and random(8,13) and ( -- Good
- function(min, max)
- if min > max then
- min, max = max, min
- end
- return random(min, max+1)
- end
- )
- gettagaddress = gettagaddress or ( -- Good
- function(a, b)
- local tag = lookup_tag(a, b)
- return tag ~= 0 and read_dword(tag + 0x14) or nil
- end
- )
- gettagid = gettagid or ( -- Good
- function(a, b)
- local tag = lookup_tag(a, b)
- return tag ~= 0 and read_dword(tag + 0xC) or nil
- end
- )
- gettaginfo = gettaginfo or ( -- Good
- function(a)
- local tag = lookup_tag(a, b)
- return tag ~= 0 and read_string(read_dword(tag + 0x10)), read_string(tag)
- end
- )
- getteam = getteam or ( -- Good
- function(playerId)
- local playerIndex = to_player_index(playerId)
- assert(playerIndex ~= 0, "invalid player id")
- local m_player = get_player(playerIndex)
- return read_byte(m_player + 0x20) or nil
- end
- )
- getteamsize = getteamsize or ( -- Good
- function(team)
- local counter = 0
- for playerIndex = 1,16 do
- if player_present(playerIndex) and get_var(playerIndex, "$team") == team then
- counter = counter + 1
- end
- end
- return counter
- end
- )
- getticks = getticks or function() return clock() * 1000 end -- Good
- halointersect = halointersect or ( -- Good
- function(dist, x, y, z, vx, vy, vz, objectId)
- return intersect(x, y, z, vx*dist, vy*dist, vz*dist, objectId)
- end
- )
- hprintf = hprintf or print -- Good
- isinvehicle = isinvehicle or ( -- Good
- function(playerId)
- local playerIndex = to_player_index(playerId)
- assert(playerIndex ~= 0, "invalid player id")
- local m_playerObj = get_object_memory(read_dword(get_player(playerIndex) + 0x34))
- return m_playerObj ~= 0 and get_object_memory(read_dword(m_playerObj + 0x11C)) ~= 0
- end
- )
- phasorkill = _SERVERAPP == "Phasor" and kill or ( -- Annoying workaround.
- function(playerId)
- kill(to_player_index(playerId))
- end
- )
- log_msg = log_msg -- Not in Sapp.
- lookuptag = lookuptag or ( -- Good
- function(a)
- local tag = lookup_tag(a)
- return tag ~= 0 and read_dword(tag+0x14) or nil
- end
- )
- movobjectcoords = movobjectcoords or moveobjcoords or moveobjectcoords or movobjcoords or ( -- Good
- function(objectId, x, y, z)
- local m_object = get_object_memory(objectId)
- assert(m_object ~= 0, "invalid object id")
- local m_vehicleObj = get_object_memory(read_dword(m_object + 0x11C))
- write_vector3d( (m_vehicleObj ~= 0 and m_vehicleObj or m_object) + 0x5C, x, y, z)
- end
- )
- objectidtoplayer = objectidtoplayer or ( -- Good
- function(objectId)
- local m_object = get_object_memory(objectId)
- assert(m_object ~= 0, "invalid object id")
- local playerId = read_word(m_object + 0xC0)
- return to_player_index(playerId) ~= 0 and playerId or nil
- end
- )
- odl_causer = odl_causer -- Not in sapp.
- odl_flags = odl_flags -- Not in sapp.
- odl_multiplier = odl_multiplier -- Not in sapp.
- odl_receiver = odl_receiver -- Not in sapp.
- odl_tag = odl_tag -- Not in sapp.
- privatesay = privatesay or ( -- Good
- function(playerId, message)
- local playerIndex = to_player_index(playerId)
- assert(playerIndex ~= 0, "invalid player id")
- if not find(message, "\n") then
- return say(message, playerIndex)
- else
- local strTable = tokenizestring(message, "\n")
- for i = 1,#strTable do
- say(strTable[i], playerIndex)
- end
- end
- end
- )
- raiseerror = error -- Good
- readbit = readbit or read_bit and ( -- Good
- function(address, offset, bit)
- address = assert(tonumber(address), "bad argument #1 to 'readbit' expected number, got " .. type(address))
- if not bit then
- bit = assert(tonumber(offset), "bad argument #2 to 'readbit' expected number, got " .. type(offset))
- offset = 0
- else
- offset = assert(tonumber(offset), "bad argument #2 to 'readbit' expected number, got " .. type(offset))
- bit = assert(tonumber(bit), "bad argument #3 to 'readbit' expected number, got " .. type(bit))
- end
- safe_read(true)
- local res = bit32.band(read_byte(address + offset + math.floor(bit / 8)), bit) ~= 0
- safe_read(safe_read_val)
- return res
- end
- )
- readbyte = readbyte or ( -- Good
- function(address, offset)
- address = assert(tonumber(address), "bad argument #1 to 'readbyte' expected number, got " .. type(address))
- offset = assert(not offset or tonumber(offset), "bad argument #2 to 'readbyte' expected number, got " .. type(offset))
- safe_read(true)
- local res = read_byte(address + (offset == true and 0 or offset))
- safe_read(safe_read_val)
- return res
- end
- )
- readchar = readchar or ( -- Good
- function(address, offset)
- address = assert(tonumber(address), "bad argument #1 to 'readchar' expected number, got " .. type(address))
- offset = assert(not offset or tonumber(offset), "bad argument #2 to 'readchar' expected number, got " .. type(offset))
- safe_read(true)
- local res = read_char(address + (offset == true and 0 or offset))
- safe_read(safe_read_val)
- return res
- end
- )
- readword = readword or ( -- Good
- function(address, offset)
- address = assert(tonumber(address), "bad argument #1 to 'readword' expected number, got " .. type(address))
- offset = assert(not offset or tonumber(offset), "bad argument #2 to 'readword' expected number, got " .. type(offset))
- safe_read(true)
- local res = read_word(address + (offset == true and 0 or offset))
- safe_read(safe_read_val)
- return res
- end
- )
- readshort = readshort or ( -- Good
- function(address, offset)
- address = assert(tonumber(address), "bad argument #1 to 'readshort' expected number, got " .. type(address))
- offset = assert(not offset or tonumber(offset), "bad argument #2 to 'readshort' expected number, got " .. type(offset))
- safe_read(true)
- local res = read_short(address + (offset == true and 0 or offset))
- safe_read(safe_read_val)
- return res
- end
- )
- readdword = readdword or ( -- Good
- function(address, offset)
- address = assert(tonumber(address), "bad argument #1 to 'readdword' expected number, got " .. type(address))
- offset = assert(not offset or tonumber(offset), "bad argument #2 to 'readdword' expected number, got " .. type(offset))
- safe_read(true)
- local res = read_dword(address + (offset == true and 0 or offset))
- safe_read(safe_read_val)
- return res
- end
- )
- readint = readint or ( -- Good
- function(address, offset)
- address = assert(tonumber(address), "bad argument #1 to 'readint' expected number, got " .. type(address))
- offset = assert(not offset or tonumber(offset), "bad argument #2 to 'readint' expected number, got " .. type(offset))
- safe_read(true)
- local res = read_int(address + (offset == true and 0 or offset))
- safe_read(safe_read_val)
- return res
- end
- )
- readfloat = readfloat or ( -- Good
- function(address, offset)
- address = assert(tonumber(address), "bad argument #1 to 'readfloat' expected number, got " .. type(address))
- offset = assert(not offset or tonumber(offset), "bad argument #2 to 'readfloat' expected number, got " .. type(offset))
- safe_read(true)
- local res = read_float(address + (offset == true and 0 or offset))
- safe_read(safe_read_val)
- return res
- end
- )
- readdouble = readdouble or ( -- Good
- function(address, offset)
- address = assert(tonumber(address), "bad argument #1 to 'readdouble' expected number, got " .. type(address))
- offset = assert(not offset or tonumber(offset), "bad argument #2 to 'readdouble' expected number, got " .. type(offset))
- safe_read(true)
- local res = read_double(address + (offset == true and 0 or offset))
- safe_read(safe_read_val)
- return res
- end
- )
- readstring = read_string and ( -- Good
- function(a, l)
- a = assert(tonumber(a), "bad argument #1 to 'readstring' expected number, got '" .. type(a) .. "'")
- l = assert(not l or tonumber(l), "bad argument #2 to 'readstring' expected number, got '" .. type(l) .. "'")
- safe_read(true)
- local str = read_string(a)
- safe_read(safe_read_val)
- return str and sub(str, 1, l or #str)
- end
- ) or (
- function(address, length)
- address = assert(tonumber(address), "bad argument #1 to 'readstring' expected number, got '" .. type(address) .. "'")
- length = assert(not length or tonumber(length), "bad argument #2 to 'readstring' expected number, got '" .. type(length) .. "'")
- local char_table = {}
- local newByte
- safe_read(true)
- for i = 0,(length == true and 256 or length)-1 do
- newByte = read_byte(address + i)
- if newByte == 0 or newByte == 255 then break end
- char_table[#char_table+1] = char(newByte)
- end
- safe_read(safe_read_val)
- return concat(char_table)
- end
- )
- readwidestring = read_wide_string and ( -- Good
- function(a, l)
- a = assert(tonumber(a), "bad argument #1 to 'readstring' expected number, got '" .. type(a) .. "'")
- l = assert(not l or tonumber(l), "bad argument #2 to 'readstring' expected number, got '" .. type(l) .. "'")
- safe_read(true)
- local str = read_wide_string(a)
- safe_read(safe_read_val)
- return str and sub(str, 1, l or #str)
- end
- ) or (
- function(address, length)
- address = assert(tonumber(address), "bad argument #1 to 'readwidestring' expected number, got '" .. type(address) .. "'")
- length = assert(not length or tonumber(length), "bad argument #2 to 'readwidestring' expected number, got '" .. type(length) .. "'")
- local char_table = {}
- local newByte
- safe_read(true)
- for i = 0,(length == true and 51001 or length)-1,2 do
- newByte = read_byte(address + i)
- if newByte == 0 or newByte == 255 or read_byte(address + i+1) ~= 0 then break end
- char_table[#char_table+1] = char(newByte)
- end
- safe_read(safe_read_val)
- return concat(char_table)
- end
- )
- registertimer = registertimer or ( -- Good
- function(delay, funcname, arg)
- local id = #timers+1
- timers[id] = funcname
- timer(delay, "__" ..funcname)
- local count = 0
- _G["__" .. funcname] = (
- function()
- if not timers[id] then return false end
- count = count + 1
- local response = ypcall(_G[funcname], id, count, arg)
- if response == false then
- timers[id] = nil
- end
- return response
- end
- )
- return id
- end
- )
- resolveplayer = resolveplayer or ( -- Good
- function(playerId)
- local playerIndex = to_player_index(playerId)
- return playerIndex ~= 0 and playerIndex or nil
- end
- )
- rresolveplayer = rresolveplayer or ( -- Good
- function(playerIndex)
- local playerId = to_real_index(playerIndex)
- return playerId ~= 0 and playerId or nil
- end
- )
- removetimer = removetimer or ( -- Good
- function(id)
- if id then -- just ignore invalid timer ids
- timers[id] = nil
- end
- end
- )
- respond = respond or function() end -- Good. (real function in onservercommand event)
- say = function(a, b) -- Good
- if tonumber(b) then
- if _SERVERAPP == "Phasor" then
- privatesay(a, rresolveplayer(b))
- else
- __say(b, a)
- end
- elseif b == false then
- if _SERVERAPP == "Sapp" then
- execute_command('say_prefix false')
- __say(a)
- execute_command('say_prefix true')
- else
- __say(a, false)
- end
- elseif b == true or b == nil then
- if _SERVERAPP == "Phasor" then
- __say(a)
- elseif not find(a, "\n") then
- say_all(a)
- else
- local strTable = tokenizestring(a, "\n")
- for i = 1,#strTable do
- say_all(strTable[i])
- end
- end
- end
- end
- sendconsoletext = sendconsoletext or ( -- Good
- function(playerId, message)
- rprint(to_player_index(playerId), message)
- end
- )
- setspeed = setspeed or (
- function(playerId, speed)
- local playerIndex = to_player_index(playerId)
- assert(playerIndex ~= 0, "invalid player id")
- speed = assert(tonumber(speed), "bad argument #2 to 'setspeed' expected number, got " .. type(speed))
- write_float(get_player(playerIndex) + 0x6C, speed)
- end
- )
- svcmd = svcmd or ( -- Good
- function(a, bResult)
- if a ~= "reload" and a ~= "lua_unload" and a ~= "lua_load" then
- bResult = not not bResult
- svcmd_echo = bResult and ""
- execute_command(a, 0, bResult)
- bResult = type(svcmd_echo) == "string" and tokenizestring(svcmd_echo, "\n") or nil
- svcmd_echo = false
- return bResult
- end
- end
- )
- svcmdplayer = svcmdplayer or ( -- Good
- function(a, playerId, bResult)
- if a ~= "reload" and a ~= "lua_unload" and a ~= "lua_load" then
- svcmd_echo = bResult and ""
- execute_command(a, to_player_index(playerId), not not bResult)
- bResult = type(svcmd_echo) == "string" and tokenizestring(svcmd_echo, "\n") or nil
- svcmd_echo = false
- return bResult
- end
- end
- )
- tokenizestring = tokenizestring or ( -- Good
- function(str, ...)
- local subs = {}
- if (...) == "" then
- for i = 1,#str do
- subs[#subs+1] = sub(str, i, i)
- end
- return subs
- end
- local strPart = ""
- local char, iter, delim
- for i = 1,#str do
- char = sub(str, i, i)
- iter = 1
- delim = select(iter, ...)
- repeat
- if delim == char then
- strPart = sub(strPart, 1, -1)
- if strPart ~= "" then
- subs[#subs+1] = strPart
- strPart = ""
- goto continue
- end
- end
- iter = iter + 1
- delim = select(iter, ...)
- until not delim or delim == select(-1, ...)
- strPart = strPart .. char
- ::continue::
- end
- if strPart ~= "" then
- subs[#subs+1] = strPart
- end
- return subs
- end
- )
- tokenizecmdstring = tokenizecmdstring or ( -- Good
- function(str)
- --remove spaces at beginning and end
- str = trim(str) .. " "
- local strParts = {}
- -- return if no delims found
- if not find(str, '[%s"]') then strParts[1] = str return strParts end
- local strPart, newPos, pos
- repeat
- strPart,newPos = match(str, '^"(.-)"%s+()', pos)
- if not strPart then
- strPart,newPos = match(str, '([^%s]+)%s+()', pos)
- end
- pos = newPos
- strParts[#strParts+1] = strPart
- until not strPart
- ::returnSplits::
- return strParts
- end
- )
- updateammo = updateammo or ( -- Good
- function(objectId)
- assert(get_object_memory(objectId) ~= 0, "invalid object id")
- sync_ammo(objectId)
- end
- )
- writebit = writebit or write_bit and ( -- Good
- function(address, offset, bit, val)
- address = assert(tonumber(address), "bad argument #1 to 'writebit' expected number, got " .. type(address))
- if not val then
- val = assert(tonumber(bit), "bad argument #3 to 'writebit' expected number, got " .. type(bit))
- bit = assert(tonumber(offset), "bad argument #2 to 'writebit' expected number, got " .. type(offset))
- offset = 0
- else
- offset = assert(tonumber(offset), "bad argument #2 to 'writebit' expected number, got " .. type(offset))
- val = assert(tonumber(val), "bad argument #4 to 'writebit' expected number, got " .. type(val))
- end
- offset = offset + math.floor((bit+1)/8)
- safe_write(true)
- write_bit(address + offset, bit, value)
- safe_write(false)
- end
- )
- writebyte = writebyte or ( -- Good
- function(address, offset, value)
- address = assert(tonumber(address), "bad argument #1 to 'writebyte' expected number, got " .. type(address))
- offset = assert(tonumber(offset), "bad argument #2 to 'writebyte' expected number, got " .. type(offset))
- if not value then
- value = offset
- offset = nil
- else
- value = assert(tonumber(value), "bad argument #3 to 'writebyte' expected number, got " .. type(value))
- end
- safe_write(true)
- write_byte(address + (offset or 0), value)
- safe_write(safe_write_val)
- end
- )
- writechar = writechar or ( -- Good
- function(address, offset, value)
- address = assert(tonumber(address), "bad argument #1 to 'writechar' expected number, got " .. type(address))
- offset = assert(tonumber(offset), "bad argument #2 to 'writechar' expected number, got " .. type(offset))
- if not value then
- value = offset
- offset = nil
- else
- value = assert(tonumber(value), "bad argument #3 to 'writechar' expected number, got " .. type(value))
- end
- safe_write(true)
- write_char(address + (offset or 0), value)
- safe_write(safe_write_val)
- end
- )
- writeword = writeword or ( -- Good
- function(address, offset, value)
- address = assert(tonumber(address), "bad argument #1 to 'writeword' expected number, got " .. type(address))
- offset = assert(tonumber(offset), "bad argument #2 to 'writeword' expected number, got " .. type(offset))
- if not value then
- value = offset
- offset = nil
- else
- value = assert(tonumber(value), "bad argument #3 to 'writeword' expected number, got " .. type(value))
- end
- safe_write(true)
- write_word(address + (offset or 0), value)
- safe_write(safe_write_val)
- end
- )
- writeshort = writeshort or ( -- Good
- function(address, offset, value)
- address = assert(tonumber(address), "bad argument #1 to 'writeshort' expected number, got " .. type(address))
- offset = assert(tonumber(offset), "bad argument #2 to 'writeshort' expected number, got " .. type(offset))
- if not value then
- value = offset
- offset = nil
- else
- value = assert(tonumber(value), "bad argument #3 to 'writeshort' expected number, got " .. type(value))
- end
- safe_write(true)
- write_short(address + (offset or 0), value)
- safe_write(safe_write_val)
- end
- )
- writedword = writedword or ( -- Good
- function(address, offset, value)
- address = assert(tonumber(address), "bad argument #1 to 'writedword' expected number, got " .. type(address))
- offset = assert(tonumber(offset), "bad argument #2 to 'writedword' expected number, got " .. type(offset))
- if not value then
- value = offset
- offset = nil
- else
- value = assert(tonumber(value), "bad argument #3 to 'writedword' expected number, got " .. type(value))
- end
- safe_write(true)
- write_dword(address + (offset or 0), value)
- safe_write(safe_write_val)
- end
- )
- writeint = writeint or ( -- Good
- function(address, offset, value)
- address = assert(tonumber(address), "bad argument #1 to 'writeint' expected number, got " .. type(address))
- offset = assert(tonumber(offset), "bad argument #2 to 'writeint' expected number, got " .. type(offset))
- if not value then
- value = offset
- offset = nil
- else
- value = assert(tonumber(value), "bad argument #3 to 'writeint' expected number, got " .. type(value))
- end
- safe_write(true)
- write_int(address + (offset or 0), value)
- safe_write(safe_write_val)
- end
- )
- writefloat = writefloat or ( -- Good
- function(address, offset, value)
- address = assert(tonumber(address), "bad argument #1 to 'writefloat' expected number, got " .. type(address))
- offset = assert(tonumber(offset), "bad argument #2 to 'writefloat' expected number, got " .. type(offset))
- if not value then
- value = offset
- offset = nil
- else
- value = assert(tonumber(value), "bad argument #3 to 'writefloat' expected number, got " .. type(value))
- end
- safe_write(true)
- write_float(address + (offset or 0), value)
- safe_write(safe_write_val)
- end
- )
- writedouble = writedouble or ( -- Good
- function(address, offset, value)
- address = assert(tonumber(address), "bad argument #1 to 'writedouble' expected number, got " .. type(address))
- offset = assert(tonumber(offset), "bad argument #2 to 'writedouble' expected number, got " .. type(offset))
- if not value then
- value = offset
- offset = nil
- else
- value = assert(tonumber(value), "bad argument #3 to 'writedouble' expected number, got " .. type(value))
- end
- safe_write(true)
- write_double(address + (offset or 0), value)
- safe_write(safe_write_val)
- end
- )
- writestring = write_string or ( -- Good
- function(address, offset, str)
- address = assert(type(address) == "number" and address, "bad argument #1 to 'writestring' expected number, got '" .. type(address) .. "'")
- if str then
- offset = assert(type(offset) == "number" and offset, "bad argument #2 to 'writestring' expected number, got '" .. type(offset) .. "'")
- str = assert(type(str) == "string" and str, "bad argument #3 to 'writestring' expected string, got '" .. type(str) .. "'")
- else
- str = assert(type(offset) == "string" and offset, "bad argument #2 to 'writestring' expected string, got '" .. type(offset) .. "'")
- offset = nil
- end
- address = address + (offset or 0x0)
- local byte_table = {}
- for char in gmatch(str, '.') do
- byte_table[#byte_table+1] = byte(char)
- end
- local length = #byte_table
- safe_write(true)
- for i = 0,length-1 do
- writebyte(address + i, byte_table[i+1])
- end
- safe_write(safe_write_val)
- end
- )
- writewidestring = write_wide_string or ( -- Good
- function(address, offset, str)
- address = assert(type(address) == "number" and address, "bad argument #1 to 'writewidestring' expected number, got '" .. type(address) .. "'")
- if str then
- offset = assert(type(offset) == "number" and offset, "bad argument #2 to 'writewidestring' expected number, got '" .. type(offset) .. "'")
- str = assert(type(str) == "string" and str, "bad argument #3 to 'writewidestring' expected string, got '" .. type(str) .. "'")
- else
- str = assert(type(offset) == "string" and offset, "bad argument #2 to 'writewidestring' expected string, got '" .. type(offset) .. "'")
- offset = nil
- end
- address = address + (offset or 0x0)
- local byte_table = {}
- for char in gmatch(str, '.') do
- byte_table[#byte_table+1] = byte(char)
- end
- local length = #byte_table
- safe_write(true)
- for i = 0,length*2 do
- writeword(address + i, 0)
- end
- safe_write(safe_write_val)
- end
- )
- -- Definitions for All Sapp Functions:
- assign_weapon = assign_weapon or ( -- Good
- function(objectId, playerIndex)
- local playerId = rresolveplayer(playerIndex)
- return playerId and assignweapon(playerId, objectId)
- end
- )
- camo = camo or ( -- Good
- function(playerIndex, duration)
- local playerId = rresolveplayer(playerIndex)
- return playerId and applycamo(playerId, duration / 30)
- end
- )
- cprint = cprint or function(a) hprintf(a) end -- Good
- destroy_object = destroy_object or ( -- Good
- function(objId)
- if getobject(objId) then destroyobject(objId) end
- end
- )
- drop_weapon = drop_weapon or ( -- Workaround
- function(playerIndex)
- local m_playerObj = getobject(getplayerobjectid(rresolveplayer(playerIndex)))
- if m_playerObj then
- destroyobject(readdword(m_playerObj + 0x118))
- end
- end
- )
- enter_vehicle = enter_vehicle or ( -- Good
- function(objectId, playerIndex, seat)
- local playerId = rresolveplayer(playerIndex)
- if playerId then entervehicle(playerId, objectId, seat) end
- end
- )
- execute_command = execute_command or ( -- Good
- function(command, playerIndex)
- local playerId = rresolveplayer(playerIndex)
- if events[cb.EVENT_ECHO][1] then
- local response = playerId and svcmdplayer(command, playerId, true) or svcmd(command, true)
- if type(response) == "table" then
- for i = 1,#response do
- ypcall(_G[events[cb.EVENT_ECHO][1]], 0, response[i])
- end
- end
- elseif playerId then svcmdplayer(command, playerId, true)
- else svcmd(command, true)
- end
- end
- )
- exit_vehicle = exit_vehicle or ( -- Good
- function(playerIndex)
- local playerId = rresolveplayer(playerIndex)
- if playerId then exitvehicle(playerId) end
- end
- )
- get_dynamic_player = get_dynamic_player or ( -- Good
- function(playerIndex)
- local playerId = rresolveplayer(playerIndex)
- local playerObjId = playerId and getplayerobjectid(playerId)
- return playerObjId and getobject(playerObjId) or 0
- end
- )
- get_object_memory = get_object_memory or ( -- Good
- function(objectId)
- return objectId and getobject(objectId) or 0
- end
- )
- get_player = get_player or ( -- Good
- function(playerIndex)
- local playerId = rresolveplayer(playerIndex)
- return playerId and getplayer(playerId) or 0
- end
- )
- get_var = get_var or ( -- Some variables don't exist in Phasor.
- function(playerIndex, var)
- playerIndex = assert(tonumber(playerIndex), "bad argument #1 to 'get_var' expected number, got " .. type(playerIndex))
- var = lower(var)
- if var == "$n" then
- return playerIndex
- elseif var == "$name" then
- return getname(rresolveplayer(playerIndex))
- elseif var == "$hash" then
- return gethash(rresolveplayer(playerIndex))
- elseif var == "$ip" then
- local playerId = rresolveplayer(playerIndex)
- return getip(playerId) .. ":" .. getport(playerId)
- elseif var == "$tk" then
- local m_player = getplayer(rresolveplayer(playerIndex))
- return readshort(m_player + 0xAC) - readshort(m_player + 0xAE)
- elseif var == "$kills" then
- return readshort(getplayer(rresolveplayer(playerIndex)) + 0x9C)
- elseif var == "$assists" then
- return readshort(getplayer(rresolveplayer(playerIndex)) + 0xA4)
- elseif var == "$deaths" then
- return readshort(getplayer(rresolveplayer(playerIndex)) + 0xAE)
- elseif var == "$suicides" then
- return readshort(getplayer(rresolveplayer(playerIndex)) + 0xB0)
- elseif var == "$streak" then
- return readshort(getplayer(rresolveplayer(playerIndex)) + 0x96)
- elseif var == "$combo" then
- return readshort(getplayer(rresolveplayer(playerIndex)) + 0x98)
- elseif var == "$score" then
- return readshort(getplayer(rresolveplayer(playerIndex)) + 0xC8)
- elseif var == "$botscore" then
- elseif var == "$afk" then
- elseif var == "$ping" then
- return readdword(getplayer(rresolveplayer(playerIndex)) + 0xDC)
- elseif var == "$x" then
- return readfloat(getplayer(rresolveplayer(playerIndex)) + 0xF8)
- elseif var == "$y" then
- return readfloat(getplayer(rresolveplayer(playerIndex)) + 0xFC)
- elseif var == "$z" then
- return readfloat(getplayer(rresolveplayer(playerIndex)) + 0x100)
- elseif var == "$hp" then
- return readfloat(getplayer(rresolveplayer(playerIndex)) + 0xE0)
- elseif var == "$sh" then
- return readfloat(getplayer(rresolveplayer(playerIndex)) + 0xE4)
- elseif var == "$invis" then
- return readword(getplayer(rresolveplayer(playerIndex)) + 0x68) > 0 and 1 or 0
- elseif var == "$team" then
- return getteam(playerId)
- elseif var == "$oteam" then
- return abs(getteam(playerId)-1)
- elseif var == "$lvl" then
- return getadminlvl(playerId)
- elseif var == "$map" then
- return _GAME == "PC" and readstring(0x698F21) or readstring(0x61D151)
- elseif var == "$mode" then
- local gt = _GAME == "PC" and readbyte(0x671340 + 0x30) or readbyte(0x5F5498 + 0x30)
- return gt == 1 and "ctf" or gt == 2 and "slayer" or gt == 3 and "koth" or gt == 4 and "oddball" or gt == 5 and "race"
- elseif var == "$gt" then
- return _GAME == "PC" and readwidestring(0x671340 + 0x2C) or readwidestring(0x5F5498 + 0x2C)
- elseif var == "$ffa" then
- return _GAME == "PC" and readbyte(0x671340 + 0x34) or readbyte(0x5F5498 + 0x34)
- elseif var == "$svname" then
- return getservername()
- elseif var == "$pn" then
- local counter = 0
- for playerId = 0,15 do
- if getplayer(playerId) then
- counter = counter + 1
- end
- end
- return counter
- elseif var == "$reds" then
- return getteamsize(0)
- elseif var == "$blues" then
- return getteamsize(1)
- elseif var == "$rand" then
- return getrandomnumber(1, 17)
- elseif var == "$game" then
- return _GAME
- end
- return "Variable doesn't exist on Phasor, sorry!"
- end
- )
- lookup_tag = lookup_tag or (
- function(a,b)
- for i=0,(tag_table_count - 1),0x20 do
- if a == readdword(0x40440034+i) or a == readstring(0x40440028+i, 4) and b == readstring(readdword(0x40440038+i)) then
- return 0x40440028+i
- end
- end
- end
- )
- sappkill = _SERVERAPP == "Sapp" and kill or function(playerIndex) kill(to_real_index(playerIndex)) end -- Annoying.
- intersect = intersect or ( -- Good
- function(x, y, z, vx, vy, vz, objectId)
- return halointersect(1, x, y, z, vx, vy, vz, objectId)
- end
- )
- player_present = player_present or function(playerIndex) return not not rresolveplayer(playerIndex) end -- Good
- rand = rand or getrandomnumber -- Good
- read_bit = read_bit or readbit -- Good
- read_byte = read_byte or readbyte -- Good
- read_char = read_char or readchar -- Good
- read_word = read_word or readword -- Good
- read_short = read_short or readshort -- Good
- read_dword = read_dword or readdword -- Good
- read_int = read_int or readint -- Good
- read_float = read_float or readfloat -- Good
- read_double = read_double or readdouble -- Good
- read_string = read_string or ( -- Good
- function(address, length)
- address = type(address) == "number" and address or error("bad argument #1 to 'readstring' expected number, got '" .. type(address) .. "'")
- if length then
- length = type(length) == "number" and length or error("bad argument #2 to 'readstring' expected number, got '" .. type(length) .. "'")
- else
- length = length or 256
- end
- local char_table = {}
- local newByte
- for i = 0,length-1 do
- newByte = readbyte(address + i)
- if newByte == 0 or newByte == 255 then break end
- char_table[#char_table+1] = char(newByte)
- end
- return concat(char_table)
- end
- )
- read_vector3d = read_vector3d or ( -- Good
- function(address)
- return readfloat(address),readfloat(address+4),readfloat(address+8)
- end
- )
- read_wide_string = read_wide_string or ( -- Good
- function(address, length)
- address = type(address) == "number" and address or error("bad argument #1 to 'readwidestring' expected number, got '" .. type(address) .. "'")
- if length then
- length = type(length) == "number" and length or error("bad argument #2 to 'readwidestring' expected number, got '" .. type(length) .. "'")
- else
- length = length or 51001
- end
- local char_table = {}
- local newByte
- for i = 0,length-1,2 do
- newByte = readbyte(address + i)
- if newByte == 0 or newByte == 255 or readbyte(address + i+1) ~= 0 then break end
- char_table[#char_table+1] = char(newByte)
- end
- return concat(char_table)
- end
- )
- -- register_callback will ALWAYS take priority over functions that Phasor calls by default
- -- This means that if you have a function named 'OnTeamChange' in your script, it will be treated as a Phasor function and will pass the default Phasor arguments because it is a phasor event function.
- -- However, if you do 'register_callback(cb.EVENT_TEAM_SWITCH, "OnTeamChange"), now it will be treated like a Sapp event function, and will be called with a playerIndex only. So be careful.
- register_callback = function(event, funcname)
- local internalEvent = phasorEvents[funcname]
- if internalEvent then
- if type(internalEvent) == "function" then
- _G["__" .. funcname] = internalEvent
- if internalEvent == _G[funcname] then
- _G[funcname] = nil
- end
- end
- funcname = "__" .. funcname
- end
- local thisEvent = events[event]
- assert(thisEvent, "Invalid event passed to 'register_event'")
- events.Create(thisEvent, event, funcname)
- end
- rprint = rprint or ( -- Good
- function(playerIndex, message)
- sendconsoletext(rresolveplayer(playerIndex), message)
- end
- )
- local __safe_read = safe_read
- local __safe_write = safe_write
- safe_read = safe_read and ( -- Phasor does not have this.
- function(bool)
- safe_read_val = not not bool
- __safe_read(safe_read_val)
- end
- )
- safe_write = safe_write and ( -- Phasor does not have this.
- function(bool)
- safe_write_val = not not bool
- __safe_write(safe_write_val)
- end
- )
- say = say -- Good
- say_all = say_all or __say -- Good
- sig_scan = sig_scan -- Phasor does not have this.
- spawn_object = spawn_object or ( -- Good
- function(tagtype, tagname, x, y, z, rot, mapId)
- mapId = tagtype and tagname and gettagid(tagtype, tagname) or mapId
- return createobject(mapId or gettagid(tagtype, tagname), 0, 0x7FFF, false, x, y, z) or 0
- end
- )
- sync_ammo = sync_ammo or function(objectId) if getobject(objectId) then updateammo(objectId) end end -- Good
- timer = timer or ( -- Good
- function(delay, funcname, ...)
- local args = {...}
- for i = 1,#args do
- args[i] = tostring(args[i]) -- all sapp arguments are actually passed as strings
- end
- _G[funcname .. "_overhead"] = (
- function()
- return ypcall(_G[funcname], unpack(args))
- end
- )
- registertimer(delay, funcname .. "_overhead", args)
- end
- )
- to_player_index = to_player_index or resolveplayer and ( -- Good
- function(playerId)
- return resolveplayer(playerId) or 0
- end
- ) or error("Functions 'to_player_index' and 'resolveplayer' not found. What server app are you even using?")
- to_real_index = to_real_index or rresolveplayer and ( -- Good
- function(playerIndex)
- return rresolveplayer(playerIndex) or -1
- end
- ) or error("Functions 'to_real_index' and 'rresolveplayer' not found. What server app are you even using?")
- write_bit = writebit -- Good
- write_byte = write_byte or writebyte -- Good
- write_char = write_char or writechar -- Good
- write_word = write_word or writeword -- Good
- write_short = write_short or writeshort -- Good
- write_dword = write_dword or writedword -- Good
- write_int = write_int or writeint -- Good
- write_float = write_float or writefloat -- Good
- write_double = write_double or writedouble -- Good
- write_string = write_string or ( -- Good
- function(address, offset, str)
- address = type(address) == "number" and address or error("bad argument #1 to 'writestring' expected number, got '" .. type(address) .. "'")
- if str then
- offset = type(offset) == "number" and offset or error("bad argument #2 to 'writestring' expected number, got '" .. type(offset) .. "'")
- str = type(str) == "string" and str or error("bad argument #3 to 'writestring' expected string, got '" .. type(str) .. "'")
- else
- str = type(offset) == "string" and offset or error("bad argument #2 to 'writestring' expected string, got '" .. type(offset) .. "'")
- offset = nil
- end
- address = address + (offset or 0x0)
- local byte_table = {}
- for char in gmatch(str, '.') do
- byte_table[#byte_table+1] = byte(char)
- end
- local length = #byte_table
- for i = 0,length-1 do
- writebyte(address + i, byte_table[i+1])
- end
- end
- )
- write_vector3d = write_vector3d or (
- function(address, a, b, c)
- writefloat(address, a)
- writefloat(address+4, b)
- writefloat(address+8, c)
- end
- )
- write_wide_string = write_wide_string or ( -- Good
- function(address, offset, str)
- address = type(address) == "number" and address or error("bad argument #1 to 'writewidestring' expected number, got '" .. type(address) .. "'")
- if str then
- offset = type(offset) == "number" and offset or error("bad argument #2 to 'writewidestring' expected number, got '" .. type(offset) .. "'")
- str = type(str) == "string" and str or error("bad argument #3 to 'writewidestring' expected string, got '" .. type(str) .. "'")
- else
- str = type(offset) == "string" and offset or error("bad argument #2 to 'writewidestring' expected string, got '" .. type(offset) .. "'")
- offset = nil
- end
- address = address + (offset or 0x0)
- local byte_table = {}
- for char in gmatch(str, '.') do
- byte_table[#byte_table+1] = byte(char)
- end
- local length = #byte_table
- for i = 0,length*2 do
- writeword(address + i, 0)
- end
- end
- )
- local OnScriptLoad2 = OnScriptLoad
- function OnScriptLoad(process, game, persistent)
- if _SERVERAPP == "Sapp" then
- registerPhasorEvents()
- end
- ypcall(OnScriptLoad2, process or pid, game or halo_type or _GAME, persistent == nil or persistent)
- end
- collectgarbage() -- No doubt there's tons of functions and variables to be cleaned up since this script overrided most of them.
- _G.kill = nil -- Been renamed, keep it out of the global table in case of accidents.
- api_version = sapp_version
- return _G
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement