Advertisement
Guest User

RenderManager.cpp

a guest
Jul 16th, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.50 KB | None | 0 0
  1. #pragma once
  2. #include "RenderManager.h"
  3.  
  4. #define _CRT_SECURE_NO_WARNINGS
  5.  
  6. #define M_PI 3.14159265358979323846
  7.  
  8. namespace Render
  9. {
  10. namespace Fonts
  11. {
  12. DWORD Default;
  13. DWORD Menu;
  14. DWORD MenuBold;
  15. DWORD ESP;
  16. DWORD MenuText;
  17. DWORD Icon;
  18. DWORD MenuTabs;
  19. DWORD Text;
  20. DWORD ICON;
  21. DWORD Slider;
  22. DWORD AAarows;
  23. DWORD Clock;
  24. DWORD Untitled1;
  25. DWORD LBY;
  26. DWORD Tabs;
  27. DWORD CheckBox;
  28. DWORD MenuSymbols;
  29. DWORD LBYIndicator;
  30. DWORD WeaponIcon;
  31. DWORD xd;
  32.  
  33. DWORD jew;
  34. DWORD gay;
  35. };
  36. };
  37.  
  38.  
  39. enum EFontFlags
  40. {
  41. FONTFLAG_NONE,
  42. FONTFLAG_ITALIC = 0x001,
  43. FONTFLAG_UNDERLINE = 0x002,
  44. FONTFLAG_STRIKEOUT = 0x004,
  45. FONTFLAG_SYMBOL = 0x008,
  46. FONTFLAG_ANTIALIAS = 0x010,
  47. FONTFLAG_GAUSSIANBLUR = 0x020,
  48. FONTFLAG_ROTARY = 0x040,
  49. FONTFLAG_DROPSHADOW = 0x080,
  50. FONTFLAG_ADDITIVE = 0x100,
  51. FONTFLAG_OUTLINE = 0x200,
  52. FONTFLAG_CUSTOM = 0x400,
  53. FONTFLAG_BITMAP = 0x800,
  54. };
  55.  
  56. void Render::Initialise()
  57. {
  58. Fonts::Default = 0x1D;
  59. Fonts::Menu = Interfaces::Surface->FontCreate();
  60. Fonts::MenuBold = Interfaces::Surface->FontCreate();
  61. Fonts::ESP = Interfaces::Surface->FontCreate();
  62. Fonts::MenuText = Interfaces::Surface->FontCreate();
  63. Fonts::Icon = Interfaces::Surface->FontCreate();
  64. Fonts::ICON = Interfaces::Surface->FontCreate();
  65. Fonts::MenuTabs = Interfaces::Surface->FontCreate();
  66. Fonts::MenuText = Interfaces::Surface->FontCreate();
  67. Fonts::Slider = Interfaces::Surface->FontCreate();
  68. Fonts::AAarows = Interfaces::Surface->FontCreate();
  69. Fonts::Clock = Interfaces::Surface->FontCreate();
  70. Fonts::Untitled1 = Interfaces::Surface->FontCreate();
  71. Fonts::LBY = Interfaces::Surface->FontCreate();
  72. Fonts::Tabs = Interfaces::Surface->FontCreate();
  73. Fonts::CheckBox = Interfaces::Surface->FontCreate();
  74. Fonts::MenuSymbols = Interfaces::Surface->FontCreate();
  75. Fonts::LBYIndicator = Interfaces::Surface->FontCreate();
  76. Fonts::WeaponIcon = Interfaces::Surface->FontCreate();
  77. Fonts::xd= Interfaces::Surface->FontCreate();
  78.  
  79. Fonts::gay= Interfaces::Surface->FontCreate();
  80.  
  81. Fonts::jew = Interfaces::Surface->FontCreate();
  82.  
  83. Interfaces::Surface->SetFontGlyphSet(Fonts::Menu, "Arial", 12, 400, 0, 0, FONTFLAG_ANTIALIAS);
  84. Interfaces::Surface->SetFontGlyphSet(Fonts::Text, "DINPro-Regular", 30, 500, 0, 0, FONTFLAG_ANTIALIAS);
  85. Interfaces::Surface->SetFontGlyphSet(Fonts::MenuBold, "Arial", 14, 420, 0, 0, FONTFLAG_ANTIALIAS);
  86. Interfaces::Surface->SetFontGlyphSet(Fonts::ESP, "Tahoma", 12, 700, 0, 0, FONTFLAG_ANTIALIAS | FONTFLAG_DROPSHADOW); //"Verdana", 12, 500, 0, 0, FONTFLAG_ANTIALIAS | FONTFLAG_OUTLINE);
  87. Interfaces::Surface->SetFontGlyphSet(Fonts::MenuText, "Arial", 14, 370, 0, 0, FONTFLAG_ANTIALIAS);
  88. Interfaces::Surface->SetFontGlyphSet(Fonts::MenuTabs, "MyScriptFont", 18, 600, 0, 0, FONTFLAG_ANTIALIAS | FONTFLAG_DROPSHADOW);
  89. Interfaces::Surface->SetFontGlyphSet(Fonts::Slider, "Arial", 17, 600, 0, 0, FONTFLAG_ANTIALIAS | FONTFLAG_OUTLINE);
  90. Interfaces::Surface->SetFontGlyphSet(Fonts::Clock, "Arial", 22, 600, 0, 0, FONTFLAG_ANTIALIAS | FONTFLAG_OUTLINE);
  91. Interfaces::Surface->SetFontGlyphSet(Fonts::Tabs, "badcache", 30, 600, 0, 0, FONTFLAG_ANTIALIAS | FONTFLAG_DROPSHADOW);
  92. Interfaces::Surface->SetFontGlyphSet(Fonts::ICON, "Tahoma", 35, 800, 0, 0, FONTFLAG_ANTIALIAS);
  93. Interfaces::Surface->SetFontGlyphSet(Fonts::LBY, "Consolas", 38, 840, 0, 0, FONTFLAG_ANTIALIAS);
  94. Interfaces::Surface->SetFontGlyphSet(Fonts::CheckBox, "eagle", 14, 900, 0, 0, FONTFLAG_ANTIALIAS);
  95. Interfaces::Surface->SetFontGlyphSet(Fonts::Untitled1, "badcache", 16, 800, 0, 0, FONTFLAG_ANTIALIAS); //18
  96. Interfaces::Surface->SetFontGlyphSet(Fonts::Icon, "undefeated", 10, 500, 0, 0, FONTFLAG_ANTIALIAS | FONTFLAG_DROPSHADOW | FONTFLAG_OUTLINE);
  97. Interfaces::Surface->SetFontGlyphSet(Fonts::MenuSymbols, "Tahoma", 16, 500, 0, 0, FONTFLAG_ANTIALIAS);
  98. Interfaces::Surface->SetFontGlyphSet(Fonts::LBYIndicator, "Verdana", 20, 700, 0, 0, FONTFLAG_ANTIALIAS | FONTFLAG_DROPSHADOW);
  99. Interfaces::Surface->SetFontGlyphSet(Fonts::WeaponIcon, "cs", 20, 500, 0, 0, FONTFLAG_NONE);
  100. Interfaces::Surface->SetFontGlyphSet(Fonts::AAarows, "Verdana", 37, 900, 0, 0, FONTFLAG_ANTIALIAS);
  101.  
  102. Interfaces::Surface->SetFontGlyphSet(Fonts::gay, "Courier", 14, 505, 0, 0, FONTFLAG_ANTIALIAS);
  103.  
  104. Interfaces::Surface->SetFontGlyphSet(Fonts::xd, "Courier", 20, 500, 0, 0, FONTFLAG_NONE);
  105.  
  106. Interfaces::Surface->SetFontGlyphSet(Fonts::jew, "Courier", 30, 530, 0, 0, FONTFLAG_NONE);
  107.  
  108. Utilities::Log("Render System Ready");
  109. }
  110.  
  111. RECT Render::GetViewport()
  112. {
  113. RECT Viewport = { 0, 0, 0, 0 };
  114. int w, h;
  115. Interfaces::Engine->GetScreenSize(w, h);
  116. Viewport.right = w; Viewport.bottom = h;
  117. return Viewport;
  118. }
  119.  
  120. void Render::Clear(int x, int y, int w, int h, Color color)
  121. {
  122. Interfaces::Surface->DrawSetColor(color);
  123. Interfaces::Surface->DrawFilledRect(x, y, x + w, y + h);
  124. }
  125.  
  126. void Render::Outline(int x, int y, int w, int h, Color color)
  127. {
  128. Interfaces::Surface->DrawSetColor(color);
  129. Interfaces::Surface->DrawOutlinedRect(x, y, x + w, y + h);
  130. }
  131. void Render::OutlinedRect(int x, int y, int w, int h, Color color_out, Color color_in)
  132. {
  133. Interfaces::Surface->DrawSetColor(color_in);
  134. Interfaces::Surface->DrawFilledRect(x, y, x + w, y + h);
  135.  
  136. Interfaces::Surface->DrawSetColor(color_out);
  137. Interfaces::Surface->DrawOutlinedRect(x, y, x + w, y + h);
  138. }
  139. void Render::Line(int x, int y, int x2, int y2, Color color)
  140. {
  141. Interfaces::Surface->DrawSetColor(color);
  142. Interfaces::Surface->DrawLine(x, y, x2, y2);
  143. }
  144.  
  145. void Render::PolyLine(int *x, int *y, int count, Color color)
  146. {
  147. Interfaces::Surface->DrawSetColor(color);
  148. Interfaces::Surface->DrawPolyLine(x, y, count);
  149. }
  150.  
  151. void Render::DrawOutlinedRect(int x, int y, int w, int h, Color col)
  152. {
  153. Interfaces::Surface->DrawSetColor(col);
  154. Interfaces::Surface->DrawOutlinedRect(x, y, x + w, y + h);
  155. }
  156.  
  157. void Render::DrawLine(int x0, int y0, int x1, int y1, Color col)
  158. {
  159. Interfaces::Surface->DrawSetColor(col);
  160. Interfaces::Surface->DrawLine(x0, y0, x1, y1);
  161. }
  162. void Render::DrawRect(int x, int y, int w, int h, Color col)
  163. {
  164. Interfaces::Surface->DrawSetColor(col);
  165. Interfaces::Surface->DrawFilledRect(x, y, x + w, y + h);
  166. }
  167. void Render::rect(int x, int y, int w, int h, Color color)
  168. {
  169. Interfaces::Surface->DrawSetColor(color);
  170. Interfaces::Surface->DrawFilledRect(x, y, x + w, y + h);
  171. }
  172. bool Render::TransformScreen(const Vector& in, Vector& out)
  173. {
  174. static ptrdiff_t ptrViewMatrix;
  175. if (!ptrViewMatrix)
  176. {// findpattern z idy do wyszkuania
  177. ptrViewMatrix = static_cast<ptrdiff_t>(Utilities::Memory::FindPatternV2("client.dll", "0F 10 05 ? ? ? ? 8D 85 ? ? ? ? B9"));
  178. ptrViewMatrix += 0x3; // do ptrMatrix dodajemy +0x3 byte aby uzyskac dokladna lokalizacje
  179. ptrViewMatrix = *reinterpret_cast<uintptr_t*>(ptrViewMatrix);
  180. ptrViewMatrix += 176;
  181. }
  182. const matrix3x4& worldToScreen = Interfaces::Engine->WorldToScreenMatrix(); // matrix
  183.  
  184.  
  185.  
  186. int ScrW, ScrH;
  187.  
  188. Interfaces::Engine->GetScreenSize(ScrW, ScrH);
  189.  
  190. float w = worldToScreen[3][0] * in[0] + worldToScreen[3][1] * in[1] + worldToScreen[3][2] * in[2] + worldToScreen[3][3];
  191. out.z = 0; // 0 poniewaz z nie jest nam potrzebne | uzywamy tylko wysokosci i szerokosci (x,y)
  192. if (w > 0.01)
  193. {
  194. float inverseWidth = 1 / w; // inverse na 1 pozycje ekranu
  195. out.x = (ScrW / 2) + (0.5 * ((worldToScreen[0][0] * in[0] + worldToScreen[0][1] * in[1] + worldToScreen[0][2] * in[2] + worldToScreen[0][3]) * inverseWidth) * ScrW + 0.5);
  196. out.y = (ScrH / 2) - (0.5 * ((worldToScreen[1][0] * in[0] + worldToScreen[1][1] * in[1] + worldToScreen[1][2] * in[2] + worldToScreen[1][3]) * inverseWidth) * ScrH + 0.5);
  197. return true;
  198. }
  199. return false;
  200. }
  201. bool Render::WorldToScreen(const Vector& in, Vector& out)
  202. {
  203. if (Render::TransformScreen(in, out)) {
  204. int w, h;
  205. Interfaces::Engine->GetScreenSize(w, h);
  206. out.x = (w / 2.0f) + (out.x * w) / 2.0f;
  207. out.y = (h / 2.0f) - (out.y * h) / 2.0f;
  208. return true;
  209. }
  210. return false;
  211. }
  212.  
  213. void Render::Text(int x, int y, Color color, DWORD font, const char* text)
  214. {
  215. size_t origsize = strlen(text) + 1;
  216. const size_t newsize = 100;
  217. size_t convertedChars = 0;
  218. wchar_t wcstring[newsize];
  219. mbstowcs_s(&convertedChars, wcstring, origsize, text, _TRUNCATE);
  220.  
  221. Interfaces::Surface->DrawSetTextFont(font);
  222.  
  223. Interfaces::Surface->DrawSetTextColor(color);
  224. Interfaces::Surface->DrawSetTextPos(x, y);
  225. Interfaces::Surface->DrawPrintText(wcstring, wcslen(wcstring));
  226. return;
  227. }
  228. void Render::Text(int x, int y, Color color, DWORD font, const wchar_t* text)
  229. {
  230. Interfaces::Surface->DrawSetTextFont(font);
  231. Interfaces::Surface->DrawSetTextColor(color);
  232. Interfaces::Surface->DrawSetTextPos(x, y);
  233. Interfaces::Surface->DrawPrintText(text, wcslen(text));
  234. }
  235. void Render::Text2(int x, int y, const char* _Input, int font, Color color)
  236. {
  237. int apple = 0;
  238. char Buffer[2048] = { '\0' };
  239. va_list Args;
  240. va_start(Args, _Input);
  241. vsprintf_s(Buffer, _Input, Args);
  242. va_end(Args);
  243. size_t Size = strlen(Buffer) + 1;
  244. wchar_t* WideBuffer = new wchar_t[Size];
  245. mbstowcs_s(0, WideBuffer, Size, Buffer, Size - 1);
  246.  
  247. Interfaces::Surface->DrawSetTextColor(color);
  248. Interfaces::Surface->DrawSetTextFont(font);
  249. Interfaces::Surface->DrawSetTextPos(x, y);
  250. Interfaces::Surface->DrawPrintText(WideBuffer, wcslen(WideBuffer));
  251. }
  252. void Render::Textf(int x, int y, Color color, DWORD font, const char* fmt, ...)
  253. {
  254. if (!fmt) return; //if the passed string is null return
  255. if (strlen(fmt) < 2) return;
  256.  
  257. //Set up va_list and buffer to hold the params
  258. va_list va_alist;
  259. char logBuf[256] = { 0 };
  260.  
  261. //Do sprintf with the parameters
  262. va_start(va_alist, fmt);
  263. _vsnprintf_s(logBuf + strlen(logBuf), 256 - strlen(logBuf), sizeof(logBuf) - strlen(logBuf), fmt, va_alist);
  264. va_end(va_alist);
  265.  
  266. Text(x, y, color, font, logBuf);
  267. }
  268.  
  269. RECT Render::GetTextSize(DWORD font, const char* text)
  270. {
  271. size_t origsize = strlen(text) + 1;
  272. const size_t newsize = 100;
  273. size_t convertedChars = 0;
  274. wchar_t wcstring[newsize];
  275. mbstowcs_s(&convertedChars, wcstring, origsize, text, _TRUNCATE);
  276.  
  277. RECT rect; int x, y;
  278. Interfaces::Surface->GetTextSize(font, wcstring, x, y);
  279. rect.left = x; rect.bottom = y;
  280. rect.right = x;
  281. return rect;
  282. }
  283.  
  284. void Render::GradientV(int x, int y, int w, int h, Color c1, Color c2)
  285. {
  286. Clear(x, y, w, h, c1);
  287. BYTE first = c2.r();
  288. BYTE second = c2.g();
  289. BYTE third = c2.b();
  290. for (int i = 0; i < h; i++)
  291. {
  292. float fi = i, fh = h;
  293. float a = fi / fh;
  294. DWORD ia = a * 255;
  295. Clear(x, y + i, w, 1, Color(first, second, third, ia));
  296. }
  297. }
  298.  
  299. void Render::TexturedPolygon(int n, std::vector<Vertex_t> vertice, Color color)
  300. {
  301. static int texture_id = Interfaces::Surface->CreateNewTextureID(true); //
  302. static unsigned char buf[4] = { 255, 255, 255, 255 };
  303. Interfaces::Surface->DrawSetTextureRGBA(texture_id, buf, 1, 1); //
  304. Interfaces::Surface->DrawSetColor(color); //
  305. Interfaces::Surface->DrawSetTexture(texture_id); //
  306. Interfaces::Surface->DrawTexturedPolygon(n, vertice.data()); //
  307. }
  308.  
  309. void Render::DrawCircle(float x, float y, float r, float segments, Color color)
  310. {
  311. Interfaces::Surface->DrawSetColor(color);
  312. Interfaces::Surface->DrawOutlinedCircle(x, y, r, segments);
  313. }
  314.  
  315. void Render::GradientH(int x, int y, int w, int h, Color c1, Color c2)
  316. {
  317. Clear(x, y, w, h, c1);
  318. BYTE first = c2.r();
  319. BYTE second = c2.g();
  320. BYTE third = c2.b();
  321. for (int i = 0; i < w; i++)
  322. {
  323. float fi = i, fw = w;
  324. float a = fi / fw;
  325. DWORD ia = a * 255;
  326. Clear(x + i, y, 1, h, Color(first, second, third, ia));
  327. }
  328. }
  329.  
  330. void Render::Polygon(int count, Vertex_t* Vertexs, Color color)
  331. {
  332. static int Texture = Interfaces::Surface->CreateNewTextureID(true); //need to make a texture with procedural true
  333. unsigned char buffer[4] = { 255, 255, 255, 255 };//{ color.r(), color.g(), color.b(), color.a() };
  334.  
  335. Interfaces::Surface->DrawSetTextureRGBA(Texture, buffer, 1, 1); //Texture, char array of texture, width, height
  336. Interfaces::Surface->DrawSetColor(color); // keep this full color and opacity use the RGBA @top to set values.
  337. Interfaces::Surface->DrawSetTexture(Texture); // bind texture
  338.  
  339. Interfaces::Surface->DrawTexturedPolygon(count, Vertexs);
  340. }
  341.  
  342. void Render::PolygonOutline(int count, Vertex_t* Vertexs, Color color, Color colorLine)
  343. {
  344. static int x[128];
  345. static int y[128];
  346.  
  347. Render::Polygon(count, Vertexs, color);
  348.  
  349. for (int i = 0; i < count; i++)
  350. {
  351. x[i] = Vertexs[i].m_Position.x;
  352. y[i] = Vertexs[i].m_Position.y;
  353. }
  354.  
  355. Render::PolyLine(x, y, count, colorLine);
  356. }
  357.  
  358. void Render::PolyLine(int count, Vertex_t* Vertexs, Color colorLine)
  359. {
  360. static int x[128];
  361. static int y[128];
  362.  
  363. for (int i = 0; i < count; i++)
  364. {
  365. x[i] = Vertexs[i].m_Position.x;
  366. y[i] = Vertexs[i].m_Position.y;
  367. }
  368.  
  369. Render::PolyLine(x, y, count, colorLine);
  370. }
  371. void Render::Color_spectrum(int x, int y, int w, int h)
  372. {
  373. static int GradientTexture = 0;
  374. static std::unique_ptr<Color[]> Gradient = nullptr;
  375. if (!Gradient)
  376. {
  377. Gradient = std::make_unique<Color[]>(w * h);
  378.  
  379. for (int i = 0; i < w; i++)
  380. {
  381. int div = w / 6;
  382. int phase = i / div;
  383. float t = (i % div) / (float)div;
  384. int r, g, b;
  385.  
  386. switch (phase)
  387. {
  388. case(0):
  389. r = 255;
  390. g = 255 * t;
  391. b = 0;
  392. break;
  393. case(1):
  394. r = 255 * (1.f - t);
  395. g = 255;
  396. b = 0;
  397. break;
  398. case(2):
  399. r = 0;
  400. g = 255;
  401. b = 255 * t;
  402. break;
  403. case(3):
  404. r = 0;
  405. g = 255 * (1.f - t);
  406. b = 255;
  407. break;
  408. case(4):
  409. r = 255 * t;
  410. g = 0;
  411. b = 255;
  412. break;
  413. case(5):
  414. r = 255;
  415. g = 0;
  416. b = 255 * (1.f - t);
  417. break;
  418. }
  419.  
  420. for (int k = 0; k < h; k++)
  421. {
  422. float sat = k / (float)h;
  423. int _r = r + sat * (128 - r);
  424. int _g = g + sat * (128 - g);
  425. int _b = b + sat * (128 - b);
  426.  
  427. *reinterpret_cast<Color*>(Gradient.get() + i + k * w) = Color(_r, _g, _b);
  428. }
  429. }
  430.  
  431. GradientTexture = Interfaces::Surface->CreateNewTextureID(true);
  432. Interfaces::Surface->DrawSetTextureRGBA(GradientTexture, (unsigned char*)Gradient.get(), w, h);
  433. }
  434. Interfaces::Surface->DrawSetColor(Color(255, 255, 255, 255));
  435. Interfaces::Surface->DrawSetTexture(GradientTexture);
  436. Interfaces::Surface->DrawTexturedRect(x, y, x + w, y + h);
  437. }
  438. Color Render::Color_spectrum_pen(int x, int y, int w, int h, Vector stx)
  439. {
  440. int div = w / 6;
  441. int phase = stx.x / div;
  442. float t = ((int)stx.x % div) / (float)div;
  443. int r, g, b;
  444.  
  445. switch (phase)
  446. {
  447. case(0):
  448. r = 255;
  449. g = 255 * t;
  450. b = 0;
  451. break;
  452. case(1):
  453. r = 255 * (1.f - t);
  454. g = 255;
  455. b = 0;
  456. break;
  457. case(2):
  458. r = 0;
  459. g = 255;
  460. b = 255 * t;
  461. break;
  462. case(3):
  463. r = 0;
  464. g = 255 * (1.f - t);
  465. b = 255;
  466. break;
  467. case(4):
  468. r = 255 * t;
  469. g = 0;
  470. b = 255;
  471. break;
  472. case(5):
  473. r = 255;
  474. g = 0;
  475. b = 255 * (1.f - t);
  476. break;
  477. }
  478.  
  479. float sat = stx.y / h;
  480. return Color(r + sat * (128 - r), g + sat * (128 - g), b + sat * (128 - b), 255);
  481. }
  482. void Render::DrawTexturedPoly(int n, Vertex_t* vertice, Color col)
  483. {
  484. static int texture_id = Interfaces::Surface->CreateNewTextureID(true);
  485. static unsigned char buf[4] = { 255, 255, 255, 255 };
  486. Interfaces::Surface->DrawSetTextureRGBA(texture_id, buf, 1, 1);
  487. Interfaces::Surface->DrawSetColor(col);
  488. Interfaces::Surface->DrawSetTexture(texture_id);
  489. Interfaces::Surface->DrawTexturedPolygon(n, vertice);
  490. }
  491.  
  492. void Render::DrawFilledCircle(Vector2D center, Color color, float radius, float points)
  493. {
  494. std::vector<Vertex_t> vertices;
  495. float step = (float)M_PI * 2.0f / points;
  496.  
  497. for (float a = 0; a < (M_PI * 2.0f); a += step)
  498. vertices.push_back(Vertex_t(Vector2D(radius * cosf(a) + center.x, radius * sinf(a) + center.y)));
  499.  
  500. DrawTexturedPoly((int)points, vertices.data(), color);
  501. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement