示例#1
0
void gsc_exec()
{
	char *command;

	if (!stackGetParamString(0, &command))
	{
		stackError("gsc_exec() argument is undefined or has wrong type");
		stackPushUndefined();
		return;
	}

	Com_DPrintf("gsc_exec() executing: %s\n", command);

	FILE *fp;

	fp = popen(command, "r");

	if (fp == NULL)
	{
		stackPushUndefined();
		return;
	}

	char c;
	int curpos = 0;
	char content[COD2_MAX_STRINGLENGTH];

	stackPushArray();

	while ((c = getc(fp)) != EOF)
	{
		if (c == '\n' || curpos == COD2_MAX_STRINGLENGTH - 1)
		{
			content[curpos] = '\0';
			stackPushString(content);
			stackPushArrayLast();
			curpos = 0;
		}
		else
		{
			content[curpos] = c;
			curpos++;
		}
	}

	content[curpos] = '\0';

	stackPushString(content);
	stackPushArrayLast();

	pclose(fp);
}
示例#2
0
void gsc_player_getip(int id) {
	#if COD_VERSION == COD2_1_0
		int info_ip_offset = 0x6E5C8;
	#elif COD_VERSION == COD2_1_2
		int info_ip_offset = 0x6E6D8;	
	#elif COD_VERSION == COD2_1_3
		int info_ip_offset = 0x6E6D8;	
	#elif COD_VERSION == COD4_1_7 || COD_VERSION == COD4_1_7_L
		int info_ip_offset = 0x9;	
	#else
		#warning gsc_player_getip() got no working addresses
		int info_ip_offset = 0x0;
	#endif
	
	char tmp[64];
	unsigned int ip_a, ip_b, ip_c, ip_d;
	
	#if COD_VERSION == COD4_1_7 || COD_VERSION == COD4_1_7_L
	char iphex[9];
	snprintf(iphex, 9, "%08x", ((int *)PLAYERBASE(id))[info_ip_offset]);
	sscanf(iphex, "%2x%2x%2x%2x", &ip_d, &ip_c, &ip_b, &ip_a);
	#else	
	int info_player = PLAYERBASE(id);
	ip_a = *(unsigned char *)(info_player + info_ip_offset + 0);
	ip_b = *(unsigned char *)(info_player + info_ip_offset + 1); // dafuq, its +1 but in IDA its +4 step :S
	ip_c = *(unsigned char *)(info_player + info_ip_offset + 2);
	ip_d = *(unsigned char *)(info_player + info_ip_offset + 3);
	//int port = *(unsigned char *)(info_player + info_ip_offset + 16);
	//snprintf(tmp, 64, "%d.%d.%d.%d:%d", ip_a, ip_b, ip_c, ip_d, port);
	#endif
	snprintf(tmp, 64, "%d.%d.%d.%d", ip_a, ip_b, ip_c, ip_d);
	
	stackPushString(tmp);
}
示例#3
0
int gsc_mysql_real_escape_string()
{
	int mysql;
	char *str;
	
	int helper = 0;
	helper += stackGetParamInt(1, &mysql);
	helper += stackGetParamString(2, &str);
	
	#if DEBUG_MYSQL
	printf_hide("gsc_mysql_real_escape_string(%d, \"%s\")\n", mysql, str);
	#endif
	
	if (helper != 2)
	{
		printf_hide("scriptengine> wrongs args for mysql_real_escape_string(...);\n");
		return stackPushUndefined();
	}
	
	char *to = (char *) malloc(strlen(str) * 2 + 1);
	int ret = mysql_real_escape_string((MYSQL *)mysql, to, str, strlen(str));	
	int retString = stackPushString(to);
	free(to);
	return retString;
}
示例#4
0
void gsc_player_stance_get(int id) {
	int entity = gentities + id * gentities_size;
	unsigned char *stance_address = (unsigned char *)(entity + 8);
	int code = *stance_address & 0x0F; // just the last 4 bits tell the state

	char *stance = "";
	switch (code) {
		case  0: stance = "stand"; break; // also in spec
		case  2: stance = "stand"; break;
		case  4: stance = "duck"; break;
		case  6: stance = "duck"; break;
		case  8: stance = "lie"; break;
		case 10: stance = "lie"; break;
		default: printf("unknown stance for player id=%d, code=%d\n", id, code);
	}

	stackPushString(stance);
}
示例#5
0
int gsc_mysql_fetch_row()
{
	int result;
	
	int helper = 0;
	helper += stackGetParamInt(1, &result);
	
	#if DEBUG_MYSQL
	printf_hide("gsc_mysql_fetch_row(result=%d)\n", result);
	#endif
	
	if (helper != 1)
	{
		printf_hide("scriptengine> wrongs args for mysql_fetch_row(result);\n");
		return stackPushUndefined();
	}

	MYSQL_ROW row = mysql_fetch_row((MYSQL_RES *)result);
	if (!row)
	{
		#if DEBUG_MYSQL
		printf_hide("row == NULL\n");
		#endif
		return stackPushUndefined();
	}

	int ret = alloc_object_and_push_to_array();
	
	int numfields = mysql_num_fields((MYSQL_RES *)result);
	for (int i=0; i<numfields; i++)
	{
		if (row[i] == NULL)
			stackPushUndefined();
		else
			stackPushString(row[i]);
		
		#if DEBUG_MYSQL
		printf_hide("row == \"%s\"\n", row[i]);
		#endif
		push_previous_var_in_array_sub();
	}

	return ret;
}
示例#6
0
void gsc_get_userinfo(int id)
{
	char* key;
	char* val;
	if(!stackGetParamString(0, &key))
	{
		printf("First param needs to be a string for get_userinfo\n");
		stackPushUndefined();
		return;
	}
	
	int entity = PLAYERBASE(id);
	val = Info_ValueForKey((char*)entity+12, key);
	
	if(strlen(val))
		stackPushString(val);
	else
		stackPushUndefined();
}
示例#7
0
int gsc_mysql_error()
{
	int mysql;
	
	int helper = 0;
	helper += stackGetParamInt(1, &mysql);
	
	#if DEBUG_MYSQL
	printf_hide("gsc_mysql_error(%d)\n", mysql);
	#endif
	
	if (helper != 1)
	{
		printf_hide("scriptengine> wrongs args for mysql_close(mysql);\n");
		return stackPushUndefined();
	}
	
	char *ret = (char *)mysql_error((MYSQL *)mysql);
	return stackPushString(ret);
}
示例#8
0
int gsc_mysql_fetch_field()
{
	int result;
	
	int helper = 0;
	helper += stackGetParamInt(1, &result);
	
	#if DEBUG_MYSQL
	printf_hide("gsc_mysql_fetch_field(result=%d)\n", result);
	#endif
	
	if (helper != 1)
	{
		printf_hide("scriptengine> wrongs args for mysql_fetch_field(result);\n");
		return stackPushUndefined();
	}

	MYSQL_FIELD *field = mysql_fetch_field((MYSQL_RES *)result);
	if (field == NULL)
		return stackPushUndefined();
	char *ret = field->name;
	return stackPushString(ret);
}
示例#9
0
void gsc_player_getip(int id) {
    #if COD_VERSION == COD2_1_0 || COD_VERSION == COD2_1_0_1
        int info_ip_offset = 0x6E5C8;
	#elif COD_VERSION == COD2_1_3
		int info_ip_offset = 0x6E6D8;
	#else
		#warning gsc_player_getip() got no working addresses
		int info_ip_offset = 0x0;
	#endif

	int info_player = PLAYERBASE(id);

	int ip_a = *(unsigned char *)(info_player + info_ip_offset + 0);
	int ip_b = *(unsigned char *)(info_player + info_ip_offset + 1); // dafuq, its +1 but in IDA its +4 step :S
	int ip_c = *(unsigned char *)(info_player + info_ip_offset + 2);
	int ip_d = *(unsigned char *)(info_player + info_ip_offset + 3);
	//int port = *(unsigned char *)(info_player + info_ip_offset + 16);

	char tmp[64];
	snprintf(tmp, 64, "%d.%d.%d.%d", ip_a, ip_b, ip_c, ip_d);
	//snprintf(tmp, 64, "%d.%d.%d.%d:%d", ip_a, ip_b, ip_c, ip_d, port);

	stackPushString(tmp);
}
示例#10
0
void gsc_exec_async_checkdone()
{
	exec_async_task *current = first_exec_async_task;

	while (current != NULL)
	{
		exec_async_task *task = current;
		current = current->next;

		if (task->done)
		{
			//push to cod
			if (Scr_IsSystemActive() && task->save && task->callback && !task->error && (scrVarPub.levelId == task->levelId))
			{
				if (task->hasargument)
				{
					switch(task->valueType)
					{
					case INT_VALUE:
						stackPushInt(task->intValue);
						break;

					case FLOAT_VALUE:
						stackPushFloat(task->floatValue);
						break;

					case STRING_VALUE:
						stackPushString(task->stringValue);
						break;

					case VECTOR_VALUE:
						stackPushVector(task->vectorValue);
						break;

					case OBJECT_VALUE:
						stackPushObject(task->objectValue);
						break;

					default:
						stackPushUndefined();
						break;
					}
				}

				stackPushArray();
				exec_outputline *output = task->output;

				while (output != NULL)
				{
					exec_outputline *next = output->next;
					stackPushString(output->content);
					stackPushArrayLast();
					delete output;
					output = next;
				}

				short ret = Scr_ExecThread(task->callback, task->save + task->hasargument);
				Scr_FreeThread(ret);
			}

			//free task
			if (task->next != NULL)
				task->next->prev = task->prev;

			if (task->prev != NULL)
				task->prev->next = task->next;
			else
				first_exec_async_task = task->next;

			delete task;
		}
	}
}