Skip to content

Commit

Permalink
Fixed opening files that are not locally present
Browse files Browse the repository at this point in the history
  • Loading branch information
ladislav-zezula committed Nov 14, 2019
1 parent 0e552e3 commit 8b9d769
Show file tree
Hide file tree
Showing 13 changed files with 87 additions and 57 deletions.
5 changes: 2 additions & 3 deletions CascLib_vs17.bat
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ if exist "%PROGRAM_FILES_DIR%\Microsoft Visual Studio\2017\Professional\VC\Auxil
if exist "%PROGRAM_FILES_DIR%\Microsoft Visual Studio\2017\Enterprise\VC\Auxiliary\Build\vcvarsall.bat" set VCVARS_BAT=%PROGRAM_FILES_DIR%\Microsoft Visual Studio\2017\Enterprise\VC\Auxiliary\Build\vcvarsall.bat

:BUILD_32BIT
call :RestoreEnvVars
call "%VCVARS_BAT%" x86
devenv.com CascLib_vs17.sln /project "CascLib" /rebuild "DebugAD|Win32"
devenv.com CascLib_vs17.sln /project "CascLib" /rebuild "DebugAS|Win32"
Expand All @@ -25,9 +24,9 @@ devenv.com CascLib_vs17.sln /project "CascLib" /rebuild "ReleaseAD|Win32"
devenv.com CascLib_vs17.sln /project "CascLib" /rebuild "ReleaseAS|Win32"
devenv.com CascLib_vs17.sln /project "CascLib" /rebuild "ReleaseUD|Win32"
devenv.com CascLib_vs17.sln /project "CascLib" /rebuild "ReleaseUS|Win32"
call :RestoreEnvVars

:BUILD_64BIT
call :RestoreEnvVars
call "%VCVARS_BAT%" x64
devenv.com CascLib_vs17.sln /project "CascLib" /rebuild "DebugAD|x64"
devenv.com CascLib_vs17.sln /project "CascLib" /rebuild "DebugAS|x64"
Expand All @@ -37,7 +36,7 @@ devenv.com CascLib_vs17.sln /project "CascLib" /rebuild "ReleaseAD|x64"
devenv.com CascLib_vs17.sln /project "CascLib" /rebuild "ReleaseAS|x64"
devenv.com CascLib_vs17.sln /project "CascLib" /rebuild "ReleaseUD|x64"
devenv.com CascLib_vs17.sln /project "CascLib" /rebuild "ReleaseUS|x64"
goto:eof
call :RestoreEnvVars

:RestoreEnvVars
set INCLUDE=%SAVE_INCLUDE%
Expand Down
8 changes: 8 additions & 0 deletions CascLib_vs17.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@
<OutDir>./bin/$(ProjectName)/$(Platform)/$(Configuration)\</OutDir>
<IntDir>./bin/$(ProjectName)/$(Platform)/$(Configuration)\</IntDir>
<TargetName>$(ProjectName)DAD</TargetName>
<IncludePath>$(VC_IncludePath);$(WindowsSdk_71A_IncludePath);</IncludePath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='DebugAS|Win32'">
<OutDir>./bin/$(ProjectName)/$(Platform)/$(Configuration)\</OutDir>
Expand All @@ -237,6 +238,7 @@
<OutDir>./bin/$(ProjectName)/$(Platform)/$(Configuration)\</OutDir>
<IntDir>./bin/$(ProjectName)/$(Platform)/$(Configuration)\</IntDir>
<TargetName>$(ProjectName)DAS</TargetName>
<IncludePath>$(VC_IncludePath);$(WindowsSdk_71A_IncludePath);</IncludePath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='ReleaseAD|Win32'">
<OutDir>./bin/$(ProjectName)/$(Platform)/$(Configuration)\</OutDir>
Expand All @@ -247,6 +249,7 @@
<OutDir>./bin/$(ProjectName)/$(Platform)/$(Configuration)\</OutDir>
<IntDir>./bin/$(ProjectName)/$(Platform)/$(Configuration)\</IntDir>
<TargetName>$(ProjectName)RAD</TargetName>
<IncludePath>$(VC_IncludePath);$(WindowsSdk_71A_IncludePath);</IncludePath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='ReleaseAS|Win32'">
<OutDir>./bin/$(ProjectName)/$(Platform)/$(Configuration)\</OutDir>
Expand All @@ -257,6 +260,7 @@
<OutDir>./bin/$(ProjectName)/$(Platform)/$(Configuration)\</OutDir>
<IntDir>./bin/$(ProjectName)/$(Platform)/$(Configuration)\</IntDir>
<TargetName>$(ProjectName)RAS</TargetName>
<IncludePath>$(VC_IncludePath);$(WindowsSdk_71A_IncludePath);</IncludePath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='DebugUD|Win32'">
<OutDir>./bin/$(ProjectName)/$(Platform)/$(Configuration)\</OutDir>
Expand All @@ -267,6 +271,7 @@
<OutDir>./bin/$(ProjectName)/$(Platform)/$(Configuration)\</OutDir>
<IntDir>./bin/$(ProjectName)/$(Platform)/$(Configuration)\</IntDir>
<TargetName>$(ProjectName)DUD</TargetName>
<IncludePath>$(VC_IncludePath);$(WindowsSdk_71A_IncludePath);</IncludePath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='DebugUS|Win32'">
<OutDir>./bin/$(ProjectName)/$(Platform)/$(Configuration)\</OutDir>
Expand All @@ -277,6 +282,7 @@
<OutDir>./bin/$(ProjectName)/$(Platform)/$(Configuration)\</OutDir>
<IntDir>./bin/$(ProjectName)/$(Platform)/$(Configuration)\</IntDir>
<TargetName>$(ProjectName)DUS</TargetName>
<IncludePath>$(VC_IncludePath);$(WindowsSdk_71A_IncludePath);</IncludePath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='ReleaseUD|Win32'">
<OutDir>./bin/$(ProjectName)/$(Platform)/$(Configuration)\</OutDir>
Expand All @@ -287,6 +293,7 @@
<OutDir>./bin/$(ProjectName)/$(Platform)/$(Configuration)\</OutDir>
<IntDir>./bin/$(ProjectName)/$(Platform)/$(Configuration)\</IntDir>
<TargetName>$(ProjectName)RUD</TargetName>
<IncludePath>$(VC_IncludePath);$(WindowsSdk_71A_IncludePath);</IncludePath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='ReleaseUS|Win32'">
<OutDir>./bin/$(ProjectName)/$(Platform)/$(Configuration)\</OutDir>
Expand All @@ -297,6 +304,7 @@
<OutDir>./bin/$(ProjectName)/$(Platform)/$(Configuration)\</OutDir>
<IntDir>./bin/$(ProjectName)/$(Platform)/$(Configuration)\</IntDir>
<TargetName>$(ProjectName)RUS</TargetName>
<IncludePath>$(VC_IncludePath);$(WindowsSdk_71A_IncludePath);</IncludePath>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='DebugAD|Win32'">
<ClCompile>
Expand Down
4 changes: 3 additions & 1 deletion CascLib_vs17_dll.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
<IntDir>./bin/$(ProjectName)/$(Platform)/$(Configuration)\</IntDir>
<LinkIncremental>true</LinkIncremental>
<TargetName>CascLib</TargetName>
<IncludePath>$(VC_IncludePath);$(WindowsSdk_71A_IncludePath);</IncludePath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<OutDir>./bin/$(ProjectName)/$(Platform)/$(Configuration)\</OutDir>
Expand All @@ -90,6 +91,7 @@
<IntDir>./bin/$(ProjectName)/$(Platform)/$(Configuration)\</IntDir>
<LinkIncremental>false</LinkIncremental>
<TargetName>CascLib</TargetName>
<IncludePath>$(VC_IncludePath);$(WindowsSdk_71A_IncludePath);</IncludePath>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
Expand Down Expand Up @@ -227,11 +229,11 @@
<ClInclude Include="src\CascCommon.h" />
<ClInclude Include="src\CascLib.h" />
<ClInclude Include="src\CascPort.h" />
<ClInclude Include="src\CascStructs.h" />
<ClInclude Include="src\common\Common.h" />
<ClInclude Include="src\common\Directory.h" />
<ClInclude Include="src\common\Csv.h" />
<ClInclude Include="src\common\Array.h" />
<ClInclude Include="src\common\FileStream.h" />
<ClInclude Include="src\common\FileTree.h" />
<ClInclude Include="src\common\ListFile.h" />
<ClInclude Include="src\common\Map.h" />
Expand Down
6 changes: 3 additions & 3 deletions CascLib_vs17_dll.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,6 @@
<ClInclude Include="src\CascPort.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="src\common\FileStream.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="src\common\Array.h">
<Filter>Source Files\common</Filter>
</ClInclude>
Expand All @@ -161,6 +158,9 @@
<ClInclude Include="src\md5\md5.h">
<Filter>Source Files\md5</Filter>
</ClInclude>
<ClInclude Include="src\CascStructs.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="src\DllMain.rc">
Expand Down
3 changes: 3 additions & 0 deletions CascLib_vs17_test.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
<IntDir>./bin/$(ProjectName)/$(Platform)/$(Configuration)\</IntDir>
<LinkIncremental>true</LinkIncremental>
<GenerateManifest>false</GenerateManifest>
<IncludePath>$(VC_IncludePath);$(WindowsSdk_71A_IncludePath);</IncludePath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<OutDir>./bin/$(ProjectName)/$(Platform)/$(Configuration)\</OutDir>
Expand All @@ -96,6 +97,7 @@
<IntDir>./bin/$(ProjectName)/$(Platform)/$(Configuration)\</IntDir>
<LinkIncremental>false</LinkIncremental>
<GenerateManifest>false</GenerateManifest>
<IncludePath>$(VC_IncludePath);$(WindowsSdk_71A_IncludePath);</IncludePath>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Midl>
Expand Down Expand Up @@ -354,6 +356,7 @@
<ClInclude Include="src\CascCommon.h" />
<ClInclude Include="src\CascLib.h" />
<ClInclude Include="src\CascPort.h" />
<ClInclude Include="src\CascStructs.h" />
<ClInclude Include="src\common\Common.h" />
<ClInclude Include="src\common\Directory.h" />
<ClInclude Include="src\common\Csv.h" />
Expand Down
3 changes: 3 additions & 0 deletions CascLib_vs17_test.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,9 @@
<ClInclude Include="src\md5\md5.h">
<Filter>Source Files\md5</Filter>
</ClInclude>
<ClInclude Include="src\CascStructs.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<Text Include="doc\History.txt">
Expand Down
1 change: 0 additions & 1 deletion src/CascCommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,6 @@ struct TCascStorage
CASC_ARRAY ExtraKeysList; // List additional encryption keys
CASC_MAP EncryptionKeys; // Map of encryption keys
ULONGLONG LastFailKeyName; // The value of the encryption key that recently was NOT found.

};

struct TCascFile
Expand Down
2 changes: 1 addition & 1 deletion src/CascFindFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ static bool DoStorageSearch_CKey(TCascSearch * pSearch, PCASC_FIND_DATA pFindDat
{
// Locate the n-th CKey entry.
pCKeyEntry = (PCASC_CKEY_ENTRY)hs->CKeyArray.ItemAt(pSearch->nFileIndex++);
// BREAK_ON_XKEY3(pCKeyEntry->CKey, 0x2B, 0xfc, 0xe4);
//BREAK_ON_XKEY3(pCKeyEntry->CKey, 0x2B, 0xfc, 0xe4);

// Only report files that are unreferenced by the ROOT handler
if(pCKeyEntry->IsFile() && pCKeyEntry->RefCount == 0)
Expand Down
22 changes: 7 additions & 15 deletions src/CascOpenFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,25 +196,17 @@ bool OpenFileByCKeyEntry(TCascStorage * hs, PCASC_CKEY_ENTRY pCKeyEntry, DWORD d
// If the CKey entry is NULL, we consider the file non-existant
if(pCKeyEntry != NULL)
{
// The storage offset must be known
if(pCKeyEntry->StorageOffset != CASC_INVALID_OFFS64)
// Create the file handle structure
if((hf = new TCascFile(hs, pCKeyEntry)) != NULL)
{
// Create the file handle structure
if((hf = new TCascFile(hs, pCKeyEntry)) != NULL)
{
hf->bVerifyIntegrity = (dwOpenFlags & CASC_STRICT_DATA_CHECK) ? true : false;
hf->bDownloadFileIf = (hs->dwFeatures & CASC_FEATURE_ONLINE) ? true : false;
hf->bOvercomeEncrypted = (dwOpenFlags & CASC_OVERCOME_ENCRYPTED) ? true : false;
dwErrCode = ERROR_SUCCESS;
}
else
{
dwErrCode = ERROR_NOT_ENOUGH_MEMORY;
}
hf->bVerifyIntegrity = (dwOpenFlags & CASC_STRICT_DATA_CHECK) ? true : false;
hf->bDownloadFileIf = (hs->dwFeatures & CASC_FEATURE_ONLINE) ? true : false;
hf->bOvercomeEncrypted = (dwOpenFlags & CASC_OVERCOME_ENCRYPTED) ? true : false;
dwErrCode = ERROR_SUCCESS;
}
else
{
dwErrCode = ERROR_FILE_NOT_FOUND;
dwErrCode = ERROR_NOT_ENOUGH_MEMORY;
}
}

Expand Down
14 changes: 10 additions & 4 deletions src/CascOpenStorage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,21 @@
//-----------------------------------------------------------------------------
// DEBUG functions

//#define CHECKED_KEY "2a378c"
#define CHECKED_KEY {0x00, 0x00, 0x0F, 0x84}

#if defined(_DEBUG) && defined(CHECKED_KEY)

inline bool CheckForXKey(LPBYTE XKey)
{
BYTE CheckedKey[4];
ConvertStringToBinary(CHECKED_KEY, 6, CheckedKey);
return (XKey[0] == CheckedKey[0] && XKey[1] == CheckedKey[1] && XKey[2] == CheckedKey[2]);
BYTE CheckedKey[] = CHECKED_KEY;

for(size_t i = 0; i < _countof(CheckedKey); i++)
{
if(XKey[i] != CheckedKey[i])
return false;
}

return true;
}
#define BREAK_ON_WATCHED(XKey) if(CheckForXKey((LPBYTE)XKey)) { __debugbreak(); }

Expand Down
22 changes: 20 additions & 2 deletions src/CascPort.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@

#pragma intrinsic(memcmp, memcpy)

typedef RTL_CRITICAL_SECTION PLATFORM_LOCK;
#define LOCK_INIT(Lock) InitializeCriticalSection(Lock)
#define LOCK(Lock) EnterCriticalSection(Lock)
#define UNLOCK(Lock) LeaveCriticalSection(Lock)
#define LOCK_FREE(Lock) DeleteCriticalSection(Lock)

#define PLATFORM_WINDOWS
#define PLATFORM_DEFINED // The platform is known now

Expand Down Expand Up @@ -112,7 +118,13 @@
#define URL_SEP_CHAR '/'
#define PATH_SEP_CHAR '/'
#define PATH_SEP_STRING "/"


typedef unsigned int PLATFORM_LOCK;
#define LOCK_INIT(Lock) { /* TODO */ }
#define LOCK(Lock) { /* TODO */ }
#define UNLOCK(Lock) { /* TODO */ }
#define LOCK_FREE(Lock) { /* TODO */ }

#define PLATFORM_MAC
#define PLATFORM_DEFINED // The platform is known now

Expand Down Expand Up @@ -143,7 +155,13 @@
#define URL_SEP_CHAR '/'
#define PATH_SEP_CHAR '/'
#define PATH_SEP_STRING "/"


typedef unsigned int PLATFORM_LOCK;
#define LOCK_INIT(Lock) { /* TODO */ }
#define LOCK(Lock) { /* TODO */ }
#define UNLOCK(Lock) { /* TODO */ }
#define LOCK_FREE(Lock) { /* TODO */ }

#define PLATFORM_LITTLE_ENDIAN
#define PLATFORM_LINUX
#define PLATFORM_DEFINED
Expand Down
8 changes: 1 addition & 7 deletions src/common/FileTree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -293,13 +293,7 @@ PCASC_FILE_NODE CASC_FILE_TREE::InsertByName(PCASC_CKEY_ENTRY pCKeyEntry, const
assert(szFileName != NULL && szFileName[0] != 0);
assert(pCKeyEntry != NULL);

//char szCKey[MD5_STRING_SIZE+1];
//char szEKey[MD5_STRING_SIZE+1];
//StringFromBinary(pCKeyEntry->CKey, MD5_HASH_SIZE, szCKey);
//StringFromBinary(pCKeyEntry->EKey, MD5_HASH_SIZE, szEKey);
//printf("%s\t%s\t%s\n", szCKey, szEKey, szFileName);

//BREAK_ON_XKEY3(pCKeyEntry->EKey, 0x03, 0xDC, 0x7D);
//BREAK_ON_XKEY3(pCKeyEntry->EKey, 0x00, 0x00, 0x0F);

// Calculate the file name hash
FileNameHash = CalcFileNameHash(szFileName);
Expand Down
Loading

0 comments on commit 8b9d769

Please sign in to comment.