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
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions AMBuildScript
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,8 @@ class ExtensionConfig(object):
cxx.cflags += [
'-pipe',
'-fno-strict-aliasing',
#'-Werror',
'-Wall',
'-Werror',
#'-Wall',
'-Wno-unused',
'-Wno-switch',
'-Wno-array-bounds',
Expand Down Expand Up @@ -322,6 +322,7 @@ class ExtensionConfig(object):
cxx.cxxflags += [
'/EHsc',
'/TP',
'/std:c++17'
]
cxx.linkflags += [
'/MACHINE:X86',
Expand Down
29 changes: 28 additions & 1 deletion extension/AMBuilder
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,33 @@ project.sources = [
'sourcesdk/basedoor.cpp',
'sourcesdk/basetoggle.cpp',
'sourcesdk/funcbrush.cpp',
'sourcesdk/takedamageinfo.cpp',
'natives.cpp',
'natives/cbasenpc.cpp',
'natives/baseentity.cpp',
'natives/baseanimating.cpp',
'natives/baseanimatingoverlay.cpp',
'natives/basecombatcharacter.cpp',
'natives/takedamageinfo.cpp',
'natives/nav.cpp',
'natives/entityfactory.cpp',
'natives/nav/area.cpp',
'natives/nextbot.cpp',
'natives/nextbot/component.cpp',
'natives/nextbot/eventresponder.cpp',
'natives/nextbot/vision.cpp',
'natives/nextbot/knownentity.cpp',
'natives/nextbot/body.cpp',
'natives/nextbot/locomotion.cpp',
'natives/nextbot/locomotion/ground.cpp',
'natives/nextbot/intention.cpp',
'natives/nextbot/behavior.cpp',
'natives/nextbot/path.cpp',
'natives/nextbot/path/chase.cpp',
'natives/nextbot/path/follower.cpp',
'natives/nextbotplayer.cpp',
'natives/tf/nav.cpp',
'natives/tf/nav/area.cpp',
'smsdk_ext.cpp'
]

Expand All @@ -61,7 +88,7 @@ for sdk_name in Extension.sdks:
os.path.join(builder.currentSourcePath, 'shared'),
os.path.join(builder.currentSourcePath, ''),
os.path.join(sdk.path, 'game', 'shared'),
os.path.join(sdk.path, 'game/server')
os.path.join(sdk.path, 'game', 'server')
]
if binary.compiler.behavior == 'gcc' or binary.compiler.behavior == 'clang':
binary.compiler.cxxflags += ['-Wno-invalid-offsetof']
Expand Down
20 changes: 10 additions & 10 deletions extension/cbasenpc_behavior.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ BEGINQUERYCALLBACK(IsHindrance, CBaseEntity* blocker)
CBPUSHENTITY(blocker == IS_ANY_HINDRANCE_POSSIBLE ? nullptr : blocker)
ENDQUERYCALLBACK()

Vector CBaseNPCPluginAction::SelectTargetPoint( const INextBot *me, const CBaseCombatCharacterHack *subject ) const
Vector CBaseNPCPluginAction::SelectTargetPoint( const INextBot* me, const CBaseCombatCharacter* subject ) const
{
Vector result = vec3_origin;

Expand All @@ -282,7 +282,7 @@ Vector CBaseNPCPluginAction::SelectTargetPoint( const INextBot *me, const CBaseC

CBPUSHCELL(this)
CBPUSHCELL(me)
CBPUSHENTITY((CBaseCombatCharacterHack*)subject)
CBPUSHENTITY((CBaseCombatCharacter*)subject)
pCallback->PushArray(buffer, 3, SM_PARAM_COPYBACK);
pCallback->Execute(nullptr);

Expand All @@ -299,7 +299,7 @@ BEGINQUERYCALLBACK(IsPositionAllowed, const Vector &pos)
ENDQUERYCALLBACK()

const CKnownEntity * CBaseNPCPluginAction::SelectMoreDangerousThreat( const INextBot *me,
const CBaseCombatCharacterHack *subject,
const CBaseCombatCharacter *subject,
const CKnownEntity *threat1,
const CKnownEntity *threat2 ) const
{
Expand All @@ -310,7 +310,7 @@ const CKnownEntity * CBaseNPCPluginAction::SelectMoreDangerousThreat( const INex
{
CBPUSHCELL(this)
CBPUSHCELL(me)
CBPUSHENTITY((CBaseCombatCharacterHack*)subject)
CBPUSHENTITY((CBaseCombatCharacter*)subject)
CBPUSHCELL(threat1)
CBPUSHCELL(threat2)
pCallback->Execute(&result);
Expand Down Expand Up @@ -366,7 +366,7 @@ BEGINEVENTCALLBACK(OnAnimationEvent, animevent_t *event)
EVENTPUSHFLOAT(event->cycle)
EVENTPUSHFLOAT(event->eventtime)
EVENTPUSHCELL(event->type)
EVENTPUSHENTITY((CBaseAnimatingHack*)event->pSource)
EVENTPUSHENTITY((CBaseAnimating*)event->pSource)
ENDEVENTCALLBACK()

BEGINEVENTCALLBACK(OnIgnite)
Expand Down Expand Up @@ -394,7 +394,7 @@ BEGINEVENTCALLBACK(OnKilled, const CTakeDamageInfo &info)
EVENTPUSHCELL(info.GetDamageCustom())
ENDEVENTCALLBACK()

BEGINEVENTCALLBACK(OnOtherKilled, CBaseCombatCharacterHack *victim, const CTakeDamageInfo &info)
BEGINEVENTCALLBACK(OnOtherKilled, CBaseCombatCharacter *victim, const CTakeDamageInfo &info)
EVENTPUSHENTITY(victim)
EVENTPUSHENTITY(info.GetAttacker())
EVENTPUSHENTITY(info.GetInflictor())
Expand Down Expand Up @@ -435,13 +435,13 @@ BEGINEVENTCALLBACK(OnSound, CBaseEntity *source, const Vector &pos, KeyValues *k

ENDEVENTCALLBACK_NOEXECUTE()

BEGINEVENTCALLBACK(OnSpokeConcept, CBaseCombatCharacterHack* who, AIConcept_t concept, AI_Response *response)
BEGINEVENTCALLBACK(OnSpokeConcept, CBaseCombatCharacter* who, AIConcept_t concept, AI_Response *response)
EVENTPUSHENTITY(who)
EVENTPUSHCELL(concept)
EVENTPUSHCELL(response)
ENDEVENTCALLBACK()

BEGINEVENTCALLBACK(OnWeaponFired, CBaseCombatCharacterHack* whoFired, CBaseEntity* weapon )
BEGINEVENTCALLBACK(OnWeaponFired, CBaseCombatCharacter* whoFired, CBaseEntity* weapon )
EVENTPUSHENTITY(whoFired)
EVENTPUSHENTITY(weapon)
ENDEVENTCALLBACK()
Expand All @@ -454,7 +454,7 @@ ENDEVENTCALLBACK()
BEGINEVENTCALLBACK(OnModelChanged)
ENDEVENTCALLBACK()

BEGINEVENTCALLBACK(OnPickUp, CBaseEntity* item, CBaseCombatCharacterHack* giver)
BEGINEVENTCALLBACK(OnPickUp, CBaseEntity* item, CBaseCombatCharacter* giver)
EVENTPUSHENTITY(item)
EVENTPUSHENTITY(giver)
ENDEVENTCALLBACK()
Expand All @@ -463,7 +463,7 @@ BEGINEVENTCALLBACK(OnDrop, CBaseEntity* item)
EVENTPUSHENTITY(item)
ENDEVENTCALLBACK()

BEGINEVENTCALLBACK(OnActorEmoted, CBaseCombatCharacterHack* emoter, int emote)
BEGINEVENTCALLBACK(OnActorEmoted, CBaseCombatCharacter* emoter, int emote)
EVENTPUSHENTITY(emoter)
EVENTPUSHCELL(emote)
ENDEVENTCALLBACK()
Expand Down
14 changes: 7 additions & 7 deletions extension/cbasenpc_behavior.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,11 @@ class CBaseNPCPluginAction : public Action <INextBot>
virtual QueryResultType ShouldAttack( const INextBot *me, const CKnownEntity *them ) const override final;
virtual QueryResultType IsHindrance( const INextBot *me, CBaseEntity *blocker ) const override final;

virtual Vector SelectTargetPoint( const INextBot *me, const CBaseCombatCharacterHack *subject ) const override final;
virtual Vector SelectTargetPoint( const INextBot *me, const CBaseCombatCharacter* subject ) const override final;
virtual QueryResultType IsPositionAllowed( const INextBot *me, const Vector &pos ) const override final;

virtual const CKnownEntity * SelectMoreDangerousThreat( const INextBot *me,
const CBaseCombatCharacterHack *subject,
const CBaseCombatCharacter* subject,
const CKnownEntity *threat1,
const CKnownEntity *threat2 ) const override final;

Expand All @@ -117,17 +117,17 @@ class CBaseNPCPluginAction : public Action <INextBot>
virtual EventDesiredResult< INextBot > OnIgnite( INextBot *me ) override final;
virtual EventDesiredResult< INextBot > OnInjured( INextBot *me, const CTakeDamageInfo &info ) override final;
virtual EventDesiredResult< INextBot > OnKilled( INextBot *me, const CTakeDamageInfo &info ) override final;
virtual EventDesiredResult< INextBot > OnOtherKilled( INextBot *me, CBaseCombatCharacterHack *victim, const CTakeDamageInfo &info ) override final;
virtual EventDesiredResult< INextBot > OnOtherKilled( INextBot *me, CBaseCombatCharacter* victim, const CTakeDamageInfo &info ) override final;
virtual EventDesiredResult< INextBot > OnSight( INextBot *me, CBaseEntity *subject ) override final;
virtual EventDesiredResult< INextBot > OnLostSight( INextBot *me, CBaseEntity *subject ) override final;
virtual EventDesiredResult< INextBot > OnSound( INextBot *me, CBaseEntity *source, const Vector &pos, KeyValues *keys ) override final;
virtual EventDesiredResult< INextBot > OnSpokeConcept( INextBot *me, CBaseCombatCharacterHack *who, AIConcept_t concept, AI_Response *response ) override final;
virtual EventDesiredResult< INextBot > OnWeaponFired( INextBot *me, CBaseCombatCharacterHack *whoFired, CBaseEntity *weapon ) override final;
virtual EventDesiredResult< INextBot > OnSpokeConcept( INextBot *me, CBaseCombatCharacter* who, AIConcept_t concept, AI_Response *response ) override final;
virtual EventDesiredResult< INextBot > OnWeaponFired( INextBot *me, CBaseCombatCharacter* whoFired, CBaseEntity *weapon ) override final;
virtual EventDesiredResult< INextBot > OnNavAreaChanged( INextBot *me, CNavArea *newArea, CNavArea *oldArea ) override final;
virtual EventDesiredResult< INextBot > OnModelChanged( INextBot *me ) override final;
virtual EventDesiredResult< INextBot > OnPickUp( INextBot *me, CBaseEntity *item, CBaseCombatCharacterHack *giver ) override final;
virtual EventDesiredResult< INextBot > OnPickUp( INextBot *me, CBaseEntity *item, CBaseCombatCharacter* giver ) override final;
virtual EventDesiredResult< INextBot > OnDrop( INextBot *me, CBaseEntity *item ) override final;
virtual EventDesiredResult< INextBot > OnActorEmoted( INextBot *me, CBaseCombatCharacterHack *emoter, int emote ) override final;
virtual EventDesiredResult< INextBot > OnActorEmoted( INextBot *me, CBaseCombatCharacter* emoter, int emote ) override final;

virtual EventDesiredResult< INextBot > OnCommandAttack( INextBot *me, CBaseEntity *victim ) override final;
virtual EventDesiredResult< INextBot > OnCommandApproach( INextBot *me, const Vector &pos, float range ) override final;
Expand Down
14 changes: 7 additions & 7 deletions extension/cbasenpc_internal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,27 +50,27 @@ CBaseNPCFactory::~CBaseNPCFactory()
{
}

void CBaseNPCFactory::Create_Extra(CBaseEntityHack* ent)
void CBaseNPCFactory::Create_Extra(CBaseEntity* ent)
{
// Replace the vtable with ours
if (CBaseNPC_Entity::vtable == nullptr)
{
CBaseNPC_Entity::vtable = vtable_dup(ent, NextBotCombatCharacter::vtable_entries);
void* original = nullptr;
original = CBaseEntityHack::vSpawn.Replace(CBaseNPC_Entity::vtable, &CBaseNPC_Entity::BotSpawn);
original = CBaseEntity::vSpawn.Replace(CBaseNPC_Entity::vtable, &CBaseNPC_Entity::BotSpawn);
CBaseNPC_Entity::mOriginalSpawn.Init(original);
original = CBaseEntityHack::vOnTakeDamage.Replace(CBaseNPC_Entity::vtable, &CBaseNPC_Entity::OnTakeDamage);
original = CBaseEntity::vOnTakeDamage.Replace(CBaseNPC_Entity::vtable, &CBaseNPC_Entity::OnTakeDamage);
CBaseNPC_Entity::mOriginalOnTakeDamage.Init(original);
original = CBaseCombatCharacterHack::vOnTakeDamage_Alive.Replace(CBaseNPC_Entity::vtable, &CBaseNPC_Entity::OnTakeDamage_Alive);
original = CBaseCombatCharacter::vOnTakeDamage_Alive.Replace(CBaseNPC_Entity::vtable, &CBaseNPC_Entity::OnTakeDamage_Alive);
CBaseNPC_Entity::mOriginalOnTakeDamage_Alive.Init(original);
original = CBaseEntityHack::vUpdateOnRemove.Replace(CBaseNPC_Entity::vtable, &CBaseNPC_Entity::BotUpdateOnRemove);
original = CBaseEntity::vUpdateOnRemove.Replace(CBaseNPC_Entity::vtable, &CBaseNPC_Entity::BotUpdateOnRemove);
CBaseNPC_Entity::mOriginalUpdateOnRemove.Init(original);
}
vtable_replace(ent, CBaseNPC_Entity::vtable);
new (((CBaseNPC_Entity*)ent)->GetNPC()) CBaseNPC_Entity::CBaseNPC((NextBotCombatCharacter*)ent);
}

void CBaseNPCFactory::Create_PostConstructor(CBaseEntityHack* ent)
void CBaseNPCFactory::Create_PostConstructor(CBaseEntity* ent)
{
((CBaseNPC_Entity*)ent)->GetNPC()->SetEntity(ent);
}
Expand Down Expand Up @@ -204,7 +204,7 @@ CBaseNPC_Body::CBaseNPC_Body(INextBot* bot) : IBody(bot)
void CBaseNPC_Body::Update()
{
// VPROF_ENTER_SCOPE("CBaseNPC_Body::Update");
CBaseCombatCharacterHack* entity = GetBot()->GetEntity();
CBaseCombatCharacter* entity = GetBot()->GetEntity();
entity->DispatchAnimEvents(entity);
entity->StudioFrameAdvance();
// VPROF_EXIT_SCOPE();
Expand Down
4 changes: 2 additions & 2 deletions extension/cbasenpc_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ class CBaseNPCFactory : public CustomFactory
CBaseNPCFactory();
virtual ~CBaseNPCFactory();
virtual size_t GetEntitySize() override final;
virtual void Create_Extra(CBaseEntityHack* ent) override final;
virtual void Create_PostConstructor(CBaseEntityHack* ent) override final;
virtual void Create_Extra(CBaseEntity* ent) override final;
virtual void Create_PostConstructor(CBaseEntity* ent) override final;
};

extern CBaseNPCFactory* g_pBaseNPCFactory;
Expand Down
4 changes: 2 additions & 2 deletions extension/cbasenpc_locomotion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ void CBaseNPC_Locomotion::V_Update()
{
// VPROF_ENTER_SCOPE("CBaseNPC_Locomotion::Update");

CBaseCombatCharacterHack* entity = GetBot()->GetEntity();
CBaseCombatCharacter* entity = GetBot()->GetEntity();
entity->UpdateLastKnownArea();

if (IsStuck())
Expand Down Expand Up @@ -398,7 +398,7 @@ void CBaseNPC_Locomotion::V_JumpAcrossGap(const Vector& landingGoal, const Vecto

bool CBaseNPC_Locomotion::DefaultIsEntityTraversable(CBaseEntity* pEntity, ILocomotion::TraverseWhenType when)
{
if (((CBaseEntityHack *)pEntity)->MyCombatCharacterPointer())
if ((pEntity)->MyCombatCharacterPointer())
{
return true;
}
Expand Down
Loading