Beispiel #1
0
bool idCameraDef::load(const char *filename) {
	char *buf;
	const char *buf_p;
	int length = FS_ReadFile( filename, (void **)&buf );
	if ( !buf ) {
		return false;
	}

	clear();
	Com_BeginParseSession( filename );
	buf_p = buf;
	parse(&buf_p);
	Com_EndParseSession();
	FS_FreeFile( buf );

	return true;
}
AttachmentDef* BG_LoadAttachmentDef_LoadObj(const char* name)
{
	char* fileBuffer;

	if (FS_ReadFile(va("weapons/attachments/%s", name), &fileBuffer) < 0)
	{
		if (!strcmp(name, "nop"))
		{
			Com_Error(0, "Could not load weapon attachment file 'nop'");
		}

		Com_Printf(0, "Could not load weapon attachment file '%s'.\n", name);
		return BG_LoadAttachmentDef_LoadObj("nop");
	}

	char* fileData = fileBuffer;

	std::list<AttachmentPatch> patches;

	Com_BeginParseSession("attachment");

	char* token = Com_ParseExt(&fileData);

	while (fileData)
	{
		if (token[0])
		{
			AttachmentPatch patch;

			if (!_stricmp(token, "multiply"))
			{
				patch.operation = APO_MULTIPLY;
			}
			else if (!_stricmp(token, "add"))
			{
				patch.operation = APO_ADD;
			}
			else if (!_stricmp(token, "set"))
			{
				patch.operation = APO_REPLACE;
			}
			else
			{
				Com_Printf(0, "Attachment error in %s: unknown operation %s\n", name, token);
				continue;
			}

			token = Com_ParseExt(&fileData);

			if (!token)
			{
				Com_Printf(0, "Attachment error in %s: premature end of file\n", name);
				break;
			}

			patch.fieldName = strdup(token);
			
			token = Com_ParseExt(&fileData);

			if (!token)
			{
				Com_Printf(0, "Attachment error in %s: premature end of file\n", name);
				break;
			}

			if ((token[0] == '-' || isdigit(token[0])) && (token[1] == '\0' || isdigit(token[1]) || token[1] == '.'))
			{
				if (strchr(token, '.'))
				{
					patch.value = atof(token);
					patch.type = APT_FLOAT;
				}
				else
				{
					patch.integer = atoi(token);
					patch.type = APT_INTEGER;
				}
			}
			else
			{
				patch.string = strdup(token);
				patch.type = APT_STRING;
			}

			patches.push_back(patch);
		}

		token = Com_ParseExt(&fileData);
	}

	Com_EndParseSession();

	FS_FreeFile(fileBuffer);

	// format the file
	AttachmentDef* adef = new AttachmentDef;
	adef->name = strdup(name);
	adef->numPatches = patches.size();

	AttachmentPatch* apatches = new AttachmentPatch[adef->numPatches];
	int n = 0;

	for (auto i = patches.begin(); i != patches.end(); i++)
	{
		apatches[n] = *i;

		n++;
	}

	adef->patches = apatches;

	return adef;
}
qboolean __cdecl Com_LoadDvarsFromBuffer(const char **inputbuf, unsigned int length, const char *data_p, const char *filename)
{
    const char *cvar_name;
    int i, count;
    char buf[16384];
    const char* line;

    Com_Memset(buf, 0, sizeof(buf));

    for(i = 0; i < length; i++)
    {
         Cvar_Reset(inputbuf[i]);
    }
	Com_BeginParseSession(filename);
	count = 0;

	while ( (cvar_name = Com_Parse(&data_p)) && cvar_name[0])
	{
		for(i = 0; i < length; i++)
		{
			if(!Q_stricmp(cvar_name, inputbuf[i]))
				break;
		}
		if(i == length)
		{
			if(com_developer && com_developer->integer)
			{
				Com_PrintWarning("WARNING: unknown cvar '%s' in file '%s'\n", cvar_name, filename);
			}
			Com_SkipRestOfLine(&data_p);
		}else{
			line = Com_ParseOnLine(&data_p);
			if(com_developer && com_developer->integer)
			{
				Cvar_Set(inputbuf[i], line);
			}else{
				if((!Q_strncmp(inputbuf[i],"bg_shock_viewKickPeriod", 23) || !Q_strncmp(inputbuf[i],"bg_shock_viewKickFadeTime", 25)) && (line[0] == '0' && line[1] == '\0'))
				{
					/* Quite this spam */
				}else{
					Cvar_Set(inputbuf[i], line);
				}
			}
			if ( !buf[i] )
			{
				buf[i] = 1;
				++count;
			}
		}
	}
	Com_EndParseSession();

	if ( length == count )
	{
		/* No Errors */
		return 1;
	}

	Com_PrintError("ERROR: the following cvars were not specified in file '%s'\n", filename);
	for(i = 0; i < length; i++)
	{
		while ( buf[i] && i < length )
		{
			++i;
		}
		if(i < length)
			Com_PrintError("  %s\n", inputbuf[i]);
	}
	return 0;
}