Exemplo n.º 1
0
void ParticleManager::ReadFile(void)
{
	this->Prune();
	if (m_iFileLoaded!=0)
	{
		return;
	}
	m_iFileLoaded=1;

	char FileName[256];

	UTIL_Format(FileName, sizeof(FileName)-1, "%s/ns.ps", MF_GetModname());
	FILE *fp=fopen(FileName,"r");

	if (!fp)
	{
		MF_Log("ParticleManager: Cannot open \"%s\" for reading!",FileName);
		return;
	}

	// Since I don't care about the actual parameters of each
	// particle system, just their order and name
	// I only have to scan for "start pSystemName NAME"

	char Buffer[1024];

	char *Start;
	char *End;

	int Count=0;

	memset(&Buffer[0],0x0,sizeof(Buffer));

	while (!feof(fp))
	{
		Buffer[0]='\0';

		fgets(Buffer,1023,fp);

		Start=&Buffer[0];

		// strip whitespace from the front
		while (*Start==' ' ||
			*Start=='\t')
		{
			++Start;
		}

		// if the first character is ' ignore it
		if (*Start=='\'')
		{
			continue;
		}

		// if the first word is "start" then this is a line we want

		if (strncmp("start ",Start,6)!=0)
		{
			continue;
		}

		// Move up past 2 space blocks

		while (*Start!='\0' &&
			*Start!=' ' &&
			*Start!='\t')
		{
			++Start;
		}
		while (*Start==' ' ||
			*Start=='\t')
		{
			++Start;
		}

		while (*Start!='\0' &&
			*Start!=' ' &&
			*Start!='\t')
		{
			++Start;
		}
		while (*Start==' ' ||
			*Start=='\t')
		{
			++Start;
		}

		// now strip whitespace from the end

		End=Start+strlen(Start)-1;

		while (*End=='\n' ||
			*End=='\r' ||
			*End==' ' ||
			*End=='\t')
		{
			*End--='\0';
		}

		// "Start" should now point to the name of this particle system

		//printf("Particle system %d = \"%s\"\n",Count,Start);


		this->Add(Start,1);


		++Count;
	}

	fclose(fp);
};
Exemplo n.º 2
0
void TitleManager::LoadTitles(void)
{
	if (m_Loaded!=0) // already loaded?
	{
		return;
	}

	m_Loaded=1;

	char FileName[128];

	UTIL_Format(FileName, sizeof(FileName)-1, "%s/titles.txt", MF_GetModname());

	FILE *fp=fopen(FileName,"r");

	if (!fp)
	{
		MF_Log("Unable to load \"%s\": TitleManager will not work!",FileName);
		return;
	};

	//MF_Log("TitleManager Loading titles from \"%s\"",FileName);
	char KeyName[512];			// last known good keyname
	char Data[2048];			// data for the key
								// does not support multi line data, but for 
								// location namesthat is acceptable.
	char  TempBuffer[2048];		// currently read data
	char *TempPointer;
	char *TempPointerEnd;

	unsigned int Line=0;
scan_for_key:
	KeyName[0]='\0';

	while (!feof(fp))
	{
		Line++;
		fgets(TempBuffer,2047,fp);
		TempPointer=&TempBuffer[0];

		// get rid of white space at the front
		while (*TempPointer=='\0' ||	// terminator
			*TempPointer==' ' ||		// space
			*TempPointer=='\t')			// tab
		{
			++TempPointer;
		}
		if (*TempPointer=='\0' ||		// terminator
			*TempPointer=='/')			// comment
		{
			continue;
		}

		// get rid of \r\n at the end
		TempPointerEnd=TempPointer+strlen(TempPointer)-1;
		while (*TempPointerEnd=='\r' || 
			*TempPointerEnd=='\n' ||
			*TempPointerEnd=='\t' ||
			*TempPointerEnd==' ')
		{
			*TempPointerEnd--='\0';
		}

		if (*TempPointer=='{')			// start of data
		{
			if (KeyName[0]!='\0')		// do we have a keyname
			{
				goto scan_for_data;
			}
			else
			{
				MF_Log("TitleManager: titles.txt line %u: began a data section with no key name in use!",Line);
				goto scan_for_key;
			}
		}

		// have a valid key name here
		strncpy(KeyName,TempBuffer,sizeof(KeyName)-1);
		
		// keep looping (until we hit a '{')
	};

	// if we're out here then !feof() failed
	goto end_of_file;
scan_for_data:
	Data[0]='\0';

	while (!feof(fp))
	{
		Line++;
		fgets(TempBuffer,2047,fp);
		TempPointer=&TempBuffer[0];

		// get rid of white space at the front
		while (*TempPointer=='\0' ||	// terminator
			*TempPointer==' ' ||		// space
			*TempPointer=='\t')			// tab
		{
			++TempPointer;
		}
		if (*TempPointer=='\0' ||		// terminator
			*TempPointer=='/')			// comment
		{
			continue;
		}

		// get rid of trailing whitespace
		TempPointerEnd=TempPointer+strlen(TempPointer)-1;
		while (*TempPointerEnd=='\r' || 
			*TempPointerEnd=='\n' ||
			*TempPointerEnd=='\t' ||
			*TempPointerEnd==' ')
		{
			*TempPointerEnd--='\0';
		}

		if (*TempPointer=='}')			// end of data
		{
			// insert KeyName & Data into the hash
			ke::AString key(UTIL_ToLowerCase(KeyName));

			this->m_Hash.insert(key, new ke::AString(Data));

			goto scan_for_key;
		}

		// have valid data here
		strncpy(Data,TempBuffer,sizeof(Data)-1);
	};
end_of_file:

	fclose(fp);

	//MF_Log("TitleManager loaded %u entries from titles.txt (%u lines parsed)",m_List.size(),Line);
};
void OnAmxxAttach(void)
{
	// Assert that the enum is aligned properly with the table

	assert(strcmp(hooklist[Ham_FVecVisible].name, "fvecvisible")==0);
	assert(strcmp(hooklist[Ham_Player_UpdateClientData].name, "player_updateclientdata")==0);
	assert(strcmp(hooklist[Ham_Item_AddToPlayer].name, "item_addtoplayer")==0);
	assert(strcmp(hooklist[Ham_Weapon_ExtractAmmo].name, "weapon_extractammo")==0);
	assert(strcmp(hooklist[Ham_TS_BreakableRespawn].name, "ts_breakablerespawn")==0);
	assert(strcmp(hooklist[Ham_NS_UpdateOnRemove].name, "ns_updateonremove")==0);
	assert(strcmp(hooklist[Ham_TS_ShouldCollide].name, "ts_shouldcollide")==0);

	assert(strcmp(hooklist[Ham_GetDeathActivity].name, "getdeathactivity")==0);
	assert(strcmp(hooklist[Ham_StopFollowing].name, "stopfollowing")==0);
	assert(strcmp(hooklist[Ham_CS_Player_OnTouchingWeapon].name, "cstrike_player_ontouchingweapon")==0);
	assert(strcmp(hooklist[Ham_DOD_Weapon_Special].name, "dod_weapon_special")==0);
	assert(strcmp(hooklist[Ham_TFC_RadiusDamage2].name, "tfc_radiusdamage2")==0);
	assert(strcmp(hooklist[Ham_ESF_Weapon_HolsterMeleed].name, "esf_weapon_holsterwhenmeleed")==0);
	assert(strcmp(hooklist[Ham_NS_Weapon_GetDeployTime].name, "ns_weapon_getdeploytime")==0);
	assert(strcmp(hooklist[Ham_SC_MedicCallSound].name, "sc_mediccallsound")==0);
	assert(strcmp(hooklist[Ham_SC_Player_CanTouchPlayer].name, "sc_player_cantouchplayer")==0);
	assert(strcmp(hooklist[Ham_SC_Weapon_ChangeWeaponSkin].name, "sc_weapon_changeweaponskin")==0);
	assert(strcmp(hooklist[Ham_SC_Player_IsConnected].name, "sc_player_isconnected")==0);

	MF_AddNatives(pdata_natives_safe);
	if (ReadConfig() > 0)
	{
		if (Offsets.IsValid())
		{
			MF_AddNatives(RegisterNatives);
			MF_AddNatives(ReturnNatives);
			MF_AddNatives(pdata_natives);
		}
		else
		{
#ifdef _WIN32
			MF_Log("Error: pev and base not set for section \"%s windows\", cannot register natives.", MF_GetModname());
#elif defined(__linux__)
			MF_Log("Error: pev and base not set for section \"%s linux\", cannot register natives.", MF_GetModname());
#elif defined(__APPLE__)
			MF_Log("Error: pev and base not set for section \"%s mac\", cannot register natives.", MF_GetModname());
#endif
		}
	}
	else
	{
		MF_Log("Error: Cannot read config file, natives not registered!");
	}
}
Exemplo n.º 4
0
bool loadDatabase()
{
	const auto isDatabaseLoaded = HandleDB.filename != nullptr;

	if (isDatabaseLoaded)
	{
		return true;
	}

	const char *databases[] =
	{
		"City",
		"Country" // Is the default shipped database with AMXX.
	};

	const auto modName = MF_GetModname();
	const auto dataDir = MF_GetLocalInfo("amxx_datadir", "addons/amxmodx/data");

	char file[260];
	auto status = -1;

	for (auto& database : databases)
	{
		// MF_BuildPathname not used because backslash
		// makes CreateFileMapping failing under windows.

		ke::SafeSprintf(file, sizeof file, "%s/%s/GeoLite2-%s.mmdb", modName, dataDir, database);

		status = MMDB_open(file, MMDB_MODE_MMAP, &HandleDB);

		if (status == MMDB_SUCCESS)
		{
			break;
		}

		if (status != MMDB_FILE_OPEN_ERROR)
		{
			MF_Log("Could not open %s - %s", file, MMDB_strerror(status));

			if (status == MMDB_IO_ERROR)
			{
				MF_Log("    IO error: %s", strerror(errno));
			}
		}
	}

	if (status != MMDB_SUCCESS)
	{
		MF_Log("Could not find GeoIP2 databases. Disabled natives.");
		return false;
	}

	MF_Log("Database info: %s %i.%i",
		   HandleDB.metadata.description.descriptions[0]->description,
		   HandleDB.metadata.binary_format_major_version,
		   HandleDB.metadata.binary_format_minor_version);

	// Retrieve supported languages.
	for (size_t i = 0; i < HandleDB.metadata.languages.count; i++)
	{
		LangList.append(ke::AString(HandleDB.metadata.languages.names[i]));
	}

	return true;
}
Exemplo n.º 5
0
int ReadConfig(void)
{
	char FileName[512];

	MF_BuildPathnameR(FileName,sizeof(FileName),"%s",get_localinfo("amxx_configsdir","addons/amxmodx/configs"));

	strncat(FileName,"/hamdata.ini",sizeof(FileName)-1);

	FILE *fp=fopen(FileName,"r");


	ke::SafeSprintf(CurrentModName, sizeof(CurrentModName), "%s", MF_GetModname());

	if (!fp)
	{
		MF_Log("Unable to open \"%s\" for reading.", FileName);

		return -1;
	}

	char data[2048];

	int insec=0;

	while (!feof(fp))
	{
		data[0]='\0';

		fgets(data, sizeof(data)-1, fp);

		char *b=&data[0];

		switch(lex(b))
		{
		case LEX_PEV:
			{
				if (insec)
				{
					process_pev(b);
				}
				break;
			};
		case LEX_BASE:
			{
				if (insec)
				{
					process_base(b);
				}
				break;
			};
		case LEX_MIRROR:
			{
				read_mirror(b);
				break;
			};
		case LEX_START_SEC:
			{
				insec=read_start_section(b);

				if (!insec)
				{
					skip_to_end_of_section(fp);
				}
				break;
			};
		case LEX_END_SEC:
			{
				insec=0;
				break;
			};
		case LEX_UNKNOWN:
			{
				if (insec)
				{
					process_key(b);
				}
			};
		}


	}

	fclose(fp);

	return 1;
}