Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
danielga committed Mar 21, 2021
0 parents commit 8e159bf
Show file tree
Hide file tree
Showing 11 changed files with 378 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/projects/
9 changes: 9 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[submodule "LRDB"]
path = LRDB
url = https://github.com/danielga/LRDB.git
[submodule "asio"]
path = asio
url = https://github.com/chriskohlhoff/asio.git
[submodule "picojson"]
path = picojson
url = https://github.com/kazuho/picojson.git
1 change: 1 addition & 0 deletions LRDB
Submodule LRDB added at 7f4e0a
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# gm_lrdb

[![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)

A Garry's Mod module that creates a Lua Remote DeBugger server.

## Compiling

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.

On Linux, everything should work fine as is.

For macOS, any **Xcode (using the GCC compiler)** version *MIGHT* work as long as the **Mac OSX 10.7 SDK** is used.

These restrictions are not random; they exist because of ABI compatibility reasons.

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.

## Requirements

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].

[1]: https://github.com/danielga/garrysmod_common
1 change: 1 addition & 0 deletions asio
Submodule asio added at b84e6c
153 changes: 153 additions & 0 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
variables:
MODULE_NAME: lrdb
DEPENDENCIES: $(System.DefaultWorkingDirectory)/dependencies
GARRYSMOD_COMMON: $(System.DefaultWorkingDirectory)/dependencies/garrysmod_common
GARRYSMOD_COMMON_BRANCH: master
GARRYSMOD_COMMON_REPOSITORY: https://github.com/danielga/garrysmod_common.git
PROJECT_GENERATOR_VERSION: 2
REPOSITORY_DIR: $(System.DefaultWorkingDirectory)
trigger:
tags:
include:
- '*'
jobs:
- job: windows
displayName: Windows
pool:
name: Azure Pipelines
vmImage: windows-2019
timeoutInMinutes: 10
variables:
BOOTSTRAP_URL: https://raw.githubusercontent.com/danielga/garrysmod_common/master/build/bootstrap.ps1
BUILD_SCRIPT: $(System.DefaultWorkingDirectory)/dependencies/garrysmod_common/build/build.ps1
COMPILER_PLATFORM: vs2019
PROJECT_OS: windows
PREMAKE5: $(System.DefaultWorkingDirectory)/dependencies/windows/premake-core/premake5.exe
PREMAKE5_URL: https://github.com/premake/premake-core/releases/download/v5.0.0-alpha15/premake-5.0.0-alpha15-windows.zip
steps:
- checkout: self
clean: true
fetchDepth: 1
submodules: recursive
- powershell: 'Invoke-Expression ((New-Object System.Net.WebClient).DownloadString("$env:BOOTSTRAP_URL"))'
displayName: Bootstrap
- powershell: '& "$env:BUILD_SCRIPT"'
displayName: Build
- task: CopyFiles@2
displayName: 'Copy files to $(Build.ArtifactStagingDirectory)'
inputs:
SourceFolder: '$(System.DefaultWorkingDirectory)/projects/windows/vs2019'
Contents: '*/Release/*.dll'
TargetFolder: '$(Build.ArtifactStagingDirectory)'
CleanTargetFolder: true
flattenFolders: true
preserveTimestamp: true
- task: PublishBuildArtifacts@1
displayName: 'Publish build artifacts'
inputs:
ArtifactName: windows
- job: linux
displayName: Linux
pool:
name: Azure Pipelines
vmImage: ubuntu-16.04
timeoutInMinutes: 10
variables:
BOOTSTRAP_URL: https://raw.githubusercontent.com/danielga/garrysmod_common/master/build/bootstrap.sh
BUILD_SCRIPT: $(System.DefaultWorkingDirectory)/dependencies/garrysmod_common/build/build.sh
COMPILER_PLATFORM: gmake
PREMAKE5: $(System.DefaultWorkingDirectory)/dependencies/linux/premake-core/premake5
PROJECT_OS: linux
PREMAKE5_URL: https://github.com/premake/premake-core/releases/download/v5.0.0-alpha15/premake-5.0.0-alpha15-linux.tar.gz
CC: gcc-9
CXX: g++-9
AR: gcc-ar-9
NM: gcc-nm-9
RANLIB: gcc-ranlib-9
steps:
- checkout: self
clean: true
fetchDepth: 1
submodules: recursive
- bash: 'curl -s -L "$BOOTSTRAP_URL" | bash'
displayName: Bootstrap
- bash: |
sudo apt-get update && sudo apt-get install -y g++-9-multilib
$BUILD_SCRIPT
displayName: Build
- task: CopyFiles@2
displayName: 'Copy files to $(Build.ArtifactStagingDirectory)'
inputs:
SourceFolder: '$(System.DefaultWorkingDirectory)/projects/linux/gmake'
Contents: '*/Release/*.dll'
TargetFolder: '$(Build.ArtifactStagingDirectory)'
CleanTargetFolder: true
flattenFolders: true
preserveTimestamp: true
- task: PublishBuildArtifacts@1
displayName: 'Publish build artifacts'
inputs:
ArtifactName: linux
- job: macosx
displayName: macOS
pool:
name: Azure Pipelines
vmImage: macOS-10.15
timeoutInMinutes: 10
variables:
BOOTSTRAP_URL: https://raw.githubusercontent.com/danielga/garrysmod_common/master/build/bootstrap.sh
BUILD_SCRIPT: $(System.DefaultWorkingDirectory)/dependencies/garrysmod_common/build/build.sh
COMPILER_PLATFORM: gmake
PREMAKE5: $(System.DefaultWorkingDirectory)/dependencies/macosx/premake-core/premake5
PROJECT_OS: macosx
PREMAKE5_URL: https://github.com/premake/premake-core/releases/download/v5.0.0-alpha15/premake-5.0.0-alpha15-macosx.tar.gz
MACOSX_SDK_URL: https://github.com/phracker/MacOSX-SDKs/releases/download/10.15/MacOSX10.7.sdk.tar.xz
MACOSX_SDK_DIRECTORY: $(System.DefaultWorkingDirectory)/dependencies/macosx/MacOSX10.7.sdk
SDKROOT: $(System.DefaultWorkingDirectory)/dependencies/macosx/MacOSX10.7.sdk
steps:
- checkout: self
clean: true
fetchDepth: 1
submodules: recursive
- bash: 'curl -s -L "$BOOTSTRAP_URL" | bash'
displayName: Bootstrap
- bash: |
sudo xcode-select -s "/Applications/Xcode_11.4.1.app/Contents/Developer"
$BUILD_SCRIPT
displayName: Build
- task: CopyFiles@2
displayName: 'Copy files to $(Build.ArtifactStagingDirectory)'
inputs:
SourceFolder: '$(System.DefaultWorkingDirectory)/projects/macosx/gmake'
Contents: '*/Release/*.dll'
TargetFolder: '$(Build.ArtifactStagingDirectory)'
CleanTargetFolder: true
flattenFolders: true
preserveTimestamp: true
- task: PublishBuildArtifacts@1
displayName: 'Publish build artifacts'
inputs:
ArtifactName: macosx
- job: publish
displayName: Publish to GitHub Releases
pool:
name: Azure Pipelines
vmImage: ubuntu-18.04
timeoutInMinutes: 5
dependsOn:
- windows
- linux
- macosx
steps:
- task: DownloadBuildArtifacts@0
displayName: 'Download build artifacts'
inputs:
downloadType: specific
parallelizationLimit: 12
- task: GitHubRelease@1
displayName: 'Publish GitHub release $(build.sourceBranchName)'
inputs:
gitHubConnection: 'GitHub danielga'
releaseNotesSource: inline
assets: '$(System.ArtifactsDirectory)/**'
addChangeLog: false
22 changes: 22 additions & 0 deletions launch.example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"configurations": [
{
"type": "lrdb",
"request": "attach",
"name": "Attach to Garry's Mod",
"stopOnEntry": true,
// If debugging directly on a Garry's Mod server or client instance, "sourceRoot" pointing to Garry's Mod "garrysmod" directory should be enough
"sourceRoot": "${workspaceFolder}",
// Host to connect to, can be localhost (127.0.0.1) or any remote host
"host": "localhost",
// Port to connect to, in case you change it with lrdb.activate(port_number)
"port": 21110,
"sourceFileMap": {
// This is an example for a remote setup
// Local directory -> remote directory (as is announced by debug.getinfo)
"${workspaceFolder}": "addons/addon_name_here",
"{FULL PATH TO GARRY'S MOD CONTENT DIRECTORY}": "."
}
}
]
}
32 changes: 32 additions & 0 deletions license.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
gm_lrdb
A Garry's Mod module that creates a Lua Remote DeBugger server.
-----------------------------------------------------------------------
Copyright (c) 2021, Daniel Almeida
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:

1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.

3. Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1 change: 1 addition & 0 deletions picojson
Submodule picojson added at 111c9b
30 changes: 30 additions & 0 deletions premake5.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
PROJECT_GENERATOR_VERSION = 2

newoption({
trigger = "gmcommon",
description = "Sets the path to the garrysmod_common (https://github.com/danielga/garrysmod_common) directory",
value = "path to garrysmod_common directory"
})

include(assert(_OPTIONS.gmcommon or os.getenv("GARRYSMOD_COMMON"),
"you didn't provide a path to your garrysmod_common (https://github.com/danielga/garrysmod_common) directory"))

CreateWorkspace({name = "lrdb"})
filter("system:windows")
defines("_WIN32_WINNT=0x0601")

CreateProject({serverside = true})
sysincludedirs({
"LRDB/include",
"asio/asio/include",
"picojson"
})
IncludeLuaShared()

CreateProject({serverside = false})
sysincludedirs({
"LRDB/include",
"asio/asio/include",
"picojson"
})
IncludeLuaShared()
105 changes: 105 additions & 0 deletions source/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
#include <GarrysMod/Lua/Interface.h>

#include <lrdb/server.hpp>

namespace global
{
static int32_t metatype = GarrysMod::Lua::Type::None;
static const int16_t default_port = 21110;

LUA_FUNCTION_STATIC( lrdb_activate )
{
lrdb::server **server = LUA->GetUserType<lrdb::server *>( lua_upvalueindex( 1 ), metatype );
if( *server != nullptr )
{
delete *server;
*server = nullptr;
}

if( LUA->IsType( 1, GarrysMod::Lua::Type::Number ) )
*server = new lrdb::server( static_cast<int16_t>( LUA->GetNumber( 1 ) ) );
else
*server = new lrdb::server( default_port );

( *server )->reset( LUA->GetState( ) );
return 0;
}

LUA_FUNCTION_STATIC( lrdb_deactivate )
{
lrdb::server **server = LUA->GetUserType<lrdb::server *>( lua_upvalueindex( 1 ), metatype );
if( *server != nullptr )
{
delete *server;
*server = nullptr;
}

return 0;
}

LUA_FUNCTION_STATIC( lrdb_destruct )
{
lrdb::server **server = LUA->GetUserType<lrdb::server *>( 1, metatype );
if( *server != nullptr )
{
delete *server;
*server = nullptr;
}

return 0;
}

static int32_t Initialize( GarrysMod::Lua::ILuaBase *LUA )
{
metatype = LUA->CreateMetaTable( "lrdb" );

LUA->PushCFunction( lrdb_destruct );
LUA->SetField( -2, "__gc" );

lrdb::server **server = LUA->NewUserType<lrdb::server *>( metatype );
*server = nullptr;

LUA->Push( -2 ); // push metatable to the stack top
LUA->SetMetaTable( -2 ); // pop reference on stack top and set it as metatable of userdata
LUA->Remove( -2 ); // remove older metatable reference on stack

LUA->CreateTable( );

LUA->PushString( "lrdb 1.0.0" );
LUA->SetField( -2, "Version" );

// version num follows LuaJIT style, xxyyzz
LUA->PushNumber( 10000 );
LUA->SetField( -2, "VersionNum" );

LUA->Push( -2 ); // push userdata to stack stop
LUA->PushCClosure( lrdb_activate, 1 );
LUA->SetField( -2, "activate" );

LUA->Push( -2 ); // push userdata to stack stop
LUA->PushCClosure( lrdb_deactivate, 1 );
LUA->SetField( -2, "deactivate" );

LUA->Push( -1 );
LUA->SetField( GarrysMod::Lua::INDEX_GLOBAL, "lrdb" );

return 1;
}

static int32_t Deinitialize( GarrysMod::Lua::ILuaBase *LUA )
{
LUA->PushNil( );
LUA->SetField( GarrysMod::Lua::INDEX_GLOBAL, "lrdb" );
return 0;
}
}

GMOD_MODULE_OPEN( )
{
return global::Initialize( LUA );
}

GMOD_MODULE_CLOSE( )
{
return global::Deinitialize( LUA );
}

0 comments on commit 8e159bf

Please sign in to comment.