From d5ae1f4483050b2e1ef7eea0b63741f5446c4383 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miikka=20Yl=C3=A4talo?= Date: Thu, 4 Feb 2021 20:20:47 +0200 Subject: [PATCH] GoldSrc: Move SetMaxSpeedFactor option to settings.ini Also makes it clear that the process can now be written into. --- ezauto/games.ini | 1 - ezauto/settings.ini | 16 ++++++++++++++-- src/core.cpp | 32 ++++++++++++++++++++++++-------- src/core.h | 20 +++++++++++++++++--- src/main.cpp | 4 ++-- src/player_goldsrc.cpp | 11 ++++++----- src/process.cpp | 6 +++++- 7 files changed, 68 insertions(+), 22 deletions(-) diff --git a/ezauto/games.ini b/ezauto/games.ini index 6724a50..fbe745b 100644 --- a/ezauto/games.ini +++ b/ezauto/games.ini @@ -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 diff --git a/ezauto/settings.ini b/ezauto/settings.ini index 12bfbf0..50c74ab 100644 --- a/ezauto/settings.ini +++ b/ezauto/settings.ini @@ -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 \ No newline at end of file +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 diff --git a/src/core.cpp b/src/core.cpp index 6f7fb71..9c50456 100644 --- a/src/core.cpp +++ b/src/core.cpp @@ -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]; @@ -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 ); } @@ -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 ); } @@ -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 ); } @@ -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(); @@ -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; diff --git a/src/core.h b/src/core.h index 39c7263..1318943 100644 --- a/src/core.h +++ b/src/core.h @@ -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; + diff --git a/src/main.cpp b/src/main.cpp index 04696c2..7638d92 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -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; diff --git a/src/player_goldsrc.cpp b/src/player_goldsrc.cpp index c887c17..261b6ff 100644 --- a/src/player_goldsrc.cpp +++ b/src/player_goldsrc.cpp @@ -1,6 +1,7 @@ #include "player_goldsrc.h" #include "process.h" #include "keys.h" +#include "core.h" #include "offsetparser.h" @@ -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(); @@ -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 ); + } } diff --git a/src/process.cpp b/src/process.cpp index c3c4aef..8ca23c9 100644 --- a/src/process.cpp +++ b/src/process.cpp @@ -1,6 +1,7 @@ #include "settings.h" #include "process.h" #include "engine.h" +#include "core.h" CProcess g_Process; @@ -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 ); @@ -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;