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

CScriptNetPropManager rewrite #260

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from

Conversation

samisalreadytaken
Copy link

@samisalreadytaken samisalreadytaken commented Dec 15, 2023

This is an important update that elevates the abilities of entity manipulation in vscript. It allows read/write of all network properties, data and prediction descriptions, including physics objects and dynamic CUtlVector fields.

A few things to note,

GetPropType() and HasProp() can't yet return array and datatable types.

Parsing member names separated with '.' temporarily modifies the source strings from the Squirrel string table. This is fast and harmless, though probably not very desired.

Indexing data table arrays (a data table array consisting of data tables) is not possible due to the original design of the NetProps interface. Though this doesn't apply to many cases, and I don't think CAI_AllySpeechManager::m_ConceptCategoryTimers is terribly important.

Due to the nature of a single utility (NetProps) being used for both net props and data description maps, some vars overshadow others, such as CPlayerResource::m_iHealth over CBaseEntity::m_iHealth. I'm not aware of many instances of this though.

The debug function NetProps.Dump() can be used to view all available fields of entities. This is better than a static field dump you might find elsewhere as the values of the variables are also displayed.

An example dump: https://gist.github.com/samisalreadytaken/7b85fa38a2c9cac9bfefa3440f9efb4f

for ( local ent; ent = Entities.Next( ent ); )
{
	local classname = ent.GetClassname();
	if ( SERVER_DLL )
	{
		NetProps.Dump( ent, "datadump_"+classname+"_sv.log" )
	}
	else
	{
		local i = classname.find(" ");
		if ( i != null )
			classname = classname.slice( i+1, classname.len() );
		NetProps.Dump( ent, "datadump_"+classname+"_cl.log" )
	}
}

As for performance, using this NetProps.GetPropInt( player, "m_iHealth" ) over a native function player.GetHealth() is 3.6 times slower, not great, not terrible.

Differences to the L4D2 implementation:

They return vec3_origin on invalid input, this returns vec3_invalid.

This can access vector indices via float accessors.

This can access 8 bit int arrays as both strings and integers. It's not possible to tell apart a char array from a cstring, so access is allowed unless the char array contains a null char.

This can access more variables than theirs, most notably CUtlVectors and physics objects.

According to their docs, they don't clamp inputs, this does.


Does this PR close any issues?

PR Checklist

  • My PR follows all guidelines in the CONTRIBUTING.md file
  • My PR targets a develop branch OR targets another branch with a specific goal in mind

Copy link

@felis-catus felis-catus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, in No More Room in Hell we have merged this pull request into a pending update, and so far we haven't encountered blocking issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants