177 lines
5.0 KiB
Python
177 lines
5.0 KiB
Python
import os
|
|
import subprocess
|
|
import time, threading
|
|
import os
|
|
# COMMENTS
|
|
#sm_track_movement jenz
|
|
#direct input
|
|
#xdotool search --name "Counter-Strike Source - OpenGL" key m
|
|
|
|
#setxkbmap -layout dk
|
|
#xdotool search --name "Counter-Strike Source - OpenGL"
|
|
#xdotool windowfocus 10488872 / 31457297 // 67108881
|
|
# keydown
|
|
# COMMENTS OVER
|
|
|
|
def processType(type):
|
|
subprocess.call(["xdotool", "type", type])
|
|
|
|
def processKeys(key):
|
|
subprocess.call(["xdotool", "key", key])
|
|
|
|
def findPosOrigin(line):
|
|
originPost = line[line.find('setpos ') + len('setpos'):line.rfind(';setang')]
|
|
print('originPost: ', originPost)
|
|
return originPost
|
|
|
|
def deleteCondump():
|
|
[os.remove(os.path.join("/home/john/.steam/steam/steamapps/common/Counter-Strike Source/cstrike/",f)) for f in os.listdir("/home/john/.steam/steam/steamapps/common/Counter-Strike Source/cstrike/") if f.startswith("condump")]
|
|
|
|
def processLine(line):
|
|
if '[SM] The current map is ' in line:
|
|
processType("say")
|
|
processKeys("space")
|
|
processType("currentmap")
|
|
processKeys("space")
|
|
processType("is")
|
|
processKeys("space")
|
|
currentmap = line[line.find('map is ') + len('map is '):line.rfind('.')]
|
|
processType(currentmap)
|
|
processKeys("Return")
|
|
global currentFilename
|
|
currentFilename = str(currentmap)
|
|
|
|
def reachgetDifference(reachpos, getpos):
|
|
#print('reachpos: ', reachpos)
|
|
#print('getpos: ', getpos)
|
|
if getpos[1] == '-':
|
|
getpos = getpos[2:]
|
|
if reachpos[1] == '-':
|
|
reachpos = reachpos[2:]
|
|
reachposAxis = float(reachpos[0].strip('"'))
|
|
getposAxis = float(getpos[0].strip('"'))
|
|
if reachposAxis - 50.0 < getposAxis:
|
|
processType("setang")
|
|
processKeys("space")
|
|
processType("0")
|
|
processKeys("space")
|
|
processType("180")
|
|
processKeys("space")
|
|
processType("0")
|
|
processKeys("Return")
|
|
return True
|
|
elif reachposAxis + 50.0 > getposAxis:
|
|
processType("setang")
|
|
processKeys("space")
|
|
processType("0")
|
|
processKeys("space")
|
|
processType("0")
|
|
processKeys("space")
|
|
processType("0")
|
|
processKeys("Return")
|
|
return True
|
|
return False
|
|
|
|
def readmovement(line):
|
|
doubleString = "setang "
|
|
processphase = 0;
|
|
characterString = ""
|
|
for index, character in enumerate(line):
|
|
#print('character: ', character)
|
|
if processphase == 0:
|
|
if character.isspace():
|
|
continue
|
|
if character.isalpha():
|
|
if character != characterString:
|
|
processKeys("minus")
|
|
if character == "w":
|
|
characterString = "forward"
|
|
elif character == "s":
|
|
characterString = "back"
|
|
print('characterString: ', characterString)
|
|
print('character: ', character)
|
|
processType(characterString)
|
|
processKeys("Return")
|
|
time.sleep(0.5)
|
|
processKeys("plus")
|
|
if character == "w":
|
|
characterString = "forward"
|
|
elif character == "s":
|
|
characterString = "back"
|
|
processType(characterString)
|
|
print('characterString2: ', characterString)
|
|
processKeys("Return")
|
|
characterString = character
|
|
processphase += 1
|
|
if processphase == 1:
|
|
if character.isdigit() or character == '.':
|
|
doubleString += character
|
|
elif character.isspace() and len(doubleString) > 10:
|
|
doubleString += " "
|
|
if line[index + 1] == "o":
|
|
processType(doubleString)
|
|
processKeys("Return")
|
|
doubleString = ""
|
|
processphase += 1
|
|
if processphase == 2:
|
|
if not character.isdigit() and not doubleString:
|
|
continue
|
|
elif character.isdigit() or character == '.':
|
|
doubleString += character
|
|
elif character.isspace() and doubleString and not line[index + 1].isalpha():
|
|
doubleString += " "
|
|
else:
|
|
reachpos = doubleString.split()
|
|
getpos = ["0.0", "0.0", "0.0"]
|
|
while reachgetDifference(reachpos, getpos):
|
|
processType("clear")
|
|
processKeys("Return")
|
|
processType("getpos")
|
|
processKeys("Return")
|
|
time.sleep(2)
|
|
processType("condump")
|
|
processKeys("Return")
|
|
time.sleep(2)
|
|
with open('/home/john/.steam/steam/steamapps/common/Counter-Strike Source/cstrike/condump000.txt') as f:
|
|
for line in f:
|
|
if 'setpos' in line:
|
|
getpos = findPosOrigin(line)
|
|
break
|
|
time.sleep(2)
|
|
deleteCondump()
|
|
processphase = 0
|
|
doubleString = "setang "
|
|
|
|
def findcurrentmap():
|
|
subprocess.call(["xdotool", "search", "--name", "Counter-Strike Source - OpenGL", "windowactivate"])
|
|
#clear console field before retrieving info
|
|
processKeys("Return")
|
|
#clean console prompt
|
|
processType("clear")
|
|
processKeys("Return")
|
|
processType("say")
|
|
processKeys("space")
|
|
processType("currentmap")
|
|
processKeys("Return")
|
|
time.sleep(2)
|
|
processType("condump")
|
|
processKeys("Return")
|
|
time.sleep(2)
|
|
with open('/home/john/.steam/steam/steamapps/common/Counter-Strike Source/cstrike/condump000.txt') as f:
|
|
for line in f:
|
|
processLine(line)
|
|
time.sleep(2)
|
|
deleteCondump()
|
|
#subprocess.call(["xdotool", "key", "Escape"])
|
|
#subprocess.call(["xdotool", "key", "o"])
|
|
|
|
def mapmovementpattern():
|
|
stringfile = "/home/nonroot/zeeman/maps/%s.txt" % (currentFilename)
|
|
with open(stringfile) as f:
|
|
for line in f:
|
|
readmovement(line)
|
|
|
|
if __name__ == '__main__':
|
|
deleteCondump()
|
|
findcurrentmap()
|
|
mapmovementpattern() |