Skip to content

PhundIO-Dota2/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. 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 of the mod 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

Visual Studio Python Tools support (Experimental)

To allow easier debugging, Visual Studio Python Tools is supported. This includes Intellisense and setting breakpoints in Python code.

You can download VSPT from:

    http://pytools.codeplex.com/

To use VSPT, you must first add a new Python Environment:

  1. Open Python.sln
  2. Go to "Tools -> Options"
  3. Go to "Python Tools -> Environment Options" and click "Add Environment"
  4. Enter name "Python 3.4 Source Engine"
  5. Enter "Path": path\to\py-source-sdk-2013\mp\game\pysource\python\vspt_server.bat
  6. Enter "Window Path": path\to\py-source-sdk-2013\mp\game\pysource\python\vspt_server.bat
  7. Enter "Library Path": path\to\py-source-sdk-2013\mp\game\pysource\python\Lib
  8. Set Architecture to "x86" and Language Version to "3.4"
  9. Go to "View -> Other Windows -> Python Environments". In the new tab press "Refresh DB" on the "Python 3.4 Source Engine" entry

This will update the Intellisense database. It launches the game in text mode to do so. You can now test the environment by clicking ''Interactive Window'' (type something like "import entities", followed by "entities." to see intellisense working).

Follow these steps to start a debugging session using VSPT:

  1. Open Python.sln
  2. Remove the "Unknown Python 3.4" entry from "Python Environments" in the project
  3. Add "Python 3.4 Source Engine" to the project
  4. Go to properties of "Python.sln"
  5. Go to the Debug tab
  6. Add "-sv -noborder -dev -game "path\to\pysource" -vsptdebug" to "Interpreter Arguments"
  7. Add "path\to\SteamApps\common\Source SDK Base 2013 Multiplayer\hl2.exe" to "Interpreter Path"
  8. Debug -> Start Debugging

Try set a breakpoint in ''examples/commands.py'' to verify debugging works.

Generating new modules

PySource makes use of gccxml, 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:

    python 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++ 89.3%
  • C 7.8%
  • Python 1.9%
  • Objective-C 0.4%
  • GLSL 0.2%
  • Perl 0.2%
  • Other 0.2%