Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 28 additions & 5 deletions plugin_II/game_II/CHud.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
*/

#include "CHud.h"
#include <algorithm>
#include <string.h>

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

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

void CHudMessage::SetHudMessage(const wchar_t* str, int priority) {
plugin::CallMethod<0x4C6060>(this, str, priority);
void CHudMessage::SetHudMessage(const char* text, eMessagePriority priority) {
_SWSTRING_STATIC_INIT(1); _SWSTRING_STATIC_FROM(1, text);
SetHudMessage(_SWSTRING_STATIC(1), priority);
}

void CHudBrief::SetHudBrief(int priority, const char* str) {
plugin::CallMethod<0x4C6750>(this, priority, str);
void CHudMessage::SetHudMessage(const wchar_t* text, eMessagePriority priority) {
plugin::CallMethod<0x4C6060>(this, text, priority);
}

void CHudBrief::Clear(int priority) {
void CHudBrief::SetHudBrief(eMessagePriority priority, const char* gxt, unsigned int timeout) {
plugin::CallMethod<0x4C6690>(this, priority, gxt, timeout);
}

void CHudBrief::SetHudBriefStr(const char* text, short time) {
_SWSTRING_STATIC_INIT(1); _SWSTRING_STATIC_FROM(1, text);
SetHudBriefStr(_SWSTRING_STATIC(1), time);
}

void CHudBrief::SetHudBriefStr(const wchar_t* text, short time) {
SetHudBrief(eMessagePriority::MESSAGE_DISPLAY_NOW, "", -1);

wcscpy_s(this->text, text);
length = wcslen(this->text);
lines = 1 + std::count_if(this->text, this->text + length, [](auto ch){ return ch == L'\n'; });

if (time == 0) time = length * GetHud()->m_nTextSpeed; // automatic
displayTime = time;
}

void CHudBrief::Clear(eMessagePriority priority) {
plugin::CallMethod<0x4C6860>(this, priority);
}
44 changes: 29 additions & 15 deletions plugin_II/game_II/CHud.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,30 +32,44 @@ enum eArrowType {
TYPE_GREEN,
};

enum eMessagePriority {
enum eMessagePriority : int {
MESSAGE_DISPLAY_NONE,
MESSAGE_DISPLAY_DEFAULT = 1,
MESSAGE_DISPLAY_SOON = 2,
MESSAGE_DISPLAY_NOW = 3,
};

#pragma pack(push, 1)
class CHudBrief {
public:
wchar_t str[640];
char field_641[36];
int* field_642;
char field_646[452];
char field_647[12];
CHudBrief* prev;
int field_652;
char* field_653;
wchar_t text[161];
int field_142;
char field_146[120];
int** field_1BE;
char field_1C2[832];
char field_502;
char field_503; // pad?
short displayTime; // render frames
short field_506; // pad?
int lines; // row count
int field_50C;
int length; // characters
int* field_514;
char gxt[8];
char field_520[472];
CHudBrief* prev; // TODO: is this still member of that struct?
int field_6FC; // TODO: is this still member of that struct?
char* field_700; // TODO: is this still member of that struct?

public:
void SetHudBrief(int priority, const char* str);
void Clear(int priority);
};
void SetHudBrief(eMessagePriority priority, const char* gxt, unsigned int timeout = -1); // GXT label
void SetHudBriefStr(const char* text, short time = 0);
void SetHudBriefStr(const wchar_t* text, short time = 0);

VALIDATE_SIZE(CHudBrief, 0x704);
void Clear(eMessagePriority priority);
};
#pragma pack(pop)
VALIDATE_SIZE(CHudBrief, 0x704); // TODO: possibly should be smaller

class CHudMessage {
char m_nTimeToShow;
Expand All @@ -66,7 +80,8 @@ class CHudMessage {
int m_nType;

public:
void SetHudMessage(const wchar_t* str, int priority);
void SetHudMessage(const char* text, eMessagePriority priority);
void SetHudMessage(const wchar_t* text, eMessagePriority priority);
};

VALIDATE_SIZE(CHudMessage, 0x1C8);
Expand Down Expand Up @@ -173,7 +188,6 @@ class CHud {
public:
static void DrawSprite(int id1, int id2, int x, int y, char style, int const& mode, int enableAlpha, int alpha, char unk);
};

VALIDATE_SIZE(CHud, 0x2AF8);

extern CHud** gHud;
Expand Down