Files
CHOMPStation2/code/modules/vore/trycatch_vr.dm
2025-09-14 20:05:26 +02:00

65 lines
1.8 KiB
Plaintext

/*
This file is for jamming single-line procs into Polaris procs.
It will prevent runtimes and allow their code to run if VOREStation's fails.
It will also log when we mess up our code rather than making it vague.
Call it at the top of a stock proc with...
if(attempt_vr(object,proc to call,args)) return
...if you are replacing an entire proc.
The proc you're attemping should return nonzero values on success.
*/
/proc/attempt_vr(callon, procname, list/arguments=null)
try
if(!callon || !procname)
log_world("## ERROR attempt_vr: Invalid obj/proc: [callon]/[procname]")
return 0
var/result = call(callon,procname)(arglist(arguments))
return result
catch(var/exception/e)
log_world("## ERROR attempt_vr runtimed when calling [procname] on [callon].")
log_world("## ERROR attempt_vr catch: [e] on [e.file]:[e.line]")
log_runtime(e)
return 0
/*
This is the _vr version of calling hooks.
It's meant to have different messages, and also the try/catch block.
For when you want hooks and want to know when you ruin everything,
vs when Polaris ruins everything.
Call it at the top of a stock proc with...
if(hook_vr(proc,args)) return
...if you are replacing an entire proc.
The hooks you're calling should return nonzero values on success.
*/
/proc/hook_vr(hook, list/arguments=null)
try
var/hook_path = text2path("/hook/[hook]")
if(!hook_path)
log_world("## ERROR hook_vr: Invalid hook '/hook/[hook]' called.")
return 0
var/hook_instance = new hook_path
var/status = 1
for(var/P in typesof("[hook_path]/proc"))
if(!call(hook_instance, P)(arglist(arguments)))
log_world("## ERROR hook_vr: Hook '[P]' failed or runtimed.")
status = 0
return status
catch(var/exception/e)
log_world("## ERROR hook_vr itself failed or runtimed. Exception below.")
log_world("## ERROR hook_vr catch: [e] on [e.file]:[e.line]")
log_runtime(e)