// setting name included in format string i.e. "sSomeSetting|newSettingValue"
bool Cmd_SetStringIniSetting_Execute(COMMAND_ARGS)
{
	char fmtString[kMaxMessageLength] = { 0 };
	*result = 0;

	if (ExtractFormatStringArgs(0, fmtString, PASS_FMTSTR_ARGS, kCommandInfo_SetStringGameSettingEX.numParams))
	{
		UInt32 pipePos = std::string(fmtString).find(GetSeparatorChar(scriptObj));
		if (pipePos != -1)
		{
			fmtString[pipePos] = 0;
			char* newValue = fmtString + pipePos + 1;

			Setting* setting = NULL;
			GameSettingCollection* gmsts = GameSettingCollection::GetSingleton();
			if (gmsts && gmsts->GetGameSetting(fmtString, &setting) && setting && setting->GetType() == Setting::kSetting_String)
			{
				setting->Set(newValue);;
				*result = 1;
			}
		}
	}

	return true;
}
bool Cmd_GetStringGameSetting_Execute(COMMAND_ARGS)
{
	char settingName[0x100] = { 0 };
	const char* settingString = "";

	if (ExtractArgs(EXTRACT_ARGS, &settingName))
	{
		Setting* setting = NULL;
		GameSettingCollection* gmsts = GameSettingCollection::GetSingleton();
		if (gmsts && gmsts->GetGameSetting(settingName, &setting) && setting && setting->GetType() == Setting::kSetting_String)
			setting->Get(settingString);
	}

	AssignToStringVar(PASS_COMMAND_ARGS, settingString);

	return true;
}
	void ParseTranslation(BSScaleformTranslator * translator, std::string & name)
	{
		Setting	* setting = GetINISetting("sLanguage:General");
		std::string path = "Interface\\Translations\\";

		// Construct translation filename
		path += name;
		path += "_";
		path += (setting && setting->GetType() == Setting::kType_String) ? setting->data.s : "ENGLISH";
		path += ".txt";

		BSResourceNiBinaryStream fileStream(path.c_str());
		if(!fileStream.IsValid())
			return;
		else
			_MESSAGE("Reading translations from %s...", path.c_str());

		// Check if file is empty, if not check if the BOM is UTF-16
		UInt16	bom = 0;
		UInt32	ret = fileStream.Read(&bom, sizeof(UInt16));
		if(ret == 0) {
			_MESSAGE("Empty translation file.");
			return;
		}
		if(bom != 0xFEFF) {
			_MESSAGE("BOM Error, file must be encoded in UCS-2 LE.");
			return;
		}

		while(true)
		{	
			wchar_t buf[512];

			UInt32	len = fileStream.ReadLine_w(buf, sizeof(buf) / sizeof(buf[0]), '\n');
			if(len == 0) // End of file
				return;

			// at least $ + wchar_t + \t + wchar_t
			if(len < 4 || buf[0] != '$')
				continue;

			wchar_t last = buf[len - 1];
			if(last == '\r')
				len--;

			// null terminate
			buf[len] = 0;

			UInt32 delimIdx = 0;
			for(UInt32 i = 0; i < len; i++)
				if(buf[i] == '\t')
					delimIdx = i;

			// at least $ + wchar_t
			if(delimIdx < 2)
				continue;

			// replace \t by \0
			buf[delimIdx] = 0;

			wchar_t * key = NULL;
			wchar_t * translation = NULL;
			BSScaleformTranslator::GetCachedString(&key, buf);
			BSScaleformTranslator::GetCachedString(&translation, &buf[delimIdx + 1]);
			TranslationTableItem item(key, translation);
			translator->translations.Add(&item);
		}
	}