Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Con_Printf() hook #222

Merged
merged 16 commits into from Oct 25, 2021
Merged

Conversation

francoromaniello
Copy link
Contributor

Related to #219

@wopox1337
Copy link
Collaborator

Why do you need this hook?

@RauliTop
Copy link
Contributor

Why do you need this hook?

It's commented here: #219

@wopox1337 wopox1337 changed the title Implement Con_Printf hook Implement Con_Printf() hook Oct 23, 2021
@wopox1337 wopox1337 self-requested a review October 23, 2021 10:43
@wopox1337
Copy link
Collaborator

@francoromaniello update PR please

@wopox1337
Copy link
Collaborator

wopox1337 commented Oct 23, 2021

Thanks. What's about pointers style?

reapi/src/hook_list.h Outdated Show resolved Hide resolved
Co-authored-by: justgo97 <hamdi2050@live.com>
reapi/src/hook_list.cpp Outdated Show resolved Hide resolved
@wopox1337
Copy link
Collaborator

test passed

Server Median FPS: `875.80` (min=163.92, max=924.80)
#include <amxmodx>
#include <reapi>

static HookChain: hook

public plugin_init() {
	DisableHookChain(
		(hook = RegisterHookChain(RH_Con_Printf, "RH_Con_Printf_Pre"))
	)

	set_task(0.1, "test", .flags = "b")
}

static Msg[ 100 ];


public test() {
	EnableHookChain(hook)
	server_cmd("stats"); server_exec()
	DisableHookChain(hook)

	static Array: arrayFPS
	if(!arrayFPS)
		arrayFPS = ArrayCreate()

	static tokens[ 14 ][ 32 ]

	for ( new i; i < sizeof tokens; i++ ) {
		trim( Msg );
		strtok( Msg, tokens[ i ], charsmax(tokens[]), Msg, charsmax( Msg ), ' ' )
	}

	static
		Float: currentFPS,
		Float: minFPS = cellmax,
		Float: maxFPS = cellmin

	currentFPS = str_to_float(tokens[12])

	ArrayPushCell(arrayFPS, currentFPS)

	if (currentFPS > maxFPS)
		maxFPS = currentFPS

	if (currentFPS < minFPS && currentFPS > 0.0)
		minFPS = currentFPS

	new median = ArrayGetMedian(arrayFPS)

	server_print("Server Median FPS: `%.2f` (min=%.2f, max=%.2f)",
		median, minFPS, maxFPS)
}

public RH_Con_Printf_Pre( const message[] ) {
	copy( Msg, charsmax( Msg ), message )

	return HC_SUPERCEDE
}

stock Float: ArrayGetMedian( const Array: array ) {
	SortADTArray(array, Sort_Ascending, Sort_Float)
	new n = ( ArraySize(array) + 1 ) / 2 - 1

	return Float: ArrayGetCell(array, n)
}

@wopox1337 wopox1337 merged commit dd1fdae into s1lentq:master Oct 25, 2021
@francoromaniello francoromaniello deleted the Con_Printf branch October 25, 2021 17:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants