Matrixs

IW6 R_AddCmdDrawText + AddBaseDrawConsoleTextCmd

Mar 6th, 2020
237
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.53 KB | None | 0 0
  1. union GfxColor {
  2.     char array[4];
  3.     unsigned int packed;
  4. };
  5.  
  6. struct GfxCmdHeader {
  7.     unsigned __int16 id;
  8.     unsigned __int16 byteCount;
  9. };
  10.  
  11. struct GfxCmdArray {
  12.     char* cmds;
  13.     unsigned __int64 usedTotal;
  14.     unsigned __int64 usedCritical;
  15.     GfxCmdHeader* lastCmd;
  16. };
  17.  
  18. void(*R_ConvertColorToBytes)(float*, GfxColor*) = (decltype(R_ConvertColorToBytes))0x14061EC50;
  19.  
  20. struct __declspec(align(2)) GfxCmdDrawText2D
  21. {
  22.     GfxCmdHeader header;
  23.     float x;
  24.     float y;
  25.     float rotation;
  26.     Font_s* font;
  27.     float xScale;
  28.     float yScale;
  29.     GfxColor color;
  30.     int maxChars;
  31.     int renderFlags;
  32.     int cursorPos;
  33.     char cursorLetter;
  34.     GfxColor glowForceColor;
  35.     int fxBirthTime;
  36.     int fxLetterTime;
  37.     int fxDecayStartTime;
  38.     int fxDecayDuration;
  39.     Material* fxMaterial;
  40.     Material* fxMaterialGlow;
  41.     float padding;
  42.     char text[3];
  43. };
  44.  
  45. GfxCmdHeader* R_GetCommandBuffer(int type, int bytes) {
  46.     GfxCmdArray* s_cmdList = *(GfxCmdArray**)0x148111820;
  47.  
  48.     std::uint64_t cmdCount = *(std::uint64_t*)0x148111810;
  49.     std::uint64_t remaining = (cmdCount - 0x2000 + s_cmdList->usedCritical - s_cmdList->usedTotal);
  50.  
  51.     if (bytes < remaining) {
  52.         s_cmdList->usedTotal = s_cmdList->usedTotal + bytes;
  53.        
  54.         GfxCmdHeader* cmd = (GfxCmdHeader*)(s_cmdList->cmds + s_cmdList->usedTotal);
  55.         s_cmdList->lastCmd = cmd;
  56.  
  57.         cmd->id = type;
  58.         cmd->byteCount = bytes;
  59.  
  60.         return cmd;
  61.     }
  62.  
  63.     return nullptr;
  64. }
  65.  
  66. void R_AddCmdDrawText(const char* text, int maxChars, Font_s* font, float x, float y, float xscale, float yscale, float rotation, float* color, int style) {
  67.     int len = strlen(text);
  68.     GfxCmdDrawText2D* cmd = (GfxCmdDrawText2D*)R_GetCommandBuffer(0x11, len + 1 & 0xFFFFFFFFFFFFFFFC);
  69.     if (cmd) {
  70.         cmd->x = x;
  71.         cmd->y = y;
  72.         cmd->rotation = rotation;
  73.         cmd->font = font;
  74.         cmd->xScale = xscale;
  75.         cmd->yScale = yscale;
  76.         cmd->maxChars = maxChars;
  77.         switch (style) {
  78.         case 3: cmd->renderFlags = 4; break;
  79.         case 6: cmd->renderFlags = 12; break;
  80.         case 7: cmd->renderFlags = 1024; break;
  81.         case 8: cmd->renderFlags = 3072; break;
  82.         case 128: cmd->renderFlags = 1; break;
  83.         case 132: cmd->renderFlags = 5; break;
  84.         }
  85.  
  86.         R_ConvertColorToBytes(color, &cmd->color);
  87.  
  88.         memcpy(cmd->text, text, len);
  89.         cmd->text[len] = '\0';
  90.     }
  91. }
  92.  
  93. void CopyPoolTextToCmd(char* textPool, int poolSize, int firstChar, int charCount, GfxCmdDrawText2D* cmd) {
  94.     int poolRemaining = poolSize - firstChar;
  95.     if (charCount > poolSize - firstChar) {
  96.         memcpy(cmd->text, &textPool[firstChar], poolRemaining);
  97.         memcpy(&cmd->text[poolRemaining], textPool, charCount - poolRemaining);
  98.     }
  99.     else {
  100.         memcpy(cmd->text, &textPool[firstChar], charCount);
  101.     }
  102.     cmd->text[charCount] = 0;
  103. }
  104.  
  105. GfxCmdDrawText2D* AddBaseDrawConsoleTextCmd(char* textPool, int poolSize, int firstChar, int charCount, Font_s* font, float x, float y, float xScale, float yScale, float* color, int style) {
  106.     if (!charCount)
  107.         return 0;
  108.  
  109.     GfxCmdDrawText2D* cmd = (GfxCmdDrawText2D*)R_GetCommandBuffer(0x11, (charCount + 96) & 0xFFFFFFFFFFFFFFFC);
  110.     if (!cmd)
  111.         return 0;
  112.  
  113.     cmd->x = x;
  114.     cmd->y = y;
  115.     cmd->rotation = 0.0f;
  116.     cmd->font = font;
  117.     cmd->xScale = xScale;
  118.     cmd->yScale = yScale;
  119.     cmd->maxChars = 0x7FFFFFFF;
  120.     cmd->renderFlags = 0;
  121.     switch (style) {
  122.     case 3: cmd->renderFlags = 4; break;
  123.     case 6: cmd->renderFlags = 12; break;
  124.     case 7: cmd->renderFlags = 1024; break;
  125.     case 8: cmd->renderFlags = 3072; break;
  126.     case 128: cmd->renderFlags = 1; break;
  127.     case 132: cmd->renderFlags = 5; break;
  128.     }
  129.  
  130.     R_ConvertColorToBytes(color, &cmd->color);
  131.     CopyPoolTextToCmd(textPool, poolSize, firstChar, charCount, cmd);
  132.     return cmd;
  133. }
Advertisement
Add Comment
Please, Sign In to add comment