• ManagedWrapper
    37 replies, posted
[B]What is it?[/B] • It's a C++\CLI Wrapper over Garry's unmanaged GMod Binary Module headers [B]What can it do?[/B] • It allows you to write binary modules in managed languages, like C# or Visual Basic.NET [B] How to install it?[/B] • Put it in same directory as hl2.exe (common/garrysmod) [B] How do i create managed binary modules? [/B]• Get Visual Studio 2012 and NuGet • Create a C# .dll solution named like your module • Install [URL="https://www.nuget.org/packages/UnmanagedExports"]Unmanaged Exports[/URL] from NuGet - this allows you to create static entry points for your module to be loadable by GMod • Add reference to ManagedWrapper.dll and disable copy to local output, you don't need it in output - it gets automatically loaded from hl2.exe dir • Write your code! • Compile, put into garrysmod/lua/bin and require() it ingame! [B]Any examples? [/B]• Yes, you can find a [URL="https://github.com/cartman300/GMOD-NET-API/blob/master/gmsv_cartmanium_win32/gmsv_cartmanium_win32/Cartmanium.cs"]module example[/URL] on GitHub [B] Please report any errors and bugs here! If you have any more questions, just ask me here or add me on steam! [/B][B]I will be happy to help! [/B] [B][URL="https://github.com/cartman300/GMOD-NET-API/"]Source (GitHub)[/URL] [URL="http://puu.sh/6iwuE.zip"]Download[/URL] [/B]
Would I be able to make something that uses SlimDX and directinput with this, and along the same lines, would I be able to use XInput with this?
[QUOTE=viperfan7;43520304]Would I be able to make something that uses SlimDX and directinput with this, and along the same lines, would I be able to use XInput with this?[/QUOTE] Well technically you should be able to do so. [editline]13th January 2014[/editline] Quick notice: Every library referenced by the managed module should be located in the same directory as hl2.exe. Now that reminds me, i should make it possible to load references from the same (or different) folder as the module. Expect next version soon!
[QUOTE=cartman300;43524795]Well technically you should be able to do so. [editline]13th January 2014[/editline] Quick notice: Every library referenced by the managed module should be located in the same directory as hl2.exe. Now that reminds me, i should make it possible to load references from the same (or different) folder as the module. Expect next version soon![/QUOTE] Sweet, now I can re-make the old joystick mod with proper FFB and XInput support
I love you
Now look you've gotten all the canadians in here
[QUOTE=viperfan7;43528093]Now look you've gotten all the canadians in here[/QUOTE] Canadians love managed wrappers.
[B]Changelog[/B] • Added GFunc delegate to the wrapper - you don't have to manually create functions now • Added GarrysMod::GLua::Utils class - currently contains only print function for easy printing • Added GarrysMod::GLua::PushGFunction • Added GarrysMod::GLua::CreateGlobalTable • Added GarrysMod::GLua::SetGlobalTableGFunc • Code cleanup [B]Note[/B] I did not add a helper function for auto resolving of references in different directories yet because C++ is a bitch about it, i'll see what i can do. You have to manually do it from C#, [URL="http://stackoverflow.com/questions/5260404/resolve-assembly-references-from-another-folder"]here's how to do it[/URL]. Any requests welcome. [B][URL="http://puu.sh/6kdTJ.zip"]Download R2[/URL][/B]
Loading library from different directories was a bitch to me too when I tried to do it in my gm_bass edit. It still is.
[QUOTE=NightmareX91;43528308]Canadians love managed wrappers.[/QUOTE] That we do
How about letting us write modules in LUA? :v:
[QUOTE=bitches;43544037]How about letting us write modules in LUA? :v:[/QUOTE] It's like letting ring3 applications work in ring0 :/ rofl
[QUOTE=bitches;43544037]How about letting us write modules in LUA? :v:[/QUOTE] That is already possible by default. :v: No, seriously, it is.
[QUOTE=cartman300;43528966][B]Changelog[/B] • Added GFunc delegate to the wrapper - you don't have to manually create functions now • Added GarrysMod::GLua::Utils class - currently contains only print function for easy printing • Added GarrysMod::GLua::PushGFunction • Added GarrysMod::GLua::CreateGlobalTable • Added GarrysMod::GLua::SetGlobalTableGFunc • Code cleanup [B]Note[/B] I did not add a helper function for auto resolving of references in different directories yet because C++ is a bitch about it, i'll see what i can do. You have to manually do it from C#, [URL="http://stackoverflow.com/questions/5260404/resolve-assembly-references-from-another-folder"]here's how to do it[/URL]. Any requests welcome. [B][URL="http://puu.sh/6kdTJ.zip"]Download R2[/URL][/B][/QUOTE] You could probably get away with changing the working directory adn changing it back
[QUOTE=Map in a box;43550444]You could probably get away with changing the working directory adn changing it back[/QUOTE] I am not really sure that does the trick, what i wanted to do is create a method that allows you to register a reference lookup path before using any referenced methods and classes, but seems C++ CLI does not support managed lambdas and that makes implementing it 200 times harder. This is possible to do in C# however, but i'm not really sure people want 2 differend .dlls.
You're using C++.net?
[QUOTE=Map in a box;43550880]You're using C++.net?[/QUOTE] That's pretty obvious. :v: [IMG]http://puu.sh/6miyS.png[/IMG] [editline]16th January 2014[/editline] [QUOTE=Map in a box;43550880]You're using C++.net?[/QUOTE] And btw, there is no such thing as C++.NET, there's C++/CLI, which is basically C++ with Microsoft extensions that allows you to write code targeting the .NET framework.
[QUOTE=cartman300;43550409]That is already possible by default. :v: No, seriously, it is.[/QUOTE] I know, but writing it into a DLL would be hilarious.
[QUOTE=cartman300;43550937]And btw, there is no such thing as C++.NET, there's C++/CLI, which is basically C++ with Microsoft extensions that allows you to write code targeting the .NET framework.[/QUOTE] That's what MS(used to atleast) call it. It's a mutilated and gross form of C++.
[QUOTE=cartman300;43528966][B]Changelog[/B] • Added GFunc delegate to the wrapper - you don't have to manually create functions now • Added GarrysMod::GLua::Utils class - currently contains only print function for easy printing • Added GarrysMod::GLua::PushGFunction • Added GarrysMod::GLua::CreateGlobalTable • Added GarrysMod::GLua::SetGlobalTableGFunc • Code cleanup [B]Note[/B] I did not add a helper function for auto resolving of references in different directories yet because C++ is a bitch about it, i'll see what i can do. You have to manually do it from C#, [URL="http://stackoverflow.com/questions/5260404/resolve-assembly-references-from-another-folder"]here's how to do it[/URL]. Any requests welcome. [B][URL="http://puu.sh/6kdTJ.zip"]Download R2[/URL][/B][/QUOTE] So I just have to get the DLL to seach for the pre-req DLLs in the same folder as hl2.exe? I'm new to coding DLLs and using external references
[QUOTE=viperfan7;43568069]So I just have to get the DLL to seach for the pre-req DLLs in the same folder as hl2.exe? I'm new to coding DLLs and using external references[/QUOTE] Right click solution -> Add Reference... -> Browse for ManagedWrapper.dll -> Make sure it's selected (checkbox) and press OK. Now open references and select ManagedWrapper [img]http://puu.sh/6nTCZ.png[/img] and make sure Copy Local is set to false in the properties window [img]http://puu.sh/6nTE2.png[/img] If it's set to true then that means it will copy ManagedWrapper.dll to output directory (it's useless there).
Okay good news i suppose, i managed to get extended lua gmod api working in my c++ project and i managed to get the standard lua headers to import lua_* and luaL_* functions from lua_shared.dll, so that means the following functions (and a LOT more of them) are gonna be in R3 once i write a script to generate wrappers for these. [code] virtual void PLACEHOLDER( ) = 0; virtual bool Init( ILuaCallback *, bool ) = 0; virtual void Shutdown( ) = 0; virtual void Cycle( ) = 0; virtual lua_State *GetLuaState( ) = 0; virtual ILuaObject *Global( ) = 0; virtual ILuaObject *GetObject( int index ) = 0; virtual void DELETE_ME_5437( int ) = 0; virtual void _DELETE_ME2466( int ) = 0; virtual void PushLuaObject( ILuaObject *obj ) = 0; virtual void PushLuaFunction( CFunc func ) = 0; virtual void LuaError( const char *err, int index ) = 0; virtual void TypeError( const char *name, int index ) = 0; virtual void CallInternal( int args, int rets ) = 0; virtual void CallInternalNoReturns( int args ) = 0; virtual bool CallInternalGetBool( int args ) = 0; virtual const char *CallInternalGetString( int args ) = 0; virtual bool CallInternalGet( int args, ILuaObject *obj ) = 0; virtual void _DELETE_ME( ILuaObject *, void * ) = 0; virtual void NewGlobalTable( const char *name ) = 0; virtual ILuaObject *NewTemporaryObject( ) = 0; virtual bool isUserData( int index ) = 0; virtual ILuaObject *GetMetaTableObject( const char *name, int type ) = 0; virtual ILuaObject *GetMetaTableObject( int index ) = 0; virtual ILuaObject *GetReturn( int index ) = 0; virtual bool IsServer( ) = 0; virtual bool IsClient( ) = 0; virtual bool IsDedicatedServer( ) = 0; virtual void DestroyObject( ILuaObject *obj ) = 0; virtual ILuaObject *CreateObject( ) = 0; virtual void SetMember( ILuaObject *table, ILuaObject *key, ILuaObject *value ) = 0; virtual void GetNewTable( ) = 0; virtual void SetMember( ILuaObject *table, float key ) = 0; virtual void SetMember( ILuaObject *table, float key, ILuaObject *value ) = 0; virtual void SetMember( ILuaObject *table, const char *key ) = 0; virtual void SetMember( ILuaObject *table, const char *key, ILuaObject *value ) = 0; virtual void SetIsServer( bool isServer ) = 0; virtual void PushLong( long num ) = 0; virtual int GetFlags( int index ) = 0; virtual bool FindOnObjectsMetaTable( int objIndex, int keyIndex ) = 0; virtual bool FindObjectOnTable( int tableIndex, int keyIndex ) = 0; virtual void SetMemberFast( ILuaObject *table, int keyIndex, int valueIndex ) = 0; virtual bool RunString( const char *filename, const char *path, const char *stringToRun, bool run, bool showErrors ) = 0; virtual bool IsEqual( ILuaObject *objA, ILuaObject *objB ) = 0; virtual void Error( const char *err ) = 0; virtual const char *GetStringOrError( int index ) = 0; virtual bool RunLuaModule( const char *name ) = 0; virtual bool FindAndRunScript( const char *filename, bool run, bool showErrors, const char * ) = 0; virtual void SetPathID( const char *pathID ) = 0; virtual const char *GetPathID( ) = 0; virtual void ErrorNoHalt( const char *fmt, ... ) = 0; virtual void Msg( const char *fmt, ... ) = 0; virtual void PushPath( const char *path ) = 0; virtual void PopPath( ) = 0; virtual const char *GetPath( ) = 0; virtual int GetColor( int index ) = 0; virtual void PushColor( int r, int g, int b, int a ) = 0; virtual int GetStack( int level, lua_Debug *dbg ) = 0; virtual int GetInfo( const char *what, lua_Debug *dbg ) = 0; virtual const char *GetLocal( lua_Debug *dbg, int n ) = 0; virtual const char *GetUpvalue( int funcIndex, int n ) = 0; virtual void RunStringEx( const char *filename, const char *path, const char *stringToRun, bool run, bool showErrors, bool ) = 0; virtual void DELETE_ME1( const char *, int ) = 0; virtual size_t GetDataString( int index, const char **str ) = 0; virtual void ErrorFromLua( const char *fmt, ... ) = 0; virtual void GetCurrentLocation( ) = 0; virtual void MsgColour( const Color &col, const char *fmt, ... ) = 0; virtual void PushState( lua_State *state ) = 0; virtual void PopState( ) = 0; virtual void GetCurrentFile( std::string &outStr ) = 0; virtual void CompileString( Bootil::Buffer &dumper, const std::string &stringToCompile ) = 0; virtual void ThreadLock( ) = 0; virtual void ThreadUnlock( ) = 0; virtual bool CallFunctionProtected( int, int, bool ) = 0; virtual void Require( const char *name ) = 0; virtual void GetActualTypeName( int type ) = 0; virtual void SetupInfiniteLoopProtection( ) = 0; // useless [/code] However i'm not really sure all lua_* and luaL_* functions work, but most of them should.
I don't think you should include the functions Garry deprecated.
[thumb]http://puu.sh/6r12h.png[/thumb] Did some reflection magic, next version will also allow you to define tables with methods like this. Just make a static class with lua functions like this [code] public unsafe static class Cart { public static int Console(lua_State *L) { int ArgCount = GLua.Top(L); for (int i = 0; i < ArgCount; i++) { var S = GLua.GetString(L, i + 1, (uint*)0); System.Console.Write(S); if (i + 1 < ArgCount) System.Console.Write(" "); } GLua.Pop(L, ArgCount); System.Console.WriteLine(); return 0; } public static int AllocConsole(lua_State* L) { GLua.PushBool(L, Kernel32.AllocConsole()); return 1; } } [/code] and it will automagically create a lua table named Cart with Console and AllocConsole functions
[B]Changelog[/B] • Added lua_* and luaL_* functions, they're in the GLua class and are named glua[L]_* • GLua::CreateClassLib [B]Note[/B] Some lua* functions have not been wrapped because they use varargs and i was lazy to do it properly, if somebody misses them i'll port them. [URL="http://puu.sh/6rbrV.zip"][B]Download R3[/B][/URL]
I love it. I can't decide what use can I make of this yet, but I'm sure I'll eventually come up with something. Also, that's some interesting folder you've got there! [QUOTE=cartman300;43598203][img]http://i.imgur.com/B4mCJFQ.png[/img][/QUOTE]
[QUOTE=Khub;43609589]I love it. I can't decide what use can I make of this yet, but I'm sure I'll eventually come up with something. Also, that's some interesting folder you've got there![/QUOTE] The folder's most likely empty, something he did just to get a quick laugh out of y'all.
[QUOTE=Shinycow;43615834]The folder's most likely empty, something he did just to get a quick laugh out of y'all.[/QUOTE] I didn't really expect anything else; I just felt the "first!!!1!" urge in me and had to share it with you all. Sorry for staying off topic, but I noticed your code view has colored brackets! Mind sharing the plugin/color scheme/whatever it is?
[QUOTE=Khub;43618552]I didn't really expect anything else; I just felt the "first!!!1!" urge in me and had to share it with you all. Sorry for staying off topic, but I noticed your code view has colored brackets! Mind sharing the plugin/color scheme/whatever it is?[/QUOTE] [URL="http://viasfora.com/"]Viasfora[/URL]
[QUOTE=cartman300;43528966][B]Changelog[/B] • Added GFunc delegate to the wrapper - you don't have to manually create functions now • Added GarrysMod::GLua::Utils class - currently contains only print function for easy printing • Added GarrysMod::GLua::PushGFunction • Added GarrysMod::GLua::CreateGlobalTable • Added GarrysMod::GLua::SetGlobalTableGFunc • Code cleanup [B]Note[/B] I did not add a helper function for auto resolving of references in different directories yet because C++ is a bitch about it, i'll see what i can do. You have to manually do it from C#, [URL="http://stackoverflow.com/questions/5260404/resolve-assembly-references-from-another-folder"]here's how to do it[/URL]. Any requests welcome. [B][URL="http://puu.sh/6kdTJ.zip"]Download R2[/URL][/B][/QUOTE] thanks for this update
Sorry, you need to Log In to post a reply to this thread.