AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Plugins (https://forums.alliedmods.net/forumdisplay.php?f=108)
-   -   [ANY] Input Hooks - DevTools (1.9) [15-Jun-2022] (https://forums.alliedmods.net/showthread.php?t=319141)

Silvers 10-14-2019 13:50

[ANY] Input Hooks - DevTools (1.9) [15-Jun-2022]
 
23 Attachment(s)


Related Plugins:

About:
  • Prints entity input data to chat (client) or console (server).
  • Can specify which entities to listen for or filter out.
  • Example command: sm_input_watch "logic_script,logic_entity,logic_relay"


Supported Games:
  • CSS
  • CSGO
  • DODS
  • L4D1
  • L4D2
  • TF2
  • Request support if required.


Thanks:
  • Dr!fter - DHooks "AcceptInput" example this is based on.
  • Dragokas - For the request and code additions.


Admin Commands: (requires "z" flag)

PHP Code:

sm_input_listen    // Starts listening to all inputs. Filters or listens for classnames from the filter and listen cvars.
sm_input_stop      // Stop printing entity inputs.
sm_input_watch     // Start printing entity inputs. Usage: sm_input_watch <classnames to watch, separate by commas> 



ConVars:

Saved to sm_input_hooks.cfg in your servers \cfg\sourcemod\ folder.

PHP Code:

// Do not hook and show output data from these classnames, separate by commas (no spaces). Only works for sm_output_listen command.
sm_input_hooks_filter ""

// Only hook and display output data from these classnames, separate by commas (no spaces). Only works for sm_output_listen command.
sm_input_hooks_listen ""

// 0=Off. 1=Logs all input data to logs/input_hooks.log file.
sm_input_hooks_logging "0"

// Output Hooks - DevTools plugin version.
sm_input_hooks_version 



Changes:
Code:

1.9 (15-Jun-2022)
    - Changed some white spacing sizes when printing.
    - Removed quotes when printing various information, for a cleaner look.

1.8 (29-Apr-2022)
    - Added support for various types. Thanks to "Ilusion9" for coding.

1.7 (10-Apr-2022)
    - Added support for the "Pirates, Vikings and Knights II" game. GameData updated. Thanks to "Marttt" for the offsets.
    - Fixed crash when retrieving Color255 values. Thanks to "Ilusion9" for reporting and "domino_" for helping fix.

1.6 (20-May-2021)
    - Fixed using a static list for reading values instead of strings. Thanks to "bottiger" for fixing.

1.5 (03-Mar-2021)
    - Fixed crashing on "SetTotalItems" input. Thanks to "Marttt" for reporting.

1.4a (30-Sep-2020)
    - Compatibility update for L4D2's "The Last Stand" update.
    - L4D2: GameData .txt file updated.

1.4 (10-May-2020)
    - Added better error log message when gamedata file is missing.
    - Various changes to tidy up code.

1.3 (16-Mar-2020)
    - Fixed server crashing when reading "InValue" commands.
    - Fixed not logging when server is empty.
    - Fixed logging code in the wrong place.

1.2 (05-Dec-2019)
    - Added cvar "sm_input_hooks_logging" to enable or disable logging.
    - Added entity name to info. - Thanks to "Dragokas" for coding.
    - Added ability to log info in file "logs/input_hooks.log". - Thanks to "Dragokas" for coding.

1.1 (15-Nov-2019)
    - Fixed multiple classnames not working for the watch command and cvars.

1.0 (14-Oct-2019)
    - Initial release.



Requirements:

Installation:
DO NOT click 'Get Plugin' or it will fail to compile because this plugin requires DHooks!
  1. Download the .smx file and put into your servers \addons\sourcemod\plugins folder.
  2. Download the .txt gamedata file and put into your servers \addons\sourcemod\gamedata\ folder.


Updating from 1.1 or older:
  • New cvars have been added: use the Cvar Configs Updater, or delete the old cvars config or manually add them.

Dragokas 10-14-2019 17:03

Re: [ANY] Input Hooks - DevTools
 
Thanks again. This make development a looooooot easier.

andi67 10-14-2019 17:38

Re: [ANY] Input Hooks - DevTools
 
No.1 ....

Alexander_Mirny 10-14-2019 17:43

Re: [ANY] Input Hooks - DevTools
 
not bad :up:

lugui 10-18-2019 07:52

Re: [ANY] Input Hooks - DevTools
 
very nice, it will be helpful

Silvers 11-15-2019 03:51

Re: [ANY] Input Hooks - DevTools (1.1) [15-Nov-2019]
 
Plugin updated.

Quote:

1.2 (05-Dec-2019)
- Added cvar "sm_input_hooks_logging" to enable or disable logging.
- Added entity name to info. - Thanks to "Dragokas" for coding.
- Added ability to log info in file "logs/input_hooks.log". - Thanks to "Dragokas" for coding.

1.1 (15-Nov-2019)
- Fixed multiple classnames not working for the watch command and cvars.

Silvers 03-16-2020 03:13

Re: [ANY] Input Hooks - DevTools (1.3) [16-Mar-2020]
 
Code:

1.3 (16-Mar-2020)
    - Fixed server crashing when reading "InValue" commands.
    - Fixed not logging when server is empty.
    - Fixed logging code in the wrong place.

If there are any other crashes please let me know which map, or better which command (you can find out by putting the following code after the "DHookGetParamString" line and seeing the last result in server console before crash).

Code:

PrintToServer("%s", command);

Ilusion9 08-25-2020 03:24

Re: [ANY] Input Hooks - DevTools (1.4) [10-May-2020]
 
https://crash.limetech.org/gv4g4mf7khdl

linux
sm 1.10
dhooks for 1.10

PHP Code:


I modified this
:
public 
MRESReturn AcceptInput(int entityHandle hReturnHandle hParams)
{
    if (
entity 0)
    {
        
entity EntRefToEntIndex(entity);
    }
    
    
char input[128];
    
DHookGetParamString(hParams1inputsizeof(input));

    
char classname[128];
    
GetEntityClassname(entityclassnamesizeof(classname));
    
    
int activator = -1;
    if (!
DHookIsNullParam(hParams2))
    {
        
activator DHookGetParam(hParams2);
    }
    
    
// Print etc..
    
return MRES_Ignored;



Ilusion9 08-25-2020 03:34

Re: [ANY] Input Hooks - DevTools (1.4) [10-May-2020]
 
He does the same thing here:
PHP Code:

    if( pThis )
        
pThis EntRefToEntIndex(pThis); 

And I've seen entities with negative values or higher than 4096, I thought entities can only have indexes between 0 and 4096..,

Silvers 08-26-2020 19:01

Re: [ANY] Input Hooks - DevTools (1.4) [10-May-2020]
 
Quote:

Originally Posted by Ilusion9 (Post 2715440)

Which game? Which plugin version? You modified that (and removed stuff?) why?

It has a specific check for reading "InValue" commands which would crash when reading with any other method, there maybe other commands which need to be read as objects instead, you can debug where its crashing by printing/logging the "command" variable value and seeing the last one printed before crash, and let me know what it is so I can fix the plugin.



Quote:

Originally Posted by Ilusion9 (Post 2715444)
He does the same thing here:
PHP Code:

    if( pThis )
        
pThis EntRefToEntIndex(pThis); 

And I've seen entities with negative values or higher than 4096, I thought entities can only have indexes between 0 and 4096..,

Because negative entity indexes are more than likely going to be entity references which is used by non-networked entities (their index is > 2048 or > 4096 depending on the game and their max entity limits). See the [TUT] SourcePawn Scripting - Tips, Basics to Advanced for more details.

The plugin should probably be checking EntRefToEntIndex != INVALID_ENT_REFERENCE after converting but I don't see why an input triggered at this stage would ever be an invalid entity (probably the reason I left out the check to see if anyone reports an invalid entity error - I specifically do this for various plugins where I think a check would not have to be required and wait for any error reports, rarely some trigger errors and sometimes only very rarely).

Ilusion9 08-27-2020 03:59

Re: [ANY] Input Hooks - DevTools (1.4) [10-May-2020]
 
Quote:

Originally Posted by Silvers (Post 2715644)
Which game? Which plugin version? You modified that (and removed stuff?) why?

It has a specific check for reading "InValue" commands which would crash when reading with any other method, there maybe other commands which need to be read as objects instead, you can debug where its crashing by printing/logging the "command" variable value and seeing the last one printed before crash, and let me know what it is so I can fix the plugin.

CSGO, I put back that thing with "InValue" etc, but it seems the crash happens when I kill entities on SDKHook_Spawn with AcceptEntitiyInput(entitiy, "Kill");
I dhook AcceptInput on SDKHook_SpawnPost and no crashes.

Marttt 02-28-2021 14:58

Re: [ANY] Input Hooks - DevTools (1.4a) [10-May-2020]
 
I have found a plugin conflict with [L4D2] Gas Cans by disawar1.

After many tests, I noticed that on c1m4_atrium map, when I enable the listen mode (sm_input_listen), right after pressing the elevator button the server crashes.

Here is the crash log.

I extracted the part from disawar1 code that triggers the crash and made a short plugin to test it.

To reproduce: Go to c1m4_atrium map, use !input_listen and then !testcrash.

Just reporting in case someone has the same problem.

Code snippet for testing below:

Spoiler


EDIT: Fixed by Silvers in newer versions.

Silvers 03-03-2021 04:11

Re: [ANY] Input Hooks - DevTools (1.5) [03-Mar-2021]
 
Thanks, fixed. Example crash plugin was very helpful to test.

bottiger 05-11-2021 18:56

Re: [ANY] Input Hooks - DevTools (1.5) [03-Mar-2021]
 
Quote:

Originally Posted by Silvers (Post 2739053)
Thanks, fixed. Example crash plugin was very helpful to test.

Why not read fieldType to determine the type of the union?

https://github.com/ValveSoftware/sou...ariant_t.h#L37

Silvers 05-12-2021 03:52

Re: [ANY] Input Hooks - DevTools (1.5) [03-Mar-2021]
 
Quote:

Originally Posted by bottiger (Post 2746576)
Why not read fieldType to determine the type of the union?

https://github.com/ValveSoftware/sou...ariant_t.h#L37

How?

bottiger 05-13-2021 19:18

Re: [ANY] Input Hooks - DevTools (1.5) [03-Mar-2021]
 
Quote:

Originally Posted by Silvers (Post 2746602)
How?

The offset of fieldType is the largest size of the union + sizeof(eVal).

Silvers 05-14-2021 22:19

Re: [ANY] Input Hooks - DevTools (1.5) [03-Mar-2021]
 
Quote:

Originally Posted by bottiger (Post 2746753)
The offset of fieldType is the largest size of the union + sizeof(eVal).

How can it be done in this plugin? How do I determine if I should be reading an int or string etc? When calling DHookGetParamObjectPtrVar for an int the server will crash if it's supposed to be a string.

bottiger 05-15-2021 15:00

Re: [ANY] Input Hooks - DevTools (1.5) [03-Mar-2021]
 
Quote:

Originally Posted by Silvers (Post 2746850)
How can it be done in this plugin? How do I determine if I should be reading an int or string etc? When calling DHookGetParamObjectPtrVar for an int the server will crash if it's supposed to be a string.

Hi sorry I am not well versed in dhooks, I just tried using it last week.

But you could try this: I don't know if the offset should be divided by sizeof(int).

int fieldtype = DHookGetParamObjectPtrVar(hParams, 4, offset_of_fieldType, ObjectValueType_Int),

then check if fieldtype == FIELD_STRING or FIELD_INTEGER or some other type here:

https://github.com/ValveSoftware/sou.../datamap.h#L28

Silvers 05-15-2021 18:20

Re: [ANY] Input Hooks - DevTools (1.5) [03-Mar-2021]
 
I don't think that's the same offset as NetProps and DataMaps which would be possible to get the param type.

bottiger 05-15-2021 23:28

Re: [ANY] Input Hooks - DevTools (1.5) [03-Mar-2021]
 
Quote:

Originally Posted by Silvers (Post 2746904)
I don't think that's the same offset as NetProps and DataMaps which would be possible to get the param type.

Not sure what you mean by being the same offset as netprops or datamaps.

The acceptinput function you are hooking has a variant_t struct.

AcceptInput( const char *szInputName, CBaseEntity *pActivator, CBaseEntity *pCaller, variant_t Value, int outputID );

You have the definition of this struct right here:

PHP Code:

class variant_t
{
    
union
    
{
        
bool bVal;
        
string_t iszVal;
        
int iVal;
        
float flVal;
        
float vecVal[3];
        
color32 rgbaVal;
    };
    
CHandle<CBaseEntity> eVal; // this can't be in the union because it has a constructor.

    
fieldtype_t fieldType

All you have to do is access the fieldType member which has nothing to do with datamaps or netprops. It is just a tagged union.

Anyway I didn't want to spent any more time on this, but I was confused by what you meant and thought it couldn't be that hard so I decided to try it myself and it works.

PHP Code:

public MRESReturn AcceptInput(int pThisHandle hReturnHandle hParams)
{
    
// Get args
    
static char param[128];
    static 
char command[128];
    
DHookGetParamString(hParams1commandsizeof(command));

    
int paramType DHookGetParamObjectPtrVar(hParams416ObjectValueType_Int);
    
PrintToServer("param type %i"paramType); 

param type 0
2091 math_counter. (GetValue). "counter" (). 1 player caller 50
param type 1
2079 info_target. (InValue). "case" (). 1 player caller 50

Silvers 05-16-2021 04:19

Re: [ANY] Input Hooks - DevTools (1.5) [03-Mar-2021]
 
Quote:

Originally Posted by bottiger (Post 2746919)
-

Excellent, thanks very much! Will update to use this instead.

Ilusion9 04-10-2022 06:16

Re: [ANY] Input Hooks - DevTools (1.6) [20-May-2021]
 
https://crash.limetech.org/odrgfbzpfqnt
DHookGetParamObjectPtrString crashed the server

Silvers 04-10-2022 08:22

Re: [ANY] Input Hooks - DevTools (1.6) [20-May-2021]
 
Quote:

Originally Posted by Ilusion9 (Post 2776299)
https://crash.limetech.org/odrgfbzpfqnt
DHookGetParamObjectPtrString crashed the server

I've added you to Steam to send a debug version if you could test with that and replicate the crash, then I'll be able to fix, I don't think Accelerator would show which value it was trying to access but worth checking if you can login and have a look.

Fixed. Thanks for testing!

Code:

1.7 (10-Apr-2022)
    - Added support for the "Pirates, Vikings and Knights II" game. GameData updated. Thanks to "Marttt" for the offsets.
    - Fixed crash when retrieving Color255 values. Thanks to "Ilusion9" for reporting and "domino_" for helping fix.



All times are GMT -4. The time now is 22:28.

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