Skip to content

Commit 4ae354e

Browse files
committed
Review
1 parent 5546c04 commit 4ae354e

File tree

10 files changed

+69
-142
lines changed

10 files changed

+69
-142
lines changed

Client/game_sa/CFontSA.cpp

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -15,25 +15,25 @@
1515
void CFontSA::PrintChar(float x, float y, char character)
1616
{
1717
// Call CFont::PrintChar
18-
((void(_cdecl*)(float, float, char))FUNC_CFont_PrintChar)(x, y, character);
18+
((void(_cdecl*)(float, float, char))0x718A10)(x, y, character);
1919
}
2020

2121
void CFontSA::PrintString(float x, float y, const char* text)
2222
{
2323
// Call CFont::PrintString
24-
((void(__cdecl*)(float, float, const char*))FUNC_CFont_PrintString)(x, y, text);
24+
((void(__cdecl*)(float, float, const char*))0x71A700)(x, y, text);
2525
}
2626

2727
void CFontSA::PrintStringFromBottom(float x, float y, const char* text)
2828
{
2929
// Call CFont::PrintStringFromBottom
30-
((void(__cdecl*)(float, float, const char*))FUNC_CFont_PrintStringFromBottom)(x, y, text);
30+
((void(__cdecl*)(float, float, const char*))0x71A820)(x, y, text);
3131
}
3232

3333
void CFontSA::SetScale(float w, float h)
3434
{
3535
// Call CFont::SetScale
36-
((void(__cdecl*)(float, float))FUNC_CFont_SetScale)(w, h);
36+
((void(__cdecl*)(float, float))0x719380)(w, h);
3737
}
3838

3939
void CFontSA::SetScale(const CVector2D& scale)
@@ -44,109 +44,109 @@ void CFontSA::SetScale(const CVector2D& scale)
4444
void CFontSA::SetScaleForCurrentLanguage(float w, float h)
4545
{
4646
// Call CFont::SetScaleForCurrentLanguage
47-
((void(__cdecl*)(float, float))FUNC_CFont_SetScaleForCurrentLanguage)(w, h);
47+
((void(__cdecl*)(float, float))0x7193A0)(w, h);
4848
}
4949

5050
void CFontSA::SetSlantRefPoint(float x, float y)
5151
{
5252
// Call CFont::SetSlantRefPoint
53-
((void(__cdecl*)(float, float))FUNC_CFont_SetSlantRefPoint)(x, y);
53+
((void(__cdecl*)(float, float))0x719400)(x, y);
5454
}
5555

5656
void CFontSA::SetSlant(float slant)
5757
{
5858
// Call CFont::SetSlant
59-
((void(__cdecl*)(float))FUNC_CFont_SetSlant)(slant);
59+
((void(__cdecl*)(float))0x719420)(slant);
6060
}
6161

6262
void CFontSA::SetColor(const RwColor& color)
6363
{
6464
// Call CFont::SetColor
65-
((void(__cdecl*)(RwColor))FUNC_CFont_SetColor)(color);
65+
((void(__cdecl*)(RwColor))0x719430)(color);
6666
}
6767

6868
void CFontSA::SetDropColor(const RwColor& color)
6969
{
7070
// Call CFont::SetDropColor
71-
((void(__cdecl*)(RwColor))FUNC_CFont_SetDropColor)(color);
71+
((void(__cdecl*)(RwColor))0x719510)(color);
7272
}
7373

7474
void CFontSA::SetFontStyle(const eFontStyle& style)
7575
{
7676
// Call CFont::SetFontStyle
77-
((void(__cdecl*)(eFontStyle))FUNC_CFont_SetStyle)(style);
77+
((void(__cdecl*)(eFontStyle))0x719490)(style);
7878
}
7979

8080
void CFontSA::SetWrapX(float wrapx)
8181
{
8282
// Call CFont::SetWrapx
83-
((void(__cdecl*)(float))FUNC_CFont_SetWrapX)(wrapx);
83+
((void(__cdecl*)(float))0x7194D0)(wrapx);
8484
}
8585

8686
void CFontSA::SetRightJustifyWrap(float wrap)
8787
{
8888
// Call CFont::SetRightJustifyWrap
89-
((void(__cdecl*)(float))FUNC_CFont_SetRightJustifyWrap)(wrap);
89+
((void(__cdecl*)(float))0x7194F0)(wrap);
9090
}
9191

9292
void CFontSA::SetCentreSize(float size)
9393
{
9494
// Call CFont::SetCentreSize
95-
((void(__cdecl*)(float))FUNC_CFont_SetCentreSize)(size);
95+
((void(__cdecl*)(float))0x7194E0)(size);
9696
}
9797

9898
void CFontSA::SetDropShadowPosition(std::int16_t offset)
9999
{
100100
// Call CFont::SetDropShadowPosition
101-
((void(__cdecl*)(std::int16_t))FUNC_CFont_SetDropShadowPosition)(offset);
101+
((void(__cdecl*)(std::int16_t))0x719570)(offset);
102102
}
103103

104104
void CFontSA::SetEdge(std::int16_t edgeSize)
105105
{
106106
// Call CFont::SetEdge
107-
((void(__cdecl*)(std::int16_t))FUNC_CFont_SetEdge)(edgeSize);
107+
((void(__cdecl*)(std::int16_t))0x719590)(edgeSize);
108108
}
109109

110110
void CFontSA::SetProportional(bool enable)
111111
{
112112
// Call CFont::SetProportional
113-
((void(__cdecl*)(bool))FUNC_CFont_SetProportional)(enable);
113+
((void(__cdecl*)(bool))0x7195B0)(enable);
114114
}
115115

116116
void CFontSA::SetBackground(bool enable, bool includeWrap)
117117
{
118118
// Call CFont::SetBackground
119-
((void(__cdecl*)(bool, bool))FUNC_CFont_SetBackground)(enable, includeWrap);
119+
((void(__cdecl*)(bool, bool))0x7195C0)(enable, includeWrap);
120120
}
121121

122122
void CFontSA::SetBackgroundColor(const RwColor& color)
123123
{
124124
// Call CFont::SetBackgroundColor
125-
((void(__cdecl*)(RwColor))FUNC_CFont_SetBackgroundColor)(color);
125+
((void(__cdecl*)(RwColor))0x7195E0)(color);
126126
}
127127

128128
void CFontSA::SetJustify(bool enable)
129129
{
130130
// Call CFont::SetJustify
131-
((void(__cdecl*)(bool))FUNC_CFont_SetJustify)(enable);
131+
((void(__cdecl*)(bool))0x719600)(enable);
132132
}
133133

134134
void CFontSA::SetOrientation(const eFontAlignment& alignment)
135135
{
136136
// Call CFont::SetOrientation
137-
((void(__cdecl*)(eFontAlignment))FUNC_CFont_SetOrientation)(alignment);
137+
((void(__cdecl*)(eFontAlignment))0x719610)(alignment);
138138
}
139139

140140
float CFontSA::GetStringWidth(const char* string, bool spaces, bool scriptValues)
141141
{
142142
// Call CFont::GetStringWidth
143-
return ((float(__cdecl*)(const char*, bool, bool))FUNC_CFont_GetStringWidth)(string, spaces, scriptValues);
143+
return ((float(__cdecl*)(const char*, bool, bool))0x71A0E0)(string, spaces, scriptValues);
144144
}
145145

146146
std::int16_t CFontSA::GetNumberLines(float x, float y, const char* text)
147147
{
148148
// Call CFont::GetNumberLines
149-
return ((std::int16_t(__cdecl*)(float, float, const char*))FUNC_CFont_GetNumberLines)(x, y, text);
149+
return ((std::int16_t(__cdecl*)(float, float, const char*))0x71A5E0)(x, y, text);
150150
}
151151

152152
float CFontSA::GetFontHeight(float scaleY)

Client/game_sa/CFontSA.h

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -14,39 +14,6 @@
1414
#include <game/RenderWare.h>
1515
#include <game/CHud.h>
1616

17-
#define FUNC_CFont_PrintChar 0x718A10
18-
#define FUNC_CFont_PrintString 0x71A700
19-
#define FUNC_CFont_PrintStringFromBottom 0x71A820
20-
21-
#define FUNC_CFont_SetScale 0x719380
22-
#define FUNC_CFont_SetScaleForCurrentLanguage 0x7193A0
23-
24-
#define FUNC_CFont_SetSlantRefPoint 0x719400
25-
#define FUNC_CFont_SetSlant 0x719420
26-
27-
#define FUNC_CFont_SetStyle 0x719490
28-
#define FUNC_CFont_SetCentreSize 0x7194E0
29-
30-
#define FUNC_CFont_SetWrapX 0x7194D0
31-
#define FUNC_CFont_SetRightJustifyWrap 0x7194F0
32-
33-
#define FUNC_CFont_SetColor 0x719430
34-
#define FUNC_CFont_SetDropColor 0x719510
35-
36-
#define FUNC_CFont_SetDropShadowPosition 0x719570
37-
#define FUNC_CFont_SetEdge 0x719590
38-
39-
#define FUNC_CFont_SetProportional 0x7195B0
40-
41-
#define FUNC_CFont_SetBackground 0x7195C0
42-
#define FUNC_CFont_SetBackgroundColor 0x7195E0
43-
44-
#define FUNC_CFont_SetJustify 0x719600
45-
#define FUNC_CFont_SetOrientation 0x719610
46-
47-
#define FUNC_CFont_GetStringWidth 0x71A0E0
48-
#define FUNC_CFont_GetNumberLines 0x71A5E0
49-
5017
#define VAR_CFont_Scale 0xC71A64
5118
#define VAR_CFont_Color 0xC71A60
5219

Client/game_sa/CHudSA.cpp

Lines changed: 23 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ DrawBarChartFunc DrawBarChart = reinterpret_cast<DrawBarChartFunc>(FUNC_CSprite2
4141
std::unordered_map<eHudComponent, SHudComponentData> defaultComponentProperties = {
4242
{HUD_HEALTH, {CHudSA::GetHUDColour(eHudColour::RED)}},
4343
{HUD_BREATH, {CHudSA::GetHUDColour(eHudColour::LIGHT_BLUE)}},
44+
{HUD_ARMOUR, {CHudSA::GetHUDColour(eHudColour::LIGHT_GRAY)}},
4445
{HUD_CLOCK, {CHudSA::GetHUDColour(eHudColour::LIGHT_GRAY), {}, false, false, COLOR_BLACK, eFontAlignment::ALIGN_RIGHT, eFontStyle::FONT_PRICEDOWN, 2}},
4546
{HUD_MONEY, {CHudSA::GetHUDColour(eHudColour::GREEN), CHudSA::GetHUDColour(eHudColour::RED), false, false, COLOR_BLACK, eFontAlignment::ALIGN_RIGHT, eFontStyle::FONT_PRICEDOWN, 2}},
4647
{HUD_AMMO, {CHudSA::GetHUDColour(eHudColour::LIGHT_BLUE), {}, false, false, COLOR_BLACK, eFontAlignment::ALIGN_CENTER, eFontStyle::FONT_SUBTITLES, 1, 0, true}},
@@ -543,7 +544,7 @@ void CHudSA::SetComponentColor(const eHudComponent& component, std::uint32_t col
543544
if (!secondColor)
544545
compRef.fillColor = RwColor{newColor.R, newColor.G, newColor.B, newColor.A};
545546
else
546-
compRef.fillColor_Second = RwColor{newColor.R, newColor.G, newColor.B, newColor.A};
547+
compRef.fillColorSecondary = RwColor{newColor.R, newColor.G, newColor.B, newColor.A};
547548
}
548549

549550
void CHudSA::ResetComponentColor(const eHudComponent& component, bool secondColor) noexcept
@@ -557,7 +558,7 @@ void CHudSA::ResetComponentColor(const eHudComponent& component, bool secondColo
557558
if (!secondColor)
558559
componentData.fillColor = defaultRef.fillColor;
559560
else
560-
componentData.fillColor_Second = defaultRef.fillColor_Second;
561+
componentData.fillColorSecondary = defaultRef.fillColorSecondary;
561562
}
562563

563564
void CHudSA::SetComponentFontDropColor(const eHudComponent& component, std::uint32_t color) noexcept
@@ -592,10 +593,10 @@ SColor CHudSA::GetComponentColor(const eHudComponent& component) const noexcept
592593
return SColorRGBA(ref.fillColor.r, ref.fillColor.g, ref.fillColor.b, ref.fillColor.a);
593594
}
594595

595-
SColor CHudSA::GetComponentSecondColor(const eHudComponent& component) const noexcept
596+
SColor CHudSA::GetComponentSecondaryColor(const eHudComponent& component) const noexcept
596597
{
597598
const auto& ref = GetHudComponentRef(component);
598-
return SColorRGBA(ref.fillColor_Second.r, ref.fillColor_Second.g, ref.fillColor_Second.b, ref.fillColor_Second.a);
599+
return SColorRGBA(ref.fillColorSecondary.r, ref.fillColorSecondary.g, ref.fillColorSecondary.b, ref.fillColorSecondary.a);
599600
}
600601

601602
SColor CHudSA::GetComponentFontDropColor(const eHudComponent& component) const
@@ -741,12 +742,12 @@ void CHudSA::RenderText(float x, float y, const char* text, SHudComponentData& p
741742
if (!properties.useCustomAlpha)
742743
{
743744
CFontSA::SetDropColor(RwColor{properties.dropColor.r, properties.dropColor.g, properties.dropColor.b, CFontSA::GetColor().a});
744-
CFontSA::SetColor(useSecondColor ? RwColor{properties.fillColor_Second.r, properties.fillColor_Second.g, properties.fillColor_Second.b, CFontSA::GetColor().a} : RwColor{properties.fillColor.r, properties.fillColor.g, properties.fillColor.b, CFontSA::GetColor().a});
745+
CFontSA::SetColor(useSecondColor ? RwColor{properties.fillColorSecondary.r, properties.fillColorSecondary.g, properties.fillColorSecondary.b, CFontSA::GetColor().a} : RwColor{properties.fillColor.r, properties.fillColor.g, properties.fillColor.b, CFontSA::GetColor().a});
745746
}
746747
else
747748
{
748749
CFontSA::SetDropColor(properties.dropColor);
749-
CFontSA::SetColor(useSecondColor ? properties.fillColor_Second : properties.fillColor);
750+
CFontSA::SetColor(useSecondColor ? properties.fillColorSecondary : properties.fillColor);
750751
}
751752

752753
// Save default position once
@@ -828,12 +829,12 @@ void __fastcall CHudSA::RenderWeaponIcon_Sprite(void* sprite, void*, CRect* rect
828829
rect->bottom = rect->top + (useCustomSize ? properties.placement.customHeight : properties.placement.height);
829830
}
830831

831-
color->r = properties.fillColor_Second.r;
832-
color->g = properties.fillColor_Second.g;
833-
color->b = properties.fillColor_Second.b;
832+
color->r = properties.fillColorSecondary.r;
833+
color->g = properties.fillColorSecondary.g;
834+
color->b = properties.fillColorSecondary.b;
834835

835836
if (properties.useCustomAlpha)
836-
color->a = properties.fillColor_Second.a;
837+
color->a = properties.fillColorSecondary.a;
837838

838839
// Call CSprite2d::Draw
839840
((void(__thiscall*)(void*, CRect*, RwColor*))FUNC_CSprie2d_Draw)(sprite, rect, color);
@@ -888,8 +889,8 @@ void CHudSA::RenderWanted(bool empty, float x, float y, const char* strLevel)
888889
RenderText(x, y, strLevel, componentProperties.wanted, empty);
889890
}
890891

891-
static constexpr DWORD back = 0x58DFD8;
892-
static void _declspec(naked) RenderWanted_Hook()
892+
static constexpr std::uintptr_t CONTINUE_RenderWanted = 0x58DFD8;
893+
static void _declspec(naked) HOOK_RenderWanted()
893894
{
894895
_asm
895896
{
@@ -906,58 +907,19 @@ static void _declspec(naked) RenderWanted_Hook()
906907
call CHudSA::RenderWanted
907908
add esp,4
908909

909-
jmp back
910+
jmp CONTINUE_RenderWanted
910911
}
911912
}
912913

913-
static void _declspec(naked) HOOK_RenderHudBar()
914+
static void HOOK_RenderHudBar(int playerId, int x, int y)
914915
{
915-
_asm
916-
{
917-
mov eax, [esp]
918-
919-
push [esp+0Ch] // y
920-
push [esp+0Ch] // x
921-
922-
// Health bar
923-
cmp eax, 0058EE9Fh
924-
jz renderHealthBar
925-
926-
cmp eax, 0058EF12h
927-
jz renderHealthBar
928-
929-
// Breath bar
930-
cmp eax, 0058F136h
931-
jz renderBreathBar
932-
933-
cmp eax, 0058F1B2h
934-
jz renderBreathBar
935-
936-
// Armor bar
937-
cmp eax, 0058EF70h
938-
jz renderArmorBar
939-
940-
cmp eax, 0058EFE3h
941-
jz renderArmorBar
942-
943-
jmp skip
944-
945-
renderHealthBar:
946-
call CHudSA::RenderHealthBar
947-
jmp skip
948-
949-
renderBreathBar:
950-
call CHudSA::RenderBreathBar
951-
jmp skip
952-
953-
renderArmorBar:
954-
call CHudSA::RenderArmorBar
955-
jmp skip
956-
957-
skip:
958-
add esp, 8
959-
retn
960-
}
916+
void* returnAdress = _ReturnAddress();
917+
if (returnAdress == (void*)0x58EE9F || returnAdress == (void*)0x58EF12)
918+
CHudSA::RenderHealthBar(x, y);
919+
else if (returnAdress == (void*)0x58F136 || returnAdress == (void*)0x58F1B2)
920+
CHudSA::RenderBreathBar(x, y);
921+
else if (returnAdress == (void*)0x58EF70 || returnAdress == (void*)0x58EFE3)
922+
CHudSA::RenderArmorBar(x, y);
961923
}
962924

963925
void CHudSA::StaticSetHooks()
@@ -977,5 +939,5 @@ void CHudSA::StaticSetHooks()
977939
HookInstallCall(0x58D988, (DWORD)&RenderWeaponIcon_Sprite);
978940
HookInstallCall(0x58D8FD, (DWORD)&RenderWeaponIcon_XLU);
979941

980-
HookInstall(0x58DFD3, (DWORD)&RenderWanted_Hook);
942+
HookInstall(0x58DFD3, &HOOK_RenderWanted);
981943
}

0 commit comments

Comments
 (0)