forked from Phobos-developers/YRpp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Drawing.h
388 lines (333 loc) · 9.59 KB
/
Drawing.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
/*
Drawing related static class.
This provides access to the game's Surfaces, color value conversion
and text aligning helpers.
*/
#pragma once
#include <ColorScheme.h>
#include <GeneralDefinitions.h>
#include <Helpers/CompileTime.h>
#include <Surface.h>
#pragma pack(push, 1)
class RGBClass
{
public:
static constexpr reference<RGBClass, 0xA80220> White {};
static constexpr reference<int, 0x8A0DD0> const RedShiftLeft {};
static constexpr reference<int, 0x8A0DD4> const RedShiftRight {};
static constexpr reference<int, 0x8A0DE0> const GreenShiftLeft {};
static constexpr reference<int, 0x8A0DE4> const GreenShiftRight {};
static constexpr reference<int, 0x8A0DD8> const BlueShiftLeft {};
static constexpr reference<int, 0x8A0DDC> const BlueShiftRight {};
unsigned char Red;
unsigned char Green;
unsigned char Blue;
explicit RGBClass() noexcept
: Red { 0 }
, Green { 0 }
, Blue { 0 }
{
}
explicit RGBClass(int r, int g, int b) noexcept
: Red { static_cast<unsigned char>(r) }
, Green { static_cast<unsigned char>(g) }
, Blue { static_cast<unsigned char>(b) }
{
}
explicit RGBClass(int rgb, bool wordcolor = false) noexcept
{
if (!wordcolor)
{
Red = GetRValue(rgb);
Green = GetGValue(rgb);
Blue = GetBValue(rgb);
}
else
{
Red = (unsigned char)((unsigned short)rgb >> RedShiftLeft) << RedShiftRight;
Green = (unsigned char)((unsigned short)rgb>> GreenShiftLeft) << GreenShiftRight;
Blue = (unsigned char)((unsigned short)rgb>> BlueShiftLeft) << BlueShiftRight;
}
}
void Adjust(int ratio, RGBClass const& rgb)
{
ratio &= 0x00FF;
int value = (int)rgb.Red - (int)Red;
Red = static_cast<unsigned char>((int)Red + (value * ratio) / 256);
value = (int)rgb.Green - (int)Green;
Green = static_cast<unsigned char>((int)Green + (value * ratio) / 256);
value = (int)rgb.Blue - (int)Blue;
Blue = static_cast<unsigned char>((int)Blue + (value * ratio) / 256);
}
int Difference(RGBClass const& rgb) const
{
int r = (int)Red - (int)rgb.Red;
if (r < 0) r = -r;
int g = (int)Green - (int)rgb.Green;
if (g < 0) g = -g;
int b = (int)Blue - (int)rgb.Blue;
if (b < 0) b = -b;
return(r * r + g * g + b * b);
}
int ToInt()
{
return
(Red >> RedShiftRight << RedShiftLeft) |
(Green >> GreenShiftRight << GreenShiftLeft) |
(Blue >> BlueShiftRight << BlueShiftLeft) ;
}
};
#pragma pack(pop)
struct DirtyAreaStruct
{
RectangleStruct Rect;
bool alphabool10;
bool operator==(const DirtyAreaStruct& another) const
{
return
Rect.X == another.Rect.X &&
Rect.Y == another.Rect.Y &&
Rect.Width == another.Rect.Width &&
Rect.Height == another.Rect.Height &&
alphabool10 == another.alphabool10;
};
};
class Drawing
{
public:
constexpr static reference<DynamicVectorClass<DirtyAreaStruct>, 0xB0CE78> DirtyAreas {};
static constexpr reference<ColorStruct, 0xB0FA1C> const TooltipColor {};
// RGB color mode currently in use, determined by primary drawing surface. The bitshift values below can change depending on this.
static constexpr reference<RGBMode, 0x8205D0> ColorMode {};
static constexpr reference<int, 0x8A0DD0> const RedShiftLeft {};
static constexpr reference<int, 0x8A0DD4> const RedShiftRight {};
static constexpr reference<int, 0x8A0DE0> const GreenShiftLeft {};
static constexpr reference<int, 0x8A0DE4> const GreenShiftRight {};
static constexpr reference<int, 0x8A0DD8> const BlueShiftLeft {};
static constexpr reference<int, 0x8A0DDC> const BlueShiftRight {};
//TextBox dimensions for tooltip-style boxes
static RectangleStruct* __fastcall GetTextDimensions(
RectangleStruct* pOutBuffer, wchar_t const* pText, Point2D location,
WORD flags, int marginX = 0, int marginY = 0)
{ JMP_STD(0x4A59E0); }
static RectangleStruct __fastcall GetTextDimensions(
wchar_t const* pText, Point2D location, WORD flags, int marginX = 0,
int marginY = 0)
{
RectangleStruct buffer;
GetTextDimensions(&buffer, pText, location, flags, marginX, marginY);
return buffer;
}
// Rectangles
static RectangleStruct* __fastcall Intersect(
RectangleStruct* pOutBuffer, RectangleStruct const& rect1,
RectangleStruct const& rect2, int* delta_left = nullptr,
int* delta_top = nullptr)
{ JMP_STD(0x421B60); }
static RectangleStruct __fastcall Intersect(
RectangleStruct const& rect1, RectangleStruct const& rect2,
int* delta_left = nullptr, int* delta_top = nullptr)
{
RectangleStruct buffer;
Intersect(&buffer, rect1, rect2, delta_left, delta_top);
return buffer;
}
// Rect1 will be changed, notice that - secsome
static RectangleStruct* __fastcall Union(
RectangleStruct* pOutBuffer,
const RectangleStruct& rect1,
const RectangleStruct& rect2)
{ JMP_STD(0x487F40); }
// Rect1 will be changed, notice that - secsome
static RectangleStruct __fastcall Union(
const RectangleStruct& rect1,
const RectangleStruct& rect2)
{
RectangleStruct buffer;
Union(&buffer, rect1, rect2);
return buffer;
}
/*
static int __fastcall RGB_To_Int(int red, int green, int blue)
{ JMP_STD(0x4355D0); }
*/
static int RGB_To_Int(int red, int green, int blue)
{
return (red >> RedShiftRight << RedShiftLeft) | (green >> GreenShiftRight << GreenShiftLeft) | (blue >> BlueShiftRight << BlueShiftLeft);
}
static int RGB_To_Int(const ColorStruct& Color)
{
return RGB_To_Int(Color.R, Color.G, Color.B);
}
static int RGB_To_Int(ColorStruct&& Color)
{
return RGB_To_Int(Color.R, Color.G, Color.B);
}
static void Int_To_RGB(int color, BYTE& red, BYTE& green, BYTE& blue)
{
red = static_cast<BYTE>(color >> RedShiftLeft << RedShiftRight);
green = static_cast<BYTE>(color >> GreenShiftLeft << GreenShiftRight);
blue = static_cast<BYTE>(color >> BlueShiftLeft << BlueShiftRight);
}
static void Int_To_RGB(int color, ColorStruct& buffer)
{
Int_To_RGB(color, buffer.R, buffer.G, buffer.B);
}
static ColorStruct Int_To_RGB(int color)
{
ColorStruct ret;
Int_To_RGB(color, ret);
return ret;
}
};
//A few preset 16bit colors.
#define COLOR_BLACK 0x0000
#define COLOR_WHITE 0xFFFF
#define COLOR_RED 0xF800
#define COLOR_GREEN 0x07E0
#define COLOR_BLUE 0x001F
#define COLOR_YELLOW (COLOR_RED | COLOR_GREEN)
#define COLOR_PURPLE (COLOR_RED | COLOR_BLUE)
#define COLOR_CYAN (COLOR_BLUE | COLOR_GREEN)
class NOVTABLE ABuffer
{
public:
static constexpr reference<ABuffer*, 0x87E8A4> Instance {};
ABuffer(RectangleStruct Rect) { JMP_THIS(0x410CE0); }
bool BlitTo(Surface* pSurface, int X, int Y, int Offset, int Size) { JMP_THIS(0x410DC0); }
void ReleaseSurface() { JMP_THIS(0x410E50); }
void Blitter(unsigned short* Data, int Length, unsigned short Value) { JMP_THIS(0x410E70); }
void BlitAt(int X, int Y, COLORREF Color) { JMP_THIS(0x410ED0); }
bool Fill(unsigned short Color) { JMP_THIS(0x4112D0); }
bool FillRect(unsigned short Color, RectangleStruct Rect) { JMP_THIS(0x411310); }
void BlitRect(RectangleStruct Rect) { JMP_THIS(0x411330); }
void* GetBuffer(int X, int Y) { JMP_THIS(0x4114B0); }
template<typename T>
void AdjustPointer(T*& ptr)
{
if (ptr >= BufferTail)
reinterpret_cast<char*&>(ptr) -= BufferSize;
}
RectangleStruct Bounds;
int BufferPosition;
BSurface* Surface;
void* BufferHead;
void* BufferTail;
int BufferSize;
int MaxValue;
int Width;
int Height;
};
class NOVTABLE ZBuffer
{
public:
static constexpr reference<ZBuffer*, 0x887644> Instance {};
ZBuffer(RectangleStruct Rect) { JMP_THIS(0x7BC970); }
bool BlitTo(Surface* pSurface, int X, int Y, int Offset, int Size) { JMP_THIS(0x7BCA50); }
void ReleaseSurface() { JMP_THIS(0x7BCAE0); }
void Blitter(unsigned short* Data, int Length, unsigned short Value) { JMP_THIS(0x7BCAF0); }
void BlitAt(int X, int Y, COLORREF Color) { JMP_THIS(0x7BCB50); }
bool Fill(unsigned short Color) { JMP_THIS(0x7BCF50); }
bool FillRect(unsigned short Color, RectangleStruct Rect) { JMP_THIS(0x7BCF90); }
void BlitRect(RectangleStruct Rect) { JMP_THIS(0x7BCFB0); }
void* GetBuffer(int X, int Y) { JMP_THIS(0x7BD130); }
template<typename T>
void AdjustPointer(T*& ptr)
{
if (ptr >= BufferTail)
reinterpret_cast<char*&>(ptr) -= BufferSize;
}
RectangleStruct Bounds;
int BufferOffset;
BSurface* Surface;
void* BufferHead;
void* BufferTail;
int BufferSize;
int MaxValue;
int Width;
int Height;
};
struct VoxelCacheStruct
{
short X;
short Y;
unsigned short Width;
unsigned short Height;
void* Buffer;
};
struct MainVoxelIndexKey
{
public:
unsigned FrameIndex : 5;
unsigned RampType : 5;
private:
unsigned bitfield_10 : 6;
public:
unsigned UseAuxVoxel : 1; // !(!pUnit->Type->NoSpawnAlt || pUnit->SpawnManager->Draw_State())
private:
unsigned bitfield_17 : 15;
};
struct TurretWeaponVoxelIndexKey
{
public:
unsigned Facing : 5;
unsigned HasTurretOffset : 5;
private:
unsigned bitfield_10 : 6;
public:
unsigned FrameIndex : 8;
unsigned TurretWeaponIndex : 8;
};
struct ShadowVoxelIndexKey
{
public:
unsigned Data : 32;
};
struct TurretBarrelVoxelIndexKey
{
public:
unsigned Facing : 5;
unsigned HasTurretOffset : 5;
private:
unsigned bitfield_10 : 6;
public:
unsigned FrameIndex : 8;
private:
unsigned bitfield_24 : 8;
};
struct ReservedVoxelIndexKey
{
private:
unsigned bitfield_0 : 10;
public:
unsigned ReservedIndex : 6;
private:
unsigned bitfield_16 : 16;
};
union VoxelIndexKey
{
constexpr VoxelIndexKey(int val = 0) noexcept
{
Value = val;
}
constexpr operator int () const
{
return Value;
}
constexpr bool Is_Valid_Key() const
{
return Value != -1;
}
constexpr void Invalidate()
{
Value = -1;
}
MainVoxelIndexKey MainVoxel;
TurretWeaponVoxelIndexKey TurretWeapon;
ShadowVoxelIndexKey Shadow;
TurretBarrelVoxelIndexKey TurretBarrel;
ReservedVoxelIndexKey Reserved;
private:
int Value;
};
static_assert(sizeof(VoxelIndexKey) == sizeof(int));