]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/turrets/all.qh
Fix array indices out of bounds; abort dump if a weapon / turret has more than MAX_CO...
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / turrets / all.qh
1 #pragma once
2
3 #include <common/command/_mod.qh>
4 #include "config.qh"
5
6 #include "turret.qh"
7
8 REGISTRY(Turrets, BITS(5))
9 #define Turrets_from(i) _Turrets_from(i, TUR_Null)
10 #define get_turretinfo(i) Turrets_from(i)
11 REGISTER_REGISTRY(Turrets)
12 REGISTRY_CHECK(Turrets)
13
14 #define TR_PROPS(L, class, prefix) \
15         L(TR_CONFIG_BEGIN, TR_CONFIG, TR_CONFIG_END, class, prefix) \
16         /**/ \
17
18 #define TR_CONFIG(class, turname, fld, T)     _TR_CONFIG(class, fld, T, turname)
19 #define TR_CONFIG_BEGIN(class) METHOD(class, tr_config, void(class this)) {
20         #ifdef SVQC
21                 #define _TR_CONFIG(class, fld, T, turname) if (#turname == this.netname) TUR_CONFIG_WRITE_CVARS(turname, fld, T);
22         #else
23                 #define _TR_CONFIG(class, fld, T, turname)
24         #endif
25 #define TR_CONFIG_END() }
26
27 GENERIC_COMMAND(dumpturrets, "Dump all turrets into turrets_dump.txt")
28 {
29     switch(request)
30     {
31         case CMD_REQUEST_COMMAND:
32         {
33             #ifdef SVQC
34             tur_config_file = -1;
35             tur_config_alsoprint = -1;
36             string filename = argv(1);
37
38             if(filename == "")
39             {
40                 filename = "turrets_dump.cfg";
41                 tur_config_alsoprint = false;
42             }
43             else if(filename == "-")
44             {
45                 filename = "turrets_dump.cfg";
46                 tur_config_alsoprint = true;
47             }
48             tur_config_file = fopen(filename, FILE_WRITE);
49
50             if(tur_config_file >= 0)
51             {
52                 Dump_Turret_Settings();
53                 LOG_INFOF("Dumping turrets... File located in ^2data/data/%s^7.", filename);
54                 fclose(tur_config_file);
55                 tur_config_file = -1;
56                 tur_config_alsoprint = -1;
57             }
58             else
59             {
60                 LOG_INFOF("^1Error: ^7Could not open file '%s'!", filename);
61             }
62             #else
63             LOG_INFO(_("Turrets dump command only works with sv_cmd."));
64             #endif
65             return;
66         }
67
68         default:
69         case CMD_REQUEST_USAGE:
70         {
71             LOG_INFO("Usage:^3 ", GetProgramCommandPrefix(), " dumpturrets [filename]");
72             LOG_INFO("  Where 'filename' is the file to write (default is turrets_dump.cfg),");
73             LOG_INFO("  if supplied with '-' output to console as well as default,");
74             LOG_INFO("  if left blank, it will only write to default.");
75             return;
76         }
77     }
78 }
79
80
81 const int TUR_FIRST = 1;
82 #define TUR_LAST (Turrets_COUNT - 1)
83
84 #define REGISTER_TURRET(id, inst) REGISTER(Turrets, TUR, id, m_id, inst)
85
86 REGISTER_TURRET(Null, NEW(Turret));
87
88 #include "turret/_mod.qh"