Skip to content

Commit 8e159bf

Browse files
committed
Initial commit
0 parents  commit 8e159bf

File tree

11 files changed

+378
-0
lines changed

11 files changed

+378
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/projects/

.gitmodules

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[submodule "LRDB"]
2+
path = LRDB
3+
url = https://github.com/danielga/LRDB.git
4+
[submodule "asio"]
5+
path = asio
6+
url = https://github.com/chriskohlhoff/asio.git
7+
[submodule "picojson"]
8+
path = picojson
9+
url = https://github.com/kazuho/picojson.git

LRDB

Submodule LRDB added at 7f4e0a2

README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# gm_lrdb
2+
3+
[![Build Status](https://metamann.visualstudio.com/GitHub%20danielga/_apis/build/status/danielga.gm_lrdb?branchName=master)](https://metamann.visualstudio.com/GitHub%20danielga/_build/latest?definitionId=16&branchName=master)
4+
5+
A Garry's Mod module that creates a Lua Remote DeBugger server.
6+
7+
## Compiling
8+
9+
The only supported compilation platform for this project on Windows is **Visual Studio 2017**. However, it's possible it'll work with *Visual Studio 2015* and *Visual Studio 2019* because of the unified runtime.
10+
11+
On Linux, everything should work fine as is.
12+
13+
For macOS, any **Xcode (using the GCC compiler)** version *MIGHT* work as long as the **Mac OSX 10.7 SDK** is used.
14+
15+
These restrictions are not random; they exist because of ABI compatibility reasons.
16+
17+
If stuff starts erroring or fails to work, be sure to check the correct line endings (`\n` and such) are present in the files for each OS.
18+
19+
## Requirements
20+
21+
This project requires [garrysmod\_common][1], a framework to facilitate the creation of compilations files (Visual Studio, make, XCode, etc). Simply set the environment variable `GARRYSMOD_COMMON` or the premake option `--gmcommon=path` to the path of your local copy of [garrysmod\_common][1].
22+
23+
[1]: https://github.com/danielga/garrysmod_common

asio

Submodule asio added at b84e6c1

azure-pipelines.yml

Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
variables:
2+
MODULE_NAME: lrdb
3+
DEPENDENCIES: $(System.DefaultWorkingDirectory)/dependencies
4+
GARRYSMOD_COMMON: $(System.DefaultWorkingDirectory)/dependencies/garrysmod_common
5+
GARRYSMOD_COMMON_BRANCH: master
6+
GARRYSMOD_COMMON_REPOSITORY: https://github.com/danielga/garrysmod_common.git
7+
PROJECT_GENERATOR_VERSION: 2
8+
REPOSITORY_DIR: $(System.DefaultWorkingDirectory)
9+
trigger:
10+
tags:
11+
include:
12+
- '*'
13+
jobs:
14+
- job: windows
15+
displayName: Windows
16+
pool:
17+
name: Azure Pipelines
18+
vmImage: windows-2019
19+
timeoutInMinutes: 10
20+
variables:
21+
BOOTSTRAP_URL: https://raw.githubusercontent.com/danielga/garrysmod_common/master/build/bootstrap.ps1
22+
BUILD_SCRIPT: $(System.DefaultWorkingDirectory)/dependencies/garrysmod_common/build/build.ps1
23+
COMPILER_PLATFORM: vs2019
24+
PROJECT_OS: windows
25+
PREMAKE5: $(System.DefaultWorkingDirectory)/dependencies/windows/premake-core/premake5.exe
26+
PREMAKE5_URL: https://github.com/premake/premake-core/releases/download/v5.0.0-alpha15/premake-5.0.0-alpha15-windows.zip
27+
steps:
28+
- checkout: self
29+
clean: true
30+
fetchDepth: 1
31+
submodules: recursive
32+
- powershell: 'Invoke-Expression ((New-Object System.Net.WebClient).DownloadString("$env:BOOTSTRAP_URL"))'
33+
displayName: Bootstrap
34+
- powershell: '& "$env:BUILD_SCRIPT"'
35+
displayName: Build
36+
- task: CopyFiles@2
37+
displayName: 'Copy files to $(Build.ArtifactStagingDirectory)'
38+
inputs:
39+
SourceFolder: '$(System.DefaultWorkingDirectory)/projects/windows/vs2019'
40+
Contents: '*/Release/*.dll'
41+
TargetFolder: '$(Build.ArtifactStagingDirectory)'
42+
CleanTargetFolder: true
43+
flattenFolders: true
44+
preserveTimestamp: true
45+
- task: PublishBuildArtifacts@1
46+
displayName: 'Publish build artifacts'
47+
inputs:
48+
ArtifactName: windows
49+
- job: linux
50+
displayName: Linux
51+
pool:
52+
name: Azure Pipelines
53+
vmImage: ubuntu-16.04
54+
timeoutInMinutes: 10
55+
variables:
56+
BOOTSTRAP_URL: https://raw.githubusercontent.com/danielga/garrysmod_common/master/build/bootstrap.sh
57+
BUILD_SCRIPT: $(System.DefaultWorkingDirectory)/dependencies/garrysmod_common/build/build.sh
58+
COMPILER_PLATFORM: gmake
59+
PREMAKE5: $(System.DefaultWorkingDirectory)/dependencies/linux/premake-core/premake5
60+
PROJECT_OS: linux
61+
PREMAKE5_URL: https://github.com/premake/premake-core/releases/download/v5.0.0-alpha15/premake-5.0.0-alpha15-linux.tar.gz
62+
CC: gcc-9
63+
CXX: g++-9
64+
AR: gcc-ar-9
65+
NM: gcc-nm-9
66+
RANLIB: gcc-ranlib-9
67+
steps:
68+
- checkout: self
69+
clean: true
70+
fetchDepth: 1
71+
submodules: recursive
72+
- bash: 'curl -s -L "$BOOTSTRAP_URL" | bash'
73+
displayName: Bootstrap
74+
- bash: |
75+
sudo apt-get update && sudo apt-get install -y g++-9-multilib
76+
$BUILD_SCRIPT
77+
displayName: Build
78+
- task: CopyFiles@2
79+
displayName: 'Copy files to $(Build.ArtifactStagingDirectory)'
80+
inputs:
81+
SourceFolder: '$(System.DefaultWorkingDirectory)/projects/linux/gmake'
82+
Contents: '*/Release/*.dll'
83+
TargetFolder: '$(Build.ArtifactStagingDirectory)'
84+
CleanTargetFolder: true
85+
flattenFolders: true
86+
preserveTimestamp: true
87+
- task: PublishBuildArtifacts@1
88+
displayName: 'Publish build artifacts'
89+
inputs:
90+
ArtifactName: linux
91+
- job: macosx
92+
displayName: macOS
93+
pool:
94+
name: Azure Pipelines
95+
vmImage: macOS-10.15
96+
timeoutInMinutes: 10
97+
variables:
98+
BOOTSTRAP_URL: https://raw.githubusercontent.com/danielga/garrysmod_common/master/build/bootstrap.sh
99+
BUILD_SCRIPT: $(System.DefaultWorkingDirectory)/dependencies/garrysmod_common/build/build.sh
100+
COMPILER_PLATFORM: gmake
101+
PREMAKE5: $(System.DefaultWorkingDirectory)/dependencies/macosx/premake-core/premake5
102+
PROJECT_OS: macosx
103+
PREMAKE5_URL: https://github.com/premake/premake-core/releases/download/v5.0.0-alpha15/premake-5.0.0-alpha15-macosx.tar.gz
104+
MACOSX_SDK_URL: https://github.com/phracker/MacOSX-SDKs/releases/download/10.15/MacOSX10.7.sdk.tar.xz
105+
MACOSX_SDK_DIRECTORY: $(System.DefaultWorkingDirectory)/dependencies/macosx/MacOSX10.7.sdk
106+
SDKROOT: $(System.DefaultWorkingDirectory)/dependencies/macosx/MacOSX10.7.sdk
107+
steps:
108+
- checkout: self
109+
clean: true
110+
fetchDepth: 1
111+
submodules: recursive
112+
- bash: 'curl -s -L "$BOOTSTRAP_URL" | bash'
113+
displayName: Bootstrap
114+
- bash: |
115+
sudo xcode-select -s "/Applications/Xcode_11.4.1.app/Contents/Developer"
116+
$BUILD_SCRIPT
117+
displayName: Build
118+
- task: CopyFiles@2
119+
displayName: 'Copy files to $(Build.ArtifactStagingDirectory)'
120+
inputs:
121+
SourceFolder: '$(System.DefaultWorkingDirectory)/projects/macosx/gmake'
122+
Contents: '*/Release/*.dll'
123+
TargetFolder: '$(Build.ArtifactStagingDirectory)'
124+
CleanTargetFolder: true
125+
flattenFolders: true
126+
preserveTimestamp: true
127+
- task: PublishBuildArtifacts@1
128+
displayName: 'Publish build artifacts'
129+
inputs:
130+
ArtifactName: macosx
131+
- job: publish
132+
displayName: Publish to GitHub Releases
133+
pool:
134+
name: Azure Pipelines
135+
vmImage: ubuntu-18.04
136+
timeoutInMinutes: 5
137+
dependsOn:
138+
- windows
139+
- linux
140+
- macosx
141+
steps:
142+
- task: DownloadBuildArtifacts@0
143+
displayName: 'Download build artifacts'
144+
inputs:
145+
downloadType: specific
146+
parallelizationLimit: 12
147+
- task: GitHubRelease@1
148+
displayName: 'Publish GitHub release $(build.sourceBranchName)'
149+
inputs:
150+
gitHubConnection: 'GitHub danielga'
151+
releaseNotesSource: inline
152+
assets: '$(System.ArtifactsDirectory)/**'
153+
addChangeLog: false

launch.example.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"configurations": [
3+
{
4+
"type": "lrdb",
5+
"request": "attach",
6+
"name": "Attach to Garry's Mod",
7+
"stopOnEntry": true,
8+
// If debugging directly on a Garry's Mod server or client instance, "sourceRoot" pointing to Garry's Mod "garrysmod" directory should be enough
9+
"sourceRoot": "${workspaceFolder}",
10+
// Host to connect to, can be localhost (127.0.0.1) or any remote host
11+
"host": "localhost",
12+
// Port to connect to, in case you change it with lrdb.activate(port_number)
13+
"port": 21110,
14+
"sourceFileMap": {
15+
// This is an example for a remote setup
16+
// Local directory -> remote directory (as is announced by debug.getinfo)
17+
"${workspaceFolder}": "addons/addon_name_here",
18+
"{FULL PATH TO GARRY'S MOD CONTENT DIRECTORY}": "."
19+
}
20+
}
21+
]
22+
}

license.txt

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
gm_lrdb
2+
A Garry's Mod module that creates a Lua Remote DeBugger server.
3+
-----------------------------------------------------------------------
4+
Copyright (c) 2021, Daniel Almeida
5+
All rights reserved.
6+
7+
Redistribution and use in source and binary forms, with or without
8+
modification, are permitted provided that the following conditions
9+
are met:
10+
11+
1. Redistributions of source code must retain the above copyright
12+
notice, this list of conditions and the following disclaimer.
13+
14+
2. Redistributions in binary form must reproduce the above copyright
15+
notice, this list of conditions and the following disclaimer in the
16+
documentation and/or other materials provided with the distribution.
17+
18+
3. Neither the name of the copyright holder nor the names of its
19+
contributors may be used to endorse or promote products derived from
20+
this software without specific prior written permission.
21+
22+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26+
HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

picojson

Submodule picojson added at 111c9be

premake5.lua

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
PROJECT_GENERATOR_VERSION = 2
2+
3+
newoption({
4+
trigger = "gmcommon",
5+
description = "Sets the path to the garrysmod_common (https://github.com/danielga/garrysmod_common) directory",
6+
value = "path to garrysmod_common directory"
7+
})
8+
9+
include(assert(_OPTIONS.gmcommon or os.getenv("GARRYSMOD_COMMON"),
10+
"you didn't provide a path to your garrysmod_common (https://github.com/danielga/garrysmod_common) directory"))
11+
12+
CreateWorkspace({name = "lrdb"})
13+
filter("system:windows")
14+
defines("_WIN32_WINNT=0x0601")
15+
16+
CreateProject({serverside = true})
17+
sysincludedirs({
18+
"LRDB/include",
19+
"asio/asio/include",
20+
"picojson"
21+
})
22+
IncludeLuaShared()
23+
24+
CreateProject({serverside = false})
25+
sysincludedirs({
26+
"LRDB/include",
27+
"asio/asio/include",
28+
"picojson"
29+
})
30+
IncludeLuaShared()

source/main.cpp

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
#include <GarrysMod/Lua/Interface.h>
2+
3+
#include <lrdb/server.hpp>
4+
5+
namespace global
6+
{
7+
static int32_t metatype = GarrysMod::Lua::Type::None;
8+
static const int16_t default_port = 21110;
9+
10+
LUA_FUNCTION_STATIC( lrdb_activate )
11+
{
12+
lrdb::server **server = LUA->GetUserType<lrdb::server *>( lua_upvalueindex( 1 ), metatype );
13+
if( *server != nullptr )
14+
{
15+
delete *server;
16+
*server = nullptr;
17+
}
18+
19+
if( LUA->IsType( 1, GarrysMod::Lua::Type::Number ) )
20+
*server = new lrdb::server( static_cast<int16_t>( LUA->GetNumber( 1 ) ) );
21+
else
22+
*server = new lrdb::server( default_port );
23+
24+
( *server )->reset( LUA->GetState( ) );
25+
return 0;
26+
}
27+
28+
LUA_FUNCTION_STATIC( lrdb_deactivate )
29+
{
30+
lrdb::server **server = LUA->GetUserType<lrdb::server *>( lua_upvalueindex( 1 ), metatype );
31+
if( *server != nullptr )
32+
{
33+
delete *server;
34+
*server = nullptr;
35+
}
36+
37+
return 0;
38+
}
39+
40+
LUA_FUNCTION_STATIC( lrdb_destruct )
41+
{
42+
lrdb::server **server = LUA->GetUserType<lrdb::server *>( 1, metatype );
43+
if( *server != nullptr )
44+
{
45+
delete *server;
46+
*server = nullptr;
47+
}
48+
49+
return 0;
50+
}
51+
52+
static int32_t Initialize( GarrysMod::Lua::ILuaBase *LUA )
53+
{
54+
metatype = LUA->CreateMetaTable( "lrdb" );
55+
56+
LUA->PushCFunction( lrdb_destruct );
57+
LUA->SetField( -2, "__gc" );
58+
59+
lrdb::server **server = LUA->NewUserType<lrdb::server *>( metatype );
60+
*server = nullptr;
61+
62+
LUA->Push( -2 ); // push metatable to the stack top
63+
LUA->SetMetaTable( -2 ); // pop reference on stack top and set it as metatable of userdata
64+
LUA->Remove( -2 ); // remove older metatable reference on stack
65+
66+
LUA->CreateTable( );
67+
68+
LUA->PushString( "lrdb 1.0.0" );
69+
LUA->SetField( -2, "Version" );
70+
71+
// version num follows LuaJIT style, xxyyzz
72+
LUA->PushNumber( 10000 );
73+
LUA->SetField( -2, "VersionNum" );
74+
75+
LUA->Push( -2 ); // push userdata to stack stop
76+
LUA->PushCClosure( lrdb_activate, 1 );
77+
LUA->SetField( -2, "activate" );
78+
79+
LUA->Push( -2 ); // push userdata to stack stop
80+
LUA->PushCClosure( lrdb_deactivate, 1 );
81+
LUA->SetField( -2, "deactivate" );
82+
83+
LUA->Push( -1 );
84+
LUA->SetField( GarrysMod::Lua::INDEX_GLOBAL, "lrdb" );
85+
86+
return 1;
87+
}
88+
89+
static int32_t Deinitialize( GarrysMod::Lua::ILuaBase *LUA )
90+
{
91+
LUA->PushNil( );
92+
LUA->SetField( GarrysMod::Lua::INDEX_GLOBAL, "lrdb" );
93+
return 0;
94+
}
95+
}
96+
97+
GMOD_MODULE_OPEN( )
98+
{
99+
return global::Initialize( LUA );
100+
}
101+
102+
GMOD_MODULE_CLOSE( )
103+
{
104+
return global::Deinitialize( LUA );
105+
}

0 commit comments

Comments
 (0)