libcod
gsc.hpp
Go to the documentation of this file.
1 #ifndef _GSC_HPP_
2 #define _GSC_HPP_
3 #define COD2_MAX_STRINGLENGTH 1024
4 
5 #ifdef __cplusplus
6 extern "C" {
7 #endif
8 
9 // needs to be over the includes
10 // example of versioning:
11 /*
12  #if COD2_VERSION == COD2_VERSION_1_2
13  int *addressToCloserPointer = (int *)0x081872D0;
14  #endif
15  #if COD2_VERSION == COD2_VERSION_1_3
16  int *addressToCloserPointer = (int *)0x081882F0;
17  #endif
18 */
19 
20 #define COD2_VERSION_1_0 0 // depricated
21 #define COD2_VERSION_1_2 2 // depricated
22 #define COD2_VERSION_1_3 3 // depricated
23 
24 #define COD1_1_5 115
25 #define COD2_1_0 210
26 #define COD2_1_2 212
27 #define COD2_1_3 213
28 #define COD4_1_7 417
29 #define COD4_1_7_L 4171
30 
31 //#define COD2_VERSION COD2_VERSION_1_2
32 
33 // gonna define that per command-line now, to build from script every version + select the correct with inbuilt if()
34 //#define COD2_VERSION COD2_VERSION_1_3
35 
36 
37 /* default stuff */
38 #include <stdio.h>
39 #include <stdlib.h>
40 #include <string.h>
41 #include <math.h>
42 
43 #include <dlfcn.h> // closer 500: dlcall
44 #include <stdarg.h> // va_args
45 
46 #include "config.hpp" // DEBUG_MYSQL etc.
47 
48 #include "functions.hpp"
49 
50 #include "gsc_player.hpp"
51 #include "gsc_astar.hpp"
52 #include "gsc_mysql.hpp"
53 #include "gsc_memory.hpp"
54 #include "gsc_car.hpp"
55 #include "gsc_tcc.hpp"
56 #include "gsc_utils.hpp"
57 #include "gsc_math.hpp"
58 
59 
60 #include "cracking.hpp" // closer 900: nop
61 
62 /*
63 static void printf_hide(const char *str, ...)
64 {
65  #if DEBUG_PRINTF == 1
66  va_list args;
67  va_start(args, str);
68  vprintf(str, args);
69  va_end(args);
70  #endif
71 }
72 */
73 
74 /*
75  just search in winhex for "localized string" in the binary and go-to-fileoffset in IDA
76 
77  in cod4 search for "developer codepos"
78 */
79 
80 #if COD2_VERSION == COD2_VERSION_1_2 || COD2_VERSION == COD2_VERSION_1_3 || COD_VERSION == COD2_1_0
81  #define STACK_UNDEFINED 0
82  #define STACK_OBJECT 1
83  #define STACK_STRING 2
84  #define STACK_LOCALIZED_STRING 3
85  #define STACK_VECTOR 4
86  #define STACK_FLOAT 5
87  #define STACK_INT 6
88  #define STACK_CODEPOS 7
89  #define STACK_PRECODEPOS 8
90  #define STACK_FUNCTION 9
91  #define STACK_STACK 10
92  #define STACK_ANIMATION 11
93  #define STACK_DEVELOPER_CODEPOS 12
94  #define STACK_INCLUDE_CODEPOS 13
95  #define STACK_THREAD_LIST 14
96  #define STACK_THREAD_1 15
97  #define STACK_THREAD_2 16
98  #define STACK_THREAD_3 17
99  #define STACK_THREAD_4 18
100  #define STACK_STRUCT 19
101  #define STACK_REMOVED_ENTITY 20
102  #define STACK_ENTITY 21
103  #define STACK_ARRAY 22
104  #define STACK_REMOVED_THREAD 23
105 
106 #elif COD_VERSION == COD1_1_5
107 
108  #define STACK_UNDEFINED 0
109  #define STACK_STRING 1
110  #define STACK_LOCALIZED_STRING 2
111  #define STACK_VECTOR 3
112  #define STACK_FLOAT 4
113  #define STACK_INT 5
114  #define STACK_CODEPOS 6
115  #define STACK_OBJECT 7
116  #define STACK_KEY_VALUE 8
117  #define STACK_FUNCTION 9
118  #define STACK_STACK 10
119  #define STACK_ANIMATION 11
120  #define STACK_THREAD 12
121  #define STACK_ENTITY 13
122  #define STACK_STRUCT 14
123  #define STACK_ARRAY 15
124  #define STACK_DEAD_THREAD 16
125  #define STACK_DEAD_ENTITY 17
126  #define STACK_DEAD_OBJECT 18
127 
128 #elif COD_VERSION == COD4_1_7 || COD_VERSION == COD4_1_7_L
129  /*
130  THOSE ARE CoD2 ones!
131 
132  WinHex: 1E3AE3
133 
134  */
135  #define STACK_UNDEFINED 0
136  #define STACK_OBJECT 1
137  #define STACK_STRING 2
138  #define STACK_LOCALIZED_STRING 3
139  #define STACK_VECTOR 4
140  #define STACK_FLOAT 5
141  #define STACK_INT 6
142  #define STACK_CODEPOS 7
143  #define STACK_PRECODEPOS 8
144  #define STACK_FUNCTION 9
145  #define STACK_STACK 10
146  #define STACK_ANIMATION 11
147  #define STACK_DEVELOPER_CODEPOS 12
148  #define STACK_INCLUDE_CODEPOS 13
149  #define STACK_THREAD_LIST 14
150  #define STACK_THREAD_1 15
151  #define STACK_THREAD_2 16
152  #define STACK_THREAD_3 17
153  #define STACK_THREAD_4 18
154  #define STACK_STRUCT 19
155  #define STACK_REMOVED_ENTITY 20
156  #define STACK_ENTITY 21
157  #define STACK_ARRAY 22
158  #define STACK_REMOVED_THREAD 23
159 #else
160  // NO ERROR, because those are only available if code is compiled version-dependent!
161  //#warning NO STACK TYPES
162 #endif
163 
164 typedef struct
165 {
166  void *offsetData;
167  int type;
168 } aStackElement;
169 
170 int getStack();
171 int stackNew();
172 int stackPushUndefined();
173 
174 int stackGetParamInt(int param, int *value);
175 int stackGetParamString(int param, char **value);
176 int stackGetParamVector(int param, float value[3]);
177 int stackGetParamFloat(int param, float *value);
179 int stackGetParamType(int param);
180 char *stackGetParamTypeAsString(int param);
181 int stackGetParams(char *params, ...);
182 
183 
184 int stackReturnInt(int ret); // obsolete
185 int stackPushInt(int ret);
186 int stackReturnVector(float *ret); // obsolete
187 int stackPushVector(float *ret);
188 int stackPushFloat(float ret);
189 int stackPushString(char *toPush);
190 int stackPushEntity(int arg);
191 int stackPushArray();
192 int stackPushArrayLast();
193 
194 int stackCallScriptFunction(int self, int scriptFunction, int numberOfArgs);
195 int stackSetKeyInArray(int precachedStringOffset);
198 
199 int sub_8101B40(int self, int eInflictor, int eAttacker, float *vDir, float *vPoint, int iDamage, int iDFlags, int iMeansOfDeath, int iHitLoc, int psOffsetTime);
200 int cdecl_cod2_player_damage_new(int self, int eInflictor, int eAttacker, float *vDir, float *vPoint, int iDamage, int iDFlags, int iMeansOfDeath, int iHitLoc, int psOffsetTime);
201 
202 // might put it in an extra file later, but atm its just one FS function
203 // int FS_LoadDir(char *path, char *dir);
204 
205 
206 // real functions and methods
207 
208 // functions
209 typedef void (*Scr_FunctionCall)();
210 
211 typedef struct {
212  const char *name;
215 } Scr_Function;
216 
217 typedef Scr_FunctionCall (*Scr_GetFunction_t)(const char **fname, int *fdev);
218 
219 Scr_FunctionCall Scr_GetCustomFunction(const char **fname, int *fdev); // could be made obsolete to remove the cracking_hook_call()-stuff
220 
221 // methods
222 typedef void (*Scr_MethodCall)(int);
223 
224 typedef struct {
225  const char* name;
228 } Scr_Method;
229 
230 typedef Scr_MethodCall (*Scr_GetMethod_t)(const char**, int*);
231 
232 Scr_MethodCall Scr_GetCustomMethod(const char **fname, int *fdev); // could be made obsolete to remove the cracking_hook_call()-stuff
233 
234 #ifdef __cplusplus
235 }
236 #endif
237 
238 #endif
int stackGetParamInt(int param, int *value)
Definition: gsc.cpp:474
int getStack()
Definition: gsc.cpp:367
void * offsetData
Definition: gsc.hpp:166
int stackReturnInt(int ret)
Definition: gsc.cpp:675
int developer
Definition: gsc.hpp:214
int stackNew()
Definition: gsc.cpp:618
char * stackGetParamTypeAsString(int param)
Definition: gsc.cpp:60
int stackPushEntity(int arg)
Definition: gsc.cpp:815
int stackGetParamFloat(int param, float *value)
Definition: gsc.cpp:542
Scr_MethodCall Scr_GetCustomMethod(const char **fname, int *fdev)
Definition: gsc.cpp:342
int stackPushVector(float *ret)
Definition: gsc.cpp:734
Scr_FunctionCall call
Definition: gsc.hpp:213
int cdecl_injected_closer()
Definition: gsc.cpp:1386
int stackPushString(char *toPush)
Definition: gsc.cpp:794
int cdecl_cod2_player_damage_new(int self, int eInflictor, int eAttacker, float *vDir, float *vPoint, int iDamage, int iDFlags, int iMeansOfDeath, int iHitLoc, int psOffsetTime)
Definition: gsc.cpp:2009
int stackGetParamString(int param, char **value)
Definition: gsc.cpp:500
Scr_MethodCall call
Definition: gsc.hpp:226
int stackReturnVector(float *ret)
Definition: gsc.cpp:722
Scr_FunctionCall(* Scr_GetFunction_t)(const char **fname, int *fdev)
Definition: gsc.hpp:217
void(* Scr_FunctionCall)()
Definition: gsc.hpp:209
int type
Definition: gsc.hpp:167
int stackCallScriptFunction(int self, int scriptFunction, int numberOfArgs)
Definition: gsc.cpp:834
int cdecl_injected_closer_stack_debug()
Definition: gsc.cpp:577
int developer
Definition: gsc.hpp:227
int stackGetParamVector(int param, float value[3])
Definition: gsc.cpp:530
void(* Scr_MethodCall)(int)
Definition: gsc.hpp:222
int stackPushFloat(float ret)
Definition: gsc.cpp:773
Scr_MethodCall(* Scr_GetMethod_t)(const char **, int *)
Definition: gsc.hpp:230
Definition: gsc.hpp:224
int stackSetKeyInArray(int precachedStringOffset)
Definition: gsc.cpp:864
const char * name
Definition: gsc.hpp:212
Definition: gsc.hpp:211
int stackPushUndefined()
Definition: gsc.cpp:641
int stackPushArray()
Definition: gsc.cpp:843
int stackGetNumberOfParams()
Definition: gsc.cpp:570
const char * name
Definition: gsc.hpp:225
Scr_FunctionCall Scr_GetCustomFunction(const char **fname, int *fdev)
Definition: gsc.cpp:279
Definition: gsc.hpp:164
int stackPushInt(int ret)
Definition: gsc.cpp:685
int stackGetParamType(int param)
Definition: gsc.cpp:387
int stackGetParams(char *params,...)
Definition: gsc.cpp:394
int sub_8101B40(int self, int eInflictor, int eAttacker, float *vDir, float *vPoint, int iDamage, int iDFlags, int iMeansOfDeath, int iHitLoc, int psOffsetTime)
Definition: gsc.cpp:1976
int stackPushArrayLast()
Definition: gsc.cpp:871