Skip to content

Commit

Permalink
[MP] reconcile game module changes with the original source releases …
Browse files Browse the repository at this point in the history
…by diffing codemp/game (#1178)

* reconcile game module changes with the SDK release by diffing codemp/game

* revert saberMoveData changes to match basejka, provide a new cvar (g_fixSaberMoveData) to patch it if desired
* introduce a new configstring (26: CS_LEGACY_FIXES) to inform the client of which fixes it should also apply, e.g. saberMoveData
* client module obtains gamestate (including configstrings) earlier to prevent use before initialisation, which is now checked for in debug builds
* revert a change to saber disarm bonus calculation if g_fixSaberDisarmBonus is not enabled
* G_CanBeEnemy considers private duels once again (removed from modbase before its git history)

* add disclaimer to legacyFixes_e

* revert: client module obtains gamestate (including configstrings) earlier to prevent use before initialisation

this was causing issues loading incorrect clientinfo
  • Loading branch information
Razish committed Feb 20, 2024
1 parent 3a697c7 commit 142e0b7
Show file tree
Hide file tree
Showing 15 changed files with 266 additions and 190 deletions.
2 changes: 1 addition & 1 deletion codemp/cgame/cg_draw.c
Expand Up @@ -3064,7 +3064,7 @@ static float CG_DrawEnemyInfo ( float y )
clientNum = cgs.duelWinner;
}

if ( clientNum >= MAX_CLIENTS || !(&cgs.clientinfo[ clientNum ]) )
if ( clientNum < 0 || clientNum >= MAX_CLIENTS || !cgs.clientinfo[clientNum].infoValid )
{
return y;
}
Expand Down
5 changes: 5 additions & 0 deletions codemp/cgame/cg_main.c
Expand Up @@ -1623,6 +1623,9 @@ CG_ConfigString
=================
*/
const char *CG_ConfigString( int index ) {
// FIXME: don't read configstrings before initialisation
// assert( cgs.gameState.dataCount != 0 );

if ( index < 0 || index >= MAX_CONFIGSTRINGS ) {
trap->Error( ERR_DROP, "CG_ConfigString: bad index: %i", index );
}
Expand Down Expand Up @@ -2626,6 +2629,8 @@ Ghoul2 Insert End
cg.distanceCull = trap->R_GetDistanceCull();

CG_ParseEntitiesFromString();

BG_FixSaberMoveData();
}

//makes sure returned string is in localized format
Expand Down
5 changes: 5 additions & 0 deletions codemp/cgame/cg_servercmds.c
Expand Up @@ -27,6 +27,7 @@ along with this program; if not, see <http://www.gnu.org/licenses/>.
// be a valid snapshot this frame

#include "cg_local.h"
#include "game/bg_public.h"
#include "ui/menudef.h"
#include "ghoul2/G2.h"
#include "ui/ui_public.h"
Expand Down Expand Up @@ -909,6 +910,10 @@ static void CG_ConfigStringModified( void ) {
else if ( num == CS_SHADERSTATE ) {
CG_ShaderStateChanged();
}
else if ( num == CS_LEGACY_FIXES ) {
// LEGACYFIX_SABERMOVEDATA may have changed
BG_FixSaberMoveData();
}
else if ( num >= CS_LIGHT_STYLES && num < CS_LIGHT_STYLES + (MAX_LIGHT_STYLES * 3))
{
CG_SetLightstyle(num - CS_LIGHT_STYLES);
Expand Down
2 changes: 1 addition & 1 deletion codemp/game/NPC_AI_MineMonster.c
Expand Up @@ -90,7 +90,7 @@ void MineMonster_Patrol( void )
}

//rwwFIXMEFIXME: Care about all clients, not just client 0
//OJKFIXME: clietnum 0
//OJKFIXME: clientnum 0
VectorSubtract( g_entities[0].r.currentOrigin, NPCS.NPC->r.currentOrigin, dif );

if ( VectorLengthSquared( dif ) < 256 * 256 )
Expand Down
4 changes: 2 additions & 2 deletions codemp/game/NPC_combat.c
Expand Up @@ -1494,7 +1494,7 @@ gentity_t *NPC_PickEnemy( gentity_t *closestTo, int enemyTeam, qboolean checkVis
minVis = VIS_360;
}

//OJKFIXME: care about clients other than 0
//OJKFIXME: clientnum 0
//OJKFIXME: choice[] is not size checked?
if( findPlayersFirst )
{//try to find a player first
Expand Down Expand Up @@ -2178,7 +2178,7 @@ qboolean NPC_EvaluateShot( int hit, qboolean glassOK )
return qfalse;
}

if ( hit == NPCS.NPC->enemy->s.number || (&g_entities[hit] != NULL && (g_entities[hit].r.svFlags&SVF_GLASS_BRUSH)) )
if ( hit == NPCS.NPC->enemy->s.number || (g_entities[hit].inuse && (g_entities[hit].r.svFlags&SVF_GLASS_BRUSH)) )
{//can hit enemy or will hit glass, so shoot anyway
return qtrue;
}
Expand Down
20 changes: 0 additions & 20 deletions codemp/game/bg_g2_utils.c
Expand Up @@ -42,26 +42,14 @@ void BG_AttachToRancor( void *ghoul2, float rancYaw, vec3_t rancOrigin, int time
// Getting the bolt here
if ( inMouth )
{//in mouth
#if defined(_GAME)
boltIndex = trap->G2API_AddBolt(ghoul2, 0, "jaw_bone");
#elif defined(_CGAME)
boltIndex = trap->G2API_AddBolt(ghoul2, 0, "jaw_bone");
#endif
}
else
{//in right hand
#if defined(_GAME)
boltIndex = trap->G2API_AddBolt(ghoul2, 0, "*r_hand");
#elif defined(_CGAME)
boltIndex = trap->G2API_AddBolt(ghoul2, 0, "*r_hand");
#endif
}
VectorSet( rancAngles, 0, rancYaw, 0 );
#if defined(_GAME)
trap->G2API_GetBoltMatrix( ghoul2, 0, boltIndex, &boltMatrix, rancAngles, rancOrigin, time, modelList, modelScale );
#elif defined(_CGAME)
trap->G2API_GetBoltMatrix( ghoul2, 0, boltIndex, &boltMatrix, rancAngles, rancOrigin, time, modelList, modelScale );
#endif
// Storing ent position, bolt position, and bolt axis
if ( out_origin )
{
Expand Down Expand Up @@ -112,11 +100,7 @@ void BG_AttachToRancor( void *ghoul2, float rancYaw, vec3_t rancOrigin, int time
#define MAX_VARIANTS 8
qboolean BG_GetRootSurfNameWithVariant( void *ghoul2, const char *rootSurfName, char *returnSurfName, int returnSize )
{
#if defined(_GAME)
if ( !ghoul2 || !trap->G2API_GetSurfaceRenderStatus( ghoul2, 0, rootSurfName ) )
#elif defined(_CGAME)
if ( !ghoul2 || !trap->G2API_GetSurfaceRenderStatus( ghoul2, 0, rootSurfName ) )
#endif
{//see if the basic name without variants is on
Q_strncpyz( returnSurfName, rootSurfName, returnSize );
return qtrue;
Expand All @@ -127,11 +111,7 @@ qboolean BG_GetRootSurfNameWithVariant( void *ghoul2, const char *rootSurfName,
for ( i = 0; i < MAX_VARIANTS; i++ )
{
Com_sprintf( returnSurfName, returnSize, "%s%c", rootSurfName, 'a'+i );
#if defined(_GAME)
if ( !trap->G2API_GetSurfaceRenderStatus( ghoul2, 0, returnSurfName ) )
#elif defined(_CGAME)
if ( !trap->G2API_GetSurfaceRenderStatus( ghoul2, 0, returnSurfName ) )
#endif
{
return qtrue;
}
Expand Down
3 changes: 1 addition & 2 deletions codemp/game/bg_misc.c
Expand Up @@ -2056,8 +2056,7 @@ qboolean BG_CanItemBeGrabbed( int gametype, const entityState_t *ent, const play
{//force powers and saber only
if ( item->giType != IT_TEAM //not a flag
&& item->giType != IT_ARMOR//not shields
&& (item->giType != IT_WEAPON
|| item->giTag != WP_SABER)//not a saber
&& (item->giType != IT_WEAPON || item->giTag != WP_SABER)//not a saber
&& (item->giType != IT_HOLDABLE || item->giTag != HI_SEEKER)//not a seeker
&& (item->giType != IT_POWERUP || item->giTag == PW_YSALAMIRI) )//not a force pick-up
{
Expand Down
20 changes: 19 additions & 1 deletion codemp/game/bg_public.h
Expand Up @@ -111,7 +111,7 @@ along with this program; if not, see <http://www.gnu.org/licenses/>.
#define CS_FLAGSTATUS 23 // string indicating flag status in CTF
#define CS_SHADERSTATE 24
#define CS_BOTINFO 25

#define CS_LEGACY_FIXES 26
#define CS_ITEMS 27 // string of 0's and 1's that tell which items are present

#define CS_CLIENT_JEDIMASTER 28 // current jedi master
Expand Down Expand Up @@ -156,6 +156,22 @@ Ghoul2 Insert End
#error overflow: (CS_MAX) > MAX_CONFIGSTRINGS
#endif

typedef enum legacyFixes_e {
LEGACYFIX_SABERMOVEDATA = 0,
/*
m m ""# " m m
# # mmm m m # mmm mmm mm#mm mmm m mm #
#mmmm# #" # "m m" # # # " # #" # #" # #
# # #"""" #m# # # """m # #"""" # # "
# # "#mm" "# # "mm mm#mm "mmm" "mm "#mm" # # #
m" "
""
Forks of OpenJK should NOT add to or modify the legacy fixes values
Removal, replacement or adding of new flags might lead to incompatibilities
Forks should define their own configstring or serverinfo cvar instead of modifying this
*/
} legacyFixes_t;

typedef enum {
G2_MODELPART_HEAD = 10,
G2_MODELPART_WAIST,
Expand Down Expand Up @@ -1717,6 +1733,8 @@ qboolean BG_InDeathAnim( int anim );
qboolean BG_InSaberLockOld( int anim );
qboolean BG_InSaberLock( int anim );

void BG_FixSaberMoveData( void );

void BG_SaberStartTransAnim( int clientNum, int saberAnimLevel, int weapon, int anim, float *animSpeed, int broken );

void BG_ForcePowerDrain( playerState_t *ps, forcePowers_t forcePower, int overrideAmt );
Expand Down
57 changes: 44 additions & 13 deletions codemp/game/bg_saber.c
Expand Up @@ -26,6 +26,12 @@ along with this program; if not, see <http://www.gnu.org/licenses/>.
#include "bg_local.h"
#include "w_saber.h"

#if defined(_GAME)
#include "g_local.h" // for cvars
#elif defined(_CGAME)
#include "cgame/cg_local.h" // for configstrings
#endif

extern qboolean BG_SabersOff( playerState_t *ps );
saberInfo_t *BG_MySaber( int clientNum, int saberNum );

Expand Down Expand Up @@ -316,30 +322,23 @@ saberMoveData_t saberMoveData[LS_MOVE_MAX] = {// NB:randomized
{"BParry Top", BOTH_H1_S1_T_, Q_T, Q_B, AFLAG_ACTIVE, 50, BLK_NO, LS_READY, LS_READY, 150 }, // LS_PARRY_UP,
{"BParry UR", BOTH_H1_S1_TR, Q_TR, Q_BL, AFLAG_ACTIVE, 50, BLK_NO, LS_READY, LS_READY, 150 }, // LS_PARRY_UR,
{"BParry UL", BOTH_H1_S1_TL, Q_TL, Q_BR, AFLAG_ACTIVE, 50, BLK_NO, LS_READY, LS_READY, 150 }, // LS_PARRY_UL,
{"BParry LR", BOTH_H1_S1_BR, Q_BL, Q_TR, AFLAG_ACTIVE, 50, BLK_NO, LS_READY, LS_READY, 150 }, // LS_PARRY_LR,
{"BParry LR", BOTH_H1_S1_BL, Q_BL, Q_TR, AFLAG_ACTIVE, 50, BLK_NO, LS_READY, LS_READY, 150 }, // LS_PARRY_LR,
{"BParry Bot", BOTH_H1_S1_B_, Q_B, Q_T, AFLAG_ACTIVE, 50, BLK_NO, LS_READY, LS_READY, 150 }, // LS_PARRY_LR
{"BParry LL", BOTH_H1_S1_BL, Q_BR, Q_TL, AFLAG_ACTIVE, 50, BLK_NO, LS_READY, LS_READY, 150 }, // LS_PARRY_LL
//{"BParry LR", BOTH_H1_S1_BL, Q_BL, Q_TR, AFLAG_ACTIVE, 50, BLK_NO, LS_READY, LS_READY, 150 }, // LS_PARRY_LR,
//{"BParry Bot", BOTH_H1_S1_B_, Q_B, Q_T, AFLAG_ACTIVE, 50, BLK_NO, LS_READY, LS_READY, 150 }, // LS_PARRY_LL
//{"BParry LL", BOTH_H1_S1_BR, Q_BR, Q_TL, AFLAG_ACTIVE, 50, BLK_NO, LS_READY, LS_READY, 150 }, // LS_PARRY_LL
{"BParry LL", BOTH_H1_S1_BR, Q_BR, Q_TL, AFLAG_ACTIVE, 50, BLK_NO, LS_READY, LS_READY, 150 }, // LS_PARRY_LL

// Knockaways
{"Knock Top", BOTH_K1_S1_T_, Q_R, Q_T, AFLAG_ACTIVE, 50, BLK_WIDE, LS_R_BL2TR, LS_T1_T__BR, 150 }, // LS_PARRY_UP,
{"Knock UR", BOTH_K1_S1_TR, Q_R, Q_TR, AFLAG_ACTIVE, 50, BLK_WIDE, LS_R_BL2TR, LS_T1_TR__R, 150 }, // LS_PARRY_UR,
{"Knock UL", BOTH_K1_S1_TL, Q_R, Q_TL, AFLAG_ACTIVE, 50, BLK_WIDE, LS_R_BR2TL, LS_T1_TL__L, 150 }, // LS_PARRY_UL,
{"Knock LR", BOTH_K1_S1_BR, Q_R, Q_BL, AFLAG_ACTIVE, 50, BLK_WIDE, LS_R_TL2BR, LS_T1_BL_TL, 150 }, // LS_PARRY_LR,
{"Knock LL", BOTH_K1_S1_BL, Q_R, Q_BR, AFLAG_ACTIVE, 50, BLK_WIDE, LS_R_TR2BL, LS_T1_BR_TR, 150 }, // LS_PARRY_LL
//{"Knock LR", BOTH_K1_S1_BL, Q_R, Q_BL, AFLAG_ACTIVE, 50, BLK_WIDE, LS_R_TL2BR, LS_T1_BL_TL, 150 }, // LS_PARRY_LR,
//{"Knock LL", BOTH_K1_S1_BR, Q_R, Q_BR, AFLAG_ACTIVE, 50, BLK_WIDE, LS_R_TR2BL, LS_T1_BR_TR, 150 }, // LS_PARRY_LL
{"Knock LR", BOTH_K1_S1_BL, Q_R, Q_BL, AFLAG_ACTIVE, 50, BLK_WIDE, LS_R_TL2BR, LS_T1_BL_TL, 150 }, // LS_PARRY_LR,
{"Knock LL", BOTH_K1_S1_BR, Q_R, Q_BR, AFLAG_ACTIVE, 50, BLK_WIDE, LS_R_TR2BL, LS_T1_BR_TR, 150 }, // LS_PARRY_LL

// Parry
{"Parry Top", BOTH_P1_S1_T_, Q_R, Q_T, AFLAG_ACTIVE, 50, BLK_WIDE, LS_R_BL2TR, LS_A_T2B, 150 }, // LS_PARRY_UP,
{"Parry UR", BOTH_P1_S1_TR, Q_R, Q_TL, AFLAG_ACTIVE, 50, BLK_WIDE, LS_R_BL2TR, LS_A_TR2BL, 150 }, // LS_PARRY_UR,
{"Parry UL", BOTH_P1_S1_TL, Q_R, Q_TR, AFLAG_ACTIVE, 50, BLK_WIDE, LS_R_BR2TL, LS_A_TL2BR, 150 }, // LS_PARRY_UL,
{"Parry LR", BOTH_P1_S1_BR, Q_R, Q_BR, AFLAG_ACTIVE, 50, BLK_WIDE, LS_R_TL2BR, LS_A_BR2TL, 150 }, // LS_PARRY_LR,
{"Parry LL", BOTH_P1_S1_BL, Q_R, Q_BL, AFLAG_ACTIVE, 50, BLK_WIDE, LS_R_TR2BL, LS_A_BL2TR, 150 }, // LS_PARRY_LL
//{"Parry LR", BOTH_P1_S1_BL, Q_R, Q_BR, AFLAG_ACTIVE, 50, BLK_WIDE, LS_R_TL2BR, LS_A_BR2TL, 150 }, // LS_PARRY_LR,
//{"Parry LL", BOTH_P1_S1_BR, Q_R, Q_BL, AFLAG_ACTIVE, 50, BLK_WIDE, LS_R_TR2BL, LS_A_BL2TR, 150 }, // LS_PARRY_LL
{"Parry LR", BOTH_P1_S1_BL, Q_R, Q_BR, AFLAG_ACTIVE, 50, BLK_WIDE, LS_R_TL2BR, LS_A_BR2TL, 150 }, // LS_PARRY_LR,
{"Parry LL", BOTH_P1_S1_BR, Q_R, Q_BL, AFLAG_ACTIVE, 50, BLK_WIDE, LS_R_TR2BL, LS_A_BL2TR, 150 }, // LS_PARRY_LL

// Reflecting a missile
{"Reflect Top", BOTH_P1_S1_T_, Q_R, Q_T, AFLAG_ACTIVE, 50, BLK_WIDE, LS_R_BL2TR, LS_A_T2B, 300 }, // LS_PARRY_UP,
Expand All @@ -349,6 +348,38 @@ saberMoveData_t saberMoveData[LS_MOVE_MAX] = {// NB:randomized
{"Reflect LL", BOTH_P1_S1_BL, Q_R, Q_BR, AFLAG_ACTIVE, 50, BLK_WIDE, LS_R_TL2BR, LS_A_BR2TL, 300 }, // LS_PARRY_LL,
};

void BG_FixSaberMoveData(void) {
#if defined(_GAME)
const qboolean doFix = !!g_fixSaberMoveData.integer;
#elif defined(_CGAME)
const char *cs = CG_ConfigString(CS_LEGACY_FIXES);
const uint32_t legacyFixes = strtoul(cs, NULL, 0);
const qboolean doFix = !!(legacyFixes & (1 << LEGACYFIX_SABERMOVEDATA));
#endif
saberMoveData_t *move;

for (move = saberMoveData; move - saberMoveData < ARRAY_LEN(saberMoveData); move++) {
if (!strcmp(move->name, "BParry LR")) {
move->animToUse = doFix ? BOTH_H1_S1_BR : BOTH_H1_S1_BL;
}
else if (!strcmp(move->name, "BParry LL")) {
move->animToUse = doFix ? BOTH_H1_S1_BL : BOTH_H1_S1_BR;
}
else if (!strcmp(move->name, "Knock LR")) {
move->animToUse = doFix ? BOTH_K1_S1_BR : BOTH_K1_S1_BL;
}
else if (!strcmp(move->name, "Knock LL")) {
move->animToUse = doFix ? BOTH_K1_S1_BL : BOTH_K1_S1_BR;
}
else if (!strcmp(move->name, "Parry LR")) {
move->animToUse = doFix ? BOTH_P1_S1_BR : BOTH_P1_S1_BL;
}
else if (!strcmp(move->name, "Parry LL")) {
move->animToUse = doFix ? BOTH_P1_S1_BL : BOTH_P1_S1_BR;
}
}
}

int transitionMove[Q_NUM_QUADS][Q_NUM_QUADS] =
{
{ LS_NONE, LS_T1_BR__R, LS_T1_BR_TR, LS_T1_BR_T_, LS_T1_BR_TL, LS_T1_BR__L, LS_T1_BR_BL, LS_NONE },
Expand Down
3 changes: 3 additions & 0 deletions codemp/game/g_bot.c
Expand Up @@ -139,6 +139,9 @@ int G_GetMapTypeBits(char *type)
typeBits |= (1 << GT_TEAM);
typeBits |= (1 << GT_JEDIMASTER);
}
if( strstr( type, "team" ) ) {
typeBits |= (1 << GT_TEAM);
}
if( strstr( type, "holocron" ) ) {
typeBits |= (1 << GT_HOLOCRON);
}
Expand Down
6 changes: 6 additions & 0 deletions codemp/game/g_cmds.c
Expand Up @@ -2358,6 +2358,12 @@ void Cmd_CallTeamVote_f( gentity_t *ent ) {
char arg1[MAX_CVAR_VALUE_STRING] = {0};
char arg2[MAX_CVAR_VALUE_STRING] = {0};

if ( g_gametype.integer < GT_TEAM )
{
trap->SendServerCommand( ent-g_entities, "print \"Cannot call a team vote in a non-team gametype!\n\"" );
return;
}

if ( team == TEAM_RED )
cs_offset = 0;
else if ( team == TEAM_BLUE )
Expand Down
21 changes: 16 additions & 5 deletions codemp/game/g_cvar.c
Expand Up @@ -21,18 +21,29 @@ along with this program; if not, see <http://www.gnu.org/licenses/>.
===========================================================================
*/

#include <inttypes.h>

#include "g_local.h"
#include "game/bg_public.h"

//
// Cvar callbacks
//

/*
static void CVU_Derpity( void ) {
// ...
}
*/
static void CVU_FixSaberMoveData(void) {
BG_FixSaberMoveData();

char sLegacyFixes[32];
trap->GetConfigstring(CS_LEGACY_FIXES, sLegacyFixes, sizeof(sLegacyFixes));

uint32_t legacyFixes = strtoul(sLegacyFixes, NULL, 0);
if (g_fixSaberMoveData.integer) {
legacyFixes |= (1 << LEGACYFIX_SABERMOVEDATA);
} else {
legacyFixes &= ~(1 << LEGACYFIX_SABERMOVEDATA);
}
trap->SetConfigstring(CS_LEGACY_FIXES, va("%" PRIu32, legacyFixes));
}

//
// Cvar table
Expand Down
5 changes: 5 additions & 0 deletions codemp/game/g_main.c
Expand Up @@ -28,6 +28,7 @@ along with this program; if not, see <http://www.gnu.org/licenses/>.
#include "g_nav.h"
#include "bg_saga.h"
#include "b_local.h"
#include "game/bg_public.h"
#include "qcommon/q_version.h"

NORETURN_PTR void (*Com_Error)( int level, const char *error, ... );
Expand Down Expand Up @@ -202,6 +203,10 @@ void G_InitGame( int levelTime, int randomSeed, int restart ) {
trap->Print ("gamename: %s\n", GAMEVERSION);
trap->Print ("gamedate: %s\n", SOURCE_DATE);

// init as zero, to be updated by the following cvar registration
// relevant cvars call their update func to modify CS_LEGACY_FIXES when necessary
trap->SetConfigstring(CS_LEGACY_FIXES, "0");

G_RegisterCvars();

G_ProcessIPBans();
Expand Down

0 comments on commit 142e0b7

Please sign in to comment.