Skip to content
This repository was archived by the owner on Dec 12, 2022. It is now read-only.

Commit f81e52c

Browse files
committed
Keep drawing without cl_showpos active
1 parent 02d5988 commit f81e52c

12 files changed

+165
-96
lines changed

README.md

-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@
7474
- `sar_cps_result` prints result of all checkpoints
7575

7676
### HUD
77-
- Drawing useful information with `cl_showpos`
7877
- `sar_draw_session` draws current session value
7978
- `sar_draw_sum` draws summary value of sessions
8079
- `sar_draw_timer` draws timer value

src/SourceAutoRecord/Callbacks.hpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ namespace Callbacks
1919
void PrintSession()
2020
{
2121
Console::Msg("Session Tick: %i (%.3f)\n", Engine::GetTick(), Engine::GetTime());
22-
//Console::Msg("Recorder Tick: %i\n", DemoRecorder::GetCurrentTick());
22+
if (*DemoRecorder::Recording)
23+
Console::Msg("Demo Recorder Tick: %i\n", DemoRecorder::GetTick());
24+
if (DemoPlayer::IsPlaying())
25+
Console::Msg("Demo Player Tick: %i\n", DemoPlayer::GetTick());
2326
}
2427
void PrintAbout()
2528
{

src/SourceAutoRecord/Commands.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ namespace Commands
4141

4242
// Drawing
4343
ConVar sar_draw_session;
44+
ConVar sar_draw_last_session;
4445
ConVar sar_draw_sum;
4546
ConVar sar_draw_timer;
4647
ConVar sar_draw_avg;

src/SourceAutoRecord/Hooks.hpp

+10-7
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,22 @@
1111

1212
namespace Hooks
1313
{
14-
ScanResult cjb, pnt, sst, cdf, str, sdf, stp, spb, pld, dsc, spl;
14+
ScanResult cjb, pnt, sst, cdf, str, sdf, stp, spb, pld, dsc, spl, shd;
1515

1616
void Load()
1717
{
1818
cjb = Scan(Patterns::CheckJumpButton);
1919
pnt = Scan(Patterns::Paint);
2020
sst = Scan(Patterns::SetSignonState);
21-
cdf = Scan(Patterns::CloseDemoFile);
21+
//cdf = Scan(Patterns::CloseDemoFile);
2222
str = Scan(Patterns::StopRecording);
2323
sdf = Scan(Patterns::StartupDemoFile);
2424
stp = Scan(Patterns::Stop);
2525
spb = Scan(Patterns::StartPlayback);
2626
pld = Scan(Patterns::PlayDemo);
2727
dsc = Scan(Patterns::Disconnect);
28-
spl = Scan(Patterns::StopPlayback);
28+
//spl = Scan(Patterns::StopPlayback);
29+
shd = Scan(Patterns::ShouldDraw);
2930

3031
Offsets::Init(cjb.Index);
3132
}
@@ -36,24 +37,26 @@ namespace Hooks
3637
MH_CreateHook(reinterpret_cast<LPVOID>(cjb.Address), Server::Detour::CheckJumpButton, reinterpret_cast<LPVOID*>(&Server::Original::CheckJumpButton));
3738
MH_CreateHook(reinterpret_cast<LPVOID>(pnt.Address), Client::Detour::Paint, reinterpret_cast<LPVOID*>(&Client::Original::Paint));
3839
MH_CreateHook(reinterpret_cast<LPVOID>(sst.Address), Engine::Detour::SetSignonState, reinterpret_cast<LPVOID*>(&Engine::Original::SetSignonState));
39-
MH_CreateHook(reinterpret_cast<LPVOID>(cdf.Address), Engine::Detour::CloseDemoFile, reinterpret_cast<LPVOID*>(&Engine::Original::CloseDemoFile));
40+
//MH_CreateHook(reinterpret_cast<LPVOID>(cdf.Address), Engine::Detour::CloseDemoFile, reinterpret_cast<LPVOID*>(&Engine::Original::CloseDemoFile));
4041
MH_CreateHook(reinterpret_cast<LPVOID>(str.Address), Engine::Detour::StopRecording, reinterpret_cast<LPVOID*>(&Engine::Original::StopRecording));
4142
MH_CreateHook(reinterpret_cast<LPVOID>(sdf.Address), Engine::Detour::StartupDemoFile, reinterpret_cast<LPVOID*>(&Engine::Original::StartupDemoFile));
4243
MH_CreateHook(reinterpret_cast<LPVOID>(stp.Address), Engine::Detour::ConCommandStop, reinterpret_cast<LPVOID*>(&Engine::Original::ConCommandStop));
4344
MH_CreateHook(reinterpret_cast<LPVOID>(spb.Address), Engine::Detour::StartPlayback, reinterpret_cast<LPVOID*>(&Engine::Original::StartPlayback));
4445
MH_CreateHook(reinterpret_cast<LPVOID>(pld.Address), Engine::Detour::PlayDemo, reinterpret_cast<LPVOID*>(&Engine::Original::PlayDemo));
4546
MH_CreateHook(reinterpret_cast<LPVOID>(dsc.Address), Engine::Detour::Disconnect, reinterpret_cast<LPVOID*>(&Engine::Original::Disconnect));
46-
MH_CreateHook(reinterpret_cast<LPVOID>(spl.Address), Engine::Detour::StopPlayback, reinterpret_cast<LPVOID*>(&Engine::Original::StopPlayback));
47+
//MH_CreateHook(reinterpret_cast<LPVOID>(spl.Address), Engine::Detour::StopPlayback, reinterpret_cast<LPVOID*>(&Engine::Original::StopPlayback));
48+
MH_CreateHook(reinterpret_cast<LPVOID>(shd.Address), Client::Detour::ShouldDraw, reinterpret_cast<LPVOID*>(&Client::Original::ShouldDraw));
4749
MH_EnableHook(reinterpret_cast<LPVOID>(cjb.Address));
4850
MH_EnableHook(reinterpret_cast<LPVOID>(pnt.Address));
4951
MH_EnableHook(reinterpret_cast<LPVOID>(sst.Address));
50-
MH_EnableHook(reinterpret_cast<LPVOID>(cdf.Address));
52+
//MH_EnableHook(reinterpret_cast<LPVOID>(cdf.Address));
5153
MH_EnableHook(reinterpret_cast<LPVOID>(str.Address));
5254
MH_EnableHook(reinterpret_cast<LPVOID>(sdf.Address));
5355
MH_EnableHook(reinterpret_cast<LPVOID>(stp.Address));
5456
MH_EnableHook(reinterpret_cast<LPVOID>(spb.Address));
5557
MH_EnableHook(reinterpret_cast<LPVOID>(pld.Address));
5658
MH_EnableHook(reinterpret_cast<LPVOID>(dsc.Address));
57-
MH_EnableHook(reinterpret_cast<LPVOID>(spl.Address));
59+
//MH_EnableHook(reinterpret_cast<LPVOID>(spl.Address));
60+
MH_EnableHook(reinterpret_cast<LPVOID>(shd.Address));
5861
}
5962
}

src/SourceAutoRecord/Main.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,15 @@ unsigned __stdcall Main(void* args)
1212
Console::DevMsg("SAR: %s\n", Patterns::CheckJumpButton.GetResult());
1313
Console::DevMsg("SAR: %s\n", Patterns::Paint.GetResult());
1414
Console::DevMsg("SAR: %s\n", Patterns::SetSignonState.GetResult());
15-
Console::DevMsg("SAR: %s\n", Patterns::CloseDemoFile.GetResult());
15+
//Console::DevMsg("SAR: %s\n", Patterns::CloseDemoFile.GetResult());
1616
Console::DevMsg("SAR: %s\n", Patterns::StopRecording.GetResult());
1717
Console::DevMsg("SAR: %s\n", Patterns::StartupDemoFile.GetResult());
1818
Console::DevMsg("SAR: %s\n", Patterns::Stop.GetResult());
1919
Console::DevMsg("SAR: %s\n", Patterns::StartPlayback.GetResult());
2020
Console::DevMsg("SAR: %s\n", Patterns::PlayDemo.GetResult());
2121
Console::DevMsg("SAR: %s\n", Patterns::Disconnect.GetResult());
22-
Console::DevMsg("SAR: %s\n", Patterns::StopPlayback.GetResult());
22+
//Console::DevMsg("SAR: %s\n", Patterns::StopPlayback.GetResult());
23+
Console::DevMsg("SAR: %s\n", Patterns::ShouldDraw.GetResult());
2324

2425
SAR::LoadEngine();
2526
Console::DevMsg("SAR: %s\n", Patterns::EngineClientPtr.GetResult());

src/SourceAutoRecord/Modules/Client.hpp

+91-64
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
using _Paint = int(__thiscall*)(void* thisptr);
1414
using _ComputeSize = int(__thiscall*)(void* thisptr);
1515
using _SetSize = int(__thiscall*)(void* thisptr, int wide, int tall);
16+
using _ShouldDraw = bool(__thiscall*)(void* thisptr);
1617

1718
// client.dll
1819
namespace Client
@@ -28,88 +29,114 @@ namespace Client
2829
{
2930
_Paint Paint;
3031
_ComputeSize ComputeSize;
32+
_ShouldDraw ShouldDraw;
3133
}
3234

3335
namespace Detour
3436
{
3537
int __fastcall Paint(void* thisptr, int edx)
3638
{
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+
3848
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;
4457

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()) {
4772
int tick = (!*Engine::LoadGame) ? Engine::GetTick() : 0;
4873
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);
5475
}
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);
6778
}
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;
7286

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);
83111
}
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);
89117
}
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: -");
108120
}
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++;
111123
}
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);
112128
return result;
113129
}
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+
}
114141
}
115142
}

src/SourceAutoRecord/Modules/DemoPlayer.hpp

+7
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,27 @@
33
#include "Utils.hpp"
44

55
using _IsPlayingBack = bool(__thiscall*)(void* thisptr);
6+
using _GetPlaybackTick = int(__thiscall*)(void* thisptr);
67

78
namespace DemoPlayer
89
{
910
void* Ptr;
1011
char* DemoName;
1112

1213
_IsPlayingBack IsPlayingBack;
14+
_GetPlaybackTick GetPlaybackTick;
1315

1416
void Set(uintptr_t demoPlayerPtr)
1517
{
1618
Ptr = **(void***)(demoPlayerPtr);
19+
GetPlaybackTick = (_GetPlaybackTick)GetVirtualFunctionByIndex(Ptr, Offsets::GetPlaybackTick);
1720
IsPlayingBack = (_IsPlayingBack)GetVirtualFunctionByIndex(Ptr, Offsets::IsPlayingBack);
1821
DemoName = (char*)reinterpret_cast<uintptr_t*>((uintptr_t)Ptr + Offsets::m_szFileName);
1922
}
23+
int GetTick()
24+
{
25+
return GetPlaybackTick(Ptr);
26+
}
2027
bool IsPlaying()
2128
{
2229
return IsPlayingBack(Ptr);

src/SourceAutoRecord/Modules/DemoRecorder.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ namespace DemoRecorder
2525
DemoNumber = (int*)reinterpret_cast<uintptr_t*>((uintptr_t)Ptr + Offsets::m_nDemoNumber);
2626
Recording = (bool*)reinterpret_cast<uintptr_t*>((uintptr_t)Ptr + Offsets::m_bRecording);
2727
}
28-
int GetCurrentTick()
28+
int GetTick()
2929
{
3030
return GetRecordingTick(Ptr);
3131
}

0 commit comments

Comments
 (0)