Advertisement
Guest User

Untitled

a guest
May 23rd, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.12 KB | None | 0 0
  1.  
  2. void InitKeyValues(KeyValues* keyValues, char* name)
  3. {
  4.  
  5. DWORD dwFunction = (DWORD)Offsets::Functions::KeyValues_KeyValues;
  6. __asm
  7. {
  8. push name
  9. mov ecx, keyValues
  10. call dwFunction
  11. }
  12. }
  13.  
  14. void LoadFromBuffer(KeyValues* keyValues, char const *resourceName, const char *pBuffer)
  15. {
  16.  
  17. DWORD dwFunction = (DWORD)Offsets::Functions::KeyValues_LoadFromBuffer;
  18.  
  19. __asm
  20. {
  21. push 0
  22. push 0
  23. push 0
  24. push pBuffer
  25. push resourceName
  26. mov ecx, keyValues
  27. call dwFunction
  28. }
  29. }
  30.  
  31. IMaterial *CreateMaterial(bool shouldIgnoreZ, bool isLit, bool isWireframe)
  32. {
  33.  
  34.  
  35. static int created = 0;
  36.  
  37. static const char tmp[] =
  38. {
  39. "\"%s\"\
  40. \n{\
  41. \n\t\"$basetexture\" \"vgui/white_additive\"\
  42. \n\t\"$envmap\" \"\"\
  43. \n\t\"$model\" \"1\"\
  44. \n\t\"$flat\" \"1\"\
  45. \n\t\"$nocull\" \"0\"\
  46. \n\t\"$selfillum\" \"1\"\
  47. \n\t\"$halflambert\" \"1\"\
  48. \n\t\"$nofog\" \"0\"\
  49. \n\t\"$ignorez\" \"%i\"\
  50. \n\t\"$znearer\" \"0\"\
  51. \n\t\"$wireframe\" \"%i\"\
  52. \n}\n"
  53. };
  54.  
  55. char* baseType = (isLit == true ? "VertexLitGeneric" : "UnlitGeneric");
  56. char material[512];
  57. sprintf_s(material, sizeof(material), tmp, baseType, (shouldIgnoreZ) ? 1 : 0, (isWireframe) ? 1 : 0);
  58.  
  59. char name[512];
  60. sprintf_s(name, sizeof(name), "#avoz_%i.vmt", created);
  61. ++created;
  62. KeyValues* keyValues = (KeyValues*)malloc(sizeof(KeyValues));
  63. InitKeyValues(keyValues, baseType);
  64. LoadFromBuffer(keyValues, name, material);
  65.  
  66. IMaterial *createdMaterial = Interfaces::MaterialSystem->CreateMaterial(name, keyValues);
  67. createdMaterial->IncrementReferenceCount();
  68. return createdMaterial;
  69. }
  70.  
  71.  
  72.  
  73. void ForceMaterial(Color color, IMaterial* material, bool useColor, bool forceMaterial)
  74. {
  75.  
  76. if (useColor)
  77. {
  78. float temp[3] =
  79. {
  80.  
  81. color.r(),
  82. color.g(),
  83. color.b()
  84. };
  85.  
  86. temp[0] /= 255.f;
  87. temp[1] /= 255.f;
  88. temp[2] /= 255.f;
  89.  
  90.  
  91. float alpha = color.a();
  92.  
  93. Interfaces::RenderView->SetBlend(1.0f);
  94. Interfaces::RenderView->SetColorModulation(temp);
  95. }
  96.  
  97. if (forceMaterial)
  98. Interfaces::ModelRender->ForcedMaterialOverride(material);
  99. else
  100. Interfaces::ModelRender->ForcedMaterialOverride(NULL);
  101.  
  102. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement