1
1
#include " entities.h"
2
2
#include < swiftly-ext/event.h>
3
3
#include < vector>
4
+ #include < set>
5
+ #include < string>
4
6
5
7
std::any tmpret;
6
8
CEntityListener g_entityListener;
7
9
8
- SH_DECL_MANUALHOOK1_void (StartTouch, 0 , 0 , 0 , CEntityInstance *);
9
- SH_DECL_MANUALHOOK1_void (Touch, 0 , 0 , 0 , CEntityInstance *);
10
- SH_DECL_MANUALHOOK1_void (EndTouch, 0 , 0 , 0 , CEntityInstance *);
10
+ SH_DECL_MANUALHOOK1_void (StartTouch, 0 , 0 , 0 , CEntityInstance*);
11
+ SH_DECL_MANUALHOOK1_void (Touch, 0 , 0 , 0 , CEntityInstance*);
12
+ SH_DECL_MANUALHOOK1_void (EndTouch, 0 , 0 , 0 , CEntityInstance*);
11
13
SH_DECL_MANUALHOOK1_void (EntityUse, 0 , 0 , 0 , class InputData_t *);
12
14
SH_DECL_EXTERN3_void (INetworkServerService, StartupServer, SH_NOATTRIB, 0 , const GameSessionConfiguration_t&, ISource2WorldSession*, const char *);
13
15
@@ -23,9 +25,9 @@ void OnPostUse(class InputData_t* ent);
23
25
void EntityListener::Initialize ()
24
26
{
25
27
SH_MANUALHOOK_RECONFIGURE (StartTouch, GetOffset (" CBaseEntity_StartTouch" ), 0 , 0 );
26
- SH_MANUALHOOK_RECONFIGURE (Touch, GetOffset (" CBaseEntity_Touch" ), 0 , 0 );
27
- SH_MANUALHOOK_RECONFIGURE (EndTouch, GetOffset (" CBaseEntity_EndTouch" ), 0 , 0 );
28
- SH_MANUALHOOK_RECONFIGURE (EntityUse, GetOffset (" CBaseEntity_Use" ), 0 , 0 );
28
+ SH_MANUALHOOK_RECONFIGURE (Touch, GetOffset (" CBaseEntity_Touch" ), 0 , 0 );
29
+ SH_MANUALHOOK_RECONFIGURE (EndTouch, GetOffset (" CBaseEntity_EndTouch" ), 0 , 0 );
30
+ SH_MANUALHOOK_RECONFIGURE (EntityUse, GetOffset (" CBaseEntity_Use" ), 0 , 0 );
29
31
30
32
SH_ADD_HOOK_MEMFUNC (INetworkServerService, StartupServer, g_pNetworkServerService, this , &EntityListener::StartupServer, true );
31
33
}
@@ -45,6 +47,21 @@ void EntityListener::StartupServer(const GameSessionConfiguration_t& config, ISo
45
47
bDone = true ;
46
48
}
47
49
50
+ std::set<std::string> classNames;
51
+
52
+ void entities_SetupScripting (EContext* ctx)
53
+ {
54
+ ADD_FUNCTION (" ListenEntityTouchUse" , [](FunctionContext* context) -> void {
55
+ std::string className = context->GetArgumentOr <std::string>(0 , " " );
56
+ classNames.insert (className);
57
+ });
58
+
59
+ ADD_FUNCTION (" RemoveListenEntityTouchUse" , [](FunctionContext* context) -> void {
60
+ std::string className = context->GetArgumentOr <std::string>(0 , " " );
61
+ classNames.erase (className);
62
+ });
63
+ }
64
+
48
65
void CEntityListener::OnEntitySpawned (CEntityInstance* pEntity)
49
66
{
50
67
}
@@ -55,79 +72,117 @@ void CEntityListener::OnEntityParentChanged(CEntityInstance* pEntity, CEntityIns
55
72
56
73
void CEntityListener::OnEntityCreated (CEntityInstance* pEntity)
57
74
{
58
- // SH_ADD_MANUALHOOK_STATICFUNC(StartTouch, pEntity, OnStartTouch, false);
59
- // SH_ADD_MANUALHOOK_STATICFUNC(StartTouch, pEntity, OnPostStartTouch, true);
60
- // SH_ADD_MANUALHOOK_STATICFUNC(Touch, pEntity, OnTouch, false);
61
- // SH_ADD_MANUALHOOK_STATICFUNC(Touch, pEntity, OnPostTouch, true);
62
- // SH_ADD_MANUALHOOK_STATICFUNC(EndTouch, pEntity, OnEndTouch, false);
63
- // SH_ADD_MANUALHOOK_STATICFUNC(EndTouch, pEntity, OnPostEndTouch, true);
64
- // SH_ADD_MANUALHOOK_STATICFUNC(EntityUse, pEntity, OnUse, false);
65
- // SH_ADD_MANUALHOOK_STATICFUNC(EntityUse, pEntity, OnPostUse, true);
75
+ if (classNames.find (pEntity->GetClassname ()) != classNames.end ()) {
76
+ SH_ADD_MANUALHOOK_STATICFUNC (StartTouch, pEntity, OnStartTouch, false );
77
+ SH_ADD_MANUALHOOK_STATICFUNC (StartTouch, pEntity, OnPostStartTouch, true );
78
+ SH_ADD_MANUALHOOK_STATICFUNC (Touch, pEntity, OnTouch, false );
79
+ SH_ADD_MANUALHOOK_STATICFUNC (Touch, pEntity, OnPostTouch, true );
80
+ SH_ADD_MANUALHOOK_STATICFUNC (EndTouch, pEntity, OnEndTouch, false );
81
+ SH_ADD_MANUALHOOK_STATICFUNC (EndTouch, pEntity, OnPostEndTouch, true );
82
+ SH_ADD_MANUALHOOK_STATICFUNC (EntityUse, pEntity, OnUse, false );
83
+ SH_ADD_MANUALHOOK_STATICFUNC (EntityUse, pEntity, OnPostUse, true );
84
+ }
66
85
}
67
86
68
87
void CEntityListener::OnEntityDeleted (CEntityInstance* pEntity)
69
88
{
89
+ if (classNames.find (pEntity->GetClassname ()) != classNames.end ()) {
90
+ SH_REMOVE_MANUALHOOK_STATICFUNC (StartTouch, pEntity, OnStartTouch, false );
91
+ SH_REMOVE_MANUALHOOK_STATICFUNC (StartTouch, pEntity, OnPostStartTouch, true );
92
+ SH_REMOVE_MANUALHOOK_STATICFUNC (Touch, pEntity, OnTouch, false );
93
+ SH_REMOVE_MANUALHOOK_STATICFUNC (Touch, pEntity, OnPostTouch, true );
94
+ SH_REMOVE_MANUALHOOK_STATICFUNC (EndTouch, pEntity, OnEndTouch, false );
95
+ SH_REMOVE_MANUALHOOK_STATICFUNC (EndTouch, pEntity, OnPostEndTouch, true );
96
+ SH_REMOVE_MANUALHOOK_STATICFUNC (EntityUse, pEntity, OnUse, false );
97
+ SH_REMOVE_MANUALHOOK_STATICFUNC (EntityUse, pEntity, OnPostUse, true );
98
+ }
70
99
}
71
100
72
101
void OnStartTouch (CEntityInstance* ent)
73
102
{
74
- if (TriggerEvent (" sdktools.ext" , " OnEntityStartTouch" , { string_format (" %p" , META_IFACEPTR (CEntityInstance)), " CEntityInstance" , string_format (" %p" , ent), " CEntityInstance" }, tmpret) == EventResult::Stop)
103
+ ClassData thisEnt ({ { " class_name" , " CEntityInstance" }, { " class_ptr" , META_IFACEPTR (CEntityInstance) } }, " SDKClass" , nullptr );
104
+ ClassData otherEnt ({ { " class_name" , " CEntityInstance" }, { " class_ptr" , ent } }, " SDKClass" , nullptr );
105
+
106
+ if (TriggerEvent (" sdktools.ext" , " OnEntityStartTouch" , { &thisEnt, &otherEnt }, tmpret) == EventResult::Stop)
75
107
RETURN_META (MRES_SUPERCEDE);
76
108
77
109
RETURN_META (MRES_IGNORED);
78
110
}
79
111
80
112
void OnPostStartTouch (CEntityInstance* ent)
81
113
{
82
- if (TriggerEvent (" sdktools.ext" , " OnPostEntityStartTouch" , { string_format (" %p" , META_IFACEPTR (CEntityInstance)), " CEntityInstance" , string_format (" %p" , ent), " CEntityInstance" }, tmpret) == EventResult::Stop)
114
+ ClassData thisEnt ({ { " class_name" , " CEntityInstance" }, { " class_ptr" , META_IFACEPTR (CEntityInstance) } }, " SDKClass" , nullptr );
115
+ ClassData otherEnt ({ { " class_name" , " CEntityInstance" }, { " class_ptr" , ent } }, " SDKClass" , nullptr );
116
+
117
+ if (TriggerEvent (" sdktools.ext" , " OnPostEntityStartTouch" , { &thisEnt, &otherEnt }, tmpret) == EventResult::Stop)
83
118
RETURN_META (MRES_SUPERCEDE);
84
119
85
120
RETURN_META (MRES_IGNORED);
86
121
}
87
122
88
123
void OnTouch (CEntityInstance* ent)
89
124
{
90
- if (TriggerEvent (" sdktools.ext" , " OnEntityTouching" , { string_format (" %p" , META_IFACEPTR (CEntityInstance)), " CEntityInstance" , string_format (" %p" , ent), " CEntityInstance" }, tmpret) == EventResult::Stop)
125
+ ClassData thisEnt ({ { " class_name" , " CEntityInstance" }, { " class_ptr" , META_IFACEPTR (CEntityInstance) } }, " SDKClass" , nullptr );
126
+ ClassData otherEnt ({ { " class_name" , " CEntityInstance" }, { " class_ptr" , ent } }, " SDKClass" , nullptr );
127
+
128
+ if (TriggerEvent (" sdktools.ext" , " OnEntityTouching" , { &thisEnt, &otherEnt }, tmpret) == EventResult::Stop)
91
129
RETURN_META (MRES_SUPERCEDE);
92
130
93
131
RETURN_META (MRES_IGNORED);
94
132
}
95
133
96
134
void OnPostTouch (CEntityInstance* ent)
97
135
{
98
- if (TriggerEvent (" sdktools.ext" , " OnPostEntityTouching" , { string_format (" %p" , META_IFACEPTR (CEntityInstance)), " CEntityInstance" , string_format (" %p" , ent), " CEntityInstance" }, tmpret) == EventResult::Stop)
136
+ ClassData thisEnt ({ { " class_name" , " CEntityInstance" }, { " class_ptr" , META_IFACEPTR (CEntityInstance) } }, " SDKClass" , nullptr );
137
+ ClassData otherEnt ({ { " class_name" , " CEntityInstance" }, { " class_ptr" , ent } }, " SDKClass" , nullptr );
138
+
139
+ if (TriggerEvent (" sdktools.ext" , " OnPostEntityTouching" , { &thisEnt, &otherEnt }, tmpret) == EventResult::Stop)
99
140
RETURN_META (MRES_SUPERCEDE);
100
141
101
142
RETURN_META (MRES_IGNORED);
102
143
}
103
144
104
145
void OnEndTouch (CEntityInstance* ent)
105
146
{
106
- if (TriggerEvent (" sdktools.ext" , " OnEntityStopTouch" , { string_format (" %p" , META_IFACEPTR (CEntityInstance)), " CEntityInstance" , string_format (" %p" , ent), " CEntityInstance" }, tmpret) == EventResult::Stop)
147
+ ClassData thisEnt ({ { " class_name" , " CEntityInstance" }, { " class_ptr" , META_IFACEPTR (CEntityInstance) } }, " SDKClass" , nullptr );
148
+ ClassData otherEnt ({ { " class_name" , " CEntityInstance" }, { " class_ptr" , ent } }, " SDKClass" , nullptr );
149
+
150
+ if (TriggerEvent (" sdktools.ext" , " OnEntityStopTouch" , { &thisEnt, &otherEnt }, tmpret) == EventResult::Stop)
107
151
RETURN_META (MRES_SUPERCEDE);
108
152
109
153
RETURN_META (MRES_IGNORED);
110
154
}
111
155
112
156
void OnPostEndTouch (CEntityInstance* ent)
113
157
{
114
- if (TriggerEvent (" sdktools.ext" , " OnPostEntityStopTouch" , { string_format (" %p" , META_IFACEPTR (CEntityInstance)), " CEntityInstance" , string_format (" %p" , ent), " CEntityInstance" }, tmpret) == EventResult::Stop)
158
+ ClassData thisEnt ({ { " class_name" , " CEntityInstance" }, { " class_ptr" , META_IFACEPTR (CEntityInstance) } }, " SDKClass" , nullptr );
159
+ ClassData otherEnt ({ { " class_name" , " CEntityInstance" }, { " class_ptr" , ent } }, " SDKClass" , nullptr );
160
+
161
+ if (TriggerEvent (" sdktools.ext" , " OnPostEntityStopTouch" , { &thisEnt, &otherEnt }, tmpret) == EventResult::Stop)
115
162
RETURN_META (MRES_SUPERCEDE);
116
163
117
164
RETURN_META (MRES_IGNORED);
118
165
}
119
166
120
167
void OnUse (class InputData_t * ent)
121
168
{
122
- if (TriggerEvent (" sdktools.ext" , " OnEntityUse" , { string_format (" %p" , META_IFACEPTR (CEntityInstance)), " CEntityInstance" , string_format (" %p" , ent->pActivator ), " CEntityInstance" , string_format (" %p" , ent->pCaller ), " CEntityInstance" , ent->nOutputID }, tmpret) == EventResult::Stop)
169
+ ClassData thisEnt ({ { " class_name" , " CEntityInstance" }, { " class_ptr" , META_IFACEPTR (CEntityInstance) } }, " SDKClass" , nullptr );
170
+ ClassData activator ({ { " class_name" , " CEntityInstance" }, { " class_ptr" , ent->pActivator } }, " SDKClass" , nullptr );
171
+ ClassData caller ({ { " class_name" , " CEntityInstance" }, { " class_ptr" , ent->pCaller } }, " SDKClass" , nullptr );
172
+
173
+ if (TriggerEvent (" sdktools.ext" , " OnEntityUse" , { &thisEnt, &activator, &caller, ent->nOutputID }, tmpret) == EventResult::Stop)
123
174
RETURN_META (MRES_SUPERCEDE);
124
175
125
176
RETURN_META (MRES_IGNORED);
126
177
}
127
178
128
179
void OnPostUse (class InputData_t * ent)
129
180
{
130
- if (TriggerEvent (" sdktools.ext" , " OnPostEntityUse" , { string_format (" %p" , META_IFACEPTR (CEntityInstance)), " CEntityInstance" , string_format (" %p" , ent->pActivator ), " CEntityInstance" , string_format (" %p" , ent->pCaller ), " CEntityInstance" , ent->nOutputID }, tmpret) == EventResult::Stop)
181
+ ClassData thisEnt ({ { " class_name" , " CEntityInstance" }, { " class_ptr" , META_IFACEPTR (CEntityInstance) } }, " SDKClass" , nullptr );
182
+ ClassData activator ({ { " class_name" , " CEntityInstance" }, { " class_ptr" , ent->pActivator } }, " SDKClass" , nullptr );
183
+ ClassData caller ({ { " class_name" , " CEntityInstance" }, { " class_ptr" , ent->pCaller } }, " SDKClass" , nullptr );
184
+
185
+ if (TriggerEvent (" sdktools.ext" , " OnPostEntityUse" , { &thisEnt, &activator, &caller, ent->nOutputID }, tmpret) == EventResult::Stop)
131
186
RETURN_META (MRES_SUPERCEDE);
132
187
133
188
RETURN_META (MRES_IGNORED);
0 commit comments