What is this?
We all know how cool the autoexecconfig function is, but also that it doesn't support appending if you add a new convar.
There are several threads and also a few bug reports mentioning this, but somehow nobody wrote an complete working solution till now.
Currently i work on a bigger project where convars sometimes are added every second release.
In times of plugins like the updater, people expect to not have to add new convars by hand at release.
Enough reasons for me to try to write an solution for this "mess".
The most important things i had in mind were security, performance, easy implementation and consistent files (white spaces, newlines)
I've came up with a working but relatively slow solution with some limitations.
How does it work?
If you add a convar with the appropriate function it will be searched in the auto-config-file you have set before.
If it can't be found within the file, it will add it with the information you created the convar with.
After that, the file should be cleaned from unnecessary white spaces created by the user or autoexecconfig itself. This is done purely for the viewers pleasure and to conserve some bytes.
Isn't that expensive?
It is, unfortunately file operations are expensive, there's nothing i can do about it.
You can run the example file and see for yourself how fast it is.
You can view the source and some more information on Github
I'd love to receive pull request over Github and/or hear some ideas, criticism or enhancements.
Although all functions return something, some also multiple defined values/codes, you currently can't get the return of the parser/appender while adding a convar.
This could be fixed with a by ref value, but i feel that, in some cases, it would make the command longer than it needs to be.
As a workaround this can be retrieved directly after you created a convar with one of the AutoExecConfig_Get*Result functions.
If you clean the configfile from white spaces or other unnecessary chars, also those made by users are removed.
This include requires the sourcemod 1.7 compiler, see here
for more information.
The prototype or name of some functions may be changed or even removed in later versions, but this will not cause compatibility issues with plugins.
Convars with a FCVAR_DONTRECORD flag will be skipped by the appender.
The parser will ignore spaces between convars and values, inside values or behind values for security.
The search, by default, is case sensitive.
The cleaner will format your file the way autoexecconfig does, 2 spaces after information, 1 after convars.
The value of a convar must be quoted, otherwise the parser will not find it.
Please let me know if you use this in your plugin. I'm interested in how it's used.
Here is a basic example of the usage. Please also take a look at the include file and the test plugin for more functions.
// Set the file for the include, the extnesion can be omitted
AutoExecConfig_CreateConVar("sm_myplugin_enabled", "1", "Whether or not this plugin is enabled");
AutoExecConfig_CreateConVar("sm_myplugin_chattrigger", "myplugin", "Chattrigger to open the menu of this plugin");
AutoExecConfig_CreateConVar("sm_myplugin_adminflag", "b", "Adminflag needed to use the chattrigger");
// This makes an internal call to AutoExecConfig with the given configfile
// Cleaning is an relatively expensive operation and should be done at the end