Skip to content

Commit 4971d36

Browse files
Merge pull request #284 from ladislav-zezula/LZ_Diablo2Steam
Finalizing
2 parents 4998293 + cac4ee2 commit 4971d36

File tree

5 files changed

+44
-20
lines changed

5 files changed

+44
-20
lines changed

src/CascFiles.cpp

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -542,14 +542,23 @@ static DWORD LoadBuildNumber(TCascStorage * hs, const char * /* szVariableName *
542542
return ERROR_BAD_FORMAT;
543543
}
544544

545-
static int LoadQueryKey(const CASC_CSV_COLUMN & Column, CASC_BLOB & Key)
545+
static DWORD LoadQueryKey(const CASC_CSV_COLUMN & Column, CASC_BLOB & Key)
546546
{
547-
// Check the input data
548-
if(Column.szValue == NULL)
549-
return ERROR_BUFFER_OVERFLOW;
550-
if(Column.nLength != MD5_STRING_SIZE)
547+
// Check for existence
548+
if(Column.Empty())
549+
{
550+
Key.Free();
551+
return ERROR_SUCCESS;
552+
}
553+
554+
// Check for invalid length
555+
if(Column.nLength && Column.nLength != MD5_STRING_SIZE)
556+
{
557+
assert(false);
551558
return ERROR_BAD_FORMAT;
559+
}
552560

561+
// Convert the text value into binary blob
553562
return LoadHashArray(&Key, Column.szValue, Column.szValue + Column.nLength, 1);
554563
}
555564

@@ -586,19 +595,24 @@ static DWORD GetDefaultLocaleByRegion(LPCSTR szRegion)
586595

587596
static DWORD GetDefaultLocaleMask(const CASC_CSV_COLUMN & Column)
588597
{
589-
LPCSTR szTagEnd = Column.szValue + Column.nLength - 4;
590-
LPCSTR szTagPtr;
591598
DWORD dwLocaleValue;
592599
DWORD dwLocaleMask = 0;
593600

594-
// Go through the whole tag string
595-
for(szTagPtr = Column.szValue; szTagPtr <= szTagEnd; szTagPtr++)
601+
// Check whether the column contains some data
602+
if(!Column.Empty())
596603
{
597-
// Try to recognize the 4-char locale code
598-
if((dwLocaleValue = GetLocaleValue(szTagPtr)) != CASC_LOCALE_NONE)
604+
LPCSTR szTagEnd = Column.szValue + Column.nLength - 4;
605+
LPCSTR szTagPtr;
606+
607+
// Go through the whole tag string
608+
for(szTagPtr = Column.szValue; szTagPtr <= szTagEnd; szTagPtr++)
599609
{
600-
dwLocaleMask |= dwLocaleValue;
601-
szTagPtr += 3; // Will be moved by 1 more at the end of the loop
610+
// Try to recognize the 4-char locale code
611+
if((dwLocaleValue = GetLocaleValue(szTagPtr)) != CASC_LOCALE_NONE)
612+
{
613+
dwLocaleMask |= dwLocaleValue;
614+
szTagPtr += 3; // Will be moved by 1 more at the end of the loop
615+
}
602616
}
603617
}
604618
return dwLocaleMask;
@@ -714,13 +728,13 @@ static DWORD ParseFile_BuildInfo(TCascStorage * hs, CASC_CSV & Csv)
714728

715729
// If we found version, extract a build number
716730
const CASC_CSV_COLUMN & VerColumn = Csv[nSelected]["Version!STRING:0"];
717-
if(VerColumn.szValue && VerColumn.nLength)
731+
if(!VerColumn.Empty())
718732
{
719733
LoadBuildNumber(hs, NULL, VerColumn.szValue, VerColumn.szValue + VerColumn.nLength, NULL);
720734
}
721735

722-
// Verify all variables
723-
return (hs->CdnBuildKey.pbData != NULL && hs->CdnConfigKey.pbData != NULL) ? ERROR_SUCCESS : ERROR_BAD_FORMAT;
736+
// At least the build key must be valid here
737+
return hs->CdnBuildKey.Valid() ? ERROR_SUCCESS : ERROR_BAD_FORMAT;
724738
}
725739

726740
return ERROR_FILE_NOT_FOUND;

src/CascOpenStorage.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1166,7 +1166,7 @@ static DWORD LoadCascStorage(TCascStorage * hs, PCASC_OPEN_STORAGE_ARGS pArgs, L
11661166
}
11671167

11681168
// Proceed with loading the CDN config file
1169-
if(dwErrCode == ERROR_SUCCESS)
1169+
if(dwErrCode == ERROR_SUCCESS && hs->CdnConfigKey.Valid())
11701170
{
11711171
dwErrCode = LoadCdnConfigFile(hs);
11721172
if(dwErrCode != ERROR_SUCCESS && (hs->dwFeatures & CASC_FEATURE_ONLINE) == 0)

src/common/Common.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -548,6 +548,11 @@ struct CASC_BLOB
548548
return pbData + cbData;
549549
}
550550

551+
bool Valid() const
552+
{
553+
return pbData && cbData;
554+
}
555+
551556
LPBYTE pbData;
552557
size_t cbData;
553558
};

src/common/Csv.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ struct CASC_CSV_COLUMN
3939
nLength = 0;
4040
}
4141

42+
bool Empty() const
43+
{
44+
return (szValue == NULL || nLength == 0);
45+
}
46+
4247
const char * szValue;
4348
size_t nLength;
4449
};

test/CascTest.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1242,7 +1242,7 @@ int main(int argc, char * argv[])
12421242

12431243
#ifdef LOAD_STORAGES_SINGLE_DEV
12441244
{
1245-
/*
1245+
12461246
CASC_OPEN_STORAGE_ARGS OpenArgs = {sizeof(CASC_OPEN_STORAGE_ARGS)};
12471247
ULONGLONG FileSize = 0;
12481248
HANDLE hStorage;
@@ -1252,7 +1252,7 @@ int main(int argc, char * argv[])
12521252
OpenArgs.PfnProgressCallback = OnlineStorage_OpenCB;
12531253

12541254
// Open the online storage
1255-
if(CascOpenStorageEx(_T("e:\\Multimedia\\CASC\\Work\\odin*odin*eu*b166bdb29359f05a2e876423f413a89c"), &OpenArgs, true, &hStorage))
1255+
if(CascOpenStorageEx(_T("e:\\Ladik\\Incoming\\diablo"), &OpenArgs, true, &hStorage))
12561256
{
12571257
if(CascOpenFile(hStorage, "ROOT", 0, CASC_OVERCOME_ENCRYPTED | CASC_OPEN_CKEY_ONCE, &hFile))
12581258
{
@@ -1261,7 +1261,7 @@ int main(int argc, char * argv[])
12611261
}
12621262
CascCloseStorage(hStorage);
12631263
}
1264-
*/
1264+
12651265
/*
12661266
CASC_OPEN_STORAGE_ARGS OpenArgs = {sizeof(CASC_OPEN_STORAGE_ARGS)};
12671267
//CASC_FIND_DATA cf;

0 commit comments

Comments
 (0)