ohai. SIGN UP.

Username:  
Password:     
Register Help Member List Calendar View New Posts View Today's Posts Search

User(s) Viewing This Thread: 1 Guest(s)
Post Reply 
Half-Life 2 Episode 2: Re-implementing bunny hopping
Author Message
Cameron:D Offline
Administrator
*******



Posts: 130
Joined: Aug 2009
Post: #1
Half-Life 2 Episode 2: Re-implementing bunny hopping

I really enjoyed bunny hopping through Half-Life 2, there is an element of fun being able to run at really high speeds, and was rather disappointed when it was removed once and for all from Episode 2. After a bit of exploring and hacky coding, I finally managed to re-implement the ability to bunny hop back into Half-Life 2: EP2 (And of course any mods that use it's engine).

Thanks to the guys at sourceruns.org for the heads up as to what file the code is located in. If you haven't already, check out their Half-Life 2 and HL2 EP1 Speed runs.

Queue masses of code. (Scroll down if you are not interested in the code)

Open up gamemovement.cpp (In the client project) and jump down to around line 2467 (About half-way down) and you will find the following code:
PHP Code:
            // We give a certain percentage of the current forward movement as a bonus to the jump speed.  That bonus is clipped
            // to not accumulate over time.
            
float flSpeedBoostPerc = ( !pMoveData->m_bIsSprinting && !player->m_Local.m_bDucked ) ? 0.5f 0.1f;
            
float flSpeedAddition fabsmv->m_flForwardMove flSpeedBoostPerc );
            
float flMaxSpeed mv->m_flMaxSpeed + ( mv->m_flMaxSpeed flSpeedBoostPerc );
            
float flNewSpeed = ( flSpeedAddition mv->m_vecVelocity.Length2D() );

            
// If we're over the maximum, we want to only boost as much as will get us to the goal speed
            
if ( flNewSpeed flMaxSpeed )
            {
                
flSpeedAddition -= flNewSpeed flMaxSpeed;
            }
    
            if ( 
mv->m_flForwardMove 0.0f )
                
flSpeedAddition *= -1.0f;

            
// Add it on
            
VectorAdd( (vecForward*flSpeedAddition), mv->m_vecVelocitymv->m_vecVelocity ); 

Get rid of it. Delete the entire chunk. Replace it with the following code (This is the code from EP1):

PHP Code:
            if ( !pMoveData->m_bIsSprinting && !player->m_Local.m_bDucked )
            {
                for ( 
int iAxis 0iAxis ; ++iAxis )
                {
                    
vecForward[iAxis] *= ( mv->m_flForwardMove 0.5f );
    
//                vecForward[iAxis] *= ( mv->m_flForwardMove * jumpforwardscale.GetFloat() );
                
}
            }
            else
            {
                for ( 
int iAxis 0iAxis ; ++iAxis )
                {
                    
vecForward[iAxis] *= ( mv->m_flForwardMove 0.1f );
    
//                vecForward[iAxis] *= ( mv->m_flForwardMove * jumpforwardsprintscale.GetFloat() );
                
}
            }
            
VectorAddvecForwardmv->m_vecVelocitymv->m_vecVelocity ); 

Recompile your code and voila! You should be able to bunny hop.

In Operation Lambda the ability to bunny hop can be set via a Cvar, this is just a really simple change too.
First, up near the top of the file you will find some code that reads:
PHP Code:
#if defined( HL2_DLL ) || defined( HL2_CLIENT_DLL )
ConVar player_limit_jump_speed"player_limit_jump_speed""1"FCVAR_REPLICATED );
#endif 

Add after that:

PHP Code:
ConVar cl_enable_bunnyhop"cl_enable_bunnyhop""0"FCVAR_ARCHIVE ); 
You can replace FCVAR_ARCHIVE with FCVAR_CHEAT if you would like it to be set as a cheat (meaning that sv_cheats needs to be enabled to enable bunny hopping)
Now back down the file where you found:
PHP Code:
            // We give a certain percentage of the current forward movement as a bonus to the jump speed.  That bonus is clipped
            // to not accumulate over time.
            
float flSpeedBoostPerc = ( !pMoveData->m_bIsSprinting && !player->m_Local.m_bDucked ) ? 0.5f 0.1f;
            
float flSpeedAddition fabsmv->m_flForwardMove flSpeedBoostPerc );
            
float flMaxSpeed mv->m_flMaxSpeed + ( mv->m_flMaxSpeed flSpeedBoostPerc );
            
float flNewSpeed = ( flSpeedAddition mv->m_vecVelocity.Length2D() );

            
// If we're over the maximum, we want to only boost as much as will get us to the goal speed
            
if ( flNewSpeed flMaxSpeed )
            {
                
flSpeedAddition -= flNewSpeed flMaxSpeed;
            }
    
            if ( 
mv->m_flForwardMove 0.0f )
                
flSpeedAddition *= -1.0f;

            
// Add it on
            
VectorAdd( (vecForward*flSpeedAddition), mv->m_vecVelocitymv->m_vecVelocity ); 
Again, delete it and replace it with this chunk:
PHP Code:
        if(cl_enable_bunnyhop.GetInt() == 0)
        {
            
// We give a certain percentage of the current forward movement as a bonus to the jump speed.  That bonus is clipped
            // to not accumulate over time.
            
float flSpeedBoostPerc = ( !pMoveData->m_bIsSprinting && !player->m_Local.m_bDucked ) ? 0.5f 0.1f;
            
float flSpeedAddition fabsmv->m_flForwardMove flSpeedBoostPerc );
            
float flMaxSpeed mv->m_flMaxSpeed + ( mv->m_flMaxSpeed flSpeedBoostPerc );
            
float flNewSpeed = ( flSpeedAddition mv->m_vecVelocity.Length2D() );

            
// If we're over the maximum, we want to only boost as much as will get us to the goal speed
            
if ( flNewSpeed flMaxSpeed )
            {
                
flSpeedAddition -= flNewSpeed flMaxSpeed;
            }
    
            if ( 
mv->m_flForwardMove 0.0f )
                
flSpeedAddition *= -1.0f;

            
// Add it on
            
VectorAdd( (vecForward*flSpeedAddition), mv->m_vecVelocitymv->m_vecVelocity );
        }
        else
        {

            if ( !
pMoveData->m_bIsSprinting && !player->m_Local.m_bDucked )
            {
                for ( 
int iAxis 0iAxis ; ++iAxis )
                {
                    
vecForward[iAxis] *= ( mv->m_flForwardMove 0.5f );
    
//                vecForward[iAxis] *= ( mv->m_flForwardMove * jumpforwardscale.GetFloat() );
                
}
            }
            else
            {
                for ( 
int iAxis 0iAxis ; ++iAxis )
                {
                    
vecForward[iAxis] *= ( mv->m_flForwardMove 0.1f );
    
//                vecForward[iAxis] *= ( mv->m_flForwardMove * jumpforwardsprintscale.GetFloat() );
                
}
            }
            
VectorAddvecForwardmv->m_vecVelocitymv->m_vecVelocity );
        } 

Now once you recompile you should be able to set cl_enable_bunnyhop to 1 (Optionally, enable cheats) and bunny hop your way around your mod.

The edited gamemovement file is attached to the bottom of the post. (With cvar toggling)

======================================================================

For those people who just wanna play and don't care about the coding of it... Then here ya go!
Download the replacement client and server DLL files here:
http://mirror.cazzaserver.com/bhop/bhop_dlls.zip (5mb)
If you are posting this info elsewhere, please link to this thread rather than the file, thanks Smile)

Place these in your Half-Life 2 EP2 bin(aries) folder which is usually located at C:\Program Files\Steam\steamapps\<STEAM USERNAME>\half-life 2 episode two\ep2\bin
Create the folder if it doesn't exist, then extract the two DLLs into it like so:
[Image: bhop_dll.jpg]

Now fire up EP2 and enjoy!

======================================================================

Can't quite get the hang of bunny hopping? Let this help you out!
Download this (AutoHotkey with the bunny hop script already written), extract and run it. Now launch EP2 and instead of continually pressing space to jump simply just hold down the Alt key and it will automagically make you jump!

For the record, the script is:
Code:
*LAlt::
Loop
{
GetKeyState, state, LAlt, P
if State = U
break
; Otherwise:
Send, {Space}
Sleep, 1
}
return
======================================================================

These DLL files will also work for any other Mod that uses the EP2 (Orange Box) engine. If you launch the mod and it isn't working, place the DLLs into the mods bin folder, usually something like C:\Program Files\Steam\steamapps\SourceMods\<MOD NAME>\bin
!!! IF THERE ARE ALREADY FILES IN THERE, OVERWRITING THEM MAY STOP THE MOD FROM WORKING AS THE MOD DEVELOPERS MAY HAVE WRITTEN THEIR OWN DLL FILES !!!


Attached File(s)
.cpp  gamemovement.cpp (Size: 133.85 KB / Downloads: 15)
(This post was last modified: 04-18-2010 12:00 PM by Cameron:D.)
04-17-2010 09:00 PM
Find all posts by this user Quote this message in a reply
Spycrabz Offline
Serious Business
**



Posts: 4
Joined: Apr 2010
Post: #2
RE: Half-Life 2 Episode 2: Re-implementing bunny hopping

Cameron, can I have your babies?

[Image: spycrabzzzz.jpg]
04-25-2010 02:14 PM
Visit this user's website Find all posts by this user Quote this message in a reply
Cameron:D Offline
Administrator
*******



Posts: 130
Joined: Aug 2009
Post: #3
RE: Half-Life 2 Episode 2: Re-implementing bunny hopping

Maybe.
04-25-2010 05:33 PM
Find all posts by this user Quote this message in a reply
CooL Offline
Junior Member
**



Posts: 3
Joined: May 2010
Post: #4
RE: Half-Life 2 Episode 2: Re-implementing bunny hopping

Nice tut man.
05-21-2010 10:46 PM
Find all posts by this user Quote this message in a reply
Cameron:D Offline
Administrator
*******



Posts: 130
Joined: Aug 2009
Post: #5
RE: Half-Life 2 Episode 2: Re-implementing bunny hopping

Thanks to you guys Wink
05-22-2010 09:09 PM
Find all posts by this user Quote this message in a reply
CooL Offline
Junior Member
**



Posts: 3
Joined: May 2010
Post: #6
RE: Half-Life 2 Episode 2: Re-implementing bunny hopping

We try :3
05-24-2010 11:36 AM
Find all posts by this user Quote this message in a reply
Post Reply