Skip to content

Commit

Permalink
Use a function that gives us the value
Browse files Browse the repository at this point in the history
how nice
  • Loading branch information
RaphaelIT7 committed Jul 17, 2024
1 parent f707138 commit c898fed
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 34 deletions.
7 changes: 2 additions & 5 deletions source/detours.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,8 @@ namespace Symbols
typedef long (*CBaseFileSystem_GetFileTime)(void* filesystem, const char *pFileName, const char *pPathID);
const Symbol CBaseFileSystem_GetFileTimeSym = Symbol::FromName("_ZN15CBaseFileSystem11GetFileTimeEPKcS1_");

typedef const char* (*CBaseFileSystem_FindFirstEx)(void* filesystem, const char *pWildCard, const char *pPathID, FileFindHandle_t *pHandle);
const Symbol CBaseFileSystem_FindFirstExSym = Symbol::FromName("_ZN15CBaseFileSystem11FindFirstExEPKcS1_Pi");

typedef const char* (*CBaseFileSystem_FindNext)(void* filesystem, FileFindHandle_t handle);
const Symbol CBaseFileSystem_FindNextSym = Symbol::FromName("_ZN15CBaseFileSystem8FindNextEi");
typedef bool (*CBaseFileSystem_FindNextFileHelper)(void* filesystem, void *, int *);
const Symbol CBaseFileSystem_FindNextFileHelperSym = Symbol::FromName("_ZN15CBaseFileSystem18FindNextFileHelperEPNS_10FindData_tEPi");

//---------------------------------------------------------------------------------
// Purpose: concommand Symbols
Expand Down
40 changes: 11 additions & 29 deletions source/modules/filesystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -571,30 +571,18 @@ long hook_CBaseFileSystem_GetFileTime(IFileSystem* filesystem, const char *pFile
return detour_CBaseFileSystem_GetFileTime.GetTrampoline<Symbols::CBaseFileSystem_GetFileTime>()(filesystem, pFileName, pPathID);
}

Detouring::Hook detour_CBaseFileSystem_FindFirstEx;
const char* hook_CBaseFileSystem_FindFirstEx(CBaseFileSystem* filesystem, const char *pWildCard, const char *pPathID, FileFindHandle_t *pHandle)
Detouring::Hook detour_CBaseFileSystem_FindNextFileHelper;
bool hook_CBaseFileSystem_FindNextFileHelper(CBaseFileSystem* filesystem, CBaseFileSystem::FindData_t* data, int *pFoundStoreID)
{
const char* ret = detour_CBaseFileSystem_FindFirstEx.GetTrampoline<Symbols::CBaseFileSystem_FindFirstEx>()(filesystem, pWildCard, pPathID, pHandle);
if (!ret || !holylib_filesystem_searchcache.GetBool())
return ret;
AddFileToSearchCache(data->findData.cFileName, data->m_CurrentStoreID);

CBaseFileSystem::FindData_t* data = &filesystem->m_FindData[*pHandle];
AddFileToSearchCache(ret, data->m_CurrentStoreID);
bool found = detour_CBaseFileSystem_FindNextFileHelper.GetTrampoline<Symbols::CBaseFileSystem_FindNextFileHelper>()(filesystem, data, pFoundStoreID);
if (!found || !holylib_filesystem_searchcache.GetBool())
return found;

return ret;
}

Detouring::Hook detour_CBaseFileSystem_FindNext;
const char* hook_CBaseFileSystem_FindNext(CBaseFileSystem* filesystem, FileFindHandle_t pHandle)
{
const char* ret = detour_CBaseFileSystem_FindNext.GetTrampoline<Symbols::CBaseFileSystem_FindNext>()(filesystem, pHandle);
if (!ret || !holylib_filesystem_searchcache.GetBool())
return ret;

CBaseFileSystem::FindData_t* data = &filesystem->m_FindData[pHandle];
AddFileToSearchCache(ret, data->m_CurrentStoreID);
AddFileToSearchCache(data->findData.cFileName, data->m_CurrentStoreID);

return ret;
return true;
}

void CFileSystemModule::Init(CreateInterfaceFn* appfn, CreateInterfaceFn* gamefn)
Expand Down Expand Up @@ -683,15 +671,9 @@ void CFileSystemModule::InitDetour(bool bPreServer)
);

Detour::Create(
&detour_CBaseFileSystem_FindFirstEx, "CBaseFileSystem::FindFirstEx",
dedicated_loader.GetModule(), Symbols::CBaseFileSystem_FindFirstExSym,
(void*)hook_CBaseFileSystem_FindFirstEx, m_pID
);

Detour::Create(
&detour_CBaseFileSystem_FindNext, "CBaseFileSystem::FindNext",
dedicated_loader.GetModule(), Symbols::CBaseFileSystem_FindNextSym,
(void*)hook_CBaseFileSystem_FindNext, m_pID
&detour_CBaseFileSystem_FindNextFileHelper, "CBaseFileSystem::FindNextFileHelper",
dedicated_loader.GetModule(), Symbols::CBaseFileSystem_FindNextFileHelperSym,
(void*)hook_CBaseFileSystem_FindNextFileHelper, m_pID
);

func_CBaseFileSystem_FindSearchPathByStoreId = (Symbols::CBaseFileSystem_FindSearchPathByStoreId)Detour::GetFunction(dedicated_loader.GetModule(), Symbols::CBaseFileSystem_FindSearchPathByStoreIdSym);
Expand Down

0 comments on commit c898fed

Please sign in to comment.