Skip to content

A Source SDK 2013 fork with automatically generated bindings for Python 3.

License

Notifications You must be signed in to change notification settings

Sandern/py-source-sdk-2013

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PySource

A Source SDK 2013 fork with automatically generated bindings for Python 3. The aim of these bindings is to have a (semi) safe Python environment of Source Engine to play around with. For a better idea of what these bindings offer, check out the examples directory.

These automatic bindings were originally made for Lambda Wars mod. Also see the Python folder of this for more examples of what is possible (most game code is written in Python!).

Please let me know if you have any issues. Pull requests are welcome too!

Quick-start

Currently tested on Windows (VS2013 Community Update 5) and OSX (XCode 7.3) only:

  1. Run mp/src/createpysourceprojects

  2. Open games.sln or games.xproj and compile. For OSX, you might need to change the projects sdk.

  3. Start mp/game/PySource and load a map

  4. Test Python by entering one of the following commands:

     spy print('Hello Source')
    
     spy print(UTIL_PlayerByIndex(1).GetPlayerName())
    

Examples

Examples can be found in the Python game directory examples. These examples cover the Your First Entity page from VDC among others.

Commands

    spy - Evaluates a Python string on the server

    cpy - Evaluates a Python string on the client

Generating new modules

PySource makes use of castxml, pygccxml and pyplusplus to generate Boost Python bindings. You can find instructions in mp/src/srcpypp.

Disabling modules.

Open mp/src/srcpypp/settings.py and uncomment the unwanted modules. Then run in the same folder:

    python3 generatemods.py -a

An updated vpc file will be generated, so after this step you need to rebuild your project files.

Most of the modules can be disabled, but the example modules will fail to import. Also the srcbuiltins module exposes Msg and Warning functions to Python, which is used to redirect stdout and stderr.

List of binding modules

  • _animation: Exposed functions from - animation.h
  • _entities: Exposes most base entity classes (CBaseEntity, CBaseAnimating, etc)
  • _entitiesmisc: Exposes miscellaneous bindings related to entities, like the entity list
  • _gamerules: Exposes Gamerules classes. Allows creating and installing custom Gamerules on the fly.
  • _gameinterface: Exposes game engine interface, user messages, ConCommands and ConVars among others.
  • _input: Exposes client IInput interface and key defines.
  • materials: Exposes materials related functions.
  • _ndebugoverlay: Exposes NDebugOverlay functions.
  • _particles: Exposed Particle system related functions, like DispatchParticleEffect.
  • _physics: Exposed IPhysicsObject and related.
  • _sound: Exposes sound engine interface and related.
  • srcbuiltins: Exposes debug Msg functions, used for redirecting output of Python
  • _steam: Exposes steam api related classes.
  • _te: Exposes temporary effects/entities, client side effects and FX_ functions
  • _utils: Exposes utils functions and related (e.g. UTIL_TraceLine)
  • _vgui: Exposes client VGUI related classes and functions.
  • _vguicontrols: Exposes client VGUI base Panel classes.
  • _vmath: Exposes mathlib
  • vprof: Exposes VProfiling

Note: Most of these modules are complemented by Python modules (e.g. entities)

About

A Source SDK 2013 fork with automatically generated bindings for Python 3.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C++ 94.0%
  • C 2.8%
  • Python 2.2%
  • Objective-C 0.4%
  • GLSL 0.3%
  • Perl 0.2%
  • Other 0.1%