Drawing.cpp 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. #pragma once
  2. #include <stdint.h>
  3. #include <string>
  4. #include <vector>
  5. #include "Drawing.h"
  6. #include "../Constants.h"
  7. namespace TLAC::Utilities
  8. {
  9. #pragma pack(push, 1)
  10. Drawing::FontInfo*(*Drawing::getFont)(FontInfo* fi, uint32_t id) = (FontInfo*(*)(FontInfo* fi, uint32_t id))0x140196510;
  11. void(*Drawing::fontSize)(FontInfo* fi, float width, float height) = (void(*)(FontInfo* fi, float width, float height))0x140199e60;
  12. void Drawing::drawText(DrawParams* dtParam, drawTextFlags flags, std::string str)
  13. {
  14. ((void(*)(DrawParams*, uint32_t, const char*, int64_t))0x140198500)(dtParam, flags, str.c_str(), str.length());
  15. }
  16. void Drawing::drawTextW(DrawParams* dtParam, drawTextFlags flags, std::wstring str)
  17. {
  18. const wchar_t* ptrs[2];
  19. ptrs[0] = str.c_str();
  20. ptrs[1] = (wchar_t*)((uint64_t)ptrs[0] + str.length() * 2);
  21. ((void(*)(DrawParams*, uint32_t, const wchar_t**))0x140198380)(dtParam, flags, &ptrs[0]);
  22. }
  23. void Drawing::drawTextFormattedW(DrawParams* dtParam, drawTextFlags flags, std::wstring str)
  24. {
  25. const wchar_t* ptrs[2];
  26. ptrs[0] = str.c_str();
  27. ptrs[1] = (wchar_t*)((uint64_t)ptrs[0] + str.length() * 2);
  28. ((void(*)(uint32_t, const wchar_t**, DrawParams*))0x1404c2aa0)(flags, &ptrs[0], dtParam);
  29. }
  30. void Drawing::drawTextWithSpritesW(DrawParams* dtParam, drawTextFlags flags, std::wstring str)
  31. {
  32. const wchar_t* ptrs[2];
  33. ptrs[0] = str.c_str();
  34. ptrs[1] = (wchar_t*)((uint64_t)ptrs[0] + str.length() * 2);
  35. ((void(*)(uint32_t, const wchar_t**, DrawParams*))0x1404c2cf0)(flags, &ptrs[0], dtParam);
  36. }
  37. void(*Drawing::fillRectangle)(DrawParams* dtParam, const RectangleBounds &rect) = (void(*)(DrawParams* dtParam, const RectangleBounds &rect))0x140198d80;
  38. // draws only a border -- use fillRectangle to fill contained pixels
  39. void Drawing::drawRectangle(DrawParams* dtParam, const RectangleBounds &rect)
  40. {
  41. ((void(*)(DrawParams*, const RectangleBounds&))0x140198320)(dtParam, rect);
  42. }
  43. // draws only a border -- use fillRectangle to fill contained pixels
  44. void Drawing::drawRectangle(DrawParams* dtParam, const RectangleBounds &rect, float thickness)
  45. {
  46. uint32_t oldFillColour = dtParam->fillColour;
  47. dtParam->fillColour = dtParam->colour;
  48. // yes this seems pretty dodgy, but sega does it this way so... I guess it's the only way
  49. RectangleBounds tempRect = { rect.x, rect.y, thickness, rect.height }; // left side
  50. fillRectangle(dtParam, tempRect);
  51. tempRect.x = rect.x + rect.width - thickness; // right side
  52. fillRectangle(dtParam, tempRect);
  53. tempRect = { rect.x + thickness, rect.y, rect.width - (thickness * 2), thickness }; // top side
  54. fillRectangle(dtParam, tempRect);
  55. tempRect.y = rect.y + rect.height - thickness; // left side
  56. fillRectangle(dtParam, tempRect);
  57. dtParam->fillColour = oldFillColour;
  58. }
  59. void Drawing::drawLine(DrawParams* dtParam, const Point &p1, const Point &p2)
  60. {
  61. ((void(*)(DrawParams*, const RectangleBounds&))0x140198080)(dtParam, { p1.x, p1.y, p2.x, p2.y });
  62. }
  63. // draw from the top left corner of rect to the bottom left
  64. void Drawing::drawLine(DrawParams* dtParam, const RectangleBounds &rect)
  65. {
  66. drawLine(dtParam, { rect.x, rect.y }, { rect.x + rect.width, rect.y + rect.height });
  67. }
  68. void Drawing::drawPolyline(DrawParams* dtParam, const std::vector<Point> points)
  69. {
  70. ((void(*)(DrawParams*, const Point*, uint64_t))0x1401980e0)(dtParam, points.data(), points.size());
  71. }
  72. /*
  73. int Drawing::findAetDebugFileId(std::string name)
  74. {
  75. AetDebugFileInfo* aetArray = *(AetDebugFileInfo**)AET_DEBUG_ARRAY_POINTER_ADDRESS;
  76. AetDebugFileInfo* aetArrayEndAddress = *(AetDebugFileInfo**)(AET_DEBUG_ARRAY_POINTER_ADDRESS + 0x08);
  77. int id = 0;
  78. while (&aetArray[id] < aetArrayEndAddress)
  79. {
  80. if (name == aetArray[id].name2.GetCharBuf()) // dwgui enum uses name2, so this should too I guess
  81. return aetArray[id].gameId;
  82. else
  83. id++;
  84. }
  85. return -1;
  86. }
  87. */
  88. // gets a file ID for use with createAetLayer
  89. // returns -1 if the file was not found
  90. // note: names are a little different to in 2dauth test -- it seems like they have "_MAIN" appended
  91. int Drawing::findAetFileId(std::string name)
  92. {
  93. AetFileInfo* aetArray = *(AetFileInfo**)AET_ARRAY_POINTER_ADDRESS;
  94. AetFileInfo* aetArrayEndAddress = *(AetFileInfo**)(AET_ARRAY_POINTER_ADDRESS + 0x08);
  95. int id = 0;
  96. while (&aetArray[id] < aetArrayEndAddress)
  97. {
  98. if (name == aetArray[id].name.GetCharBuf()) // dwgui enum uses name2, so this should too I guess
  99. return aetArray[id].id1;
  100. else
  101. id++;
  102. }
  103. return -1;
  104. }
  105. // draw an aet layer (with all settings)
  106. // aetSpeedCallback is actually a pointer to a class or struct with the callback address at offset +0x8
  107. int Drawing::createAetLayer(int32_t fileId, uint32_t drawLayer, createAetFlags flags, const char* name, const Point &loc, int32_t unk2, const char* animation, const char* animation2, float animationInTime, float animationOutTime, const Point &scale, const void* aetSpeedCallback)
  108. {
  109. return ((int(*)(int32_t, uint32_t, createAetFlags, const char*, const Point&, int32_t, const char*, const char*, float, float, const Point&, const void*))0x14013be60)(fileId, drawLayer, flags, name, loc, unk2, animation, animation2, animationInTime, animationOutTime, scale, aetSpeedCallback);
  110. }
  111. // draw an aet layer (with animation timing override)
  112. int Drawing::createAetLayer(int32_t fileId, uint32_t drawLayer, createAetFlags flags, const char* name, const Point &loc, float animationInTime, float animationOutTime)
  113. {
  114. return createAetLayer(fileId, drawLayer, flags, name, loc, 0, 0, 0, animationInTime, animationOutTime, *(Point*)0, 0);
  115. }
  116. // draw an aet layer (with scale)
  117. int Drawing::createAetLayer(int32_t fileId, uint32_t drawLayer, createAetFlags flags, const char* name, const Point &loc, const Point &scale)
  118. {
  119. return createAetLayer(fileId, drawLayer, flags, name, loc, 0, 0, 0, -1, -1, scale, 0);
  120. }
  121. // draw an aet layer
  122. int Drawing::createAetLayer(int32_t fileId, uint32_t drawLayer, createAetFlags flags, const char* name, const Point &loc)
  123. {
  124. return createAetLayer(fileId, drawLayer, flags, name, loc, 0, 0, 0, -1, -1, *(Point*)0, 0);
  125. }
  126. void Drawing::destroyAetLayer(int &layer)
  127. {
  128. if (layer != 0)
  129. {
  130. ((void(*)(int layer))0x14019d570)(layer);
  131. layer = 0;
  132. }
  133. }
  134. #pragma pack(pop)
  135. }