Why is my GMod binary module getting these errors?

I'm trying to compile this DLL for Garry's Mod that will bypass scriptenforcer but I'm getting loads of errors. I have almost no experience with C++ and am currently a Lua user, so I need you guys' help.

I have been trying to do this for a long time and I would greatly appreciate some help.

Here's all the headers:

http://filesmelt.com/dl/blah1.png

Additional include directories:

http://filesmelt.com/dl/blah2.png

And here's the code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#include "winlite.h" 
  
 #undef _UNICODE 
  
 #include <interface.h> 
 #include "icvar.h" 
 #include "convar.h" 
  
 #include "detours.h" 
  
 #include "GMLuaModule.h" 

extern "C"
{
	#include "lua.h"
}

 GMOD_MODULE(Init, Shutdown); 

 static ICvar *g_pCVar = NULL; 
  
 lua_State *(lua_newstateOriginal)(lua_Alloc, void *); 
 lua_State *(* lua_newstateDetour)(lua_Alloc, void *); 
 lua_State *(* lua_newstateTramp)(lua_Alloc, void *); 
  
 DETOUR_TRAMPOLINE_EMPTY(lua_State *(lua_newstateOriginal)(lua_Alloc, void *)); 
  
 static lua_State *currentState = NULL; 
  
 lua_State *lua_newstateNew(lua_Alloc f, void *ud) 
 { 
         lua_State* L = lua_newstateOriginal(f, ud); 
          
         currentState = L; 
  
         return L; 
 } 
  
 typedef struct LoadS { 
         const char *s; 
         size_t size; 
 } LoadS; 
  
 static const char *getS (lua_State *L, void *ud, size_t *size) { 
         LoadS *ls = (LoadS *)ud; 
         (void)L; 
         if (ls->size == 0) return NULL; 
         *size = ls->size; 
         ls->size = 0; 
         return ls->s; 
 } 
  
 void LoadLua(const CCommand &command) 
 { 
         if(currentState == NULL) 
                 return; 
  
         // util.RelativePathToFull(  path ) 
  
         lua_getglobal(currentState, "util"); 
         lua_pushstring(currentState, "RelativePathToFull"); 
         lua_gettable(currentState, -2); 
  
         lua_pushstring(currentState, command.ArgS()); 
         if(lua_pcall(currentState, 1, 1, 0) != 0) 
         { 
                 lua_pop(currentState, 1); 
                 return; 
         } 
  
         const char *fullpath = lua_tostring(currentState, -1); 
         lua_pop(currentState, 2); 
  
         FILE *f = fopen(fullpath, "rb"); 
  
         if(f == NULL) 
                 return; 
  
 fseek(f, 0, SEEK_END); 
 long size = ftell(f); 
 rewind(f); 
  
 char *data = (char *)malloc(size); 
  
 fread(data, 1, size, f); 
  
 fclose(f); 
  
 // The game will think any calls from this code are coming from the base gamemodes cl_init.lua 
//luaL_loadbuffer(currentState, data, size, "gamemodes\\base\\gamemode\\cl_init.lua"); 
  
 LoadS ls; 
 ls.s = data; 
 ls.size = size; 
 lua_load(currentState, getS, &ls, "gamemodes\\base\\gamemode\\cl_init.lua"); 
  
 lua_pcall(currentState, 0, 0, 0); 
  
 free(data); 
 } 
  
 static ConCommand *cmd; 
  
 int Init(void) 
 { 
 lua_newstateDetour = &lua_newstateNew; 
 lua_newstateTramp = &lua_newstateOriginal; 
  
 // Detour the lua_newstate function from lua_shared.dll so we can capture the lua_State when its created. 
 DetourFunctionWithEmptyTrampoline(*(PBYTE *) &lua_newstateTramp, (PBYTE) &lua_newstate, *(PBYTE *) &lua_newstateDetour); 
  
 g_pCVar = *(ICvar **)GetProcAddress(GetModuleHandleA("client.dll"), "cvar"); 
  
 cmd = new ConCommand("lua_se2_load", LoadLua, "", FCVAR_UNREGISTERED); 
  
 g_pCVar->RegisterConCommand(cmd); 
  
 return 0; 
 } 
  
 int Shutdown(void) 
 { 
 DetourRemove(*(PBYTE*) &lua_newstateOriginal, *(PBYTE*) &lua_newstateDetour); 
  
 g_pCVar->UnregisterConCommand(cmd); 
  
 delete cmd; 
  
 return 0; 
 }  


And the build log wall of text:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
1
1>Compiling...
1>gm_bypass.cpp
1>.\gm_bypass.cpp(22) : error C2065: 'lua_Alloc' : undeclared identifier
1>.\gm_bypass.cpp(22) : error C2062: type 'void' unexpected
1>.\gm_bypass.cpp(23) : error C2065: 'lua_Alloc' : undeclared identifier
1>.\gm_bypass.cpp(23) : error C2062: type 'void' unexpected
1>.\gm_bypass.cpp(24) : error C2065: 'lua_Alloc' : undeclared identifier
1>.\gm_bypass.cpp(24) : error C2062: type 'void' unexpected
1>.\gm_bypass.cpp(26) : error C2061: syntax error : identifier 'lua_Alloc'
1>.\gm_bypass.cpp(26) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>.\gm_bypass.cpp(30) : error C2065: 'lua_Alloc' : undeclared identifier
1>.\gm_bypass.cpp(30) : error C2146: syntax error : missing ')' before identifier 'f'
1>.\gm_bypass.cpp(30) : error C2059: syntax error : ')'
1>.\gm_bypass.cpp(31) : error C2143: syntax error : missing ';' before '{'
1>.\gm_bypass.cpp(31) : error C2447: '{' : missing function header (old-style formal list?)
1>.\gm_bypass.cpp(65) : error C3861: 'lua_pcall': identifier not found
1>.\gm_bypass.cpp(95) : error C3861: 'lua_load': identifier not found
1>.\gm_bypass.cpp(97) : error C3861: 'lua_pcall': identifier not found
1>.\gm_bypass.cpp(106) : error C2065: 'lua_newstateDetour' : undeclared identifier
1>.\gm_bypass.cpp(107) : error C2065: 'lua_newstateTramp' : undeclared identifier
1>.\gm_bypass.cpp(107) : error C2065: 'lua_newstateOriginal' : undeclared identifier
1>.\gm_bypass.cpp(110) : error C2065: 'lua_newstateTramp' : undeclared identifier
1>.\gm_bypass.cpp(110) : error C2065: 'lua_newstate' : undeclared identifier
1>.\gm_bypass.cpp(110) : error C2065: 'lua_newstateDetour' : undeclared identifier
1>.\gm_bypass.cpp(110) : error C3861: 'DetourFunctionWithEmptyTrampoline': identifier not found
1>.\gm_bypass.cpp(123) : error C2065: 'lua_newstateOriginal' : undeclared identifier
1>.\gm_bypass.cpp(123) : error C2065: 'lua_newstateDetour' : undeclared identifier
1>.\gm_bypass.cpp(123) : error C3861: 'DetourRemove': identifier not found
1>Build log was saved at "file://c:\Users\fffff\Documents\Visual Studio 2008\Projects\gm_bypass\gm_bypass\Release\BuildLog.htm"
1>gm_bypass - 26 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Well, it's sort of telling you exactly what the problem is.

Why are you trying to declare values as type "lua_Alloc"? lua_Alloc is a function.
Topic archived. No new replies allowed.