Advertisement
encoree1996

Untitled

Dec 26th, 2015
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.22 KB | None | 0 0
  1. class cKeyValues
  2. {
  3. char __pad[6000];
  4. };
  5.  
  6. bool bDataCompare(const BYTE *pData, const BYTE *bMask, const char *szMask)
  7. {
  8. for (; *szMask; ++szMask, ++pData, ++bMask)
  9. if (*szMask == 'x' && *pData != *bMask)
  10. return false;
  11. return (*szMask) == NULL;
  12. }
  13.  
  14. DWORD dwFindPattern(DWORD dwAddress, DWORD dwLen, BYTE *bMask, char *szMask)
  15. {
  16. for (DWORD i = 0; i < dwLen; i++)
  17. if (bDataCompare((BYTE*)(dwAddress + i), bMask, szMask))
  18. return (DWORD)(dwAddress + i);
  19. return 0;
  20. }
  21.  
  22. void GameFunc_InitKeyValues(cKeyValues* pKeyValues, const char* name)
  23. {
  24. /*Mid function Pattern -> sub 0x45*/
  25. /*8B 0E 33 4D FC 81 E1 ? ? ? ? 31 0E 88 46 03 C1 F8 08 66 89 46 12 8B C6*/
  26. static uint32_t funcAddr = dwFindPattern((DWORD)GetModuleHandleA(XOR("client.dll")), MAXDWORD, (PBYTE)"\x8B\x0E\x33\x4D\xFC\x81\xE1\x00\x00\x00\x00\x31\x0E\x88\x46\x03\xC1\xF8\x08\x66\x89\x46\x12\x8B\xC6", "xxxxxxx????xxxxxxxxxxxxxx") - 0x45;
  27.  
  28. typedef void(__thiscall* orgGameFunc_InitKeyValues)(void* thisptr, const char* name);
  29. static orgGameFunc_InitKeyValues pInitKeyValues = reinterpret_cast<orgGameFunc_InitKeyValues>(funcAddr);
  30.  
  31. pInitKeyValues(pKeyValues, name);
  32. }
  33.  
  34. void GameFunc_LoadFromBuffer(cKeyValues* pKeyValues, const char* resourceName, const char* pBuffer, IBaseFileSystem* pFileSystem = nullptr, const char* pPathID = NULL, void* pfnEvaluateSymbolProc = nullptr)
  35. {
  36. /*55 8B EC 83 E4 F8 83 EC 34 53 8B 5D 0C 89 4C 24 04*/
  37. static uint32_t funcAddr = dwFindPattern((DWORD)GetModuleHandleA(XOR("client.dll")), MAXDWORD, (PBYTE)"\x55\x8B\xEC\x83\xE4\xF8\x83\xEC\x34\x53\x8B\x5D\x0C\x89\x4C\x24\x04", "xxxxxxxxxxxxxxxxx");
  38.  
  39. typedef void(__thiscall* orgGameFunc_LoadFromBuffer)(void* thisptr, const char* resourceName, const char* pBuffer, IBaseFileSystem* pFileSystem, const char* pPathID, void* pfnEvaluateSymbolProc);
  40. static orgGameFunc_LoadFromBuffer pLoadFromBuffer = reinterpret_cast<orgGameFunc_LoadFromBuffer>(funcAddr);
  41.  
  42. pLoadFromBuffer(pKeyValues, resourceName, pBuffer, pFileSystem, pPathID, pfnEvaluateSymbolProc);
  43. }
  44.  
  45. IMaterial* CreateMaterial()
  46. {
  47. /*Assemble the material*/
  48. //std::string std_StrMaterialData1 = "\"VertexLitGeneric\"\n{\n\t\"$basetexture\" \"vgui/white_additive\"\n\t\"$envmap\" \"\"\n\t\"$model\" \"1\"\n\t\"$flat\" \"1\"\n\t\"$nocull\" \"0\"\n\t\"$selfillum\" \"1\"\n\t\"$halflambert\" \"1\"\n\t\"$nofog\" \"0\"\n\t\"$znearer\" \"0\"\n\t\"$wireframe\" \"0\"\n}\n";
  49. std::string std_StrMaterialData2 = XOR("\"VertexLitGeneric\"\n{\n\t\"$basetexture\" \"vgui/white_additive\"\n\t\"$envmap\" \"\"\n\t\"$model\" \"1\"\n\t\"$flat\" \"1\"\n\t\"$nocull\" \"0\"\n\t\"$selfillum\" \"1\"\n\t\"$halflambert\" \"1\"\n\t\"$nofog\" \"1\"\n\t\"$znearer\" \"1\"\n\t\"$wireframe\" \"0\"\n}\n");
  50. std::string std_StrMaterialName = XOR("mmat.vtf");
  51.  
  52. /*Register the material*/
  53. cKeyValues* pKeyValues = new cKeyValues();
  54. GameFunc_InitKeyValues(pKeyValues, XOR("VertexLitGeneric"));
  55. GameFunc_LoadFromBuffer(pKeyValues, std_StrMaterialName.c_str(), std_StrMaterialData2.c_str(), nullptr, NULL, nullptr);
  56.  
  57. /*Create the new material (Increasing refCount by 1 to keep engine from freeing it)*/
  58. IMaterial* pMaterial = materials->CreateMaterial(std_StrMaterialName.c_str(), pKeyValues);
  59. pMaterial->IncrementReferenceCount();
  60.  
  61. return pMaterial;
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement