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

Commit 9addb88

Browse files
committed
Update to 1.4
1 parent 7b8d966 commit 9addb88

13 files changed

+407
-287
lines changed

README.md

+13-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
[![Build Version](https://img.shields.io/badge/version-v1.3-brightgreen.svg)](https://github.com/NeKzor/SourceAutoRecord/projects/1)
1+
[![Build Version](https://img.shields.io/badge/version-v1.4-brightgreen.svg)](https://github.com/NeKzor/SourceAutoRecord/projects/1)
22
[![Release Status](https://img.shields.io/github/release/NeKzor/SourceAutoRecord/all.svg)](https://github.com/NeKzor/SourceAutoRecord/releases)
33

44
**SourceAutoRecord** allows automatic demo recording, automatic binding, demo parsing, session timing and [much more](#features).
@@ -101,7 +101,18 @@
101101
- `sar_aircontrol` enables more air-control on the server
102102
- `sar_never_open_cm_hud` disables HUD for challenge mode stats (Portal 2)
103103
- `sar_never_delay_start` disables start delay when spawning
104-
- `sv_bonus_challenge`, `sv_accelerate`, `sv_airaccelerate`, `sv_friction`, `sv_maxspeed` and `sv_stopspeed` can be accessed in the developer console
104+
- These commands can be accessed in the developer console:
105+
- sv_bonus_challenge
106+
- sv_accelerate
107+
- sv_airaccelerate
108+
- sv_friction
109+
- sv_maxspeed
110+
- sv_stopspeed
111+
- sv_maxvelocity
112+
- sv_transition_fade_time (Portal 2)
113+
- sv_laser_cube_autoaim (Portal 2)
114+
- ui_loadingscreen_transition_time (Portal 2)
115+
- hide_gun_when_holding (Portal 2)
105116

106117
### Patches
107118
- Limited character printing has been extended for `help`

src/SourceAutoRecord/Callbacks.hpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ namespace Callbacks
3434
{
3535
Console::Print("SourceAutoRecord tells the engine to keep recording when loading a save.\n");
3636
Console::Print("More information at: https://nekzor.github.io/SourceAutoRecord\n");
37-
Console::Print("Game: %s\n", Offsets::GetGame());
37+
Console::Print("Game: %s\n", Game::GetVersion());
3838
Console::Print("Version: %s\n", SAR_VERSION);
3939
Console::Print("Build: %s\n", SAR_BUILD);
4040
}
@@ -94,7 +94,7 @@ namespace Callbacks
9494

9595
std::string name;
9696
std::string dir = Engine::GetDir() + std::string("\\");
97-
for (size_t i = 1; i < args.Count(); i++)
97+
for (int i = 1; i < args.Count(); i++)
9898
{
9999
name = std::string(args.At(i));
100100

@@ -314,7 +314,7 @@ namespace Callbacks
314314
return;
315315
}
316316

317-
for (size_t i = 0; i < average; i++) {
317+
for (int i = 0; i < average; i++) {
318318
Console::Print("%s -> ", Timer::Average::Items[i].Map);
319319
Console::Print("%i ticks", Timer::Average::Items[i].Ticks);
320320
Console::Print("(%.3f)\n", Timer::Average::Items[i].Time);
@@ -349,7 +349,7 @@ namespace Callbacks
349349
return;
350350
}
351351

352-
for (size_t i = 0; i < cps; i++) {
352+
for (int i = 0; i < cps; i++) {
353353
if (i == cps - 1 && Timer::IsRunning) {
354354
Console::PrintActive("%s -> ", Timer::CheckPoints::Items[i].Map);
355355
Console::PrintActive("%i ticks", Timer::CheckPoints::Items[i].Ticks);

src/SourceAutoRecord/Game.hpp

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#pragma once
2+
3+
namespace Game
4+
{
5+
enum SourceGame
6+
{
7+
Portal2, // Portal 2 6879
8+
INFRA // INFRA 6905
9+
};
10+
11+
SourceGame Version;
12+
13+
bool IsSupported()
14+
{
15+
TCHAR temp[MAX_PATH];
16+
GetModuleFileName(NULL, temp, _countof(temp));
17+
std::string exe = std::string(temp);
18+
int index = exe.find_last_of("\\/");
19+
exe = exe.substr(index + 1, exe.length() - index);
20+
21+
if (exe == "portal2.exe") {
22+
Version = SourceGame::Portal2;
23+
}
24+
else if (exe == "infra.exe") {
25+
Version = SourceGame::INFRA;
26+
}
27+
else {
28+
return false;
29+
}
30+
return true;
31+
}
32+
const char* GetVersion() {
33+
switch (Version) {
34+
case 0:
35+
return "Portal 2 (6879)";
36+
case 1:
37+
return "INFRA (6905)";
38+
}
39+
return "Unknown";
40+
}
41+
}

src/SourceAutoRecord/Hooks.hpp

+18-18
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#include "Modules/Engine.hpp"
77
#include "Modules/Server.hpp"
88

9-
#include "Offsets.hpp"
9+
#include "Game.hpp"
1010
#include "Patterns.hpp"
1111
#include "Utils.hpp"
1212

@@ -16,13 +16,13 @@ namespace Hooks
1616
// signature scans have been completed
1717
std::vector<uintptr_t> HookAddresses;
1818

19-
ScanResult Create(Pattern toScan, LPVOID detour, LPVOID* original)
19+
ScanResult Create(Pattern* toScan, LPVOID detour, LPVOID original)
2020
{
2121
auto result = Scan(toScan);
2222
if (result.Found) {
2323
Console::DevMsg("SAR: %s\n", result.Message);
2424

25-
if (MH_CreateHook(reinterpret_cast<LPVOID>(result.Address), detour, original) != MH_OK) {
25+
if (MH_CreateHook(reinterpret_cast<LPVOID>(result.Address), detour, reinterpret_cast<LPVOID*>(original)) != MH_OK) {
2626
Console::DevWarning("SAR: Could not create this hook!\n");
2727
}
2828
else {
@@ -54,24 +54,24 @@ namespace Hooks
5454
return;
5555
}
5656

57-
Create(Patterns::Get("CheckJumpButton"), Server::Detour::CheckJumpButton, reinterpret_cast<LPVOID*>(&Server::Original::CheckJumpButton));
58-
Create(Patterns::Get("Paint"), Client::Detour::Paint, reinterpret_cast<LPVOID*>(&Client::Original::Paint));
59-
Create(Patterns::Get("SetSignonState"), Engine::Detour::SetSignonState, reinterpret_cast<LPVOID*>(&Engine::Original::SetSignonState));
60-
Create(Patterns::Get("StopRecording"), Engine::Detour::StopRecording, reinterpret_cast<LPVOID*>(&Engine::Original::StopRecording));
61-
Create(Patterns::Get("StartupDemoFile"), Engine::Detour::StartupDemoFile, reinterpret_cast<LPVOID*>(&Engine::Original::StartupDemoFile));
62-
Create(Patterns::Get("Stop"), Engine::Detour::ConCommandStop, reinterpret_cast<LPVOID*>(&Engine::Original::ConCommandStop));
63-
Create(Patterns::Get("StartPlayback"), Engine::Detour::StartPlayback, reinterpret_cast<LPVOID*>(&Engine::Original::StartPlayback));
64-
Create(Patterns::Get("PlayDemo"), Engine::Detour::PlayDemo, reinterpret_cast<LPVOID*>(&Engine::Original::PlayDemo));
65-
Create(Patterns::Get("Disconnect"), Engine::Detour::Disconnect, reinterpret_cast<LPVOID*>(&Engine::Original::Disconnect));
66-
Create(Patterns::Get("ShouldDraw"), Client::Detour::ShouldDraw, reinterpret_cast<LPVOID*>(&Client::Original::ShouldDraw));
67-
Create(Patterns::Get("PlayerUse"), Server::Detour::PlayerUse, reinterpret_cast<LPVOID*>(&Server::Original::PlayerUse));
68-
Create(Patterns::Get("HostStateFrame"), Engine::Detour::HostStateFrame, reinterpret_cast<LPVOID*>(&Engine::Original::HostStateFrame));
69-
Create(Patterns::Get("CloseDemoFile"), Engine::Detour::CloseDemoFile, reinterpret_cast<LPVOID*>(&Engine::Original::CloseDemoFile));
70-
Create(Patterns::Get("FindElement"), Client::Detour::FindElement, reinterpret_cast<LPVOID*>(&Client::Original::FindElement));
57+
Create(Patterns::Get("CheckJumpButton"), Server::Detour::CheckJumpButton, &Server::Original::CheckJumpButton);
58+
Create(Patterns::Get("Paint"), Client::Detour::Paint, &Client::Original::Paint);
59+
Create(Patterns::Get("SetSignonState"), Engine::Detour::SetSignonState, &Engine::Original::SetSignonState);
60+
Create(Patterns::Get("StopRecording"), Engine::Detour::StopRecording, &Engine::Original::StopRecording);
61+
Create(Patterns::Get("StartupDemoFile"), Engine::Detour::StartupDemoFile, &Engine::Original::StartupDemoFile);
62+
Create(Patterns::Get("Stop"), Engine::Detour::ConCommandStop, &Engine::Original::ConCommandStop);
63+
Create(Patterns::Get("StartPlayback"), Engine::Detour::StartPlayback, &Engine::Original::StartPlayback);
64+
Create(Patterns::Get("PlayDemo"), Engine::Detour::PlayDemo, &Engine::Original::PlayDemo);
65+
Create(Patterns::Get("Disconnect"), Engine::Detour::Disconnect, &Engine::Original::Disconnect);
66+
Create(Patterns::Get("ShouldDraw"), Client::Detour::ShouldDraw, &Client::Original::ShouldDraw);
67+
Create(Patterns::Get("PlayerUse"), Server::Detour::PlayerUse, &Server::Original::PlayerUse);
68+
Create(Patterns::Get("HostStateFrame"), Engine::Detour::HostStateFrame, &Engine::Original::HostStateFrame);
69+
Create(Patterns::Get("CloseDemoFile"), Engine::Detour::CloseDemoFile, &Engine::Original::CloseDemoFile);
70+
Create(Patterns::Get("FindElement"), Client::Detour::FindElement, &Client::Original::FindElement);
7171

7272
// Mid-function-hooks
7373
Server::SetAirMove(Create(Patterns::Get("AirMove"), Server::Detour::AirMove, NULL).Address);
74-
if (Offsets::Game == 0) {
74+
if (Game::Version == Game::Portal2) {
7575
Server::SetRunCommand(Create(Patterns::Get("PlayerRunCommand"), Server::Detour::PlayerRunCommand, NULL).Address);
7676
}
7777
}

src/SourceAutoRecord/Main.cpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,17 @@
33

44
unsigned __stdcall Main(void* args)
55
{
6-
if (!Offsets::Init()) return Error("Game not supported!", "SourceAutoRecord");
6+
if (!Game::IsSupported()) return Error("Game not supported!", "SourceAutoRecord");
77
if (!Console::Init()) return Error("Could not initialize console!", "SourceAutoRecord");
88

9-
Patterns::LoadAll();
9+
Offsets::Init();
10+
Patterns::Init();
1011

1112
// ConCommand and ConVar
1213
if (SAR::LoadTier1()) {
1314

1415
// Cheats
15-
SAR::RegisterCommands();
16+
SAR::CreateCommands();
1617
SAR::EnableGameCheats();
1718

1819
// Hooks

src/SourceAutoRecord/Modules/ConCommand.hpp

+4-6
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
#pragma once
22
#include "Tier1.hpp"
33

4-
#include "Offsets.hpp"
4+
#include "Game.hpp"
55

66
namespace Tier1
77
{
88
_ConCommand ConCommandCtor;
99
_ConCommand ConCommandCtor2;
1010

11-
// Portal 2 6879
12-
// INFRA 6905
1311
struct ConCommandData : ConCommandBase {
1412
union {
1513
void* CommandCallbackV1;
@@ -38,9 +36,9 @@ namespace Tier1
3836
ConCommand::ConCommand() {
3937
size_t size = 0;
4038

41-
switch (Offsets::Game) {
42-
case 0: // Portal 2 6879
43-
case 1: // INFRA 6905
39+
switch (Game::Version) {
40+
case 0:
41+
case 1:
4442
size = sizeof(ConCommandData);
4543
break;
4644
}

src/SourceAutoRecord/Modules/ConVar.hpp

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
#pragma once
22
#include "Cvar.hpp"
3-
#include "Offsets.hpp"
43
#include "Tier1.hpp"
54

5+
#include "Game.hpp"
6+
67
namespace Tier1
78
{
89
_ConVar ConVarCtor;
@@ -87,9 +88,9 @@ namespace Tier1
8788
ConVar cv;
8889
size_t size = 0;
8990

90-
switch (Offsets::Game) {
91-
case 0: // Portal 2 6879
92-
case 1: // INFRA 6905
91+
switch (Game::Version) {
92+
case 0:
93+
case 1:
9394
size = sizeof(ConVarData);
9495
break;
9596
}

src/SourceAutoRecord/Offsets.hpp

+5-28
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
#pragma once
22
#include <string>
33

4+
#include "Game.hpp"
5+
46
namespace Offsets
57
{
6-
int Game;
7-
88
// CCvar
99
int FindVar;
1010

@@ -55,17 +55,9 @@ namespace Offsets
5555
int AirMoveSkip;
5656
int PlayerRunCommandSkip;
5757

58-
bool Init()
58+
void Init()
5959
{
60-
TCHAR temp[MAX_PATH];
61-
GetModuleFileName(NULL, temp, _countof(temp));
62-
std::string exe = std::string(temp);
63-
int index = exe.find_last_of("\\/");
64-
exe = exe.substr(index + 1, exe.length() - index);
65-
66-
// Portal 2 6879
67-
if (exe == "portal2.exe") {
68-
Game = 0;
60+
if (Game::Version == Game::Portal2) {
6961
InternalSetValue = 12;
7062
InternalSetFloatValue = 13;
7163
InternalSetIntValue = 14;
@@ -93,9 +85,7 @@ namespace Offsets
9385
AirMoveSkip = 142;
9486
PlayerRunCommandSkip = 51;
9587
}
96-
// INFRA 6905
97-
else if (exe == "infra.exe") {
98-
Game = 1;
88+
else if (Game::Version == Game::INFRA) {
9989
InternalSetValue = 14;
10090
InternalSetFloatValue = 15;
10191
InternalSetIntValue = 16;
@@ -123,18 +113,5 @@ namespace Offsets
123113
AirMoveSkip = 162;
124114
//PlayerRunCommandSkip = 132;
125115
}
126-
else {
127-
return false;
128-
}
129-
return true;
130-
}
131-
const char* GetGame() {
132-
switch (Game) {
133-
case 0:
134-
return "Portal 2 (6879)";
135-
case 1:
136-
return "INFRA (6905)";
137-
}
138-
return "Unknown";
139116
}
140117
}

0 commit comments

Comments
 (0)