Skip to content

Commit d0014e0

Browse files
authored
Add support for GMod (Source-Python-Dev-Team#200)
* Start of GMod support. * Patched memalloc.h * Removed memalloc.h patch * Patched ../game/shared/collisionproperty.h * Fixed EmitSound * Patched matlib.lib * Added back _EngineServer.get_cluster_sound * Remove ../game/shared/collisionproperty.h patch * Removed cluster_count from other engines now that it is supported in GMod (therefore, all engines). * Added GetEntityFactoryDictionary to gmod. * Added server_version and create_fake_client_ex to engine_server for gmod. * Updated memory.manager to use GameConfigObj instead of ConfigObj. * Fixed OSError * Added BaseEntityOutput.fire_output data. * Fixed a NameError when unloading * Added data for CGlobalEntityList Requires this PR to be merged: alliedmodders/hl2sdk#29 * Added data for IServer * Fixed compiler and linker errors for GMod on Linux * Added data for CBaseClient * Added data for _WeaponDatabase * Added _WeaponDatabase class Fixed _WeaponDatabase signature * Added effects data * Fixed missing engine specific export function for GMod * Fixed an error when loading GMod * Removed a redundant patch * Fixed compiler errors due to output listener update
1 parent 6d90665 commit d0014e0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+2279
-25
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# ../data/source-python/client/gmod/CBaseClient.ini
2+
3+
[virtual_function]
4+
[[set_name]]
5+
offset_linux = 56
6+
offset_windows = 17
7+
arguments = STRING
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# ../effects/gmod/CTEAntlionDust.ini
2+
# Temp Entity Name: AntlionDust
3+
4+
is_spawner_blocked = m_bBlockedSpawner
5+
angles = m_vecAngles
6+
7+
[origin]
8+
name = m_vecOrigin[0]
9+
type = Vector
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# ../effects/gmod/CTEConcussiveExplosion.ini
2+
# Temp Entity Name: ConcussiveExplosion
3+
4+
scale = m_flScale
5+
magnitude = m_nMagnitude
6+
radius = m_nRadius
7+
normal = m_vecNormal
8+
9+
[origin]
10+
name = m_vecOrigin[0]
11+
type = Vector
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# ../effects/gmod/CTEEffectDispatch.ini
2+
# Temp Entity Name: EffectDispatch
3+
4+
entity_index = m_EffectData.entindex
5+
particle_attachment = m_EffectData.m_ControlPoint1.m_eParticleAttachment
6+
primary_color = m_EffectData.m_CustomColors.m_vecColor1
7+
secondary_color = m_EffectData.m_CustomColors.m_vecColor2
8+
control_point = m_EffectData.m_bControlPoint1
9+
has_custom_colors = m_EffectData.m_bCustomColors
10+
flags = m_EffectData.m_fFlags
11+
magnitude = m_EffectData.m_flMagnitude
12+
radius = m_EffectData.m_flRadius
13+
scale = m_EffectData.m_flScale
14+
effect_name_index = m_EffectData.m_iEffectName
15+
attachment_index = m_EffectData.m_nAttachmentIndex
16+
color = m_EffectData.m_nColor
17+
damage_type = m_EffectData.m_nDamageType
18+
hitbox = m_EffectData.m_nHitBox
19+
material_index = m_EffectData.m_nMaterial
20+
surface_prop = m_EffectData.m_nSurfaceProp
21+
angles = m_EffectData.m_vAngles
22+
normal = m_EffectData.m_vNormal
23+
allow_override = m_bAllowOverride
24+
25+
[offset]
26+
name = m_EffectData.m_ControlPoint1.m_vecOffset[0]
27+
type = Vector
28+
29+
[origin]
30+
name = m_EffectData.m_vOrigin[0]
31+
type = Vector
32+
33+
[start]
34+
name = m_EffectData.m_vStart[0]
35+
type = Vector
36+
37+
[entity]
38+
name = entity_index
39+
type = Entity
40+
41+
[material]
42+
name = material_index
43+
type = Model
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# ../effects/gmod/CTEHL2MPFireBullets.ini
2+
# Temp Entity Name: Shotgun Shot
3+
4+
do_impacts = m_bDoImpacts
5+
do_tracers = m_bDoTracers
6+
spread = m_flSpread
7+
ammo_id = m_iAmmoID
8+
player_index = m_iPlayer
9+
seed = m_iSeed
10+
shots = m_iShots
11+
direction = m_vecDir
12+
origin = m_vecOrigin
13+
tracer_type = m_TracerType
14+
15+
[player]
16+
name = player_index
17+
type = Player
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# ../effects/gmod/CTEPhysicProp.ini
2+
# Temp Entity Name: physicsprop
3+
4+
effects = m_nEffects
5+
flags = m_nFlags
6+
model_index = m_nModelIndex
7+
skin = m_nSkin
8+
origin = m_vecOrigin
9+
velocity = m_vecVelocity
10+
11+
[rotation]
12+
name = m_angRotation[0]
13+
type = Vector
14+
15+
[model]
16+
name = model_index
17+
type = Model
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# ../effects/gmod/CTEPlayerAnimEvent.ini
2+
# Temp Entity Name: PlayerAnimEvent
3+
4+
player_handle = m_hPlayer
5+
event = m_iEvent
6+
data = m_nData
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# ../data/source-python/entity_output/gmod/CBaseEntityOutput.ini
2+
3+
binary = server
4+
5+
[function]
6+
[[fire_output]]
7+
identifier_linux = _ZN17CBaseEntityOutput10FireOutputE9variant_tP11CBaseEntityS2_f
8+
identifier_windows = 55 8B EC 81 EC 20 01 00 00 53 56 8B
9+
arguments_linux = POINTER, POINTER, POINTER, FLOAT
10+
arguments_windows = INT, INT, INT, INT, POINTER, POINTER, POINTER, FLOAT
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# ../data/source-python/memory/gmod/global_pointers.ini
2+
3+
[CGlobalEntityList]
4+
binary = server
5+
identifier_linux = gEntList
6+
identifier_windows = 55 8B EC 83 EC 08 56 57 8B 7D 08 6A 00 B9
7+
offset_windows = 14
8+
level_windows = 1
9+
10+
[IServer]
11+
binary = bin/engine
12+
identifier_linux = sv
13+
identifier_windows = 55 8B EC 53 56 8B 75 0C 57 85 F6
14+
offset_windows = 27
15+
level_windows = 1
16+
17+
[CBaseTempEntity]
18+
binary = server
19+
identifier_linux = _ZN15CBaseTempEntity15s_pTempEntitiesE
20+
identifier_windows = 56 8B 35 2A 2A 2A 2A 85 F6 74 2A EB 2A 8D 49 00 8B 06
21+
offset_windows = 3
22+
level_windows = 2
23+
level_linux = 1
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# ../data/source-python/weapons/scripts/gmod/global_pointers.ini
2+
3+
[_WeaponDatabase]
4+
identifier_linux = _ZL20m_WeaponInfoDatabase
5+
identifier_windows = 55 8B EC 81 EC 88 2A 2A 2A 56 8B 75 10 85 F6 75 07 32 C0 5E
6+
offset_windows = 37
7+
level_windows = 1

addons/source-python/packages/source-python/__init__.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@
2929
# =============================================================================
3030
# >> IMPORTS
3131
# =============================================================================
32+
# Python Imports
33+
# Context
34+
from contextlib import suppress
35+
3236
# Source.Python Imports
3337
# Loggers
3438
from loggers import _sp_logger # It's save to import this here
@@ -286,8 +290,9 @@ def remove_entities_listener():
286290
from _core import _sp_plugin
287291
from memory.manager import manager
288292

289-
manager.get_global_pointer('GlobalEntityList').remove_entity_listener(
290-
_sp_plugin)
293+
with suppress(NameError):
294+
manager.get_global_pointer('GlobalEntityList').remove_entity_listener(
295+
_sp_plugin)
291296

292297

293298
# =============================================================================

addons/source-python/packages/source-python/listeners/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,7 @@ def _pre_call_global_change_callbacks(args):
540540
# >> Fix for issue #181.
541541
# ============================================================================
542542
# Get the function name to hook...
543-
if SOURCE_ENGINE in ('bms', 'orangebox'):
543+
if SOURCE_ENGINE in ('bms', 'orangebox', 'gmod'):
544544
_hibernation_function_name = 'SetServerHibernation'
545545
elif SOURCE_ENGINE in ('blade', 'csgo', 'l4d2'):
546546
_hibernation_function_name = 'ServerHibernationUpdate'

addons/source-python/packages/source-python/memory/manager.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,9 @@
55
# =============================================================================
66
# >> IMPORTS
77
# =============================================================================
8-
# Site-Package Imports
9-
# ConfigObj
10-
from configobj import ConfigObj
11-
128
# Source.Python Imports
9+
# Core
10+
from core import GameConfigObj
1311
# Memory
1412
from memory import Convention
1513
from memory import DataType
@@ -294,7 +292,7 @@ def create_pipe(cls_dict):
294292

295293
def create_pipe_from_file(self, f):
296294
"""Create a pipe from a file or URL."""
297-
return self.create_pipe_from_dict(ConfigObj(f, file_error=True))
295+
return self.create_pipe_from_dict(GameConfigObj(f))
298296

299297
def create_pipe_from_dict(self, raw_data):
300298
"""Create a pipe from a dictionary."""
@@ -341,7 +339,7 @@ def pipe_function(
341339
def create_type_from_file(self, type_name, f, bases=(CustomType,)):
342340
"""Create and registers a new type from a file or URL."""
343341
return self.create_type_from_dict(
344-
type_name, ConfigObj(f, file_error=True), bases)
342+
type_name, GameConfigObj(f), bases)
345343

346344
def create_type_from_dict(self, type_name, raw_data, bases=(CustomType,)):
347345
"""Create and registers a new type from a dictionary."""
@@ -697,7 +695,7 @@ def make_function(ptr):
697695
def create_function_typedefs_from_file(self, f):
698696
"""Create function typedefs from a file."""
699697
# Read the data
700-
raw_data = ConfigObj(f, file_error=True)
698+
raw_data = GameConfigObj(f)
701699

702700
# Prepare typedefs
703701
typedefs = parse_data(
@@ -740,7 +738,7 @@ def create_global_pointers_from_file(self, f):
740738
# Parse pointer data
741739
pointers = parse_data(
742740
self,
743-
ConfigObj(f, file_error=True),
741+
GameConfigObj(f),
744742
(
745743
(Key.BINARY, Key.as_str, NO_DEFAULT),
746744
(Key.IDENTIFIER, Key.as_identifier, NO_DEFAULT),

src/core/modules/cvars/gmod/cvars.h

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/**
2+
* =============================================================================
3+
* Source Python
4+
* Copyright (C) 2014 Source Python Development Team. All rights reserved.
5+
* =============================================================================
6+
*
7+
* This program is free software; you can redistribute it and/or modify it under
8+
* the terms of the GNU General Public License, version 3.0, as published by the
9+
* Free Software Foundation.
10+
*
11+
* This program is distributed in the hope that it will be useful, but WITHOUT
12+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13+
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
14+
* details.
15+
*
16+
* You should have received a copy of the GNU General Public License along with
17+
* this program. If not, see <http://www.gnu.org/licenses/>.
18+
*
19+
* As a special exception, the Source Python Team gives you permission
20+
* to link the code of this program (as well as its derivative works) to
21+
* "Half-Life 2," the "Source Engine," and any Game MODs that run on software
22+
* by the Valve Corporation. You must obey the GNU General Public License in
23+
* all respects for all other code used. Additionally, the Source.Python
24+
* Development Team grants this exception to all derivative works.
25+
*/
26+
27+
#ifndef _CVARS_GMOD_H
28+
#define _CVARS_GMOD_H
29+
30+
//-----------------------------------------------------------------------------
31+
// Includes.
32+
//-----------------------------------------------------------------------------
33+
#include "icvar.h"
34+
35+
36+
//-----------------------------------------------------------------------------
37+
// ICVar extension class.
38+
//-----------------------------------------------------------------------------
39+
class ICVarExt
40+
{
41+
public:
42+
static ConCommandBase* GetCommands(ICvar* pCvar)
43+
{
44+
return pCvar->GetCommands();
45+
};
46+
};
47+
48+
#endif // _CVARS_GMOD_H
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/**
2+
* =============================================================================
3+
* Source Python
4+
* Copyright (C) 2012-2015 Source Python Development Team. All rights reserved.
5+
* =============================================================================
6+
*
7+
* This program is free software; you can redistribute it and/or modify it under
8+
* the terms of the GNU General Public License, version 3.0, as published by the
9+
* Free Software Foundation.
10+
*
11+
* This program is distributed in the hope that it will be useful, but WITHOUT
12+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13+
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
14+
* details.
15+
*
16+
* You should have received a copy of the GNU General Public License along with
17+
* this program. If not, see <http://www.gnu.org/licenses/>.
18+
*
19+
* As a special exception, the Source Python Team gives you permission
20+
* to link the code of this program (as well as its derivative works) to
21+
* "Half-Life 2," the "Source Engine," and any Game MODs that run on software
22+
* by the Valve Corporation. You must obey the GNU General Public License in
23+
* all respects for all other code used. Additionally, the Source.Python
24+
* Development Team grants this exception to all derivative works.
25+
*/
26+
27+
#ifndef _EFFECTS_BASE_WRAP_GMOD_H
28+
#define _EFFECTS_BASE_WRAP_GMOD_H
29+
30+
//-----------------------------------------------------------------------------
31+
// Includes.
32+
//-----------------------------------------------------------------------------
33+
#include "game/shared/itempents.h"
34+
#include "toolframework/itoolentity.h"
35+
#include "game/server/basetempentity.h"
36+
37+
38+
//-----------------------------------------------------------------------------
39+
// External variables.
40+
//-----------------------------------------------------------------------------
41+
extern IServerTools *servertools;
42+
43+
44+
//-----------------------------------------------------------------------------
45+
// Exports CBaseTempEntity.
46+
//-----------------------------------------------------------------------------
47+
template<class T, class U>
48+
void export_engine_specific_temp_entity(T _base, U TempEntity)
49+
{
50+
// Nothing specific to GMod...
51+
}
52+
53+
54+
#endif // _EFFECTS_BASE_WRAP_GMOD_H

src/core/modules/engines/engines_server_wrap.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -565,18 +565,18 @@ static void export_engine_server(scope _server)
565565
args("benchmark_mode")
566566
)
567567

568+
.add_property("cluster_count",
569+
&IVEngineServer::GetClusterCount,
570+
"Returns total number of clusters."
571+
)
572+
568573
/*
569574
.def("is_split_screen_player",
570575
&IVEngineServer::SetDedicatedServerBenchmarkMode,
571576
args("ent_num")
572577
)
573578
*/
574579

575-
.add_property("cluster_count",
576-
&IVEngineServer::GetClusterCount,
577-
"Returns total number of clusters."
578-
)
579-
580580
/*
581581
TODO: Create a wrapper that requires a list or tuple with bbox_t elements
582582
.def("get_all_cluster_bounds",

0 commit comments

Comments
 (0)