Skip to content

Commit

Permalink
Ability to choose between my and old mysql stuff :)
Browse files Browse the repository at this point in the history
Also made proper stackpush function defs and minor other fixes
  • Loading branch information
voron00 committed Oct 22, 2017
1 parent 8829e43 commit 7a82dd5
Show file tree
Hide file tree
Showing 20 changed files with 1,853 additions and 1,246 deletions.
4 changes: 2 additions & 2 deletions .gitignore
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
!gsc_memory.hpp
!gsc_mysql.cpp
!gsc_mysql.hpp
!gsc_async_mysql.cpp
!gsc_async_mysql.hpp
!gsc_mysql_voron.cpp
!gsc_mysql_voron.hpp
!gsc_player.cpp
!gsc_player.hpp
!gsc_utils.cpp
Expand Down
Empty file modified README.md
100755 → 100644
Empty file.
4 changes: 2 additions & 2 deletions config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
#define COMPILE_BOTS 1
#define COMPILE_EXEC 1
#define COMPILE_MEMORY 1
#define COMPILE_MYSQL 1
#define COMPILE_ASYNC_MYSQL 1
#define COMPILE_MYSQL_DEFAULT 0
#define COMPILE_MYSQL_VORON 0
#define COMPILE_PLAYER 1
#define COMPILE_UTILS 1
#define COMPILE_WEAPONS 1
Expand Down
2 changes: 1 addition & 1 deletion cracking.cpp
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ void cHook::hook()
void cHook::unhook()
{
memcpy((void *)from, (void *)oldCode, 5);
}
}
2 changes: 1 addition & 1 deletion cracking.hpp
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ class cHook
};
#endif

#endif
#endif
59 changes: 49 additions & 10 deletions doit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,44 @@
cc="g++"
options="-I. -m32 -fPIC -Wall -Wno-write-strings"

mysql_variant=0

if [ "$1" != "clean" ]; then
if [ `perl -ne 'print if s/^#define\sCOMPILE(_ASYNC)?_MYSQL\s(\d)$/\1/' config.hpp` == "0" ]; then
mysql_link=""
elif [ -d "./vendors/lib" ]; then
mysql_link="-lmysqlclient -L./vendors/lib"
export LD_LIBRARY_PATH_32="./vendors/lib"
read -rsp $'\nChoose Your MySQL variant:\n
0. MySQL disabled. (default)\n
1. Default MySQL variant: A classic MySQL implentation
made by kung and izno.
Multiple connections, multiple threads,
good for servers that use
remote MySQL sessions, IRC stuff, and etc.\n
2. VoroN\'s MySQL variant. My own MySQL implentation.
Native callbacks, native arguments,
single connection, single thread,
good for local MySQL session,
less cpu usage, less memory usage.\n
Press a key to continue...\n' -n1 key

if [ "$key" = '1' ]; then
mysql_variant=1
sed -i "/#define COMPILE_MYSQL_DEFAULT 0/c\#define COMPILE_MYSQL_DEFAULT 1" config.hpp
if [ -d "./vendors/lib" ]; then
mysql_link="-lmysqlclient -L./vendors/lib"
export LD_LIBRARY_PATH_32="./vendors/lib"
else
mysql_link="-lmysqlclient -L/usr/lib/mysql"
fi
elif [ "$key" = '2' ]; then
mysql_variant=2
sed -i "/#define COMPILE_MYSQL_VORON 0/c\#define COMPILE_MYSQL_VORON 1" config.hpp
if [ -d "./vendors/lib" ]; then
mysql_link="-lmysqlclient -L./vendors/lib"
export LD_LIBRARY_PATH_32="./vendors/lib"
else
mysql_link="-lmysqlclient -L/usr/lib/mysql"
fi
else
mysql_link="-lmysqlclient -L/usr/lib/mysql"
mysql_link=""
mysql_variant=0
fi
fi

Expand Down Expand Up @@ -83,14 +113,14 @@ if [ `perl -ne 'print if s/^#define\sCOMPILE_MEMORY\s(\d)$/\1/' config.hpp` == "
$cc $options $constants -c gsc_memory.cpp -o objects_$1/gsc_memory.opp
fi

if [ `perl -ne 'print if s/^#define\sCOMPILE_MYSQL\s(\d)$/\1/' config.hpp` == "1" ]; then
if [ `perl -ne 'print if s/^#define\sCOMPILE_MYSQL_DEFAULT\s(\d)$/\1/' config.hpp` == "1" ]; then
echo "##### COMPILE $1 GSC_MYSQL.CPP #####"
$cc $options $constants -c gsc_mysql.cpp -o objects_$1/gsc_mysql.opp
fi

if [ `perl -ne 'print if s/^#define\sCOMPILE_ASYNC_MYSQL\s(\d)$/\1/' config.hpp` == "1" ]; then
echo "##### COMPILE $1 GSC_ASYNC_MYSQL.CPP #####"
$cc $options $constants -c gsc_async_mysql.cpp -o objects_$1/gsc_async_mysql.opp
if [ `perl -ne 'print if s/^#define\sCOMPILE_MYSQL_VORON\s(\d)$/\1/' config.hpp` == "1" ]; then
echo "##### COMPILE $1 GSC_MYSQL_VORON.CPP #####"
$cc $options $constants -c gsc_mysql_voron.cpp -o objects_$1/gsc_mysql_voron.opp
fi

if [ `perl -ne 'print if s/^#define\sCOMPILE_PLAYER\s(\d)$/\1/' config.hpp` == "1" ]; then
Expand Down Expand Up @@ -125,3 +155,12 @@ $cc $options $constants -c libcod.cpp -o objects_$1/libcod.opp
echo "##### LINKING lib$1.so #####"
objects="$(ls objects_$1/*.opp)"
$cc -m32 -shared -L/lib32 -o bin/lib$1.so -ldl $objects -lpthread $mysql_link
rm objects_$1 -r

if [ mysql_variant > 0 ]; then
sed -i "/#define COMPILE_MYSQL_DEFAULT 1/c\#define COMPILE_MYSQL_DEFAULT 0" config.hpp
sed -i "/#define COMPILE_MYSQL_VORON 1/c\#define COMPILE_MYSQL_VORON 0" config.hpp
fi

# Read leftover
rm 0
72 changes: 72 additions & 0 deletions functions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -871,4 +871,76 @@ static const Sys_GetValue_t Sys_GetValue = (Sys_GetValue_t)0x080D6A7C;
static const Sys_GetValue_t Sys_GetValue = (Sys_GetValue_t)0x080D6BC0;
#endif

typedef void (*Scr_AddInt_t)(int value);
#if COD_VERSION == COD2_1_0
static const Scr_AddInt_t Scr_AddInt = (Scr_AddInt_t)0x08084B1C;
#elif COD_VERSION == COD2_1_2
static const Scr_AddInt_t Scr_AddInt = (Scr_AddInt_t)0x08085098;
#elif COD_VERSION == COD2_1_3
static const Scr_AddInt_t Scr_AddInt = (Scr_AddInt_t)0x08085164;
#endif

typedef void (*Scr_AddFloat_t)(float);
#if COD_VERSION == COD2_1_0
static const Scr_AddFloat_t Scr_AddFloat = (Scr_AddFloat_t)0x08084B40;
#elif COD_VERSION == COD2_1_2
static const Scr_AddFloat_t Scr_AddFloat = (Scr_AddFloat_t)0x080850BC;
#elif COD_VERSION == COD2_1_3
static const Scr_AddFloat_t Scr_AddFloat = (Scr_AddFloat_t)0x08085188;
#endif

typedef void (*Scr_AddString_t)(const char *string);
#if COD_VERSION == COD2_1_0
static const Scr_AddString_t Scr_AddString = (Scr_AddString_t)0x08084C1A;
#elif COD_VERSION == COD2_1_2
static const Scr_AddString_t Scr_AddString = (Scr_AddString_t)0x08085196;
#elif COD_VERSION == COD2_1_3
static const Scr_AddString_t Scr_AddString = (Scr_AddString_t)0x08085262;
#endif

typedef void (*Scr_AddUndefined_t)(void);
#if COD_VERSION == COD2_1_0
static const Scr_AddUndefined_t Scr_AddUndefined = (Scr_AddUndefined_t)0x08084B88;
#elif COD_VERSION == COD2_1_2
static const Scr_AddUndefined_t Scr_AddUndefined = (Scr_AddUndefined_t)0x08085104;
#elif COD_VERSION == COD2_1_3
static const Scr_AddUndefined_t Scr_AddUndefined = (Scr_AddUndefined_t)0x080851D0;
#endif

typedef void (*Scr_AddVector_t)(vec3_t vec);
#if COD_VERSION == COD2_1_0
static const Scr_AddVector_t Scr_AddVector = (Scr_AddVector_t)0x08084CBE;
#elif COD_VERSION == COD2_1_2
static const Scr_AddVector_t Scr_AddVector = (Scr_AddVector_t)0x0808523A;
#elif COD_VERSION == COD2_1_3
static const Scr_AddVector_t Scr_AddVector = (Scr_AddVector_t)0x08085306;
#endif

typedef void (*Scr_AddEntity_t)(int entity);
#if COD_VERSION == COD2_1_0
static const Scr_AddEntity_t Scr_AddEntity = (Scr_AddEntity_t)0x08118CC0;
#elif COD_VERSION == COD2_1_2
static const Scr_AddEntity_t Scr_AddEntity = (Scr_AddEntity_t)0x0811AFF4;
#elif COD_VERSION == COD2_1_3
static const Scr_AddEntity_t Scr_AddEntity = (Scr_AddEntity_t)0x08117F50;
#endif

typedef void (*Scr_MakeArray_t)(void);
#if COD_VERSION == COD2_1_0
static const Scr_MakeArray_t Scr_MakeArray = (Scr_MakeArray_t)0x08084CF0;
#elif COD_VERSION == COD2_1_2
static const Scr_MakeArray_t Scr_MakeArray = (Scr_MakeArray_t)0x0808526C;
#elif COD_VERSION == COD2_1_3
static const Scr_MakeArray_t Scr_MakeArray = (Scr_MakeArray_t)0x08085338;
#endif

typedef void (*Scr_AddArray_t)(void);
#if COD_VERSION == COD2_1_0
static const Scr_AddArray_t Scr_AddArray = (Scr_AddArray_t)0x08084D1C;
#elif COD_VERSION == COD2_1_2
static const Scr_AddArray_t Scr_AddArray = (Scr_AddArray_t)0x08085298;
#elif COD_VERSION == COD2_1_3
static const Scr_AddArray_t Scr_AddArray = (Scr_AddArray_t)0x08085364;
#endif

#endif
150 changes: 26 additions & 124 deletions gsc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,9 @@ char *stackGetParamTypeAsString(int param)

scr_function_t scriptFunctions[] =
{
#if COMPILE_MYSQL == 1
{"mysql_initialize", gsc_mysql_initialize, 0},
#if COMPILE_MYSQL_DEFAULT == 1
{"mysql_init", gsc_mysql_init, 0},
{"mysql_real_connect", gsc_mysql_real_connect, 0},
{"mysql_close", gsc_mysql_close, 0},
{"mysql_query", gsc_mysql_query, 0},
{"mysql_errno", gsc_mysql_errno, 0},
Expand All @@ -133,9 +134,30 @@ scr_function_t scriptFunctions[] =
{"mysql_fetch_row", gsc_mysql_fetch_row, 0},
{"mysql_free_result", gsc_mysql_free_result, 0},
{"mysql_real_escape_string", gsc_mysql_real_escape_string, 0},
{"mysql_async_create_query", gsc_mysql_async_create_query, 0},
{"mysql_async_create_query_nosave", gsc_mysql_async_create_query_nosave, 0},
{"mysql_async_getdone_list", gsc_mysql_async_getdone_list, 0},
{"mysql_async_getresult_and_free", gsc_mysql_async_getresult_and_free, 0},
{"mysql_async_initializer", gsc_mysql_async_initializer, 0},
{"mysql_reuse_connection", gsc_mysql_reuse_connection, 0},
#endif

#if COMPILE_ASYNC_MYSQL == 1
#if COMPILE_MYSQL_VORON == 1
{"mysql_initialize", gsc_mysql_initialize, 0},
{"mysql_close", gsc_mysql_close, 0},
{"mysql_query", gsc_mysql_query, 0},
{"mysql_errno", gsc_mysql_errno, 0},
{"mysql_error", gsc_mysql_error, 0},
{"mysql_affected_rows", gsc_mysql_affected_rows, 0},
{"mysql_store_result", gsc_mysql_store_result, 0},
{"mysql_num_rows", gsc_mysql_num_rows, 0},
{"mysql_num_fields", gsc_mysql_num_fields, 0},
{"mysql_field_seek", gsc_mysql_field_seek, 0},
{"mysql_fetch_field", gsc_mysql_fetch_field, 0},
{"mysql_fetch_row", gsc_mysql_fetch_row, 0},
{"mysql_free_result", gsc_mysql_free_result, 0},
{"mysql_real_escape_string", gsc_mysql_real_escape_string, 0},

{"async_mysql_initialize", gsc_async_mysql_initialize, 0},
{"async_mysql_close", gsc_async_mysql_close, 0},
{"async_mysql_create_query", gsc_async_mysql_create_query, 0},
Expand Down Expand Up @@ -327,7 +349,7 @@ scr_method_t scriptMethods[] =
{"switchtoweaponid", gsc_bots_switchtoweaponid, 0},
#endif

#if COMPILE_ASYNC_MYSQL == 1
#if COMPILE_MYSQL_VORON == 1
{"async_mysql_create_entity_query", gsc_async_mysql_create_entity_query, 0},
{"async_mysql_create_entity_query_nosave", gsc_async_mysql_create_entity_query_nosave, 0},
#endif
Expand Down Expand Up @@ -534,123 +556,3 @@ int stackGetParamFloat(int param, float *value)
return 1;
}

int stackPushUndefined()
{
int (*signature)();

#if COD_VERSION == COD2_1_0
*((int *)(&signature)) = 0x08084B88;
#elif COD_VERSION == COD2_1_2
*((int *)(&signature)) = 0x08085104;
#elif COD_VERSION == COD2_1_3
*((int *)(&signature)) = 0x080851D0;
#endif

return signature();
}

int stackPushInt(int ret) // as in isalive
{
int (*signature)(int);

#if COD_VERSION == COD2_1_0
*((int *)(&signature)) = 0x08084B1C;
#elif COD_VERSION == COD2_1_2
*((int *)(&signature)) = 0x08085098; // difference to 1.3: CC
#elif COD_VERSION == COD2_1_3
*((int *)(&signature)) = 0x08085164;
#endif

return signature(ret);
}

int stackPushVector(float *ret) // as in vectornormalize
{
int (*signature)(float *);

#if COD_VERSION == COD2_1_0
*((int *)(&signature)) = 0x08084CBE;
#elif COD_VERSION == COD2_1_2
*((int *)(&signature)) = 0x0808523A; // difference to 1.3: CC
#elif COD_VERSION == COD2_1_3
*((int *)(&signature)) = 0x08085306;
#endif

return signature(ret);
}

int stackPushFloat(float ret) // as in distance
{
int (*signature)(float);

#if COD_VERSION == COD2_1_0
*((int *)(&signature)) = 0x08084B40;
#elif COD_VERSION == COD2_1_2
*((int *)(&signature)) = 0x080850BC; // difference to 1.3: CC
#elif COD_VERSION == COD2_1_3
*((int *)(&signature)) = 0x08085188;
#endif

return signature(ret);
}

int stackPushString(char *toPush) // as in getcvar()
{
int (*signature)(char *);

#if COD_VERSION == COD2_1_0
*((int *)(&signature)) = 0x08084C1A;
#elif COD_VERSION == COD2_1_2
*((int *)(&signature)) = 0x08085196; // difference to 1.3: CC
#elif COD_VERSION == COD2_1_3
*((int *)(&signature)) = 0x08085262;
#endif

return signature(toPush);
}

int stackPushEntity(int arg) // as in getent() // todo: find out how to represent an entity
{
int (*signature)(int);

#if COD_VERSION == COD2_1_0
*((int *)(&signature)) = 0x08118CC0;
#elif COD_VERSION == COD2_1_2
*((int *)(&signature)) = 0x0811AFF4; // difference OTHER then CC
#elif COD_VERSION == COD2_1_3
*((int *)(&signature)) = 0x08117F50;
#endif

return signature(arg);
}

// as in bullettrace
int stackPushArray()
{
int (*signature)();

#if COD_VERSION == COD2_1_0
*((int *)(&signature)) = 0x08084CF0;
#elif COD_VERSION == COD2_1_2
*((int *)(&signature)) = 0x0808526C;
#elif COD_VERSION == COD2_1_3
*((int *)(&signature)) = 0x08085338;
#endif

return signature();
}

int stackPushArrayLast() // as in getentarray
{
int (*signature)();

#if COD_VERSION == COD2_1_0
*((int *)(&signature)) = 0x08084D1C;
#elif COD_VERSION == COD2_1_2
*((int *)(&signature)) = 0x08085298;
#elif COD_VERSION == COD2_1_3
*((int *)(&signature)) = 0x08085364;
#endif

return signature();
}
Loading

0 comments on commit 7a82dd5

Please sign in to comment.