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

Revise natives code #40

Merged
merged 9 commits into from
Jul 23, 2023
Merged

Revise natives code #40

merged 9 commits into from
Jul 23, 2023

Conversation

Kenzzer
Copy link
Collaborator

@Kenzzer Kenzzer commented Jul 22, 2023

What's changed ?

Instead of all the natives being inside various include files, and then all included by natives.h we instead divide those natives into multiple .hpp and .cpp files, available in the natives directory. Very much mirroring the setup of our .inc files.

New way to register natives

No more global array, instead an std::vector is passed around by reference. The natives are then added to it by each .cpp module. Furthermore, macros to define native functions have been eliminated. Everything are now locally defined functions, only available in their respective .cpp file.

Example :

void setup(std::vector<sp_nativeinfo_t>& natives) {
	area::setup(natives);
	surroundingareas::setup(natives);
	
	tf::nav::setup(natives);

	sp_nativeinfo_t list[] = {
		{"CNavMesh.Address.get", GetAddress},
		{"CNavMesh.IsLoaded", IsLoaded},
		{"CNavMesh.IsAnalyzed", IsAnalyzed},
		{"CNavMesh.IsOutOfDate", IsOutOfDate},
		{"CNavMesh.GetNavAreaCount", GetNavAreaCount},
		{"CNavMesh.CollectSurroundingAreas", CollectSurroundingAreas},
		{"CNavMesh.GetNavAreaByID", GetNavAreaByID},
		{"CNavMesh.GetNearestNavArea", GetNearestNavArea},
		{"CNavMesh.BuildPath", BuildPath},
		{"CNavMesh.GetNavArea", GetNavArea},
		{"CNavMesh.GetNavAreaEntity", GetNavAreaEntity},
	};

	natives.insert(natives.end(), std::begin(list), std::end(list));
}

New coding style for {}

As of this PR, I wish that we adopt Rust's styling for .cpp and .hpp files. The extension never had a coding style to begin with, so I believe this is a good point to start introducing some.

New/updated natives

  • Added the following natives to the extension. The usefulness and 0 gamedata cost more than enough warrants the addition of such a useful methodmap to the extension.
CTakeDamageInfo.CTakeDamageInfo
GetInflictor
SetInflictor
GetWeapon
SetWeapon
GetAttacker
SetAttacker
GetDamage
SetDamage
GetMaxDamage
SetMaxDamage
ScaleDamage
AddDamage
SubtractDamage
GetDamageBonus
SetDamageBonus
GetDamageBonusProvider
GetBaseDamage
BaseDamageIsValid
GetDamageForce
SetDamageForce
ScaleDamageForce
GetDamageForForceCalc
SetDamageForForceCalc
GetDamagePosition
SetDamagePosition
GetReportedPosition
SetReportedPosition
GetDamageType
SetDamageType
AddDamageType
GetDamageCustom
SetDamageCustom
GetDamageStats
SetDamageStats
SetForceFriendlyFire
IsForceFriendlyFire
GetAmmoType
SetAmmoType
GetAmmoName
GetPlayerPenetrationCount
SetPlayerPenetrationCount
GetDamagedOtherPlayers
SetDamagedOtherPlayers
SetCritType
GetCritType
  • Fixed CBaseNPC and CExtNPC natives not verifying invalid npc index. Leading to spectacular nullpointer crashes.

Prepare for TF2 x64 bits

In addition to everything above, speculative but correct changes have been made to hopefully prepare enough the extension for the eventual release of 64bits tf2. See alliedmodders/hl2sdk#127 for further details.

@KitRifty KitRifty self-requested a review July 22, 2023 19:32
Copy link
Collaborator

@KitRifty KitRifty left a comment

Choose a reason for hiding this comment

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

Very nice work refactoring the natives code. This is much preferred over having that huge list in the main natives file. However there are a couple of types and a handful of instances where pawn addresses aren't being converted to pointers, and vice versa.

extension/sourcesdk/takedamageinfo.cpp Show resolved Hide resolved
extension/natives/takedamageinfo.cpp Outdated Show resolved Hide resolved
extension/natives/takedamageinfo.cpp Show resolved Hide resolved
extension/natives/nav/area.cpp Outdated Show resolved Hide resolved
extension/natives/nav/area.cpp Outdated Show resolved Hide resolved
extension/natives/nextbot/path.cpp Outdated Show resolved Hide resolved
extension/natives/nextbot/path.cpp Outdated Show resolved Hide resolved
extension/natives/nextbot/path.cpp Outdated Show resolved Hide resolved
extension/natives/nextbot/path.cpp Outdated Show resolved Hide resolved
extension/natives/nextbot/path.cpp Outdated Show resolved Hide resolved
@Kenzzer Kenzzer merged commit fe96b5f into master Jul 23, 2023
5 checks passed
@Kenzzer Kenzzer deleted the natives branch July 23, 2023 16:00
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