Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "Main.h"
- ConfigEntry pEntries[] = {
- //Chicken
- {"Chicken", "Town life", "0", CONFIG_INT, &v_TownLifeChicken},
- };
- bool readConfig ()
- {
- char pFile[65535];
- strncpy_s(pFile, sizeof(pFile), szPath, sizeof(pFile));
- strcat_s(pFile, "\\pk.ini");
- char nRet[65535];
- for (int i = 0; i < ArraySize(pEntries); i++)
- {
- GetPrivateProfileString(pEntries[i].pSection, pEntries[i].pKey, pEntries[i].pDefault, nRet, sizeof(nRet), pFile);
- if (pEntries[i].nType == CONFIG_BOOL)
- *(PBOOL)pEntries[i].nVar = getBool(nRet);
- else if (pEntries[i].nType == CONFIG_INT)
- *(PINT)pEntries[i].nVar = atoi(nRet);
- else if (pEntries[i].nType == CONFIG_STRING)
- strncpy_s((PCHAR)pEntries[i].nVar, sizeof((PCHAR)pEntries[i].nVar), nRet, sizeof(nRet));
- }
- return true;
- }
- bool getBool(char* pLower)
- {
- if ((_stricmp(pLower, "1") == 0) || (_stricmp(pLower, "y") == 0) || (_stricmp(pLower, "yes") == 0) || (_stricmp(pLower, "true") == 0))
- return true;
- return false;
- }
- VOID setConfig(char* pKey, char* pValue)
- {
- if (strlen(pKey) == 0 || strlen(pValue) == 0)
- return;
- for (int i = 0; i < ArraySize(pEntries); i++)
- {
- if (_strcmpi(pKey, pEntries[i].pKey) == 0)
- {
- if (pEntries[i].nType == CONFIG_BOOL)
- {
- *(PBOOL)pEntries[i].nVar = getBool(pValue);
- Print("ÿc0%s is now set to %i", pEntries[i].pKey, ((*(PBOOL)pEntries[i].nVar) ? "true" : "false"));
- } else if (pEntries[i].nType == CONFIG_INT) {
- *(PINT)pEntries[i].nVar = atoi(pValue);
- Print("ÿc0%s is now set to %d", pEntries[i].pKey, *(PINT)pEntries[i].nVar);
- } else if (pEntries[i].nType == CONFIG_STRING) {
- strncpy_s((PCHAR)pEntries[i].nVar, sizeof((PCHAR)pEntries[i].nVar), pValue, sizeof(pValue));
- Print("ÿc0%s is now set to %s", pEntries[i].pKey, (PCHAR)pEntries[i].nVar);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement