View Single Post
Author Message
hmmmmm
Senior Member
Join Date: Mar 2017
Location: ...
Old 03-03-2018 , 05:17   [CSGO] Change player collision hull
Reply With Quote #1

Made this for a movement gametype and I thought might be helpful to some others.
Basic idea is that collision hull values are stored in a global variable named g_CSViewVectors (these values are a bit different in CS:GO), so all we have to do is change those values.

To get the address of g_CSViewVectors on Windows, we need to offset 1 byte from CCSGameRules::GetViewVectors function, which has a virtual offset of 30 (120 bytes) from CCSGameRules vtable. I combined this with gamedata I had previously for g_pGameRules from a different project.

So gamedata file ends up looking like this:
Code:
"Games"
{
	"csgo"
	{
		"Addresses"
		{
			"g_CSViewVectors"
			{
				"windows"
				{
					"signature" "g_pGameRules"
					"read" "2" // g_pGameRules
					"read" "0" // CCSGameRules object
					"read" "0" // CCSGameRules vtable
					"read" "120" // CCSGameRules::GetViewVectors()
					"read" "1" // g_CSViewVectors
				}
				"linux"
				{
					"signature" "g_pGameRules"
					"read" "2"
					"read" "0"
					"read" "0"
					"read" "124"
					"read" "2"
				}
			}
		}
		
		"Signatures"
		{
			"g_pGameRules"
			{
				"library"	"server"
				"windows"	"\x8B\x2A\x2A\x2A\x2A\x2A\x8B\x2A\x8B\x2A\x2A\x2A\x2A\x2A\xFF\x2A\x84\x2A\x75\x2A\x8B\x2A\x2A\x2A\x2A\x2A\x85"
				"linux"	"\x8B\x2A\x2A\x2A\x2A\x2A\x89\x2A\x2A\x85\x2A\x74\x2A\xA1"
			}
		}
	}
}
Here's a plugin that changes some of those values so that they match these:
PHP Code:
#pragma semicolon 1
#pragma newdecls required

#include <sourcemod>
#include <sdktools>

float g_fNewHullValues[] = 
{
      
0.0,   0.0,  64.0,
    
    -
16.0, -16.0,   0.0,
     
16.0,  16.0,  72.0,
    
    -
16.0, -16.0,  0.0,
     
16.0,  16.0,  36.0,
      
0.0,   0.0,  28.0,
    
    -
10.0, -10.0, -10.0,
     
10.0 10.0,  10.0,

      
0.0,   0.0,  14.0
};

float g_fOldHullValues[sizeofg_fNewHullValues )];

Address g_CSViewVectors;

public 
Plugin myinfo 
{
    
name "Change Hull",
    
author "SlidyBat",
    
description "Changes player hulls",
    
version "1.0",
    
url ""
}

// was gonna do OnPluginStart, but not sure if GameRules has been initialized then
public void OnMapStart()
{
    
Handle hGameConf LoadGameConfigFile("changehull.games");
    if(
hGameConf == INVALID_HANDLE)
    {
        
SetFailState"Can't find changehull.games.txt gamedata." );
    }
    
    
g_CSViewVectors GameConfGetAddresshGameConf"g_CSViewVectors" );
    if( 
g_CSViewVectors == Address_Null )
    {
        
SetFailState"Couldn't get address of g_CSViewVectors" );
    }
    
    for( 
int i 0sizeofg_fNewHullValues ); i++ )
    {
        
g_fOldHullValues[i] = view_as<float>( LoadFromAddressg_CSViewVectors view_as<Address>( i*), NumberType_Int32 ) );
        
StoreToAddressg_CSViewVectors view_as<Address>( i*), view_as<int>( g_fNewHullValues[i] ), NumberType_Int32 );
    }
    
    
delete hGameConf;
}

public 
void OnPluginEnd()
{
    
// restore the original hull values, if we patched them.
    
if( g_CSViewVectors != Address_Null )
    {
        for( 
int i 0sizeofg_fOldHullValues ); i++ )
        {
            
StoreToAddress(g_CSViewVectors view_as<Address>( i*), view_as<int>( g_fOldHullValues[i] ), NumberType_Int32 );
        }
    }

You could also possibly set these collision hulls separately by player if you set the values on PreThink, but I haven't tested this out myself.

One of the obvious issues is prediction, since this value is also hardcoded in the client. This is especially obvious when you change height of hull and you hit something above you, due to the client prediction it spases out a bit. Other than that I've found that when there isn't any lag it works alright (although a little snappy in some cases).

Last edited by hmmmmm; 03-09-2018 at 02:11. Reason: Fix linux gamedata
hmmmmm is offline