13
13
using _Paint = int (__thiscall*)(void * thisptr);
14
14
using _ComputeSize = int (__thiscall*)(void * thisptr);
15
15
using _SetSize = int (__thiscall*)(void * thisptr, int wide , int tall);
16
+ using _ShouldDraw = bool (__thiscall*)(void * thisptr);
16
17
17
18
// client.dll
18
19
namespace Client
@@ -28,88 +29,114 @@ namespace Client
28
29
{
29
30
_Paint Paint;
30
31
_ComputeSize ComputeSize;
32
+ _ShouldDraw ShouldDraw;
31
33
}
32
34
33
35
namespace Detour
34
36
{
35
37
int __fastcall Paint (void * thisptr, int edx)
36
38
{
37
- int result = Original::Paint (thisptr);
39
+ int result = 0 ;
40
+
41
+ int m_hFont = *(int *)((uintptr_t )thisptr + Offsets::m_hFont);
42
+
43
+ int level = 0 ;
44
+ int offset = 2 ;
45
+ const int size = 10 ;
46
+ const int spacing = 4 ;
47
+
38
48
if (cl_showpos.GetBool ()) {
39
- int m_hFont = *(int *)((uintptr_t )thisptr + Offsets::m_hFont);
40
- const int start = 67 ;
41
- const int factor = 10 ;
42
- const int space = 4 ;
43
- int level = 0 ;
49
+ result = Original::Paint (thisptr);
50
+ offset = 67 ;
51
+ }
52
+
53
+ // Session
54
+ if (sar_draw_session.GetBool ()) {
55
+ int tick = (!*Engine::LoadGame) ? Engine::GetTick () : 0 ;
56
+ float time = tick * *Engine::IntervalPerTick;
44
57
45
- // Session
46
- if (sar_draw_session.GetBool ()) {
58
+ char session[64 ];
59
+ snprintf (session, sizeof (session), " session: %i (%.3f)" , tick, time );
60
+ Surface::Draw (m_hFont, 1 , offset + level * (size + spacing), COL_WHITE, session);
61
+ level++;
62
+ }
63
+ if (sar_draw_last_session.GetBool ()) {
64
+ char session[64 ];
65
+ snprintf (session, sizeof (session), " last session: %i (%.3f)" , Engine::LastSavedSession, Engine::LastSavedSession * *Engine::IntervalPerTick);
66
+ Surface::Draw (m_hFont, 1 , offset + level * (size + spacing), COL_WHITE, session);
67
+ level++;
68
+ }
69
+ if (sar_draw_sum.GetBool ()) {
70
+ char sum[64 ];
71
+ if (Summary::IsRunning && sar_sum_during_session.GetBool ()) {
47
72
int tick = (!*Engine::LoadGame) ? Engine::GetTick () : 0 ;
48
73
float time = tick * *Engine::IntervalPerTick;
49
-
50
- char session[64 ];
51
- snprintf (session, sizeof (session), " session: %i (%.3f)" , tick, time );
52
- Surface::Draw (m_hFont, 1 , start + level * (factor + level), COL_WHITE, session);
53
- level++;
74
+ snprintf (sum, sizeof (sum), " sum: %i (%.3f)" , Summary::TotalTicks + tick, Summary::TotalTime + time );
54
75
}
55
- if (sar_draw_sum.GetBool ()) {
56
- char sum[64 ];
57
- if (Summary::IsRunning && sar_sum_during_session.GetBool ()) {
58
- int tick = (!*Engine::LoadGame) ? Engine::GetTick () : 0 ;
59
- float time = tick * *Engine::IntervalPerTick;
60
- snprintf (sum, sizeof (sum), " sum: %i (%.3f)" , Summary::TotalTicks + tick, Summary::TotalTime + time );
61
- }
62
- else {
63
- snprintf (sum, sizeof (sum), " sum: %i (%.3f)" , Summary::TotalTicks, Summary::TotalTime);
64
- }
65
- Surface::Draw (m_hFont, 1 , start + level * (factor + level), COL_WHITE, sum);
66
- level++;
76
+ else {
77
+ snprintf (sum, sizeof (sum), " sum: %i (%.3f)" , Summary::TotalTicks, Summary::TotalTime);
67
78
}
68
- // Timer
69
- if (sar_draw_timer.GetBool ()) {
70
- int tick = Timer::GetTick ((Timer::IsRunning) ? Engine::GetTick () : -1 );
71
- float time = tick * *Engine::IntervalPerTick;
79
+ Surface::Draw (m_hFont, 1 , offset + level * (size + spacing), COL_WHITE, sum);
80
+ level++;
81
+ }
82
+ // Timer
83
+ if (sar_draw_timer.GetBool ()) {
84
+ int tick = Timer::GetTick ((Timer::IsRunning) ? Engine::GetTick () : -1 );
85
+ float time = tick * *Engine::IntervalPerTick;
72
86
73
- char timer[64 ];
74
- snprintf (timer, sizeof (timer), " timer: %i (%.3f)" , tick, time );
75
- Surface::Draw (m_hFont, 1 , start + level * (factor + level), COL_WHITE, timer);
76
- level++;
77
- }
78
- if (sar_draw_avg.GetBool ()) {
79
- char avg[64 ];
80
- snprintf (avg, sizeof (avg), " avg: %i (%.3f)" , Timer::Average::AverageTicks, Timer::Average::AverageTime);
81
- Surface::Draw (m_hFont, 1 , start + level * (factor + level), COL_WHITE, avg);
82
- level++;
87
+ char timer[64 ];
88
+ snprintf (timer, sizeof (timer), " timer: %i (%.3f)" , tick, time );
89
+ Surface::Draw (m_hFont, 1 , offset + level * (size + spacing), COL_WHITE, timer);
90
+ level++;
91
+ }
92
+ if (sar_draw_avg.GetBool ()) {
93
+ char avg[64 ];
94
+ snprintf (avg, sizeof (avg), " avg: %i (%.3f)" , Timer::Average::AverageTicks, Timer::Average::AverageTime);
95
+ Surface::Draw (m_hFont, 1 , offset + level * (size + spacing), COL_WHITE, avg);
96
+ level++;
97
+ }
98
+ if (sar_draw_cps.GetBool ()) {
99
+ char cps[64 ];
100
+ snprintf (cps, sizeof (cps), " last cp: %i (%.3f)" , Timer::CheckPoints::LatestTick, Timer::CheckPoints::LatestTime);
101
+ Surface::Draw (m_hFont, 1 , offset + level * (size + spacing), COL_WHITE, cps);
102
+ level++;
103
+ }
104
+ // Demo
105
+ if (sar_draw_demo.GetBool ()) {
106
+ char demo[64 ];
107
+ if (!*Engine::LoadGame && *DemoRecorder::Recording && !DemoRecorder::CurrentDemo.empty ()) {
108
+ int tick = DemoRecorder::GetTick ();
109
+ float time = tick * *Engine::IntervalPerTick;
110
+ snprintf (demo, sizeof (demo), " demo: %s %i (%.3f)" , DemoRecorder::CurrentDemo.c_str (), tick, time );
83
111
}
84
- if (sar_draw_cps. GetBool ()) {
85
- char cps[ 64 ] ;
86
- snprintf (cps, sizeof (cps), " last cp: %i (%.3f) " , Timer::CheckPoints::LatestTick, Timer::CheckPoints::LatestTime);
87
- Surface::Draw (m_hFont, 1 , start + level * (factor + level), COL_WHITE, cps) ;
88
- level++ ;
112
+ else if (!*Engine::LoadGame && DemoPlayer::IsPlaying ()) {
113
+ int tick = DemoPlayer::GetTick () ;
114
+ // Demos should overwrite interval_per_tick anyway if I remember correctly
115
+ float time = tick * *Engine::IntervalPerTick ;
116
+ snprintf (demo, sizeof (demo), " demo: %s %i (%.3f) " , DemoPlayer::DemoName, tick, time ) ;
89
117
}
90
- // Demo
91
- if (sar_draw_demo.GetBool ()) {
92
- char demo[64 ];
93
- if (!DemoRecorder::CurrentDemo.empty ()) {
94
- if (*DemoRecorder::Recording && !*Engine::LoadGame) {
95
- int tick = DemoRecorder::GetCurrentTick ();
96
- float time = tick * *Engine::IntervalPerTick;
97
- snprintf (demo, sizeof (demo), " demo: %s %i (%.3f)" , DemoRecorder::CurrentDemo.c_str (), tick, time );
98
- }
99
- else {
100
- snprintf (demo, sizeof (demo), " demo: %s" , DemoRecorder::CurrentDemo.c_str ());
101
- }
102
- }
103
- else {
104
- snprintf (demo, sizeof (demo), " demo: -" );
105
- }
106
- Surface::Draw (m_hFont, 1 , start + level * (factor + level), COL_WHITE, demo);
107
- level++;
118
+ else {
119
+ snprintf (demo, sizeof (demo), " demo: -" );
108
120
}
109
-
110
- SetSize (thisptr, FPS_PANEL_WIDTH, FPS_PANEL_WIDTH) ;
121
+ Surface::Draw (m_hFont, 1 , offset + level * (size + spacing), COL_WHITE, demo);
122
+ level++ ;
111
123
}
124
+
125
+ // Original paint function might resize the panel
126
+ // And this needs more space anyway
127
+ SetSize (thisptr, FPS_PANEL_WIDTH, FPS_PANEL_WIDTH);
112
128
return result;
113
129
}
130
+ bool __fastcall ShouldDraw (void * thisptr, int edx)
131
+ {
132
+ return Original::ShouldDraw (thisptr)
133
+ || sar_draw_session.GetBool ()
134
+ || sar_draw_last_session.GetBool ()
135
+ || sar_draw_sum.GetBool ()
136
+ || sar_draw_timer.GetBool ()
137
+ || sar_draw_avg.GetBool ()
138
+ || sar_draw_cps.GetBool ()
139
+ || sar_draw_demo.GetBool ();
140
+ }
114
141
}
115
142
}
0 commit comments