ScrapHacks/lib/dbg.py

358 lines
8.1 KiB
Python
Raw Normal View History

2017-10-07 23:37:53 +00:00
import sys
import Scrap
import quickconsole
import MissionsFuncs
2018-12-22 03:25:18 +00:00
import SScorer
import Menu
import sys
2018-12-22 03:25:18 +00:00
QC = quickconsole
MF = MissionsFuncs
last_frame = None
sys.path.append(".\\pylib\\Lib")
sys.path.append(".\\pylib\\Libs")
sys.path.append(".\\pylib")
2018-12-22 03:25:18 +00:00
def reload():
sys.settrace(None)
sys.modules['__builtin__'].reload(sys.modules['dbg'])
def dgb_info():
SScorer.SetLabelText(`last_frame`, Scrap.GetTime() + 0.1)
Scrap.DeleteScheduledFuncs("dbg.dbg_info")
Scrap.DeleteScheduledFuncs("dbg.dbg_info")
Scrap.AddScheduledFunc(Scrap.GetTime()+0.1, dgb_info, (), "dbg.dbg_info")
2018-12-22 03:25:18 +00:00
def crazy():
E = Scrap.GetFirst()
me = Scrap.UsrEntity(0)
while E:
if E.Name == me.Name:
E = Scrap.GetEntity(E.NextInSlot)
try:
E.Action = "CrazyInit"
E.CanPhoto = 1
E.DefLoop = "Crazy"
except:
pass
E = Scrap.GetEntity(E.NextInSlot)
def decrazy():
E = Scrap.GetFirst()
me = Scrap.UsrEntity(0)
while E:
if E.Name == me.Name:
E = Scrap.GetEntity(E.NextInSlot)
try:
E.Action = "CrazyEnd"
E.CanPhoto = 0
E.ForceDefLoop = "Relax"
except:
pass
E = Scrap.GetEntity(E.NextInSlot)
2017-10-07 23:37:53 +00:00
def p_s(*args):
2018-12-22 03:25:18 +00:00
msg = ""
2017-10-07 23:37:53 +00:00
for obj in args:
if msg:
2018-12-22 03:25:18 +00:00
msg = msg+" "+str(obj)
2017-10-07 23:37:53 +00:00
else:
2018-12-22 03:25:18 +00:00
msg = msg+str(obj)
2017-10-07 23:37:53 +00:00
Scrap.Print(msg)
2018-12-22 03:25:18 +00:00
2017-10-07 23:37:53 +00:00
def p_e(*args):
2018-12-22 03:25:18 +00:00
msg = ""
2017-10-07 23:37:53 +00:00
for obj in args:
if msg:
2018-12-22 03:25:18 +00:00
msg = msg+" "+str(obj)
2017-10-07 23:37:53 +00:00
else:
2018-12-22 03:25:18 +00:00
msg = msg+str(obj)
2017-10-07 23:37:53 +00:00
Scrap.ConsoleError(msg)
2018-12-22 03:25:18 +00:00
sys.stdout.write = p_s
sys.stderr.write = p_e
2017-10-07 23:37:53 +00:00
def p(*args):
2018-12-22 03:25:18 +00:00
msg = ""
2017-10-07 23:37:53 +00:00
for obj in args:
if msg:
2018-12-22 03:25:18 +00:00
msg = msg+" "+str(obj)
2017-10-07 23:37:53 +00:00
else:
2018-12-22 03:25:18 +00:00
msg = msg+str(obj)
2017-10-07 23:37:53 +00:00
Scrap.Print(msg+"\n")
2018-12-22 03:25:18 +00:00
2017-10-07 23:37:53 +00:00
def e(*args):
2018-12-22 03:25:18 +00:00
msg = ""
2017-10-07 23:37:53 +00:00
for obj in args:
if msg:
2018-12-22 03:25:18 +00:00
msg = msg+" "+str(obj)
2017-10-07 23:37:53 +00:00
else:
2018-12-22 03:25:18 +00:00
msg = msg+str(obj)
2017-10-07 23:37:53 +00:00
Scrap.ConsoleError(msg+"\n")
2018-12-22 03:25:18 +00:00
# sys.modules['__builtin__'].__dict__['print']=e
sys.modules['__builtin__'].__dict__['s_write'] = p
sys.modules['__builtin__'].__dict__['e_write'] = e
def modhelp(Module="Scrap"):
print "======== [ " + Module + " ] ========"
exec("import "+Module)
for v in dir(eval(Module)):
if v in ("__doc__", "__name__"):
continue
print v + ":"
try:
print " " + eval(Module + "." + v + ".__doc__")
except:
pass
def helpfunc(func):
print func.__name__+":"
print " "+func.__doc__
2017-10-07 23:37:53 +00:00
2018-12-22 03:25:18 +00:00
def trace(frame, event, arg):
global last_frame
if event != "call":
return
g = frame.f_globals
l = frame.f_locals
if frame.f_code.co_name == "godcall":
2017-10-07 23:37:53 +00:00
return
2018-12-22 03:25:18 +00:00
if frame.f_code.co_filename == ".\\lib\\dbg.py":
return
R = frame.f_code.co_filename+": "+frame.f_code.co_name+"("
2017-10-07 23:37:53 +00:00
for i in range(frame.f_code.co_argcount):
name = frame.f_code.co_varnames[i]
2018-12-22 03:25:18 +00:00
R = R+name+"="+repr(frame.f_locals[name])+","
R = R+") Consts: ["
2017-10-07 23:37:53 +00:00
for const in frame.f_code.co_consts:
2018-12-22 03:25:18 +00:00
R = R+repr(const)+","
R = R+"]"
print R, "Locals:", l, "Globals:", g
last_frame = R
2017-10-07 23:37:53 +00:00
return trace
2018-12-22 03:25:18 +00:00
2017-10-07 23:37:53 +00:00
def menu():
import Menu
2018-12-22 03:25:18 +00:00
Menu.DebugMenu(1, '')
Menu.InitMenuSys(1)
2017-10-07 23:37:53 +00:00
def settrace():
sys.settrace(trace)
2018-12-22 03:25:18 +00:00
def notrace():
sys.settrace(None)
2017-10-07 23:37:53 +00:00
def log(*args):
if not args:
2018-12-22 03:25:18 +00:00
open(logfile_name, "w").close()
2017-10-07 23:37:53 +00:00
return
2018-12-22 03:25:18 +00:00
msg = ""
2017-10-07 23:37:53 +00:00
for obj in args:
if msg:
2018-12-22 03:25:18 +00:00
msg = msg+" "+str(obj)
2017-10-07 23:37:53 +00:00
else:
2018-12-22 03:25:18 +00:00
msg = msg+str(obj)
open(logfile_name, "a").write(msg+"\n")
2017-10-07 23:37:53 +00:00
def helplib():
2018-12-22 03:25:18 +00:00
global logfile_name
2017-10-07 23:37:53 +00:00
print "Generating helplib.txt"
2018-12-22 03:25:18 +00:00
logfile_name = "helplib.txt"
2017-10-07 23:37:53 +00:00
log()
2018-12-22 03:25:18 +00:00
for modname, mod in sys.modules.items():
if hasattr(mod, '__file__'):
continue
2017-10-07 23:37:53 +00:00
log("======== [ "+modname+" ] ========")
2018-12-22 03:25:18 +00:00
for name, value in vars(mod).items():
if name in ("__doc__", "__name__"):
2017-10-07 23:37:53 +00:00
continue
2018-12-22 03:25:18 +00:00
if hasattr(value, "__doc__"):
2017-10-07 23:37:53 +00:00
if value.__doc__:
log("- "+name+":"+repr(value))
2017-10-07 23:37:53 +00:00
log(" "+value.__doc__)
else:
log("- "+name+":"+repr(value))
2017-10-07 23:37:53 +00:00
else:
log("- "+name+": "+repr(value))
log("\n")
2018-12-22 03:25:18 +00:00
logfile_name = None
2017-10-07 23:37:53 +00:00
print "Done!"
2018-12-22 03:25:18 +00:00
2017-10-07 23:37:53 +00:00
def enable_all_conv():
2018-12-22 03:25:18 +00:00
try:
import CharConversor
except ImportError:
print("CharConversor not available")
return
CharConversor.ConversionChars = list(CharConversor.ConversionChars)
E = Scrap.GetFirst()
2017-10-07 23:37:53 +00:00
while E:
try:
if E.ActCtrl not in CharConversor.ConversionChars:
CharConversor.ConversionChars.append(E.ActCtrl)
except:
E = Scrap.GetEntity(E.NextInSlot)
continue
2018-12-22 03:25:18 +00:00
E.Invulnerable = 0
E.Life = 100
2017-10-07 23:37:53 +00:00
E = Scrap.GetEntity(E.NextInSlot)
2018-12-22 03:25:18 +00:00
def goto(name=None):
2018-12-22 03:25:18 +00:00
if name == None:
name = MF.currentTarget
Scrap.UsrEntity(0).Pos = Scrap.GetEntity(name).Pos
def bring(name=None):
2018-12-22 03:25:18 +00:00
if name == None:
name = MF.currentTarget
Scrap.GetEntity(name).Pos = Scrap.UsrEntity(0).Pos
def nuke():
2018-12-22 03:25:18 +00:00
E = Scrap.GetFirst()
me = Scrap.UsrEntity(0)
while E:
2018-12-22 03:25:18 +00:00
if E.Name == me.Name:
E = Scrap.GetEntity(E.NextInSlot)
try:
2018-12-22 03:25:18 +00:00
E.Life = 0
E.Invulnerable = 0
except:
pass
E = Scrap.GetEntity(E.NextInSlot)
2018-12-22 03:25:18 +00:00
2017-10-07 23:37:53 +00:00
def become(name):
import CharConversor
enable_all_conv()
2017-10-07 23:37:53 +00:00
me = Scrap.UsrEntity(0)
ent = Scrap.GetEntity(name)
if ent:
2018-12-22 03:25:18 +00:00
CharConversor.Possession(me.Name, name)
2017-10-07 23:37:53 +00:00
else:
print "Entity not found"
2018-12-22 03:25:18 +00:00
2017-10-07 23:37:53 +00:00
StopMovie = 0
2018-12-22 03:25:18 +00:00
2017-10-07 23:37:53 +00:00
def movie(MovieName="Movie/Movie"):
2018-12-22 03:25:18 +00:00
global StopMovie
if LastTime == None:
Scrap.Set("PhysicalAspectRatio", 16.0/9.0)
LastTime = Scrap.GetTime()
StopMovie = 0
if StopMovie == 1:
return
Scrap.Set("DisableSkipSlot", 1)
Scrap.ProcessDVF(MovieName+".dvf", 0)
Scrap.ScreenShot(MovieName+"*")
NextTime = LastTime+1.0/25.0
Scrap.AddScheduledFunc(NextTime, movie, (Speed, MovieName, NextTime))
def find(filt="*"):
dummy = Scrap.StartDummySearch(filt, 1)
2018-12-22 03:25:18 +00:00
while dummy:
dummy = Scrap.NextDummySearch()
print dummy
def getall():
E = Scrap.GetFirst()
me = Scrap.UsrEntity(0)
while E:
try:
E.Pos = me.Pos
except:
pass
E = Scrap.GetEntity(E.NextInSlot)
def god(e=None):
if e == None:
e = Scrap.UsrEntity(0)
if e:
if e.IsType("Car"):
e.Ammo00 = SWeap.GetFAmmo(0, "Max")
e.Ammo01 = SWeap.GetFAmmo(1, "Max")
e.Ammo02 = SWeap.GetFAmmo(2, "Max")
e.Ammo03 = SWeap.GetFAmmo(3, "Max")
e.WeapList = "63,63,63,63,63,63,1"
e.MaxLife = e.MinLife
if e.Life > e.MaxLife:
e.Life = e.MaxLife
e.CMStamp = 0
e.FireStamp = 0
e.BoostTime = 0
elif e.IsType("WalkChar"):
e.Energy = 1
e.Invulnerable = 1
Scrap.DeleteScheduledFuncs("dbg.god")
Scrap.DeleteScheduledFuncs("dbg.god")
Scrap.AddScheduledFunc(Scrap.GetTime(), god, (e,), "dbg.god")
def ultranuke():
nuke()
Scrap.DeleteScheduledFuncs("dbg.ultranuke")
Scrap.DeleteScheduledFuncs("dbg.ultranuke")
Scrap.AddScheduledFunc(Scrap.GetTime(), ultranuke,
(), "dbg.ultranuke")
def brake():
if me:
me.Vel = (0, 0, 0)
for _ in range(1024):
Scrap.DeleteScheduledFuncs("dbg.dbg_info")
Scrap.DeleteScheduledFuncs("dbg.god")
Scrap.DeleteScheduledFuncs("dbg_info")
2018-12-22 03:25:18 +00:00
for module in sys.builtin_module_names:
if module[0] == "S":
print "Loading "+module
exec("import " + module)
sys.settrace(None)
2018-12-22 03:25:18 +00:00
me = Scrap.UsrEntity(0)
2018-12-22 03:25:18 +00:00
notrace()
2017-10-07 23:37:53 +00:00
helplib()
2018-12-22 03:25:18 +00:00
# settrace()
dgb_info()
enable_all_conv()
god()
Scrap.Set("debug", 3)
Scrap.Set("ShowConsoleLog", 1)
Scrap.Set("AlwaysFlushLog", 1)
Scrap.Set("PythonExecute", "import dbg")
exec("import QuickConsole;QuickConsole.debug=sys.modules['dbg']")
2018-12-22 03:25:18 +00:00
print "Debug Module loaded"