AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Code Snippets/Tutorials (https://forums.alliedmods.net/forumdisplay.php?f=83)
-   -   Orpheu: Engine PM Functions (https://forums.alliedmods.net/showthread.php?t=118476)

joaquimandrade 02-11-2010 10:30

Orpheu: Engine PM Functions
 
1 Attachment(s)
In half life engine there is a part of the code where the physic calculations to player movement happen (jumping, ducking, moving on water, no clipping, etc). It is unexplored in scripting because those functions are not acessible normally. With orpheu you can use them.

The entry point for the calculations is the function PM_Move, that has the following header:

PHP Code:

PM_Move struct playermove_s *ppmoveint server 

The first argument is a structure (a group of data belonging to a player) that is saved when PM_Move is called and then used in other PM functions.

You can see the structure data here:

http://metamod.org/sdk/dox/pm__defs_8h-source.html

When using Orpheu to hook PM functions the way of accessing the ppmove structure varies from PM_Move to other functions.

In PM_Move you can use it directly:
PHP Code:

public PM_Move(ppmove,server)
{
    new 
Float:gravity Float:OrpheuGetParamStructMember(1,"gravity")


In other functions you have to get ppmove from memory and use it after.
We need to declare in a file how to obtain it from memory but that part is already made by me so you just have to care with using it:

PHP Code:

OrpheuStruct:get_ppmove()
{        
    return 
OrpheuGetStructFromAddress(OrpheuStructPlayerMove,OrpheuMemoryGet("ppmove"))
}
   
public 
PM_Duck()
{
    new 
OrpheuStruct:ppmove get_ppmove()
        
    new 
gravity OrpheuGetStructMember(ppmove,"gravity")


To retrieve the id of a player you should use the member of ppmove called "player_index":

PHP Code:

new id OrpheuGetStructMember(ppmove,"player_index") + 

A full example on blocking duck for non bot players:


PHP Code:


#include <amxmodx>
#include <orpheu>
#include <orpheu_advanced>
#include <orpheu_memory>
    
public plugin_init()
{        
    
OrpheuRegisterHook(OrpheuGetFunction("PM_Duck"),"OnPM_Duck")
}

public 
OrpheuHookReturn:OnPM_Duck()
{
    new 
OrpheuStruct:ppmove get_ppmove()
    
    new 
id OrpheuGetStructMember(ppmove,"player_index") + 1
    
    
if(is_user_bot(id))
    {
        return 
OrpheuSupercede
    
}
    
    return 
OrpheuIgnored
}

OrpheuStruct:get_ppmove()
{        
    return 
OrpheuGetStructFromAddress(OrpheuStructPlayerMove,OrpheuMemoryGet("ppmove"))


Before using these functions do some research about how they work.
Download hlsdk

And check multiplayer/pm_shared/pm_shared.cpp

As attachment I will provide an example script and files to use those functions out of the box:
Code:

PM_Init
PM_Move
PM_PlayerMove
PM_Jump
PM_PlayStepSound
PM_CatagorizeTextureType
PM_FlyMove
PM_UpdateStepSound
PM_CheckVelocity
PM_WaterMove
PM_CheckWater
PM_SpectatorMove
PM_LadderMove
PM_Physics_Toss
PM_CheckWaterJump
PM_CheckFalling
PM_ReduceTimers
PM_CreateStuckTable

Note that these files are meant to be used for your experiments and thus I did not took the time to create signatures but instead providing their offsets. This means that you should use them for testing only. If you want to release plugins with it make signatures or ask here.

On a last note, PM functions occur in parallel in the server and the client and because of client prediction there are functions that are useless to block since they will occur in the client anyway or at least don't act exactly as expected.

Arkshine 02-11-2010 10:50

Re: Orpheu: Engine PM Functions
 
Quote:

On a last note, PM functions occur in parallel in the server and the client and because of client prediction there are functions that are useless to block since they will occur in the client anyway or at least don't act exactly as expected.
Like things related to the sounds. Wanted to try to block the jump sound, it's always played by the client.

meTaLiCroSS 02-11-2010 11:43

Re: Orpheu: Engine PM Functions
 
Omg, this module rocks :crab:

You can force players to duck? D:

joaquimandrade 02-11-2010 11:50

Re: Orpheu: Engine PM Functions
 
Quote:

Originally Posted by meTaLiCroSS (Post 1085541)
Omg, this module rocks :crab:

You can force players to duck? D:

I guess so.

A simple plugin example of multijump

PHP Code:


#include <amxmodx>
#include <orpheu>
#include <orpheu_advanced>
#include <orpheu_memory>
#include <fakemeta>
    
public plugin_init()
{            
    
OrpheuRegisterHook(OrpheuGetFunction("PM_Jump"),"OnPM_Jump")
}

public 
OrpheuHookReturn:OnPM_Jump()
{    
    new 
OrpheuStruct:ppmove get_ppmove()
    
    if(~
OrpheuGetStructMember(ppmove,"oldbuttons") & IN_JUMP)
    {
        
OrpheuSetStructMember(ppmove,"oldbuttons",OrpheuGetStructMember(ppmove,"oldbuttons") & ~IN_JUMP)    
        
OrpheuSetStructMember(ppmove,"onground",1)    
    }    
}

OrpheuStruct:get_ppmove()
{        
    return 
OrpheuGetStructFromAddress(OrpheuStructPlayerMove,OrpheuMemoryGet("ppmove"))



joaquimandrade 02-11-2010 12:58

Re: Orpheu: Engine PM Functions
 
Quote:

Originally Posted by meTaLiCroSS (Post 1085541)
Omg, this module rocks :crab:

You can force players to duck? D:

This is not exactly what you asked but check if its ok for what you want:

PHP Code:


#include <amxmodx>
#include <orpheu>

public plugin_init()
{            
    
OrpheuRegisterHook(OrpheuGetFunction("PM_Duck"),"OnPM_Duck")
    
OrpheuRegisterHook(OrpheuGetFunction("PM_Move"),"OnPM_Move")
}

public 
OnPM_Move(ppmove,server)
{
    
OrpheuSetParamStructMember(1,"usehull",2)    
}

public 
OrpheuHookReturn:OnPM_Duck()
{    
    return 
OrpheuSupercede



01101101 02-11-2010 17:53

Re: Orpheu: Engine PM Functions
 
What about changing player size?

meTaLiCroSS 02-12-2010 12:40

Re: Orpheu: Engine PM Functions
 
Quote:

Originally Posted by 01101101 (Post 1085903)
What about changing player size?

It's strange, i've tried to hook FM_SetSize to check when it's called: Every frame when is ducking (tested with a message). I have tried to change her size, and nothings changes o.O, and the most strange thing is, SetSize forward is not called and stills with the default size.

Sorry for my bad english :crab::crab:

joropito 02-12-2010 21:24

Re: Orpheu: Engine PM Functions
 
With PM_* hooks it's possible to make func_ladder entities work when spawned from a plugin :)

Lt.RAT 04-19-2010 12:02

Re: Orpheu: Engine PM Functions
 
1 Attachment(s)
I`ve perform decompile of pm_shared.c CS functions with windows library.

Amazing change CTEXTURESMAX to 1024, but whole rest code still with 512 :shock:

All my comments with triple slash, when its possible i`d try to keep HLSDK code, for compare simplification. Also provided Length of functions, if developers changed something - it will be much easier to find.


@Arkshine Please, add it to CSSDK :)

Arkshine 04-19-2010 13:04

Re: Orpheu: Engine PM Functions
 
Thanks you for your contribution, I will add it soon.


All times are GMT -4. The time now is 12:19.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.