Skip to content

CS:GO weapons update #169

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

Merged
merged 18 commits into from
Dec 10, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Changed entities.entity to be engine/game specific.
Implemented changes to Entity.find and Entity.create for csgo engine.
  • Loading branch information
satoon101 committed Oct 20, 2016
commit 65636533f554ce782bc0fb86134b6336663c11d3
22 changes: 2 additions & 20 deletions addons/source-python/packages/source-python/entities/_base.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# ../entities/entity.py
# ../entities/_base.py

"""Provides a base class to interact with a specific entity."""

Expand All @@ -20,19 +20,18 @@
from engines.trace import Ray
from engines.trace import TraceFilterSimple
# Entities
from _entities._entity import BaseEntity
from entities import BaseEntityGenerator
from entities import TakeDamageInfo
from entities.classes import server_classes
from entities.constants import DamageTypes
from entities.constants import RenderMode
from entities.helpers import edict_from_index
from entities.helpers import index_from_inthandle
from entities.helpers import index_from_pointer
from entities.helpers import wrap_entity_mem_func
# Filters
from filters.weapons import WeaponClassIter
# Memory
from memory import get_object_pointer
from memory import make_object
# Players
from players.constants import HitGroup
Expand All @@ -41,23 +40,6 @@
from studio.constants import INVALID_ATTACHMENT_INDEX


# =============================================================================
# >> FORWARD IMPORTS
# =============================================================================
# Source.Python Imports
# Entities
from _entities._entity import BaseEntity


# =============================================================================
# >> ALL DECLARATION
# =============================================================================
# Add all the global variables to __all__
__all__ = ('BaseEntity',
'Entity',
)


# =============================================================================
# >> GLOBAL VARIABLES
# =============================================================================
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# ../entities/engines/__init__.py

"""Provides engine specific Entity based functionality."""
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# ../engines/engines/csgo/__init__.py

"""Provides CS:GO specific Entity based functionality."""

# =============================================================================
# >> IMPORTS
# =============================================================================
# Source.Python Imports
from entities._base import Entity as _Entity
from weapons.manager import weapon_manager


# =============================================================================
# >> GLOBAL VARIABLES
# =============================================================================
_weapon_names_for_definition = {
weapon_manager[weapon].name: values.get('item_definition_index')
for weapon, values in weapon_manager.ini['weapons'].items()
if values.get('item_definition_index')
}
_weapon_parents = {
weapon_manager[weapon].name: values.get('parent_class')
for weapon, values in weapon_manager.ini['weapons'].items()
if values.get('parent_class')
}
_parent_weapons = set(_weapon_parents.values())


# =============================================================================
# >> CLASSES
# =============================================================================
class Entity(_Entity):
"""Class used to interact directly with entities."""

@classmethod
def create(cls, classname):
index = _weapon_names_for_definition.get(classname)
if classname in _weapon_parents and index is not None:
entity = super().create(_weapon_parents[classname])
entity.item_definition_index = index
else:
entity = super().create(classname)
return entity

@classmethod
def find(cls, classname):
from filters.entities import EntityIter
index = _weapon_names_for_definition.get(classname)
if classname in _weapon_parents and index is not None:
for entity in EntityIter(_weapon_parents[classname]):
if entity.item_definition_index == index:
return entity
elif classname in _parent_weapons:
for entity in EntityIter(classname):
if entity.item_definition_index in (index, 0):
return entity
return super().find(classname)
59 changes: 59 additions & 0 deletions addons/source-python/packages/source-python/entities/entity.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# ../entities/entity.py

"""Provides a class used to interact with a specific entity."""

# =============================================================================
# >> IMPORTS
# =============================================================================
from importlib import import_module
from core import GAME_NAME
from core import SOURCE_ENGINE
from paths import SP_PACKAGES_PATH


# =============================================================================
# >> FORWARD IMPORTS
# =============================================================================
# Source.Python Imports
# Entities
from _entities._entity import BaseEntity


# =============================================================================
# >> ALL DECLARATION
# =============================================================================
__all__ = ('BaseEntity'
'Entity',
)


# =============================================================================
# >> GLOBAL VARIABLES
# =============================================================================
if SP_PACKAGES_PATH.joinpath(
'entities', 'engines', SOURCE_ENGINE, GAME_NAME + '.py'
).isfile():

# Import the game-specific 'Entity' class
Entity = import_module(
'entities.engines.{engine}.{game}'.format(
engine=SOURCE_ENGINE,
game=GAME_NAME,
)
).Entity

elif SP_PACKAGES_PATH.joinpath(
'entities', 'engines', SOURCE_ENGINE, '__init__.py'
).isfile():

# Import the engine-specific 'Entity' class
Entity = import_module(
'entities.engines.{engine}'.format(
engine=SOURCE_ENGINE,
)
).Entity

else:

# Import the base 'Entity' class
from entities._base import Entity