Source Python for GMod?

All other Source.Python topics and issues.
User avatar
Doldol
Senior Member
Posts: 200
Joined: Sat Jul 07, 2012 7:09 pm
Location: Belgium

Source Python for GMod?

Postby Doldol » Sun Aug 21, 2016 9:11 pm

Have you guys ever considered adding support for Garry's Mod to Source Python?

I've tried to build a SP branch for GMod a while ago, ran into issues, got busy with other stuff and never really revisited the idea.

It's a fairly active game and a popular game to write addons for (obviously). I'm aware GMod includes LUA as a scripting language, but I don't find LUA particularly powerful for starters and I find the implementation to be rather poor in GMod. It just doesn't feel intuitive at all.

Afaik it should be adding just another engine version and data to SP, or are there any particular issues in getting a build for GMod that I'm unaware of?
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Re: Source Python for GMod?

Postby satoon101 » Sun Aug 21, 2016 11:33 pm

There is a decent amount you have to do to get it to work with a new engine. Specifically, you have to add the engine specific logic in several of the src/core/modules/ directories, any patches, and possibly some defined checks in the loader and sp_main. I have been attempting to add a few new engines to our support, but had not worked on GMod. However, after seeing your post, I did make a new branch locally and start on adding GMod support. Right now, I am only seeing one error when building, though that error appears about 60 times.

Code: Select all

2>e:\projects\source.python\src\core\modules\memory\memory_alloc.h(65): error C3861: 'MemAlloc_Alloc': identifier not found

It seems that GMod's memalloc.h does not include a MemAlloc_Alloc function, which is causing this error. I will commit what I have, so far, and anyone can feel free to continue the work on it.

*Edit:
https://github.com/Source-Python-Dev-Te ... ngine_gmod
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 » Mon Aug 22, 2016 11:06 am

It seems that you're not supposed to use it, so setting NO_MALLOC_OVERRIDE should do the trick.

I updated gmod.makec to

Code: Select all

# ------------------------------------------------------------------
# File: src/makefiles/branch/gmod.cmake
# Purpose: This is the CMake file for the gmod branch.
# ------------------------------------------------------------------

# ------------------------------------------------------------------
# Set the engine version.
# ------------------------------------------------------------------
Set(SOURCE_ENGINE "gmod")
add_definitions(-DENGINE_GMOD)

# ------------------------------------------------------------------
# Don't use MemAlloc_Alloc
# ------------------------------------------------------------------
add_definitions(-DNO_MALLOC_OVERRIDE)


Now I get an error from the sdk:

Code: Select all

1>..\..\..\hl2sdk\gmod\tier1\KeyValues.cpp(2352): error C3861: 'MemAlloc_PushAllocDbgInfo': identifier not found
1>..\..\..\hl2sdk\gmod\tier1\KeyValues.cpp(2354): error C3861: 'MemAlloc_PopAllocDbgInfo': identifier not found
User avatar
Ayuto
Project Leader
Posts: 2193
Joined: Sat Jul 07, 2012 8:17 am
Location: Germany

Re: Source Python for GMod?

Postby Ayuto » Mon Aug 22, 2016 11:48 am

I haven't taken a look at it, but instead of defining NO_MALLOC_OVERRIDE on Windows, i would rather add -DMemAlloc_Alloc=malloc. However, maybe it's just missing include. But again: i haven't taken a look at it yet, but I will do that when I get home today.
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 » Mon Aug 22, 2016 12:12 pm

Seems like memalloc.h on GMod branch has not been updated for the lastest version. Added a patch for it and it now compile fine for me (on windows).
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Re: Source Python for GMod?

Postby satoon101 » Mon Aug 22, 2016 6:04 pm

Yep, compiles for me, as well, thank you! I will attempt to build it on Linux tonight and download the servers to get the binaries.
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 » Tue Aug 23, 2016 8:54 pm

Any luck? On Windows it ran into this and unloaded.

Code: Select all

[Source.Python] Could not retrieve interface FileSystem019


Thanks for the support so far!
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 » Tue Aug 23, 2016 9:09 pm

User avatar
Doldol
Senior Member
Posts: 200
Joined: Sat Jul 07, 2012 7:09 pm
Location: Belgium

Re: Source Python for GMod?

Postby Doldol » Wed Aug 24, 2016 12:22 am

L'In20Cible wrote:https://github.com/Source-Python-Dev-Team/Source.Python/commit/0c3294c847fc550505f21bffa2a4ca070febd045#commitcomment-18732172


Cool, I understand if it ends up being to much work to implement, or lower on the list of priorities.
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 3:55 am

Psychonic pushed updates for the Gmod branch! When you get the time to, could you try again and see if it loads? It will still raise on load due to missing data/global pointers that we still have to add but if the SDK is fully updated, you should at least see this message.
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 4:06 am

I just tested the new version, and I am getting this error 37 times:

Code: Select all

E:\Projects\Source.Python\src\hl2sdk\gmod\game/server/baseentity.h(1570): error C2259: 'CBaseEntity
::NetworkVar_m_Collision' : cannot instantiate abstract class [E:\Projects\Source.Python\src\Builds
\WINDOWS\gmod\core.vcxproj]
          due to following members:
          'const Vector &ICollideable::OBBMinsPreScaled(void) const' : is abstract
          e:\projects\source.python\src\hl2sdk\gmod\public\engine/ICollideable.h(35) : see declarat
  ion of 'ICollideable::OBBMinsPreScaled'
          'const Vector &ICollideable::OBBMaxsPreScaled(void) const' : is abstract
          e:\projects\source.python\src\hl2sdk\gmod\public\engine/ICollideable.h(36) : see declarat
  ion of 'ICollideable::OBBMaxsPreScaled'


Also, I think we can now remove the memalloc.h patch, as that file was updated.
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 4:10 am

I removed the memalloc patch. As for this error, I will see if I can find the cause. Seeing NetworkVar I'm assuming we need to update networkvar.h with our patch for the current version. Doing some testings right now and will push the required fixes.
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 4:20 am

I didn't realize you were going to be so fast :smile: I had a fix for EmitSound that I hadn't committed locally. But, since you are making fixes, I'll let you handle that, too.
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 4:27 am

Fixed the compile error, the file collisionproperty.h need to be updated. I will add it as a fix in our repo for now, and PR it on their once it is fully tested on both platform. The EmitSound is the one I need to fix, now. :P
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 4:37 am

Pushed. I'm now getting:

Code: Select all

1>mathlib.lib(mathlib_base.obj) : error LNK2019: unresolved external symbol ___vdecl_sin2 referenced in function "void __cdecl InitSinCosTable(void)" (?InitSinCosTable@@YAXXZ)
1>mathlib.lib(color_conversion.obj) : error LNK2019: unresolved external symbol ___vdecl_pow2 referenced in function "void __cdecl BuildGammaTable(float,float,float,int)" (?BuildGammaTable@@YAXMMMH@Z)
1>mathlib.lib(color_conversion.obj) : error LNK2019: unresolved external symbol ___vdecl_powf4 referenced in function "void __cdecl BuildGammaTable(float,float,float,int)" (?BuildGammaTable@@YAXMMMH@Z)


But I think I screwed it on my side pulling while compiling. Unless you get the same?
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 4:39 am

I get the same. Heading to bed, so I won't be able to do any more till tomorrow evening.
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 4:47 am

Seems like mathlib.lib will have to be recompiled with updated color_conversion.cpp file. I will start an issue on their repo for this.

EDIT: Patched mathlib.lib on our repo for now. It now compile fine for me, the compiled binaries are loading perfectly on my test server (still unloading itself due to missing data but the builds are fine).
User avatar
Doldol
Senior Member
Posts: 200
Joined: Sat Jul 07, 2012 7:09 pm
Location: Belgium

Re: Source Python for GMod?

Postby Doldol » Thu Aug 25, 2016 1:18 pm

Wouldn't it be better if Source Python was more vocal when loading with missing data? All it outputs is "Loading main module" and then "failed to load main module", then begins to unload everything.
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 4:01 pm

I would agree. I think the best idea, though, is to not require the data. If the data is missing, that functionality should just not work, but the plugin should still load. I'm not sure how feasible that will be at this time. I know the OnEntityOutput listener could easily be implemented this way. Other objects that utilize data to get objects in memory might be far more engrained into Source.Python itself to not allow for this.
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 8:46 pm

On my side I replaced the load function into __init__.py with:

Syntax: Select all

def load():
"""Load Source.Python's Python side."""
def try_to_setup(func):
try:
func()
except:
import sys
exc_type, exc_value, exc_traceback = sys.exc_info()
print('Unable to {} due to an {}:'.format(func.__name__.replace('_', ' '), exc_type.__name__))
print('\t', exc_value)

try_to_setup(setup_core_settings)
try_to_setup(setup_logging)
try_to_setup(setup_hooks)
try_to_setup(setup_translations)
try_to_setup(setup_global_pointers)
try_to_setup(setup_sp_command)
try_to_setup(setup_auth)
try_to_setup(setup_user_settings)
try_to_setup(setup_entities_listener)
try_to_setup(setup_versioning)
try_to_setup(setup_sqlite)


Code: Select all

Unable to setup core settings due to an AttributeError:
         type object 'BaseEntityOutput' has no attribute 'fire_output'
Unable to setup global pointers due to an NameError:
         No global pointer found for "Server".
Unable to setup sp command due to an AttributeError:
         type object 'BaseEntityOutput' has no attribute 'fire_output'
Unable to setup user settings due to an AttributeError:
         type object 'BaseEntityOutput' has no attribute 'fire_output'
Unable to setup entities listener due to an NameError:
         No global pointer found for "GlobalEntityList".

Return to “General Discussion”

Who is online

Users browsing this forum: No registered users and 27 guests