Example #1
0
//this is the file parser for dictionary text files
// -- BAILOPAN
int CLangMngr::MergeDefinitionFile(const char *file)
{
	/** Tries to open the file. */
	struct stat fileStat;
	if (stat(file, &fileStat))
	{
		FileList.remove(file);
		AMXXLOG_Log("[AMXX] Failed to open dictionary file: %s", file);
		return 0;
	}

	/** Checks if there is an existing entry with same time stamp. */
	time_t timeStamp;
	if (FileList.retrieve(file, &timeStamp) && fileStat.st_mtime == timeStamp)
	{
		return -1;
	}

	/** If yes, it either means that the entry doesn't exist or the existing entry needs to be updated. */
	FileList.replace(file, fileStat.st_mtime);

	Data.currentFile = file;

	unsigned int line, col;
	bool result = textparsers->ParseFile_INI(file, static_cast<ITextListener_INI*>(this), &line, &col);

	if (!result)
	{
		AMXXLOG_Log("[AMXX] Failed to re-open dictionary file: %s", file);
		return 0;
	}

	return 1;
}
CAmxxReader::Error CAmxxReader::GetSection(void *buffer)
{
    if (!m_pFile)
        return m_Status;

    if (m_AmxxFile)
    {
        PluginEntry *pe = &(m_Bh.plugins[m_Entry]);
        char *tempBuffer = new char[m_SectionLength + 1];
        fseek(m_pFile, pe->offs, SEEK_SET);
        DATAREAD((void *)tempBuffer, 1, m_SectionLength);
        uLongf destLen = GetBufferSize();
        int result = uncompress((Bytef *)buffer, &destLen, (Bytef *)tempBuffer, m_SectionLength);
        delete [] tempBuffer;

        if (result != Z_OK)
        {
            AMXXLOG_Log("[AMXX] Zlib error encountered: %d(%d)", result, m_SectionLength);
            m_Status = Err_Decompress;
            return Err_Decompress;
        }

        return Err_None;
    } else {
        // new file type: go to the section table entry
        fseek(m_pFile, m_SectionHdrOffset, SEEK_SET);
        // go to the offset
        TableEntry entry;
        DATAREAD(&entry, sizeof(entry), 1);
        fseek(m_pFile, entry.offset, SEEK_SET);
        uLongf destLen = GetBufferSize();
        // read the data to a temporary buffer
        char *tempBuffer = new char[m_SectionLength + 1];
        //fread(tempBuffer, sizeof(char), m_SectionLength, m_pFile);
        DATAREAD((void*)tempBuffer, 1, m_SectionLength);
        // decompress
        int result = uncompress((Bytef *)buffer, &destLen, (Bytef *)tempBuffer, m_SectionLength);
        delete [] tempBuffer;

        if (result != Z_OK)
        {
            AMXXLOG_Log("[AMXX] Zlib error encountered: %d(%d)", result, m_SectionLength);
            m_Status = Err_Decompress;

            return Err_Decompress;
        }

        return Err_None;
    }
}
Example #3
0
void CGameConfigManager::OnAmxxStartup()
{
	char error[256] = "";

	if (!LoadGameConfigFile("common.games", &CommonConfig, error, sizeof(error)))
	{
		AMXXLOG_Log("Could not read common.games gamedata: %s", error);
		return;
	}
}
Example #4
0
bool CLangMngr::ReadINI_NewSection(const char *section, bool invalid_tokens, bool close_bracket, bool extra_tokens, unsigned int *curtok)
{
	if (Data.multiLine)
	{
		AMXXLOG_Log("New section, unterminated block (file \"%s\" key \"%s\" lang \"%s\")", Data.currentFile.chars(), Data.lastKey.chars(), Data.language);

		Data.clearEntry();
	}

	if (!Data.defsQueue.empty())
	{
		MergeDefinitions(Data.language, Data.defsQueue);
	}

	Data.reset();

	Data.language[0] = section[0];
	Data.language[1] = section[1];
	Data.language[2] = '\0';

	return true;
}
Example #5
0
void CPluginMngr::CPlugin::Finalize()
{
	char buffer[128];
	int old_status = status;

	if (CheckModules(&amx, buffer))
	{
		if (amx_Register(&amx, core_Natives, -1) != AMX_ERR_NONE)
		{
			Handler *pHandler = (Handler *)amx.userdata[UD_HANDLER];
			int res = 0;

			if (pHandler->IsNativeFiltering())
				res = amx_CheckNatives(&amx, native_handler);

			if (!res)
			{
				status = ps_bad_load;
				sprintf(buffer, "Plugin uses an unknown function (name \"%s\") - check your modules.ini.", no_function);
				errorMsg = buffer;
				amx.error = AMX_ERR_NOTFOUND;
			} else {
				amx_RegisterToAny(&amx, invalid_native);
			}
		}
	} else {
		status = ps_bad_load;
		errorMsg = buffer;
		amx.error = AMX_ERR_NOTFOUND;
	}

	if (old_status != status)
	{
		AMXXLOG_Log("[AMXX] Plugin \"%s\" failed to load: %s", name.chars(), errorMsg.chars());
	}
}
Example #6
0
bool CLangMngr::ReadINI_KeyValue(const char *key, const char *value, bool invalid_tokens, bool equal_token, bool quotes, unsigned int *curtok)
{
	bool colons_token = (key[strlen(key) - 1] == ':');

	if (!Data.multiLine)
	{
		Data.lastKey = key;

		if (colons_token || equal_token)
		{
			int iKey = GetKeyEntry(key);

			if (iKey == -1)
			{
				iKey = AddKeyEntry(key);
			}

			if (equal_token)
			{
				strncopy(Data.valueBuffer, value, sizeof(Data.valueBuffer));

				reparse_newlines_and_color(Data.valueBuffer);

				Data.entry.key = iKey;
				Data.entry.definition = new ke::AutoString;
				*Data.entry.definition = Data.valueBuffer;

				Data.defsQueue.append(Data.entry);
				Data.clearEntry();
			}
			else if (!value && colons_token)
			{
				Data.entry.key = iKey;
				Data.entry.definition = new ke::AutoString;

				Data.multiLine = true;
			}
		}
		else
		{
			AMXXLOG_Log("Invalid multi-lingual line (file \"%s\" key \"%s\" lang \"%s\")", Data.currentFile.chars(), Data.lastKey.chars(), Data.language);
		}
	}
	else
	{
		if (!value && colons_token)
		{
			strncopy(Data.valueBuffer, Data.entry.definition->ptr(), sizeof(Data.valueBuffer));
			reparse_newlines_and_color(Data.valueBuffer);

			*Data.entry.definition = Data.valueBuffer;

			Data.defsQueue.append(Data.entry);
			Data.clearEntry();

			Data.multiLine = false;
		}
		else
		{
			if (!Data.entry.definition)
			{
				Data.entry.definition = new ke::AutoString();
			}

			*Data.entry.definition = *Data.entry.definition + key;
		}
	}

	return true;
}
Example #7
0
bool CGameConfig::Reparse(char *error, size_t maxlength)
{
	m_Offsets.clear();
	m_OffsetsByClass.clear();
	m_Keys.clear();
	m_Addresses.clear();

	char path[PLATFORM_MAX_PATH];
	const char *dataDir = get_localinfo("amxx_datadir", "addons/amxmodx/data");

	build_pathname_r(path, sizeof(path), "%s/gamedata/%s/master.games.txt", dataDir, m_File);

	if (!g_LibSys.PathExists(path))
	{
		// Single config file without master
		g_LibSys.PathFormat(path, sizeof(path), "%s.txt", m_File);

		if (!EnterFile(path, error, maxlength))
		{
			return false;
		}

		// Allow customizations of default gamedata files
		build_pathname_r(path, sizeof(path), "%s/gamedata/custom/%s.txt", dataDir, m_File);

		if (g_LibSys.PathExists(path))
		{
			g_LibSys.PathFormat(path, sizeof(path), "custom/%s.txt", m_File);

			auto success = EnterFile(path, error, maxlength);

			if (success)
			{
				AMXXLOG_Log("[AMXX] Parsed custom gamedata override file: %s", path);
			}

			return success;
		}
		return true;
	}

	SMCError err;
	SMCStates state = { 0, 0 };

	ke::Vector<ke::AString> fileList;
	MasterReader.m_FileList = &fileList;

	err = textparsers->ParseSMCFile(path, &MasterReader, &state, error, maxlength);

	if (err != SMCError_Okay)
	{
		const char *msg = textparsers->GetSMCErrorString(err);

		AMXXLOG_Error("Error parsing master gameconf file \"%s\":", path);
		AMXXLOG_Error("Error %d on line %d, col %d: %s", err, state.line, state.col, msg ? msg : "Unknown error");

		return false;
	}

	for (size_t i = 0; i < fileList.length(); ++i)
	{
		g_LibSys.PathFormat(path, sizeof(path), "%s/%s", m_File, fileList[i].chars());

		if (!EnterFile(path, error, maxlength))
		{
			return false;
		}
	}

	build_pathname_r(path, sizeof(path), "%s/gamedata/%s/custom", dataDir, m_File);
	CDirectory *customDir = g_LibSys.OpenDirectory(path);

	if (!customDir)
	{
		return true;
	}

	while (customDir->MoreFiles())
	{
		if (!customDir->IsEntryFile())
		{
			customDir->NextEntry();
			continue;
		}

		const char *currentFile = customDir->GetEntryName();

		size_t length = strlen(currentFile);

		if (length > 4 && strcmp(&currentFile[length - 4], ".txt") != 0)
		{
			customDir->NextEntry();
			continue;
		}

		g_LibSys.PathFormat(path, sizeof(path), "%s/custom/%s", m_File, currentFile);

		if (!EnterFile(path, error, maxlength))
		{
			g_LibSys.CloseDirectory(customDir);
			return false;
		}

		AMXXLOG_Log("[AMXX] Parsed custom gamedata override file: %s", path);

		customDir->NextEntry();
	}

	g_LibSys.CloseDirectory(customDir);

	return true;
}