From f865fb10a6bb625cbfff57ec1e69f496568511f4 Mon Sep 17 00:00:00 2001 From: false_genesis Date: Tue, 19 Feb 2008 22:42:14 +0000 Subject: [PATCH] * added script preload cmd #escape-all=0/1 to autoescape parts of scripts, to ease up hooking and related... what needs escaping in general * added first part of a script to help with other scripts hooking --- bin/scripts/__core_hookHelper.def | 54 ++++++++++++++++++++++++++++++ src/Client/DefScript/DefScript.cpp | 10 ++++++ 2 files changed, 64 insertions(+) create mode 100644 bin/scripts/__core_hookHelper.def diff --git a/bin/scripts/__core_hookHelper.def b/bin/scripts/__core_hookHelper.def new file mode 100644 index 0000000..f437e32 --- /dev/null +++ b/bin/scripts/__core_hookHelper.def @@ -0,0 +1,54 @@ + +#script=IsHooked +// @def: script name +return ?{ScriptHasLine,{${@def}} #tag:hook:${@caller}} + +#script=HookStart +// @def: script name +appenddef,{${@def}} #tag:hook:${@caller} +set,{#HookHelper::CurScript} ${@def} + +#script=HookEnd +set,sc ${@0} +default,sc ${#HookHelper::CurScript} +appenddef,{${sc}} #tag:hook-end:${@caller} +unset ${sc} +unset sc + +#script=HookAdd +// @def: script line +// @0: script name +set,sc ${@0} +default,sc ${#HookHelper::CurScript} +appenddef,{${sc}} ${@def} +unset sc + +#script=HookAddList +// @def: list name +// @0: script name +set,sc ${@0} +set,l ?{globname,{${@caller}} ${@def}} +default,sc ${#HookHelper::CurScript} +set,i 0 +loop + if ?{bigger_eq,${i} ?{llen ${l}}} + exitloop + endif + HookAdd,{${sc}} ?{lindex,{${l}} ${i}} + add,i 1 +endloop +unset sc + +#script=HookStartOpcode +// @def: opcode name +HookStart OPCODE::${@def} + + +////////////////////////////////////////////////////////// +#comments-start +TODO: +- add UnHook[,which_script] hook_name +- add UnHookAll which_script +- Add HookStartAfter + +#comments-end \ No newline at end of file diff --git a/src/Client/DefScript/DefScript.cpp b/src/Client/DefScript/DefScript.cpp index 888b3dd..fd855eb 100644 --- a/src/Client/DefScript/DefScript.cpp +++ b/src/Client/DefScript/DefScript.cpp @@ -260,6 +260,7 @@ bool DefScriptPackage::LoadScriptFromFile(std::string fn){ bool load_debug=false,load_notify=false,cantload=false; bool line_strip = true; // true by default bool commented = false; + bool escape_all = false; char z; unsigned int absline=0; DefScript *curScript = NULL; @@ -363,6 +364,10 @@ bool DefScriptPackage::LoadScriptFromFile(std::string fn){ { line_strip = isTrue(value); } + else if(label=="escape-all") + { + escape_all = isTrue(value); + } else if(line=="debug") { if(curScript) @@ -392,6 +397,11 @@ bool DefScriptPackage::LoadScriptFromFile(std::string fn){ continue; // line was an option, not script content } + if(escape_all) + { + line = EscapeString(line); + } + // help with loading lines where a space or tab have accidently been put after the cmd std::string tline=stringToLower(line); if(memcmp(tline.c_str(),"else ",5)==0 || memcmp(tline.c_str(),"else\t",5)==0) tline="else";