├── thumbnail.png ├── FindMDL Hook ├── FindMDL Hook.vcxproj.user ├── CommonIncludes.h ├── Hooks.h ├── Offsets.h ├── Interfaces.h ├── Offsets.cpp ├── Interfaces.cpp ├── VMTManager.h ├── Hooks.cpp ├── dllmain.cpp ├── VMTManager.cpp ├── Utilities.h ├── FindMDL Hook.vcxproj.filters ├── Utilities.cpp ├── FindMDL Hook.vcxproj └── IMDLCache.h ├── FindMDL Hook.sln └── README.md /thumbnail.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kruz1337/CSGO-FindMDL/HEAD/thumbnail.png -------------------------------------------------------------------------------- /FindMDL Hook/FindMDL Hook.vcxproj.user: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /FindMDL Hook/CommonIncludes.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include -------------------------------------------------------------------------------- /FindMDL Hook/Hooks.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | //Includes 4 | #include "Utilities.h" 5 | #include "VMTManager.h" 6 | 7 | //Extern Hooks 8 | namespace Hooks 9 | { 10 | void Initialise(); 11 | 12 | extern VMTManager VMTModelCache; 13 | }; -------------------------------------------------------------------------------- /FindMDL Hook/Offsets.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | //Includes 4 | #include "CommonIncludes.h" 5 | #include "Utilities.h" 6 | 7 | //Extern Offsets 8 | namespace Offsets 9 | { 10 | void Initialise(); 11 | 12 | extern DWORD DataCaches; 13 | extern DWORD dwLocalPlayer; 14 | } -------------------------------------------------------------------------------- /FindMDL Hook/Interfaces.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | //Includes 4 | #include "Offsets.h" 5 | #include "Interfaces.h" 6 | #include "IMDLCache.h" 7 | 8 | //Extern Interfaces 9 | namespace Interfaces 10 | { 11 | void Initialise(); 12 | 13 | extern IMDLCache* ModelCache; 14 | }; 15 | -------------------------------------------------------------------------------- /FindMDL Hook/Offsets.cpp: -------------------------------------------------------------------------------- 1 | #include "Offsets.h" 2 | 3 | //Initialise Offsets 4 | void Offsets::Initialise() 5 | { 6 | DataCaches = WaitOnModuleHandle("datacache.dll"); 7 | dwLocalPlayer = 0xD882B; 8 | }; 9 | 10 | //Offsets 11 | namespace Offsets 12 | { 13 | DWORD DataCaches; 14 | DWORD dwLocalPlayer; 15 | } -------------------------------------------------------------------------------- /FindMDL Hook/Interfaces.cpp: -------------------------------------------------------------------------------- 1 | //Includes 2 | #include "Interfaces.h" 3 | 4 | typedef void* (__cdecl* CreateInterface_t)(const char*, int*); 5 | CreateInterface_t DataCaching = NULL; 6 | 7 | //Interfaces 8 | namespace Interfaces 9 | { 10 | IMDLCache* ModelCache; 11 | }; 12 | 13 | //Initialise Interfaces 14 | void Interfaces::Initialise() 15 | { 16 | DataCaching = (CreateInterface_t)GetProcAddress((HMODULE)Offsets::DataCaches, "CreateInterface"); //Getting the process address of the DataCaches offset 17 | 18 | char* pDataCache = (char*)FindTextPattern("datacache.dll", "MDLCache00"); //Getting MDLCache00 memory address on "datacache.dll" module 19 | 20 | ModelCache = (IMDLCache*)DataCaching(pDataCache, NULL); 21 | }; -------------------------------------------------------------------------------- /FindMDL Hook/VMTManager.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | class VMTManager 4 | { 5 | private: 6 | DWORD* CustomTable; 7 | bool initComplete; 8 | DWORD* OriginalTable; 9 | DWORD* Instance; 10 | 11 | int MethodCount(DWORD* InstancePointer); 12 | 13 | public: 14 | bool Initialise(DWORD* InstancePointer); // Pass a &class 15 | 16 | DWORD HookMethod(DWORD NewFunction, int Index); 17 | void UnhookMethod(int Index); 18 | 19 | void RestoreOriginal(); 20 | void RestoreCustom(); 21 | 22 | template 23 | T GetMethod(size_t nIndex) 24 | { 25 | return (T)OriginalTable[nIndex]; 26 | } 27 | 28 | DWORD GetOriginalFunction(int Index); 29 | }; 30 | 31 | template 32 | FORCEINLINE T GetMethod(const void* instance, size_t index) 33 | { 34 | uintptr_t* vmt = *(uintptr_t**)instance; 35 | 36 | return (T)vmt[index]; 37 | } -------------------------------------------------------------------------------- /FindMDL Hook/Hooks.cpp: -------------------------------------------------------------------------------- 1 | //Includes 2 | #include "Hooks.h" 3 | #include "Interfaces.h" 4 | #include "Utilities.h" 5 | 6 | typedef MDLHandle_t(__thiscall* iFindMdl)(void*, char*); 7 | iFindMdl oFindMDL; 8 | MDLHandle_t __fastcall hkFindMDL(void*, void*, char*); 9 | 10 | //Hooks 11 | namespace Hooks 12 | { 13 | VMTManager VMTModelCache; 14 | }; 15 | 16 | //Hooks Initialise 17 | void Hooks::Initialise() 18 | { 19 | VMTModelCache.Initialise((DWORD*)Interfaces::ModelCache); //Initialise ModelCache interfaces with VMTManager 20 | oFindMDL = (iFindMdl)VMTModelCache.HookMethod((DWORD)&hkFindMDL, 10); //Hooking FindMDL 21 | } 22 | 23 | //Custom Models 24 | MDLHandle_t __fastcall hkFindMDL(void* ecx, void* edx, char* FilePath) 25 | { 26 | if (strstr(FilePath, "knife_default_ct.mdl") || strstr(FilePath, "knife_default_t.mdl")) 27 | { 28 | sprintf(FilePath, "models/weapons/v_minecraft_pickaxe.mdl"); 29 | } 30 | 31 | return oFindMDL(ecx, FilePath); 32 | } -------------------------------------------------------------------------------- /FindMDL Hook.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 17 4 | VisualStudioVersion = 17.1.32421.90 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "FindMDL Hook", "FindMDL Hook\FindMDL Hook.vcxproj", "{18C0D96B-0BCE-4465-9D1F-9858272706E2}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|x86 = Debug|x86 11 | Release|x86 = Release|x86 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {18C0D96B-0BCE-4465-9D1F-9858272706E2}.Debug|x86.ActiveCfg = Debug|Win32 15 | {18C0D96B-0BCE-4465-9D1F-9858272706E2}.Debug|x86.Build.0 = Debug|Win32 16 | {18C0D96B-0BCE-4465-9D1F-9858272706E2}.Release|x86.ActiveCfg = Release|Win32 17 | {18C0D96B-0BCE-4465-9D1F-9858272706E2}.Release|x86.Build.0 = Release|Win32 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | GlobalSection(ExtensibilityGlobals) = postSolution 23 | SolutionGuid = {C4242475-6134-4715-B7BF-7BBA37D4E778} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /FindMDL Hook/dllmain.cpp: -------------------------------------------------------------------------------- 1 | //Includes 2 | #include 3 | #include "Utilities.h" 4 | #include "Interfaces.h" 5 | #include "Hooks.h" 6 | #include "Offsets.h" 7 | 8 | struct values { 9 | DWORD localPlayer; 10 | DWORD gameModule; 11 | }value; 12 | 13 | void main() 14 | { 15 | Offsets::Initialise(); 16 | Interfaces::Initialise(); 17 | Hooks::Initialise(); 18 | 19 | value.gameModule = (DWORD)GetModuleHandle("client.dll"); //Get "client.dll" module handle 20 | value.localPlayer = *(DWORD*)(value.gameModule + Offsets::dwLocalPlayer); //Get local player value 21 | 22 | //Get local player value again if local player value is null 23 | if (value.localPlayer == NULL) 24 | { 25 | while (value.localPlayer == NULL) 26 | { 27 | value.localPlayer = *(DWORD*)(value.gameModule + Offsets::dwLocalPlayer); 28 | } 29 | } 30 | } 31 | 32 | //DLL Main 33 | BOOL APIENTRY DllMain( HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) 34 | { 35 | switch (ul_reason_for_call) 36 | { 37 | case DLL_PROCESS_ATTACH: 38 | { 39 | DisableThreadLibraryCalls(hModule); 40 | CreateThread(NULL, NULL, (LPTHREAD_START_ROUTINE)main, NULL, NULL, NULL); 41 | } 42 | case DLL_PROCESS_DETACH: 43 | break; 44 | } 45 | return TRUE; 46 | } -------------------------------------------------------------------------------- /FindMDL Hook/VMTManager.cpp: -------------------------------------------------------------------------------- 1 | #include "CommonIncludes.h" 2 | #include "VMTManager.h" 3 | 4 | bool VMTManager::Initialise(DWORD* InstancePointer) 5 | { 6 | Instance = InstancePointer; 7 | OriginalTable = (DWORD*)*InstancePointer; 8 | int VMTSize = MethodCount(InstancePointer); 9 | size_t TableBytes = VMTSize * 4; 10 | 11 | CustomTable = (DWORD*)malloc(TableBytes + 8); 12 | if (!CustomTable) return false; 13 | memcpy((void*)CustomTable, (void*)OriginalTable, VMTSize * 4); 14 | 15 | *InstancePointer = (DWORD)CustomTable; 16 | initComplete = true; 17 | 18 | return true; 19 | } 20 | 21 | int VMTManager::MethodCount(DWORD* InstancePointer) 22 | { 23 | DWORD* VMT = (DWORD*)*InstancePointer; 24 | int Index = 0; 25 | int Amount = 0; 26 | while (!IsBadCodePtr((FARPROC)VMT[Index])) 27 | { 28 | if (!IsBadCodePtr((FARPROC)VMT[Index])) 29 | { 30 | Amount++; 31 | Index++; 32 | } 33 | } 34 | 35 | return Amount; 36 | } 37 | 38 | DWORD VMTManager::HookMethod(DWORD NewFunction, int Index) 39 | { 40 | if (initComplete) 41 | { 42 | CustomTable[Index] = NewFunction; 43 | return OriginalTable[Index]; 44 | } 45 | 46 | return NULL; 47 | } 48 | 49 | void VMTManager::UnhookMethod(int Index) 50 | { 51 | if (initComplete) 52 | { 53 | CustomTable[Index] = OriginalTable[Index]; 54 | } 55 | 56 | return; 57 | } 58 | 59 | void VMTManager::RestoreOriginal() 60 | { 61 | if (initComplete) 62 | { 63 | *Instance = (DWORD)OriginalTable; 64 | } 65 | 66 | return; 67 | } 68 | 69 | void VMTManager::RestoreCustom() 70 | { 71 | if (initComplete) 72 | { 73 | *Instance = (DWORD)CustomTable; 74 | } 75 | 76 | return; 77 | } 78 | 79 | DWORD VMTManager::GetOriginalFunction(int Index) 80 | { 81 | return OriginalTable[Index]; 82 | } 83 | -------------------------------------------------------------------------------- /FindMDL Hook/Utilities.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "CommonIncludes.h" 3 | 4 | static DWORD WaitOnModuleHandle(std::string moduleName) 5 | { 6 | DWORD ModuleHandle = NULL; 7 | while (!ModuleHandle) 8 | { 9 | ModuleHandle = (DWORD)GetModuleHandle(moduleName.c_str()); 10 | if (!ModuleHandle) 11 | { 12 | Sleep(50); 13 | } 14 | } 15 | return ModuleHandle; 16 | } 17 | 18 | static bool bCompare(const BYTE* Data, const BYTE* Mask, const char* szMask) 19 | { 20 | for (; *szMask; ++szMask, ++Mask, ++Data) 21 | { 22 | if (*szMask == 'x' && *Mask != *Data) 23 | { 24 | return false; 25 | } 26 | } 27 | return (*szMask) == 0; 28 | } 29 | 30 | static DWORD FindPattern(std::string moduleName, BYTE* Mask, char* szMask) 31 | { 32 | DWORD Address = WaitOnModuleHandle(moduleName.c_str()); 33 | MODULEINFO ModInfo; GetModuleInformation(GetCurrentProcess(), (HMODULE)Address, &ModInfo, sizeof(MODULEINFO)); 34 | DWORD Length = ModInfo.SizeOfImage; 35 | for (DWORD c = 0; c < Length; c += 1) 36 | { 37 | if (bCompare((BYTE*)(Address + c), Mask, szMask)) 38 | { 39 | return (DWORD)(Address + c); 40 | } 41 | } 42 | return 0; 43 | } 44 | 45 | static DWORD FindTextPattern(std::string moduleName, char* string) 46 | { 47 | DWORD Address = WaitOnModuleHandle(moduleName.c_str()); 48 | MODULEINFO ModInfo; GetModuleInformation(GetCurrentProcess(), (HMODULE)Address, &ModInfo, sizeof(MODULEINFO)); 49 | DWORD Length = ModInfo.SizeOfImage; 50 | 51 | int len = strlen(string); 52 | char* szMask = new char[len + 1]; 53 | for (int i = 0; i < len; i++) 54 | { 55 | szMask[i] = 'x'; 56 | } 57 | szMask[len] = '\0'; 58 | 59 | for (DWORD c = 0; c < Length; c += 1) 60 | { 61 | if (bCompare((BYTE*)(Address + c), (BYTE*)string, szMask)) 62 | { 63 | return (DWORD)(Address + c); 64 | } 65 | } 66 | return 0; 67 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # FindMDL Hook 2 | This repository has a internal model changer with FindMDL Hook for Counter-Strike: Global Offensive game. It's fully open source and loadable into the game as a [Dynamic-link library (DLL)](https://en.wikipedia.org/wiki/Dynamic-link_library) 3 | 4 | ![](https://img.shields.io/badge/language-c++-e76089?style=plastic) ![](https://img.shields.io/badge/game-csgo-yellow?style=plastic) ![](https://img.shields.io/badge/license-GNU-green?style=plastic) ![](https://img.shields.io/badge/arch-x86-d9654f?style=plastic) 5 | 6 | ![Image of RequestX International Developer Group on Discord](https://github.com/kruz1337/CSGO-FindMDL/blob/main/thumbnail.png) 7 | 8 | ## How to build FindMDL Hook Project files? 9 | * First of all you should download project files on project page or clone this repository from GitBash or GitHub Desktop on your PC. [FindMDL.zip](https://github.com/kruz1337/CSGO-FindMDL/releases) 10 | 11 | * If you download project files with manual method you need extract zip file. 12 | 13 | * Run .sln file on Visual Studio (2019+). 14 | 15 | * Change build configuration to Debug | x86 and press Build button or press CTRL+B on your keyboard. 16 | 17 | * Check out bin folder include that. 18 | 19 | * Go to the bottom heading to add your custom models. 20 | 21 | ## How to load into the game? 22 | * First download any [Dynamic-link library (DLL)](https://en.wikipedia.org/wiki/Dynamic-link_library) injector and open. 23 | 24 | * Then select builded [Dynamic-link library (DLL)](https://en.wikipedia.org/wiki/Dynamic-link_library) file and Inject to csgo.exe 25 | 26 | * That's all, enjoy it :) 27 | 28 | ## How to add your custom model? 29 | * First go to "Hooks.cpp" in Source Files. 30 | 31 | * Then go to hkFindMDL below the "Custom Models" comment line. 32 | 33 | * Paste this code and read comment lines in this code. 34 | ```c++ 35 | if (strstr(FilePath, "v_.mdl")) //v_: Name of the model to change 36 | { 37 | sprintf(FilePath, "models/weapons/v_new_.mdl"); //v_new_: Name of the changing custom model: 38 | } 39 | ``` 40 | -------------------------------------------------------------------------------- /FindMDL Hook/FindMDL Hook.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | {e39da851-8d9e-4afc-8f59-fcca812d6b79} 18 | 19 | 20 | 21 | 22 | Header Files 23 | 24 | 25 | Header Files 26 | 27 | 28 | Header Files 29 | 30 | 31 | Header Files 32 | 33 | 34 | Header Files\SDK 35 | 36 | 37 | Header Files 38 | 39 | 40 | Header Files 41 | 42 | 43 | 44 | 45 | Source Files 46 | 47 | 48 | Source Files 49 | 50 | 51 | Source Files 52 | 53 | 54 | Source Files 55 | 56 | 57 | Source Files 58 | 59 | 60 | -------------------------------------------------------------------------------- /FindMDL Hook/Utilities.cpp: -------------------------------------------------------------------------------- 1 | // Includes 2 | #include "Utilities.h" 3 | #include 4 | #include 5 | 6 | //Utilities Memory 7 | DWORD Utilities::Memory::WaitOnModuleHandle(std::string moduleName) 8 | { 9 | DWORD ModuleHandle = NULL; 10 | while (!ModuleHandle) 11 | { 12 | ModuleHandle = (DWORD)GetModuleHandle(moduleName.c_str()); 13 | if (!ModuleHandle) 14 | Sleep(50); 15 | } 16 | return ModuleHandle; 17 | } 18 | bool bCompare(const BYTE* Data, const BYTE* Mask, const char* szMask) 19 | { 20 | for (; *szMask; ++szMask, ++Mask, ++Data) 21 | { 22 | if (*szMask == 'x' && *Mask != *Data) 23 | { 24 | return false; 25 | } 26 | } 27 | return (*szMask) == 0; 28 | } 29 | DWORD Utilities::Memory::FindPattern(std::string moduleName, BYTE* Mask, char* szMask) 30 | { 31 | DWORD Address = WaitOnModuleHandle(moduleName.c_str()); 32 | MODULEINFO ModInfo; GetModuleInformation(GetCurrentProcess(), (HMODULE)Address, &ModInfo, sizeof(MODULEINFO)); 33 | DWORD Length = ModInfo.SizeOfImage; 34 | for (DWORD c = 0; c < Length; c += 1) 35 | { 36 | if (bCompare((BYTE*)(Address + c), Mask, szMask)) 37 | { 38 | return (DWORD)(Address + c); 39 | } 40 | } 41 | return 0; 42 | } 43 | DWORD Utilities::Memory::FindTextPattern(std::string moduleName, char* string) 44 | { 45 | DWORD Address = WaitOnModuleHandle(moduleName.c_str()); 46 | MODULEINFO ModInfo; GetModuleInformation(GetCurrentProcess(), (HMODULE)Address, &ModInfo, sizeof(MODULEINFO)); 47 | DWORD Length = ModInfo.SizeOfImage; 48 | 49 | int len = strlen(string); 50 | char* szMask = new char[len + 1]; 51 | for (int i = 0; i < len; i++) 52 | { 53 | szMask[i] = 'x'; 54 | } 55 | szMask[len] = '\0'; 56 | 57 | for (DWORD c = 0; c < Length; c += 1) 58 | { 59 | if (bCompare((BYTE*)(Address + c), (BYTE*)string, szMask)) 60 | { 61 | return (DWORD)(Address + c); 62 | } 63 | } 64 | return 0; 65 | } 66 | 67 | //VMT Manager 68 | bool Utilities::Memory::VMTManager::Initialise(DWORD* InstancePointer) 69 | { 70 | Instance = InstancePointer; 71 | OriginalTable = (DWORD*)*InstancePointer; 72 | int VMTSize = MethodCount(InstancePointer); 73 | size_t TableBytes = VMTSize * 4; 74 | 75 | CustomTable = (DWORD*)malloc(TableBytes + 8); 76 | if (!CustomTable) return false; 77 | memcpy((void*)CustomTable, (void*)OriginalTable, VMTSize * 4); 78 | 79 | *InstancePointer = (DWORD)CustomTable; 80 | 81 | initComplete = true; 82 | return true; 83 | } 84 | int Utilities::Memory::VMTManager::MethodCount(DWORD* InstancePointer) 85 | { 86 | DWORD* VMT = (DWORD*)*InstancePointer; 87 | int Index = 0; 88 | int Amount = 0; 89 | while (!IsBadCodePtr((FARPROC)VMT[Index])) 90 | { 91 | if (!IsBadCodePtr((FARPROC)VMT[Index])) 92 | { 93 | Amount++; 94 | Index++; 95 | } 96 | } 97 | 98 | return Amount; 99 | } 100 | DWORD Utilities::Memory::VMTManager::HookMethod(DWORD NewFunction, int Index) 101 | { 102 | if (initComplete) 103 | { 104 | CustomTable[Index] = NewFunction; 105 | return OriginalTable[Index]; 106 | } 107 | else 108 | return NULL; 109 | } 110 | void Utilities::Memory::VMTManager::UnhookMethod(int Index) 111 | { 112 | if (initComplete) 113 | CustomTable[Index] = OriginalTable[Index]; 114 | return; 115 | } 116 | void Utilities::Memory::VMTManager::RestoreOriginal() 117 | { 118 | if (initComplete) 119 | { 120 | *Instance = (DWORD)OriginalTable; 121 | } 122 | return; 123 | } 124 | void Utilities::Memory::VMTManager::RestoreCustom() 125 | { 126 | if (initComplete) 127 | { 128 | *Instance = (DWORD)CustomTable; 129 | } 130 | return; 131 | } 132 | DWORD Utilities::Memory::VMTManager::GetOriginalFunction(int Index) 133 | { 134 | return OriginalTable[Index]; 135 | } -------------------------------------------------------------------------------- /FindMDL Hook/FindMDL Hook.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | 14 | 16.0 15 | Win32Proj 16 | {18c0d96b-0bce-4465-9d1f-9858272706e2} 17 | CSGOInternalCheating 18 | 10.0 19 | FindMDL Hook 20 | 21 | 22 | 23 | DynamicLibrary 24 | false 25 | v143 26 | MultiByte 27 | 28 | 29 | DynamicLibrary 30 | false 31 | v143 32 | true 33 | MultiByte 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | false 49 | 50 | 51 | false 52 | 53 | 54 | 55 | TurnOffAllWarnings 56 | false 57 | 58 | 59 | Disabled 60 | true 61 | 62 | 63 | false 64 | 65 | 66 | 67 | 68 | true 69 | false 70 | true 71 | 72 | 73 | %(AdditionalDependencies) 74 | 75 | 76 | 77 | 78 | TurnOffAllWarnings 79 | true 80 | true 81 | false 82 | false 83 | 84 | 85 | Windows 86 | true 87 | true 88 | true 89 | false 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | -------------------------------------------------------------------------------- /FindMDL Hook/IMDLCache.h: -------------------------------------------------------------------------------- 1 | #ifndef IMDLCACHE_H 2 | #define IMDLCACHE_H 3 | 4 | #ifdef _WIN32 5 | #pragma once 6 | #endif 7 | 8 | //----------------------------------------------------------------------------- 9 | // Forward declarations 10 | //----------------------------------------------------------------------------- 11 | struct studiohdr_t; 12 | struct studiohwdata_t; 13 | struct vcollide_t; 14 | struct virtualmodel_t; 15 | struct vertexFileHeader_t; 16 | 17 | namespace OptimizedModel 18 | { 19 | struct FileHeader_t; 20 | } 21 | 22 | 23 | //----------------------------------------------------------------------------- 24 | // Reference to a loaded studiomdl 25 | //----------------------------------------------------------------------------- 26 | typedef unsigned short MDLHandle_t; 27 | 28 | enum 29 | { 30 | MDLHANDLE_INVALID = (MDLHandle_t)~0 31 | }; 32 | 33 | 34 | //----------------------------------------------------------------------------- 35 | // Cache data types 36 | //----------------------------------------------------------------------------- 37 | enum MDLCacheDataType_t 38 | { 39 | // Callbacks to get called when data is loaded or unloaded for these: 40 | MDLCACHE_STUDIOHDR = 0, 41 | MDLCACHE_STUDIOHWDATA, 42 | MDLCACHE_VCOLLIDE, 43 | 44 | // Callbacks NOT called when data is loaded or unloaded for these: 45 | MDLCACHE_ANIMBLOCK, 46 | MDLCACHE_VIRTUALMODEL, 47 | MDLCACHE_VERTEXES, 48 | MDLCACHE_DECODEDANIMBLOCK, 49 | }; 50 | 51 | class IMDLCacheNotify 52 | { 53 | public: 54 | // Called right after the data is loaded 55 | virtual void OnDataLoaded(MDLCacheDataType_t type, MDLHandle_t handle) = 0; 56 | 57 | // Called right before the data is unloaded 58 | virtual void OnDataUnloaded(MDLCacheDataType_t type, MDLHandle_t handle) = 0; 59 | }; 60 | 61 | 62 | //----------------------------------------------------------------------------- 63 | // Flags for flushing 64 | //----------------------------------------------------------------------------- 65 | enum MDLCacheFlush_t 66 | { 67 | MDLCACHE_FLUSH_STUDIOHDR = 0x01, 68 | MDLCACHE_FLUSH_STUDIOHWDATA = 0x02, 69 | MDLCACHE_FLUSH_VCOLLIDE = 0x04, 70 | MDLCACHE_FLUSH_ANIMBLOCK = 0x08, 71 | MDLCACHE_FLUSH_VIRTUALMODEL = 0x10, 72 | MDLCACHE_FLUSH_AUTOPLAY = 0x20, 73 | MDLCACHE_FLUSH_VERTEXES = 0x40, 74 | 75 | MDLCACHE_FLUSH_IGNORELOCK = 0x80000000, 76 | MDLCACHE_FLUSH_ALL = 0xFFFFFFFF 77 | }; 78 | 79 | /* 80 | #define MDLCACHE_INTERFACE_VERSION_4 "MDLCache004" 81 | namespace MDLCacheV4 82 | { 83 | abstract_class IMDLCache : public IAppSystem 84 | { 85 | public: 86 | // Used to install callbacks for when data is loaded + unloaded 87 | virtual void SetCacheNotify( IMDLCacheNotify *pNotify ) = 0; 88 | // NOTE: This assumes the "GAME" path if you don't use 89 | // the UNC method of specifying files. This will also increment 90 | // the reference count of the MDL 91 | virtual MDLHandle_t FindMDL( const char *pMDLRelativePath ) = 0; 92 | // Reference counting 93 | virtual int AddRef( MDLHandle_t handle ) = 0; 94 | virtual int Release( MDLHandle_t handle ) = 0; 95 | // Gets at the various data associated with a MDL 96 | virtual studiohdr_t *GetStudioHdr( MDLHandle_t handle ) = 0; 97 | virtual studiohwdata_t *GetHardwareData( MDLHandle_t handle ) = 0; 98 | virtual vcollide_t *GetVCollide( MDLHandle_t handle ) = 0; 99 | virtual unsigned char *GetAnimBlock( MDLHandle_t handle, int nBlock ) = 0; 100 | virtual virtualmodel_t *GetVirtualModel( MDLHandle_t handle ) = 0; 101 | virtual int GetAutoplayList( MDLHandle_t handle, unsigned short **pOut ) = 0; 102 | virtual vertexFileHeader_t *GetVertexData( MDLHandle_t handle ) = 0; 103 | // Brings all data associated with an MDL into memory 104 | virtual void TouchAllData( MDLHandle_t handle ) = 0; 105 | // Gets/sets user data associated with the MDL 106 | virtual void SetUserData( MDLHandle_t handle, void* pData ) = 0; 107 | virtual void *GetUserData( MDLHandle_t handle ) = 0; 108 | // Is this MDL using the error model? 109 | virtual bool IsErrorModel( MDLHandle_t handle ) = 0; 110 | // Flushes the cache, force a full discard 111 | virtual void Flush( int nFlushFlags = MDLCACHE_FLUSH_ALL ) = 0; 112 | // Flushes a particular model out of memory 113 | virtual void Flush( MDLHandle_t handle, int nFlushFlags = MDLCACHE_FLUSH_ALL ) = 0; 114 | // Returns the name of the model (its relative path) 115 | virtual const char *GetModelName( MDLHandle_t handle ) = 0; 116 | // faster access when you already have the studiohdr 117 | virtual virtualmodel_t *GetVirtualModelFast( const studiohdr_t *pStudioHdr, MDLHandle_t handle ) = 0; 118 | // all cache entries that subsequently allocated or successfully checked 119 | // are considered "locked" and will not be freed when additional memory is needed 120 | virtual void BeginLock() = 0; 121 | // reset all protected blocks to normal 122 | virtual void EndLock() = 0; 123 | // returns a pointer to a counter that is incremented every time the cache has been out of the locked state (EVIL) 124 | virtual int *GetFrameUnlockCounterPtr() = 0; 125 | // Finish all pending async operations 126 | virtual void FinishPendingLoads() = 0; 127 | }; 128 | } 129 | */ 130 | 131 | //----------------------------------------------------------------------------- 132 | // The main MDL cacher 133 | //----------------------------------------------------------------------------- 134 | #define MDLCACHE_INTERFACE_VERSION "MDLCache004" 135 | 136 | class IMDLCache 137 | { 138 | public: 139 | // Used to install callbacks for when data is loaded + unloaded 140 | // Returns the prior notify 141 | virtual void SetCacheNotify(IMDLCacheNotify* pNotify) = 0; 142 | 143 | // NOTE: This assumes the "GAME" path if you don't use 144 | // the UNC method of specifying files. This will also increment 145 | // the reference count of the MDL 146 | virtual MDLHandle_t FindMDL(const char* pMDLRelativePath) = 0; 147 | 148 | // Reference counting 149 | virtual int AddRef(MDLHandle_t handle) = 0; 150 | virtual int Release(MDLHandle_t handle) = 0; 151 | virtual int GetRef(MDLHandle_t handle) = 0; 152 | 153 | // Gets at the various data associated with a MDL 154 | virtual studiohdr_t* GetStudioHdr(MDLHandle_t handle) = 0; 155 | virtual studiohwdata_t* GetHardwareData(MDLHandle_t handle) = 0; 156 | virtual vcollide_t* GetVCollide(MDLHandle_t handle) = 0; 157 | virtual unsigned char* GetAnimBlock(MDLHandle_t handle, int nBlock) = 0; 158 | virtual virtualmodel_t* GetVirtualModel(MDLHandle_t handle) = 0; 159 | virtual int GetAutoplayList(MDLHandle_t handle, unsigned short** pOut) = 0; 160 | virtual vertexFileHeader_t* GetVertexData(MDLHandle_t handle) = 0; 161 | 162 | // Brings all data associated with an MDL into memory 163 | virtual void TouchAllData(MDLHandle_t handle) = 0; 164 | 165 | // Gets/sets user data associated with the MDL 166 | virtual void SetUserData(MDLHandle_t handle, void* pData) = 0; 167 | virtual void* GetUserData(MDLHandle_t handle) = 0; 168 | 169 | // Is this MDL using the error model? 170 | virtual bool IsErrorModel(MDLHandle_t handle) = 0; 171 | 172 | // Flushes the cache, force a full discard 173 | virtual void Flush(MDLCacheFlush_t nFlushFlags = MDLCACHE_FLUSH_ALL) = 0; 174 | 175 | // Flushes a particular model out of memory 176 | virtual void Flush(MDLHandle_t handle, int nFlushFlags = MDLCACHE_FLUSH_ALL) = 0; 177 | 178 | // Returns the name of the model (its relative path) 179 | virtual const char* GetModelName(MDLHandle_t handle) = 0; 180 | 181 | // faster access when you already have the studiohdr 182 | virtual virtualmodel_t* GetVirtualModelFast(const studiohdr_t* pStudioHdr, MDLHandle_t handle) = 0; 183 | 184 | // all cache entries that subsequently allocated or successfully checked 185 | // are considered "locked" and will not be freed when additional memory is needed 186 | virtual void BeginLock() = 0; 187 | 188 | // reset all protected blocks to normal 189 | virtual void EndLock() = 0; 190 | 191 | // returns a pointer to a counter that is incremented every time the cache has been out of the locked state (EVIL) 192 | virtual int* GetFrameUnlockCounterPtrOLD() = 0; 193 | 194 | // Finish all pending async operations 195 | virtual void FinishPendingLoads() = 0; 196 | 197 | virtual vcollide_t* GetVCollideEx(MDLHandle_t handle, bool synchronousLoad = true) = 0; 198 | virtual bool GetVCollideSize(MDLHandle_t handle, int* pVCollideSize) = 0; 199 | 200 | virtual bool GetAsyncLoad(MDLCacheDataType_t type) = 0; 201 | virtual bool SetAsyncLoad(MDLCacheDataType_t type, bool bAsync) = 0; 202 | 203 | virtual void BeginMapLoad() = 0; 204 | virtual void EndMapLoad() = 0; 205 | virtual void MarkAsLoaded(MDLHandle_t handle) = 0; 206 | 207 | virtual void InitPreloadData(bool rebuild) = 0; 208 | virtual void ShutdownPreloadData() = 0; 209 | 210 | virtual bool IsDataLoaded(MDLHandle_t handle, MDLCacheDataType_t type) = 0; 211 | 212 | virtual int* GetFrameUnlockCounterPtr(MDLCacheDataType_t type) = 0; 213 | 214 | virtual studiohdr_t* LockStudioHdr(MDLHandle_t handle) = 0; 215 | virtual void UnlockStudioHdr(MDLHandle_t handle) = 0; 216 | 217 | virtual bool PreloadModel(MDLHandle_t handle) = 0; 218 | 219 | // Hammer uses this. If a model has an error loading in GetStudioHdr, then it is flagged 220 | // as an error model and any further attempts to load it will just get the error model. 221 | // That is, until you call this function. Then it will load the correct model. 222 | virtual void ResetErrorModelStatus(MDLHandle_t handle) = 0; 223 | 224 | virtual void MarkFrame() = 0; 225 | }; 226 | 227 | 228 | //----------------------------------------------------------------------------- 229 | // Critical section helper code 230 | //----------------------------------------------------------------------------- 231 | class CMDLCacheCriticalSection 232 | { 233 | public: 234 | CMDLCacheCriticalSection(IMDLCache *pCache) : m_pCache(pCache) 235 | { 236 | m_pCache->BeginLock(); 237 | } 238 | 239 | ~CMDLCacheCriticalSection() 240 | { 241 | m_pCache->EndLock(); 242 | } 243 | 244 | private: 245 | IMDLCache* m_pCache; 246 | }; 247 | 248 | #define MDCACHE_FINE_GRAINED 1 249 | 250 | #if defined(MDCACHE_FINE_GRAINED) 251 | #define MDLCACHE_CRITICAL_SECTION_( pCache ) CMDLCacheCriticalSection cacheCriticalSection(pCache) 252 | #define MDLCACHE_COARSE_LOCK_( pCache ) ((void)(0)) 253 | #elif defined(MDLCACHE_LEVEL_LOCKED) 254 | #define MDLCACHE_CRITICAL_SECTION_( pCache ) ((void)(0)) 255 | #define MDLCACHE_COARSE_LOCK_( pCache ) ((void)(0)) 256 | #else 257 | #define MDLCACHE_CRITICAL_SECTION_( pCache ) ((void)(0)) 258 | #define MDLCACHE_COARSE_LOCK_( pCache ) CMDLCacheCriticalSection cacheCriticalSection(pCache) 259 | #endif 260 | #define MDLCACHE_CRITICAL_SECTION() MDLCACHE_CRITICAL_SECTION_(mdlcache) 261 | #define MDLCACHE_COARSE_LOCK() MDLCACHE_COARSE_LOCK_(mdlcache) 262 | 263 | #endif // IMDLCACHE_H --------------------------------------------------------------------------------