Source Python for GMod?

All other Source.Python topics and issues.
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Re: Source Python for GMod?

Postby satoon101 » Thu Aug 25, 2016 9:41 pm

And, we can eliminate the fire_output errors if we change listeners._entity_output to something like:

Syntax: Select all

# ../listeners/_entity_output.py

"""Provides a listener manager for entity outputs."""

# =============================================================================
# >> IMPORTS
# =============================================================================
# Source.Python Imports
# Core
from core import GameConfigObj
from core import PLATFORM
# Paths
from paths import SP_DATA_PATH
# Memory
import memory

from memory.hooks import PreHook
from memory.manager import manager
# Entity
from entities.entity import BaseEntity
from entities.entity import Entity
from entities.datamaps import Variant
from entities.helpers import find_output_name
# Listeners
from _listeners import ListenerManager


# =============================================================================
# >> GLOBAL VARIABLES
# =============================================================================
BaseEntityOutput = manager.create_type_from_dict(
'BaseEntityOutput', GameConfigObj(
SP_DATA_PATH / 'entity_output' / 'CBaseEntityOutput.ini'))

_fire_output = getattr(BaseEntityOutput, 'fire_output', None)
on_entity_output_listener_manager = (
None if _fire_output is None else ListenerManager()
)


# =============================================================================
# >> CALLBACKS
# =============================================================================
if _fire_output is not None:
@PreHook(_fire_output)
def _pre_fire_output(args):
"""Called when an output is about to be fired."""
if not on_entity_output_listener_manager:
return

# Windows is a bit weird: the function takes 4 additional arguments...
if PLATFORM == 'windows':
args = (args[0],) + tuple(args)[5:]

caller_ptr = args[3]
if not caller_ptr:
# If we don't know the caller, we won't be able to retrieve the
# output name
return

caller = memory.make_object(BaseEntity, caller_ptr)
output_name = find_output_name(caller, args[0])
if output_name is None:
return None

if caller.is_networked():
caller = memory.make_object(Entity, caller_ptr)

value_ptr = args[1]
value = (value_ptr or None) and memory.make_object(Variant, value_ptr)

activator_ptr = args[2]
activator = ((activator_ptr or None) and memory.make_object(
BaseEntity, activator_ptr))
if activator is not None and activator.is_networked():
activator = memory.make_object(Entity, activator_ptr)

delay = args[4]
on_entity_output_listener_manager.notify(
output_name, activator, caller, value, delay)


We might want to at least print warnings, so that it is known that this functionality is not available. The same should probably be done to the OnEntityOutput listener.
Image
User avatar
L'In20Cible
Project Leader
Posts: 1533
Joined: Sat Jul 14, 2012 9:29 pm
Location: Québec

Re: Source Python for GMod?

Postby L'In20Cible » Thu Aug 25, 2016 10:17 pm

As for the global pointers, we could make the manager.get_global_pointer method to act like dict.get adding a default keyword that return it upon fail or raise if not defined. We could then use that feature to return a custom NotImplementedPointer that raises on __getattr__ or something like that. Tho we could also simply ignore global pointer errors into the initialization process since definitions to None has been added a couple weeks ago which means that if they are None, they are not implemented.
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Re: Source Python for GMod?

Postby satoon101 » Thu Aug 25, 2016 10:20 pm

That last one sounds like a good idea to me. We could wrap each of those calls in a suppress.
Image
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Re: Source Python for GMod?

Postby satoon101 » Fri Aug 26, 2016 12:24 am

I am working on downloading the Linux server right now. Once that is done, I will upload all the server binaries to my Dropbox, if you have the time to get the data from them.
Image
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Re: Source Python for GMod?

Postby satoon101 » Fri Aug 26, 2016 1:08 am

I just pushed changes to the master branch to fix these missing data issues. I'll pull it into the gmod branch and push that up, too. GMod server is still downloading, should be done in the next few minutes.

*Edit: actually, we no longer need the EntityFactoryDictionary, as the engine now supports GetEntityFactoryDictionary. I updated the branch with that change.
Image
User avatar
L'In20Cible
Project Leader
Posts: 1533
Joined: Sat Jul 14, 2012 9:29 pm
Location: Québec

Re: Source Python for GMod?

Postby L'In20Cible » Fri Aug 26, 2016 4:09 am

Interesting. Garry's Mod have both, server.so and server_srv.so. I guess we will have to make sure to define the right one into our data files. Will grab the required signatures in a few.
User avatar
L'In20Cible
Project Leader
Posts: 1533
Joined: Sat Jul 14, 2012 9:29 pm
Location: Québec

Re: Source Python for GMod?

Postby L'In20Cible » Fri Aug 26, 2016 8:00 am

I'm having trouble getting the address of gEntList.

Syntax: Select all

# ../data/source-python/memory/gmod/global_pointers.ini

[CGlobalEntityList]
binary = server
identifier_linux = gEntList
identifier_windows = 55 8B EC 83 EC 08 56 57 8B 7D 08 6A 00 B9
offset_windows = 14
level_windows = 1


No doubt that the signature is right but the server crash with the following exception:

Code: Select all

The thread tried to read from or write to a virtual address for which it does not have the appropriate access.


Seems like Garry doesn't like memory hacking.
User avatar
Doldol
Senior Member
Posts: 200
Joined: Sat Jul 07, 2012 7:09 pm
Location: Belgium

Re: Source Python for GMod?

Postby Doldol » Fri Aug 26, 2016 5:41 pm

Urh, and I was thinking that at one point we'll probably have to access the Gmod Lua API if we want to do GMod specific stuff with SP (for example, create a server-side UI), since I'm pretty sure it wouldn't be possible, or hard to get access to all the C functions that Lua wraps for it's api functions, etc.

As far as I can see, it should be possible to wrap the functions for the C Lua API inside lua_shared_srv.so/dll, and call them like we would with any C functions wrapped from the engine. How to use the GLua API from C++: https://wiki.garrysmod.com/page/C_Lua:_Functions
User avatar
L'In20Cible
Project Leader
Posts: 1533
Joined: Sat Jul 14, 2012 9:29 pm
Location: Québec

Re: Source Python for GMod?

Postby L'In20Cible » Fri Aug 26, 2016 10:48 pm

Offering the functionalities proposed by the engine itself is definitely planned but, as far as wrapping Lua into SP I'd say no. At least, I would not personally dig into that. Custom packages written by the community seems to fit perfectly fine for such a thing, imo.
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Re: Source Python for GMod?

Postby satoon101 » Fri Aug 26, 2016 11:09 pm

L'In20Cible wrote:Offering the functionalities proposed by the engine itself is definitely planned but, as far as wrapping Lua into SP I'd say no. At least, I would not personally dig into that. Custom packages written by the community seems to fit perfectly fine for such a thing, imo.

Agreed. I can't imagine what you would be able to accomplish with that that you couldn't accomplish with just SP.
Image
User avatar
Doldol
Senior Member
Posts: 200
Joined: Sat Jul 07, 2012 7:09 pm
Location: Belgium

Re: Source Python for GMod?

Postby Doldol » Sat Aug 27, 2016 1:07 am

L'In20Cible wrote:Offering the functionalities proposed by the engine itself is definitely planned but, as far as wrapping Lua into SP I'd say no. At least, I would not personally dig into that. Custom packages written by the community seems to fit perfectly fine for such a thing, imo.


I wasn't suggesting for that to be included with SP, I just meant that a setback for memory hacking is also especially a setback for that idea too. I was probably unclear on that.
User avatar
L'In20Cible
Project Leader
Posts: 1533
Joined: Sat Jul 14, 2012 9:29 pm
Location: Québec

Re: Source Python for GMod?

Postby L'In20Cible » Sat Aug 27, 2016 11:31 am

I didn't have/take the time to look more into the gEntList issue. But there is definitely something going wrong. When the server is crashing, I get the following prompt:

err.PNG
err.PNG (6.68 KiB) Viewed 11623 times


For some reasons, server.dll (or more precisely, the dll that pointer get exported from) seems to be mapped into D:/ while the server is installed onto Z:/. I'm not quite sure of the cause but yesterday I readed that a lot of users had similar issues installing the game itself (client version) onto a different disk than steam. When I get the chance to, I will see if reinstalling the server onto C:/ or even renaming Z:/ to D:/ fixes the issues.
User avatar
Ayuto
Project Leader
Posts: 2195
Joined: Sat Jul 07, 2012 8:17 am
Location: Germany

Re: Source Python for GMod?

Postby Ayuto » Sat Aug 27, 2016 3:08 pm

The gEntList issue should be fixed with this commit:
https://github.com/Source-Python-Dev-Te ... ea3b9bfa38
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Re: Source Python for GMod?

Postby satoon101 » Sat Aug 27, 2016 3:49 pm

Awesome! That did the trick. I think that GMod is ready to be merged into master, correct?
Image
User avatar
Ayuto
Project Leader
Posts: 2195
Joined: Sat Jul 07, 2012 8:17 am
Location: Germany

Re: Source Python for GMod?

Postby Ayuto » Sat Aug 27, 2016 4:05 pm

I haven't tested Linux yet. We probably need to add srv_check=True to the data files.

Edit: I forgot that it's set to True by default. :grin:
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Re: Source Python for GMod?

Postby satoon101 » Sat Aug 27, 2016 4:09 pm

Ah yeah, forgot we need to test Linux. I will attempt to do that myself here in a few. I have the server installed, but I haven't tried building.
Image
User avatar
Doldol
Senior Member
Posts: 200
Joined: Sat Jul 07, 2012 7:09 pm
Location: Belgium

Re: Source Python for GMod?

Postby Doldol » Sat Sep 03, 2016 12:41 am

Any clue when builds will be available? It's a pain for me to build for Linux atm. But if they won't be available for a while I'll have to set that up.
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Re: Source Python for GMod?

Postby satoon101 » Sat Sep 03, 2016 1:37 am

Ayuto built the Linux binaries a few days ago. You can find them here:
http://builds.sourcepython.com/job/Sour ... el=master/

We should be very close to adding this to the master branch. I'm not 100% sure what we still need to do at this point.
Image
User avatar
Ayuto
Project Leader
Posts: 2195
Joined: Sat Jul 07, 2012 8:17 am
Location: Germany

Re: Source Python for GMod?

Postby Ayuto » Sat Sep 03, 2016 7:01 am

The only thing that is left is some data. Though, it's also working without it. Some functionality is just not available.

Edit:

Here is a list of things that is either missing or should be checked:
  • teams/gmod.ini (There are 3 static teams, but teams can be added dynamically)
  • weapons/gmod.ini
  • weapons/scripts/gmod/WeaponInfo.ini
  • weapons/constants/gmod/*
  • entities/gmod/*
  • (weapons/constants/l4d2/*)
  • (weapons/constants/bms/*)
  • (weapons/scripts/bms/*)
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Re: Source Python for GMod?

Postby satoon101 » Sat Sep 03, 2016 8:03 pm

I trie to add team data the other day, but there were no entities when I tried to iterate over the team manager entity (don't remember the name). So, I added bots (I don't own GMod, so I couldn't join the server), but still no entities showed. Obviously, not owning the game, I couldn't test out and add weapon data.
Image

Return to “General Discussion”

Who is online

Users browsing this forum: No registered users and 38 guests