/* ============================ JKG_ParseAmmoOverride_Int Parses a single ammo override ============================ */ static void JKG_ParseAmmoOverride_Int(cJSON* json, const char* name, complexAmmoOverride<int>& field) { cJSON* node = cJSON_GetObjectItem(json, name); if (!node) { field.bIsPresent = qfalse; } else { cJSON* child; field.bIsPresent = qtrue; field.bAdd = qfalse; field.bSet = qfalse; field.bMultiply = qfalse; child = cJSON_GetObjectItem(node, "set"); if (child) { field.bSet = qtrue; field.set = cJSON_ToInteger(child); } child = cJSON_GetObjectItem(node, "add"); if (child) { field.bAdd = qtrue; field.add = cJSON_ToInteger(child); } child = cJSON_GetObjectItem(node, "multiply"); if (child) { field.bMultiply = qtrue; field.multiply = cJSON_ToNumber(child); } } }
void JPLua_Serialiser_IterateTableRead( cJSON *parent, const char *name, lua_State *L ) { cJSON *t = NULL; int numElements, i, top; lua_newtable( L ); top = lua_gettop( L ); t = cJSON_GetObjectItem( parent, name ); numElements = cJSON_GetArraySize( t ); for ( i = 0; i < numElements; i++ ) { cJSON *e, *it; int kType, vType; const char *tmp; char k[256]; e = cJSON_GetArrayItem( t, i ); // key it = cJSON_GetObjectItem( e, "key" ); kType = cJSON_ToInteger( cJSON_GetObjectItem( e, "key_type" ) ); if ( (tmp = cJSON_ToString( it )) ) Q_strncpyz( k, tmp, sizeof(k) ); if ( kType == LUA_TSTRING ) { lua_pushstring( L, k ); } else if ( kType == LUA_TNUMBER ) { lua_pushnumber( L, cJSON_ToNumber( it ) ); } else { Com_Printf( "Invalid key type %s when reading table %s\n", lua_typename( L, kType ), name ); } // value must be created based on type. it = cJSON_GetObjectItem( e, "value" ); vType = cJSON_ToInteger( cJSON_GetObjectItem( e, "value_type" ) ); if ( vType == LUA_TTABLE ) { JPLua_Serialiser_IterateTableRead( e, "value", L ); } else if ( vType == LUA_TNUMBER ) { lua_pushnumber( L, cJSON_ToNumber( it ) ); } else if ( vType == LUA_TBOOLEAN ) { lua_pushboolean( L, cJSON_ToBoolean( it ) ); } else if ( vType == LUA_TSTRING ) { char v[1024 * 8]; // should be plenty.. if ( (tmp = cJSON_ToString( it )) ) Q_strncpyz( v, tmp, sizeof(v) ); lua_pushstring( L, v ); } lua_settable( L, top ); } }
void JKG_Bans_LoadBans() { char *buffer; char error[256]; fileHandle_t f; int len; int i, banCount; cJSON *root, *banlist, *item, *ip; banentry_t *entry; len = trap_FS_FOpenFile(g_banfile.string, &f, FS_READ); if (len < 1) { return; } buffer = malloc(len+1); trap_FS_Read(buffer, len, f); trap_FS_FCloseFile(f); buffer[len] = 0; root = cJSON_ParsePooled(buffer, error, sizeof(error)); free(buffer); if (!root) { G_Printf("Error: Could not parse banlist: %s\n", error); return; } JKG_Bans_Clear(); nextBanId = cJSON_ToInteger(cJSON_GetObjectItem(root, "nextid")); banlist = cJSON_GetObjectItem(root, "bans"); banCount = cJSON_GetArraySize(banlist); for (i=0; i<banCount; i++) { item = cJSON_GetArrayItem(banlist, i); ip = cJSON_GetObjectItem(item, "ip"); entry = malloc(sizeof(banentry_t)); entry->id = cJSON_ToInteger(cJSON_GetObjectItem(item, "id")); entry->mask = cJSON_ToInteger(cJSON_GetObjectItem(item, "mask")); entry->expireTime = cJSON_ToInteger(cJSON_GetObjectItem(item, "expire")); Q_strncpyz(entry->banreason, cJSON_ToString(cJSON_GetObjectItem(item, "reason")), sizeof(entry->banreason)); entry->ip[0] = cJSON_ToInteger(cJSON_GetArrayItem(ip, 0)); entry->ip[1] = cJSON_ToInteger(cJSON_GetArrayItem(ip, 1)); entry->ip[2] = cJSON_ToInteger(cJSON_GetArrayItem(ip, 2)); entry->ip[3] = cJSON_ToInteger(cJSON_GetArrayItem(ip, 3)); entry->next = bans; bans = entry; } cJSON_Delete(root); }
int testMasterFinalFunc (struct asyncTask_s *task) { cJSON *data = (cJSON *)task->finalData; if (task->errorCode == 0) { G_Printf("Test successful! (bounce: %i - %i)", cJSON_ToInteger(cJSON_GetObjectItem(data, "bounce")), level.time); } else { G_Printf("Test failed!"); } return 0; }
// TEST int testMasterFinalFunc (asyncTask_t *task) { cJSON *data = (cJSON *)task->finalData; if (task->errorCode == 0) { Com_Printf("Test successful! (bounce: %i - %i)\n", cJSON_ToInteger(cJSON_GetObjectItem(data, "bounce")), trap_Milliseconds()); } else { Com_Printf("Test failed!\n"); } return 0; }
void Modification::Init(void){ QDir basedir; basedir.setPath(Settings::JKFolder + "base/"); QStringList modlist = basedir.entryList(QDir::Filter::Readable, QDir::SortFlag::Name); if (modlist.size() < 4){ /* ERROR*/ }/*assets0-3.pk3*/ Q_FOREACH(QString name, modlist){ if (name.contains(QRegExp("assets[0-4].pk3"))) continue; name.chop(3); //purge extension QFile *file = new QFile(Settings::JKFolder + "base" + name + ".json"); QByteArray data = file->readAll(); cJSON *root = cJSON_Parse(data.toStdString().c_str()), *temp; if (!root) continue; /* WARNING*/ temp = cJSON_GetObjectItem(root, "id"); Modification *mod = new Modification(cJSON_ToInteger(temp)); temp = cJSON_GetObjectItem(root, "author"); mod->author = cJSON_ToString(temp); temp = cJSON_GetObjectItem(root, "description"); mod->description = cJSON_ToString(temp); temp = cJSON_GetObjectItem(root, "notcompatiblewith"); QStringList list = QString(cJSON_ToString(temp)).split(QChar(',')); Q_FOREACH(QString num, list){ mod->notcompatiblewith.push_back(num.toInt()); } temp = cJSON_GetObjectItem(root, "name"); mod->name = cJSON_ToString(temp); temp = cJSON_GetObjectItem(root, "version"); mod->version = cJSON_ToInteger(temp); cJSON_Delete(root); delete file; }
/* ============================ JKG_ParseSimpleOverrideInt ============================ */ static void JKG_ParseSimpleOverrideInt(std::pair<qboolean, int>& field, const char* nodeName, cJSON* json) { cJSON* child = cJSON_GetObjectItem(json, nodeName); if (child) { field.first = qtrue; field.second = cJSON_ToInteger(json); } else { field.first = qfalse; } }
int registerFinalFunc (asyncTask_t *task) { cJSON *data = (cJSON *)task->finalData; if (task->errorCode == 0) { if (cJSON_ToInteger(cJSON_GetObjectItem(data, "errorCode"))) { Com_Printf("Registration failed: %s\n", cJSON_ToString(cJSON_GetObjectItem(data, "message"))); } else { Com_Printf("Registration successful\n"); } } else { Com_Printf("Registration request failed\n"); } return 0; }
static int GLua_JSON_ToInteger( lua_State *L ) { // Check and make sure we're using a valid index if( !FJSON_ValidateNode( L, 1 ) ) { lua_pushnil(L); return 1; } // Convert to integer cJSON *node = FJSON_RetrieveNode( L, 1 ); lua_pushinteger( L, cJSON_ToInteger( node ) ); return 1; }
void G_ReadSessionData( void ) { char *buffer = NULL; fileHandle_t f = NULL_FILE; unsigned int len = 0u; cJSON *root; char jsonError[MAX_STRING_CHARS] = {}; trap->Print( "G_ReadSessionData: reading %s...", metaFileName ); len = trap->FS_Open( metaFileName, &f, FS_READ ); // no file if ( !f || !len || len == -1 ) { trap->Print( "failed to open file, clearing session data...\n" ); level.newSession = qtrue; return; } buffer = (char *)malloc( len + 1 ); if ( !buffer ) { trap->Print( "failed to allocate buffer, clearing session data...\n" ); level.newSession = qtrue; return; } trap->FS_Read( buffer, len, f ); trap->FS_Close( f ); buffer[len] = '\0'; // read buffer root = cJSON_Parse( buffer, jsonError, sizeof(jsonError) ); // if the gametype changed since the last session, don't use any client sessions if ( level.gametype != cJSON_ToInteger( cJSON_GetObjectItem( root, "gametype" ) ) ) { level.newSession = qtrue; trap->Print( "gametype changed, clearing session data..." ); } free( buffer ); cJSON_Delete( root ); root = NULL; trap->Print( "done\n" ); }
int loginFinalFunc (asyncTask_t *task) { int errorcode; cJSON *data = (cJSON *)task->finalData; if (task->errorCode == 0) { errorcode = cJSON_ToInteger(cJSON_GetObjectItem(data, "errorCode")); if (errorcode == 0) { Com_Printf("Login successful!\n"); } else if (errorcode == 1) { Com_Printf("Bad username or password!\n"); } else if (errorcode == 7) { Com_Printf("Could not access database, please try again in a moment!\n"); } else if (errorcode == 8) { Com_Printf("Account is not yet activated!\n"); } } else { Com_Printf("Login request failed\n"); } return 0; }
// called on a reconnect void G_ReadClientSessionData( gclient_t *client ) { clientSession_t *sess = &client->sess; cJSON *root = NULL, *object = NULL; char fileName[MAX_QPATH] = {}; char *buffer = NULL; fileHandle_t f = NULL_FILE; unsigned int len = 0; const char *tmp = NULL; Com_sprintf( fileName, sizeof(fileName), "session/client%02i.json", client - level.clients ); len = trap->FS_Open( fileName, &f, FS_READ ); // no file if ( !f || !len || len == -1 ) { trap->FS_Close( f ); return; } buffer = (char *)malloc( len + 1 ); if ( !buffer ) { return; } trap->FS_Read( buffer, len, f ); trap->FS_Close( f ); buffer[len] = '\0'; // read buffer root = cJSON_Parse( buffer ); free( buffer ); if ( !root ) { Com_Printf( "G_ReadSessionData(%02i): could not parse session data\n", client - level.clients ); return; } if ( (object = cJSON_GetObjectItem( root, "sessionTeam" )) ) { sess->sessionTeam = (team_t)cJSON_ToInteger( object ); } if ( (object = cJSON_GetObjectItem( root, "spectatorTime" )) ) { sess->spectatorTime = cJSON_ToInteger( object ); } if ( (object = cJSON_GetObjectItem( root, "spectatorState" )) ) { sess->spectatorState = (spectatorState_t)cJSON_ToInteger( object ); } if ( (object = cJSON_GetObjectItem( root, "spectatorClient" )) ) { sess->spectatorClient = cJSON_ToInteger( object ); } if ( (object = cJSON_GetObjectItem( root, "wins" )) ) { sess->wins = cJSON_ToInteger( object ); } if ( (object = cJSON_GetObjectItem( root, "losses" )) ) { sess->losses = cJSON_ToInteger( object ); } if ( (object = cJSON_GetObjectItem( root, "setForce" )) ) { sess->setForce = cJSON_ToInteger( object ); } if ( (object = cJSON_GetObjectItem( root, "saberLevel" )) ) { sess->saberLevel = cJSON_ToInteger( object ); } if ( (object = cJSON_GetObjectItem( root, "selectedFP" )) ) { sess->selectedFP = cJSON_ToInteger( object ); } if ( (object = cJSON_GetObjectItem( root, "duelTeam" )) ) { sess->duelTeam = cJSON_ToInteger( object ); } if ( (object = cJSON_GetObjectItem( root, "siegeDesiredTeam" )) ) { sess->siegeDesiredTeam = cJSON_ToInteger( object ); } if ( (object = cJSON_GetObjectItem( root, "siegeClass" )) ) { if ( (tmp = cJSON_ToString( object )) ) { Q_strncpyz( sess->siegeClass, tmp, sizeof(sess->siegeClass) ); } } if ( (object = cJSON_GetObjectItem( root, "IP" )) ) { if ( (tmp = cJSON_ToString( object )) ) { Q_strncpyz( sess->IP, tmp, sizeof(sess->IP) ); } } if ( (object = cJSON_GetObjectItem( root, "admin" )) ) { if ( (tmp = cJSON_ToString( object )) ) { client->pers.adminUser = AM_ChecksumLogin( tmp ); } } if ( (object = cJSON_GetObjectItem( root, "empowered" )) ) { client->pers.adminData.empowered = cJSON_ToBoolean( object ); } if ( (object = cJSON_GetObjectItem( root, "merc" )) ) { client->pers.adminData.merc = cJSON_ToBoolean( object ); } if ( (object = cJSON_GetObjectItem( root, "silenced" )) ) { client->pers.adminData.silenced = cJSON_ToBoolean( object ); } if ( (object = cJSON_GetObjectItem( root, "slept" )) ) { client->pers.adminData.isSlept = cJSON_ToBoolean( object ); } if ((object = cJSON_GetObjectItem(root, "tempprivs"))) { client->pers.tempprivs = cJSON_ToInteger(object); } client->ps.fd.saberAnimLevel = sess->saberLevel; client->ps.fd.saberDrawAnimLevel = sess->saberLevel; client->ps.fd.forcePowerSelected = sess->selectedFP; cJSON_Delete( root ); root = NULL; }
static void BG_ParseDamage ( weaponFireModeStats_t *fireModeStats, cJSON *damageNode, qboolean secondary ) { if ( !damageNode ) { return; } if ( !secondary && cJSON_IsNumber (damageNode) ) { fireModeStats->baseDamage = (short)cJSON_ToIntegerOpt (damageNode, 0); } else if ( cJSON_IsObject (damageNode) ) { damageSettings_t darea; cJSON *node = NULL; qhandle_t areaHandle = 0; memset (&darea, 0, sizeof (darea)); node = cJSON_GetObjectItem (damageNode, "damageradius"); if ( node ) { cJSON *child = NULL; const char *s = NULL; darea.radial = qtrue; child = cJSON_GetObjectItem (node, "start"); darea.radiusParams.startRadius = (float)cJSON_ToNumber (child); child = cJSON_GetObjectItem (node, "end"); darea.radiusParams.endRadius = (float)cJSON_ToNumber (child); child = cJSON_GetObjectItem (node, "parm"); darea.radiusParams.generic1 = cJSON_ToInteger (child); child = cJSON_GetObjectItem (node, "falloff"); s = cJSON_ToStringOpt (child, "constant"); if ( Q_stricmp (s, "constant") == 0 ) darea.radiusParams.damageFunc = DF_CONSTANT; else if ( Q_stricmp (s, "linear") == 0 ) darea.radiusParams.damageFunc = DF_LINEAR; else if ( Q_stricmp (s, "gaussian") == 0 ) darea.radiusParams.damageFunc = DF_GAUSSIAN; else { darea.radiusParams.damageFunc = DF_CONSTANT; Com_Printf ("Unknown damage falloff type used: %s. Defaulting to linear falloff.\n", s); } child = cJSON_GetObjectItem (node, "function"); s = cJSON_ToStringOpt (child, "constant"); if ( Q_stricmp (s, "linear") == 0 ) darea.radiusParams.radiusFunc = RF_LINEAR; else if ( Q_stricmp (s, "nonlinear") == 0 ) darea.radiusParams.radiusFunc = RF_NONLINEAR; else if ( Q_stricmp (s, "clamp") == 0 ) darea.radiusParams.radiusFunc = RF_CLAMP; else if ( Q_stricmp (s, "wave") == 0 ) darea.radiusParams.radiusFunc = RF_WAVE; else if ( Q_stricmp (s, "constant") == 0 ) darea.radiusParams.radiusFunc = RF_CONSTANT; else { darea.radiusParams.radiusFunc = RF_CONSTANT; Com_Printf ("Unknown radius function used: %s; Defaulting to constant radius.\n", s); } } node = cJSON_GetObjectItem (damageNode, "duration"); darea.lifetime = cJSON_ToIntegerOpt (node, 0); node = cJSON_GetObjectItem (damageNode, "delay"); darea.delay = cJSON_ToIntegerOpt (node, 0); node = cJSON_GetObjectItem (damageNode, "damage"); darea.damage = cJSON_ToIntegerOpt (node, 0); fireModeStats->baseDamage = darea.damage; node = cJSON_GetObjectItem (damageNode, "damagedelay"); darea.damageDelay = cJSON_ToIntegerOpt (node, 0); node = cJSON_GetObjectItem (damageNode, "penetration"); switch ( cJSON_ToIntegerOpt (node, 0) ) { default: case 0: darea.penetrationType = PT_NONE; break; case 1: darea.penetrationType = PT_SHIELD; break; case 2: darea.penetrationType = PT_SHIELD_ARMOR; break; case 3: darea.penetrationType = PT_SHIELD_ARMOR_BUILDING; break; } node = cJSON_GetObjectItem (damageNode, "damagetype"); if ( node ) { int i = 0; const char *types[NUM_DAMAGE_TYPES]; int numTypes = cJSON_ReadStringArray (node, NUM_DAMAGE_TYPES, types); for ( i = 0; i < numTypes; i++ ) { if ( Q_stricmp (types[i], "annihilate") == 0 ) { int dType = (int)darea.damageType; dType |= (1 << DT_ANNIHILATION); darea.damageType = dType; } else if ( Q_stricmp (types[i], "concussion") == 0 ) { int dType = (int)darea.damageType; dType |= (1 << DT_CONCUSSION); darea.damageType = dType; } else if ( Q_stricmp (types[i], "cut") == 0 ) { int dType = (int)darea.damageType; dType |= (1 << DT_CUT); darea.damageType = dType; } else if ( Q_stricmp (types[i], "disintegrate") == 0 ) { int dType = (int)darea.damageType; dType |= (1 << DT_DISINTEGRATE); darea.damageType = dType; } else if ( Q_stricmp (types[i], "electric") == 0 ) { int dType = (int)darea.damageType; dType |= (1 << DT_ELECTRIC); darea.damageType = dType; } else if ( Q_stricmp (types[i], "explosion") == 0 ) { int dType = (int)darea.damageType; dType |= (1 << DT_EXPLOSION); darea.damageType = dType; } else if ( Q_stricmp (types[i], "fire") == 0 ) { int dType = (int)darea.damageType; dType |= ( 1 << DT_FIRE ); darea.damageType = dType; } else if ( Q_stricmp (types[i], "freeze") == 0 ) { int dType = (int)darea.damageType; dType |= (1 << DT_FREEZE); darea.damageType = dType; } else if ( Q_stricmp (types[i], "implosion") == 0 ) { int dType = (int)darea.damageType; dType |= (1 << DT_IMPLOSION); darea.damageType = dType; } else if ( Q_stricmp (types[i], "stun") == 0 ) { int dType = (int)darea.damageType; dType |= (1 << DT_STUN); darea.damageType = dType; } else if ( Q_stricmp (types[i], "carbonite") == 0 ) { int dType = (int)darea.damageType; dType |= (1 << DT_CARBONITE); darea.damageType = dType; } else { Com_Printf ("Unknown damage type used: %s.\n", types[i]); } } } areaHandle = JKG_RegisterDamageSettings (&darea); if ( !secondary ) { fireModeStats->damageTypeHandle = areaHandle; } else { fireModeStats->secondaryDmgHandle = areaHandle; } } }
static void BG_ParseWeaponFireMode ( weaponFireModeStats_t *fireModeStats, cJSON *fireModeNode ) { cJSON *node; const char *str = NULL; if ( fireModeNode == NULL ) { return; } node = cJSON_GetObjectItem (fireModeNode, "ammo"); str = cJSON_ToString (node); if ( str && str[0] ) { fireModeStats->ammo = BG_GetAmmo (str); } node = cJSON_GetObjectItem (fireModeNode, "damage"); #ifdef QAGAME BG_ParseDamage (fireModeStats, node, qfalse); node = cJSON_GetObjectItem (fireModeNode, "secondarydamage"); BG_ParseDamage (fireModeStats, node, qtrue); #else fireModeStats->baseDamage = cJSON_ToInteger (node); #endif node = cJSON_GetObjectItem (fireModeNode, "grenade"); fireModeStats->isGrenade = (qboolean)cJSON_ToBooleanOpt (node, 0); node = cJSON_GetObjectItem (fireModeNode, "grenadeBounces"); fireModeStats->grenadeBounces = (qboolean)cJSON_ToBooleanOpt (node, 1); node = cJSON_GetObjectItem (fireModeNode, "grenadeBounceDMG"); fireModeStats->grenadeBounceDMG = (char)cJSON_ToIntegerOpt (node, 10); node = cJSON_GetObjectItem (fireModeNode, "ballistic"); fireModeStats->applyGravity = (char)cJSON_ToBooleanOpt (node, 0); node = cJSON_GetObjectItem (fireModeNode, "bounces"); fireModeStats->bounceCount = (char)cJSON_ToIntegerOpt (node, 0); node = cJSON_GetObjectItem (fireModeNode, "hitscan"); fireModeStats->hitscan = (char)cJSON_ToBooleanOpt (node, 0); node = cJSON_GetObjectItem (fireModeNode, "projectiles"); fireModeStats->shotCount = (char)cJSON_ToIntegerOpt (node, 0); node = cJSON_GetObjectItem (fireModeNode, "collisionsize"); fireModeStats->boxSize = (float)cJSON_ToNumberOpt (node, 0.0); node = cJSON_GetObjectItem (fireModeNode, "maxchargetime"); fireModeStats->chargeMaximum = (short)cJSON_ToIntegerOpt (node, 0); node = cJSON_GetObjectItem (fireModeNode, "chargedamage"); fireModeStats->chargeMultiplier = (float)cJSON_ToNumberOpt (node, 0); node = cJSON_GetObjectItem (fireModeNode, "chargedelay"); fireModeStats->chargeTime = (short)cJSON_ToIntegerOpt (node, 0); node = cJSON_GetObjectItem (fireModeNode, "ammocost"); fireModeStats->cost = (char)cJSON_ToIntegerOpt (node, 0); node = cJSON_GetObjectItem (fireModeNode, "firingtype"); BG_ParseFireModeFiringType (fireModeStats, cJSON_ToStringOpt (node, "auto")); // 0 means fully automatic, otherwise one burst will fire weapon n times. node = cJSON_GetObjectItem (fireModeNode, "shotsperburst"); fireModeStats->shotsPerBurst = (char)cJSON_ToIntegerOpt (node, 0); // 0 means infinite delay (semi-automatic), otherwise n milliseconds between // rounds in a burst. node = cJSON_GetObjectItem (fireModeNode, "burstshotdelay"); fireModeStats->burstFireDelay = (short)cJSON_ToIntegerOpt (node, 0); node = cJSON_GetObjectItem (fireModeNode, "firedelay"); fireModeStats->delay = (short)cJSON_ToIntegerOpt (node, 0); node = cJSON_GetObjectItem (fireModeNode, "range"); fireModeStats->range = (float)cJSON_ToIntegerOpt (node, WPR_M); node = cJSON_GetObjectItem (fireModeNode, "splashrange"); fireModeStats->rangeSplash = (float)cJSON_ToNumberOpt (node, 0.0); node = cJSON_GetObjectItem (fireModeNode, "recoil"); fireModeStats->recoil = (float)cJSON_ToNumberOpt (node, 0.0); //node = cJSON_GetObjectItem (fireModeNode, "spread"); //fireModeStats->spread = (float)cJSON_ToNumberOpt (node, 0.0); node = cJSON_GetObjectItem (fireModeNode, "accuracy"); if( node ) { cJSON *child = NULL; child = cJSON_GetObjectItem( node, "accuracyRating" ); fireModeStats->weaponAccuracy.accuracyRating = (vec_t)cJSON_ToNumberOpt( child, 32.0f ); child = cJSON_GetObjectItem( node, "crouchModifier" ); fireModeStats->weaponAccuracy.crouchModifier = (float)cJSON_ToNumberOpt( child, 0.8f ); child = cJSON_GetObjectItem( node, "runModifier" ); fireModeStats->weaponAccuracy.runModifier = (float)cJSON_ToNumberOpt( child, 2.0f ); child = cJSON_GetObjectItem( node, "sightsModifier" ); fireModeStats->weaponAccuracy.sightsModifier = (float)cJSON_ToNumberOpt( child, 0.2f ); child = cJSON_GetObjectItem( node, "walkModifier" ); fireModeStats->weaponAccuracy.walkModifier = (float)cJSON_ToNumberOpt( child, 1.55f ); child = cJSON_GetObjectItem( node, "inAirModifier" ); fireModeStats->weaponAccuracy.inAirModifier = (float)cJSON_ToNumberOpt( child, 3.0f ); child = cJSON_GetObjectItem( node, "accuracyRatingPerShot" ); fireModeStats->weaponAccuracy.accuracyRatingPerShot = (int)cJSON_ToNumberOpt( child, 2 ); child = cJSON_GetObjectItem( node, "msToDrainAccuracy" ); fireModeStats->weaponAccuracy.msToDrainAccuracy = (int)cJSON_ToNumberOpt( child, 200 ); child = cJSON_GetObjectItem( node, "maxAccuracyAdd" ); fireModeStats->weaponAccuracy.maxAccuracyAdd = (int)cJSON_ToNumberOpt( child, 128 ); } else { fireModeStats->weaponAccuracy.accuracyRating = 32.0f; fireModeStats->weaponAccuracy.crouchModifier = 0.8f; fireModeStats->weaponAccuracy.runModifier = 2.0f; fireModeStats->weaponAccuracy.sightsModifier = 0.2f; fireModeStats->weaponAccuracy.walkModifier = 1.55f; fireModeStats->weaponAccuracy.inAirModifier = 3.0f; fireModeStats->weaponAccuracy.accuracyRatingPerShot = 2; fireModeStats->weaponAccuracy.msToDrainAccuracy = 200; fireModeStats->weaponAccuracy.maxAccuracyAdd = 128; } node = cJSON_GetObjectItem (fireModeNode, "projectilespeed"); fireModeStats->speed = (float)cJSON_ToNumberOpt (node, 0.0); node = cJSON_GetObjectItem (fireModeNode, "projectileclass"); str = cJSON_ToStringOpt (node, "unknown_proj"); Q_strncpyz (fireModeStats->weaponClass, str, sizeof (fireModeStats->weaponClass)); node = cJSON_GetObjectItem (fireModeNode, "meansofdeath"); str = cJSON_ToStringOpt (node, "MOD_UNKNOWN"); fireModeStats->weaponMOD = GetIDForString (MODTable, str); node = cJSON_GetObjectItem (fireModeNode, "splashmeansofdeath"); str = cJSON_ToStringOpt (node, "MOD_UNKNOWN"); fireModeStats->weaponSplashMOD = GetIDForString (MODTable, str); }
static void BG_ParseVisualsFireMode ( weaponVisualFireMode_t *fireMode, cJSON *fireModeNode, int numFireModes ) { cJSON *node = NULL; cJSON *child = NULL; qboolean isGrenade = qfalse; qboolean isBlaster = qfalse; qboolean isTripmine = qfalse; qboolean isDetpack = qfalse; ReadString (fireModeNode, "type", fireMode->type, sizeof (fireMode->type)); isGrenade = (qboolean)(Q_stricmp (fireMode->type, "grenade") == 0); isBlaster = (qboolean)(Q_stricmp (fireMode->type, "blaster") == 0); isTripmine = (qboolean)(Q_stricmp (fireMode->type, "tripmine") == 0); isDetpack = (qboolean)(Q_stricmp (fireMode->type, "detpack") == 0); ReadString (fireModeNode, "displayName", fireMode->displayName, 128); ReadString (fireModeNode, "crosshairShader", fireMode->crosshairShader, MAX_QPATH); ReadString (fireModeNode, "switchToSound", fireMode->switchToSound, MAX_QPATH); if(!fireMode->switchToSound || !fireMode->switchToSound[0]) { if(fmLoadCounter == 0) { Com_sprintf(fireMode->switchToSound, MAX_QPATH, "sound/weapons/common/click%i.wav", numFireModes); } else { Com_sprintf(fireMode->switchToSound, MAX_QPATH, "sound/weapons/common/click1.wav"); } } node = cJSON_GetObjectItem (fireModeNode, "animType"); fireMode->animType = (firingModeAnim_t)cJSON_ToInteger (node); fireMode->overrideIndicatorFrame = -1; // set this as default since 0 is still a valid frame node = cJSON_GetObjectItem (fireModeNode, "overrideIndicatorFrame"); if(node) { fireMode->overrideIndicatorFrame = cJSON_ToInteger (node); } // TODO: Need to tie this to the table in cg_weapons.c somehow... // Weapon Render node = cJSON_GetObjectItem (fireModeNode, "muzzlelightintensity"); fireMode->weaponRender.generic.muzzleLightIntensity = (float)cJSON_ToNumber (node); ReadString (fireModeNode, "muzzlelightcolor", fireMode->weaponRender.generic.muzzleLightColor, sizeof (fireMode->weaponRender.generic.muzzleLightColor)); ReadString (fireModeNode, "chargingfx", fireMode->weaponRender.generic.chargingEffect, sizeof (fireMode->weaponRender.generic.chargingEffect)); ReadString (fireModeNode, "muzzlefx", fireMode->weaponRender.generic.muzzleEffect, sizeof (fireMode->weaponRender.generic.muzzleEffect)); // Weapon Fire child = cJSON_GetObjectItem (fireModeNode, "firesound"); if ( child ) { if ( cJSON_IsArray (child) ) { const char *fireSounds[8]; int numFireSounds = cJSON_ReadStringArray (child, 8, fireSounds); int i; for ( i = 0; i < numFireSounds; i++ ) { Q_strncpyz (fireMode->weaponFire.generic.fireSound[i], fireSounds[i], sizeof (fireMode->weaponFire.generic.fireSound[i])); } } else { const char *s = cJSON_ToString (child); if ( s ) Q_strncpyz (fireMode->weaponFire.generic.fireSound[0], s, sizeof (fireMode->weaponFire.generic.fireSound[0])); } } // Traceline Render ReadString (fireModeNode, "tracelineshader", fireMode->tracelineRender.generic.tracelineShader, sizeof (fireMode->tracelineRender.generic.tracelineShader)); node = cJSON_GetObjectItem (fireModeNode, "minsize"); fireMode->tracelineRender.generic.minSize = (float)cJSON_ToNumber (node); node = cJSON_GetObjectItem (fireModeNode, "maxsize"); fireMode->tracelineRender.generic.maxSize = (float)cJSON_ToNumber (node); node = cJSON_GetObjectItem (fireModeNode, "lifetime"); fireMode->tracelineRender.generic.lifeTime = cJSON_ToInteger (node); // Weapon Charge ReadString (fireModeNode, "chargingsound", fireMode->weaponCharge.chargingSound, sizeof (fireMode->weaponCharge.chargingSound)); // Projectile render ReadString (fireModeNode, "projectilemodel", fireMode->projectileRender.generic.projectileModel, sizeof (fireMode->projectileRender.generic.projectileModel)); ReadString (fireModeNode, "projectilefx", fireMode->projectileRender.generic.projectileEffect, sizeof (fireMode->projectileRender.generic.projectileEffect)); ReadString (fireModeNode, "runsound", fireMode->projectileRender.generic.runSound, sizeof (fireMode->projectileRender.generic.runSound)); node = cJSON_GetObjectItem (fireModeNode, "lightintensity"); fireMode->projectileRender.generic.lightIntensity = (float)cJSON_ToNumber (node); ReadString (fireModeNode, "lightcolor", fireMode->projectileRender.generic.lightColor, sizeof (fireMode->projectileRender.generic.lightColor)); ReadString (fireModeNode, "deathfx", fireMode->projectileRender.generic.deathEffect, sizeof (fireMode->projectileRender.generic.deathEffect)); // Projectile miss event child = cJSON_GetObjectItem (fireModeNode, "miss"); if ( isTripmine || isDetpack ) { ReadString (child, "sticksound", fireMode->projectileMiss.explosive.stickSound, sizeof (fireMode->projectileMiss.explosive.stickSound)); } else { ReadString (child, "impactfx", fireMode->projectileMiss.generic.impactEffect, sizeof (fireMode->projectileMiss.generic.impactEffect)); ReadString (child, "shockwavefx", fireMode->projectileMiss.grenade.shockwaveEffect, sizeof (fireMode->projectileMiss.grenade.shockwaveEffect)); } // Projectile hit event child = cJSON_GetObjectItem (fireModeNode, "hit"); ReadString (child, "impactfx", fireMode->projectileHitPlayer.generic.impactEffect, sizeof (fireMode->projectileHitPlayer.generic.impactEffect)); ReadString (child, "shockwavefx", fireMode->projectileHitPlayer.grenade.shockwaveEffect, sizeof (fireMode->projectileHitPlayer.grenade.shockwaveEffect)); // Projectile deflected event ReadString (fireModeNode, "deflectedfx", fireMode->projectileDeflected.generic.deflectEffect, sizeof (fireMode->projectileDeflected.generic.deflectEffect)); // Grenade bounce event child = cJSON_GetObjectItem (fireModeNode, "bouncesound"); if ( child ) { const char *bounceSounds[2]; int numBounceSounds = cJSON_ReadStringArray (child, 2, bounceSounds); int i; for ( i = 0; i < numBounceSounds; i++ ) { Q_strncpyz (fireMode->grenadeBounce.grenade.bounceSound[i], bounceSounds[i], sizeof (fireMode->grenadeBounce.grenade.bounceSound[i])); } } // Explosive render ReadString (fireModeNode, "g2model", fireMode->explosiveRender.detpack.g2Model, sizeof (fireMode->explosiveRender.detpack.g2Model)); node = cJSON_GetObjectItem (fireModeNode, "g2radius"); fireMode->explosiveRender.detpack.g2Radius = (float)cJSON_ToNumber (node); ReadString (fireModeNode, "linefx", fireMode->explosiveRender.tripmine.lineEffect, sizeof (fireMode->explosiveRender.tripmine.lineEffect)); // Explosive blow event ReadString (fireModeNode, "explodefx", fireMode->explosiveBlow.generic.explodeEffect, sizeof (fireMode->explosiveBlow.generic.explodeEffect)); // Explosive armed event ReadString (fireModeNode, "armsound", fireMode->explosiveArm.armSound, sizeof (fireMode->explosiveArm.armSound)); fmLoadCounter++; }
// Called on a reconnect void G_ReadClientSessionData( gclient_t *client ) { clientSession_t *sess = &client->sess; cJSON *root = NULL, *object = NULL; char fileName[MAX_QPATH] = {}; char *buffer = NULL; fileHandle_t f = NULL_FILE; unsigned int len = 0; const char *tmp = NULL; char jsonError[MAX_STRING_CHARS] = {}; Com_sprintf( fileName, sizeof(fileName), "session/client%02i.json", client - level.clients ); len = trap->FS_Open( fileName, &f, FS_READ ); // no file if ( !f || !len || len == -1 ) { trap->FS_Close( f ); return; } buffer = (char *)malloc( len + 1 ); if ( !buffer ) { return; } trap->FS_Read( buffer, len, f ); trap->FS_Close( f ); buffer[len] = '\0'; // read buffer root = cJSON_Parse( buffer, jsonError, sizeof(jsonError) ); free( buffer ); if ( !root ) { Com_Printf( "G_ReadSessionData(%02i): could not parse session data\n", client - level.clients ); return; } if ( (object = cJSON_GetObjectItem( root, "sessionTeam" )) ) { sess->sessionTeam = (team_t)cJSON_ToInteger( object ); } if ( (object = cJSON_GetObjectItem( root, "spectatorNum" )) ) { sess->spectatorNum = cJSON_ToInteger( object ); } if ( (object = cJSON_GetObjectItem( root, "spectatorState" )) ) { sess->spectatorState = (spectatorState_t)cJSON_ToInteger( object ); } if ( (object = cJSON_GetObjectItem( root, "spectatorClient" )) ) { sess->spectatorClient = cJSON_ToInteger( object ); } if ( (object = cJSON_GetObjectItem( root, "wins" )) ) { sess->wins = cJSON_ToInteger( object ); } if ( (object = cJSON_GetObjectItem( root, "losses" )) ) { sess->losses = cJSON_ToInteger( object ); } if ( (object = cJSON_GetObjectItem( root, "setForce" )) ) { sess->setForce = (qboolean)cJSON_ToInteger( object ); } if ( (object = cJSON_GetObjectItem( root, "saberLevel" )) ) { sess->saberLevel = cJSON_ToInteger( object ); } if ( (object = cJSON_GetObjectItem( root, "selectedFP" )) ) { sess->selectedFP = cJSON_ToInteger( object ); } if ( (object = cJSON_GetObjectItem( root, "updateUITime" )) ) { sess->updateUITime = cJSON_ToInteger( object ); } if ( (object = cJSON_GetObjectItem( root, "duelTeam" )) ) { sess->duelTeam = cJSON_ToInteger( object ); } if ( (object = cJSON_GetObjectItem( root, "siegeDesiredTeam" )) ) { sess->siegeDesiredTeam = cJSON_ToInteger( object ); } if ( (object = cJSON_GetObjectItem( root, "saberType" )) ) { if ( (tmp = cJSON_ToString( object )) ) { Q_strncpyz( sess->saberType, tmp, sizeof(sess->saberType) ); } } if ( (object = cJSON_GetObjectItem( root, "saber2Type" )) ) { if ( (tmp = cJSON_ToString( object )) ) { Q_strncpyz( sess->saber2Type, tmp, sizeof(sess->saber2Type) ); } } if ( (object = cJSON_GetObjectItem( root, "IP" )) ) { if ( (tmp = cJSON_ToString( object )) ) { Q_strncpyz( sess->IP, tmp, sizeof(sess->IP) ); } } if ( (object = cJSON_GetObjectItem( root, "connTime" )) ) { sess->connTime = cJSON_ToInteger( object ); } if ( (object = cJSON_GetObjectItem( root, "noq3fill" )) ) { sess->noq3fill = cJSON_ToInteger( object ); } if ( (object = cJSON_GetObjectItem( root, "validated" )) ) { sess->validated = cJSON_ToInteger( object ); } if ( (object = cJSON_GetObjectItem( root, "adminRank" )) ) { sess->adminRank = cJSON_ToInteger( object ); } if ( (object = cJSON_GetObjectItem( root, "canUseCheats" )) ) { sess->canUseCheats = !!cJSON_ToInteger( object ); } client->ps.fd.saberAnimLevel = client->sess.saberLevel; client->ps.fd.saberDrawAnimLevel = client->sess.saberLevel; client->ps.fd.forcePowerSelected = client->sess.selectedFP; cJSON_Delete( root ); root = NULL; }
static void BG_ParseVisuals ( weaponData_t *weaponData, cJSON *visualsNode ) { cJSON *node = NULL; cJSON *child = NULL; weaponVisual_t *weaponVisuals = &weaponData->visuals; int i; ReadString (visualsNode, "worldmodel", weaponVisuals->world_model, sizeof (weaponVisuals->world_model)); ReadString (visualsNode, "viewmodel", weaponVisuals->view_model, sizeof (weaponVisuals->view_model)); ReadString (visualsNode, "hudicon", weaponVisuals->icon, sizeof (weaponVisuals->icon)); ReadString (visualsNode, "hudnaicon", weaponVisuals->icon_na, sizeof (weaponVisuals->icon_na)); ReadString (visualsNode, "selectsound", weaponVisuals->selectSound, sizeof (weaponVisuals->selectSound)); child = cJSON_GetObjectItem (visualsNode, "indicators"); if ( child ) { int numGroupIndicators = 0; int i; char *shaders[3]; cJSON *subchild = cJSON_GetObjectItem (child, "ammo"); if ( subchild ) { weaponVisuals->indicatorType = IND_NORMAL; numGroupIndicators = cJSON_ReadStringArray (subchild, 3, const_cast<const char **>(shaders)); for ( i = 0; i < numGroupIndicators; i++ ) { Q_strncpyz (weaponVisuals->groupedIndicatorShaders[i], shaders[i], sizeof (weaponVisuals->groupedIndicatorShaders[i])); } } else if ( (subchild = cJSON_GetObjectItem (child, "leds")) != NULL ) { weaponVisuals->indicatorType = IND_GRENADE; numGroupIndicators = cJSON_ReadStringArray (subchild, 3, const_cast<const char **>(shaders)); for ( i = 0; i < numGroupIndicators; i++ ) { Q_strncpyz (weaponVisuals->groupedIndicatorShaders[i], shaders[i], sizeof (weaponVisuals->groupedIndicatorShaders[i])); } } ReadString (child, "firemode", weaponVisuals->firemodeIndicatorShader, sizeof (weaponVisuals->firemodeIndicatorShader)); } ReadString (visualsNode, "gunposition", weaponVisuals->gunPosition, sizeof (weaponVisuals->gunPosition)); ReadString (visualsNode, "ironsightsPosition", weaponVisuals->ironsightsPosition, sizeof (weaponVisuals->ironsightsPosition)); node = cJSON_GetObjectItem (visualsNode, "ironsightsFov"); weaponVisuals->ironsightsFov = (float)cJSON_ToNumberOpt (node, 0.0); // Scope toggle child = cJSON_GetObjectItem (visualsNode, "scope"); ReadString (child, "startsound", weaponVisuals->scopeStartSound, sizeof (weaponVisuals->scopeStartSound)); ReadString (child, "stopsound", weaponVisuals->scopeStopSound, sizeof (weaponVisuals->scopeStopSound)); // Scope zoom node = cJSON_GetObjectItem (child, "looptime"); weaponVisuals->scopeSoundLoopTime = cJSON_ToInteger (node); ReadString (child, "loopsound", weaponVisuals->scopeLoopSound, sizeof (weaponVisuals->scopeLoopSound)); // Scope render ReadString (child, "mask", weaponVisuals->scopeShader, sizeof (weaponVisuals->scopeShader)); //Crosshair -- eezstreet add node = cJSON_GetObjectItem (visualsNode, "crosshairValue"); weaponVisuals->crosshairValue = (int)cJSON_ToNumberOpt(node, (double)1); /*node = cJSON_GetObjectItem (visualsNode, "primary"); BG_ParseVisualsFireMode (&weaponVisuals->primary, node); node = cJSON_GetObjectItem (visualsNode, "secondary"); BG_ParseVisualsFireMode (&weaponVisuals->secondary, node);*/ for ( i = 0; i < weaponData->numFiringModes; i++ ) { node = cJSON_GetObjectItem (visualsNode, va("firemode%i", i) ); if(node) { BG_ParseVisualsFireMode(&weaponVisuals->visualFireModes[i], node, weaponData->numFiringModes); } } }
qboolean JKG_Items_LoadCraftFile( const char *filePath, craftRecipe_t *craftData, const char * const bench, const char * const type ) { char error[MAX_STRING_CHARS]; int i, j; cJSON *json = NULL; cJSON *jsonNode = NULL; char craftFileData[MAX_CRAFTING_FILE_SIZE]; fileHandle_t f; int fileLen = strap_FS_FOpenFile(filePath, &f, FS_READ); if(!f || fileLen == -1) { Com_Printf(S_COLOR_RED "Unreadable or empty loot file: %s\n", filePath); return qfalse; } if( (fileLen + 1) >= MAX_CRAFTING_FILE_SIZE ) { strap_FS_FCloseFile(f); Com_Printf(S_COLOR_RED "%s: File too large\n", filePath); return qfalse; } strap_FS_Read(&craftFileData, fileLen, f); craftFileData[fileLen] = '\0'; strap_FS_FCloseFile(f); json = cJSON_ParsePooled(craftFileData, error, sizeof(error)); if(json == NULL) { Com_Printf(S_COLOR_RED "%s:%s\n", filePath, error); return qfalse; } JKG_Array_Init(&craftData->input, sizeof(craftInput_t), 1); JKG_Array_Init(&craftData->output, sizeof(craftInput_t), 1); for(i = 0; i < MAX_INPUTS; i++) { int inputSize; cJSON *inputNode = NULL; jsonNode = cJSON_GetObjectItem(json, va("input%i", i)); inputSize = cJSON_GetArraySize(jsonNode); for(j = 0; j < inputSize; j++) { craftInput_t dummy2; inputNode = cJSON_GetArrayItem(jsonNode, j); dummy2.internalName = cJSON_ToString(cJSON_GetObjectItem(inputNode, "internal")); dummy2.itemID = cJSON_ToInteger(cJSON_GetObjectItem(inputNode, "itemid")); dummy2.quantity = 1; dummy2.quantity = cJSON_ToInteger(cJSON_GetObjectItem(inputNode, "quantity")); JKG_Array_Add(&craftData->input, &dummy2); } } for(i = 0; i < MAX_INPUTS; i++) { int outputSize; cJSON *outputNode = NULL; jsonNode = cJSON_GetObjectItem(json, va("output%i", i)); outputSize = cJSON_GetArraySize(jsonNode); for(j = 0; j < outputSize; j++) { craftInput_t dummy2; outputNode = cJSON_GetArrayItem(jsonNode, j); dummy2.internalName = cJSON_ToString(cJSON_GetObjectItem(outputNode, "internal")); dummy2.itemID = cJSON_ToInteger(cJSON_GetObjectItem(outputNode, "itemid")); dummy2.quantity = 1; dummy2.quantity = cJSON_ToInteger(cJSON_GetObjectItem(outputNode, "quantity")); JKG_Array_Add(&craftData->output, &dummy2); } } if(Q_stricmp(bench, "workbench")) craftData->craftBench = CRAFTING_WORKBENCH; else if(Q_stricmp(bench, "welding")) craftData->craftBench = CRAFTING_WELDING; else if(Q_stricmp(bench, "laboratory")) craftData->craftBench = CRAFTING_CHEMICAL; else craftData->craftBench = CRAFTING_WORKBENCH; craftData->freestyle = (Q_stricmp(type, "freestyle") == 0) ? qtrue : qfalse; craftData->group = (craftData->freestyle == qtrue) ? cJSON_ToInteger(cJSON_GetObjectItem(json, "group")) : -1; if(craftData->freestyle) JKG_Array_Add(&FreestyleRecipes[craftData->craftBench], craftData); else JKG_Array_Add(&CraftingRecipes[craftData->craftBench], craftData); cJSON_Delete(json); return qtrue; }
static void JKG_ParseBuffOverrides(ammo_t* ammo, cJSON* json, const char* nodeName) { cJSON* child = cJSON_GetObjectItem(json, nodeName); if (child == nullptr) { return; } int elemCount = cJSON_GetArraySize(child); if (elemCount <= 0) { return; // not actually an array } // Iterate through each buff array item for (int i = 0; i < elemCount; i++) { cJSON* buff = cJSON_GetArrayItem(child, i); complexAmmoBuffOverride buffOverride = { 0 }; cJSON* buffChild = cJSON_GetObjectItem(buff, "buff"); if (buffChild == nullptr) { // JSON doesn't contain a "buff" field. Continue. continue; } buffOverride.buff = JKG_ResolveBuffName(cJSON_ToStringOpt(buffChild, "")); if (buffOverride.buff < 0) { // A buff by this name doesn't exist, continue. continue; } buffChild = cJSON_GetObjectItem(buff, "remove"); buffOverride.bRemove = cJSON_ToBooleanOpt(buffChild, qfalse); buffChild = cJSON_GetObjectItem(buff, "addbuff"); buffOverride.bAddBuff = cJSON_ToBooleanOpt(buffChild, qfalse); buffChild = cJSON_GetObjectItem(buff, "duration"); if (buffChild != nullptr) { cJSON* childProps; childProps = cJSON_GetObjectItem(buffChild, "add"); if (childProps != nullptr) { buffOverride.bAddDuration = qtrue; buffOverride.addDuration = cJSON_ToInteger(childProps); } childProps = cJSON_GetObjectItem(buffChild, "multiply"); if (childProps != nullptr) { buffOverride.bMultiplyDuration = qtrue; buffOverride.multiplyDuration = cJSON_ToNumber(childProps); } childProps = cJSON_GetObjectItem(buffChild, "set"); if (childProps != nullptr) { buffOverride.bSetDuration = qtrue; buffOverride.setDuration = cJSON_ToInteger(childProps); } } buffChild = cJSON_GetObjectItem(buff, "intensity"); if (buffChild != nullptr) { cJSON* childProps; childProps = cJSON_GetObjectItem(buffChild, "add"); if (childProps != nullptr) { buffOverride.bAddIntensity = qtrue; buffOverride.addIntensity = cJSON_ToNumber(childProps); } childProps = cJSON_GetObjectItem(buffChild, "multiply"); if (childProps != nullptr) { buffOverride.bMultiplyIntensity = qtrue; buffOverride.multiplyIntensity = cJSON_ToNumber(childProps); } childProps = cJSON_GetObjectItem(buffChild, "set"); if (childProps != nullptr) { buffOverride.bSetIntensity = qtrue; buffOverride.setIntensity = cJSON_ToNumber(childProps); } } // Add the override to the list of buff overrides ammo->overrides.buffs.emplace_back(buffOverride); } }