Hymns For Disco wrote:I've tried implementing this solution however I am now getting errors thrown when picking up weapons.
Code: Select all
[SP] Caught an Exception:
Traceback (most recent call last):
File "..\addons\source-python\plugins\timer\core\zone.py", line 163, in pre_to
uch
parent.touch.call_trampoline(other)
File "..\addons\source-python\packages\source-python\memory\helpers.py", line
335, in call_trampoline
return super().call_trampoline(self._this, *args)
File "<string>", line 1, in <lambda>
ValueError: Function was not hooked.
Im not too sure what this error means or why its being raised. If it's safe to just catch the exception and ignore it, I could do that.
You get this error because the Function instance you try to call the trampoline is not hooked. Without your code it won't be possible to tell you where and why it happens but let's just say you are trying to do something that cannot be done. But if I had to guess, I would say that pOther has its own implementation of the Touch method into its dispatch table meaning that this is not the one that is hooked so you could just leave the call continue in such case. Either that or you are hooking start_touch and is calling the trampoline for touch, which is obviously not hooked.
Hymns For Disco wrote:The second problem im having is that I can't find the entity property names for the start_touch and end_touch functions (if they exist). For touch you use m_pfnTouch, but I can't seem to find any other properties like this for touch function. If these properties dont exist, is there any alternate method I can use to hook these touch events?
Edit: If these pointers do not exist for such functions, doesn't this make EntityHooks nearly unusable since you can't confirm that they won't randomly kill your server at any time? (various maps may or may not have parented entities of certain types)
You don't have to do that call for StartTouch, because the original
CBaseEntity::StartTouch is not doing so unlike
CBaseEntity::Touch. So basically, you only have to call the trampoline for the parent in your case.
Hymns For Disco wrote:Well I've realised finally that I can use EntityPostHook instead of EntityPreHook and it seems to avoid this whole server freezing situation, which is great since post hooks will work fine in my circumstances. However I, and I'm sure other people too, would like to know how to safely use EntityPreHook for functions other than touch
They only have to know that the hooks are not thread safe meaning that if you hook a function that call itself, you cannot let the original call go through and you have to mimic what it does by calling the trampoline so that the hook doesn't get re-called internally before the original call is done. For
start_touch, you would use the same code I linked above without the following lines:
Syntax: Select all
ptr = entity.get_property_pointer('m_pfnTouch')
if ptr != NULL:
func = ptr.make_function(Convention.THISCALL,
(DataType.POINTER, DataType.POINTER), DataType.VOID)
func(entity, other)
Because
StartTouch does nothing else than noticing the parent of the this pointer.