Advertisement
Guest User

CHAMS.CPP

a guest
Feb 24th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.20 KB | None | 0 0
  1. #include "Chams.h"
  2. #include "offsets.h"
  3. #include "SDK.h"
  4. #include "Interfaces.h"
  5.  
  6. void InitKeyValues(KeyValues* keyValues, char* name)
  7. {
  8. DWORD dwFunction = (DWORD)Offsets::Functions::KeyValues_KeyValues;
  9. __asm
  10. {
  11. push name
  12. mov ecx, keyValues
  13. call dwFunction
  14. }
  15. }
  16.  
  17. void LoadFromBuffer(KeyValues* keyValues, char const *resourceName, const char *pBuffer)
  18. {
  19. DWORD dwFunction = (DWORD)Offsets::Functions::KeyValues_LoadFromBuffer;
  20.  
  21. __asm
  22. {
  23. push 0
  24. push 0
  25. push 0
  26. push pBuffer
  27. push resourceName
  28. mov ecx, keyValues
  29. call dwFunction
  30. }
  31. }
  32.  
  33. IMaterial *CreateMaterial(bool shouldIgnoreZ, bool isLit, bool isWireframe)
  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), "#CHAMS_%i.vmt", created);
  61. ++created;
  62.  
  63. KeyValues* keyValues = (KeyValues*)malloc(sizeof(KeyValues));
  64. InitKeyValues(keyValues, baseType);
  65. LoadFromBuffer(keyValues, name, material);
  66.  
  67. IMaterial *createdMaterial = Interfaces::MaterialSystem->CreateMaterial(name, keyValues);
  68. createdMaterial->IncrementReferenceCount();
  69.  
  70. return createdMaterial;
  71. }
  72.  
  73. void ForceMaterial(Color color, IMaterial* material, bool useColor, bool forceMaterial)
  74. {
  75. if (useColor)
  76. {
  77. float temp[3] =
  78. {
  79. color.r(),
  80. color.g(),
  81. color.b()
  82. };
  83.  
  84. temp[0] /= 255.f;
  85. temp[1] /= 255.f;
  86. temp[2] /= 255.f;
  87.  
  88.  
  89. float alpha = color.a();
  90.  
  91. Interfaces::RenderView->SetBlend(1.0f);
  92. Interfaces::RenderView->SetColorModulation(temp);
  93. }
  94.  
  95. if (forceMaterial)
  96. Interfaces::ModelRender->ForcedMaterialOverride(material);
  97. else
  98. Interfaces::ModelRender->ForcedMaterialOverride(NULL);
  99.  
  100. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement