From ee93967d423003e1539af862ac9d6c5d759c8e87 Mon Sep 17 00:00:00 2001 From: TimePath Date: Sat, 26 Sep 2015 20:27:12 +1000 Subject: [PATCH] effectinfo: dumpeffectinfo command --- qcsrc/common/command/generic.qc | 42 ++++++++++++++++++++++++++++++ qcsrc/common/effects/effectinfo.qc | 8 +++--- 2 files changed, 47 insertions(+), 3 deletions(-) diff --git a/qcsrc/common/command/generic.qc b/qcsrc/common/command/generic.qc index 0c8f85816..64083a89d 100644 --- a/qcsrc/common/command/generic.qc +++ b/qcsrc/common/command/generic.qc @@ -240,6 +240,47 @@ void GenericCommand_dumpcommands(float request) } } +void effectinfo_dump(int fh, bool alsoprint); +void GenericCommand_dumpeffectinfo(float request) +{ + switch (request) { + case CMD_REQUEST_COMMAND: { + #ifndef MENUQC + string filename = argv(1); + bool alsoprint = false; + if (filename == "") { + filename = "effectinfo_dump.txt"; + alsoprint = false; + } else if (filename == "-") { + filename = "effectinfo_dump.txt"; + alsoprint = true; + } + int fh = fopen(filename, FILE_WRITE); + if (fh >= 0) { + effectinfo_dump(fh, alsoprint); + LOG_INFOF("Dumping effectinfo... File located at ^2data/data/%s^7.\n", filename); + LOG_INFOF("Reload with ^2cl_particles_reloadeffects data/%s^7.\n", filename); + fclose(fh); + } else { + LOG_WARNINGF("Could not open file '%s'!\n", filename); + } + #else + LOG_INFO(_("Effectinfo dump command only works with cl_cmd and sv_cmd.\n")); + #endif + return; + } + default: + case CMD_REQUEST_USAGE: { + LOG_INFO(strcat("\nUsage:^3 ", GetProgramCommandPrefix(), " dumpeffectinfo [filename]")); + LOG_INFO(" Where 'filename' is the file to write (default is effectinfo_dump.txt),\n"); + LOG_INFO(" if supplied with '-' output to console as well as default,\n"); + LOG_INFO(" if left blank, it will only write to default.\n"); + return; + } + } +} +STATIC_INIT(dumpeffectinfo) { localcmd("alias dumpeffectinfo \"qc_cmd_svcl dumpeffectinfo ${* ?}\"\n"); } + void GenericCommand_dumpitems(float request) { switch(request) @@ -722,6 +763,7 @@ void GenericCommand_(float request) #define GENERIC_COMMANDS(request,arguments,command) \ GENERIC_COMMAND("addtolist", GenericCommand_addtolist(request, arguments), "Add a string to a cvar") \ GENERIC_COMMAND("dumpcommands", GenericCommand_dumpcommands(request), "Dump all commands on the program to *_cmd_dump.txt") \ + GENERIC_COMMAND("dumpeffectinfo", GenericCommand_dumpeffectinfo(request), "Dump all effectinfo to effectinfo_dump.txt") \ GENERIC_COMMAND("dumpitems", GenericCommand_dumpitems(request), "Dump all items to the console") \ GENERIC_COMMAND("dumpnotifs", GenericCommand_dumpnotifs(request), "Dump all notifications into notifications_dump.txt") \ GENERIC_COMMAND("dumpturrets", GenericCommand_dumpturrets(request), "Dump all turrets into turrets_dump.txt") \ diff --git a/qcsrc/common/effects/effectinfo.qc b/qcsrc/common/effects/effectinfo.qc index 0288f9e9d..6d5732d2f 100644 --- a/qcsrc/common/effects/effectinfo.qc +++ b/qcsrc/common/effects/effectinfo.qc @@ -257,11 +257,13 @@ void effectinfo_read() fclose(fh); } -void effectinfo_dump() +void effectinfo_dump(int fh, bool alsoprint) { for (EffectInfo it = NULL; (it = findfloat(it, instanceOfEffectInfo, true)); ) { if (it.classname == "vtbl") continue; - print(it.dump(it)); + string s = it.dump(it); + fputs(fh, s); + if (alsoprint) print(s); } } @@ -284,7 +286,7 @@ REGISTER_REGISTRY(RegisterEffectInfo) #define MY(f) this.effectinfo_##f #define DEF(name) EFFECTINFO(name) #define SUB(name) \ - [[accumulate]] void effectinfo_##name(EffectInfoGroup parent, EffectInfo this) { parent = EFFECTINFO_##name; parent.children[parent.children_count++] = this = NEW(EffectInfo); } \ + [[accumulate]] void effectinfo_##name(EffectInfoGroup parent, EffectInfo this) { parent = EFFECTINFO_##name; parent.children[parent.children_count++] = this = NEW(EffectInfo, #name); } \ [[accumulate]] void effectinfo_##name(EffectInfoGroup parent, EffectInfo this) #include "effectinfo.inc" #undef MY -- 2.39.2