fix: 修复视频无法从vfs加载

This commit is contained in:
2025-03-12 18:02:36 +08:00
parent c5f5899f20
commit f15d9fecaa
3 changed files with 71 additions and 5 deletions

View File

@@ -17,6 +17,9 @@ static BOOL(WINAPI *TrueCloseHandle)(HANDLE hObject) = CloseHandle;
static DWORD(WINAPI *TrueGetFileSize)(HANDLE hFile, LPDWORD lpFileSizeHigh) = GetFileSize;
static decltype(GetFileSizeEx) *TrueGetFileSizeEx = GetFileSizeEx;
static DWORD(WINAPI *TrueSetFilePointer)(HANDLE hFile, LONG lDistanceToMove, PLONG lpDistanceToMoveHigh, DWORD dwMoveMethod) = SetFilePointer;
static decltype(GetFileType) *TrueGetFileType = GetFileType;
static decltype(GetFileAttributesW) *TrueGetFileAttributesW = GetFileAttributesW;
static decltype(GetFileAttributesExW) *TrueGetFileAttributesExW = GetFileAttributesExW;
static Config config;
static std::wstring defaultFont;
@@ -144,6 +147,27 @@ DWORD WINAPI HookedSetFilePointer(HANDLE hFile, LONG lDistanceToMove, PLONG lpDi
return TrueSetFilePointer(hFile, lDistanceToMove, lpDistanceToMoveHigh, dwMoveMethod);
}
DWORD WINAPI HookedGetFileType(HANDLE hFile) {
if (vfs.ContainsHandle(hFile)) {
return FILE_TYPE_DISK;
}
return TrueGetFileType(hFile);
}
DWORD WINAPI HookedGetFileAttributesW(LPCWSTR lpFileName) {
if (vfs.ContainsFile(lpFileName)) {
return FILE_ATTRIBUTE_READONLY;
}
return TrueGetFileAttributesW(lpFileName);
}
BOOL WINAPI HookedGetFileAttributesExW(LPCWSTR lpFileName, GET_FILEEX_INFO_LEVELS fInfoLevelId, LPVOID lpFileInformation) {
if (vfs.ContainsFile(lpFileName)) {
return vfs.GetFileAttributesExW(lpFileName, fInfoLevelId, lpFileInformation);
}
return TrueGetFileAttributesExW(lpFileName, fInfoLevelId, lpFileInformation);
}
extern "C" __declspec(dllexport) void Attach() {
config.Load("config.txt");
if (!wchar_util::str_to_wstr(defaultFont, config.configs["defaultFont"], CP_UTF8)) {
@@ -169,6 +193,9 @@ extern "C" __declspec(dllexport) void Attach() {
DetourAttach(&TrueGetFileSize, HookedGetFileSize);
DetourAttach(&TrueGetFileSizeEx, HookedGetFileSizeEx);
DetourAttach(&TrueSetFilePointer, HookedSetFilePointer);
DetourAttach(&TrueGetFileType, HookedGetFileType);
DetourAttach(&TrueGetFileAttributesW, HookedGetFileAttributesW);
DetourAttach(&TrueGetFileAttributesExW, HookedGetFileAttributesExW);
DetourTransactionCommit();
std::string stringReplaceFile = config.configs["stringReplaceFile"];
if (!stringReplaceFile.empty()) {
@@ -195,6 +222,9 @@ extern "C" __declspec(dllexport) void Detach() {
DetourDetach(&TrueGetFileSize, HookedGetFileSize);
DetourDetach(&TrueGetFileSizeEx, HookedGetFileSizeEx);
DetourDetach(&TrueSetFilePointer, HookedSetFilePointer);
DetourDetach(&TrueGetFileType, HookedGetFileType);
DetourDetach(&TrueGetFileAttributesW, HookedGetFileAttributesW);
DetourDetach(&TrueGetFileAttributesExW, HookedGetFileAttributesExW);
DetourTransactionCommit();
}