Jump to content

Small MSS Sound Scripts


Recommended Posts

  • Honorable Member

Hi everyone.

I'd like to share a small guide for the official .mss file. It is a new Token in the sound script files which is controlling the volume, if the Token has been set of course.
Couple of sound scripts are using this option:

Spoiler

956164a68a.png

0.0.) Make a backup of your files.
0.1.) Copying the codes from the board brings some invisible white characters with it, paste first into notepad++ and remove all the "?" characters.
1.0.) Open MilesLib/Type.h.
1.1.) Add the following variable to the two structured types by name: TSoundData and TSoundInstance.

		float fSoundVolume;

2.0.) Open MilesLib/Type.cpp.
2.1.) In the function by name "NSound::LoadSoundInformationPiece" look for the following code:

	int iCount;
	if (!rkTextFileLoader.GetTokenInteger("sounddatacount", &iCount))
	{
		SetResultString((strResult + " File format error, SoundDataCount Unable to find.").c_str());
		return false;
	}

2.2.) Paste the following below of it:

	float fVolume = 0.0f;
	if (rkTextFileLoader.GetTokenFloat("soundpositionenable", &fVolume))
	{
		SetResultString((strResult + " SoundPosition has checked.").c_str());
	}
	else
	{
		SetResultString((strResult + " SoundPosition has not checked.").c_str());
	}

2.3.) Bit scrolled down extend the for cycle like this:

	for (DWORD i = 0; i < rSoundDataVector.size(); ++i)
	{
		//Some random stuff
		//{}
		rSoundDataVector[i].fSoundVolume = fVolume;
	}

2.4.) At the bottom of the file you will find this function: "NSound::DataToInstance", extend the for cycle with this line:

		rSoundInstance.fSoundVolume = c_rSoundData.fSoundVolume;

3.0.) Open the MilesLib/SoundManager.h.
3.1.) Add a new argument to the definition of the "PlaySound2D" function:

void PlaySound2D(const char * c_szFileName, float fVolume = 0.0f);

4.0.) Open the MilesLib/SoundManager.cpp.
4.1.) Replace the function "PlaySound2D" with this:

void CSoundManager::PlaySound2D(const char * c_szFileName, float fVolume)
{
	if (0.0f == GetSoundVolume())
		return;

	ISoundInstance * pInstance;
	if (!GetSoundInstance2D(c_szFileName, &pInstance))
		return;

	float fNewVolume = fVolume;
	if (fVolume == 0.0f)
		fNewVolume = GetSoundVolume();
	pInstance->SetVolume(fNewVolume);
	pInstance->Play(1);
}

4.2.) Replace this function "CSoundManager::UpdateSoundInstance" with this:
<!> Attention: Of this function you will find two, be sure you will replace the correct one, check the arguments! I think the second one is not in used at all <!>

void CSoundManager::UpdateSoundInstance(float fx, float fy, float fz, DWORD dwcurFrame, const NSound::TSoundInstanceVector * c_pSoundInstanceVector, BOOL bCheckFrequency)
{
	for (DWORD i = 0; i < c_pSoundInstanceVector->size(); ++i)
	{
		const NSound::TSoundInstance & c_rSoundInstance = c_pSoundInstanceVector->at(i);
		if (c_rSoundInstance.dwFrame == dwcurFrame)
		{
			if (0.0f == c_rSoundInstance.fSoundVolume)
			{
				//Tracenf("PLAY SOUND %s", c_rSoundInstance.strSoundFileName.c_str());
				PlayCharacterSound3D(fx, fy, fz, c_rSoundInstance.strSoundFileName.c_str(), bCheckFrequency);
			}
			else
			{
				PlaySound2D(c_rSoundInstance.strSoundFileName.c_str(), c_rSoundInstance.fSoundVolume);
			}
		}
	}
}

 

Any problem occurs, post a comment below.

Edited by Metin2 Dev
Core X - External 2 Internal
  • Love 14
Link to comment
Share on other sites

  • Gold

@xP3NG3Rx Love you bro! :) Thanks for making client better. 

Btw. I'm not 100% sure if I extended two functions by the right way. Can you check it please?

Spoiler

bool NSound::LoadSoundInformationPiece(const char * c_szFileName, NSound::TSoundDataVector & rSoundDataVector, const char * c_szPathHeader)
{
	std::string strResult;
	strResult = c_szFileName;

	CTextFileLoader* pkTextFileLoader=CTextFileLoader::Cache(c_szFileName);
	if (!pkTextFileLoader)
		return false;

	CTextFileLoader& rkTextFileLoader=*pkTextFileLoader;
	if (rkTextFileLoader.IsEmpty())
	{
		SetResultString((strResult + " Ŕбâżë ĆÄŔĎŔ» ż­ Ľö ľřŔ˝").c_str());
		return false;
	}

	rkTextFileLoader.SetTop();

	int iCount;
	if (!rkTextFileLoader.GetTokenInteger("sounddatacount", &iCount))
	{
		SetResultString((strResult + " ĆÄŔĎ Ć÷¸ä żˇ·Ż, SoundDataCount¸¦ ĂŁŔ» Ľö ľřŔ˝").c_str());
		return false;
	}

	//START OF NEW MSS TOKEN SCRIPT
	float fVolume = 0.0f;

	if (rkTextFileLoader.GetTokenFloat("soundpositionenable", &fVolume))
	{
		SetResultString((strResult + " SoundPosition has checked.").c_str());
	}
	else
	{
		SetResultString((strResult + " SoundPosition has not checked.").c_str());
	}
	//END OF NEW MSS TOKEN SCRIPT

	rSoundDataVector.clear();
	rSoundDataVector.resize(iCount);

	char szSoundDataHeader[32+1];
	for (DWORD i = 0; i < rSoundDataVector.size(); ++i)
	{
		_snprintf(szSoundDataHeader, sizeof(szSoundDataHeader), "sounddata%02d", i);
		CTokenVector * pTokenVector;
		if (!rkTextFileLoader.GetTokenVector(szSoundDataHeader, &pTokenVector))
		{
			SetResultString((strResult + " ĆÄŔĎ Ć÷¸ä żˇ·Ż: " + szSoundDataHeader + " ¸¦ ĂŁŔ» Ľö ľřŔ˝").c_str());
			return false;
		}

		if (2 != pTokenVector->size())
		{
			SetResultString((strResult + " ĆÄŔĎ Ć÷¸ä żˇ·Ż: ş¤ĹÍ Ĺ©±â°ˇ 2°ˇ ľĆ´Ô").c_str());
			return false;
		}

		rSoundDataVector[i].fTime = (float) atof(pTokenVector->at(0).c_str());
		if (c_szPathHeader)
		{
			rSoundDataVector[i].strSoundFileName = c_szPathHeader;
			rSoundDataVector[i].strSoundFileName += pTokenVector->at(1).c_str();
		}
		else
		{
			rSoundDataVector[i].strSoundFileName = pTokenVector->at(1).c_str();
		}

		//START OF NEW MSS TOKEN SCRIPT
		rSoundDataVector[i].fSoundVolume = fVolume;
		//END OF NEW MSS TOKEN SCRIPT
	}

	SetResultString((strResult + " şŇ·ŻżČ").c_str());
	return true;
}

 

Spoiler

void NSound::DataToInstance(const TSoundDataVector & c_rSoundDataVector, TSoundInstanceVector * pSoundInstanceVector)
{
	if (c_rSoundDataVector.empty())
		return;

	DWORD dwFPS = 60;
	const float c_fFrameTime = 1.0f / float(dwFPS);

	pSoundInstanceVector->clear();
	pSoundInstanceVector->resize(c_rSoundDataVector.size());
	for (DWORD i = 0; i < c_rSoundDataVector.size(); ++i)
	{
		const TSoundData & c_rSoundData = c_rSoundDataVector[i];
		TSoundInstance & rSoundInstance = pSoundInstanceVector->at(i);

		rSoundInstance.dwFrame = (DWORD) (c_rSoundData.fTime / c_fFrameTime);
		rSoundInstance.strSoundFileName = c_rSoundData.strSoundFileName;

		//START OF NEW MSS TOKEN SCRIPT
		rSoundInstance.fSoundVolume = c_rSoundData.fSoundVolume;
		//END OF NEW MSS TOKEN SCRIPT
	}
}

 

Thanks for your answer! Keep the good work up!

I'll be always helpful! 👊 

Link to comment
Share on other sites

Announcements



×
×
  • Create New...

Important Information

Terms of Use / Privacy Policy / Guidelines / We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.