Skip to content

Commit

Permalink
Implement #190
Browse files Browse the repository at this point in the history
  • Loading branch information
T-Maxxx committed Sep 29, 2017
1 parent f26f7e0 commit 00f6463
Show file tree
Hide file tree
Showing 6 changed files with 182 additions and 4 deletions.
12 changes: 12 additions & 0 deletions src/bg.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include "bg.h"

void BG_AddPredictableEventToPlayerstate(const BGEvent EventNum_, const byte EventParam_, gclient_t* Client_)
{
if (EventNum_)
{
const int eventIdx = Client_->ps.eventSequence & 3;
Client_->ps.events[eventIdx] = EventNum_;
Client_->ps.eventParms[eventIdx] = EventParam_;
++Client_->ps.eventSequence;
}
}
144 changes: 144 additions & 0 deletions src/bg.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
#pragma once
#include "player.h"

typedef enum BGEvent
{
EV_NONE = 0,
EV_FOLIAGE_SOUND,
EV_STOP_WEAPON_SOUND,
EV_SOUND_ALIAS,
EV_SOUND_ALIAS_AS_MASTER,
EV_STOPSOUNDS,
EV_STANCE_FORCE_STAND,
EV_STANCE_FORCE_CROUCH,
EV_STANCE_FORCE_PRONE,
EV_ITEM_PICKUP,
EV_AMMO_PICKUP,
EV_NOAMMO,
EV_EMPTYCLIP,
EV_EMPTY_OFFHAND,
EV_RESET_ADS,
EV_RELOAD,
EV_RELOAD_FROM_EMPTY,
EV_RELOAD_START,
EV_RELOAD_END,
EV_RELOAD_START_NOTIFY,
EV_RELOAD_ADDAMMO,
EV_RAISE_WEAPON,
EV_FIRST_RAISE_WEAPON,
EV_PUTAWAY_WEAPON,
EV_WEAPON_ALT,
EV_PULLBACK_WEAPON,
EV_FIRE_WEAPON,
EV_FIRE_WEAPON_LASTSHOT,
EV_RECHAMBER_WEAPON,
EV_EJECT_BRASS,
EV_MELEE_SWIPE,
EV_FIRE_MELEE,
EV_PREP_OFFHAND,
EV_USE_OFFHAND,
EV_SWITCH_OFFHAND,
EV_MELEE_HIT,
EV_MELEE_MISS,
EV_MELEE_BLOOD,
EV_FIRE_WEAPON_MG42,
EV_FIRE_QUADBARREL_1,
EV_FIRE_QUADBARREL_2,
EV_BULLET_HIT,
EV_BULLET_HIT_CLIENT_SMALL,
EV_BULLET_HIT_CLIENT_LARGE,
EV_GRENADE_BOUNCE,
EV_GRENADE_EXPLODE,
EV_ROCKET_EXPLODE,
EV_ROCKET_EXPLODE_NOMARKS,
EV_FLASHBANG_EXPLODE,
EV_CUSTOM_EXPLODE,
EV_CUSTOM_EXPLODE_NOMARKS,
EV_CHANGE_TO_DUD,
EV_DUD_EXPLODE,
EV_DUD_IMPACT,
EV_BULLET,
EV_PLAY_FX,
EV_PLAY_FX_ON_TAG,
EV_PHYS_EXPLOSION_SPHERE,
EV_PHYS_EXPLOSION_CYLINDER,
EV_PHYS_EXPLOSION_JOLT,
EV_PHYS_JITTER,
EV_EARTHQUAKE,
EV_GRENADE_SUICIDE,
EV_DETONATE,
EV_NIGHTVISION_WEAR,
EV_NIGHTVISION_REMOVE,
EV_OBITUARY,
EV_NO_FRAG_GRENADE_HINT,
EV_NO_SPECIAL_GRENADE_HINT,
EV_TARGET_TOO_CLOSE_HINT,
EV_TARGET_NOT_ENOUGH_CLEARANCE,
EV_LOCKON_REQUIRED_HINT,
EV_FOOTSTEP_SPRINT,
EV_FOOTSTEP_RUN,
EV_FOOTSTEP_WALK,
EV_FOOTSTEP_PRONE,
EV_JUMP,
EV_LANDING_DEFAULT,
EV_LANDING_BARK,
EV_LANDING_BRICK,
EV_LANDING_CARPET,
EV_LANDING_CLOTH,
EV_LANDING_CONCRETE,
EV_LANDING_DIRT,
EV_LANDING_FLESH,
EV_LANDING_FOLIAGE,
EV_LANDING_GLASS,
EV_LANDING_GRASS,
EV_LANDING_GRAVEL,
EV_LANDING_ICE,
EV_LANDING_METAL,
EV_LANDING_MUD,
EV_LANDING_PAPER,
EV_LANDING_PLASTER,
EV_LANDING_ROCK,
EV_LANDING_SAND,
EV_LANDING_SNOW,
EV_LANDING_WATER,
EV_LANDING_WOOD,
EV_LANDING_ASPHALT,
EV_LANDING_CERAMIC,
EV_LANDING_PLASTIC,
EV_LANDING_RUBBER,
EV_LANDING_CUSHION,
EV_LANDING_FRUIT,
EV_LANDING_PAINTEDMETAL,
EV_LANDING_PAIN_DEFAULT,
EV_LANDING_PAIN_BARK,
EV_LANDING_PAIN_BRICK,
EV_LANDING_PAIN_CARPET,
EV_LANDING_PAIN_CLOTH,
EV_LANDING_PAIN_CONCRETE,
EV_LANDING_PAIN_DIRT,
EV_LANDING_PAIN_FLESH,
EV_LANDING_PAIN_FOLIAGE,
EV_LANDING_PAIN_GLASS,
EV_LANDING_PAIN_GRASS,
EV_LANDING_PAIN_GRAVEL,
EV_LANDING_PAIN_ICE,
EV_LANDING_PAIN_METAL,
EV_LANDING_PAIN_MUD,
EV_LANDING_PAIN_PAPER,
EV_LANDING_PAIN_PLASTER,
EV_LANDING_PAIN_ROCK,
EV_LANDING_PAIN_SAND,
EV_LANDING_PAIN_SNOW,
EV_LANDING_PAIN_WATER,
EV_LANDING_PAIN_WOOD,
EV_LANDING_PAIN_ASPHALT,
EV_LANDING_PAIN_CERAMIC,
EV_LANDING_PAIN_PLASTIC,
EV_LANDING_PAIN_RUBBER,
EV_LANDING_PAIN_CUSHION,
EV_LANDING_PAIN_FRUIT,
EV_LANDING_PAIN_PAINTEDMETAL
}BGEvent;

// 0x08052562
void __cdecl BG_AddPredictableEventToPlayerstate(const BGEvent EventNum_, const byte EventParam_, gclient_t* Client_);
6 changes: 3 additions & 3 deletions src/player.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,10 @@ typedef struct playerState_s {
int eFlags; // 176
int eventSequence; // 180

int events[4];
unsigned int eventParms[4];
int events[4]; // 184
unsigned int eventParms[4]; // 200

int oldEventSequence;
int oldEventSequence; // 216

int clientNum; // 220
int offHandIndex; // 224
Expand Down
20 changes: 20 additions & 0 deletions src/scr_vm_functions.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#include "plugin_handler.h"
#include "scr_vm_functions.h"
#include "tomcrypt/tomcrypt_misc.h"
#include "bg.h"

static qboolean g_isLocStringPrecached[MAX_LOCALIZEDSTRINGS] = {qfalse};

Expand Down Expand Up @@ -3307,3 +3308,22 @@ void GScr_CloneBrushModelToScriptModel(scr_entref_t scriptModelEntNum)
scriptEnt->r.contents |= contents;
SV_LinkEntity(scriptEnt);
}

void PlayerCmd_SetStance(scr_entref_t playerEntNum)
{
if (Scr_GetNumParam() != 1)
Scr_Error("usage: <client> setStance(<string stance>);");

// Object check.
gclient_t* cl = VM_GetGClientForEntityNumber(playerEntNum);
if (!cl)
Scr_ObjectError("entity is not a client");

// Param check.
short stanceIdx = Scr_GetConstString(0);
if (stanceIdx != stringIndex.stand && stanceIdx != stringIndex.crouch && stanceIdx != stringIndex.prone)
Scr_ParamError(0, "stance must be one of {stand, crouch, prone}");

BGEvent event = stanceIdx == stringIndex.stand ? EV_STANCE_FORCE_STAND : stanceIdx == stringIndex.crouch ? EV_STANCE_FORCE_CROUCH : EV_STANCE_FORCE_PRONE;
BG_AddPredictableEventToPlayerstate(event, 0, cl);
}
1 change: 1 addition & 0 deletions src/scr_vm_functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,3 +123,4 @@ void GScr_IsInt();
void GScr_Float();

void GScr_CloneBrushModelToScriptModel(scr_entref_t brushModelEnt);
void PlayerCmd_SetStance(scr_entref_t playerEntNum);
3 changes: 2 additions & 1 deletion src/scr_vm_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,6 @@ void Scr_AddStockMethods()
Scr_AddMethod("showtoplayer", (void *)0x80c4252, 0);
Scr_AddMethod("setcontents", (void *)0x80c41e4, 0);
Scr_AddMethod("getstance", (void *)0x80c42d2, 0);
// Scr_AddMethod("setstance", ScrCmd_SetStance, 0);
Scr_AddMethod("setjumpheight", PlayerCmd_SetJumpHeight, 0);
Scr_AddMethod("setgravity", PlayerCmd_SetGravity, 0);
Scr_AddMethod("setgroundreferenceent", PlayerCmd_SetGroundReferenceEnt, 0);
Expand Down Expand Up @@ -649,6 +648,8 @@ void Scr_AddStockMethods()

// Clone script_brushmodel settings to script_model.
Scr_AddMethod("clonebrushmodeltoscriptmodel", GScr_CloneBrushModelToScriptModel, qfalse);
// Force player stance.
Scr_AddMethod("setstance", PlayerCmd_SetStance, qfalse);
}

void Scr_InitFunctions()
Expand Down

0 comments on commit 00f6463

Please sign in to comment.