forked from kungfooman/libcod
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgsc_utils.cpp
executable file
·135 lines (115 loc) · 3.3 KB
/
gsc_utils.cpp
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
131
132
133
134
135
#include "gsc_utils.hpp"
//#if COMPILE_UTILS == 1
int gsc_utils_disableGlobalPlayerCollision()
{
int ret;
// well, i could also just write LEAVE,RETN C9,C3 at beginnung of function
#if COD_VERSION == COD2_1_2
/*
//ret = cracking_nop(0x080F6D5A, 0x080F7150);
ret = cracking_nop(0x080F6E82, 0x080F7150); // requires setcontents(0) hack and brushmodels arent working
*/
cracking_write_hex(0x080F6D5A, (char *)"C3");
cracking_write_hex(0x080F77AD, (char *)"02");
cracking_write_hex(0x0805AC1A, (char *)"C3");
#endif
#if COD_VERSION == COD2_1_3
//ret = cracking_nop(0x080F6E9E, 0x080F7294);
//ret = cracking_nop(0x080F6FC6, 0x080F7294);
cracking_write_hex(0x080F6E9E, (char *)"C3");
cracking_write_hex(0x080F78F1, (char *)"02");
cracking_write_hex(0x0805AC12, (char *)"C3");
#endif
return stackPushInt(ret);
}
int gsc_utils_ClientCommand()
{
int clientNum;
if ( ! stackGetParamInt(1, &clientNum))
return stackPushUndefined();
int ret = ClientCommand(clientNum);
return stackPushInt(ret);
}
int gsc_utils_getAscii()
{
char *str;
if ( ! stackGetParamString(1, &str))
return stackPushUndefined();
if (strlen(str) == 0)
return stackPushUndefined();
return stackPushInt(str[0]);
}
int gsc_utils_system() // closer 903, "ls"
{
char *cmd;
if (stackGetNumberOfParams() < 2) // function, command
{
printf_hide("scriptengine> ERROR: please specify atleast 2 arguments to gsc_system_command()\n");
return stackPushUndefined();
}
if (!stackGetParamString(1, &cmd))
{
printf_hide("scriptengine> ERROR: closer(): param \"cmd\"[1] has to be a string!\n");
return stackPushUndefined();
}
setenv("LD_PRELOAD", "", 1); // dont inherit lib of parent
int ret = system(cmd);
return stackPushInt(ret);
}
int gsc_utils_file_link()
{
char *source;
char *dest;
if (stackGetNumberOfParams() < 3) // function, source, dest
{
printf_hide("scriptengine> ERROR: please specify atleast 3 arguments to gsc_link_file()\n");
return stackPushUndefined();
}
if (!stackGetParamString(1, &source))
{
printf_hide("scriptengine> ERROR: closer(): param \"source\"[1] has to be a string!\n");
return stackPushUndefined();
}
if (!stackGetParamString(2, &dest))
{
printf_hide("scriptengine> ERROR: closer(): param \"dest\"[2] has to be a string!\n");
return stackPushUndefined();
}
int ret = link(source, dest);
return stackPushInt(ret); // 0 == success
}
int gsc_utils_file_unlink()
{
char *file;
if (stackGetNumberOfParams() < 2) // function, source, dest
{
printf_hide("scriptengine> ERROR: please specify atleast 2 arguments to gsc_unlink_file()\n");
return stackPushUndefined();
}
if (!stackGetParamString(1, &file))
{
printf_hide("scriptengine> ERROR: closer(): param \"file\"[1] has to be a string!\n");
return stackPushUndefined();
}
int ret = unlink(file);
return stackPushInt(ret); // 0 == success
}
int gsc_utils_FS_LoadDir() // closer(1302, "/home/ns_test", "NsZombiesV4.3");
{
char *path, *dir;
if ( ! stackGetParams("ss", &path, &dir))
return stackPushUndefined();
//printf("path %s dir %s \n", path, dir);
int ret = FS_LoadDir(path, dir);
return stackPushInt(ret);
}
int gsc_utils_fileexists()
{
char *filename;
if ( ! stackGetParams("s", &filename))
return stackPushUndefined();
if (access(filename, F_OK) == -1)
return stackPushInt(0);
return stackPushInt(1);
}
//#endif