Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
MinoMino committed Aug 14, 2017
2 parents d7620ed + 5847219 commit e032b4b
Show file tree
Hide file tree
Showing 7 changed files with 502 additions and 207 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ CC = gcc
CFLAGS += -shared -std=gnu11
LDFLAGS_NOPY += -ldl
LDFLAGS += $(shell python3.5-config --libs)
SOURCES_NOPY += dllmain.c commands.c simple_hook.c hooks.c misc.c maps_parser.c
SOURCES += dllmain.c commands.c python_embed.c python_dispatchers.c simple_hook.c hooks.c misc.c maps_parser.c
SOURCES_NOPY += dllmain.c commands.c simple_hook.c hooks.c misc.c maps_parser.c trampoline.c
SOURCES += dllmain.c commands.c python_embed.c python_dispatchers.c simple_hook.c hooks.c misc.c maps_parser.c trampoline.c
OBJS = $(SOURCES:.c=.o)
OBJS_NOPY = $(SOURCES_NOPY:.c=.o)
OUTPUT = $(BINDIR)/minqlx.so
Expand Down
10 changes: 9 additions & 1 deletion hooks.c
Original file line number Diff line number Diff line change
Expand Up @@ -313,29 +313,37 @@ void HookVm(void) {
#ifndef NOPY
*(void**)(vm_call_table + RELOFFSET_VM_CALL_RUNFRAME) = My_G_RunFrame;

int res, failed = 0;
int res, failed = 0, count = 0;
res = Hook((void*)ClientConnect, My_ClientConnect, (void*)&ClientConnect);
if (res) {
DebugPrint("ERROR: Failed to hook ClientConnect: %d\n", res);
failed = 1;
}
count++;

res = Hook((void*)G_StartKamikaze, My_G_StartKamikaze, (void*)&G_StartKamikaze);
if (res) {
DebugPrint("ERROR: Failed to hook G_StartKamikaze: %d\n", res);
failed = 1;
}
count++;

res = Hook((void*)ClientSpawn, My_ClientSpawn, (void*)&ClientSpawn);
if (res) {
DebugPrint("ERROR: Failed to hook ClientSpawn: %d\n", res);
failed = 1;
}
count++;

if (failed) {
DebugPrint("Exiting.\n");
exit(1);
}

if ( !seek_hook_slot( -count ) ) {
DebugPrint("ERROR: Failed to rewind hook slot\nExiting.\n");
exit(1);
}
#endif
}

Expand Down
53 changes: 49 additions & 4 deletions python_embed.c
Original file line number Diff line number Diff line change
Expand Up @@ -1129,9 +1129,6 @@ static PyObject* PyMinqlx_SetHoldable(PyObject* self, PyObject* args) {
* ================================================================
*/

// FixMe: holdable pickup is predicted on client (if cg_predictItems == 1)
// this generates holdable pickup sound on drop

void __cdecl Switch_Touch_Item(gentity_t *ent) {
ent->touch = (void*)Touch_Item;
ent->think = G_FreeEntity;
Expand All @@ -1145,6 +1142,8 @@ void __cdecl My_Touch_Item(gentity_t *ent, gentity_t *other, trace_t *trace) {

static PyObject* PyMinqlx_DropHoldable(PyObject* self, PyObject* args) {
int client_id, item;
vec3_t velocity;
vec_t angle;
if (!PyArg_ParseTuple(args, "i:drop_holdable", &client_id))
return NULL;
else if (client_id < 0 || client_id >= sv_maxclients->integer) {
Expand All @@ -1162,11 +1161,17 @@ static PyObject* PyMinqlx_DropHoldable(PyObject* self, PyObject* args) {
item = g_entities[client_id].client->ps.stats[STAT_HOLDABLE_ITEM];
if (item == 0) Py_RETURN_FALSE;

gentity_t* entity = Drop_Item(&g_entities[client_id], bg_itemlist + item, 0);
angle = g_entities[client_id].s.apos.trBase[1] * (M_PI*2 / 360);
velocity[0] = 150*cos(angle);
velocity[1] = 150*sin(angle);
velocity[2] = 250;

gentity_t* entity = LaunchItem(bg_itemlist + item, g_entities[client_id].s.pos.trBase, velocity);
entity->touch = (void*)My_Touch_Item;
entity->parent = &g_entities[client_id];
entity->think = Switch_Touch_Item;
entity->nextthink = level->time + 1000;
entity->s.pos.trTime = level->time - 500;

// removing holdable from player entity
g_entities[client_id].client->ps.stats[STAT_HOLDABLE_ITEM] = 0;
Expand Down Expand Up @@ -1409,6 +1414,8 @@ static PyObject* PyMinqlx_SpawnItem(PyObject* self, PyObject* args) {
gentity_t* ent = LaunchItem(bg_itemlist + item_id, origin, velocity);
ent->nextthink = 0;
ent->think = 0;
G_AddEvent(ent, EV_ITEM_RESPAWN, 0); // make item be scaled up

Py_RETURN_TRUE;
}

Expand Down Expand Up @@ -1634,6 +1641,42 @@ static PyObject* PyMinqlx_DevPrintItems(PyObject* self, PyObject* args) {
Py_RETURN_NONE;
}

/*
* ================================================================
* force_weapon_respawn_time
* ================================================================
*/

static PyObject* PyMinqlx_ForceWeaponRespawnTime(PyObject* self, PyObject* args) {
int respawn_time;
gentity_t* ent;

if (!PyArg_ParseTuple(args, "i:force_weapon_respawn_time", &respawn_time))
return NULL;

if (respawn_time < 0) {
PyErr_Format(PyExc_ValueError, "respawn time needs to be an integer 0 or greater");
return NULL;
}

for (int i=0; i<MAX_GENTITIES; i++) {
ent = &g_entities[i];

if (!ent->inuse)
continue;

if (ent->s.eType != ET_ITEM || ent->item == NULL)
continue;

if (ent->item->giType != IT_WEAPON)
continue;

ent->wait = respawn_time;
}

Py_RETURN_TRUE;
}

/*
* ================================================================
* Module definition and initialization
Expand Down Expand Up @@ -1725,6 +1768,8 @@ static PyMethodDef minqlxMethods[] = {
"Replaces target entity's item with specified one."},
{"dev_print_items", PyMinqlx_DevPrintItems, METH_NOARGS,
"Prints all items and entity numbers to server console."},
{"force_weapon_respawn_time", PyMinqlx_ForceWeaponRespawnTime, METH_VARARGS,
"Force all weapons to have a specified respawn time, overriding custom map respawn times set for them."},
{NULL, NULL, 0, NULL}
};

Expand Down
Loading

0 comments on commit e032b4b

Please sign in to comment.