-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
140 changed files
with
4,076 additions
and
8,172 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,118 +1,86 @@ | ||
/*================================================================= | ||
File created by Yohann NICOLAS. | ||
Get Game version. | ||
=================================================================*/ | ||
|
||
//#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers | ||
#include "VersionInfo.h" | ||
#pragma comment(lib, "Version.Lib") //ïî ñðàâíåíèþ ñ Delphi 7 - òàêîé ãåììîðîé! :( | ||
#include <windows.h> | ||
|
||
#pragma comment(lib, "Version.Lib") | ||
|
||
const char* VersionStrings[16] = { "1.00","1.07","1.08","1.09","1.09b","1.09d","1.10","1.11","1.11b","1.12","1.13c","1.13d","1.14a","1.14b","1.14c","1.14d" }; | ||
|
||
bool IsFile(char* sPath) | ||
const char* GetVersionString(int version) | ||
{ | ||
bool bFile = false; | ||
HANDLE hFile = CreateFile | ||
( | ||
sPath, | ||
GENERIC_READ, | ||
FILE_SHARE_READ, | ||
NULL, | ||
OPEN_EXISTING, | ||
FILE_ATTRIBUTE_NORMAL, | ||
NULL | ||
); | ||
if(hFile != INVALID_HANDLE_VALUE) | ||
{ | ||
CloseHandle(hFile); | ||
bFile = true; | ||
} | ||
return bFile; | ||
return VersionStrings[version]; | ||
} | ||
|
||
bool GetAppVersion(char* FileName, TFileVersion* VerInfo){ // ïîëó÷åíèå âåðñèè ôàéëà | ||
VerInfo->full = -1; | ||
if(!IsFile(FileName)){ // Ïðîâåðÿåì íàëè÷èå ôàéëà | ||
return false; // Åñëè íåò ô-öèÿ íåóñïåøíà | ||
} | ||
DWORD FSize = GetFileVersionInfoSize(FileName,NULL); // ðàçìåð èíôû î âåðñèè ôàéëà | ||
if(FSize==0){ // Åñëè 0 ôóíêöèÿ íåóñïåøíà | ||
return false; | ||
} | ||
LPVOID pBlock = (char*)malloc(FSize); // àäðåñ áóôåðà äëÿ ðåñóðñîâ âåðñèè | ||
GetFileVersionInfo(FileName,NULL,FSize,pBlock); // ïîëó÷àåì ðåñóðñ èíôîðìàöèè î âåðñèè | ||
LPVOID MS; | ||
UINT LS; | ||
try{ | ||
VerQueryValue(pBlock,"\\",&MS,&LS); // èçâëåêàåì èíôîðìàöèþ èç ðåñóðñà | ||
} | ||
catch(...){ | ||
return false; // â ñëó÷àå îøèáêè ôóíêöèÿ íåóñïåøíà | ||
} | ||
VS_FIXEDFILEINFO FixedFileInfo; // ñòðóêòóðà ñ èíôîðìàöèåé î âåðñèè ôàéëà | ||
memmove(&FixedFileInfo, MS, LS); // ïðèâîäèì èíôîðìàöèþ ê ñòðóêòóðå | ||
|
||
DWORD FileVersionMS = FixedFileInfo.dwFileVersionMS; | ||
DWORD FileVersionLS = FixedFileInfo.dwFileVersionLS; | ||
|
||
VerInfo->major = HIWORD(FileVersionMS) ; // ïîëó÷àåì çíà÷åíèÿ | ||
VerInfo->minor = LOWORD(FileVersionMS); // è ïðèñâàèâàåè èõ âõîäíîìó óêàçàòåëþ | ||
VerInfo->revision = HIWORD(FileVersionLS); | ||
VerInfo->subrevision = LOWORD(FileVersionLS); | ||
|
||
return true; // ôóíêöèÿ óñïåøíà | ||
} | ||
eGameVersion GetD2Version(LPCVOID pVersionResource) | ||
{ | ||
UINT uLen; | ||
VS_FIXEDFILEINFO* ptFixedFileInfo; | ||
if (!VerQueryValue(pVersionResource, "\\", (LPVOID*)&ptFixedFileInfo, &uLen)) | ||
return UNKNOW; | ||
|
||
if (uLen == 0) | ||
return UNKNOW; | ||
|
||
#define SUBKEY "Software\\Blizzard Entertainment\\Diablo II" | ||
#define GAMEFILE "\\Game.exe" | ||
bool GetD2Path(char* buf, DWORD bufsize) | ||
{ | ||
HKEY hKey; | ||
DWORD type; | ||
int res; | ||
if (RegOpenKeyEx(HKEY_CURRENT_USER, SUBKEY, 0, KEY_READ, &hKey) == ERROR_SUCCESS) { | ||
res = RegQueryValueEx(hKey,"InstallPath",NULL,&type,(LPBYTE)buf,&bufsize); | ||
RegCloseKey(hKey); | ||
if (res!=ERROR_SUCCESS) return false; | ||
} else if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, SUBKEY, 0, KEY_READ, &hKey) == ERROR_SUCCESS) { | ||
res = RegQueryValueEx(hKey,"InstallPath",NULL,&type,(LPBYTE)buf,&bufsize); | ||
RegCloseKey(hKey); | ||
if (res!=ERROR_SUCCESS) return false; | ||
} else { | ||
return false; | ||
} | ||
strcat(buf, GAMEFILE); | ||
if (GetFileAttributes(buf) == INVALID_FILE_ATTRIBUTES) | ||
return false; | ||
return true; | ||
}; | ||
|
||
int GetVerD2(TFileVersion GameVer) | ||
{ | ||
if ((GameVer.major != 1)||(GameVer.minor != 0)) return -1; | ||
switch (GameVer.revision) | ||
{ | ||
case 9: | ||
if (GameVer.subrevision == 20) return v109b; | ||
if (GameVer.subrevision == 22) return v109d; | ||
break; | ||
case 10: | ||
if (GameVer.subrevision == 39) return v110; | ||
break; | ||
case 11: | ||
if (GameVer.subrevision == 45) return v111; | ||
if (GameVer.subrevision == 46) return v111b; | ||
break; | ||
case 12: | ||
if (GameVer.subrevision == 49) return v112; | ||
break; | ||
case 13: | ||
if (GameVer.subrevision == 60) return v113c; | ||
if (GameVer.subrevision == 64) return v113d; | ||
break; | ||
} | ||
return -1; | ||
WORD major = HIWORD(ptFixedFileInfo->dwFileVersionMS); | ||
WORD minor = LOWORD(ptFixedFileInfo->dwFileVersionMS); | ||
WORD revision = HIWORD(ptFixedFileInfo->dwFileVersionLS); | ||
WORD subrevision = LOWORD(ptFixedFileInfo->dwFileVersionLS); | ||
|
||
if (major != 1) | ||
return UNKNOW; | ||
if (minor == 0 && revision == 7 && subrevision == 0) return V107; | ||
if (minor == 0 && revision == 8 && subrevision == 28) return V108; | ||
if (minor == 0 && revision == 9 && subrevision == 19) return V109; | ||
if (minor == 0 && revision == 9 && subrevision == 20) return V109b; | ||
if (minor == 0 && revision == 9 && subrevision == 22) return V109d; | ||
if (minor == 0 && revision == 10 && subrevision == 39) return V110; | ||
if (minor == 0 && revision == 11 && subrevision == 45) return V111; | ||
if (minor == 0 && revision == 11 && subrevision == 46) return V111b; | ||
if (minor == 0 && revision == 12 && subrevision == 49) return V112; | ||
if (minor == 0 && revision == 13 && subrevision == 60) return V113c; | ||
if (minor == 0 && revision == 13 && subrevision == 64) return V113d; | ||
if (minor == 14 && revision == 0 && subrevision == 64) return V114a; | ||
if (minor == 14 && revision == 1 && subrevision == 68) return V114b; | ||
if (minor == 14 && revision == 2 && subrevision == 70) return V114c; | ||
if (minor == 14 && revision == 3 && subrevision == 71) return V114d; | ||
return UNKNOW; | ||
} | ||
|
||
eGameVersion GetD2Version(char* gameExe) | ||
{ | ||
DWORD len = GetFileVersionInfoSize(gameExe, NULL); | ||
if (len == 0) | ||
return UNKNOW; | ||
|
||
BYTE* pVersionResource = new BYTE[len]; | ||
GetFileVersionInfo(gameExe, NULL, len, pVersionResource); | ||
eGameVersion version = GetD2Version(pVersionResource); | ||
delete pVersionResource; | ||
|
||
return version; | ||
} | ||
|
||
int GetD2Version(char* PathGameExe) | ||
eGameVersion GetD2Version() | ||
{ | ||
TFileVersion GameVer = {-1}; | ||
if (! GetAppVersion(PathGameExe, &GameVer)) return -1; | ||
int ver = GetVerD2(GameVer); | ||
return ver; | ||
} | ||
HMODULE hModule = GetModuleHandle(NULL); | ||
HRSRC hResInfo = FindResource(hModule, MAKEINTRESOURCE(VS_VERSION_INFO), RT_VERSION); | ||
HGLOBAL hResData = LoadResource(hModule, hResInfo); | ||
LPVOID pVersionResource = LockResource(hResData); | ||
//DWORD dwSize = SizeofResource(hInst, hResInfo); | ||
//LPVOID pVersionResource = LocalAlloc(LMEM_FIXED, dwSize); | ||
//CopyMemory(pVersionResource, pRes, dwSize); | ||
|
||
eGameVersion version = GetD2Version(pVersionResource); | ||
FreeResource(hResData); | ||
//LocalFree(pVersionResource); | ||
return version; | ||
} | ||
|
||
///////////////////////// END OF FILE /////////////////////// |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,34 @@ | ||
#include <windows.h> | ||
/*================================================================= | ||
File created by Yohann NICOLAS. | ||
union TFileVersion | ||
{ | ||
__int64 full; | ||
struct { | ||
WORD subrevision; | ||
WORD revision; | ||
WORD minor; | ||
WORD major; | ||
}; | ||
WORD w[4]; | ||
}; | ||
Get Game version. | ||
=================================================================*/ | ||
#pragma once | ||
|
||
enum eGameVersion | ||
{ | ||
v109b=0, | ||
v109d, | ||
v110, | ||
v111, | ||
v111b, | ||
v112, | ||
v113c, | ||
v113d, | ||
v114a | ||
UNKNOW = -1, | ||
V100 = 0, | ||
V107, | ||
V108, | ||
V109, | ||
V109b, | ||
V109d, | ||
V110, | ||
V111, | ||
V111b, | ||
V112, | ||
V113c, | ||
V113d, | ||
V114a, | ||
V114b, | ||
V114c, | ||
V114d | ||
}; | ||
|
||
bool GetAppVersion(char* FileName, TFileVersion* VerInfo); // ïîëó÷åíèå âåðñèè ôàéëà | ||
bool GetD2Path(char* buf, DWORD bufsize); | ||
int GetD2Version(char* PathGameExe); | ||
const char* GetVersionString(int version); | ||
eGameVersion GetD2Version(char* gamePath); | ||
eGameVersion GetD2Version(); | ||
|
||
///////////////////////// END OF FILE /////////////////////// |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.