-
Notifications
You must be signed in to change notification settings - Fork 2
/
sourcechat.h
179 lines (137 loc) · 4.5 KB
/
sourcechat.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
#ifndef SOURCECHAT_H
#define SOURCECHAT_H
#endif
#ifdef _WIN32
#pragma once
#endif
#define IMGUI_USE_SDL ( 1 )
#define IMGUI_USE_GL3 ( 1 )
#define CHAT_HISTORY_BUFFER_SIZE ( 8192 )
#define CHAT_INPUT_BUFFER_SIZE ( 128 )
#include <messagebuffer.h>
#include <base_feature.h>
#include <IDetoursAPI.h>
#include <imgui.h>
#include "public/ISourceChat.h"
//-----------------------------------------------------------------------------
// Forward declarations
//-----------------------------------------------------------------------------
FUNC_SIGNATURE( float *, __cdecl, GetClientColorFn, int client );
FUNC_SIGNATURE( void, __thiscall, CClient_SoundEngine__Play2DSoundFn, void *thisptr, const char *sound, float volume );
FUNC_SIGNATURE( void *, __cdecl, GetClientVoiceMgrFn );
FUNC_SIGNATURE( bool, __thiscall, CVoiceStatus__IsPlayerBlockedFn, void *thisptr, int index );
#if IMGUI_USE_SDL
struct SDL_Window;
typedef union SDL_Event SDL_Event;
#endif
//-----------------------------------------------------------------------------
// Source chat
//-----------------------------------------------------------------------------
class CSourceChat : public CBaseFeature, ISourceChat
{
public:
CSourceChat();
// ISourceChat interface
virtual bool IsOpened( void ) override;
virtual bool IsTeamChat( void ) override;
virtual void Clear( void ) override;
// CBaseFeature abstract class
virtual bool Load( void ) override;
virtual void PostLoad( void ) override;
virtual void Unload( void ) override;
public:
// Callbacks
void OnEnterToServer();
void OnDisconnect();
void Draw( void );
void FadeThink( void );
void PrintMessage( int client, const char *pszMessage, int src );
void SendMessageFromChat( void );
char *PushMessageToBuffer( char *buffer, int maxsize, const char *msg, int *shift_quantity );
private:
void AddTextColor( const char *pszTextPos, float *pflColor );
void ApplyShiftQuantityToTextColor( int shiftQuantity );
void RemoveInvalidTextColor( void );
void AddTextOpacity( const char *pszTextPos, float flTime );
void ApplyShiftQuantityToTextOpacity( int shiftQuantity );
void RemoveInvalidTextOpacity( void );
void DrawKeyCodes( void );
void DrawTextHistory( void );
void DrawInputLineName( void );
void DrawInputLine( void );
void DrawKeyboardLayout( const char *pszLayoutName );
public:
#if IMGUI_USE_SDL
void InitImGui( SDL_Window *window );
#else
void InitImGui( HDC hdc );
#endif
void InitStyle( void );
void InitFont( void );
void OnOpen( bool bTeamChat );
void OnClose( void );
#if !IMGUI_USE_SDL
inline WNDPROC GetGameWindowProc( void ) const { return m_hGameWndProc; };
#endif
float GetTime() const;
inline bool IsOpened_Internal( void ) const { return m_bOpened; };
inline bool IsTeamChat_Internal( void ) const { return m_bTeamChat; };
inline void SetOpened_Internal( bool bOpened ) { m_bOpened = bOpened; };
inline void SetTeamChat_Internal( bool bTeamChat ) { m_bTeamChat = bTeamChat; };
private:
#if !IMGUI_USE_SDL
HWND m_hGameWnd;
WNDPROC m_hGameWndProc;
#endif
float m_flWindowWidth;
float m_flWindowHeight;
char m_szInputBuffer[ CHAT_INPUT_BUFFER_SIZE ];
char m_szHistoryBuffer[ CHAT_HISTORY_BUFFER_SIZE ];
bool m_bOpened;
bool m_bWasOpenedRightNow;
bool m_bTeamChat;
bool m_bCalcTextHistoryHeight;
float m_flOpenTime;
float m_flCloseTime;
float m_flCurrentTime;
float m_flTextHistoryHeight;
float m_flTextHistoryDefaultColor[3];
ImVector<ImTextColorStyle> m_ColorfulTextStyle;
ImVector<ImTextOpacity> m_TextOpacity;
ImFont *m_pFont;
ImFont *m_pFontBitmap;
ImFont *m_pFontSmall;
cvar_t *hud_draw;
GetClientColorFn m_pfnGetClientColor;
CClient_SoundEngine__Play2DSoundFn m_pfnCClient_SoundEngine__Play2DSound;
GetClientVoiceMgrFn m_pfnGetClientVoiceMgr;
CVoiceStatus__IsPlayerBlockedFn m_pfnCVoiceStatus__IsPlayerBlocked;
void **m_pSoundEngine;
double *m_dbRealtime;
// Detour members
void *m_pfnKey_Event;
void *m_pfnIN_Move;
void *m_pfnCHudTextMessage__MsgFunc_TextMsg;
#if IMGUI_USE_SDL
void *m_pfnSDL_PollEvent;
void *m_pfnSDL_GL_SwapWindow;
#else
void *m_pfnwglSwapBuffers;
#endif
void *m_pfnSetCursorPos;
DetourHandle_t m_hKey_Event;
DetourHandle_t m_hIN_Move;
DetourHandle_t m_hMessageMode;
DetourHandle_t m_hMessageMode2;
DetourHandle_t m_hUserMsgHook_SayText;
DetourHandle_t m_hUserMsgHook_TextMsg;
DetourHandle_t m_hNetMsgHook_TempEntity;
#if IMGUI_USE_SDL
DetourHandle_t m_hSDL_PollEvent;
DetourHandle_t m_hSDL_GL_SwapWindow;
#else
DetourHandle_t m_hwglSwapBuffers;
#endif
DetourHandle_t m_hSetCursorPos;
};
extern CSourceChat g_SourceChat;