Skip to content

Commit 9439365

Browse files
authored
Merge pull request #35 from danielga/update-signatures-and-fix-longstanding-issues
Update signatures and fix some longstanding issues
2 parents cb6cd3e + 82c03c3 commit 9439365

37 files changed

+215
-7709
lines changed

azure-pipelines.yml

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,7 @@ variables:
66
GARRYSMOD_COMMON_REPOSITORY: https://github.com/danielga/garrysmod_common.git
77
PROJECT_GENERATOR_VERSION: 2
88
REPOSITORY_DIR: $(System.DefaultWorkingDirectory)
9-
TARGET_ARCHITECTURE: x86
10-
TARGET_ARCHITECTURE_64: x86_64
119
DISABLE_X86_64_BUILD: true
12-
SOURCE_SDK: $(System.DefaultWorkingDirectory)/dependencies/sourcesdk-minimal
13-
SOURCE_SDK_BRANCH: master
14-
SOURCE_SDK_REPOSITORY: https://github.com/danielga/sourcesdk-minimal.git
1510
trigger:
1611
tags:
1712
include:
@@ -26,13 +21,10 @@ jobs:
2621
variables:
2722
BOOTSTRAP_URL: https://raw.githubusercontent.com/danielga/garrysmod_common/master/build/bootstrap.ps1
2823
BUILD_SCRIPT: $(System.DefaultWorkingDirectory)/dependencies/garrysmod_common/build/build.ps1
29-
TARGET_OS: win32
30-
TARGET_OS_64: win64
3124
COMPILER_PLATFORM: vs2019
3225
PROJECT_OS: windows
33-
PREMAKE5_EXECUTABLE: premake5.exe
3426
PREMAKE5: $(System.DefaultWorkingDirectory)/dependencies/windows/premake-core/premake5.exe
35-
PREMAKE5_URL: https://github.com/premake/premake-core/releases/download/v5.0.0-alpha14/premake-5.0.0-alpha14-windows.zip
27+
PREMAKE5_URL: https://github.com/premake/premake-core/releases/download/v5.0.0-alpha15/premake-5.0.0-alpha15-windows.zip
3628
steps:
3729
- powershell: 'Invoke-Expression ((New-Object System.Net.WebClient).DownloadString("$env:BOOTSTRAP_URL"))'
3830
displayName: Bootstrap
@@ -55,24 +47,25 @@ jobs:
5547
displayName: Linux
5648
pool:
5749
name: Azure Pipelines
58-
vmImage: ubuntu-18.04
50+
vmImage: ubuntu-16.04
5951
timeoutInMinutes: 10
6052
variables:
6153
BOOTSTRAP_URL: https://raw.githubusercontent.com/danielga/garrysmod_common/master/build/bootstrap.sh
6254
BUILD_SCRIPT: $(System.DefaultWorkingDirectory)/dependencies/garrysmod_common/build/build.sh
63-
TARGET_OS: linux
64-
TARGET_OS_64: linux64
6555
COMPILER_PLATFORM: gmake
6656
PREMAKE5: $(System.DefaultWorkingDirectory)/dependencies/linux/premake-core/premake5
6757
PROJECT_OS: linux
68-
PREMAKE5_URL: https://github.com/premake/premake-core/releases/download/v5.0.0-alpha14/premake-5.0.0-alpha14-linux.tar.gz
69-
CC: gcc-8
70-
CXX: g++-8
58+
PREMAKE5_URL: https://github.com/premake/premake-core/releases/download/v5.0.0-alpha15/premake-5.0.0-alpha15-linux.tar.gz
59+
CC: gcc-9
60+
CXX: g++-9
61+
AR: gcc-ar-9
62+
NM: gcc-nm-9
63+
RANLIB: gcc-ranlib-9
7164
steps:
7265
- bash: 'curl -s -L "$BOOTSTRAP_URL" | bash'
7366
displayName: Bootstrap
7467
- bash: |
75-
sudo apt-get update && sudo apt-get install -y g++-8-multilib
68+
sudo apt-get update && sudo apt-get install -y g++-9-multilib
7669
$BUILD_SCRIPT
7770
displayName: Build
7871
- task: CopyFiles@2
@@ -92,22 +85,23 @@ jobs:
9285
displayName: macOS
9386
pool:
9487
name: Azure Pipelines
95-
vmImage: macOS-10.13
88+
vmImage: macOS-10.15
9689
timeoutInMinutes: 10
9790
variables:
9891
BOOTSTRAP_URL: https://raw.githubusercontent.com/danielga/garrysmod_common/master/build/bootstrap.sh
9992
BUILD_SCRIPT: $(System.DefaultWorkingDirectory)/dependencies/garrysmod_common/build/build.sh
100-
TARGET_OS: osx
101-
TARGET_OS_64: osx64
10293
COMPILER_PLATFORM: gmake
10394
PREMAKE5: $(System.DefaultWorkingDirectory)/dependencies/macosx/premake-core/premake5
10495
PROJECT_OS: macosx
105-
PREMAKE5_URL: https://github.com/premake/premake-core/releases/download/v5.0.0-alpha14/premake-5.0.0-alpha14-macosx.tar.gz
96+
PREMAKE5_URL: https://github.com/premake/premake-core/releases/download/v5.0.0-alpha15/premake-5.0.0-alpha15-macosx.tar.gz
97+
MACOSX_SDK_URL: https://github.com/phracker/MacOSX-SDKs/releases/download/10.15/MacOSX10.7.sdk.tar.xz
98+
MACOSX_SDK_DIRECTORY: $(System.DefaultWorkingDirectory)/dependencies/macosx/MacOSX10.7.sdk
99+
SDKROOT: $(System.DefaultWorkingDirectory)/dependencies/macosx/MacOSX10.7.sdk
106100
steps:
107101
- bash: 'curl -s -L "$BOOTSTRAP_URL" | bash'
108102
displayName: Bootstrap
109103
- bash: |
110-
sudo xcode-select -s "/Applications/Xcode_9.4.1.app/Contents/Developer"
104+
sudo xcode-select -s "/Applications/Xcode_11.4.1.app/Contents/Developer"
111105
$BUILD_SCRIPT
112106
displayName: Build
113107
- task: CopyFiles@2

license.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ gm_sourcenet
22
A module for Garry's Mod that provides interfaces to many systems
33
of VALVe's engine.
44
-----------------------------------------------------------------------
5-
Copyright (c) 2015-2019, Daniel Almeida
5+
Copyright (c) 2015-2020, Daniel Almeida
66
All rights reserved.
77

88
Redistribution and use in source and binary forms, with or without

premake5.lua

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,36 +6,25 @@ newoption({
66

77
local gmcommon = assert(_OPTIONS.gmcommon or os.getenv("GARRYSMOD_COMMON"),
88
"you didn't provide a path to your garrysmod_common (https://github.com/danielga/garrysmod_common) directory")
9-
include(path.join(gmcommon, "generator.v2.lua"))
9+
include(gmcommon .. "/generator.v2.lua")
1010

1111
CreateWorkspace({name = "sourcenet", abi_compatible = true})
1212
CreateProject({serverside = true})
1313
IncludeLuaShared()
14+
IncludeHelpersExtended()
1415
IncludeSDKCommon()
1516
IncludeSDKTier0()
1617
IncludeSDKTier1()
18+
IncludeSDKLZMA()
1719
IncludeScanning()
1820
IncludeDetouring()
1921
files({"source/server/*.cpp", "source/server/*.hpp"})
20-
links("LZMA")
2122

2223
CreateProject({serverside = false})
2324
IncludeLuaShared()
25+
IncludeHelpersExtended()
2426
IncludeSDKCommon()
2527
IncludeSDKTier0()
2628
IncludeSDKTier1()
2729
IncludeScanning()
2830
IncludeDetouring()
29-
30-
project("LZMA")
31-
language("C")
32-
kind("StaticLib")
33-
defines("_7ZIP_ST")
34-
files({
35-
"source/lzma/*.h",
36-
"source/lzma/*.c"
37-
})
38-
vpaths({
39-
["Header files"] = "source/lzma/*.h",
40-
["Source files"] = "source/lzma/*.c"
41-
})

readme.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@ A module for Garry's Mod that provides interfaces to many systems of VALVe's eng
55

66
## Compiling
77

8-
The only supported compilation platform for this project on Windows is **Visual Studio 2017** on **release** mode.
8+
The only supported compilation platforms for this project on Windows are **Visual Studio 2015**, **Visual Studio 2017** and **Visual Studio 2019** on **release** mode.
99
On Linux, everything should work fine as is, on **release** mode.
10-
For Mac OSX, any **Xcode (using the GCC compiler)** version *MIGHT* work as long as the **Mac OSX 10.7 SDK** is used, on **release** mode.
10+
For Mac OSX, any **Xcode version (using the GCC compiler)** *MIGHT* work as long as the **Mac OSX 10.7 SDK** is used, on **release** mode.
1111
These restrictions are not random; they exist because of ABI compatibility reasons.
12-
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.
12+
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.
1313

1414
## Requirements
1515

16-
This project requires [garrysmod\_common][2], 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**' to the path of your local copy of [garrysmod\_common][2].
17-
We also use [SourceSDK2013][3], so set the environment variable '**SOURCE\_SDK**' or the premake option '**sourcesdk**' to the path of your local copy of [SourceSDK2013][3]. The previous links to [SourceSDK2013][3] point to my own fork of VALVe's repo and for good reason: Garry's Mod has lots of backwards incompatible changes to interfaces and it's much smaller, being perfect for automated build systems like Travis-CI.
16+
This project requires [garrysmod_common][2], 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][2].
17+
We also use [SourceSDK2013][3]. The previous links to [SourceSDK2013][3] point to my own fork of VALVe's repo and for good reason: Garry's Mod has lots of backwards incompatible changes to interfaces and it's much smaller, being perfect for automated build systems like Azure Pipelines (which is used for this project).
1818

1919
[1]: https://github.com/AlexSwift/GMod13-Modules/tree/master/gm_sourcenet3
2020
[2]: https://github.com/danielga/garrysmod_common

source/gameeventmanager.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "sn_bf_write.hpp"
66

77
#include <GarrysMod/Lua/AutoReference.h>
8+
89
#include <igameevents.h>
910

1011
namespace GameEventManager

source/hooks.cpp

Lines changed: 33 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@
66
#include "sn_bf_write.hpp"
77
#include "net.hpp"
88

9-
#include <inetmsghandler.h>
10-
#include <cdll_int.h>
11-
#include <scanning/symbolfinder.hpp>
129
#include <GarrysMod/Lua/Helpers.hpp>
13-
#include <detouring/classproxy.hpp>
10+
#include <GarrysMod/FunctionPointers.hpp>
1411
#include <Platform.hpp>
1512

13+
#include <detouring/classproxy.hpp>
14+
15+
#include <inetmsghandler.h>
16+
#include <cdll_int.h>
17+
1618
namespace Hooks
1719
{
1820

@@ -64,17 +66,6 @@ namespace Hooks
6466
class CNetChanProxy : public Detouring::ClassProxy<CNetChan, CNetChanProxy>
6567
{
6668
private:
67-
68-
#if defined SYSTEM_WINDOWS
69-
70-
typedef bool( __thiscall *ProcessMessages_t )( CNetChan *netchan, bf_read &buf );
71-
72-
#else
73-
74-
typedef bool( *ProcessMessages_t )( CNetChan *netchan, bf_read &buf );
75-
76-
#endif
77-
7869
typedef CNetChan TargetClass;
7970
typedef CNetChanProxy SubstituteClass;
8071

@@ -83,25 +74,12 @@ namespace Hooks
8374
return NetChannel::Get( LUA, index );
8475
}
8576

86-
static const char ProcessMessages_sig[];
87-
static const size_t ProcessMessages_siglen;
88-
89-
static ProcessMessages_t ProcessMessages_original;
77+
static FunctionPointers::CNetChan_ProcessMessages_t ProcessMessages_original;
9078

9179
public:
9280
static void Initialize( GarrysMod::Lua::ILuaBase *LUA )
9381
{
94-
{
95-
SymbolFinder symfinder;
96-
97-
ProcessMessages_original =
98-
reinterpret_cast<ProcessMessages_t>( symfinder.Resolve(
99-
global::engine_loader.GetModuleLoader( ).GetModule( ),
100-
ProcessMessages_sig,
101-
ProcessMessages_siglen
102-
) );
103-
}
104-
82+
ProcessMessages_original = FunctionPointers::CNetChan_ProcessMessages( );
10583
if( ProcessMessages_original == nullptr )
10684
LUA->ThrowError( "failed to locate CNetChan::ProcessMessages" );
10785
}
@@ -210,15 +188,19 @@ namespace Hooks
210188
{
211189
CNetChan *netchan = This( );
212190

213-
static uint8_t data[100000] = { 0 };
214191
if( !buf.IsOverflowed( ) )
215192
{
216-
memcpy( data, buf.GetBasePointer( ), buf.GetNumBytesRead( ) );
193+
static uint8_t data[100000] = { 0 };
217194

218-
int32_t bitsread = buf.GetNumBitsRead( );
195+
const int32_t bytesread = buf.GetNumBytesRead( );
196+
if( bytesread > 0 )
197+
std::memcpy( data, buf.GetBasePointer( ), bytesread );
198+
199+
const int32_t bitsread = buf.GetNumBitsRead( );
219200
bf_write write( data, sizeof( data ) );
220201
write.SeekToBit( bitsread );
221202

203+
bool handled = false;
222204
HOOK_INIT( "PreProcessMessages" );
223205
HOOK_PUSH( NetChannel::Push( LUA, netchan ) );
224206
HOOK_PUSH( bf_read **reader = sn_bf_read::Push( LUA, &buf ) );
@@ -232,21 +214,30 @@ namespace Hooks
232214
) );
233215
}
234216

235-
HOOK_CALL( 0 );
217+
if( HOOK_CALL( 1 ) )
218+
{
219+
if( LUA->IsType( -1, GarrysMod::Lua::Type::BOOL ) )
220+
handled = LUA->GetBool( -1 );
221+
222+
LUA->Pop( 1 );
223+
}
236224

237225
*reader = nullptr;
238226
*writer = nullptr;
239227
HOOK_END( );
240228

241-
buf.StartReading(
242-
write.GetBasePointer( ),
243-
write.GetNumBytesWritten( ),
244-
bitsread,
245-
write.GetNumBitsWritten( )
246-
);
229+
if( handled )
230+
buf.StartReading(
231+
write.GetBasePointer( ),
232+
write.GetNumBytesWritten( ),
233+
bitsread,
234+
write.GetNumBitsWritten( )
235+
);
236+
else
237+
buf.Seek( bitsread );
247238
}
248239

249-
return Call<bool, bf_read &>( ProcessMessages_original, buf );
240+
return Call<bool, CNetChan, bf_read &>( ProcessMessages_original, buf );
250241
}
251242

252243
bool HookShutdown( CNetChan *netchan )
@@ -262,28 +253,7 @@ namespace Hooks
262253

263254
CNetChanProxy CNetChanProxy::Singleton;
264255

265-
#if defined SYSTEM_WINDOWS
266-
267-
const char CNetChanProxy::ProcessMessages_sig[] = "\x55\x8B\xEC\x83\xEC\x2C\xF7\x05";
268-
const size_t CNetChanProxy::ProcessMessages_siglen =
269-
sizeof( CNetChanProxy::ProcessMessages_sig ) - 1;
270-
271-
#elif ( defined SYSTEM_LINUX && defined SOURCENET_SERVER ) || defined SYSTEM_MACOSX
272-
273-
const char CNetChanProxy::ProcessMessages_sig[] =
274-
"@_ZN8CNetChan15ProcessMessagesER7bf_read";
275-
const size_t CNetChanProxy::ProcessMessages_siglen = 0;
276-
277-
#elif defined SYSTEM_LINUX && defined SOURCENET_CLIENT
278-
279-
const char CNetChanProxy::ProcessMessages_sig[] =
280-
"\x55\x89\xE5\x57\x56\x53\x83\xEC\x6C\x8B\x3D\x2A\x2A\x2A\x2A\x8B";
281-
const size_t CNetChanProxy::ProcessMessages_siglen =
282-
sizeof( CNetChanProxy::ProcessMessages_sig ) - 1;
283-
284-
#endif
285-
286-
CNetChanProxy::ProcessMessages_t CNetChanProxy::ProcessMessages_original = nullptr;
256+
FunctionPointers::CNetChan_ProcessMessages_t CNetChanProxy::ProcessMessages_original = nullptr;
287257

288258
class INetChannelHandlerProxy : public Detouring::ClassProxy<INetChannelHandler, INetChannelHandlerProxy>
289259
{

0 commit comments

Comments
 (0)