Advertisement
Guest User

Untitled

a guest
Jun 20th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include "Main.h"
  2.  
  3. ConfigEntry pEntries[] = {
  4.  
  5.     //Chicken
  6.     {"Chicken", "Town life", "0", CONFIG_INT, &v_TownLifeChicken},
  7.  
  8. };
  9.  
  10. bool readConfig ()
  11. {
  12.     char pFile[65535];
  13.     strncpy_s(pFile, sizeof(pFile), szPath, sizeof(pFile));
  14.     strcat_s(pFile, "\\pk.ini");
  15.  
  16.     char nRet[65535];
  17.     for (int i = 0; i < ArraySize(pEntries); i++)
  18.     {
  19.         GetPrivateProfileString(pEntries[i].pSection, pEntries[i].pKey, pEntries[i].pDefault, nRet, sizeof(nRet), pFile);
  20.         if (pEntries[i].nType == CONFIG_BOOL)
  21.             *(PBOOL)pEntries[i].nVar = getBool(nRet);
  22.         else if (pEntries[i].nType == CONFIG_INT)
  23.             *(PINT)pEntries[i].nVar = atoi(nRet);
  24.         else if (pEntries[i].nType == CONFIG_STRING)
  25.             strncpy_s((PCHAR)pEntries[i].nVar, sizeof((PCHAR)pEntries[i].nVar), nRet, sizeof(nRet));
  26.     }
  27.  
  28.     return true;
  29. }
  30.  
  31. bool getBool(char* pLower)
  32. {
  33.     if ((_stricmp(pLower, "1") == 0) || (_stricmp(pLower, "y") == 0) || (_stricmp(pLower, "yes") == 0) || (_stricmp(pLower, "true") == 0))
  34.         return true;
  35.     return false;
  36. }
  37.  
  38. VOID setConfig(char* pKey, char* pValue)
  39. {
  40.     if (strlen(pKey) == 0 || strlen(pValue) == 0)
  41.         return;
  42.  
  43.     for (int i = 0; i < ArraySize(pEntries); i++)
  44.     {
  45.         if (_strcmpi(pKey, pEntries[i].pKey) == 0)
  46.         {
  47.             if (pEntries[i].nType == CONFIG_BOOL)
  48.             {
  49.                 *(PBOOL)pEntries[i].nVar = getBool(pValue);
  50.                 Print("ÿc0%s is now set to %i", pEntries[i].pKey, ((*(PBOOL)pEntries[i].nVar) ? "true" : "false"));
  51.             } else if (pEntries[i].nType == CONFIG_INT) {
  52.                 *(PINT)pEntries[i].nVar = atoi(pValue);
  53.                 Print("ÿc0%s is now set to %d", pEntries[i].pKey, *(PINT)pEntries[i].nVar);
  54.             } else if (pEntries[i].nType == CONFIG_STRING) {
  55.                 strncpy_s((PCHAR)pEntries[i].nVar, sizeof((PCHAR)pEntries[i].nVar), pValue, sizeof(pValue));
  56.                 Print("ÿc0%s is now set to %s", pEntries[i].pKey, (PCHAR)pEntries[i].nVar);
  57.             }
  58.  
  59.         }
  60.     }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement