Raised This Month: $32 Target: $400
 8% 

Getting user fps


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Empowers
BANNED
Join Date: Feb 2009
Location: Ukraine
Old 04-04-2010 , 09:26   Getting user fps
Reply With Quote #1

Getting user fps:
PHP Code:
#include <amxmodx>
#include <engine>

new g_count[33]
new 
g_fps[33]

public 
plugin_init() {
    
register_plugin("Get FPS""1.0""Empower")
    
register_clcmd("say fps","get_fps")
}

public 
get_fps(id)
{
    
client_print(id,print_chat,"Your fps is: %i",g_fps[id])
    
    return 
PLUGIN_HANDLED;
}

public 
client_PostThink(id)
{
    
g_count[id]++
    
    static 
lastendtime[33]
    
// did second passed?
    
if (floatround(get_gametime())==lastendtime[id]) return;
    
    
lastendtime[id] = floatround(get_gametime())
    
    
g_fps[id] = g_count[id]
    
g_count[id] = 0

For me and people on my server gives exact value. No ±.

Last edited by Empowers; 04-06-2010 at 14:06.
Empowers is offline
Send a message via ICQ to Empowers
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 04-04-2010 , 10:54   Re: get user fps
Reply With Quote #2

You tested on your listenserver.
__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 04-04-2010 , 11:41   Re: get user fps
Reply With Quote #3

Again that. If I'm right there is already such plugin.
__________________
Arkshine is offline
Empowers
BANNED
Join Date: Feb 2009
Location: Ukraine
Old 04-04-2010 , 13:28   Re: get user fps
Reply With Quote #4

Quote:
Originally Posted by Arkshine View Post
Again that. If I'm right there is already such plugin.
I don't know. I have written this code by myself

Quote:
Originally Posted by ConnorMcLeod View Post
You tested on your listenserver.
no on dedicated server..
Empowers is offline
Send a message via ICQ to Empowers
Old 04-11-2010, 12:12
Hawk552
This message has been deleted by Hawk552.
Lt.RAT
Member
Join Date: Sep 2008
Location: Russia Yekaterinburg
Old 04-15-2010 , 17:21   Re: Getting user fps
Reply With Quote #5

Again it

Atm most coders uses too many methods for it
For Example:
1) getting server time and calculating fps via it
Code:
 
//Credits to Coderiz aka Skyjur
#include <amxmodx>
#include <amxmisc>
#include <fakemeta>

/*.....*/
new Float:f1
new Float:plr_fps_cof[33]
new Float:plr_frame_time[33]

public plugin_init() 
{
        /*.....*/        
        register_forward(FM_PlayerPreThink, "preThink")
}

public preThink(id)
{
        f1 = get_gametime()
        plr_fps_cof[id] = (10 * plr_fps_cof[id] + 100.0 * (f1 - plr_frame_time[id])) / 11
        plr_frame_time[id] = f1
}
this one with filter, also it could be without it...

2) best code but still with server time constituent
Code:
	
static Float:fFrameTime
global_get(glb_frametime, fFrameTime)
3) the best way to avoid server time constituent:
in hlsdk (pm_shared.c PM_PlayerMove) we can find such code for getting player fps for performing movement
Code:
	// # of msec to apply movement
	pmove->frametime = pmove->cmd.msec * 0.001;
We can use same method. Unfortunaly cmd.msec transimitted in 1 byte. How to write time in 1 byte? It`s easy For example client have 91 fps (1/91)=0,010989 seconds, then this value multiply by 1000 (10,989), cut off (10) and then transmitted to server.
Minimal client fps via fps_max = 20, so maximal value in cmd.msec = 50 ((1/20)*1000 = 50)
And minimal cmd.msec value could be find with 1000 fps. When player is dead and there is no alive movement for him, client sends to server cmd.msec = 0 (+1 way to isPlayerAlive )

Let`s perform reverse conversion: frametime=10*0,001=0,01 => 100 fps. So real fps for movement could be much different from client (in current example 9%)

Code to retrieve cmd.msec:
Code:
#include <amxmodx>
#include <fakemeta>

public plugin_init() 
{
        /*.....*/        
	register_forward(FM_CmdStart, "cmdStart");
}
new gFrameTime[33][2]

new Float:gFrameTimeInMsec[33]

public cmdStart(id, uc_handle, seed)
{
	gFrameTime[id][1] = gFrameTime[id][0]; //maybe u dont need it
	gFrameTime[id][0] = get_uc(uc_handle, UC_Msec); // Our cmd.msec

	gFrameTimeInMsec[id] = gFrameTime[id][0] * 0.001;
}
Also cmd.msec uses in calculation of
Code:
pmove->waterjumptime -= pmove->cmd.msec; //CD_WaterJumpTime
pmove->flTimeStepSound -= pmove->cmd.msec; //pev_flTimeStepSound
pmove->flDuckTime -= pmove->cmd.msec; //pev_flDuckTime
pmove->flSwimTime -= pmove->cmd.msec; //pev_flSwimTime
and others (pev_fuser2 etc)
NOTE: If u set fps_max 101, and developer 1, your client will send to server UC_Msec = 9, that means for prediction code 111,+ fps. So really by setting fps_max 101 its real 101 fps, and better to force fps to value = 100 and not 101 in that case in many other protection plugins.

Also u can use it to predict or prove some movement values, for example:
Log of vertical movement after jump
Code:
Frame1: origin[2]=-155,968750 ; velocity[2]=000,000000 ; UC_Msec=16
Frame2: origin[2]=-151,777893 ; velocity[2]=255,528167 ; UC_Msec=19
Frame3: origin[2]=-147,067260 ; velocity[2]=240,328155 ; UC_Msec=20
We want to know velocity[2] at jump off:
F1.velocity[2] = F2.velocity[2] + F1.pev_gravity*F1.sv_gravity*F1.UC_Msec*0,001 = 255,528167+1,0*800,0*16*0,001 = 268,328167;
For example knowing of real velocity[2] at jump off we could calculate height=velocity[2]*velocity[2]/(800*2)

Also we can find next velocity[2]:F3.velocity[2] = F2.velocity[2] - F2.pev_gravity*F2.sv_gravity*F2.UC_Msec*0,001 = 255,528167-1,0*800,0*19*0,001 = 240,328167; (as you see difference 0,000012 unit)

With such knowledge we can detect slide surfaces (if they changes our velocity[2]), edge bugs, wall bugs, we can write universal protection for longjump stats (and drop all hooks of +hook, slap commands etc), real emulation of movement for custom entity (in some rare cases) and many other things.

Add: if you want to find F3.origin[2] from F2 you can use: F3.origin[2] = F2.origin[2] + F2.UC_Msec*0,001*(F2.velocity[2] - F2.pev_gravity*F2.sv_gravity*F2.UC_Msec*0,001/2) = -151,777893 + 19*0,001*(255,528167 - 1,0*800,0*19*0,001/2) = -147,067258 (0,000002 from original) Isn`t easy

Last edited by Lt.RAT; 04-15-2010 at 17:53.
Lt.RAT is offline
Send a message via ICQ to Lt.RAT
xPaw
Retired AMX Mod X Moderator
Join Date: Jul 2008
Old 04-16-2010 , 12:46   Re: Getting user fps
Reply With Quote #6

Lt.RAT:
And he wanted only to get user fps...
__________________
xPaw is offline
Old 04-25-2010, 06:23
Empowers
This message has been deleted by Hawk552.
Old 04-25-2010, 12:12
Hawk552
This message has been deleted by Hawk552.
Lt.RAT
Member
Join Date: Sep 2008
Location: Russia Yekaterinburg
Old 04-26-2010 , 12:07   Re: Getting user fps
Reply With Quote #7

Quote:
Originally Posted by Empowers View Post
Thx man, but when testing get_uc(uc_handle, UC_Msec) always returns 0. Why that could be?
Tested code - it`s works
Code:
#include <amxmodx>
#include <fakemeta>

public plugin_init() 
{
	register_plugin("Cmd test", "0.1", "Lt.RAT")
	register_forward(FM_CmdStart, "cmdStart");
}

new gFrameTime[33][2]

new Float:gFrameTimeInMsec[33]

public cmdStart(id, uc_handle, seed)
{

	gFrameTime[id][1] = gFrameTime[id][0]; 
	gFrameTime[id][0] = get_uc(uc_handle, UC_Msec); 

	gFrameTimeInMsec[id] = gFrameTime[id][0] * 0.001;

	engclient_print(id, engprint_console, "DBG: %d %f", gFrameTime[id][0], gFrameTimeInMsec[id]);
}
Example of plugin output:
Code:
DBG: 12 0.012000
DBG: 10 0.010000
DBG: 10 0.010000
DBG: 14 0.014000
DBG: 10 0.010000
DBG: 11 0.011000
DBG: 11 0.011000
DBG: 10 0.010000
So it works, dunno why it AlwayS returns 0 for you. But it return 0, if you are not alive, or have FL_FROZEN flag (it can be used for kreedz timers) (+maybe some other unknown for me cases).
Lt.RAT is offline
Send a message via ICQ to Lt.RAT
Seta00
The Seta00 user has crashed.
Join Date: Jan 2010
Location: Berlin
Old 04-26-2010 , 13:31   Re: Getting user fps
Reply With Quote #8

Quote:
Originally Posted by Lt.RAT View Post
With such knowledge we can detect slide surfaces (if they changes our velocity[2]), edge bugs, wall bugs, we can write universal protection for longjump stats (and drop all hooks of +hook, slap commands etc), real emulation of movement for custom entity (in some rare cases) and many other things.
Did you test the slide surface/edge bugs/etc stuff?
Seta00 is offline
Lt.RAT
Member
Join Date: Sep 2008
Location: Russia Yekaterinburg
Old 04-26-2010 , 16:31   Re: Getting user fps
Reply With Quote #9

Quote:
Originally Posted by Seta00 View Post
Did you test the slide surface/edge bugs/etc stuff?
Yes, ofc. xPaw uses in his edgebug plugin that kind of initial detection (dunno release he it or not ) Also Im using it in new ljstats project for universal detection of illegal jumps, so no need to catch [register_clcmd("+hook", "someFunc"...] anymore, amx_slap commands etc etc. That protection have all things in ~15 lines of plugin. If something changes standard HL physics it would be detected. (JumpBug, EdgeBug etc, changes it too but in special manner, so u can analyze change and understand what changes your movement)

PS Within the next few months I haven`t enough free time to finish my plugins.
Lt.RAT is offline
Send a message via ICQ to Lt.RAT
Seta00
The Seta00 user has crashed.
Join Date: Jan 2010
Location: Berlin
Old 04-28-2010 , 17:17   Re: Getting user fps
Reply With Quote #10

Quote:
Originally Posted by Lt.RAT View Post
Yes, ofc. xPaw uses in his edgebug plugin that kind of initial detection (dunno release he it or not ) Also Im using it in new ljstats project for universal detection of illegal jumps, so no need to catch [register_clcmd("+hook", "someFunc"...] anymore, amx_slap commands etc etc. That protection have all things in ~15 lines of plugin. If something changes standard HL physics it would be detected. (JumpBug, EdgeBug etc, changes it too but in special manner, so u can analyze change and understand what changes your movement)

PS Within the next few months I haven`t enough free time to finish my plugins.
What about surfing? Does it breaks the physics rules checked by your method?

Last edited by Seta00; 04-28-2010 at 17:20.
Seta00 is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


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


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