Subversion Repositories WoWGM

Rev

Rev 21 | Rev 32 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 21 Rev 31
Line 4... Line 4...
4
#include "ConsoleClient.h"
4
#include "ConsoleClient.h"
5
#include <Os/W32/OsFile.h>
5
#include <Os/W32/OsFile.h>
6
 
6
 
7
/****************************************************************************
7
/****************************************************************************
8
*
8
*
9
*	Memory addresses
9
*   Client memory addresses
10
*
10
*
11
***/
11
***/
12
#define  CONSOLECOMMANDDESTROY	0x007685C0;
-
 
13
 
12
 
14
void (__cdecl* ConsoleCommandDestroyPtr) () = *(void(__cdecl*)())CONSOLECOMMANDDESTROY;
13
#define  CONSOLECOMMANDDESTROY  0x007685C0;
15
 
14
 
16
 
15
 
-
 
16
/****************************************************************************
-
 
17
*
-
 
18
*   Client symbol pointers
-
 
19
*
-
 
20
***/
-
 
21
 
-
 
22
void (*ConsoleCommandDestroyPtr)() = *(void(*)())CONSOLECOMMANDDESTROY;
-
 
23
 
-
 
24
 
-
 
25
/****************************************************************************
-
 
26
*
-
 
27
*   Privates
-
 
28
*
-
 
29
***/
-
 
30
 
-
 
31
static char s_fileName[260] = {};
-
 
32
 
17
//===========================================================================
33
//===========================================================================
18
void __cdecl ConsoleCommandDestroy()
34
void ConsoleCommandDestroy () {
19
{
-
 
20
	// Remove the function trampoline
35
	// Remove the function trampoline
21
	DETOUR_INIT;
36
	DETOUR_INIT;
22
	DETOUR_DETACH(ConsoleCommandDestroyPtr,ConsoleCommandDestroy);
37
	DETOUR_DETACH(ConsoleCommandDestroyPtr,ConsoleCommandDestroy);
23
	DETOUR_COMMIT;
38
	DETOUR_COMMIT;
24
 
39
 
Line 29... Line 44...
29
 
44
 
30
	// Call the original function
45
	// Call the original function
31
	ConsoleCommandDestroyPtr();
46
	ConsoleCommandDestroyPtr();
32
}
47
}
33
 
48
 
34
 
-
 
35
static char s_fileName[260] = {};
-
 
36
 
-
 
37
//===========================================================================
49
//===========================================================================
38
BOOL ValidateFileName (const char* fileName)
50
BOOL ValidateFileName (const char* fileName) {
39
{
-
 
40
	if (fileName && *fileName) {
51
  if (fileName && *fileName) {
41
		if (strstr(fileName,"..") || strstr(fileName,"\\")) {
52
    if (strstr(fileName,"..") || strstr(fileName,"\\")) {
42
			ConsoleWrite("File Name cannot contain '\\' or '..'",ERROR_COLOR);
53
      ConsoleWrite("File Name cannot contain '\\' or '..'",ERROR_COLOR);
43
			return FALSE;
54
      return FALSE;
-
 
55
    }
-
 
56
 
-
 
57
    const char* fileExtension = strrchr(fileName,'.');
-
 
58
    if (fileExtension&& *fileExtension) {
-
 
59
      if (_strcmpi(fileExtension,".wtf")) {
-
 
60
        ConsoleWrite("Only '.wtf' extensions are allowed",ERROR_COLOR);
-
 
61
        return FALSE;
-
 
62
      }
-
 
63
    }
-
 
64
    return TRUE;
44
		}
65
  }
45
 
66
 
46
		const char* fileExtension = strrchr(fileName,'.');
-
 
47
		if (fileExtension&& *fileExtension) {
-
 
48
			if (_strcmpi(fileExtension,".wtf")) {
-
 
49
				ConsoleWrite("Only '.wtf' extensions are allowed",ERROR_COLOR);
-
 
50
				return FALSE;
-
 
51
			}
-
 
52
		}
-
 
53
		return TRUE;
-
 
54
	}
-
 
55
	return FALSE;
67
  return FALSE;
56
}
68
}
57
 
69
 
58
//===========================================================================
70
//===========================================================================
59
BOOL CreateWTFFilePath (char* filePath, unsigned int size)
71
BOOL CreateWTFFilePath (char* filePath, unsigned int size) {
60
{
-
 
61
	char buffer[FILENAME_MAX] = {};
72
	char buffer[FILENAME_MAX] = {};
62
 
73
 
63
	if (filePath && *filePath && size != 0) {
74
	if (filePath && *filePath && size != 0) {
64
		SStrCopy(buffer,"WTF\\",FILENAME_MAX);
75
		SStrCopy(buffer,"WTF\\",FILENAME_MAX);
65
		strncat_s(buffer,filePath,FILENAME_MAX);
76
		strncat_s(buffer,filePath,FILENAME_MAX);
Line 75... Line 86...
75
			strncat_s(buffer,".wtf",FILENAME_MAX);
86
			strncat_s(buffer,".wtf",FILENAME_MAX);
76
		}
87
		}
77
		SStrCopy(filePath,buffer,FILENAME_MAX);
88
		SStrCopy(filePath,buffer,FILENAME_MAX);
78
		return TRUE;
89
		return TRUE;
79
	}
90
	}
-
 
91
 
80
	return FALSE;
92
	return FALSE;
81
}
93
}
82
 
94
 
83
 
95
 
84
/****************************************************************************
96
/****************************************************************************
85
*
97
*
86
*  Command definitions
98
*   Command definitions
87
*
99
*
88
***/
100
***/
89
 
101
 
90
//===========================================================================
102
//===========================================================================
91
int __cdecl ConsoleCommand_CreateExec (const char* cmd, const char* arguments)
103
BOOL  ConsoleCommand_CreateExec (const char* cmd, const char* arguments) {
92
{
-
 
93
	if (ValidateFileName(arguments))
104
	if (ValidateFileName(arguments)) {
94
	{
-
 
95
		char folder[FILENAME_MAX] = {};
105
		char folder[FILENAME_MAX] = {};
96
		char filePath[FILENAME_MAX] = {};
106
		char filePath[FILENAME_MAX] = {};
97
 
107
 
98
		SStrCopy(s_fileName,arguments,FILENAME_MAX);
108
		SStrCopy(s_fileName,arguments,FILENAME_MAX);
99
		SStrCopy(filePath,s_fileName,FILENAME_MAX);
109
		SStrCopy(filePath,s_fileName,FILENAME_MAX);
Line 119... Line 129...
119
					g_ExecCreateMode = EM_NOTACTIVE;
129
					g_ExecCreateMode = EM_NOTACTIVE;
120
				}
130
				}
121
			}
131
			}
122
		}
132
		}
123
	}
133
	}
124
	return 0;
134
	return FALSE;
125
}
135
}
126
 
136
 
127
//===========================================================================
137
//===========================================================================
128
int __cdecl ConsoleCommand_CloseExec(const char *cmd, const char *arguments)
138
BOOL ConsoleCommand_CloseExec (const char *cmd, const char *arguments) {
129
{
-
 
130
	int result = FALSE;
139
	BOOL result = FALSE;
131
	if (g_ExecCreateMode < EM_APPEND || g_ExecCreateMode > EM_WRITEFILE)
140
	if (g_ExecCreateMode < EM_APPEND || g_ExecCreateMode > EM_WRITEFILE)
132
	{
141
	{
133
		ConsoleWrite("You must type 'new' 'filename' to begin creating an Exec file",WARNING_COLOR);
142
		ConsoleWrite("You must type 'new' 'filename' to begin creating an Exec file",WARNING_COLOR);
134
		result = TRUE;
143
		result = TRUE;
135
	}
144
	}
Line 171... Line 180...
171
		}
180
		}
172
		g_ExecCreateMode = EM_NOTACTIVE;
181
		g_ExecCreateMode = EM_NOTACTIVE;
173
		memset(g_ExecBuffer,'\0',sizeof(g_ExecBuffer));
182
		memset(g_ExecBuffer,'\0',sizeof(g_ExecBuffer));
174
		result = TRUE;
183
		result = TRUE;
175
	}
184
	}
-
 
185
 
176
	return result;
186
	return result;
177
}
187
}
178
 
188
 
179
//===========================================================================
189
//===========================================================================
180
int __cdecl ConsoleCommand_RunExec(const char *command, const char *arguments)
190
BOOL ConsoleCommand_RunExec (const char *command, const char *arguments) {
181
{
-
 
182
	int result = 0;
191
	BOOL result = FALSE;
183
	char filename[FILENAME_MAX] = { '\0' };
192
	char filename[FILENAME_MAX] = { '\0' };
184
	char tmp[FILENAME_MAX] = { '\0' };
193
	char tmp[FILENAME_MAX] = { '\0' };
185
	char lineBuffer[128] = { '\0' };
194
	char lineBuffer[128] = { '\0' };
186
	char param1[32] = { '\0' };
195
	char param1[32] = { '\0' };
187
	DWORD bytes;
196
	DWORD bytes;
Line 260... Line 269...
260
	else
269
	else
261
	{
270
	{
262
		ConsoleWrite("Invalid number of parameters", ERROR_COLOR);
271
		ConsoleWrite("Invalid number of parameters", ERROR_COLOR);
263
		ConsoleCommandWriteHelp(command);
272
		ConsoleCommandWriteHelp(command);
264
	}
273
	}
-
 
274
 
265
	return result;
275
	return result;
266
}
276
}
267
 
277
 
268
//===========================================================================
278
//===========================================================================
269
BOOL ConsoleCommand_Ver (LPCSTR command, LPCSTR args) {
279
BOOL ConsoleCommand_Ver (LPCSTR command, LPCSTR args) {
Line 276... Line 286...
276
}
286
}
277
 
287
 
278
 
288
 
279
/****************************************************************************
289
/****************************************************************************
280
*
290
*
281
*	External functions
291
*   External functions
282
*
292
*
283
***/
293
***/
284
 
294
 
285
//===========================================================================
295
//===========================================================================
286
void __cdecl ConsoleCommandInitialize()
296
void ConsoleCommandInitialize () {
287
{
-
 
288
	// This function is called from WowGM,
297
	// This function is called internally,
289
	// so only setup a trampoline for ConsoleCommandDestroy()
298
	// so only setup a trampoline for ConsoleCommandDestroy()
290
	DETOUR_INIT;
299
	DETOUR_INIT;
291
	DETOUR_ATTACH(ConsoleCommandDestroyPtr,ConsoleCommandDestroy);
300
	DETOUR_ATTACH(ConsoleCommandDestroyPtr,ConsoleCommandDestroy);
292
	DETOUR_COMMIT;
301
	DETOUR_COMMIT;
293
 
302
 
294
	// Replace the client's "ver" command
303
	// Replace the client's "ver" command with our own
295
	ConsoleCommandUnregister("ver");
304
	ConsoleCommandUnregister("ver");
296
	ConsoleCommandRegister("ver",ConsoleCommand_Ver,DEFAULT,NOHELP); 
305
	ConsoleCommandRegister("ver",ConsoleCommand_Ver,DEFAULT,NOHELP); 
297
 
306
 
298
	ConsoleCommandRegister("new",ConsoleCommand_CreateExec,CONSOLE,"[File Name] starts recording a new script");
307
	ConsoleCommandRegister("new",ConsoleCommand_CreateExec,CONSOLE,"[File Name] starts recording a new script");
299
	ConsoleCommandRegister("run",ConsoleCommand_RunExec,CONSOLE,"[File Name] Runs a wtf file from the WTF folder");
308
	ConsoleCommandRegister("run",ConsoleCommand_RunExec,CONSOLE,"[File Name] Runs a wtf file from the WTF folder");