Source-Python-Dev-Team / Source.Python

This plugin aims to use boost::python and create an easily accessible wrapper around the Source Engine API for scripter use.
http://forums.sourcepython.com
GNU General Public License v3.0
164 stars 32 forks source link

Need something like metamod or sourcemod-extension #172

Closed PerfectLaugh closed 7 years ago

PerfectLaugh commented 7 years ago

I don't know whether it is a good place to post forum-like thread. Forgive me if I miss something. Upon reading the source code of SourcePython, I found that every interfaces needed by SourcePython was wrapped at core dll level. This is quite confusing me since I don't want to start a time-consuming pull request because of a missing interface I needed. I would expect something like metamod wrapping GetInterface or other nasty C++ things, then I can expose things to Python at module-level, without the need to start a pull request.

Ayuto commented 7 years ago

You have two possibilities to get the interface you need:

  1. Use the memory module to retrieve the pointer and reconstruct the interface class.
  2. Write a Python module in C++ (an example can be found here: https://github.com/Ayuto/SP-Lua-Bridge). Obviously, it doesn't use the SDK, but that should work fine as well.
satoon101 commented 7 years ago

Which interface are you wanting access to?

PerfectLaugh commented 7 years ago

I was trying to make a plugin like stripper-source, which uses the following: INTERFACEVERSION_VENGINESERVER (Included in SP) INTERFACEVERSION_SERVERGAMEDLL INTERFACEVERSION_SERVERGAMECLIENTS

PerfectLaugh commented 7 years ago

Well I just want to say, in my limited knowledge in SP, I see no CreateInterface like function exposed for plugins

PerfectLaugh commented 7 years ago

Or maybe I can try to make a pull request to expose that kind of function, somehow

satoon101 commented 7 years ago

We do export a couple IServerGameDLL functions: https://github.com/Source-Python-Dev-Team/Source.Python/blob/2be091cdbbbbc11c026728a5e464affc3439d7a5/src/core/modules/engines/engines_server_wrap.cpp#L781

What specific functions are you wanting from these 3 interfaces? Maybe there might be some merit to us exposing them ourselves. Is it just these 3?: https://github.com/alliedmodders/stripper-source/blob/75f9ef985b324d7c7712229175fa04e010ccb769/gameshim/stripper_mm.cpp#L246-#L248

If so, the only one we don't already expose is IServerGameClients::SetCommandClient. We do use that ourselves to know which use used "say" or "say_team", but we did not actually expose it.

We don't expose LevelInit to be called directly. But, it seems the only references in stripper-source are hooks, which is exactly what is already available with our LevelInit listener.

PerfectLaugh commented 7 years ago

Well since the SetCommandClient is used by stripper for only dump command purpose, it is not necessary to expose that after all. The main question is: Do I have to send a pull request to master? or is there a way to let me add virtual functions and boost python implementation without pulling to master?

PerfectLaugh commented 7 years ago

It does have some merit to pull all the things to master though, it will be inconvenience for a user want to expose something personally. He will have to send a pull request.

satoon101 commented 7 years ago

You can use the memory package to grab virtual and dynamic functions within a plugin itself.

For your specific case, though, it seems that you have access to everything you need, at least from what I see in stripper-source's source code. If there is something I am missing that you do need, please mention it and we'll see what we can do on our end.

We have done a pretty good job of exposing everything that we see as useful to plugin developers, but I am sure there are more things that we could (should?) expose. If you see anything specific, we can certainly discuss the merits of it. The original design was to expose everything possible, but we've learned that that wasn't really the best approach, for multiple reasons.

Ayuto commented 7 years ago

It does have some merit to pull all the things to master though, it will be inconvenience for a user want to expose something personally. He will have to send a pull request.

Again, beside the memory package you can also create your own Python module in C++. There is no need to create Pull Requests. Though, if it's something that could be useful for more people, it would make sense to create one.