Skip to content

Commit

Permalink
GoldSrc: Move SetMaxSpeedFactor option to settings.ini
Browse files Browse the repository at this point in the history
Also makes it clear that the process can now be written into.
  • Loading branch information
TotallyMehis committed Feb 4, 2021
1 parent be94fb2 commit d5ae1f4
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 22 deletions.
1 change: 0 additions & 1 deletion ezauto/games.ini
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,4 @@ WindowTitle=Counter-Strike
Engine=goldsrc
Offset:flags=hw.dll+0x1009D38
Offset:movetype=flags+0x24
;SetMaxSpeedFactor=10000; If this is set, we set the max speed factor (bhop cap) to this value. Will require write access.
Offset:BUNNYJUMP_MAX_SPEED_FACTOR=client.dll+0xC42F0
16 changes: 14 additions & 2 deletions ezauto/settings.ini
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
[Settings]
; ================================
; General settings you should configure.
; ================================
[General]
; Pause key - Pressing this will pause bunnyhopping.
PauseKey=f12

; Hold key - This is the button that you will hold. It is a good idea to just unbind this key.
HoldKey=space

; Jump key - This button has to be bound to +jump, so the program can press it for you.
JumpKey=v
JumpKey=v

; ================================
; CS 1.6 specific options.
; ================================
[CS 1.6]
; If this is uncommented, set the max speed factor (bhop cap) to this value. Will require write access.
; Useful for bunnyhopping in high ping servers with no bunnyhop cap.
;SetMaxSpeedFactor=10000
32 changes: 24 additions & 8 deletions src/core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,20 @@
#include "player_src.h"


void Core::ReadSettings()
CCore g_Core;


CCore::CCore()
{
m_flBunnyHopSpeedFactor = -1.0f;
}

void CCore::Init()
{
ReadSettings();
}

void CCore::ReadSettings()
{
char temp[32];

Expand All @@ -20,8 +33,7 @@ void Core::ReadSettings()
// Read our file.
CSettings* settings = CSettings::OpenFile( SETTINGS_FILE );


if ( settings && !g_Keys.GetPauseKey().IsValidVirtual() && settings->FindOption( "PauseKey", temp, sizeof temp ) )
if ( settings && !g_Keys.GetPauseKey().IsValidVirtual() && settings->FindOption( "PauseKey", temp, sizeof( temp ) ) )
{
g_Keys.SetPauseKey( temp );
}
Expand All @@ -30,7 +42,7 @@ void Core::ReadSettings()
g_Keys.SetPauseKey( "f11" );
}

if ( settings && !g_Keys.GetHoldKey().IsValidVirtual() && settings->FindOption( "HoldKey", temp, sizeof temp ) )
if ( settings && !g_Keys.GetHoldKey().IsValidVirtual() && settings->FindOption( "HoldKey", temp, sizeof( temp ) ) )
{
g_Keys.SetHoldKey( temp );
}
Expand All @@ -39,7 +51,7 @@ void Core::ReadSettings()
g_Keys.SetHoldKey( "space" );
}

if ( settings && !g_Keys.GetJumpKey().IsValidScancode() && settings->FindOption( "JumpKey", temp, sizeof temp ) )
if ( settings && !g_Keys.GetJumpKey().IsValidScancode() && settings->FindOption( "JumpKey", temp, sizeof( temp ) ) )
{
g_Keys.SetJumpKey( temp );
}
Expand All @@ -48,11 +60,15 @@ void Core::ReadSettings()
g_Keys.SetJumpKey( "v" );
}

if ( settings && settings->FindOption( "SetMaxSpeedFactor", temp, sizeof( temp ) ) )
{
m_flBunnyHopSpeedFactor = (float)atof( temp );
}

delete settings;
}

int Core::ListenToProcess()
int CCore::ListenToProcess()
{
// Get the game section from games.ini
const CSettings_Section* data = CProcess::ListenToProcesses();
Expand Down Expand Up @@ -113,13 +129,13 @@ int Core::ListenToProcess()
}


Core::JumpLoop( pBase );
CCore::JumpLoop( pBase );


return 0;
}

void Core::JumpLoop( CPlayer_Base* pPlayer )
void CCore::JumpLoop( CPlayer_Base* pPlayer )
{
if ( !pPlayer ) return;

Expand Down
20 changes: 17 additions & 3 deletions src/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,25 @@
#define GAMEDATA_FILE "games.ini"
#define SETTINGS_FILE "settings.ini"

namespace Core
class CCore
{
public:
CCore();
virtual ~CCore() {}

void Init();
int ListenToProcess();

float CS16_MaxSpeedFactor() const { return m_flBunnyHopSpeedFactor; }

private:
void ReadSettings();

void JumpLoop( CPlayer_Base* );
}
void JumpLoop( CPlayer_Base* pPlayer );


float m_flBunnyHopSpeedFactor;
};

extern CCore g_Core;

4 changes: 2 additions & 2 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ int main( int argc, char* argv[] )
}


Core::ReadSettings();
g_Core.Init();

while ( true )
{
auto ret = Core::ListenToProcess();
auto ret = g_Core.ListenToProcess();
if ( ret != 0 )
{
return ret;
Expand Down
11 changes: 6 additions & 5 deletions src/player_goldsrc.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "player_goldsrc.h"
#include "process.h"
#include "keys.h"
#include "core.h"
#include "offsetparser.h"


Expand Down Expand Up @@ -43,11 +44,7 @@ bool CPlayer_GoldSrc::ParseGameData( const CSettings_Section* data )
delete parser;


auto* pszSpeedFactor = data->GetOptionValue( "SetMaxSpeedFactor" );
if ( pszSpeedFactor )
{
m_flBunnyHopSpeedFactor = (float)atof( pszSpeedFactor );
}
m_flBunnyHopSpeedFactor = g_Core.CS16_MaxSpeedFactor();



Expand All @@ -65,6 +62,10 @@ bool CPlayer_GoldSrc::Init()
{
CSystem::PrintWarning( "Failed to override BUNNYJUMP_MAX_SPEED_FACTOR! Try restarting this.\n" );
}
else
{
CSystem::PrintDev( "Changed BUNNYJUMP_MAX_SPEED_FACTOR to %.1f!\n", m_flBunnyHopSpeedFactor );
}
}


Expand Down
6 changes: 5 additions & 1 deletion src/process.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "settings.h"
#include "process.h"
#include "engine.h"
#include "core.h"


CProcess g_Process;
Expand Down Expand Up @@ -119,6 +120,8 @@ bool CProcess::OpenProcess( bool bWrite )
if ( bWrite )
{
flags |= PROCESS_VM_WRITE | PROCESS_VM_OPERATION;

CSystem::PrintWarning( "Opening process for writing!\n" );
}

m_hProcess = ::OpenProcess( flags, false, m_dwProcessID );
Expand Down Expand Up @@ -223,7 +226,8 @@ const CSettings_Section* CProcess::ListenToProcesses()

if ( engine && (eng = Engine::EngineNameToType( engine )) != ENGINE_INVALID )
{
if ( g_Process.OpenProcess( eng == ENGINE_GOLDSRC ) )
// Open for write if on GoldSrc and wants max speed factor changed.
if ( g_Process.OpenProcess( eng == ENGINE_GOLDSRC && g_Core.CS16_MaxSpeedFactor() >= 0.0f ) )
{
g_Process.m_Engine = eng;

Expand Down

0 comments on commit d5ae1f4

Please sign in to comment.