Simple antihack implementation example for Starcraft maphack, based on SID_READMEMORY https://github.com/HarpyWar/pvpgn/pull/26

This commit is contained in:
HarpyWar 2014-06-19 21:16:57 +04:00
parent 7af51a1f88
commit c0263d3f7e
7 changed files with 106 additions and 8 deletions

View file

@ -0,0 +1,83 @@
--[[
Simple Anti MapHack for Starcraft: BroodWar 1.16.1
Copyright (C) 2014 HarpyWar (harpywar@gmail.com)
This file is a part of the PvPGN Project http://pvpgn.pro
Licensed under the same terms as Lua itself.
]]--
-- just unique request id for maphack
ah_mh_request_id = 99
-- map visible offset
ah_mh_offset = 0x0047FD12
-- map visible normal value (without maphack)
ah_mh_value = 139
function ah_init()
timer_add("ah_timer", config.ah_interval, ah_timer_tick)
TRACE("Antihack activated")
end
-- send memory check request to all players in games
function ah_timer_tick(options)
-- iterate all games
for i,game in pairs(api.server_get_games()) do
-- check only Starcraft: BroodWar
if game.clienttag and (game.clienttag == CLIENTTAG_BROODWARS) then
-- check only games where count of players > 1
if game.players and (substr_count(game.players, ",") > -1) then
--DEBUG(game.players)
-- check every player in the game
for username in string.split(game.players,",") do
api.client_readmemory(username, ah_mh_request_id, ah_mh_offset, 2)
-- HINT: place here more readmemory requests
end
end
end
end
end
-- handle response from the client
function ah_handle_client(account, request_id, data)
local is_cheater = false
-- maphack
if (request_id == ah_mh_request_id) then
-- read value from the memory
local value = bytes_to_int(data, 0, 2)
DEBUG(account.name .. " memory value: " .. value)
if not (value == ah_mh_value) then
is_cheater = true
end
-- process another hack check
--elseif (request_id == ...) then
end
if (is_cheater) then
-- lock cheater account
account_set_auth_lock(account.name, true)
account_set_auth_lockreason(account.name, "we do not like cheaters")
-- notify all players in the game about cheater
local game = api.game_get_by_id(account.game_id)
if game then
for username in string.split(game.players,",") do
api.message_send_text(username, message_type_error, nil, account.name .. " was banned by the antihack system.")
end
end
-- kick cheater
api.client_kill(account.name)
INFO(account.name .. " was banned by the antihack system.")
end
end

View file

@ -19,5 +19,9 @@ config = {
quiz_users_in_top = 15, -- how many users display in TOP list
quiz_channel = nil, -- (do not modify!) channel when quiz has started (it assigned with start)
-- AntiHack (Starcraft)
ah = true,
ah_interval = 60, -- interval for send memory request to all players in games
}

View file

@ -84,10 +84,10 @@ function account_set_auth_botlogin(username, value)
end
function account_get_auth_lock(username)
return api.account_get_attr(username, "BNET\\auth\\lockk", attr_type_bool)
return api.account_get_attr(username, "BNET\\auth\\lock", attr_type_bool)
end
function account_set_auth_lock(username, value)
return api.account_set_attr(username, "BNET\\auth\\lockk", attr_type_bool, value)
return api.account_set_attr(username, "BNET\\auth\\lock", attr_type_bool, value)
end
function account_get_auth_locktime(username)

View file

@ -8,10 +8,13 @@
function handle_client_readmemory(account, request_id, data)
TRACE("Read memory request Id: " .. request_id)
--TRACE("Read memory request Id: " .. request_id)
-- display memory bytes
DEBUG(data)
if (config.ah) then
ah_handle_client(account, request_id, data)
end
end

View file

@ -46,7 +46,7 @@ function handle_game_report(game)
-- api.message_send_text(game.owner, message_type_info, game.owner, i.." = "..j)
--end
--api.eventlog(eventlog_level_gui, __FUNCTION__, game.last_access)
--DEBUG(game.last_access)
end

View file

@ -56,4 +56,8 @@ function replace_char(pos, str, replacement)
return str:sub(1, pos-1) .. replacement .. str:sub(pos+1)
end
-- return count of substr in str
function substr_count(str, substr)
local _, count = string.gsub(str, substr, "")
return count
end

View file

@ -8,6 +8,10 @@
-- this function executes after preload all the lua scripts
function main()
-- start antihack
if (config.ah) then
ah_init()
end
end