diff --git a/saco/game/util.cpp b/saco/game/util.cpp index d0a8a90..9d136fd 100644 --- a/saco/game/util.cpp +++ b/saco/game/util.cpp @@ -1,6 +1,8 @@ #include #include +#include "../main.h" +#include #define NUM_RADAR_COLORS 1000 @@ -1031,4 +1033,26 @@ DWORD __stdcall TranslateColorCodeToRGBA(int iCode) void GameResetRadarColors() { memcpy(&dwUseHudColors[0],&dwHudColors[0],sizeof(DWORD)*NUM_RADAR_COLORS); -} \ No newline at end of file + + + + + + + + +//---------------------------------------------------- + +BOOL IsFileOrDirectoryExists(char * szPath) +{ + struct _stat buf; + + return _stat(szPath, &buf) == 0; +} + +//---------------------------------------------------- + + + + + diff --git a/saco/game/util.h b/saco/game/util.h index c9a89bf..d1e215e 100644 --- a/saco/game/util.h +++ b/saco/game/util.h @@ -6,3 +6,5 @@ void __stdcall SetRadarColor(int nIndex,DWORD dwColor); DWORD __stdcall TranslateColorCodeToRGBA(int iCode); void GameResetRadarColors(); + +BOOL IsFileOrDirectoryExists(char * szPath); diff --git a/saco/main.cpp b/saco/main.cpp index 05d1658..8598701 100644 --- a/saco/main.cpp +++ b/saco/main.cpp @@ -1,9 +1,15 @@ #include "main.h" +#include "game/util.h" int iGtaVersion=0; GAME_SETTINGS tSettings; + +CHAR szArtworkProxy[MAX_PATH+1]; +CHAR szSAMPDir[MAX_PATH+1]; +CHAR szCacheDir[MAX_PATH+1]; + CConfig *pConfig=0; CChatWindow *pChatWindow=0; CCmdWindow *pCmdWindow=0; @@ -79,6 +85,88 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) //---------------------------------------------------- +PCHAR GetSAMPPath() +{ + return szSAMPDir; +} + +//---------------------------------------------------- + +PCHAR GetCachePath() +{ + return szCacheDir; +} + +//---------------------------------------------------- + +void SetupCacheDirectories() +{ + ZeroMemory(szCacheDir, sizeof(szCacheDir)); + + CHAR szPath[MAX_PATH+1]; + DWORD cbData = MAX_PATH; + HKEY hKey; + DWORD dwType; + ZeroMemory(szPath, sizeof(szPath)); + + sprintf(szCacheDir, "%s\\cache", szSAMPDir); + if(RegOpenKeyEx(HKEY_CURRENT_USER, "Software\\SAMP", 0, KEY_READ, &hKey) == ERROR_SUCCESS && + RegQueryValueEx(hKey, "model_cache", NULL, &dwType, (LPBYTE) szPath, &cbData) == ERROR_SUCCESS) + { + strncpy(szCacheDir, szPath, MAX_PATH+1); + } + if(!IsFileOrDirectoryExists(szCacheDir)) + CreateDirectoryA(szCacheDir, NULL); + + CHAR szLocalDir[MAX_PATH+1]; + sprintf(szLocalDir, "%s\\local", szCacheDir); + if(!IsFileOrDirectoryExists(szLocalDir)) + CreateDirectoryA(szLocalDir, NULL); +} + +//---------------------------------------------------- + +PCHAR GetArtworkProxy() +{ + ZeroMemory(szArtworkProxy, sizeof(szArtworkProxy)); + + DWORD cbData = MAX_PATH; + HKEY hKey; + DWORD dwType; + + if(RegOpenKeyEx(HKEY_CURRENT_USER, "Software\\SAMP", 0, KEY_READ, &hKey) != ERROR_SUCCESS) + return NULL; + + if(RegQueryValueEx(hKey, "artwork_proxy", NULL, &dwType, (LPBYTE) szArtworkProxy, &cbData) != ERROR_SUCCESS) + return NULL; + + return szArtworkProxy; +} + +//---------------------------------------------------- + +void SetupDirectories() +{ + ZeroMemory(szSAMPDir, sizeof(szSAMPDir)); + + if(strlen((char*)0xC92368) == 0) { + GetCurrentDirectory(MAX_PATH+1, szSAMPDir); + } else { + sprintf(szSAMPDir, "%s\\SAMP", (char*)0xC92368); + if(!IsFileOrDirectoryExists(szSAMPDir)) + CreateDirectoryA(szSAMPDir, NULL); + + CHAR szScreensDir[MAX_PATH+1]; + sprintf(szScreensDir, "%s\\screens", szSAMPDir); + if(!IsFileOrDirectoryExists(szScreensDir)) + CreateDirectoryA(szScreensDir, NULL); + + SetupCacheDirectories(); + } +} + +//---------------------------------------------------- + void TheGraphicsLoop() { }