@amxts/config-core 0.1.2 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/include/universal_config.inc +355 -355
- package/package.json +2 -2
- package/prebuilt/linux/config-core.aot +0 -0
- package/prebuilt/manifest.json +20 -19
- package/prebuilt/windows/config-core.aot +0 -0
- package/src/natives.ts +271 -271
|
@@ -1,355 +1,355 @@
|
|
|
1
|
-
#if defined _universal_config_included
|
|
2
|
-
#endinput
|
|
3
|
-
#endif
|
|
4
|
-
#define _universal_config_included
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Universal Config System — public API include
|
|
8
|
-
* Version: 1.6.1
|
|
9
|
-
* Author: kukson777
|
|
10
|
-
*
|
|
11
|
-
* A flexible configuration system for parsing, managing and writing INI-like
|
|
12
|
-
* files with support for nested sections, key-value pairs and block structures.
|
|
13
|
-
*/
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Configuration file handle.
|
|
17
|
-
*/
|
|
18
|
-
enum ConfigFile {
|
|
19
|
-
CFG_FILE_INVALID = -1
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Configuration section handle.
|
|
24
|
-
*/
|
|
25
|
-
enum ConfigSection {
|
|
26
|
-
CFG_SECTION_INVALID = -1
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Entry structure type used inside a config section.
|
|
31
|
-
*/
|
|
32
|
-
enum EntryType {
|
|
33
|
-
CFG_ENTRY_SIMPLE, // Simple key = value entry
|
|
34
|
-
CFG_ENTRY_BRACKET // Block entry: key { ... }
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Content type of an entry's value.
|
|
39
|
-
*/
|
|
40
|
-
enum ContentType {
|
|
41
|
-
CFG_CONTENT_SIMPLE = 0, // Single value
|
|
42
|
-
CFG_CONTENT_STRINGS, // Array of strings
|
|
43
|
-
CFG_CONTENT_ENTRIES // Array of nested entries
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
// ============================================================
|
|
47
|
-
// Loading and section lookup
|
|
48
|
-
// ============================================================
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* Loads a configuration file.
|
|
52
|
-
*
|
|
53
|
-
* @param fileName File name (e.g. "menu.ini"). If no extension is given,
|
|
54
|
-
* ".ini" is appended automatically.
|
|
55
|
-
* @return A ConfigFile handle on success, CFG_FILE_INVALID on failure.
|
|
56
|
-
*/
|
|
57
|
-
native ConfigFile:cfg_load_file(const fileName[]);
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* Retrieves a section handle by name from a loaded configuration.
|
|
61
|
-
*
|
|
62
|
-
* @param cfg ConfigFile handle returned by cfg_load_file.
|
|
63
|
-
* @param sectionName Name of the section to look up.
|
|
64
|
-
* @return A ConfigSection handle on success,
|
|
65
|
-
* CFG_SECTION_INVALID if not found.
|
|
66
|
-
*/
|
|
67
|
-
native ConfigSection:cfg_get_section(ConfigFile:cfg, const sectionName[]);
|
|
68
|
-
|
|
69
|
-
// ============================================================
|
|
70
|
-
// Reading values
|
|
71
|
-
// ============================================================
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* Retrieves a string value from a section.
|
|
75
|
-
*
|
|
76
|
-
* @param section ConfigSection handle.
|
|
77
|
-
* @param key Key name or path (e.g. "key" or "block/subkey").
|
|
78
|
-
* @param value Output buffer (recommended size: 512).
|
|
79
|
-
* @param len Maximum buffer length.
|
|
80
|
-
* @param index Value index for multi-value keys (default: 0).
|
|
81
|
-
* @return true if the value was found and written, false otherwise.
|
|
82
|
-
*/
|
|
83
|
-
native bool:cfg_get_value(ConfigSection:section, const key[], value[], len, index = 0);
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
* Retrieves a string value by its hierarchical path.
|
|
87
|
-
*
|
|
88
|
-
* @param section ConfigSection handle.
|
|
89
|
-
* @param path Path to the value (e.g. "MAIN/HUD").
|
|
90
|
-
* @param value Output buffer.
|
|
91
|
-
* @param len Maximum buffer length.
|
|
92
|
-
* @param index Value index (default: 0).
|
|
93
|
-
* @param lineIndex Line index within a block (default: 0).
|
|
94
|
-
* @return true if the value was found, false otherwise.
|
|
95
|
-
*/
|
|
96
|
-
native bool:cfg_get_value_by_path(ConfigSection:section, const path[], value[], len, index = 0, lineIndex = 0);
|
|
97
|
-
|
|
98
|
-
/**
|
|
99
|
-
* Retrieves an integer value from a section.
|
|
100
|
-
*
|
|
101
|
-
* @param section ConfigSection handle.
|
|
102
|
-
* @param key Key name or path.
|
|
103
|
-
* @param index Value index (default: 0).
|
|
104
|
-
* @return Integer value, or 0 if not found.
|
|
105
|
-
*/
|
|
106
|
-
native cfg_get_int(ConfigSection:section, const key[], index = 0);
|
|
107
|
-
|
|
108
|
-
/**
|
|
109
|
-
* Retrieves a float value from a section.
|
|
110
|
-
*
|
|
111
|
-
* @param section ConfigSection handle.
|
|
112
|
-
* @param key Key name or path.
|
|
113
|
-
* @param index Value index (default: 0).
|
|
114
|
-
* @return Float value, or 0.0 if not found.
|
|
115
|
-
*/
|
|
116
|
-
native Float:cfg_get_float(ConfigSection:section, const key[], index = 0);
|
|
117
|
-
|
|
118
|
-
/**
|
|
119
|
-
* Retrieves a boolean value from a section.
|
|
120
|
-
*
|
|
121
|
-
* @param section ConfigSection handle.
|
|
122
|
-
* @param key Key name or path.
|
|
123
|
-
* @param index Value index (default: 0).
|
|
124
|
-
* @return true if the value is non-zero, false if not found or zero.
|
|
125
|
-
*/
|
|
126
|
-
native bool:cfg_get_bool(ConfigSection:section, const key[], index = 0);
|
|
127
|
-
|
|
128
|
-
/**
|
|
129
|
-
* Returns a dynamic array of string tokens split from a single config line
|
|
130
|
-
* (space-delimited, quote-aware).
|
|
131
|
-
*
|
|
132
|
-
* @param section ConfigSection handle.
|
|
133
|
-
* @param key Key name or path.
|
|
134
|
-
* @param index Line index for multi-value keys (default: 0).
|
|
135
|
-
* @return Array handle with string tokens, or Invalid_Array on failure.
|
|
136
|
-
* The caller is responsible for destroying the array.
|
|
137
|
-
*/
|
|
138
|
-
native Array:cfg_get_value_array(ConfigSection:section, const key[], index = 0);
|
|
139
|
-
|
|
140
|
-
/**
|
|
141
|
-
* Returns a dynamic array of float values parsed from a single config line.
|
|
142
|
-
*
|
|
143
|
-
* @param section ConfigSection handle.
|
|
144
|
-
* @param key Key name or path.
|
|
145
|
-
* @param index Line index for multi-value keys (default: 0).
|
|
146
|
-
* @return Array handle with Float values, or Invalid_Array on failure.
|
|
147
|
-
* The caller is responsible for destroying the array.
|
|
148
|
-
*/
|
|
149
|
-
native Array:cfg_get_float_array(ConfigSection:section, const key[], index = 0);
|
|
150
|
-
|
|
151
|
-
/**
|
|
152
|
-
* Returns a dynamic array of tokens split from a value found by hierarchical path.
|
|
153
|
-
*
|
|
154
|
-
* @param section ConfigSection handle.
|
|
155
|
-
* @param path Path to the block (e.g. "MAIN/HUD").
|
|
156
|
-
* @param index Part index within the value (default: 0).
|
|
157
|
-
* @param lineIndex Line index within a block (default: 0).
|
|
158
|
-
* @return Array handle with string tokens, or Invalid_Array on failure.
|
|
159
|
-
*/
|
|
160
|
-
native Array:cfg_get_value_array_by_path(ConfigSection:section, const path[], index = 0, lineIndex = 0);
|
|
161
|
-
|
|
162
|
-
/**
|
|
163
|
-
* Returns a dynamic array containing all top-level key names in a section.
|
|
164
|
-
*
|
|
165
|
-
* @param section ConfigSection handle.
|
|
166
|
-
* @return Array handle with key strings, or Invalid_Array if empty.
|
|
167
|
-
*/
|
|
168
|
-
native Array:cfg_get_top_level_keys(ConfigSection:section);
|
|
169
|
-
|
|
170
|
-
/**
|
|
171
|
-
* Returns the raw section data as an array.
|
|
172
|
-
* The array contains three sub-arrays: keys, values and pair-index mappings.
|
|
173
|
-
*
|
|
174
|
-
* @param section ConfigSection handle.
|
|
175
|
-
* @return Array handle, or Invalid_Array if the section is empty.
|
|
176
|
-
*/
|
|
177
|
-
native Array:cfg_get_section_data(ConfigSection:section);
|
|
178
|
-
|
|
179
|
-
/**
|
|
180
|
-
* Returns the number of values associated with a key.
|
|
181
|
-
*
|
|
182
|
-
* @param section ConfigSection handle.
|
|
183
|
-
* @param key Key name or path.
|
|
184
|
-
* @return Value count, or 0 if the key is not found.
|
|
185
|
-
*/
|
|
186
|
-
native cfg_get_array_size(ConfigSection:section, const key[]);
|
|
187
|
-
|
|
188
|
-
// ============================================================
|
|
189
|
-
// Writing values
|
|
190
|
-
// ============================================================
|
|
191
|
-
|
|
192
|
-
/**
|
|
193
|
-
* Sets a string value for a key.
|
|
194
|
-
*
|
|
195
|
-
* @param section ConfigSection handle.
|
|
196
|
-
* @param key Key name.
|
|
197
|
-
* @param value String value to set.
|
|
198
|
-
* @param index Value index (default: 0).
|
|
199
|
-
* @return true on success, false otherwise.
|
|
200
|
-
*/
|
|
201
|
-
native bool:cfg_set_value(ConfigSection:section, const key[], const value[], index = 0, lineIndex = 0);
|
|
202
|
-
|
|
203
|
-
/**
|
|
204
|
-
* Sets an integer value for a key.
|
|
205
|
-
*
|
|
206
|
-
* @param section ConfigSection handle.
|
|
207
|
-
* @param key Key name.
|
|
208
|
-
* @param value Integer value.
|
|
209
|
-
* @param index Value index (default: 0).
|
|
210
|
-
* @return true on success, false otherwise.
|
|
211
|
-
*/
|
|
212
|
-
native bool:cfg_set_int(ConfigSection:section, const key[], value, index = 0);
|
|
213
|
-
|
|
214
|
-
/**
|
|
215
|
-
* Sets a float value for a key.
|
|
216
|
-
*
|
|
217
|
-
* @param section ConfigSection handle.
|
|
218
|
-
* @param key Key name.
|
|
219
|
-
* @param value Float value.
|
|
220
|
-
* @param index Value index (default: 0).
|
|
221
|
-
* @return true on success, false otherwise.
|
|
222
|
-
*/
|
|
223
|
-
native bool:cfg_set_float(ConfigSection:section, const key[], Float:value, index = 0);
|
|
224
|
-
|
|
225
|
-
/**
|
|
226
|
-
* Sets a boolean value for a key.
|
|
227
|
-
*
|
|
228
|
-
* @param section ConfigSection handle.
|
|
229
|
-
* @param key Key name.
|
|
230
|
-
* @param value Boolean value.
|
|
231
|
-
* @param index Value index (default: 0).
|
|
232
|
-
* @return true on success, false otherwise.
|
|
233
|
-
*/
|
|
234
|
-
native bool:cfg_set_bool(ConfigSection:section, const key[], bool:value, index = 0);
|
|
235
|
-
|
|
236
|
-
// ============================================================
|
|
237
|
-
// Key and section management
|
|
238
|
-
// ============================================================
|
|
239
|
-
|
|
240
|
-
/**
|
|
241
|
-
* Deletes a key from a section.
|
|
242
|
-
*
|
|
243
|
-
* @param section ConfigSection handle.
|
|
244
|
-
* @param key Key to delete.
|
|
245
|
-
* @return true if deleted, false if not found or section is invalid.
|
|
246
|
-
*/
|
|
247
|
-
native bool:cfg_delete_key(ConfigSection:section, const key[]);
|
|
248
|
-
|
|
249
|
-
/**
|
|
250
|
-
* Checks whether a key exists in a section.
|
|
251
|
-
*
|
|
252
|
-
* @param section ConfigSection handle.
|
|
253
|
-
* @param key Key to check.
|
|
254
|
-
* @return true if the key exists, false otherwise.
|
|
255
|
-
*/
|
|
256
|
-
native bool:cfg_has_key(ConfigSection:section, const key[]);
|
|
257
|
-
|
|
258
|
-
/**
|
|
259
|
-
* Creates a new in-memory section (not backed by a file).
|
|
260
|
-
*
|
|
261
|
-
* @param sectionName Name of the new section.
|
|
262
|
-
* @return ConfigSection handle on success, CFG_SECTION_INVALID on failure.
|
|
263
|
-
*/
|
|
264
|
-
native ConfigSection:cfg_create_section(ConfigFile:cfg, const sectionName[]);
|
|
265
|
-
|
|
266
|
-
/**
|
|
267
|
-
* Sets the EntryType for a key in a section.
|
|
268
|
-
*
|
|
269
|
-
* @param section ConfigSection handle.
|
|
270
|
-
* @param key Key name.
|
|
271
|
-
* @param entryType CFG_ENTRY_SIMPLE or CFG_ENTRY_BRACKET.
|
|
272
|
-
* @return true on success, false otherwise.
|
|
273
|
-
*/
|
|
274
|
-
native bool:cfg_set_entry_type(ConfigSection:section, const key[], EntryType:entryType);
|
|
275
|
-
|
|
276
|
-
/**
|
|
277
|
-
* Sets the ContentType for a key in a section.
|
|
278
|
-
*
|
|
279
|
-
* @param section ConfigSection handle.
|
|
280
|
-
* @param key Key name.
|
|
281
|
-
* @param contentType CFG_CONTENT_SIMPLE, CFG_CONTENT_STRINGS or CFG_CONTENT_ENTRIES.
|
|
282
|
-
* @return true on success, false otherwise.
|
|
283
|
-
*/
|
|
284
|
-
native bool:cfg_set_entry_content_type(ConfigSection:section, const key[], ContentType:contentType);
|
|
285
|
-
|
|
286
|
-
// ============================================================
|
|
287
|
-
// Saving and writing
|
|
288
|
-
// ============================================================
|
|
289
|
-
|
|
290
|
-
/**
|
|
291
|
-
* Writes a section to a file.
|
|
292
|
-
* Can be called with 2 arguments (fileName, sectionName) or with 3 arguments
|
|
293
|
-
* (ConfigFile:cfg, fileName, sectionName) when you need to target a specific
|
|
294
|
-
* loaded file handle.
|
|
295
|
-
*
|
|
296
|
-
* @param fileName Destination file name (e.g. "core.ini").
|
|
297
|
-
* @param sectionName Section name to write.
|
|
298
|
-
* @return true on success, false otherwise.
|
|
299
|
-
*/
|
|
300
|
-
native bool:cfg_write_file(ConfigFile:cfg, const fileName[], const sectionName[]);
|
|
301
|
-
|
|
302
|
-
/**
|
|
303
|
-
* Saves a loaded configuration back to its source file.
|
|
304
|
-
*
|
|
305
|
-
* ';' comment lines are round-tripped: a comment block is re-emitted before the
|
|
306
|
-
* element it preceded in the source (section / top-level key / bracket row).
|
|
307
|
-
* Only comments that were present in the loaded file survive — elements created
|
|
308
|
-
* programmatically (e.g. via cfg_set_value) carry no comment unless one already
|
|
309
|
-
* existed on that row. Pass fileName explicitly for multi-section files.
|
|
310
|
-
*
|
|
311
|
-
* @param cfg ConfigFile handle returned by cfg_load_file.
|
|
312
|
-
* @return true on success, false otherwise.
|
|
313
|
-
*/
|
|
314
|
-
native bool:cfg_save_config(ConfigFile:cfg, const fileName[] = "");
|
|
315
|
-
|
|
316
|
-
// ============================================================
|
|
317
|
-
// Utility
|
|
318
|
-
// ============================================================
|
|
319
|
-
|
|
320
|
-
/**
|
|
321
|
-
* Sets the base directory used when resolving relative config file names.
|
|
322
|
-
*
|
|
323
|
-
* @param dir Path to the directory (e.g. "addons/amxmodx/configs/jbe").
|
|
324
|
-
*/
|
|
325
|
-
native cfg_set_base_dir(const dir[]);
|
|
326
|
-
|
|
327
|
-
/**
|
|
328
|
-
* Returns the total number of sections currently loaded in memory.
|
|
329
|
-
*
|
|
330
|
-
* @return Section count.
|
|
331
|
-
*/
|
|
332
|
-
native cfg_get_sections_count();
|
|
333
|
-
|
|
334
|
-
/**
|
|
335
|
-
* Returns the name of a loaded section by its sequential index.
|
|
336
|
-
*
|
|
337
|
-
* @param index Zero-based section index (0 .. cfg_get_sections_count() - 1).
|
|
338
|
-
* @param name Output buffer for the section name.
|
|
339
|
-
* @param len Maximum buffer length.
|
|
340
|
-
* @return 1 on success, 0 if the index is out of range.
|
|
341
|
-
*/
|
|
342
|
-
native cfg_get_section_name(index, name[], len);
|
|
343
|
-
|
|
344
|
-
/**
|
|
345
|
-
* Sets the leading "; ..." comment of a bracket-block row (e.g. the column hint
|
|
346
|
-
* shown above the first data row). Mirrors what a file round-trip preserves, so
|
|
347
|
-
* blocks created programmatically can carry the same in-block hint.
|
|
348
|
-
*
|
|
349
|
-
* @param section Section handle (cfg_get_section / cfg_create_section).
|
|
350
|
-
* @param key Top-level bracket key holding the rows (e.g. "3x3", "CVARS").
|
|
351
|
-
* @param row Zero-based row index inside the block.
|
|
352
|
-
* @param comment Single comment line incl. leading ';'; "" clears it.
|
|
353
|
-
* @return true on success, false if the row/key was not found.
|
|
354
|
-
*/
|
|
355
|
-
native bool:cfg_set_row_comment(ConfigSection:section, const key[], row, const comment[]);
|
|
1
|
+
#if defined _universal_config_included
|
|
2
|
+
#endinput
|
|
3
|
+
#endif
|
|
4
|
+
#define _universal_config_included
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Universal Config System — public API include
|
|
8
|
+
* Version: 1.6.1
|
|
9
|
+
* Author: kukson777
|
|
10
|
+
*
|
|
11
|
+
* A flexible configuration system for parsing, managing and writing INI-like
|
|
12
|
+
* files with support for nested sections, key-value pairs and block structures.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Configuration file handle.
|
|
17
|
+
*/
|
|
18
|
+
enum ConfigFile {
|
|
19
|
+
CFG_FILE_INVALID = -1
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Configuration section handle.
|
|
24
|
+
*/
|
|
25
|
+
enum ConfigSection {
|
|
26
|
+
CFG_SECTION_INVALID = -1
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Entry structure type used inside a config section.
|
|
31
|
+
*/
|
|
32
|
+
enum EntryType {
|
|
33
|
+
CFG_ENTRY_SIMPLE, // Simple key = value entry
|
|
34
|
+
CFG_ENTRY_BRACKET // Block entry: key { ... }
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Content type of an entry's value.
|
|
39
|
+
*/
|
|
40
|
+
enum ContentType {
|
|
41
|
+
CFG_CONTENT_SIMPLE = 0, // Single value
|
|
42
|
+
CFG_CONTENT_STRINGS, // Array of strings
|
|
43
|
+
CFG_CONTENT_ENTRIES // Array of nested entries
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// ============================================================
|
|
47
|
+
// Loading and section lookup
|
|
48
|
+
// ============================================================
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Loads a configuration file.
|
|
52
|
+
*
|
|
53
|
+
* @param fileName File name (e.g. "menu.ini"). If no extension is given,
|
|
54
|
+
* ".ini" is appended automatically.
|
|
55
|
+
* @return A ConfigFile handle on success, CFG_FILE_INVALID on failure.
|
|
56
|
+
*/
|
|
57
|
+
native ConfigFile:cfg_load_file(const fileName[]);
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Retrieves a section handle by name from a loaded configuration.
|
|
61
|
+
*
|
|
62
|
+
* @param cfg ConfigFile handle returned by cfg_load_file.
|
|
63
|
+
* @param sectionName Name of the section to look up.
|
|
64
|
+
* @return A ConfigSection handle on success,
|
|
65
|
+
* CFG_SECTION_INVALID if not found.
|
|
66
|
+
*/
|
|
67
|
+
native ConfigSection:cfg_get_section(ConfigFile:cfg, const sectionName[]);
|
|
68
|
+
|
|
69
|
+
// ============================================================
|
|
70
|
+
// Reading values
|
|
71
|
+
// ============================================================
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Retrieves a string value from a section.
|
|
75
|
+
*
|
|
76
|
+
* @param section ConfigSection handle.
|
|
77
|
+
* @param key Key name or path (e.g. "key" or "block/subkey").
|
|
78
|
+
* @param value Output buffer (recommended size: 512).
|
|
79
|
+
* @param len Maximum buffer length.
|
|
80
|
+
* @param index Value index for multi-value keys (default: 0).
|
|
81
|
+
* @return true if the value was found and written, false otherwise.
|
|
82
|
+
*/
|
|
83
|
+
native bool:cfg_get_value(ConfigSection:section, const key[], value[], len, index = 0);
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Retrieves a string value by its hierarchical path.
|
|
87
|
+
*
|
|
88
|
+
* @param section ConfigSection handle.
|
|
89
|
+
* @param path Path to the value (e.g. "MAIN/HUD").
|
|
90
|
+
* @param value Output buffer.
|
|
91
|
+
* @param len Maximum buffer length.
|
|
92
|
+
* @param index Value index (default: 0).
|
|
93
|
+
* @param lineIndex Line index within a block (default: 0).
|
|
94
|
+
* @return true if the value was found, false otherwise.
|
|
95
|
+
*/
|
|
96
|
+
native bool:cfg_get_value_by_path(ConfigSection:section, const path[], value[], len, index = 0, lineIndex = 0);
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Retrieves an integer value from a section.
|
|
100
|
+
*
|
|
101
|
+
* @param section ConfigSection handle.
|
|
102
|
+
* @param key Key name or path.
|
|
103
|
+
* @param index Value index (default: 0).
|
|
104
|
+
* @return Integer value, or 0 if not found.
|
|
105
|
+
*/
|
|
106
|
+
native cfg_get_int(ConfigSection:section, const key[], index = 0);
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Retrieves a float value from a section.
|
|
110
|
+
*
|
|
111
|
+
* @param section ConfigSection handle.
|
|
112
|
+
* @param key Key name or path.
|
|
113
|
+
* @param index Value index (default: 0).
|
|
114
|
+
* @return Float value, or 0.0 if not found.
|
|
115
|
+
*/
|
|
116
|
+
native Float:cfg_get_float(ConfigSection:section, const key[], index = 0);
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Retrieves a boolean value from a section.
|
|
120
|
+
*
|
|
121
|
+
* @param section ConfigSection handle.
|
|
122
|
+
* @param key Key name or path.
|
|
123
|
+
* @param index Value index (default: 0).
|
|
124
|
+
* @return true if the value is non-zero, false if not found or zero.
|
|
125
|
+
*/
|
|
126
|
+
native bool:cfg_get_bool(ConfigSection:section, const key[], index = 0);
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Returns a dynamic array of string tokens split from a single config line
|
|
130
|
+
* (space-delimited, quote-aware).
|
|
131
|
+
*
|
|
132
|
+
* @param section ConfigSection handle.
|
|
133
|
+
* @param key Key name or path.
|
|
134
|
+
* @param index Line index for multi-value keys (default: 0).
|
|
135
|
+
* @return Array handle with string tokens, or Invalid_Array on failure.
|
|
136
|
+
* The caller is responsible for destroying the array.
|
|
137
|
+
*/
|
|
138
|
+
native Array:cfg_get_value_array(ConfigSection:section, const key[], index = 0);
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Returns a dynamic array of float values parsed from a single config line.
|
|
142
|
+
*
|
|
143
|
+
* @param section ConfigSection handle.
|
|
144
|
+
* @param key Key name or path.
|
|
145
|
+
* @param index Line index for multi-value keys (default: 0).
|
|
146
|
+
* @return Array handle with Float values, or Invalid_Array on failure.
|
|
147
|
+
* The caller is responsible for destroying the array.
|
|
148
|
+
*/
|
|
149
|
+
native Array:cfg_get_float_array(ConfigSection:section, const key[], index = 0);
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Returns a dynamic array of tokens split from a value found by hierarchical path.
|
|
153
|
+
*
|
|
154
|
+
* @param section ConfigSection handle.
|
|
155
|
+
* @param path Path to the block (e.g. "MAIN/HUD").
|
|
156
|
+
* @param index Part index within the value (default: 0).
|
|
157
|
+
* @param lineIndex Line index within a block (default: 0).
|
|
158
|
+
* @return Array handle with string tokens, or Invalid_Array on failure.
|
|
159
|
+
*/
|
|
160
|
+
native Array:cfg_get_value_array_by_path(ConfigSection:section, const path[], index = 0, lineIndex = 0);
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Returns a dynamic array containing all top-level key names in a section.
|
|
164
|
+
*
|
|
165
|
+
* @param section ConfigSection handle.
|
|
166
|
+
* @return Array handle with key strings, or Invalid_Array if empty.
|
|
167
|
+
*/
|
|
168
|
+
native Array:cfg_get_top_level_keys(ConfigSection:section);
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* Returns the raw section data as an array.
|
|
172
|
+
* The array contains three sub-arrays: keys, values and pair-index mappings.
|
|
173
|
+
*
|
|
174
|
+
* @param section ConfigSection handle.
|
|
175
|
+
* @return Array handle, or Invalid_Array if the section is empty.
|
|
176
|
+
*/
|
|
177
|
+
native Array:cfg_get_section_data(ConfigSection:section);
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Returns the number of values associated with a key.
|
|
181
|
+
*
|
|
182
|
+
* @param section ConfigSection handle.
|
|
183
|
+
* @param key Key name or path.
|
|
184
|
+
* @return Value count, or 0 if the key is not found.
|
|
185
|
+
*/
|
|
186
|
+
native cfg_get_array_size(ConfigSection:section, const key[]);
|
|
187
|
+
|
|
188
|
+
// ============================================================
|
|
189
|
+
// Writing values
|
|
190
|
+
// ============================================================
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* Sets a string value for a key.
|
|
194
|
+
*
|
|
195
|
+
* @param section ConfigSection handle.
|
|
196
|
+
* @param key Key name.
|
|
197
|
+
* @param value String value to set.
|
|
198
|
+
* @param index Value index (default: 0).
|
|
199
|
+
* @return true on success, false otherwise.
|
|
200
|
+
*/
|
|
201
|
+
native bool:cfg_set_value(ConfigSection:section, const key[], const value[], index = 0, lineIndex = 0);
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* Sets an integer value for a key.
|
|
205
|
+
*
|
|
206
|
+
* @param section ConfigSection handle.
|
|
207
|
+
* @param key Key name.
|
|
208
|
+
* @param value Integer value.
|
|
209
|
+
* @param index Value index (default: 0).
|
|
210
|
+
* @return true on success, false otherwise.
|
|
211
|
+
*/
|
|
212
|
+
native bool:cfg_set_int(ConfigSection:section, const key[], value, index = 0);
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* Sets a float value for a key.
|
|
216
|
+
*
|
|
217
|
+
* @param section ConfigSection handle.
|
|
218
|
+
* @param key Key name.
|
|
219
|
+
* @param value Float value.
|
|
220
|
+
* @param index Value index (default: 0).
|
|
221
|
+
* @return true on success, false otherwise.
|
|
222
|
+
*/
|
|
223
|
+
native bool:cfg_set_float(ConfigSection:section, const key[], Float:value, index = 0);
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* Sets a boolean value for a key.
|
|
227
|
+
*
|
|
228
|
+
* @param section ConfigSection handle.
|
|
229
|
+
* @param key Key name.
|
|
230
|
+
* @param value Boolean value.
|
|
231
|
+
* @param index Value index (default: 0).
|
|
232
|
+
* @return true on success, false otherwise.
|
|
233
|
+
*/
|
|
234
|
+
native bool:cfg_set_bool(ConfigSection:section, const key[], bool:value, index = 0);
|
|
235
|
+
|
|
236
|
+
// ============================================================
|
|
237
|
+
// Key and section management
|
|
238
|
+
// ============================================================
|
|
239
|
+
|
|
240
|
+
/**
|
|
241
|
+
* Deletes a key from a section.
|
|
242
|
+
*
|
|
243
|
+
* @param section ConfigSection handle.
|
|
244
|
+
* @param key Key to delete.
|
|
245
|
+
* @return true if deleted, false if not found or section is invalid.
|
|
246
|
+
*/
|
|
247
|
+
native bool:cfg_delete_key(ConfigSection:section, const key[]);
|
|
248
|
+
|
|
249
|
+
/**
|
|
250
|
+
* Checks whether a key exists in a section.
|
|
251
|
+
*
|
|
252
|
+
* @param section ConfigSection handle.
|
|
253
|
+
* @param key Key to check.
|
|
254
|
+
* @return true if the key exists, false otherwise.
|
|
255
|
+
*/
|
|
256
|
+
native bool:cfg_has_key(ConfigSection:section, const key[]);
|
|
257
|
+
|
|
258
|
+
/**
|
|
259
|
+
* Creates a new in-memory section (not backed by a file).
|
|
260
|
+
*
|
|
261
|
+
* @param sectionName Name of the new section.
|
|
262
|
+
* @return ConfigSection handle on success, CFG_SECTION_INVALID on failure.
|
|
263
|
+
*/
|
|
264
|
+
native ConfigSection:cfg_create_section(ConfigFile:cfg, const sectionName[]);
|
|
265
|
+
|
|
266
|
+
/**
|
|
267
|
+
* Sets the EntryType for a key in a section.
|
|
268
|
+
*
|
|
269
|
+
* @param section ConfigSection handle.
|
|
270
|
+
* @param key Key name.
|
|
271
|
+
* @param entryType CFG_ENTRY_SIMPLE or CFG_ENTRY_BRACKET.
|
|
272
|
+
* @return true on success, false otherwise.
|
|
273
|
+
*/
|
|
274
|
+
native bool:cfg_set_entry_type(ConfigSection:section, const key[], EntryType:entryType);
|
|
275
|
+
|
|
276
|
+
/**
|
|
277
|
+
* Sets the ContentType for a key in a section.
|
|
278
|
+
*
|
|
279
|
+
* @param section ConfigSection handle.
|
|
280
|
+
* @param key Key name.
|
|
281
|
+
* @param contentType CFG_CONTENT_SIMPLE, CFG_CONTENT_STRINGS or CFG_CONTENT_ENTRIES.
|
|
282
|
+
* @return true on success, false otherwise.
|
|
283
|
+
*/
|
|
284
|
+
native bool:cfg_set_entry_content_type(ConfigSection:section, const key[], ContentType:contentType);
|
|
285
|
+
|
|
286
|
+
// ============================================================
|
|
287
|
+
// Saving and writing
|
|
288
|
+
// ============================================================
|
|
289
|
+
|
|
290
|
+
/**
|
|
291
|
+
* Writes a section to a file.
|
|
292
|
+
* Can be called with 2 arguments (fileName, sectionName) or with 3 arguments
|
|
293
|
+
* (ConfigFile:cfg, fileName, sectionName) when you need to target a specific
|
|
294
|
+
* loaded file handle.
|
|
295
|
+
*
|
|
296
|
+
* @param fileName Destination file name (e.g. "core.ini").
|
|
297
|
+
* @param sectionName Section name to write.
|
|
298
|
+
* @return true on success, false otherwise.
|
|
299
|
+
*/
|
|
300
|
+
native bool:cfg_write_file(ConfigFile:cfg, const fileName[], const sectionName[]);
|
|
301
|
+
|
|
302
|
+
/**
|
|
303
|
+
* Saves a loaded configuration back to its source file.
|
|
304
|
+
*
|
|
305
|
+
* ';' comment lines are round-tripped: a comment block is re-emitted before the
|
|
306
|
+
* element it preceded in the source (section / top-level key / bracket row).
|
|
307
|
+
* Only comments that were present in the loaded file survive — elements created
|
|
308
|
+
* programmatically (e.g. via cfg_set_value) carry no comment unless one already
|
|
309
|
+
* existed on that row. Pass fileName explicitly for multi-section files.
|
|
310
|
+
*
|
|
311
|
+
* @param cfg ConfigFile handle returned by cfg_load_file.
|
|
312
|
+
* @return true on success, false otherwise.
|
|
313
|
+
*/
|
|
314
|
+
native bool:cfg_save_config(ConfigFile:cfg, const fileName[] = "");
|
|
315
|
+
|
|
316
|
+
// ============================================================
|
|
317
|
+
// Utility
|
|
318
|
+
// ============================================================
|
|
319
|
+
|
|
320
|
+
/**
|
|
321
|
+
* Sets the base directory used when resolving relative config file names.
|
|
322
|
+
*
|
|
323
|
+
* @param dir Path to the directory (e.g. "addons/amxmodx/configs/jbe").
|
|
324
|
+
*/
|
|
325
|
+
native cfg_set_base_dir(const dir[]);
|
|
326
|
+
|
|
327
|
+
/**
|
|
328
|
+
* Returns the total number of sections currently loaded in memory.
|
|
329
|
+
*
|
|
330
|
+
* @return Section count.
|
|
331
|
+
*/
|
|
332
|
+
native cfg_get_sections_count();
|
|
333
|
+
|
|
334
|
+
/**
|
|
335
|
+
* Returns the name of a loaded section by its sequential index.
|
|
336
|
+
*
|
|
337
|
+
* @param index Zero-based section index (0 .. cfg_get_sections_count() - 1).
|
|
338
|
+
* @param name Output buffer for the section name.
|
|
339
|
+
* @param len Maximum buffer length.
|
|
340
|
+
* @return 1 on success, 0 if the index is out of range.
|
|
341
|
+
*/
|
|
342
|
+
native cfg_get_section_name(index, name[], len);
|
|
343
|
+
|
|
344
|
+
/**
|
|
345
|
+
* Sets the leading "; ..." comment of a bracket-block row (e.g. the column hint
|
|
346
|
+
* shown above the first data row). Mirrors what a file round-trip preserves, so
|
|
347
|
+
* blocks created programmatically can carry the same in-block hint.
|
|
348
|
+
*
|
|
349
|
+
* @param section Section handle (cfg_get_section / cfg_create_section).
|
|
350
|
+
* @param key Top-level bracket key holding the rows (e.g. "3x3", "CVARS").
|
|
351
|
+
* @param row Zero-based row index inside the block.
|
|
352
|
+
* @param comment Single comment line incl. leading ';'; "" clears it.
|
|
353
|
+
* @return true on success, false if the row/key was not found.
|
|
354
|
+
*/
|
|
355
|
+
native bool:cfg_set_row_comment(ConfigSection:section, const key[], row, const comment[]);
|