Created
March 2, 2016 20:19
-
-
Save Mytherin/2d56ef995ea7d9e26e92 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
import os | |
import sys | |
def tibia_client_exists(): | |
if os.system('pgrep Tibia >/dev/null 2>&1') != 0: | |
return False | |
return True | |
def tibia_client_id(): | |
return os.popen('pgrep Tibia').read().split('\n')[0] | |
cached_loot_messages = set() | |
def read_process_memory(pid): | |
item_drops = [] | |
exp = dict() | |
damage_dealt = dict() | |
damage_dealt['You'] = dict() | |
maps_file = open("/proc/%s/maps" % pid, 'r') | |
mem_file = open("/proc/%s/mem" % pid, 'r') | |
for line in maps_file.readlines(): # for each mapped region | |
m = re.match(r'([0-9A-Fa-f]+)-([0-9A-Fa-f]+) ([-r])', line) | |
if m.group(3) == 'r': # if this is a readable region | |
start = int(m.group(1), 16) | |
end = int(m.group(2), 16) | |
mem_file.seek(start) # seek to region start | |
try: chunk = mem_file.read(end - start) # read region contents | |
except: continue | |
index = 0 | |
while True: | |
chunkmatch = re.search('([0-9]{2}:[0-9]{2}[^\0]{10,})\0', chunk[index:]) | |
if chunkmatch == None: | |
break | |
log_message = chunkmatch.groups()[0] | |
match = re.search('([0-9]{2}:[0-9]{2} Loot of [^\0]*)', log_message) | |
if match != None: | |
global cached_loot_messages | |
if match.groups()[0] in cached_loot_messages: | |
index = index + chunkmatch.end() | |
continue | |
cached_loot_messages = cached_loot_messages.union([match.groups()[0]]) | |
list.append(item_drops, match.groups()[0]) | |
else: | |
match = re.search('([0-9]{2}:[0-9]{2}) You gained ([0-9]+) experience points\.', log_message) | |
if match != None: | |
t = match.groups()[0] | |
e = int(match.groups()[1]) | |
if t not in exp: exp[t] = e | |
else: exp[t] = exp[t] + e | |
else: | |
match = re.search('([0-9]{2}:[0-9]{2}) [a-zA-Z0-9_\- \t]*loses ([0-9]+) hitpoints due to your attack\.', log_message) | |
if match != None: | |
player = 'You' | |
t = match.groups()[0] | |
d = int(match.groups()[1]) | |
if t not in damage_dealt[player]: damage_dealt[player][t] = d | |
else: damage_dealt[player][t] = damage_dealt[player][t] + d | |
else: | |
match = re.search('([0-9]{2}:[0-9]{2}) [a-zA-Z0-9_\- \t]*loses ([\d]+) hitpoints? due to an attack by ([a-zA-Z0-9\-\t ]*)\.', log_message) | |
if match != None: | |
t = match.groups()[0] | |
d = int(match.groups()[1]) | |
player = match.groups()[2] | |
if player not in damage_dealt: damage_dealt[player] = dict() | |
if t not in damage_dealt[player]: damage_dealt[player][t] = d | |
else: damage_dealt[player][t] = damage_dealt[player][t] + d | |
index = index + chunkmatch.end() | |
maps_file.close() | |
mem_file.close() | |
return_values = dict() | |
return_values['item_drops'] = item_drops | |
return_values['experience'] = exp | |
return_values['damage_dealt'] = damage_dealt | |
return return_values | |
while True: | |
res = read_process_memory(tibia_client_id()) | |
for drops in res['item_drops']: | |
if 'ape fur' in drops: | |
os.system('notify-send \"%s\"' % drops) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment