-
-
Notifications
You must be signed in to change notification settings - Fork 546
Expand file tree
/
Copy pathCHudSA.h
More file actions
323 lines (266 loc) · 12.6 KB
/
CHudSA.h
File metadata and controls
323 lines (266 loc) · 12.6 KB
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
/*****************************************************************************
*
* PROJECT: Multi Theft Auto v1.0
* LICENSE: See LICENSE in the top level directory
* FILE: game_sa/CHudSA.h
* PURPOSE: Header file for HUD display class
*
* Multi Theft Auto is available from https://www.multitheftauto.com/
*
*****************************************************************************/
#pragma once
#include <game/CHud.h>
#include <CVector.h>
#include <game/RenderWare.h>
#include "CFontSA.h"
#include "CRect.h"
#define FUNC_Draw 0x58FAE0
#define VAR_DisableClock 0xBAA400
// X
#define VAR_AspectRatioMultX 0x859520
// Y
#define VAR_AspectRatioMult 0x859524
#define VAR_CameraCrosshairScale 0x866C74
#define FUNC_DrawAmmo 0x5893B0
#define FUNC_DrawWeaponIcon 0x58D7D0
#define FUNC_RenderHealthBar 0x589270
#define FUNC_RenderBreathBar 0x589190
#define FUNC_RenderArmorBar 0x5890A0
#define FUNC_DrawVitalStats 0x589650
#define FUNC_DrawVehicleName 0x58AEA0
#define FUNC_DrawHelpText 0x58B6E0
#define FUNC_DrawAreaName 0x58AA50
#define FUNC_DrawRadar 0x58A330
#define FUNC_DrawRadarPlanB 0x58A335
#define FUNC_DrawRadioName 0x4E9E50
#define FUNC_DrawWantedLevel 0x58D9A0
#define FUNC_DrawCrosshair 0x58E020
#define FUNC_CStats_GetFatAndMuscleModifier 0x559AF0
#define FUNC_CSprite2d_DrawBarChart 0x728640
#define FUNC_CSprite2d_Draw 0x728350
#define FUNC_CSprite_RenderOneXLUSprite 0x70D000
#define FUNC_CRadar_DrawMap 0x586B00
#define FUNC_CRadar_DrawBlips 0x588050
#define CODE_ShowMoney 0x58F47D
#define CODE_ShowRadarAltimeter 0x58A5A6
#define VAR_RSGlobal 0xC17040
#define VAR_ItemToFlash 0xBAB1DC
#define VAR_ChairMultX 0xB6EC14
#define VAR_ChairMultY 0xB6EC10
#define VAR_CrosshairTexSize 64.0f // 64x64
struct SHudComponent
{
bool bIsPartOfAll;
eHudComponent type;
bool bSaveOriginalBytes;
DWORD uiDataAddr;
DWORD uiDataSize;
DWORD origData;
DWORD disabledData;
};
enum class eHudColour
{
RED,
GREEN,
DARK_BLUE,
LIGHT_BLUE,
LIGHT_GRAY,
BLACK,
GOLD,
PURPLE,
DARK_GRAY,
DARK_RED,
DARK_GREEN,
CREAM,
NIGHT_BLUE,
BLUE,
YELLOW,
};
struct RsGlobal
{
const char* appName;
std::int32_t maximumWidth;
std::int32_t maximumHeight;
std::int32_t frameLimit;
bool quit;
void* ps;
std::uint8_t keyboard[12]; // RsInputDevice
std::uint8_t mouse[12]; // RsInputDevice
std::uint8_t pad[12]; // RsInputDevice
};
struct SComponentPlacement
{
// Original position & size
float x{0.0f}, y{0.0f}; // for getter function only
float width{0.0f}, height{0.0f};
float stringWidth{0.0f}, stringHeight{0.0f}; // for getter function only
// Custom position & size
float customX{0.0f}, customY{0.0f};
float customWidth{0.0f}, customHeight{0.0f};
bool useCustomPosition{false};
bool useCustomSize{false};
bool setDefaultXY{false};
};
struct SHudComponentData
{
SComponentPlacement placement{};
RwColor fillColor{};
RwColor fillColorSecondary{0, 0, 0, 255};
// Bar
bool drawBlackBorder{true};
bool drawPercentage{false};
// Text
RwColor dropColor{0, 0, 0, 255};
eFontAlignment alignment{};
eFontStyle style{};
std::int16_t textOutline{0};
std::int16_t textShadow{0};
bool proportional{false};
bool useCustomAlpha{false};
SHudComponentData(RwColor fill = {}, RwColor fillSecondary = {0, 0, 0, 255}, bool blackBorder = true, bool percentage = false, RwColor drop = {},
eFontAlignment align = eFontAlignment::ALIGN_LEFT, eFontStyle fontStyle = eFontStyle::FONT_PRICEDOWN, std::int16_t outline = 0,
std::int16_t shadow = 0, bool prop = false, bool useCustomAlpha = false)
: fillColor(fill),
fillColorSecondary(fillSecondary),
drawBlackBorder(blackBorder),
drawPercentage(percentage),
dropColor(drop),
alignment(align),
style(fontStyle),
textOutline(outline),
textShadow(shadow),
proportional(prop),
useCustomAlpha(useCustomAlpha)
{
}
};
struct ComponentProperties
{
SHudComponentData hpBar;
SHudComponentData breathBar;
SHudComponentData armorBar;
SHudComponentData clock;
SHudComponentData money;
SHudComponentData ammo;
SHudComponentData vehName;
SHudComponentData areaName;
SHudComponentData radioName;
SHudComponentData weaponIcon;
SHudComponentData wanted;
SHudComponentData crosshair;
};
class CHudSA : public CHud
{
public:
CHudSA();
void Disable(bool bDisabled);
bool IsDisabled();
void SetComponentVisible(eHudComponent component, bool bVisible);
bool IsComponentVisible(eHudComponent component);
void AdjustComponents(float fAspectRatio);
void ResetComponentAdjustment();
bool IsCrosshairVisible();
bool IsComponentBar(const eHudComponent& component) const noexcept override;
bool IsComponentText(const eHudComponent& component) const noexcept override;
void SetComponentPlacementPosition(SComponentPlacement& placement, const CVector2D& position) noexcept;
void SetComponentPlacementSize(SComponentPlacement& placement, const CVector2D& size) noexcept;
void SetComponentPosition(const eHudComponent& component, const CVector2D& position) noexcept override
{
SetComponentPlacementPosition(GetHudComponentRef(component).placement, position);
}
void SetComponentSize(const eHudComponent& component, const CVector2D& size) noexcept override
{
SetComponentPlacementSize(GetHudComponentRef(component).placement, size);
}
void ResetComponentPlacement(const eHudComponent& component, bool resetSize) noexcept override;
void SetComponentColor(const eHudComponent& component, std::uint32_t color, bool secondColor = false) noexcept override;
void ResetComponentColor(const eHudComponent& component, bool secondColor = false) noexcept override;
void SetComponentDrawBlackBorder(const eHudComponent& component, bool draw) noexcept override { GetHudComponentRef(component).drawBlackBorder = draw; }
void SetComponentDrawPercentage(const eHudComponent& component, bool draw) noexcept override { GetHudComponentRef(component).drawPercentage = draw; }
void SetHealthBarBlinkingValue(float minHealth) noexcept override { blinkingBarHPValue = minHealth; }
void SetComponentFontDropColor(const eHudComponent& component, std::uint32_t color) noexcept override;
void SetComponentFontOutline(const eHudComponent& component, float outline) noexcept override
{
GetHudComponentRef(component).textOutline = static_cast<std::int16_t>(outline);
}
void SetComponentFontShadow(const eHudComponent& component, float shadow) noexcept override
{
GetHudComponentRef(component).textShadow = static_cast<std::int16_t>(shadow);
}
void SetComponentFontStyle(const eHudComponent& component, const eFontStyle& style) noexcept override { GetHudComponentRef(component).style = style; }
void SetComponentFontAlignment(const eHudComponent& component, const eFontAlignment& alignment) noexcept override
{
GetHudComponentRef(component).alignment = alignment;
}
void SetComponentFontProportional(const eHudComponent& component, bool proportional) noexcept override
{
GetHudComponentRef(component).proportional = proportional;
}
void SetComponentUseCustomAlpha(const eHudComponent& component, bool useCustomAlpha) noexcept override
{
GetHudComponentRef(component).useCustomAlpha = useCustomAlpha;
}
void ResetComponentFontOutline(const eHudComponent& component) noexcept override { ResetComponentFontData(component, eHudComponentProperty::TEXT_OUTLINE); }
void ResetComponentFontShadow(const eHudComponent& component) noexcept override { ResetComponentFontData(component, eHudComponentProperty::TEXT_SHADOW); }
void ResetComponentFontStyle(const eHudComponent& component) noexcept override { ResetComponentFontData(component, eHudComponentProperty::TEXT_STYLE); }
void ResetComponentFontAlignment(const eHudComponent& component) noexcept override
{
ResetComponentFontData(component, eHudComponentProperty::TEXT_ALIGNMENT);
}
void ResetComponentFontProportional(const eHudComponent& component) noexcept override
{
ResetComponentFontData(component, eHudComponentProperty::TEXT_PROPORTIONAL);
}
CVector2D GetComponentPosition(const eHudComponent& component) const noexcept override;
CVector2D GetComponentSize(const eHudComponent& component) const noexcept override;
SColor GetComponentColor(const eHudComponent& component) const noexcept override;
SColor GetComponentSecondaryColor(const eHudComponent& component) const noexcept override;
SColor GetComponentFontDropColor(const eHudComponent& component) const override;
bool GetComponentDrawBlackBorder(const eHudComponent& component) const noexcept override { return GetHudComponentRef(component).drawBlackBorder; }
bool GetComponentDrawPercentage(const eHudComponent& component) const noexcept override { return GetHudComponentRef(component).drawPercentage; }
float GetHealthBarBlinkingValue(const eHudComponent& component) const noexcept override { return CHudSA::blinkingBarHPValue; }
float GetComponentFontOutline(const eHudComponent& component) const override { return CFontSA::GetEdge(); }
float GetComponentFontShadow(const eHudComponent& component) const override { return CFontSA::GetDropdownShadow(); }
eFontStyle GetComponentFontStyle(const eHudComponent& component) const override { return CFontSA::GetFontStyle(); }
eFontAlignment GetComponentFontAlignment(const eHudComponent& component) const override { return CFontSA::GetOrientation(); }
bool GetComponentFontProportional(const eHudComponent& component) const override { return CFontSA::GetProportional(); }
bool GetComponentUseCustomAlpha(const eHudComponent& component) const noexcept override { return GetHudComponentRef(component).useCustomAlpha; }
CVector2D GetComponentTextSize(const eHudComponent& component) const override;
static RsGlobal* GetRSGlobal() noexcept { return rsGlobal; }
static RwColor GetHUDColour(const eHudColour& colour) noexcept;
static void StaticSetHooks();
static void RenderHealthBar(int x, int y);
static void RenderBreathBar(int x, int y);
static void RenderArmorBar(int x, int y);
private:
void InitComponentList();
void UpdateStreetchCalculations();
void ResetComponent(SComponentPlacement& placement, bool resetSize) noexcept;
void ResetComponentFontData(const eHudComponent& component, const eHudComponentProperty& property) noexcept;
SHudComponentData& GetHudComponentRef(const eHudComponent& component) const noexcept;
static void RenderText(float x, float y, const char* text, SHudComponentData& properties, bool useSecondColor = false, bool drawFromBottom = false,
bool scaleForLanguage = false);
static void RenderClock(float x, float y, const char* strTime);
static void RenderMoney(float x, float y, const char* strMoney);
static void RenderAmmo(float x, float y, const char* strAmmo);
static void RenderVehicleName(float x, float y, const char* vehName);
static void RenderZoneName(float x, float y, const char* strArea);
static void RenderRadioName(float x, float y, const char* strRadio);
static void __fastcall RenderWeaponIcon_Sprite(void* sprite, void*, CRect* rect, RwColor* color);
static void RenderWeaponIcon_XLU(CVector pos, CVector2D halfSize, std::uint8_t r, std::uint8_t g, std::uint8_t b, std::uint16_t intensity, float rhw,
std::uint8_t a, std::uint8_t uDir, std::uint8_t vDir);
static void RenderWanted(bool empty, float x, float y, const char* strLevel);
static void __fastcall RenderCircleCrosshair(void* sprite, void*, CRect* rect, RwColor* color);
static void RenderRocketCrosshair(CVector pos, CVector2D halfSize, std::uint8_t r, std::uint8_t g, std::uint8_t b, std::uint16_t intensity, float rhw,
std::uint8_t a, std::uint8_t uDir, std::uint8_t vDir);
private:
std::map<eHudComponent, SHudComponent> m_HudComponentMap;
float* m_pfAspectRatioMultiplicator;
float* m_pfCameraCrosshairScale;
float m_fSniperCrosshairScale;
static RsGlobal* rsGlobal;
static std::int16_t* itemToFlash;
static float calcStreetchX;
static float calcStreetchY;
static float blinkingBarHPValue;
};