| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 4f574e7 commit a6c6e39
6 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -24,7 +24,7 @@ | |||
| 24 | 24 | from entities.datamaps import FieldType | |
| 25 | 25 | from entities.datamaps import InputFunction | |
| 26 | 26 | from entities.datamaps import TypeDescriptionFlags | |
| 27 | - from entities.helpers import edict_from_pointer | ||
| 27 | + from entities.helpers import baseentity_from_pointer | ||
| 28 | 28 | from entities.props import SendPropFlags | |
| 29 | 29 | from entities.props import SendPropType | |
| 30 | 30 | # Memory | |
@@ -456,12 +456,12 @@ def keyvalue(name, type_name): | |||
| 456 | 456 | """Entity keyvalue.""" | |
| 457 | 457 | def fget(pointer): | |
| 458 | 458 | """Retrieve the keyvalue for the entity.""" | |
| 459 | - return getattr(edict_from_pointer( | ||
| 459 | + return getattr(baseentity_from_pointer( | ||
| 460 | 460 | pointer), 'get_key_value_' + type_name)(name) | |
| 461 | 461 | ||
| 462 | 462 | def fset(pointer, value): | |
| 463 | 463 | """Set the keyvalue for the entity to the given value.""" | |
| 464 | - getattr(edict_from_pointer( | ||
| 464 | + getattr(baseentity_from_pointer( | ||
| 465 | 465 | pointer), 'set_key_value_' + type_name)(name, value) | |
| 466 | 466 | ||
| 467 | 467 | return property(fget, fset) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -316,24 +316,24 @@ def set_color(self, color, current_alpha=False): | |||
| 316 | 316 | ||
| 317 | 317 | def get_origin(self): | |
| 318 | 318 | """Return the entity's origin vector.""" | |
| 319 | - return self.edict.get_key_value_vector('origin') | ||
| 319 | + return self.get_key_value_vector('origin') | ||
| 320 | 320 | ||
| 321 | 321 | def set_origin(self, vector): | |
| 322 | 322 | """Set the entity's origin to the given vector.""" | |
| 323 | - self.edict.set_key_value_vector('origin', vector) | ||
| 323 | + self.set_key_value_vector('origin', vector) | ||
| 324 | 324 | ||
| 325 | 325 | origin = property( | |
| 326 | 326 | get_origin, set_origin, | |
| 327 | 327 | doc="""Property to get/set the entity's origin.""") | |
| 328 | 328 | ||
| 329 | 329 | def get_model(self): | |
| 330 | 330 | """Return the entity's model.""" | |
| 331 | - return Model(self.get_server_entity().get_model_name()) | ||
| 331 | + return Model(self.get_model_name()) | ||
| 332 | 332 | ||
| 333 | 333 | def set_model(self, model): | |
| 334 | 334 | """Set the entity's model to the given model.""" | |
| 335 | - self.edict.get_server_entity().set_model_index(model.index) | ||
| 336 | - self.edict.set_key_value_string('model', model.path) | ||
| 335 | + self.edict.set_model_index(model.index) | ||
| 336 | + self.set_key_value_string('model', model.path) | ||
| 337 | 337 | ||
| 338 | 338 | model = property( | |
| 339 | 339 | get_model, set_model, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -32,6 +32,13 @@ | |||
| 32 | 32 | //----------------------------------------------------------------------------- | |
| 33 | 33 | #include "utilities/baseentity.h" | |
| 34 | 34 | #include "utilities/sp_util.h" | |
| 35 | + #include "toolframework/itoolentity.h" | ||
| 36 | + | ||
| 37 | + | ||
| 38 | + //----------------------------------------------------------------------------- | ||
| 39 | + // External variables. | ||
| 40 | + //----------------------------------------------------------------------------- | ||
| 41 | + extern IServerTools* servertools; | ||
| 35 | 42 | ||
| 36 | 43 | ||
| 37 | 44 | //----------------------------------------------------------------------------- | |
@@ -44,6 +51,58 @@ class BaseEntityExt | |||
| 44 | 51 | { | |
| 45 | 52 | return boost::shared_ptr<CBaseEntity>(BaseEntityFromIndex(uiEntityIndex, true), &NeverDeleteDeleter<CBaseEntity *>); | |
| 46 | 53 | } | |
| 54 | + | ||
| 55 | + static str GetKeyValueString(CBaseEntity* pBaseEntity, const char* szName) | ||
| 56 | + { | ||
| 57 | + char szResult[1024]; | ||
| 58 | + servertools->GetKeyValue(pBaseEntity, szName, szResult, 1024); | ||
| 59 | + | ||
| 60 | + // Fix for field name "model". I think a string_t object is copied to szResult. | ||
| 61 | + if (strcmp(szName, "model") == 0) | ||
| 62 | + return *(char **) szResult; | ||
| 63 | + | ||
| 64 | + return str(szResult); | ||
| 65 | + } | ||
| 66 | + | ||
| 67 | + static int GetKeyValueInt(CBaseEntity* pBaseEntity, const char* szName) | ||
| 68 | + { | ||
| 69 | + return extract<int>(eval("lambda x: int(x)")(GetKeyValueString(pBaseEntity, szName))); | ||
| 70 | + } | ||
| 71 | + | ||
| 72 | + static float GetKeyValueFloat(CBaseEntity* pBaseEntity, const char* szName) | ||
| 73 | + { | ||
| 74 | + return extract<float>(eval("lambda x: float(x)")(GetKeyValueString(pBaseEntity, szName))); | ||
| 75 | + } | ||
| 76 | + | ||
| 77 | + static Vector GetKeyValueVector(CBaseEntity* pBaseEntity, const char* szName) | ||
| 78 | + { | ||
| 79 | + object vec = eval("lambda x: tuple(map(float, x.split(' ')))")(GetKeyValueString(pBaseEntity, szName)); | ||
| 80 | + return Vector(extract<float>(vec[0]), extract<float>(vec[1]), extract<float>(vec[2])); | ||
| 81 | + } | ||
| 82 | + | ||
| 83 | + static bool GetKeyValueBool(CBaseEntity* pBaseEntity, const char* szName) | ||
| 84 | + { | ||
| 85 | + return strcmp(extract<const char *>(GetKeyValueString(pBaseEntity, szName)), "1") == 0; | ||
| 86 | + } | ||
| 87 | + | ||
| 88 | + static Color GetKeyValueColor(CBaseEntity* pBaseEntity, const char* szName) | ||
| 89 | + { | ||
| 90 | + object color = eval("lambda x: tuple(map(int, x.split(' ')))")(GetKeyValueString(pBaseEntity, szName)); | ||
| 91 | + return Color(extract<int>(color[0]), extract<int>(color[1]), extract<int>(color[2]), extract<int>(color[3])); | ||
| 92 | + } | ||
| 93 | + | ||
| 94 | + static void SetKeyValueColor(CBaseEntity* pBaseEntity, const char* szName, Color color) | ||
| 95 | + { | ||
| 96 | + char string[16]; | ||
| 97 | + Q_snprintf(string, sizeof(string), "%i %i %i %i", color.r(), color.g(), color.b(), color.a()); | ||
| 98 | + SetKeyValue(pBaseEntity, szName, string); | ||
| 99 | + } | ||
| 100 | + | ||
| 101 | + template<class T> | ||
| 102 | + static void SetKeyValue(CBaseEntity* pBaseEntity, const char* szName, T value) | ||
| 103 | + { | ||
| 104 | + servertools->SetKeyValue(pBaseEntity, szName, value); | ||
| 105 | + } | ||
| 47 | 106 | }; | |
| 48 | 107 | ||
| 49 | 108 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -75,6 +75,79 @@ void export_base_entity(scope _entity) | |||
| 75 | 75 | "Returns the ServerClass object of the entity." | |
| 76 | 76 | ); | |
| 77 | 77 | ||
| 78 | + // Methods... | ||
| 79 | + BaseEntity.def("get_key_value_string", | ||
| 80 | + &BaseEntityExt::GetKeyValueString, | ||
| 81 | + "Returns the value of the given field name.", | ||
| 82 | + args("field_name") | ||
| 83 | + ); | ||
| 84 | + | ||
| 85 | + BaseEntity.def("get_key_value_int", | ||
| 86 | + &BaseEntityExt::GetKeyValueInt, | ||
| 87 | + "Returns the value of the given field name.", | ||
| 88 | + args("field_name") | ||
| 89 | + ); | ||
| 90 | + | ||
| 91 | + BaseEntity.def("get_key_value_float", | ||
| 92 | + &BaseEntityExt::GetKeyValueFloat, | ||
| 93 | + "Returns the value of the given field name.", | ||
| 94 | + args("field_name") | ||
| 95 | + ); | ||
| 96 | + | ||
| 97 | + BaseEntity.def("get_key_value_vector", | ||
| 98 | + &BaseEntityExt::GetKeyValueVector, | ||
| 99 | + "Returns the value of the given field name.", | ||
| 100 | + args("field_name") | ||
| 101 | + ); | ||
| 102 | + | ||
| 103 | + BaseEntity.def("get_key_value_bool", | ||
| 104 | + &BaseEntityExt::GetKeyValueBool, | ||
| 105 | + "Returns the value of the given field name.", | ||
| 106 | + args("field_name") | ||
| 107 | + ); | ||
| 108 | + | ||
| 109 | + BaseEntity.def("get_key_value_color", | ||
| 110 | + &BaseEntityExt::GetKeyValueColor, | ||
| 111 | + "Returns the value of the given field name.", | ||
| 112 | + args("field_name") | ||
| 113 | + ); | ||
| 114 | + | ||
| 115 | + BaseEntity.def("set_key_value_int", | ||
| 116 | + &BaseEntityExt::SetKeyValue<int>, | ||
| 117 | + "Sets a field to the given value.", | ||
| 118 | + args("field_name", "value") | ||
| 119 | + ); | ||
| 120 | + | ||
| 121 | + BaseEntity.def("set_key_value_float", | ||
| 122 | + &BaseEntityExt::SetKeyValue<float>, | ||
| 123 | + "Sets a field to the given value.", | ||
| 124 | + args("field_name", "value") | ||
| 125 | + ); | ||
| 126 | + | ||
| 127 | + BaseEntity.def("set_key_value_string", | ||
| 128 | + &BaseEntityExt::SetKeyValue<const char *>, | ||
| 129 | + "Sets a field to the given value.", | ||
| 130 | + args("field_name", "value") | ||
| 131 | + ); | ||
| 132 | + | ||
| 133 | + BaseEntity.def("set_key_value_vector", | ||
| 134 | + &BaseEntityExt::SetKeyValue<Vector>, | ||
| 135 | + "Sets a field to the given value.", | ||
| 136 | + args("field_name", "value") | ||
| 137 | + ); | ||
| 138 | + | ||
| 139 | + BaseEntity.def("set_key_value_bool", | ||
| 140 | + &BaseEntityExt::SetKeyValue<bool>, | ||
| 141 | + "Sets a field to the given value.", | ||
| 142 | + args("field_name", "value") | ||
| 143 | + ); | ||
| 144 | + | ||
| 145 | + BaseEntity.def("set_key_value_color", | ||
| 146 | + &BaseEntityExt::SetKeyValueColor, | ||
| 147 | + "Sets a field to the given value.", | ||
| 148 | + args("field_name", "value") | ||
| 149 | + ); | ||
| 150 | + | ||
| 78 | 151 | // Add memory tools... | |
| 79 | 152 | BaseEntity ADD_MEM_TOOLS(CBaseEntity); | |
| 80 | 153 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -32,7 +32,6 @@ | |||
| 32 | 32 | #include "edict.h" | |
| 33 | 33 | #include "server_class.h" | |
| 34 | 34 | #include <cstdint> | |
| 35 | - #include "toolframework/itoolentity.h" | ||
| 36 | 35 | #include "modules/memory/memory_tools.h" | |
| 37 | 36 | #include "string_t.h" | |
| 38 | 37 | #include "dt_send.h" | |
@@ -43,73 +42,6 @@ | |||
| 43 | 42 | #include "utilities/conversions.h" | |
| 44 | 43 | ||
| 45 | 44 | ||
| 46 | - //----------------------------------------------------------------------------- | ||
| 47 | - // External variables. | ||
| 48 | - //----------------------------------------------------------------------------- | ||
| 49 | - extern IServerTools* servertools; | ||
| 50 | - | ||
| 51 | - | ||
| 52 | - //----------------------------------------------------------------------------- | ||
| 53 | - // edict_t extension class. | ||
| 54 | - //----------------------------------------------------------------------------- | ||
| 55 | - class CEdictExt | ||
| 56 | - { | ||
| 57 | - public: | ||
| 58 | - static str GetKeyValueString(edict_t* pEdict, const char* szName) | ||
| 59 | - { | ||
| 60 | - char szResult[1024]; | ||
| 61 | - CBaseEntity* pEntity = pEdict->GetUnknown()->GetBaseEntity(); | ||
| 62 | - servertools->GetKeyValue(pEntity, szName, szResult, 1024); | ||
| 63 | - | ||
| 64 | - // Fix for field name "model". I think a string_t object is copied to szResult. | ||
| 65 | - if (strcmp(szName, "model") == 0) | ||
| 66 | - return *(char **) szResult; | ||
| 67 | - | ||
| 68 | - return str(szResult); | ||
| 69 | - } | ||
| 70 | - | ||
| 71 | - static int GetKeyValueInt(edict_t* pEdict, const char* szName) | ||
| 72 | - { | ||
| 73 | - return extract<int>(eval("lambda x: int(x)")(GetKeyValueString(pEdict, szName))); | ||
| 74 | - } | ||
| 75 | - | ||
| 76 | - static float GetKeyValueFloat(edict_t* pEdict, const char* szName) | ||
| 77 | - { | ||
| 78 | - return extract<float>(eval("lambda x: float(x)")(GetKeyValueString(pEdict, szName))); | ||
| 79 | - } | ||
| 80 | - | ||
| 81 | - static Vector GetKeyValueVector(edict_t* pEdict, const char* szName) | ||
| 82 | - { | ||
| 83 | - object vec = eval("lambda x: tuple(map(float, x.split(' ')))")(GetKeyValueString(pEdict, szName)); | ||
| 84 | - return Vector(extract<float>(vec[0]), extract<float>(vec[1]), extract<float>(vec[2])); | ||
| 85 | - } | ||
| 86 | - | ||
| 87 | - static bool GetKeyValueBool(edict_t* pEdict, const char* szName) | ||
| 88 | - { | ||
| 89 | - return strcmp(extract<const char *>(GetKeyValueString(pEdict, szName)), "1") == 0; | ||
| 90 | - } | ||
| 91 | - | ||
| 92 | - static Color GetKeyValueColor(edict_t* pEdict, const char* szName) | ||
| 93 | - { | ||
| 94 | - object color = eval("lambda x: tuple(map(int, x.split(' ')))")(GetKeyValueString(pEdict, szName)); | ||
| 95 | - return Color(extract<int>(color[0]), extract<int>(color[1]), extract<int>(color[2]), extract<int>(color[3])); | ||
| 96 | - } | ||
| 97 | - | ||
| 98 | - static void SetKeyValueColor(edict_t* pEdict, const char* szName, Color color) | ||
| 99 | - { | ||
| 100 | - char string[16]; | ||
| 101 | - Q_snprintf(string, sizeof(string), "%i %i %i %i", color.r(), color.g(), color.b(), color.a()); | ||
| 102 | - SetKeyValue(pEdict, szName, string); | ||
| 103 | - } | ||
| 104 | - | ||
| 105 | - template<class T> | ||
| 106 | - static void SetKeyValue(edict_t* pEdict, const char* szName, T value) | ||
| 107 | - { | ||
| 108 | - servertools->SetKeyValue(BaseEntityFromEdict(pEdict, true), szName, value); | ||
| 109 | - } | ||
| 110 | - }; | ||
| 111 | - | ||
| 112 | - | ||
| 113 | 45 | //----------------------------------------------------------------------------- | |
| 114 | 46 | // CTakeDamageInfo wrapper class. | |
| 115 | 47 | //----------------------------------------------------------------------------- | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -379,78 +379,6 @@ void export_edict(scope _entities) | |||
| 379 | 379 | reference_existing_object_policy() | |
| 380 | 380 | ) | |
| 381 | 381 | ||
| 382 | - .def("get_key_value_string", | ||
| 383 | - &CEdictExt::GetKeyValueString, | ||
| 384 | - "Returns the value of the given field name.", | ||
| 385 | - args("field_name") | ||
| 386 | - ) | ||
| 387 | - | ||
| 388 | - .def("get_key_value_int", | ||
| 389 | - &CEdictExt::GetKeyValueInt, | ||
| 390 | - "Returns the value of the given field name.", | ||
| 391 | - args("field_name") | ||
| 392 | - ) | ||
| 393 | - | ||
| 394 | - .def("get_key_value_float", | ||
| 395 | - &CEdictExt::GetKeyValueFloat, | ||
| 396 | - "Returns the value of the given field name.", | ||
| 397 | - args("field_name") | ||
| 398 | - ) | ||
| 399 | - | ||
| 400 | - .def("get_key_value_vector", | ||
| 401 | - &CEdictExt::GetKeyValueVector, | ||
| 402 | - "Returns the value of the given field name.", | ||
| 403 | - args("field_name") | ||
| 404 | - ) | ||
| 405 | - | ||
| 406 | - .def("get_key_value_bool", | ||
| 407 | - &CEdictExt::GetKeyValueBool, | ||
| 408 | - "Returns the value of the given field name.", | ||
| 409 | - args("field_name") | ||
| 410 | - ) | ||
| 411 | - | ||
| 412 | - .def("get_key_value_color", | ||
| 413 | - &CEdictExt::GetKeyValueColor, | ||
| 414 | - "Returns the value of the given field name.", | ||
| 415 | - args("field_name") | ||
| 416 | - ) | ||
| 417 | - | ||
| 418 | - .def("set_key_value_int", | ||
| 419 | - &CEdictExt::SetKeyValue<int>, | ||
| 420 | - "Sets a field to the given value.", | ||
| 421 | - args("field_name", "value") | ||
| 422 | - ) | ||
| 423 | - | ||
| 424 | - .def("set_key_value_float", | ||
| 425 | - &CEdictExt::SetKeyValue<float>, | ||
| 426 | - "Sets a field to the given value.", | ||
| 427 | - args("field_name", "value") | ||
| 428 | - ) | ||
| 429 | - | ||
| 430 | - .def("set_key_value_string", | ||
| 431 | - &CEdictExt::SetKeyValue<const char *>, | ||
| 432 | - "Sets a field to the given value.", | ||
| 433 | - args("field_name", "value") | ||
| 434 | - ) | ||
| 435 | - | ||
| 436 | - .def("set_key_value_vector", | ||
| 437 | - &CEdictExt::SetKeyValue<Vector>, | ||
| 438 | - "Sets a field to the given value.", | ||
| 439 | - args("field_name", "value") | ||
| 440 | - ) | ||
| 441 | - | ||
| 442 | - .def("set_key_value_bool", | ||
| 443 | - &CEdictExt::SetKeyValue<bool>, | ||
| 444 | - "Sets a field to the given value.", | ||
| 445 | - args("field_name", "value") | ||
| 446 | - ) | ||
| 447 | - | ||
| 448 | - .def("set_key_value_color", | ||
| 449 | - &CEdictExt::SetKeyValueColor, | ||
| 450 | - "Sets a field to the given value.", | ||
| 451 | - args("field_name", "value") | ||
| 452 | - ) | ||
| 453 | - | ||
| 454 | 382 | // Class attributes | |
| 455 | 383 | /* | |
| 456 | 384 | // TODO: Missing on CS:GO | |
| Back | FazBrowse Home | New Git URL |
0 commit comments