-
Notifications
You must be signed in to change notification settings - Fork 37
Added a set_attacker function to CBaseCSGrenadeProjectile for CS:GO. #366
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
Added a set_attacker function to CBaseCSGrenadeProjectile for CS:GO. #366
Conversation
Hmm. Is there a getter or a way to read it also? As for the name, perhaps we could override "thrower" in the CS:GO weapon class so that the behaviours are consistent with other games as well as being backward compatible. |
I'm not sure what exactly you want to read, but the # Source.Python Imports
# Core
import core
# Entities
from entities.entity import Entity
# Memory
from memory import make_object
from memory.manager import CustomType
from memory.manager import Type
from memory.manager import manager
# Players
from players.entity import Player
class CSGOAttackerInfo(CustomType, metaclass=manager):
need_init = manager.instance_attribute(Type.BOOL, 0, "bool m_bNeedInit")
handle = manager.instance_attribute(Type.INT, 4, "EHANDLE m_hHndl")
is_player = manager.instance_attribute(Type.BOOL, 8, "bool m_bIsPlayer")
is_world = manager.instance_attribute(Type.BOOL, 9, "bool m_bIsWorld")
client_index = manager.instance_attribute(Type.INT, 12, "int m_iClientIndex")
survival_team = manager.instance_attribute(Type.INT, 16, "int m_nSurvivalTeam")
team_checked = manager.instance_attribute(Type.INT, 20, "int m_iTeamChecked")
team_num = manager.instance_attribute(Type.INT, 24, "int m_iTeamNum")
userid = manager.instance_attribute(Type.INT, 28, "int m_iUserId")
if core.PLATFORM == "linux":
offset = 1300
else:
offset = 1276
attacker = Player(1)
molotov = Entity.create("molotov_projectile")
molotov.set_attacker(attacker)
attacker_info = make_object(CSGOAttackerInfo, molotov._ptr()+offset)
print(attacker_info.handle)
print(attacker_info.is_player)
print(attacker_info.client_index)
Which class does this mean, exactly? |
We could simply export that structure from the C++ side as well and just store an offset in our data. But since the thrower is set during that call, I'm fine with the signature. Time will tell if it becomes less stable than an offset I guess.
On other games, or before that update for CS:GO, giving ownership of a projectile to a player was as simple as setting the thrower like so: from players.entity import Player
from weapons.entity import Weapon
player = Player(1)
weapon = Weapon.create('hegrenade_projectile')
weapon.thrower = player.inthandle
weapon.damage = 10000
weapon.teleport(player.view_coordinates)
weapon.detonate() Now such code on CS:GO is no longer working as it used to, and solely adding a |
I think that's an option. But if we expand the support to other entities, such as inferno(2936 on Linux and 2912 on Windows), we might have to re-examine the entire entity.
I may have agreed head-on if it was an Entity class. The problem is the some existing plugins and users (including myself) assume it will work with |
If the offset is different for some projectiles then a signature is better. Otherwise it multiplies the effort of maintaining them since if one is changed then the others are likely to as well.
thrower = property(
lambda self: self.__getattr__('thrower'),
lambda self, value: self.set_attacker(pointer_from_inthandle(value))
) Should theoretically do it. Would raise an attribute error for non-projectile entities, and would properly override it for projectiles. I used lambdas since we override a dynamic property but we could also use private getter/setter methods as well. Also, is there a string in that method? If so, please add it as a reference comment in the data file so it makes it easier if someone else try to track it down. |
The offset of the projectiles are equal.
No. It is on the top of create function for projectiles, such as CMolotovProjectile::Create, but there is no clear indicator.
It's exactly the best way! |
This function allows you to properly set the attacker on the Projectile.
If you think there is a problem with the name, please suggest a new name.