Skip to content

Commit fa52cb9

Browse files
Merge pull request #275 from MiranDMC/GTA2_CHud_updates
GTA2 hud updates
2 parents 72a7130 + 1e45019 commit fa52cb9

File tree

2 files changed

+57
-20
lines changed

2 files changed

+57
-20
lines changed

plugin_II/game_II/CHud.cpp

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
*/
77

88
#include "CHud.h"
9+
#include <algorithm>
10+
#include <string.h>
911

1012
CHud** gHud = (CHud**)0x672F40;
1113

@@ -29,14 +31,35 @@ void CHud::DrawSprite(int id1, int id2, int x, int y, char style, int const& mod
2931
plugin::CallStd<0x4C71B0, int, int, int, int, char, int const&, int, int, char>(id1, id2, x, y, style, mode, enableAlpha, alpha, unk);
3032
}
3133

32-
void CHudMessage::SetHudMessage(const wchar_t* str, int priority) {
33-
plugin::CallMethod<0x4C6060>(this, str, priority);
34+
void CHudMessage::SetHudMessage(const char* text, eMessagePriority priority) {
35+
_SWSTRING_STATIC_INIT(1); _SWSTRING_STATIC_FROM(1, text);
36+
SetHudMessage(_SWSTRING_STATIC(1), priority);
3437
}
3538

36-
void CHudBrief::SetHudBrief(int priority, const char* str) {
37-
plugin::CallMethod<0x4C6750>(this, priority, str);
39+
void CHudMessage::SetHudMessage(const wchar_t* text, eMessagePriority priority) {
40+
plugin::CallMethod<0x4C6060>(this, text, priority);
3841
}
3942

40-
void CHudBrief::Clear(int priority) {
43+
void CHudBrief::SetHudBrief(eMessagePriority priority, const char* gxt, unsigned int timeout) {
44+
plugin::CallMethod<0x4C6690>(this, priority, gxt, timeout);
45+
}
46+
47+
void CHudBrief::SetHudBriefStr(const char* text, short time) {
48+
_SWSTRING_STATIC_INIT(1); _SWSTRING_STATIC_FROM(1, text);
49+
SetHudBriefStr(_SWSTRING_STATIC(1), time);
50+
}
51+
52+
void CHudBrief::SetHudBriefStr(const wchar_t* text, short time) {
53+
SetHudBrief(eMessagePriority::MESSAGE_DISPLAY_NOW, "", -1);
54+
55+
wcscpy_s(this->text, text);
56+
length = wcslen(this->text);
57+
lines = 1 + std::count_if(this->text, this->text + length, [](auto ch){ return ch == L'\n'; });
58+
59+
if (time == 0) time = length * GetHud()->m_nTextSpeed; // automatic
60+
displayTime = time;
61+
}
62+
63+
void CHudBrief::Clear(eMessagePriority priority) {
4164
plugin::CallMethod<0x4C6860>(this, priority);
4265
}

plugin_II/game_II/CHud.h

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -32,30 +32,44 @@ enum eArrowType {
3232
TYPE_GREEN,
3333
};
3434

35-
enum eMessagePriority {
35+
enum eMessagePriority : int {
3636
MESSAGE_DISPLAY_NONE,
3737
MESSAGE_DISPLAY_DEFAULT = 1,
3838
MESSAGE_DISPLAY_SOON = 2,
3939
MESSAGE_DISPLAY_NOW = 3,
4040
};
4141

42+
#pragma pack(push, 1)
4243
class CHudBrief {
4344
public:
44-
wchar_t str[640];
45-
char field_641[36];
46-
int* field_642;
47-
char field_646[452];
48-
char field_647[12];
49-
CHudBrief* prev;
50-
int field_652;
51-
char* field_653;
45+
wchar_t text[161];
46+
int field_142;
47+
char field_146[120];
48+
int** field_1BE;
49+
char field_1C2[832];
50+
char field_502;
51+
char field_503; // pad?
52+
short displayTime; // render frames
53+
short field_506; // pad?
54+
int lines; // row count
55+
int field_50C;
56+
int length; // characters
57+
int* field_514;
58+
char gxt[8];
59+
char field_520[472];
60+
CHudBrief* prev; // TODO: is this still member of that struct?
61+
int field_6FC; // TODO: is this still member of that struct?
62+
char* field_700; // TODO: is this still member of that struct?
5263

5364
public:
54-
void SetHudBrief(int priority, const char* str);
55-
void Clear(int priority);
56-
};
65+
void SetHudBrief(eMessagePriority priority, const char* gxt, unsigned int timeout = -1); // GXT label
66+
void SetHudBriefStr(const char* text, short time = 0);
67+
void SetHudBriefStr(const wchar_t* text, short time = 0);
5768

58-
VALIDATE_SIZE(CHudBrief, 0x704);
69+
void Clear(eMessagePriority priority);
70+
};
71+
#pragma pack(pop)
72+
VALIDATE_SIZE(CHudBrief, 0x704); // TODO: possibly should be smaller
5973

6074
class CHudMessage {
6175
char m_nTimeToShow;
@@ -66,7 +80,8 @@ class CHudMessage {
6680
int m_nType;
6781

6882
public:
69-
void SetHudMessage(const wchar_t* str, int priority);
83+
void SetHudMessage(const char* text, eMessagePriority priority);
84+
void SetHudMessage(const wchar_t* text, eMessagePriority priority);
7085
};
7186

7287
VALIDATE_SIZE(CHudMessage, 0x1C8);
@@ -173,7 +188,6 @@ class CHud {
173188
public:
174189
static void DrawSprite(int id1, int id2, int x, int y, char style, int const& mode, int enableAlpha, int alpha, char unk);
175190
};
176-
177191
VALIDATE_SIZE(CHud, 0x2AF8);
178192

179193
extern CHud** gHud;

0 commit comments

Comments
 (0)