--[[
AddConfig

Specialization for extended configurations and register new configurations.

Author:		Ifko[nator]
Date:		12.04.2020

Version:	v8.8

History:	v1.0 @ 28.02.2017 - initial implementation in FS 17 - added possibility to change capacity via configuration --## FS17 (removed)
			--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
			v2.0 @ 25.03.2017 - added possibility to change rim and axis color via configuration --## FS17 and FS 19
			--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
			v3.0 @ 21.07.2017 - added possibility to change fillable fill types and cutable fruit types via configuration --## FS17 (removed)
			--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
			v3.1 @ 13.12.2017 - a little bit code optimation --## FS17
			--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
			v3.2 @ 31.12.2017 - increased the limit from 64 to 134.217.728 configurations, i hope thats enough now! --## FS17
			--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
			v3.3 @ 04.03.2018 - the capacity value from the fillUnit in the xml file will now set to the new capacity to avoid fill the fill volume too fast or too slow --## FS17 (removed)
			--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
			v3.4 @ 04.07.2018 - added possibility to change the mass and possiblity to deactivate the fillable Spezi of an vehicle via configuration --## FS17 (removed)
			--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
			v3.9 BETA @ 07.01.2019 - first conversion to FS 19, current only color configs working! --## FS19
			--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
			v4.0 @ 10.01.2019 - added support for 'design' configurations and finish the conversion but this is currentlly still an TEST Version! --## FS19
			--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
			v4.2 @ 23.01.2019 - added support for default configurations and possibility to change the honk sound via configuration --## FS19
			--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
			v4.5 @ 27.01.2019 - added possibility to change the external sound file for motor sounds (wish from Unguided) --## FS19
			--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
			v4.6 @ 08.02.2019 - added possibility to change the beacon lights (wish from juli7250) --## FS19
			--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
			v4.7 @ 10.02.2019 - added possibility to make any vehicle selectable (wish from Ahran Modding) --## FS19
			--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
			v4.8 @ 12.02.2019 - fixed register of an exists configuration, script will stop now --## FS19
			--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
			v4.9 @ 05.03.2019 - fixed issue that additonial wheels won't be colered with color changes and added the TAG 'getColorFromConfig' to get the color from given config --## FS19
			--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
			v5.0 @ 17.06.2019 - fixed issue that th connectors from the additonial wheels won't be colered with color changes --## FS19
			--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
			v5.1 @ 08.08.2019 - added compatibility with the FSIconGenerator from GIANTS, so it will not crash anymore. You can't select the new configurations in the generator --## FS19
			--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
			v5.2 @ 23.08.2019 - added possibility to change the material in a new color configuration (thanks for the hint Unguided) --##FS19
			--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
			v5.3 @ 24.08.2019 - increased again the limit from 64 to 134.217.728 configurations --## FS19
			--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
			v5.5 @ 31.08.2019 - added compatibilty with some default configurations --## FS 19
			--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
			v5.7 @ 02.09.2019 - added possibility to change the color from top arm and starfire and filename from the top arm --##FS19
			--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
			v5.8 @ 08.09.2019 - added possibility to change the max forward speed and min forward gear ratio --##FS19
			--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
			v5.9 @ 18.09.2019 - added possibility to change ikChains via configuration --##FS19
			--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
			v6.0 @ 05.10.2019 - added support for strobe lights configuration --##FS19
			--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
			v6.1 @ 11.10.2019 - a little bit code optimation --## FS19
			--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
			v6.5 @ 16.10.2019 - added possibility to change the wheel filename --##FS19 (removed in v6.9 because this is not needed anymore!)
			--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
			v6.8 @ 04.11.2019 - added possibility to change the color from the screws of the wheels --##FS19
			--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
			v6.9 @ 11.12.2019 - added the TAG 'getRimColorFromConfig' to get the color for the rims from given config --##FS19
			--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
			v7.0 @ 29.12.2019 - removed possibility to set an configName with an 'Ö, Ä, Ü or ß' --##FS19
			--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
			v7.5 @ 13.03.2020 - added support to change the collisions mask of root components and support for adding cameras --##FS19
			--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
			v8.0 @ 18.03.2020 - added possibility to change the decal from the starfire --##FS19
			--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
			v8.5 @ 21.03.2020 - added possibility to change the 'additional' and 'normal' charachter --##FS19
			--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
			v8.6 @ 01.04.2020 - added possibility to change the typeDesc of an vehicle --##FS19
			--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
			v8.7 @ 04.04.2020 - added support to color the hubs to any color configuration, like it is possible with 'baseColor' --##FS19
			--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
			v8.8 @ 12.04.2020 - little script fix thanks to Unguided --##FS19
]]

AddConfig = {};

AddConfig.currentModDirectory = g_currentModDirectory;
AddConfig.currentModName = g_currentModName;
AddConfig.debugPriority = 0;
AddConfig.newConfgurations = {};

AddConfig.defaultChangeObjectsConfigurations = {
	"vehicleType",
	"attacherJoint",
	"motor",
	"frontloader",
	"powerTakeOff",
	"trailer",
	"tensionBelts",
	"pipe",
	"inputAttacherJoint",
	"cover",
	"folding",
	"fillUnit",
	"fillVolume",
	"wheel",
	"consumer",
	"ai",
	"dischargeable",
	"plow",
	"roller",
	"treeSaplingType",
	"variableWorkWidth",
	"workArea",
	"workMode",
	"differential"
};

AddConfig.defaultColorConfigurations = {
	"design",
	"design2",
	"design3",
	"design4",
	"design5",
	"design6",
	"design7",
	"design8",
	"baseMaterial",
	"designMaterial",
	"designMaterial2",
	"designMaterial3",
};

AddConfig.defaultColor1Configurations = {
	"baseColor",
	"designColor",
	"rimColor",
	"wrappingColor"
};

local function printError(errorMessage, isWarning, isInfo)
	local prefix = "::ERROR:: ";

	if isWarning then
		prefix = "::WARNING:: ";
	elseif isInfo then
		prefix = "::INFO:: ";
	end;

	print(prefix .. "from the AddConfig.lua: " .. tostring(errorMessage));
end;

local function printDebug(debugMessage, priority, addString)
	if AddConfig.debugPriority >= priority then
		local prefix = "";

		if addString then
			prefix = "::DEBUG:: from the AddConfig.lua: ";
		end;

		setFileLogPrefixTimestamp(false);
		print(prefix .. tostring(debugMessage));
		setFileLogPrefixTimestamp(true);
	end;
end;

function AddConfig.Logging_table(t)
    setFileLogPrefixTimestamp(false)

    local print_r_cache = {}
    if AddConfig.debugPriority == 2 then

        local function sub_print_r(t, indent)
            if (print_r_cache[tostring(t)]) then
                print(indent .. "*" .. tostring(t))
            else
                print_r_cache[tostring(t)] = true
                if (type(t) == "table") then
                    for pos, val in pairs(t) do
                        pos = tostring(pos)

                        if (type(val) == "table") then
                            print(indent .. "[" .. pos .. "] => " .. tostring(t) .. " {")
                            sub_print_r(val, indent .. string.rep(" ", string.len(pos) + 8))
                            print(indent .. string.rep(" ", string.len(pos) + 6) .. "}")
                        elseif (type(val) == "string") then
                            print(indent .. "[" .. pos .. '] => "' .. val .. '"')
                        else
                            print(indent .. "[" .. pos .. "] => " .. tostring(val))
                        end
                    end
                else
                    print(indent .. tostring(t))
                end
            end
        end

        if (type(t) == "table") then
            print(tostring(t) .. " {")
            sub_print_r(t, "  ")
            print("}")
        else
            sub_print_r(t, "  ")
        end

        print()
        
    else
    end

    setFileLogPrefixTimestamp(true)
end
if ConfigurationUtil.SEND_NUM_BITS < 27 then
	ConfigurationUtil.SEND_NUM_BITS = 27; --## = 134.217.728 possible configurations! I think, thats enough (2^27 = 134.217.728)!
	
	printError("Set max number of configurations to ".. g_i18n:formatNumber(2^ConfigurationUtil.SEND_NUM_BITS), false, true);
end;

function AddConfig.prerequisitesPresent(specializations)
    return true;
end

function AddConfig.registerEventListeners(vehicleType)
	local functionNames = {
		"onLoadFinished",
		"onPreLoad",
		"onUpdate"
	};

	for _, functionName in ipairs(functionNames) do
		SpecializationUtil.registerEventListener(vehicleType, functionName, AddConfig);
	end;
end;

function AddConfig.registerFunctions(vehicleType)
	local functionNames = {
		"setColor",
		"changeObjects",
		"initExtraOptions",
		"getConfigKey",
		"getXMLPrefix",
		"loadExtraOptions",
		"updateBeaconLightBlinking",
		"resetBeaconLightBlinking"
	};

	for _, functionName in ipairs(functionNames) do
		SpecializationUtil.registerFunction(vehicleType, functionName, AddConfig[functionName]);
	end;
end;


function AddConfig.registerOverwrittenFunctions(vehicleType)
	local overwrittenFunctionNames = {
		"getCanBeSelected"
	};

	for _, overwrittenFunctionName in ipairs(overwrittenFunctionNames) do
		SpecializationUtil.registerOverwrittenFunction(vehicleType, overwrittenFunctionName, AddConfig[overwrittenFunctionName]);
	end;
end;

function AddConfig.initSpecialization()
	local schema = Vehicle.xmlSchema

	schema:setXMLSpecializationType("addConfig")
	schema:register(XMLValueType.STRING, "vehicle.wheels.hubs.color0#getHubColorFromConfig", "getHubColor0FromConfig")
	schema:register(XMLValueType.STRING, "vehicle.wheels.hubs.color1#getHubColorFromConfig", "getHubColor1FromConfig")
	schema:register(XMLValueType.STRING, "vehicle.wheels.hubs.color2#getHubColorFromConfig", "getHubColor2FromConfig")
	schema:register(XMLValueType.STRING, "vehicle.wheels.hubs.color3#getHubColorFromConfig", "getHubColor3FromConfig")
	schema:register(XMLValueType.STRING, "vehicle.wheels.hubs.color4#getHubColorFromConfig", "getHubColor4FromConfig")
	schema:register(XMLValueType.STRING, "vehicle.wheels.hubs.color5#getHubColorFromConfig", "getHubColor5FromConfig")
	schema:register(XMLValueType.STRING, "vehicle.wheels.hubs.color6#getHubColorFromConfig", "getHubColor6FromConfig")
	schema:register(XMLValueType.STRING, "vehicle.wheels.hubs.color7#getHubColorFromConfig", "getHubColor7FromConfig")
	schema:register(XMLValueType.STRING, "vehicle.wheels.hubs.color0#shaderParameterName", "shaderParameterName0")
	schema:register(XMLValueType.STRING, "vehicle.wheels.hubs.color1#shaderParameterName", "shaderParameterName1")
	schema:register(XMLValueType.STRING, "vehicle.wheels.hubs.color2#shaderParameterName", "shaderParameterName2")
	schema:register(XMLValueType.STRING, "vehicle.wheels.hubs.color3#shaderParameterName", "shaderParameterName3")
	schema:register(XMLValueType.STRING, "vehicle.wheels.hubs.color4#shaderParameterName", "shaderParameterName4")
	schema:register(XMLValueType.STRING, "vehicle.wheels.hubs.color5#shaderParameterName", "shaderParameterName5")
	schema:register(XMLValueType.STRING, "vehicle.wheels.hubs.color6#shaderParameterName", "shaderParameterName6")
	schema:register(XMLValueType.STRING, "vehicle.wheels.hubs.color7#shaderParameterName", "shaderParameterName7")
	schema:setXMLSpecializationType()
	
	local modDesc = loadXMLFile("modDesc", AddConfig.currentModDirectory .. "modDesc.xml");
	local configNumber = 0;

	while true do
		local configKey = "modDesc.newConfigurations.newConfiguration(" .. tostring(configNumber) .. ")";

		if not hasXMLProperty(modDesc, configKey) then
			break;
		end;
		
		local newConfguration = {};

		newConfguration.isColorConfig = Utils.getNoNil(getXMLBool(modDesc, configKey .. "#isColorConfig"), false);
		newConfguration.isColorConfig2 = Utils.getNoNil(getXMLBool(modDesc, configKey .. "#isColorConfig2"), false);
		newConfguration.configName = Utils.getNoNil(getXMLString(modDesc, configKey .. "#configName"), "");
		newConfguration.title = g_i18n:getText("configuration_" .. Utils.getNoNil(getXMLString(modDesc, configKey .. "#useTitleFromConfig"),  newConfguration.configName));

		if newConfguration.configName ~= "" then 
			local function getIsValidConfigName(configName)
				if configName:len() == 0 then
					return false;
				end;
			
				if configName:find("%d") == 1 then
					return false;
				end;
				
				if configName:find("[^%w_]") ~= nil then
					return false;
				end;

				return true;
			end;

			if getIsValidConfigName(newConfguration.configName) then 
				if g_configurationManager.configurations[newConfguration.configName] == nil then	
					
					if newConfguration.isColorConfig then	
						--## config to change color on vehicle

						schema:setXMLSpecializationType("addConfig")
						printDebug("(newConfigurations) :: Register color configuration '" .. newConfguration.configName .. "' (title '" .. newConfguration.title .. "') successfully.", 1, true);
						AddConfig.registerXMLPaths(schema, "vehicle." .. newConfguration.configName .. "Configurations." .. newConfguration.configName .. "Configuration(?)")
						AddConfig.registerColorXMLPaths(schema, newConfguration.configName)
						ConfigurationUtil.registerColorConfigurationXMLPaths(schema, newConfguration.configName)
						ObjectChangeUtil.registerObjectChangeXMLPaths(schema, "vehicle." .. newConfguration.configName .. "Configurations." .. newConfguration.configName .. "Configuration(?)")
						schema:setXMLSpecializationType()

						g_configurationManager:addConfigurationType(newConfguration.configName, newConfguration.title, nil, nil, ConfigurationUtil.getConfigColorSingleItemLoad, ConfigurationUtil.getConfigColorPostLoad, ConfigurationUtil.SELECTOR_COLOR);
					elseif newConfguration.isColorConfig2 then	
						--## config to change color on vehicle

						schema:setXMLSpecializationType("addConfig")
						printDebug("(newConfigurations) :: Register color configuration '" .. newConfguration.configName .. "' (title '" .. newConfguration.title .. "') successfully.", 1, true);
						AddConfig.registerXMLPaths(schema, "vehicle." .. newConfguration.configName .. "Configurations." .. newConfguration.configName .. "Configuration(?)")
						AddConfig.registerColorXMLPaths(schema, newConfguration.configName)
						ConfigurationUtil.registerColorConfigurationXMLPaths(schema, newConfguration.configName)
						ObjectChangeUtil.registerObjectChangeXMLPaths(schema, "vehicle." .. newConfguration.configName .. "Configurations." .. newConfguration.configName .. "Configuration(?)")
						schema:setXMLSpecializationType()

						g_configurationManager:addConfigurationType(newConfguration.configName, newConfguration.title, nil, nil, ConfigurationUtil.getConfigColorSingleItemLoad, ConfigurationUtil.getConfigColorPostLoad, ConfigurationUtil.SELECTOR_MULTIOPTION);
					else
						--## config to change objects on vehicle

						schema:setXMLSpecializationType("addConfig")
						printDebug("(newConfigurations) :: Register multi option configuration '" .. newConfguration.configName .. "' (title '" .. newConfguration.title .. "') successfully.", 1, true);
						AddConfig.registerXMLPaths(schema, "vehicle." .. newConfguration.configName .. "Configurations." .. newConfguration.configName .. "Configuration(?)")
						-- ConfigurationUtil.registerColorConfigurationXMLPaths(schema, newConfguration.configName)
						ObjectChangeUtil.registerObjectChangeXMLPaths(schema, "vehicle." .. newConfguration.configName .. "Configurations." .. newConfguration.configName .. "Configuration(?)")
						schema:setXMLSpecializationType()

						g_configurationManager:addConfigurationType(newConfguration.configName, newConfguration.title, nil, nil, nil, nil, ConfigurationUtil.SELECTOR_MULTIOPTION);
					end;
				end;

				table.insert(AddConfig.newConfgurations, newConfguration);
			else
				printError("Invalid config name '" .. newConfguration.configName .. "'! Characters allowed: (_, A-Z, a-z, 0-9). Characters not allowed: (Ö, Ä, Ü, ß). The first character must not be a digit! Skipping this configuration now!", false, false);
			end;
		end;

		configNumber = configNumber + 1;
	end;

	delete(modDesc);
end;

function AddConfig.registerColorXMLPaths(schema, configurationName)
	local baseKey = string.format("vehicle.%sConfigurations", configurationName)

	schema:register(XMLValueType.STRING, baseKey .. ".material(?)#name", "Material name")
	schema:register(XMLValueType.STRING, baseKey .. ".material(?)#shaderParameter", "Material shader parameter")
	schema:register(XMLValueType.COLOR, baseKey .. ".material(?)#color", "Material color if it shouldn't be used from configuration")
	schema:register(XMLValueType.INT, baseKey .. ".material(?)#material", "Material id if it shouldn't be used from configuration")
	schema:register(XMLValueType.BOOL, baseKey .. ".material(?)#useContrastColor", "Use contrast color from configuration", false)
	schema:register(XMLValueType.FLOAT, baseKey .. ".material(?)#contrastThreshold", "Contrast color brightness threshold", 0.5)
end

function AddConfig.registerXMLPaths(schema, baseName)

end

function AddConfig.registerExtraOptionXMLPaths(schema, baseName)
	schema:register(XMLValueType.VECTOR_N, baseName .. "#beaconLightBlinkingSequences", "RUL BlinkSpeed")
	schema:register(XMLValueType.VECTOR_N, baseName .. "#beaconLightIndices", "RUL Index")
	
	schema:register(XMLValueType.INT, baseName .. "#fillUnit", "FillUnit", 1)
	schema:register(XMLValueType.BOOL, baseName .. "#setCoverOpen", "setCoverOpen")
	
	schema:register(XMLValueType.INT, baseName .. "#newCollisionMask", "newCollisionMask", -1)
	schema:register(XMLValueType.VECTOR_N, baseName .. "#componentIndices", "componentIndices")
	
	schema:register(XMLValueType.STRING, baseName .. "#honkSoundTemplate", "triggerPointSize")
	schema:register(XMLValueType.STRING, baseName .. "#honkSoundFilename", "triggerDistance")
	schema:register(XMLValueType.FLOAT, baseName .. "#honkSoundOuterRadius", "triggerDistance")
	schema:register(XMLValueType.FLOAT, baseName .. "#honkSoundInnerRadius", "triggerDistance")
	schema:register(XMLValueType.FLOAT, baseName .. "#honkSoundOuterVolume", "triggerDistance")
	schema:register(XMLValueType.FLOAT, baseName .. "#honkSoundInnerVolume", "triggerDistance")
	schema:register(XMLValueType.STRING, baseName .. "#externalMotorSoundFile", "triggerDistance")
	
	schema:register(XMLValueType.STRING, baseName .. "#beaconLightFilename", "triggerDistance")
	schema:register(XMLValueType.FLOAT, baseName .. "#beaconLightSpeed", "triggerDistance")
	
	schema:register(XMLValueType.STRING, baseName .. "#supportAnimationName", "triggerDistance")
	schema:register(XMLValueType.STRING, baseName .. "#changeConfigurationName", "triggerDistance")
	
	schema:register(XMLValueType.STRING, baseName .. "#topArmFilename", "triggerDistance")
	schema:register(XMLValueType.VECTOR_N, baseName .. "#attacherJointIndices", "triggerDistance")
	
	schema:register(XMLValueType.FLOAT, baseName .. "#maxForwardSpeed", "triggerDistance")
	schema:register(XMLValueType.VECTOR_N, baseName .. "#motorIndices", "triggerDistance")
	-- schema:register(XMLValueType.VECTOR_N, baseName .. "#motorIndices", "triggerDistance")
	
	schema:register(XMLValueType.STRING, baseName .. "#ikChain", "triggerDistance")
	schema:register(XMLValueType.STRING, baseName .. "#targetNode", "triggerDistance")
	
	schema:register(XMLValueType.STRING, baseName .. "#addCameraNode", "triggerDistance")
	schema:register(XMLValueType.STRING, baseName .. "#cameraTransMin", "triggerDistance", 0)
	schema:register(XMLValueType.FLOAT, baseName .. "#cameraTransMax", "triggerDistance", 2)
	schema:register(XMLValueType.FLOAT, baseName .. "#rotMinX", "triggerDistance", -1.1)
	schema:register(XMLValueType.FLOAT, baseName .. "#rotMaxX", "triggerDistance", 0.4)
	schema:register(XMLValueType.BOOL, baseName .. "#cameraUseWorldXZRotation", "triggerDistance", false)
	schema:register(XMLValueType.BOOL, baseName .. "#rotatable", "triggerDistance", false)
	schema:register(XMLValueType.BOOL, baseName .. "#limit", "triggerDistance", true)
	schema:register(XMLValueType.BOOL, baseName .. "#useDefaultPositionSmoothing", "triggerDistance", false)
	schema:register(XMLValueType.BOOL, baseName .. "#isInside", "triggerDistance", false)
	schema:register(XMLValueType.BOOL, baseName .. "#useMirror", "triggerDistance", false)
	schema:register(XMLValueType.INT, baseName .. "#cameraNumber", "triggerDistance", "")
	
	schema:register(XMLValueType.STRING, baseName .. ".additionalCharacter#node", "triggerDistance")
	schema:register(XMLValueType.FLOAT, baseName .. ".additionalCharacter#foldMinLimit", "triggerDistance")
	schema:register(XMLValueType.FLOAT, baseName .. ".additionalCharacter#foldMaxLimit", "triggerDistance")
	schema:register(XMLValueType.FLOAT, baseName .. ".additionalCharacter#cameraMinDistance", "triggerDistance")
	schema:register(XMLValueType.FLOAT, baseName .. ".additionalCharacter#spineRotation", "triggerDistance")
	schema:register(XMLValueType.STRING, baseName .. ".additionalCharacter.target(?)#ikChain", "triggerDistance")
	schema:register(XMLValueType.STRING, baseName .. ".additionalCharacter.target(?)#targetNode", "triggerDistance")
	
	schema:register(XMLValueType.STRING, baseName .. ".character#node", "triggerDistance")
	schema:register(XMLValueType.FLOAT, baseName .. ".character#foldMinLimit", "triggerDistance")
	schema:register(XMLValueType.FLOAT, baseName .. ".character#foldMaxLimit", "triggerDistance")
	schema:register(XMLValueType.FLOAT, baseName .. ".character#cameraMinDistance", "triggerDistance")
	schema:register(XMLValueType.FLOAT, baseName .. ".character#spineRotation", "triggerDistance")
	schema:register(XMLValueType.STRING, baseName .. ".character.target(?)#ikChain", "triggerDistance")
	schema:register(XMLValueType.STRING, baseName .. ".character.target(?)#targetNode", "triggerDistance")
	
	schema:register(XMLValueType.STRING, baseName .. "#newTypeDesc", "triggerDistance")
	schema:register(XMLValueType.STRING, baseName .. "#hubFilename", "triggerDistance")
	schema:register(XMLValueType.BOOL, baseName .. "#invertedTire", "triggerDistance")
	schema:register(XMLValueType.STRING, baseName .. "#fruitPreparerFruit", "triggerDistance")
	schema:register(XMLValueType.STRING, baseName .. "#fillTypeConverter", "triggerDistance")
	schema:register(XMLValueType.STRING, baseName .. "#wheelFilename", "triggerDistance")
	schema:register(XMLValueType.STRING, baseName .. "#foliageBendingModifier", "triggerDistance")


end

function AddConfig:onPreLoad(savegame)
	for _, newConfguration in pairs(AddConfig.newConfgurations) do
		if self.configurations[newConfguration.configName] ~= nil then
			local schema = Vehicle.xmlSchema

			schema:setXMLSpecializationType("addConfig")
			AddConfig.registerExtraOptionXMLPaths(schema, "vehicle." .. newConfguration.configName .. "Configurations." .. newConfguration.configName .. "Configuration(?).extraOption(?)")
			schema:setXMLSpecializationType()
		
			self:initExtraOptions(newConfguration.configName, self.configurations[newConfguration.configName], nil, false, false);
		end;
	end;

	for _, defaultChangeObjectsConfiguration in pairs(AddConfig.defaultChangeObjectsConfigurations) do
		if self.configurations[defaultChangeObjectsConfiguration] ~= nil then
			local prefix = self:getXMLPrefix(defaultChangeObjectsConfiguration)
			local schema = Vehicle.xmlSchema

			schema:setXMLSpecializationType("addConfig")
			AddConfig.registerExtraOptionXMLPaths(schema, "vehicle.".. prefix .. "Configurations." .. defaultChangeObjectsConfiguration .. "Configuration(?).extraOption(?)")
			schema:setXMLSpecializationType()
		
			self:initExtraOptions(self:getXMLPrefix(defaultChangeObjectsConfiguration), self.configurations[defaultChangeObjectsConfiguration], defaultChangeObjectsConfiguration, false, false);
		end;
	end;
	
	for _, defaultColorConfiguration in pairs(AddConfig.defaultColorConfigurations) do
		if self.configurations[defaultColorConfiguration] ~= nil then
			local prefix = self:getXMLPrefix(defaultColorConfiguration)
			local schema = Vehicle.xmlSchema

			schema:setXMLSpecializationType("addConfig")
			AddConfig.registerExtraOptionXMLPaths(schema, "vehicle.".. prefix .. "Configurations." .. defaultColorConfiguration .. "Configuration(?).extraOption(?)")
			schema:setXMLSpecializationType()
		
			self:initExtraOptions(self:getXMLPrefix(defaultColorConfiguration), self.configurations[defaultColorConfiguration], defaultColorConfiguration, false, false);
		end;
	end;
	for _, defaultColorConfiguration in pairs(AddConfig.defaultColor1Configurations) do
		if self.configurations[defaultColorConfiguration] ~= nil then
			local prefix = self:getXMLPrefix(defaultColorConfiguration)
			local schema = Vehicle.xmlSchema

			schema:setXMLSpecializationType("addConfig")
			AddConfig.registerExtraOptionXMLPaths(schema, "vehicle.".. prefix .. "Configurations." .. defaultColorConfiguration .. "Configuration(?).extraOption(?)")
			schema:setXMLSpecializationType()
		
			self:initExtraOptions(self:getXMLPrefix(defaultColorConfiguration), self.configurations[defaultColorConfiguration], defaultColorConfiguration, false, false);
		end;
	end;
end;

function AddConfig:onLoadFinished(savegame)
	local modDesc = loadXMLFile("modDesc", AddConfig.currentModDirectory .. "modDesc.xml");
	
	AddConfig.debugPriority = Utils.getNoNil(getXMLFloat(modDesc, "modDesc.newConfigurations#debugPriority"), AddConfig.debugPriority);
	
	delete(modDesc);
	
	for _, newConfguration in pairs(AddConfig.newConfgurations) do
		if self.configurations[newConfguration.configName] ~= nil then	
			printDebug("(newConfigurations) :: Found configuration '" .. newConfguration.configName .. "' in vehicle '" .. self.configFileName .. "'.", 1, true);

			if newConfguration.isColorConfig then
				--## config to change color on vehicle
				
				self:setColor(newConfguration.configName, self.configurations[newConfguration.configName]);
				self:applyBaseMaterialConfiguration(self.xmlFile, newConfguration.configName, self.configurations[newConfguration.configName]);
				self:applyBaseMaterial();
				self:changeObjects(newConfguration.configName, self.configurations[newConfguration.configName]);
			else
				--## config to change objects on vehicle
				
				self:changeObjects(newConfguration.configName, self.configurations[newConfguration.configName]);
			end;
		end;
	end;
	
	for _, defaultColorConfiguration in pairs(AddConfig.defaultColorConfigurations) do
		if self.configurations[defaultColorConfiguration] ~= nil then	
			--## config to change color on vehicle
			
			self:setColor(defaultColorConfiguration, self.configurations[defaultColorConfiguration]);
			self:changeObjects(self:getXMLPrefix(defaultColorConfiguration), self.configurations[defaultColorConfiguration], defaultColorConfiguration);
		end;
	end;

	for _, defaultColorConfiguration in pairs(AddConfig.defaultColor1Configurations) do
		if self.configurations[defaultColorConfiguration] ~= nil then	
			--## config to change color on vehicle
			
			self:setColor(defaultColorConfiguration, self.configurations[defaultColorConfiguration]);
		end;
	end;

	for _, defaultChangeObjectsConfiguration in pairs(AddConfig.defaultChangeObjectsConfigurations) do
		if self.configurations[defaultChangeObjectsConfiguration] ~= nil then
			--## config to change objects on vehicle
			
			self:changeObjects(self:getXMLPrefix(defaultChangeObjectsConfiguration), self.configurations[defaultChangeObjectsConfiguration], defaultChangeObjectsConfiguration);
		end;
	end;

	self.hasFinishedFirstRun = false;

	local specLights = self.spec_lights;

	if specLights ~= nil and #specLights.beaconLights > 0 then
		specLights.beaconLightsWasActive = false;
	end;

	for _, newConfguration in pairs(AddConfig.newConfgurations) do
		if self.configurations[newConfguration.configName] ~= nil then
			if not newConfguration.isColorConfig then	
				self:initExtraOptions(newConfguration.configName, self.configurations[newConfguration.configName], nil, false, true);
			end;
		end;
	end;

	for _, defaultChangeObjectsConfiguration in pairs(AddConfig.defaultChangeObjectsConfigurations) do
		if self.configurations[defaultChangeObjectsConfiguration] ~= nil then
			self:initExtraOptions(self:getXMLPrefix(defaultChangeObjectsConfiguration), self.configurations[defaultChangeObjectsConfiguration], defaultChangeObjectsConfiguration, false, true);
		end;
	end;

	for hubNumber = 0, 7 do
		local hubColorKey = string.format("vehicle.wheels.hubs.color%d", hubNumber);
		
		if self.xmlFile:hasProperty(hubColorKey) then
			local getHubColorFromConfig = Utils.getNoNil(self.xmlFile:getString(hubColorKey .. "#getHubColorFromConfig"), "");

			if getHubColorFromConfig ~= "" then
				if self.configurations[getHubColorFromConfig] ~= nil then
					local isColorConfig = false;
					local colorName;
					local shaderParameterName = Utils.getNoNil(self.xmlFile:getString(hubColorKey .. "#shaderParameterName"), "colorMat0");

					for _, newConfguration in pairs(AddConfig.newConfgurations) do
						if getHubColorFromConfig == newConfguration.configName then
							isColorConfig = newConfguration.isColorConfig;

							break;
						end;
					end;

					for _, defaultColorConfiguration in pairs(AddConfig.defaultColorConfigurations) do
						if getHubColorFromConfig == defaultColorConfiguration then
							isColorConfig = true;

							break;
						end;
					end;

					for _, defaultColorConfiguration in pairs(AddConfig.defaultColor1Configurations) do
						if getHubColorFromConfig == defaultColorConfiguration then
							isColorConfig = true;

							break;
						end;
					end;

					if isColorConfig then
						colorName = ConfigurationUtil.getColorByConfigId(self, getHubColorFromConfig, self.configurations[getHubColorFromConfig]);
					else
						printError("(colorChanges) :: The configuration '" .. getHubColorFromConfig .. "' is not an color configuration! Stop coloring wheel hubs!", false, true)
					end;

					if colorName ~= nil then
						for _, hub in pairs(self.spec_wheels.hubs) do
							if hub.node ~= nil then
								local r, g, b, _ = unpack(colorName);

								if materialId == nil then
									_, _, _, materialId = getShaderParameter(hub.node, shaderParameterName);
								end;

								setShaderParameter(hub.node, shaderParameterName, r, g, b, Utils.getNoNil(materialId, Utils.getNoNil(colorName[4], 0)), false);

								printDebug("(colorChanges) :: Change hub color successfully in '" .. self.configFileName .. "'.", 1, true);
							end;
						end;
					end;
				end;
			end;
		end;
	end;
end;

function AddConfig:getCanBeSelected(superFunc)
	--## Make any Vehicle, wich has the script, selectable

	return true;
end;

function AddConfig:onUpdate(dt, isActiveForInput, isActiveForInputIgnoreSelection, isSelected)
	if not self.hasFinishedFirstRun then
		for _, newConfguration in pairs(AddConfig.newConfgurations) do
			if self.configurations[newConfguration.configName] ~= nil then
				if not newConfguration.isColorConfig then	
					self:initExtraOptions(newConfguration.configName, self.configurations[newConfguration.configName], nil, true, false);
				end;
			end;
		end;

		for _, defaultChangeObjectsConfiguration in pairs(AddConfig.defaultChangeObjectsConfigurations) do
			if self.configurations[defaultChangeObjectsConfiguration] ~= nil then
				self:initExtraOptions(self:getXMLPrefix(defaultChangeObjectsConfiguration), self.configurations[defaultChangeObjectsConfiguration], defaultChangeObjectsConfiguration, true, false);
			end;
		end;

		for _, defaultColorConfiguration in pairs(AddConfig.defaultColorConfigurations) do
			if self.configurations[defaultColorConfiguration] ~= nil then
				self:initExtraOptions(self:getXMLPrefix(defaultColorConfiguration), self.configurations[defaultColorConfiguration], defaultColorConfiguration, true, false);
			end;
		end;

		self.hasFinishedFirstRun = true;
	end;

	local specLights = self.spec_lights;

	if specLights ~= nil and #specLights.beaconLights > 0 then
		if self.getIsMotorStarted ~= nil then
			if not self:getIsMotorStarted() then
				if specLights.beaconLightsActive then
					specLights.beaconLightsWasActive = true;

					self:setBeaconLightsVisibility(false, true, nil);
				end;
			else
				if specLights.beaconLightsWasActive then
					self:setBeaconLightsVisibility(true, true, nil);

					specLights.beaconLightsWasActive = false;
				end;
			end;
		end;

		if specLights.beaconLightsActive then
			for _, newConfguration in pairs(AddConfig.newConfgurations) do
				if self.configurations[newConfguration.configName] ~= nil then
					if not newConfguration.isColorConfig then
						local extraOptionNumber = 0;
						
						while true do
							local configKey = self:getConfigKey(newConfguration.configName, self.configurations[newConfguration.configName], nil) .. ".extraOption(" .. tostring(extraOptionNumber) .. ")";
							
							if self.xmlFile:hasProperty(configKey .. "#beaconLightBlinkingSequences") then
								local beaconLightBlinkingSequences = {string.getVector(self.xmlFile:getString(configKey .. "#beaconLightBlinkingSequences"))};
								local beaconLightIndices = {string.getVector(self.xmlFile:getString(configKey .. "#beaconLightIndices"))};
								AddConfig.Logging_table(beaconLightIndices)
									
								if #beaconLightIndices > 0 then
									for _, beaconLightIndice in pairs(beaconLightIndices) do
										self:updateBeaconLightBlinking(beaconLightBlinkingSequences, beaconLightIndice, dt, specLights.beaconLights);
									end;
								else
									self:updateBeaconLightBlinking(beaconLightBlinkingSequences, extraOptionNumber + 1, dt, specLights.beaconLights);
								end;
							else
								break;
							end;
							
							extraOptionNumber = extraOptionNumber + 1;
						end;
					end;
				end;
			end;

			for _, defaultChangeObjectsConfiguration in pairs(AddConfig.defaultChangeObjectsConfigurations) do
				if self.configurations[defaultChangeObjectsConfiguration] ~= nil then
					local extraOptionNumber = 0;
					
					while true do
						local configKey = self:getConfigKey(self:getXMLPrefix(defaultChangeObjectsConfiguration), self.configurations[defaultChangeObjectsConfiguration], defaultChangeObjectsConfiguration) .. ".extraOption(" .. tostring(extraOptionNumber) .. ")";
						
						if self.xmlFile:hasProperty(configKey .. "#beaconLightBlinkingSequences") then
							local beaconLightBlinkingSequences = {string.getVector(self.xmlFile:getString(configKey .. "#beaconLightBlinkingSequences"))};
							local beaconLightIndices = {string.getVector(self.xmlFile:getString(configKey .. "#beaconLightIndices"))};
							AddConfig.Logging_table(beaconLightIndices)
							if #beaconLightIndices > 0 then
								for _, beaconLightIndice in pairs(beaconLightIndices) do
									self:updateBeaconLightBlinking(beaconLightBlinkingSequences, beaconLightIndice, dt, specLights.beaconLights);
								end;
							else
								self:updateBeaconLightBlinking(beaconLightBlinkingSequences, extraOptionNumber + 1, dt, specLights.beaconLights);
							end;
						else
							break;
						end;
						
						extraOptionNumber = extraOptionNumber + 1;
					end;
				end;
			end;

			specLights.hasResetBeaconLightBlinking = false;
		else
			if not specLights.hasResetBeaconLightBlinking then	
				self:resetBeaconLightBlinking(specLights.beaconLights);

				specLights.hasResetBeaconLightBlinking = true;
			end;
		end;
	end;
end;

function AddConfig:updateBeaconLightBlinking(beaconLightBlinkingSequences, beaconLightIndice, dt, beaconLights)
	for beaconLightNumber, beaconLight in pairs(beaconLights) do
		if beaconLightNumber == beaconLightIndice then	
			beaconLight.blinkingSequences = beaconLightBlinkingSequences;
			if #beaconLight.blinkingSequences > 0 then
				if beaconLight.doBlinking == nil then
					beaconLight.doBlinking = false;
				end;
			
				if beaconLight.blinkingTime == nil then
					beaconLight.blinkingTime = 0;
				end;

				if beaconLight.sequence == nil then 
					beaconLight.sequence = 1;
				end;
			
				if beaconLight.blinkingSpeed == nil then
					beaconLight.blinkingSpeed = beaconLight.blinkingSequences[beaconLight.sequence];
				end;
				
				if beaconLight.blinkingTime > beaconLight.blinkingSpeed then
					beaconLight.doBlinking = not beaconLight.doBlinking;

					if beaconLight.realLightNode ~= nil then
						setVisibility(beaconLight.realLightNode, g_gameSettings:getValue("realBeaconLights") and beaconLight.doBlinking and beaconLight.blinkingSpeed > 0);
					end;
				
					if beaconLight.lightNode ~= nil then
						setVisibility(beaconLight.lightNode, beaconLight.doBlinking and beaconLight.blinkingSpeed > 0);
					end;
				
					if beaconLight.lightShaderNode ~= nil then
						local value = 1 * beaconLight.intensity;

						if not beaconLight.doBlinking or beaconLight.blinkingSpeed == 0 then
							value = 0;
						end;

						local _, y, z, w = getShaderParameter(beaconLight.lightShaderNode, "lightControl");
					
						setShaderParameter(beaconLight.lightShaderNode, "lightControl",  value, y, z, w, false);
					end;

					beaconLight.blinkingTime = 0;
					beaconLight.sequence = beaconLight.sequence + 1;
					
					if beaconLight.sequence > #beaconLight.blinkingSequences then
						beaconLight.sequence = 1;
					end;

					beaconLight.blinkingSpeed = beaconLight.blinkingSequences[beaconLight.sequence];
				else
					beaconLight.blinkingTime = beaconLight.blinkingTime + dt;
				end;
			end;
		end;
	end;
end;

function AddConfig:resetBeaconLightBlinking(beaconLights)
	for _, beaconLight in pairs(beaconLights) do
		beaconLight.doBlinking = false;
		beaconLight.blinkingTime = 0;
		beaconLight.sequence = 1;

		if beaconLight.realLightNode ~= nil then
			setVisibility(beaconLight.realLightNode, false);
		end;

		if beaconLight.lightNode ~= nil then
			setVisibility(beaconLight.lightNode, false);
		end;

		if beaconLight.lightShaderNode ~= nil then
			local _, y, z, w = getShaderParameter(beaconLight.lightShaderNode, "lightControl");
		
			setShaderParameter(beaconLight.lightShaderNode, "lightControl",  0, y, z, w, false);
		end;
	end;
end;

function AddConfig:getXMLPrefix(configName)
	local prefix = "";
	
	if configName == "motor" 
		or configName == "consumer" 
		or configName == "differential" 
	then
		prefix = "motorized.";
	elseif configName == "fillUnit" 
		or configName == "fillVolume"
		or configName == "trailer"
		or configName == "tensionBelts"
		or configName == "cover"
		or configName == "pipe"
		or configName == "variableWorkWidth"
	then
		prefix = configName .. ".";
	elseif configName == "attacherJoint" 
		or configName == "powerTakeOff"
		or configName == "wheel"
		or configName == "workArea"
		or configName == "workMode"
	then
		prefix = configName .. "s.";
	elseif configName == "inputAttacherJoint" then
		prefix = "attachable.";
	elseif configName == "folding" then
		prefix = "foldable.";
	elseif configName == "treeSaplingType" then
		prefix = "treeSaplingPallet.";
	end;
	
	return prefix .. configName;
end;

function AddConfig:getConfigKey(configName, configId, secondConfigName)
	if secondConfigName == nil then
		secondConfigName = configName;
	end;

	local configKey = string.format("vehicle." .. configName .. "Configurations." .. secondConfigName .. "Configuration(%d)", configId - 1);

	if not self.xmlFile:hasProperty(configKey) then
        printError("(getConfigKey) :: Invalid " .. configName .. " configuration " .. configId .. " (key = " .. configKey .. ")", true, false);
        
		return "noKeyFound";
	end;

	return configKey;
end;

function AddConfig:loadExtraOptions(configKey, extraOptionNeedUpdate, extraOptionOnLoad)
	local extraOptionNumber = 0;

	while true do
		local extraOptionKey = string.format(configKey .. ".extraOption(%d)", extraOptionNumber);

	   	if not self.xmlFile:hasProperty(extraOptionKey) then
		   break;
	   	end;

		if extraOptionNeedUpdate then   
			local coverFillUnit = Utils.getNoNil(self.xmlFile:getInt(extraOptionKey .. "#fillUnit"), 1);
			local setCoverOpen = self.xmlFile:getBool(extraOptionKey .. "#setCoverOpen");
			   
			if self.spec_cover ~= nil and setCoverOpen ~= nil then
				self:setCoverState(coverFillUnit, setCoverOpen);
 
				printDebug("(loadExtraOptions) :: Open cover state is '" .. tostring(setCoverOpen) .. "'." , 1, true);
			end;

		elseif extraOptionOnLoad then
			local newCollisionMask = Utils.getNoNil(self.xmlFile:getInt(extraOptionKey .. "#newCollisionMask"), -1);

			if newCollisionMask > -1 then
				local componentIndices = {string.getVector(self.xmlFile:getString(extraOptionKey .. "#componentIndices"))};

				if #componentIndices > 0 then
					for _, componentIndice in pairs(componentIndices) do
						if self.components[componentIndice].node ~= nil then	
							setCollisionMask(self.components[componentIndice].node, newCollisionMask);

							printDebug("(loadExtraOptions) :: Set collision mask to '" .. tostring(newCollisionMask) .. "' for index '" .. componentIndice .. ">'." , 1, true);
						end;
					end;
				end;
			end;
		else
	  		local honkSoundTemplate = string.upper(Utils.getNoNil(self.xmlFile:getString(extraOptionKey .. "#honkSoundTemplate"), ""));
			local honkSoundFilename = Utils.getNoNil(self.xmlFile:getString(extraOptionKey .. "#honkSoundFilename"), "");
			local honkSoundOuterRadius = Utils.getNoNil(self.xmlFile:getFloat(extraOptionKey .. "#honkSoundOuterRadius"), "");
			local honkSoundInnerRadius = Utils.getNoNil(self.xmlFile:getFloat(extraOptionKey .. "#honkSoundInnerRadius"), "");
			local honkSoundOuterVolume = Utils.getNoNil(self.xmlFile:getFloat(extraOptionKey .. "#honkSoundOuterVolume"), "");
			local honkSoundInnerVolume = Utils.getNoNil(self.xmlFile:getFloat(extraOptionKey .. "#honkSoundInnerVolume"), "");
			local externalMotorSoundFile = Utils.getNoNil(self.xmlFile:getString(extraOptionKey .. "#externalMotorSoundFile"), "");
			local beaconLightFilename = Utils.getNoNil(self.xmlFile:getString(extraOptionKey .. "#beaconLightFilename"), "");
			local supportAnimationName = Utils.getNoNil(self.xmlFile:getString(extraOptionKey .. "#supportAnimationName"), "");
			local changeConfigurationName = Utils.getNoNil(self.xmlFile:getString(extraOptionKey .. "#changeConfigurationName"), "");
			local topArmFilename = Utils.getNoNil(self.xmlFile:getString(extraOptionKey .. "#topArmFilename"), "");
			local maxForwardSpeed = Utils.getNoNil(self.xmlFile:getFloat(extraOptionKey .. "#maxForwardSpeed"), "");
			local ikChain = Utils.getNoNil(self.xmlFile:getString(extraOptionKey .. "#ikChain"), "");
			local addCamera = Utils.getNoNil(self.xmlFile:getString(extraOptionKey .. "#addCameraNode"), "");
			local additionalCharacterNode = Utils.getNoNil(self.xmlFile:getString(extraOptionKey .. ".additionalCharacter#node"), "");
			local characterNode = Utils.getNoNil(self.xmlFile:getString(extraOptionKey .. ".character#node"), "");
			local newTypeDesc = Utils.getNoNil(self.xmlFile:getString(extraOptionKey .. "#newTypeDesc"), "");
			local hubFilename = Utils.getNoNil(self.xmlFile:getString(extraOptionKey .. "#hubFilename"), "");
			local wheelInvertedTire = Utils.getNoNil(self.xmlFile:getString(extraOptionKey .. "#invertedTire"), "");
			local fruitPreparerFruit = Utils.getNoNil(self.xmlFile:getString(extraOptionKey .. "#fruitPreparerFruit"), "");
			local fillTypeConverter = Utils.getNoNil(self.xmlFile:getString(extraOptionKey .. "#fillTypeConverter"), "");
			local wheelFilename = Utils.getNoNil(self.xmlFile:getString(extraOptionKey .. "#wheelFilename"), "");
			local foliageBendingModifier = Utils.getNoNil(self.xmlFile:getString(extraOptionKey .. "#foliageBendingModifier"), "");

			if newTypeDesc ~= "" then
				self.xmlFile:setString("vehicle.base.typeDesc", newTypeDesc);

				printDebug("(extraOptions) :: Set 'typeDesc' to " .. newTypeDesc .. ".", 1, true);
			end;

			if characterNode ~= "" then
				self.xmlFile:setString("vehicle.enterable.character#node", characterNode);

				printDebug("(extraOptions) :: Set character 'node' to " .. characterNode .. ".", 1, true);

				local foldMinLimit = Utils.getNoNil(self.xmlFile:getFloat(extraOptionKey .. ".character#foldMinLimit"), "");
				local foldMaxLimit = Utils.getNoNil(self.xmlFile:getFloat(extraOptionKey .. ".character#foldMaxLimit"), "");
				local cameraMinDistance = Utils.getNoNil(self.xmlFile:getFloat(extraOptionKey .. ".character#foldMaxLimit"), "");
				local spineRotation = Utils.getNoNil(self.xmlFile:getString(extraOptionKey .. ".character#spineRotation"), "");

				if foldMinLimit ~= "" then
					self.xmlFile:setFloat("vehicle.enterable.character#foldMinLimit", foldMinLimit);

					printDebug("(extraOptions) :: Set character 'foldMinLimit' to " .. foldMinLimit .. ".", 1, true);
				end;

				if foldMaxLimit ~= "" then
					self.xmlFile:setFloat("vehicle.enterable.character#foldMaxLimit", foldMaxLimit);

					printDebug("(extraOptions) :: Set character 'foldMaxLimit' to " .. foldMaxLimit .. ".", 1, true);
				end;

				if cameraMinDistance ~= "" then
					self.xmlFile:setString("vehicle.enterable.character#cameraMinDistance", cameraMinDistance);

					printDebug("(extraOptions) :: Set character 'cameraMinDistance' to " .. cameraMinDistance .. ".", 1, true);
				end;

				if spineRotation ~= "" then
					self.xmlFile:setString("vehicle.enterable.character#spineRotation", spineRotation);

					printDebug("(extraOptions) :: Set character 'spineRotation' to " .. spineRotation .. ".", 1, true);
				end;
				
				local targetNumber = 0;
				
				while true do
					local targetKey = extraOptionKey .. ".character.target(" .. tostring(targetNumber) .. ")";
					
					if not self.xmlFile:hasProperty(targetKey) then
						break;
					end;
					
					local ikChain = Utils.getNoNil(self.xmlFile:getString(targetKey .. "#ikChain"), "");
					local targetNode = Utils.getNoNil(self.xmlFile:getString(targetKey .. "#targetNode"), "");
					
					if ikChain ~= "" and targetNode ~= "" then
						self.xmlFile:setString("vehicle.enterable.character.target(" .. tostring(targetNumber) .. ")#ikChain", ikChain);
						self.xmlFile:setString("vehicle.enterable.character.target(" .. tostring(targetNumber) .. ")#targetNode", targetNode);
						
						printDebug("(extraOptions) :: Set character 'ikChain' to " .. ikChain .. ".", 1, true);
						printDebug("(extraOptions) :: Set character 'targetNode' to " .. targetNode .. ".", 1, true);
					else
						printError("(extraOptions) :: Missing 'ikChain' or 'targetNode' in '" .. targetKey .. "' Stop changeing character!", true, false);
					end;

					targetNumber = targetNumber + 1;
				end;
			end;

			if additionalCharacterNode ~= "" then
				self.xmlFile:setString("vehicle.enterable.additionalCharacter#node", additionalCharacterNode);

				printDebug("(extraOptions) :: Set additional character 'node' to " .. additionalCharacterNode .. ".", 1, true);

				local foldMinLimit = Utils.getNoNil(self.xmlFile:getFloat(extraOptionKey .. ".additionalCharacter#foldMinLimit"), "");
				local foldMaxLimit = Utils.getNoNil(self.xmlFile:getFloat(extraOptionKey .. ".additionalCharacter#foldMaxLimit"), "");
				local cameraMinDistance = Utils.getNoNil(self.xmlFile:getFloat(extraOptionKey .. ".additionalCharacter#foldMaxLimit"), "");
				local spineRotation = Utils.getNoNil(self.xmlFile:getString(extraOptionKey .. ".additionalCharacter#spineRotation"), "");

				if foldMinLimit ~= "" then
					self.xmlFile:setFloat("vehicle.enterable.additionalCharacter#foldMinLimit", foldMinLimit);

					printDebug("(extraOptions) :: Set additional character 'foldMinLimit' to " .. foldMinLimit .. ".", 1, true);
				end;

				if foldMaxLimit ~= "" then
					self.xmlFile:setFloat("vehicle.enterable.additionalCharacter#foldMaxLimit", foldMaxLimit);

					printDebug("(extraOptions) :: Set additional character 'foldMaxLimit' to " .. foldMaxLimit .. ".", 1, true);
				end;

				if cameraMinDistance ~= "" then
					self.xmlFile:setFloat("vehicle.enterable.additionalCharacter#cameraMinDistance", cameraMinDistance);

					printDebug("(extraOptions) :: Set additional character 'cameraMinDistance' to " .. cameraMinDistance .. ".", 1, true);
				end;

				if spineRotation ~= "" then
					self.xmlFile:setString("vehicle.enterable.additionalCharacter#spineRotation", spineRotation);

					printDebug("(extraOptions) :: Set additional character 'spineRotation' to " .. spineRotation .. ".", 1, true);
				end;

				local targetNumber = 0;
				
				while true do
					local targetKey = extraOptionKey .. ".additionalCharacter.target(" .. tostring(targetNumber) .. ")";
					
					if not self.xmlFile:hasProperty(targetKey) then
						break;
					end;
					
					local ikChain = Utils.getNoNil(self.xmlFile:getString(targetKey .. "#ikChain"), "");
					local targetNode = Utils.getNoNil(self.xmlFile:getString(targetKey .. "#targetNode"), "");
					
					if ikChain ~= "" and targetNode ~= "" then
						self.xmlFile:setString("vehicle.enterable.additionalCharacter.target(" .. tostring(targetNumber) .. ")#ikChain", ikChain);
						self.xmlFile:setString("vehicle.enterable.additionalCharacter.target(" .. tostring(targetNumber) .. ")#targetNode", targetNode);
						
						printDebug("(extraOptions) :: Set additional character 'ikChain' to " .. ikChain .. ".", 1, true);
						printDebug("(extraOptions) :: Set additional character 'targetNode' to " .. targetNode .. ".", 1, true);
					else
						printError("(extraOptions) :: Missing 'ikChain' or 'targetNode' in '" .. targetKey .. "' Stop changeing additional character!", true, false);
					end;

					targetNumber = targetNumber + 1;
				end;
			end;

			if addCamera ~= "" then
				local transMin = Utils.getNoNil(self.xmlFile:getFloat(extraOptionKey .. "#cameraTransMin"), 0);
				local transMax = Utils.getNoNil(self.xmlFile:getFloat(extraOptionKey .. "#cameraTransMax"), 2);
				local rotMinX = Utils.getNoNil(self.xmlFile:getFloat(extraOptionKey .. "#rotMinX"), -1.1);
				local rotMaxX = Utils.getNoNil(self.xmlFile:getFloat(extraOptionKey .. "#rotMaxX"), 0.4);

				local useWorldXZRotation = Utils.getNoNil(self.xmlFile:getBool(extraOptionKey .. "#cameraUseWorldXZRotation"), false);
				local rotatable = Utils.getNoNil(self.xmlFile:getBool(extraOptionKey .. "#rotatable"), false);
				local limit = Utils.getNoNil(self.xmlFile:getBool(extraOptionKey .. "#limit"), true);
				local useDefaultPositionSmoothing = Utils.getNoNil(self.xmlFile:getBool(extraOptionKey .. "#useDefaultPositionSmoothing"), false);
				local isInside = Utils.getNoNil(self.xmlFile:getBool(extraOptionKey .. "#isInside"), false);
				local useMirror = Utils.getNoNil(self.xmlFile:getBool(extraOptionKey .. "#useMirror"), false);
				
				local cameraNumber = Utils.getNoNil(self.xmlFile:getInt(extraOptionKey .. "#cameraNumber"), "");

				if cameraNumber == "" then
					printError("(extraOptions) :: Missing 'cameraNumber' for '" .. addCamera .. "' in '" .. extraOptionKey .. "' Using default value '3' instead! This could mess up your cameras!", true, false);

					cameraNumber = 3;
				end;

				local floatTable = {
					transMax = transMax, 
					transMin = transMin, 
					rotMinX = rotMinX, 
					rotMaxX = rotMaxX,
				};

				for tag, value in pairs(floatTable) do
					self.xmlFile:setFloat("vehicle.enterable.cameras.camera(" .. cameraNumber - 1 .. ")#" .. tag, value);

					printDebug("(extraOptions) :: Set camera tag '" .. tag .. "' to " .. tostring(value) .. ".", 1, true);
				end;

				local boolTable = {
					useWorldXZRotation = useWorldXZRotation, 
					rotatable = rotatable, 
					limit = limit, 
					useDefaultPositionSmoothing = useDefaultPositionSmoothing, 
					isInside = isInside, 
					useMirror = useMirror
				}; 

				for tag, value in pairs(boolTable) do
					self.xmlFile:setBool("vehicle.enterable.cameras.camera(" .. cameraNumber - 1 .. ")#" .. tag, value);

					printDebug("(extraOptions) :: Set camera tag '" .. tag .. "' to " .. tostring(value) .. ".", 1, true);
				end;

				self.xmlFile:setString("vehicle.enterable.cameras.camera(" .. cameraNumber - 1 .. ")#node", addCamera);
				
				printDebug("(extraOptions) :: Add camera '" .. addCamera .. "'.", 1, true);
			end;


			if ikChain ~= "" then
				local targetNode = Utils.getNoNil(self.xmlFile:getString(extraOptionKey .. "#targetNode"), "");

				if targetNode ~= "" then
					local ikChainNumber = 0;

					while true do
						local ikChainKey = "vehicle.enterable.characterNode.target(" .. tostring(ikChainNumber) .. ")";

						if not self.xmlFile:hasProperty(ikChainKey) then
							break;
						end;

						local ikChainOld = self.xmlFile:getString(ikChainKey .. "#ikChain");

						if ikChain == ikChainOld then
							local targetNodeOld = self.xmlFile:getString(ikChainKey .. "#targetNode");
							local characterTargetNodeModifier = self.xmlFile:getString("vehicle.enterable.characterTargetNodeModifier#node");
							local stateNodeIndices = {string.getVector(self.xmlFile:getString(extraOptionKey .. "#stateNodeIndices"))};

							if #stateNodeIndices > 0 then
								printDebug("(extraOptions) :: targetNodeOld = '" .. targetNodeOld .. "' vs characterTargetNodeModifier = '" .. characterTargetNodeModifier .. "'.", 2, true);

								if characterTargetNodeModifier == targetNodeOld then
									local stateNode = Utils.getNoNil(self.xmlFile:getString(extraOptionKey .. "#stateNode"), "");
									local referenceNode = Utils.getNoNil(self.xmlFile:getString(extraOptionKey .. "#referenceNode"), "");

									if stateNode ~= "" and referenceNode ~= "" then
										self.xmlFile:setString("vehicle.enterable.characterTargetNodeModifier#node", targetNode);

										printDebug("(extraOptions) :: Set characterTargetNodeModifier target node to '" .. targetNode .. "'.", 1, true);

										for _, stateNodeIndice in pairs(stateNodeIndices) do
											local stateNodeKey = "vehicle.enterable.characterTargetNodeModifier.state(" .. tostring(stateNodeIndice - 1) .. ")";

											if self.xmlFile:hasProperty(stateNodeKey) then	
												self.xmlFile:setString(stateNodeKey .. "#node", stateNode);
												self.xmlFile:setString(stateNodeKey .. "#referenceNode", referenceNode);

												printDebug("(extraOptions) :: Set state(" .. tostring(stateNodeIndice) .. ") node to '" .. stateNode .. "'.", 1, true);
												printDebug("(extraOptions) :: Set state(" .. tostring(stateNodeIndice) .. ") referenceNode to '" .. referenceNode .. "'.", 1, true);
											end;
										end;
									else
										if stateNode == "" then
											printError("(extraOptions) :: Missing 'stateNode' TAG for vehicle '" .. self.configFileName .. "'! Stop change ikChain!", true, false);
										else
											printError("(extraOptions) :: Missing 'referenceNode' TAG for vehicle '" .. self.configFileName .. "'! Stop change ikChain!", true, false);
										end;
									end;
								end;

								self.xmlFile:setString(ikChainKey .. "#targetNode", targetNode);

								printDebug("(extraOptions) :: Set characterNode target node to '" .. targetNode .. "'.", 1, true);

								break;
							else
								printError("(extraOptions) :: Missing 'stateNodeIndices' TAG for vehicle '" .. self.configFileName .. "'! Stop change ikChain!", true, false);
							end;
						end;

						ikChainNumber = ikChainNumber + 1;
					end; 
				end;
			end;

			if maxForwardSpeed ~= "" then
				local motorIndices = {string.getVector(self.xmlFile:getString(extraOptionKey .. "#motorIndices"))};

				if #motorIndices > 0 then
					for _, motorIndice in pairs(motorIndices) do
						local motorKey = string.format("vehicle.motorized.motorConfigurations.motorConfiguration(" .. tostring(motorIndice - 1) .. ")");

						if self.xmlFile:hasProperty(motorKey) then
							self.xmlFile:setFloat(motorKey .. ".motor#maxForwardSpeed", maxForwardSpeed);

							printDebug("(extraOptions) :: Set motor config(" .. tostring(motorIndice) .. ") max forward speed to '" .. maxForwardSpeed .. "'.", 1, true);

							local minForwardGearRatio = Utils.getNoNil(self.xmlFile:getFloat(extraOptionKey .. "#minForwardGearRatio"), "");

							if minForwardGearRatio ~= "" then
								local gearRatioKey = motorKey .. ".transmission";

								self.xmlFile:setFloat(gearRatioKey .. "#minForwardGearRatio", minForwardGearRatio);

								printDebug("(extraOptions) :: Set motor config(" .. tostring(motorIndice) .. ") min forward gear ratio to '" .. minForwardGearRatio .. "'.", 1, true);
							end;
						end;
					end;
				else
					printError("(extraOptions) :: Missing 'motorIndices' TAG for vehicle '" .. self.configFileName .. "'! Stop change max forward speed!", true, false);
				end;
			end;

			if topArmFilename ~= "" then
				local attacherJointIndices = {string.getVector(self.xmlFile:getString(extraOptionKey .. "#attacherJointIndices"))};
				
				if #attacherJointIndices > 0 then
					for _, attacherJointIndice in pairs(attacherJointIndices) do
						local attacherJointKey = string.format("vehicle.attacherJoints.attacherJoint(" .. tostring(attacherJointIndice - 1) .. ")");

						if self.xmlFile:hasProperty(attacherJointKey) then
							if self.xmlFile:hasProperty(attacherJointKey .. ".topArm#filename") then	
								self.xmlFile:setString(attacherJointKey .. ".topArm#filename", topArmFilename);

								printDebug("(extraOptions) :: Set attacher joint(" .. tostring(attacherJointIndice) + 1 .. ") top arm filename to '" .. topArmFilename .. "'.", 1, true);
							end;
						end;
					end;
				else
					printError("(extraOptions) :: Missing 'attacherJointIndices' TAG for vehicle '" .. self.configFileName .. "'! Stop change top arm filename!", true, false);
				end;
			end;
			
			if supportAnimationName ~= "" then
				self.xmlFile:setString("vehicle.attachable.supportArm#animationName", "notDefined"); --## deactivate the manual support animation of my SupportArm Script
				self.xmlFile:setString("vehicle.attachable.support#animationName", supportAnimationName);

				printDebug("(extraOptions) :: Set support animation name to '" .. supportAnimationName .. "'.", 1, true);
			end;

			if beaconLightFilename ~= "" then
				local beaconLightIndices = {string.getVector(self.xmlFile:getString(configKey .. "#beaconLightIndices"))};
				AddConfig.Logging_table(beaconLightIndices)
				local beaconLightSpeed = Utils.getNoNil(self.xmlFile:getFloat(extraOptionKey .. "#beaconLightSpeed"), "");
				
				if #beaconLightIndices > 0 then
					for _, beaconLightIndice in pairs(beaconLightIndices) do
						local beaconLightKey = string.format("vehicle.lights.beaconLights.beaconLight(" .. tostring(beaconLightIndice - 1) .. ")");

						if self.xmlFile:hasProperty(beaconLightKey) then
							self.xmlFile:setString(beaconLightKey .. "#filename", beaconLightFilename);

							printDebug("(extraOptions) :: Set beacon light(" .. tostring(beaconLightIndice) .. ") filename to '" .. beaconLightFilename .. "'.", 1, true);

							if beaconLightSpeed ~= "" then
								self.xmlFile:setFloat(beaconLightKey .. "#speed", beaconLightSpeed);

								printDebug("(extraOptions) :: Set beacon light(" .. tostring(beaconLightIndice) .. ") speed to '" .. beaconLightSpeed .. "'.", 1, true);
							end;
						end;
					end;
				else
					local beaconLightNumber = 0;

					while true do
						local beaconLightKey = "vehicle.lights.beaconLights.beaconLight(" .. tostring(beaconLightNumber) .. ")";

						if not self.xmlFile:hasProperty(beaconLightKey) then
							break;
						end;

						self.xmlFile:setString(beaconLightKey .. "#filename", beaconLightFilename);

						printDebug("(extraOptions) :: Set beacon light(" .. tostring(beaconLightNumber + 1) .. ") filename to '" .. beaconLightFilename .. "'.", 1, true);

						if beaconLightSpeed ~= "" then
							self.xmlFile:setFloat(beaconLightKey .. "#speed", beaconLightSpeed);

							printDebug("(extraOptions) :: Set beacon light(" .. tostring(beaconLightNumber) .. ") speed to '" .. beaconLightSpeed .. "'.", 1, true);
						end;

						beaconLightNumber = beaconLightNumber + 1;
					end;
				end;
			end;
			

			if wheelInvertedTire ~= "" then
			
				local wheelConIndicesOld1 = self.xmlFile:getString(extraOptionKey .. "#wheelConIndices");
				if wheelConIndicesOld1 == nil then
					self.xmlFile:setString(extraOptionKey .. "#wheelConIndices", " ");
				else
				end
				local wheelIndicesOld1 = self.xmlFile:getString(extraOptionKey .. "#wheelIndices");
				if wheelIndicesOld1 == nil then
					self.xmlFile:setString(extraOptionKey .. "#wheelIndices", "1 2");
				else
				end
				local wheelConIndicesOld = self.xmlFile:getString(extraOptionKey .. "#wheelConIndices");
				printDebug("WheelConIndicesOld = '" .. wheelConIndicesOld .. "'", 1, true)
				if wheelConIndicesOld == " " then
				
				
					local wheelConNumber = 0;

					while true do
						local wheelConKey = string.format("vehicle.wheels.wheelConfigurations.wheelConfiguration(" .. tostring(wheelConNumber) .. ")");
						local wheelConfigIndicesOld = self.xmlFile:getString(extraOptionKey .. "#wheelConIndices")

						if not self.xmlFile:hasProperty(wheelConKey) then
							break;
						end;
						printDebug(" WheelConfig '" .. wheelConNumber + 1 .. "' loaded.", 1, true);
						wheelConfigIndices =  "".. wheelConfigIndicesOld .. " " .. wheelConNumber + 1 .. ""
						self.xmlFile:setString(extraOptionKey .. "#wheelConIndices", wheelConfigIndices);
						printDebug(" wheelConIndices " .. wheelConfigIndices .. " new loaded.", 1, true);
						
						
						wheelConNumber = wheelConNumber + 1;
					end
					local wheelIndices = {string.getVector(self.xmlFile:getString(extraOptionKey .. "#wheelIndices"))};
					local wheelConIndices = {string.getVector(self.xmlFile:getString(extraOptionKey .. "#wheelConIndices"))};
				
					if #wheelConIndices > 0 then
						for _, wheelConIndice in pairs(wheelConIndices) do
							local wheelConKey = string.format("vehicle.wheels.wheelConfigurations.wheelConfiguration(" .. tostring(wheelConIndice - 1) .. ")");
							if self.xmlFile:hasProperty(wheelConKey) then						
								if #wheelIndices > 0 then
									for _, wheelIndice in pairs(wheelIndices) do
										local wheelKey = string.format(wheelConKey .. ".wheels.wheel(" .. tostring(wheelIndice - 1) .. ")");

										if self.xmlFile:hasProperty(wheelKey) then
											self.xmlFile:setString(wheelKey .. ".tire#isInverted", wheelInvertedTire);

											printDebug("(extraOptions) :: Set Wheel (" .. tostring(wheelIndice) .. ") isInverted to '" .. wheelInvertedTire .. "'.", 1, true);

										end;
									end
								end
							end
						end;
					else
					printDebug("no WheelConIndices available", 1, true)
					end;
				else
					local wheelIndices = {string.getVector(self.xmlFile:getString(extraOptionKey .. "#wheelIndices"))};
					local wheelConIndices = {string.getVector(self.xmlFile:getString(extraOptionKey .. "#wheelConIndices"))};
				
					if #wheelConIndices > 0 then
						for _, wheelConIndice in pairs(wheelConIndices) do
							local wheelConKey = string.format("vehicle.wheels.wheelConfigurations.wheelConfiguration(" .. tostring(wheelConIndice - 1) .. ")");
							if self.xmlFile:hasProperty(wheelConKey) then						
								if #wheelIndices > 0 then
									for _, wheelIndice in pairs(wheelIndices) do
										local wheelKey = string.format(wheelConKey .. ".wheels.wheel(" .. tostring(wheelIndice - 1) .. ")");

										if self.xmlFile:hasProperty(wheelKey) then
											self.xmlFile:setString(wheelKey .. ".tire#isInverted", wheelInvertedTire);

											printDebug("(extraOptions) :: Set only Wheel (" .. tostring(wheelIndice) .. ") isInverted to '" .. wheelInvertedTire .. "'.", 1, true);

										end;
									end
								end
							end
						end;
					else
					printDebug("no WheelConIndices available", 1, true)
					end;
				end
				
			end;

			if wheelFilename ~= "" then
				local wheelConfigId = Utils.getNoNil(self.xmlFile:getString(extraOptionKey .. "#configId"), "");
				local rotSpeed = Utils.getNoNil(self.xmlFile:getString(extraOptionKey .. "#rotSpeed"), "");
				local restLoad = Utils.getNoNil(self.xmlFile:getString(extraOptionKey .. "#restLoad"), "");
				local steeringNode = Utils.getNoNil(self.xmlFile:getString(extraOptionKey .. "#steeringNode"), "");
				local nodeMinTransX = Utils.getNoNil(self.xmlFile:getString(extraOptionKey .. "#nodeMinTransX"), "");
				local nodeMaxTransX = Utils.getNoNil(self.xmlFile:getString(extraOptionKey .. "#nodeMaxTransX"), "");
				local steeringNode = Utils.getNoNil(self.xmlFile:getString(extraOptionKey .. "#steeringNode"), "");
				local nodeMinTransX = Utils.getNoNil(self.xmlFile:getString(extraOptionKey .. "#nodeMinTransX"), "");
				local nodeMaxTransX = Utils.getNoNil(self.xmlFile:getString(extraOptionKey .. "#nodeMaxTransX"), "");
			
				local size = Utils.getNoNil(self.xmlFile:getString(extraOptionKey .. "#size"), "");
				local ackermannSteeringIndex = Utils.getNoNil(self.xmlFile:getString(extraOptionKey .. "#ackermannSteeringIndex"), "");
				local autoRotateBackSpeed = Utils.getNoNil(self.xmlFile:getString(extraOptionKey .. "#autoRotateBackSpeed"), "");
				local suspTravel = Utils.getNoNil(self.xmlFile:getString(extraOptionKey .. ".wheels.wheel#suspTravel"), "");
				local spring = Utils.getNoNil(self.xmlFile:getString(extraOptionKey .. ".wheels.wheel#spring"), "");
				local damper = Utils.getNoNil(self.xmlFile:getString(extraOptionKey .. ".wheels.wheel#damper"), "");
				local rotMax = Utils.getNoNil(self.xmlFile:getString(extraOptionKey .. ".wheels.wheel#rotMax"), "");
				local rotMin = Utils.getNoNil(self.xmlFile:getString(extraOptionKey .. ".wheels.wheel#rotMin"), "");
				local isCareWheel = Utils.getNoNil(self.xmlFile:getString(extraOptionKey .. ".wheels.wheel#isCareWheel"), "");
				
				local isLeft = Utils.getNoNil(self.xmlFile:getString(extraOptionKey .. ".wheels.wheel#isLeft"), "");
				local hasParticles = Utils.getNoNil(self.xmlFile:getString(extraOptionKey .. ".wheels.wheel#hasParticles"), "");
				local tipOcclusionAreaGroupId = Utils.getNoNil(self.xmlFile:getString(extraOptionKey .. ".wheels.wheel#tipOcclusionAreaGroupId"), "");
				local repr = Utils.getNoNil(self.xmlFile:getString(extraOptionKey .. ".wheels.wheel#repr"), "");
				local driveNode = Utils.getNoNil(self.xmlFile:getString(extraOptionKey .. ".wheels.wheel#driveNode"), "");
				local forcePointRatio = Utils.getNoNil(self.xmlFile:getString(extraOptionKey .. ".wheels.wheel#forcePointRatio"), "");
				local steeringAxleScale = Utils.getNoNil(self.xmlFile:getString(extraOptionKey .. "#steeringAxleScale"), "");
				local steeringAxleRotMax = Utils.getNoNil(self.xmlFile:getString(extraOptionKey .. "#steeringAxleRotMax"), "");
				local steeringAxleRotMin = Utils.getNoNil(self.xmlFile:getString(extraOptionKey .. "#steeringAxleRotMin"), "");
				local initialCompression = Utils.getNoNil(self.xmlFile:getString(extraOptionKey .. ".wheels.wheel#initialCompression"), "");
				local additionalWheelFilename = Utils.getNoNil(self.xmlFile:getString(extraOptionKey .. ".additional#additionalWheelFilename"), "");
				local configId = Utils.getNoNil(self.xmlFile:getString(extraOptionKey .. ".additional#configId"), "");
				local offset = Utils.getNoNil(self.xmlFile:getString(extraOptionKey .. ".additional#offset"), "");
				local connectorFilename = Utils.getNoNil(self.xmlFile:getString(extraOptionKey .. ".additional#connectorFilename"), "");
				

				local wheelConIndicesOld1 = self.xmlFile:getString(extraOptionKey .. "#wheelConIndices");
				if wheelConIndicesOld1 == nil then
					self.xmlFile:setString(extraOptionKey .. "#wheelConIndices", " ");
				else
				end
				local BrandIndex = self.xmlFile:getString(extraOptionKey .. "#BrandIndex")
				local newWheelBrandIndex = self.xmlFile:getString(extraOptionKey .. "#newWheelBrandIndex")
				local wheelConName = self.xmlFile:getString(extraOptionKey .. "#wheelConName")
				local wheelConIndicesOld = self.xmlFile:getString(extraOptionKey .. "#wheelConIndices");
				printDebug("WheelConIndicesOld = '" .. wheelConIndicesOld .. "'", 1, true)
				if wheelConIndicesOld == " " then
				
					local wheelConNumber = 0;

					while true do
						local wheelConKey = string.format("vehicle.wheels.wheelConfigurations.wheelConfiguration(" .. tostring(wheelConNumber) .. ")");
						local wheelConfigIndicesOld = self.xmlFile:getString(extraOptionKey .. "#wheelConIndices")

						if not self.xmlFile:hasProperty(wheelConKey) then
							break;
						end;
						local BrandIndex1 = self.xmlFile:getString(wheelConKey .. "#brand")
						local NameIndex1 = self.xmlFile:getString(wheelConKey .. "#name")
						local newWheelBrandName = self.xmlFile:getString("#newWheelBrand")

						if BrandIndex ~= nil and wheelConName ~= nil then
							if BrandIndex == BrandIndex1 and wheelConName == NameIndex1 then
								printDebug(" WheelConfig '" .. wheelConNumber + 1 .. "' loaded.", 1, true);
								wheelConfigIndices =  "".. wheelConfigIndicesOld .. " " .. wheelConNumber + 1 .. ""
								self.xmlFile:setString(extraOptionKey .. "#wheelConIndices", wheelConfigIndices);
								printDebug(" wheelConIndices " .. wheelConfigIndices .. " new loaded.", 1, true);
							end
						elseif newWheelBrandIndex ~= nil and wheelConName ~= nil then
							if newWheelBrandIndex == newWheelBrandName and wheelConName == NameIndex1 then
								printDebug(" WheelConfig '" .. wheelConNumber + 1 .. "' loaded.", 1, true);
								wheelConfigIndices =  "".. wheelConfigIndicesOld .. " " .. wheelConNumber + 1 .. ""
								self.xmlFile:setString(extraOptionKey .. "#wheelConIndices", wheelConfigIndices);
								printDebug(" wheelConIndices " .. wheelConfigIndices .. " new loaded.", 1, true);
							end
						else
							if BrandIndex == BrandIndex1 then
								printDebug(" WheelConfig '" .. wheelConNumber + 1 .. "' loaded.", 1, true);
								wheelConfigIndices =  "".. wheelConfigIndicesOld .. " " .. wheelConNumber + 1 .. ""
								self.xmlFile:setString(extraOptionKey .. "#wheelConIndices", wheelConfigIndices);
								printDebug(" wheelConIndices " .. wheelConfigIndices .. " new loaded.", 1, true);
							end
						end
						
						wheelConNumber = wheelConNumber + 1;
					end
				end

				local wheelConIndices = {string.getVector(self.xmlFile:getString(extraOptionKey .. "#wheelConIndices"))};
				local wheelIndices = {string.getVector(self.xmlFile:getString(extraOptionKey .. "#wheelIndices"))};

				if #wheelConIndices > 0 then
					for _, wheelConIndice in pairs(wheelConIndices) do
						local wheelConKey = string.format("vehicle.wheels.wheelConfigurations.wheelConfiguration(" .. tostring(wheelConIndice - 1) .. ")");
						if self.xmlFile:hasProperty(wheelConKey) then						
							if ackermannSteeringIndex ~= "" then
								self.xmlFile:setString(wheelConKey .. ".wheels#ackermannSteeringIndex", ackermannSteeringIndex);
								printDebug("(extraOptions) :: Set only Wheels of Config	(" .. tostring(wheelConIndice) .. ") ackermannSteeringIndex to '" .. ackermannSteeringIndex .. "'.", 1, true);
							end;
							if autoRotateBackSpeed ~= "" then
								self.xmlFile:setString(wheelConKey .. ".wheels#autoRotateBackSpeed", autoRotateBackSpeed);
								printDebug("(extraOptions) :: Set only Wheels of Config (" .. tostring(wheelConIndice) .. ") autoRotateBackSpeed to '" .. autoRotateBackSpeed .. "'.", 1, true);
							end;
							if size ~= "" then
								self.xmlFile:setString(wheelConKey .. ".size#width", size);
								printDebug("(extraOptions) :: Set only Wheels of Config (" .. tostring(wheelConIndice) .. ") width to '" .. size .. "'.", 1, true);
							end;
							local objectChangeNumber = 0;

							while true do
								local objectChangeExtraKey = string.format(extraOptionKey .. ".objectChange(" .. tostring(objectChangeNumber) .. ")");

								if not self.xmlFile:hasProperty(objectChangeExtraKey) then
									break;
								end;

								local objectChangeIndices = {string.getVector(self.xmlFile:getString(objectChangeExtraKey .. "#indices"))};
								local objectChangeN = Utils.getNoNil(self.xmlFile:getString(objectChangeExtraKey .. "#node"), "");
								local objectChangeS = Utils.getNoNil(self.xmlFile:getString(objectChangeExtraKey .. "#scale"), "");
								local objectChangeT = Utils.getNoNil(self.xmlFile:getString(objectChangeExtraKey .. "#trans"), "");
								local objectChangeR = Utils.getNoNil(self.xmlFile:getString(objectChangeExtraKey .. "#rot"), "");
								local objectChangeV = Utils.getNoNil(self.xmlFile:getString(objectChangeExtraKey .. "#visual"), "");
								local objectChangeS1 = Utils.getNoNil(self.xmlFile:getString(objectChangeExtraKey .. "#scale1"), "");
								local objectChangeT1 = Utils.getNoNil(self.xmlFile:getString(objectChangeExtraKey .. "#trans1"), "");
								local objectChangeR1 = Utils.getNoNil(self.xmlFile:getString(objectChangeExtraKey .. "#rot1"), "");
								local objectChangeV1 = Utils.getNoNil(self.xmlFile:getString(objectChangeExtraKey .. "#visual1"), "");
								
							
								
								if #objectChangeIndices > 0 then
									for _, objectChangeIndice in pairs(objectChangeIndices) do
										local objectChangeKey = string.format(wheelConKey .. ".objectChange(" .. tostring(objectChangeIndice - 1) .. ")");
										if self.xmlFile:hasProperty(objectChangeKey) then
											if objectChangeN ~= "" then
												self.xmlFile:setString(objectChangeKey .. "#node", objectChangeN);
												printDebug("(extraOptions) :: Set only Wheels of Config (" .. tostring(objectChangeIndice) .. ") objectChangeN to '" .. objectChangeN .. "'.", 1, true);
											end;
											if objectChangeS ~= "" then
												self.xmlFile:setString(objectChangeKey .. "#scaleActive", objectChangeS);
												printDebug("(extraOptions) :: Set only Wheels of Config (" .. tostring(objectChangeIndice) .. ") objectChangeS to '" .. objectChangeS .. "'.", 1, true);
											end;
											if objectChangeT ~= "" then
												self.xmlFile:setString(objectChangeKey .. "#translationActive", objectChangeT);
												printDebug("(extraOptions) :: Set only Wheels of Config (" .. tostring(objectChangeIndice) .. ") objectChangeT to '" .. objectChangeT .. "'.", 1, true);
											end;
											if objectChangeR ~= "" then
												self.xmlFile:setString(objectChangeKey .. "#rotationActive", objectChangeR);
												printDebug("(extraOptions) :: Set only Wheels of Config (" .. tostring(objectChangeIndice) .. ") objectChangeR to '" .. objectChangeR .. "'.", 1, true);
											end;
											if objectChangeV ~= "" then
												self.xmlFile:setString(objectChangeKey .. "#visibilityActive", objectChangeV);
												printDebug("(extraOptions) :: Set only Wheels of Config (" .. tostring(objectChangeIndice) .. ") objectChangeV to '" .. objectChangeV .. "'.", 1, true);
											end;
											if objectChangeS1 ~= "" then
												self.xmlFile:setString(objectChangeKey .. "#scaleInactive", objectChangeS1);
												printDebug("(extraOptions) :: Set only Wheels of Config (" .. tostring(objectChangeIndice) .. ") objectChangeS1 to '" .. objectChangeS1 .. "'.", 1, true);
											end;
											if objectChangeT1 ~= "" then
												self.xmlFile:setString(objectChangeKey .. "#translationInactive", objectChangeT1);
												printDebug("(extraOptions) :: Set only Wheels of Config (" .. tostring(objectChangeIndice) .. ") objectChangeT1 to '" .. objectChangeT1 .. "'.", 1, true);
											end;
											if objectChangeR1 ~= "" then
												self.xmlFile:setString(objectChangeKey .. "#rotationInactive", objectChangeR1);
												printDebug("(extraOptions) :: Set only Wheels of Config (" .. tostring(objectChangeIndice) .. ") objectChangeR1 to '" .. objectChangeR1 .. "'.", 1, true);
											end;
											if objectChangeV1 ~= "" then
												self.xmlFile:setString(objectChangeKey .. "#visibilityInactive", objectChangeV1);
												printDebug("(extraOptions) :: Set only Wheels of Config (" .. tostring(objectChangeIndice) .. ") objectChangeV1 to '" .. objectChangeV1 .. "'.", 1, true);
											end;
										end
									end
								end
								objectChangeNumber = objectChangeNumber + 1;
							end
							if #wheelIndices > 0 then
								for _, wheelIndice in pairs(wheelIndices) do
									local wheelKey = string.format(wheelConKey .. ".wheels.wheel(" .. tostring(wheelIndice - 1) .. ")");
									if self.xmlFile:hasProperty(wheelKey) then
										if wheelFilename ~= " " then
											self.xmlFile:setString(wheelKey .. "#filename", wheelFilename);
											printDebug("(extraOptions) :: Set only Wheel (" .. tostring(wheelIndice) .. ") wheelFilename to '" .. wheelFilename .. "'.", 1, true);
										end;
										if wheelConfigId ~= "" then
											self.xmlFile:setString(wheelKey .. "#configId", wheelConfigId);
											printDebug("(extraOptions) :: Set only Wheel (" .. tostring(wheelIndice) .. ") wheelConfigId to '" .. wheelConfigId .. "'.", 1, true);
										end;
										if isLeft ~= "" then
											self.xmlFile:setString(wheelKey .. "#isLeft", isLeft);
											printDebug("(extraOptions) :: Set only Wheel (" .. tostring(wheelIndice) .. ") isLeft to '" .. isLeft .. "'.", 1, true);
										end;
										if hasParticles ~= "" then
											self.xmlFile:setString(wheelKey .. "#hasParticles", hasParticles);
											printDebug("(extraOptions) :: Set only Wheel (" .. tostring(wheelIndice) .. ") hasParticles to '" .. hasParticles .. "'.", 1, true);
										end;
										if initialCompression ~= "" then
											self.xmlFile:setString(wheelKey .. ".physics#initialCompression", initialCompression);
											printDebug("(extraOptions) :: Set only Wheel (" .. tostring(wheelIndice) .. ") initialCompression to '" .. initialCompression .. "'.", 1, true);
										end;
										if suspTravel ~= "" then
											self.xmlFile:setString(wheelKey .. ".physics#suspTravel", suspTravel);
											printDebug("(extraOptions) :: Set only Wheel (" .. tostring(wheelIndice) .. ") suspTravel to '" .. suspTravel .. "'.", 1, true);
										end;
										if spring ~= "" then
											self.xmlFile:setString(wheelKey .. ".physics#spring", spring);
											printDebug("(extraOptions) :: Set only Wheel (" .. tostring(wheelIndice) .. ") spring to '" .. spring .. "'.", 1, true);
										end;
										if damper ~= "" then
											self.xmlFile:setString(wheelKey .. ".physics#damper", damper);
											printDebug("(extraOptions) :: Set only Wheel (" .. tostring(wheelIndice) .. ") damper to '" .. damper .. "'.", 1, true);
										end;
										if rotSpeed ~= "" then
											self.xmlFile:setString(wheelKey .. ".physics#rotSpeed", rotSpeed);
											printDebug("(extraOptions) :: Set only Wheel (" .. tostring(wheelIndice) .. ") rotSpeed to '" .. rotSpeed .. "'.", 1, true);
										end;
										if restLoad ~= "" then
											self.xmlFile:setString(wheelKey .. ".physics#restLoad", restLoad);
											printDebug("(extraOptions) :: Set only Wheel (" .. tostring(wheelIndice) .. ") restLoad to '" .. restLoad .. "'.", 1, true);
										end;
										if tipOcclusionAreaGroupId ~= "" then
											self.xmlFile:setString(wheelKey .. ".physics#tipOcclusionAreaGroupId", tipOcclusionAreaGroupId);
											printDebug("(extraOptions) :: Set only Wheel (" .. tostring(wheelIndice) .. ") tipOcclusionAreaGroupId to '" .. tipOcclusionAreaGroupId .. "'.", 1, true);
										end;
										if repr ~= "" then
											self.xmlFile:setString(wheelKey .. ".physics#repr", repr);
											printDebug("(extraOptions) :: Set only Wheel (" .. tostring(wheelIndice) .. ") repr to '" .. repr .. "'.", 1, true);
										end;
										if driveNode ~= "" then
											self.xmlFile:setString(wheelKey .. ".physics#driveNode", driveNode);
											printDebug("(extraOptions) :: Set only Wheel (" .. tostring(wheelIndice) .. ") driveNode to '" .. driveNode .. "'.", 1, true);
										end;
										if forcePointRatio ~= "" then
											self.xmlFile:setString(wheelKey .. ".physics#forcePointRatio", forcePointRatio);
											printDebug("(extraOptions) :: Set only Wheel (" .. tostring(wheelIndice) .. ") forcePointRatio to '" .. forcePointRatio .. "'.", 1, true);
										end;
										if rotMax ~= "" then
											self.xmlFile:setString(wheelKey .. ".fender#rotMax", rotMax);
											printDebug("(extraOptions) :: Set only Wheel (" .. tostring(wheelIndice) .. ") rotMax to '" .. rotMax .. "'.", 1, true);
										end;
										if rotMin ~= "" then
											self.xmlFile:setString(wheelKey .. ".fender#rotMin", rotMin);
											printDebug("(extraOptions) :: Set only Wheel (" .. tostring(wheelIndice) .. ") rotMin to '" .. rotMin .. "'.", 1, true);
										end;
										if additionalWheelFilename ~= "" then
											self.xmlFile:setString(wheelKey .. ".additionalWheel#filename", additionalWheelFilename);
											printDebug("(extraOptions) :: Set only Wheel (" .. tostring(wheelIndice) .. ") additionalWheelFilename to '" .. additionalWheelFilename .. "'.", 1, true);
										end;
										if configId ~= "" then
											self.xmlFile:setString(wheelKey .. ".additionalWheel#configId", configId);
											printDebug("(extraOptions) :: Set only Wheel (" .. tostring(wheelIndice) .. ") configId to '" .. configId .. "'.", 1, true);
										end;
										if offset ~= "" then
											self.xmlFile:setString(wheelKey .. ".additionalWheel#offset", offset);
											printDebug("(extraOptions) :: Set only Wheel (" .. tostring(wheelIndice) .. ") offset to '" .. offset .. "'.", 1, true);
										end;
										if connectorFilename ~= "" then
											self.xmlFile:setString(wheelKey .. ".additionalWheel.connector#filename", connectorFilename);
											printDebug("(extraOptions) :: Set only Wheel (" .. tostring(wheelIndice) .. ") connectorFilename to '" .. connectorFilename .. "'.", 1, true);
										end;
										if isCareWheel ~= "" then
											self.xmlFile:setString(wheelKey .. ".tire#isCareWheel", isCareWheel);
											printDebug("(extraOptions) :: Set only Wheel (" .. tostring(wheelIndice) .. ") isCareWheel to '" .. isCareWheel .. "'.", 1, true);
										end;
										if steeringNode ~= "" then
											self.xmlFile:setString(wheelKey .. ".steering#node", steeringNode);
											printDebug("(extraOptions) :: Set only Wheel (" .. tostring(wheelIndice) .. ") steeringNode to '" .. steeringNode .. "'.", 1, true);
										end;
										if nodeMinTransX ~= "" then
											self.xmlFile:setString(wheelKey .. ".steering#nodeMinTransX", nodeMinTransX);
											printDebug("(extraOptions) :: Set only Wheel (" .. tostring(wheelIndice) .. ") nodeMinTransX to '" .. nodeMinTransX .. "'.", 1, true);
										end;
										if nodeMaxTransX ~= "" then
											self.xmlFile:setString(wheelKey .. ".steering#nodeMaxTransX", nodeMaxTransX);
											printDebug("(extraOptions) :: Set only Wheel (" .. tostring(wheelIndice) .. ") nodeMaxTransX to '" .. nodeMaxTransX .. "'.", 1, true);
										end;
										if steeringAxleScale ~= "" then
											self.xmlFile:setString(wheelKey .. ".steeringAxle#scale", steeringAxleScale);
											printDebug("(extraOptions) :: Set only Wheel (" .. tostring(wheelIndice) .. ") steeringAxleScale to '" .. steeringAxleScale .. "'.", 1, true);
										end;
										if steeringAxleRotMin ~= "" then
											self.xmlFile:setString(wheelKey .. ".steeringAxle#rotMin", steeringAxleRotMin);
											printDebug("(extraOptions) :: Set only Wheel (" .. tostring(wheelIndice) .. ") steeringAxleRotMin to '" .. steeringAxleRotMin .. "'.", 1, true);
										end;
										if steeringAxleRotMax ~= "" then
											self.xmlFile:setString(wheelKey .. ".steeringAxle#rotMax", steeringAxleRotMax);
											printDebug("(extraOptions) :: Set only Wheel (" .. tostring(wheelIndice) .. ") steeringAxleRotMax to '" .. steeringAxleRotMax .. "'.", 1, true);
										end;
									end;
								end
							end
						end
					end;
				else
				printDebug("no WheelConIndices available", 1, true)
				end;
			end;
			
			if foliageBendingModifier ~= "" then
				local wheelConIndicesOld1 = self.xmlFile:getString(extraOptionKey .. "#wheelConIndices");
				if wheelConIndicesOld1 == nil then
					self.xmlFile:setString(extraOptionKey .. "#wheelConIndices", " ");
				else
				end
				local BrandIndex = self.xmlFile:getString(extraOptionKey .. "#BrandIndex")
				local wheelConName = self.xmlFile:getString(extraOptionKey .. "#wheelConName")
				local wheelConIndicesOld = self.xmlFile:getString(extraOptionKey .. "#wheelConIndices");
				printDebug("WheelConIndicesOld = '" .. wheelConIndicesOld .. "'", 1, true)
				if wheelConIndicesOld == " " then
				
					local wheelConNumber = 0;

					while true do
						local wheelConKey = string.format("vehicle.wheels.wheelConfigurations.wheelConfiguration(" .. tostring(wheelConNumber) .. ")");
						local wheelConfigIndicesOld = self.xmlFile:getString(extraOptionKey .. "#wheelConIndices")

						if not self.xmlFile:hasProperty(wheelConKey) then
							break;
						end;
						local BrandIndex1 = self.xmlFile:getString(wheelConKey .. "#brand")
						local NameIndex1 = self.xmlFile:getString(wheelConKey .. "#name")

						if BrandIndex ~= nil and wheelConName ~= nil then
							if BrandIndex == BrandIndex1 and wheelConName == NameIndex1 then
								printDebug(" WheelConfig '" .. wheelConNumber + 1 .. "' loaded.", 1, true);
								wheelConfigIndices =  "".. wheelConfigIndicesOld .. " " .. wheelConNumber + 1 .. ""
								self.xmlFile:setString(extraOptionKey .. "#wheelConIndices", wheelConfigIndices);
								printDebug(" wheelConIndices " .. wheelConfigIndices .. " new loaded.", 1, true);
							end
						else
							if BrandIndex == BrandIndex1 then
								printDebug(" WheelConfig '" .. wheelConNumber + 1 .. "' loaded.", 1, true);
								wheelConfigIndices =  "".. wheelConfigIndicesOld .. " " .. wheelConNumber + 1 .. ""
								self.xmlFile:setString(extraOptionKey .. "#wheelConIndices", wheelConfigIndices);
								printDebug(" wheelConIndices " .. wheelConfigIndices .. " new loaded.", 1, true);
							else
							end
						end
						wheelConNumber = wheelConNumber + 1;
					end
				end
				local wheelConIndices = {string.getVector(self.xmlFile:getString(extraOptionKey .. "#wheelConIndices"))};
				local fBMIndices = {string.getVector(self.xmlFile:getString(extraOptionKey .. "#fBMIndices"))};
				local fBMIndex = Utils.getNoNil(self.xmlFile:getString(extraOptionKey .. "#fBMIndex"), "");
				local fBMminX = Utils.getNoNil(self.xmlFile:getString(extraOptionKey .. "#fBMminX"), "");
				local fBMmaxX = Utils.getNoNil(self.xmlFile:getString(extraOptionKey .. "#fBMmaxX"), "");
			
				if #wheelConIndices > 0 then
					for _, wheelConIndice in pairs(wheelConIndices) do
						local wheelConKey = string.format("vehicle.wheels.wheelConfigurations.wheelConfiguration(" .. tostring(wheelConIndice - 1) .. ")");
						if self.xmlFile:hasProperty(wheelConKey) then						
							if #fBMIndices > 0 then
								for _, fBMIndice in pairs(fBMIndices) do
									local fBMKey = string.format(wheelConKey .. ".wheels.foliageBendingModifier(" .. tostring(fBMIndice - 1) .. ")");

									if self.xmlFile:hasProperty(fBMKey) then
										if fBMIndex ~= "" then
											self.xmlFile:setString(fBMKey .. "#index", fBMIndex);
											printDebug("(extraOptions) :: Set only Wheel (" .. tostring(fBMIndice) .. ") fBMIndex to '" .. fBMIndex .. "'.", 1, true);
										end;
										if fBMminX ~= "" then
											self.xmlFile:setString(fBMKey .. "#minX", fBMminX);
											printDebug("(extraOptions) :: Set only Wheel (" .. tostring(fBMIndice) .. ") fBMminX to '" .. fBMminX .. "'.", 1, true);
										end;
										if fBMmaxX ~= "" then
											self.xmlFile:setString(fBMKey .. "#maxX", fBMmaxX);
											printDebug("(extraOptions) :: Set only Wheel (" .. tostring(fBMIndice) .. ") fBMmaxX to '" .. fBMmaxX .. "'.", 1, true);
										end;
									end;
								end
							end
						end
					end;
				else
				printDebug("no WheelConIndices available", 1, true)
				end;
				
			end;
			
			if hubFilename ~= "" then

				local hubIndices = {string.getVector(self.xmlFile:getString(extraOptionKey .. "#hubIndices"))};
				local hubScale = Utils.getNoNil(self.xmlFile:getString(extraOptionKey .. "#hubScale"), "");
				
				if #hubIndices > 0 then
					for _, hubIndice in pairs(hubIndices) do
						local hubKey = string.format("vehicle.wheels.hubs.hub(" .. tostring(hubIndice - 1) .. ")");

						if self.xmlFile:hasProperty(hubKey) then
							if hubFilename ~= " " then
								self.xmlFile:setString(hubKey .. "#filename", hubFilename);
								
								printDebug("(extraOptions) :: Set hub(" .. tostring(hubIndice) .. ") filename to '" .. hubFilename .. "'.", 1, true);
							end

							if hubScale ~= "" then
								self.xmlFile:setString(hubKey .. "#scale", hubScale);

								printDebug("(extraOptions) :: Set hub(" .. tostring(hubIndice) .. ") scale to '" .. hubScale .. "'.", 1, true);
							end;
						end;
					end;
				else
				printDebug("no Hub Indices available", 1, true)
				end;
			end
			
			if externalMotorSoundFile ~= "" then
				-- self.xmlFile:setString("vehicle.motorized.sounds#externalSoundFile", externalMotorSoundFile);
				self.xmlFile:setString("vehicle.base.sounds#filename", externalMotorSoundFile);

				printDebug("(extraOptions) :: Set external motor sound file to '" .. externalMotorSoundFile .. "'.", 1, true);
			end;

			if fruitPreparerFruit ~= "" then
				self.xmlFile:setString("vehicle.fruitPreparer#fruitType", fruitPreparerFruit);

				printDebug("(extraOptions) :: Set 'typeDesc' to " .. fruitPreparerFruit .. ".", 1, true);
			end;

			if fillTypeConverter ~= "" then
				local fillTypeConverterSpec = Utils.getNoNil(self.xmlFile:getString(extraOptionKey .. "#fillTypeConverterSpec"), "");
			
				self.xmlFile:setString("vehicle." .. fillTypeConverterSpec .. "#fillTypeConverter", fillTypeConverter);

				printDebug("(extraOptions) :: Set 'fillTypeConverter' of " .. fillTypeConverterSpec .. " to " .. fillTypeConverter .. ".", 1, true);
			end;

			if self.spec_honk ~= nil then
				if honkSoundOuterRadius ~= "" then
					self.xmlFile:setFloat("vehicle.honk.sound#outerRadius", honkSoundOuterRadius);
				end;

				if honkSoundInnerRadius ~= "" then
					self.xmlFile:setFloat("vehicle.honk.sound#innerRadius", honkSoundInnerRadius);
				end;
				
				if honkSoundOuterVolume ~= "" then
					self.xmlFile:setFloat("vehicle.honk.sound.volume#outdoor", honkSoundOuterVolume);
				end;

				if honkSoundInnerVolume ~= "" then
					self.xmlFile:setFloat("vehicle.honk.sound.volume#indoor", honkSoundInnerVolume);
				end;

				if honkSoundTemplate ~= "" then	
					if self.xmlFile:hasProperty("vehicle.honk.sound#file") then	
						removeXMLProperty(self.xmlFile, "vehicle.honk.sound#file");
					end;

					-- self.xmlFile:setString("vehicle.honk.sound#template", honkSoundTemplate);
					self.xmlFile:setString("vehicle.honk.sound#template", honkSoundTemplate);

					printDebug("(extraOptions) :: Set honk sound template to '" .. honkSoundTemplate .. "'.", 1, true);
				elseif honkSoundFilename ~= "" then
					if self.xmlFile:hasProperty("vehicle.honk.sound#template") then	
						removeXMLProperty(self.xmlFile, "vehicle.honk.sound#template");
					end;

					self.xmlFile:setString("vehicle.honk.sound#file", honkSoundFilename);

					printDebug("(extraOptions) :: Set honk sound filename to '" .. AddConfig.currentModDirectory .. honkSoundFilename .. "'.", 1, true);
				end;
			end;

			if changeConfigurationName ~= "" then
				if self.configurations[changeConfigurationName] ~= nil then
					local configurationIndex = Utils.getNoNil(self.xmlFile:getInt(extraOptionKey .. "#configurationIndex"), 1);
					
					local storeItem = g_storeManager:getItemByXMLFilename(self.configFileName);
					local config = storeItem.configurations[changeConfigurationName][configurationIndex];

					configName = config.name;

					if configName == "" then
						configName = "index " .. configurationIndex;
					end;

					ConfigurationUtil.setConfiguration(self, changeConfigurationName, configurationIndex);
					
					printDebug("(extraOptions) :: Set '" .. changeConfigurationName .. "' configuration to '" .. configName .. "' for vehicle '" .. self.configFileName .. "'.", 1, true);
				else
					printError("(extraOptions) :: Invalid '" .. changeConfigurationName .. "' configuration for vehicle '" .. self.configFileName .. "'! Stop change this configuration!", true, false);
				end;
			end;
		end;

	   extraOptionNumber = extraOptionNumber + 1;
   	end;
end;

function AddConfig:initExtraOptions(configName, configId, secondConfigName, extraOptionNeedUpdate, extraOptionOnLoad)
	local configKey = self:getConfigKey(configName, configId, secondConfigName);

	if configKey ~= "noKeyFound" then
		self:loadExtraOptions(configKey, extraOptionNeedUpdate, extraOptionOnLoad);
	else
		printError("(" .. configName .. "Configurations) :: Failed to load config key! Stop loading extra options from '" .. configName .. "Configurations'!", true, false);
	end;
end;

function AddConfig:setColor(configName, configId)
	local color = ConfigurationUtil.getColorByConfigId(self, configName, configId);

	printDebug("(" .. configName .. "Configurations) :: color = '" .. tostring(color) .. "'.", 1, true);

	if color ~= nil then
		local r, g, b, material = unpack(color);

		printDebug("(" .. configName .. "Configurations) :: r, g, b, materialId = " .. r .. ", " .. g .. ", " .. b .. ", " .. tostring(material), 1, true);

		local configNumber = 0;

		while true do
			local colorKey = string.format("vehicle.%sConfigurations.colorNode(%d)", configName, configNumber);

			if not self.xmlFile:hasProperty(colorKey) then
				break;
			end;

			local node = I3DUtil.indexToObject(self.components, self.xmlFile:getString(colorKey .. "#node"), self.i3dMappings);

			if node ~= nil then
				local shaderParameter = Utils.getNoNil(self.xmlFile:getString(colorKey .. "#shaderParameter"), "colorScale");
				local materialId = self.xmlFile:getInt(colorKey .. "#materialId");

				if getHasClassId(node, ClassIds.SHAPE) then
					if getHasShaderParameter(node, shaderParameter) then
						if materialId == nil then
							_, _, _, materialId = getShaderParameter(node, shaderParameter);
						end
		
						printDebug("(" .. configName .. "Configurations) :: shader parameter values (r, g, b, materialId) = " .. r .. ", " .. g .. ", " .. b .. ", " .. tostring(Utils.getNoNil(materialId, Utils.getNoNil(color[4], 0))), 1, true);
						
						if Utils.getNoNil(self.xmlFile:getBool(colorKey .. "#recursive"), false) then				
							I3DUtil.setShaderParameterRec(node, shaderParameter, r, g, b, Utils.getNoNil(materialId, Utils.getNoNil(color[4], 0)));
						else
							setShaderParameter(node, shaderParameter, r, g, b, Utils.getNoNil(materialId, Utils.getNoNil(color[4], 0)), true);
						end;
					else
						printError("(" .. configName .. "Configurations) :: Could not set vehicle color to '" .. getName(node) .. "' because the node has not the shader parameter '" .. shaderParameter .. "'! Stop try to coloring!", true, false);
					end;
				else
					printError("(" .. configName .. "Configurations) :: Could not set vehicle color to '" .. getName(node) .. "' because the node is not a shape! Stop try to coloring!", true, false);
				end;
			else
				printError("(" .. configName .. "Configurations) :: Could not find node! Stop try to coloring!", true, false);
			end;

			configNumber = configNumber + 1;
		end;

		configNumber = 0;

		while true do
			local materialKey = string.format("vehicle.%sConfigurations.material(%d)", configName, configNumber);

			if not self.xmlFile:hasProperty(materialKey) then
				break;
			end;

			local materialName = self.xmlFile:getString(materialKey .. "#name");

			if materialName ~= nil then
				local shaderParameterName = self.xmlFile:getString(materialKey .. "#shaderParameter");

				if shaderParameterName ~= nil then
					local colorStr = self.xmlFile:getString(materialKey .. "#color");
					local color;

					if colorStr ~= nil then
						color = g_brandColorManager:getBrandColorByName(colorStr);
					end;

					if color == nil then
						color = ConfigurationUtil.getColorByConfigId(self, configName, configId);
					end;

					if color ~= nil then
						local materialId = self.xmlFile:getInt(materialKey .. "#materialId");

						if self.setBaseMaterialColor ~= nil then
							self:setBaseMaterialColor(materialName, shaderParameterName, color, Utils.getNoNil(materialId, Utils.getNoNil(color[4], 0)));
						else
							printError("(" .. configName .. "Configurations) :: Missing function 'setBaseMaterialColor'!", true, false);
						end;
					else
						printError("(" .. configName .. "Configurations) :: Failed to load color '" .. tostring(colorStr) .. "' in '" .. self.cofingFileName .. "'! Stop coloring '" .. materialName .. "'!", false, false);
					end;
				else
					printError("(" .. configName .. "Configurations) :: Missing shader parameter in '" .. self.cofingFileName .. "'! Stop coloring '" .. materialName .. "'!", true, false);
				end;
			end;

			configNumber = configNumber + 1;
		end;
	end;
end;

function AddConfig:changeObjects(configName, configId, secondConfigName)
	secondConfigName = Utils.getNoNil(secondConfigName, configName);

	local configKey = self:getConfigKey(configName, configId, secondConfigName);

	if configKey ~= "noKeyFound" then
    	local configNumber = 0;

   		while true do
     		local materialKey = string.format(configKey .. ".material(%d)", configNumber);

			if not self.xmlFile:hasProperty(materialKey) then
            	break;
        	end;

			local baseMaterialNode = I3DUtil.indexToObject(self.components, self.xmlFile:getString(materialKey .. "#node"), self.i3dMappings);
        	local refMaterialNode = I3DUtil.indexToObject(self.components, self.xmlFile:getString(materialKey .. "#refNode"), self.i3dMappings);

			if baseMaterialNode ~= nil and refMaterialNode ~= nil then
            	local oldMaterial = getMaterial(baseMaterialNode, 0);
            	local newMaterial = getMaterial(refMaterialNode, 0);

				for _, component in pairs(self.components) do
               		ConfigurationUtil.replaceMaterialRec(self, component.node, oldMaterial, newMaterial);
            	end;
        	end;

			configNumber = configNumber + 1;
		end;
		
		local getRimColorAndIndexFromConfig = Utils.getNoNil(self.xmlFile:getString(configKey .. ".colorChanges.additional#getRimColorAndIndexFromConfig"), "");
		local getRimColorFromConfig = Utils.getNoNil(self.xmlFile:getString(configKey .. ".colorChanges.additional#getRimColorFromConfig"), "");
		
		if getRimColorAndIndexFromConfig ~= "" then
			if self.configurations[getRimColorAndIndexFromConfig] ~= nil then
				for _, wheel in pairs(self.spec_wheels.wheels) do
					if wheel.wheelAdditional ~= nil then
						local xmlKey = self:getConfigKey(self:getXMLPrefix(getRimColorAndIndexFromConfig), self.configurations[getRimColorAndIndexFromConfig], getRimColorAndIndexFromConfig);
						
						if xmlKey ~= "noKeyFound" then
							local additionalColor = self.xmlFile:getString(xmlKey .. ".colorChanges.rim#color");
							local materialId = self.xmlFile:getInt(xmlKey .. ".colorChanges.rim#materialId");
							local shaderParameterName = Utils.getNoNil(self.xmlFile:getString(xmlKey .. ".colorChanges.rim#shaderParameterName"), "colorMat0");
							
							if additionalColor ~= nil then
								local additionalColorName = g_brandColorManager:getBrandColorByName(additionalColor);

								if additionalColorName == nil then
									additionalColorName = ConfigurationUtil.getColorFromString(additionalColor);
								end;

								if additionalColorName ~= nil then
									local r, g, b, _ = unpack(additionalColorName);
								
									if materialId == nil then
										_, _, _, materialId = getShaderParameter(wheel.wheelAdditional, shaderParameterName);
									end;

									setShaderParameter(wheel.wheelAdditional, shaderParameterName, r, g, b, Utils.getNoNil(materialId, Utils.getNoNil(additionalColorName[4], 0)), false);

									printDebug("(colorChanges) :: Change additional wheel color successfully in '" .. self.configFileName .. "'.", 1, true);
								else
									printError("(colorChanges) :: Failed to load rim color in configuration '" .. tostring(getRimColorAndIndexFromConfig) .. "'(line " .. self.configurations[getRimColorAndIndexFromConfig] + 1 .. ") in '" .. self.configFileName .. "'! Stop coloring '" .. tostring(self.xmlFile:getString(xmlKey .. ".colorChanges#materialName")) .. "'!", false, false);
								end;
							end;
						end;
					end;
				end;
			end;
		elseif getRimColorFromConfig ~= "" then
			if self.configurations[getRimColorFromConfig] ~= nil then
				local isColorConfig = false;
				local colorName;
				local shaderParameterName = Utils.getNoNil(self.xmlFile:getString(configKey .. ".colorChanges.additional#shaderParameterName"), "colorMat0");
				local isColorConfig = false;
				local isColorConfig2 = false;

				for _, newConfguration in pairs(AddConfig.newConfgurations) do
					if getRimColorFromConfig == newConfguration.configName then
						isColorConfig = newConfguration.isColorConfig;
						isColorConfig2 = newConfguration.isColorConfig2;

						break;
					end;
				end;

				for _, defaultColorConfiguration in pairs(AddConfig.defaultColorConfigurations) do
					if getRimColorFromConfig == defaultColorConfiguration then
						isColorConfig = true;

						break;
					end;
				end;

				for _, defaultColorConfiguration in pairs(AddConfig.defaultColor1Configurations) do
					if getRimColorFromConfig == defaultColorConfiguration then
						isColorConfig = true;

						break;
					end;
				end;

				if isColorConfig or isColorConfig2 then
					colorName = ConfigurationUtil.getColorByConfigId(self, getRimColorFromConfig, self.configurations[getRimColorFromConfig]);
				else
					printError("(colorChanges) :: The configuration '" .. getRimColorFromConfig .. "' is not an color configuration! Stop coloring wheel weights!", false, true)
				end;
				
				if colorName ~= nil then
					for _, wheel in pairs(self.spec_wheels.wheels) do
						if wheel.wheelAdditional ~= nil then
							local r, g, b, _ = unpack(colorName);
							
							if materialId == nil then
								_, _, _, materialId = getShaderParameter(wheel.wheelAdditional, shaderParameterName);
							end;

							setShaderParameter(wheel.wheelAdditional, shaderParameterName, r, g, b, Utils.getNoNil(materialId, Utils.getNoNil(colorName[4], 0)), false);

							printDebug("(colorChanges) :: Change additional wheel color successfully in '" .. self.configFileName .. "'.", 1, true);
						end;
					end;
				end;
			end;
		end;

		--## change body color

		local colorNumber = 0;

		while true do
			local colorKey = configKey .. ".colorChanges.colorChange(" .. tostring(colorNumber) .. ")";

			if not self.xmlFile:hasProperty(colorKey) then
				break;
			end;

			local color = self.xmlFile:getString(colorKey .. "#color");
			local getColorFromConfig = self.xmlFile:getString(colorKey .. "#getColorFromConfig");
--			local shaderParameterName = Utils.getNoNil(self.xmlFile:getString(colorKey .. "#shaderParameterName"), "colorMat0");
			local shaderParameterName = self.xmlFile:getString(colorKey .. "#shaderParameterName");
			if shaderParameterName == nil then
				self.xmlFile:setString(colorKey .. "#shaderParameterName", "colorMat0");
			else
			end
			local materialName = self.xmlFile:getString(colorKey .. "#materialName");
			local materialId = self.xmlFile:getInt(colorKey .. "#materialId");
			local colorName;
			local isColorConfig = false;
			local isColorConfig2 = false;
			local doStop = false;

			if materialName ~= nil then
				if getColorFromConfig ~= nil then
					if self.configurations[getColorFromConfig] ~= nil then	
						for _, newConfguration in pairs(AddConfig.newConfgurations) do
							if getColorFromConfig == newConfguration.configName then
								isColorConfig = newConfguration.isColorConfig;
								isColorConfig2 = newConfguration.isColorConfig2;

								break;
							end;
						end;

						for _, defaultColorConfiguration in pairs(AddConfig.defaultColorConfigurations) do
							if getColorFromConfig == defaultColorConfiguration then
								isColorConfig = true;

								break;
							end;
						end;	
						for _, defaultColorConfiguration in pairs(AddConfig.defaultColor1Configurations) do
							if getColorFromConfig == defaultColorConfiguration then
								isColorConfig = true;

								break;
							end;
						end;	


						if isColorConfig or isColorConfig2 then
							colorName = ConfigurationUtil.getColorByConfigId(self, getColorFromConfig, self.configurations[getColorFromConfig]);
						else
							printError("(colorChanges) :: The configuration '" .. getColorFromConfig .. "' is not an color configuration! Stop coloring part '" .. materialName .. "'!", false, true);

							doStop = true;
						end;
					else
						printError("(colorChanges) :: Can't find the configuration '" .. getColorFromConfig .. "' in vehicle '" .. self.configFileName .. "'! Stop coloring part '" .. materialName .. "'!", false, true);

						doStop = true;
					end;
				else
					colorName = g_brandColorManager:getBrandColorByName(color);
				end;
				printDebug("shaderParameterName: ",1,true)
				AddConfig.Logging_table(shaderParameterName)
					if string.find(shaderParameterName, "0") then 
						printDebug("shaderParameterName colorMat0", 1, true)
						
						if not doStop then
							if colorName == nil then
								colorName = ConfigurationUtil.getColorFromString(color);
							end;

							if colorName ~= nil then
								self:setBaseMaterialColor(materialName, "colorMat0", colorName, Utils.getNoNil(materialId, Utils.getNoNil(colorName[4], 0)));
							
								printDebug("(colorChanges) :: Change color successfully in '" .. self.configFileName .. "' for '" .. materialName .. "' to r, g, b, [4], materialId = " .. colorName[1] .. ", " .. colorName[2] .. ", " .. colorName[3] .. ", " .. tostring(colorName[4]) .. ", " .. tostring(materialId) .. ".", 1, true);
							else
								printError("(colorChanges) :: Failed to load color '" .. tostring(color) .. "' in '" .. self.configFileName .. "'! Stop coloring '" .. materialName .. "'!", false, false);
							end;
						end;
					end;
					if string.find(shaderParameterName, "1") then 
						printDebug("shaderParameterName colorMat1", 1, true)
						
						if not doStop then
							if colorName == nil then
								colorName = ConfigurationUtil.getColorFromString(color);
							end;

							if colorName ~= nil then
								self:setBaseMaterialColor(materialName, "colorMat1", colorName, Utils.getNoNil(materialId, Utils.getNoNil(colorName[4], 0)));
							
								printDebug("(colorChanges) :: Change color successfully in '" .. self.configFileName .. "' for '" .. materialName .. "' to r, g, b, [4], materialId = " .. colorName[1] .. ", " .. colorName[2] .. ", " .. colorName[3] .. ", " .. tostring(colorName[4]) .. ", " .. tostring(materialId) .. ".", 1, true);
							else
								printError("(colorChanges) :: Failed to load color '" .. tostring(color) .. "' in '" .. self.configFileName .. "'! Stop coloring '" .. materialName .. "'!", false, false);
							end;
						end;
					end;
					if string.find(shaderParameterName, "2") then 
						printDebug("shaderParameterName colorMat2", 1, true)
						
						if not doStop then
							if colorName == nil then
								colorName = ConfigurationUtil.getColorFromString(color);
							end;

							if colorName ~= nil then
								self:setBaseMaterialColor(materialName, "colorMat2", colorName, Utils.getNoNil(materialId, Utils.getNoNil(colorName[4], 0)));
							
								printDebug("(colorChanges) :: Change color successfully in '" .. self.configFileName .. "' for '" .. materialName .. "' to r, g, b, [4], materialId = " .. colorName[1] .. ", " .. colorName[2] .. ", " .. colorName[3] .. ", " .. tostring(colorName[4]) .. ", " .. tostring(materialId) .. ".", 1, true);
							else
								printError("(colorChanges) :: Failed to load color '" .. tostring(color) .. "' in '" .. self.configFileName .. "'! Stop coloring '" .. materialName .. "'!", false, false);
							end;
						end;
					end;
					if string.find(shaderParameterName, "3") then 
						printDebug("shaderParameterName colorMat3", 1, true)
						
						if not doStop then
							if colorName == nil then
								colorName = ConfigurationUtil.getColorFromString(color);
							end;

							if colorName ~= nil then
								self:setBaseMaterialColor(materialName, "colorMat3", colorName, Utils.getNoNil(materialId, Utils.getNoNil(colorName[4], 0)));
							
								printDebug("(colorChanges) :: Change color successfully in '" .. self.configFileName .. "' for '" .. materialName .. "' to r, g, b, [4], materialId = " .. colorName[1] .. ", " .. colorName[2] .. ", " .. colorName[3] .. ", " .. tostring(colorName[4]) .. ", " .. tostring(materialId) .. ".", 1, true);
							else
								printError("(colorChanges) :: Failed to load color '" .. tostring(color) .. "' in '" .. self.configFileName .. "'! Stop coloring '" .. materialName .. "'!", false, false);
							end;
						end;
					end;
					if string.find(shaderParameterName, "4") then 
						printDebug("shaderParameterName colorMat4", 1, true)
						
						if not doStop then
							if colorName == nil then
								colorName = ConfigurationUtil.getColorFromString(color);
							end;

							if colorName ~= nil then
								self:setBaseMaterialColor(materialName, "colorMat4", colorName, Utils.getNoNil(materialId, Utils.getNoNil(colorName[4], 0)));
							
								printDebug("(colorChanges) :: Change color successfully in '" .. self.configFileName .. "' for '" .. materialName .. "' to r, g, b, [4], materialId = " .. colorName[1] .. ", " .. colorName[2] .. ", " .. colorName[3] .. ", " .. tostring(colorName[4]) .. ", " .. tostring(materialId) .. ".", 1, true);
							else
								printError("(colorChanges) :: Failed to load color '" .. tostring(color) .. "' in '" .. self.configFileName .. "'! Stop coloring '" .. materialName .. "'!", false, false);
							end;
						end;
					end;
					if string.find(shaderParameterName, "5") then 
						printDebug("shaderParameterName colorMat5", 1, true)
						
						if not doStop then
							if colorName == nil then
								colorName = ConfigurationUtil.getColorFromString(color);
							end;

							if colorName ~= nil then
								self:setBaseMaterialColor(materialName, "colorMat5", colorName, Utils.getNoNil(materialId, Utils.getNoNil(colorName[4], 0)));
							
								printDebug("(colorChanges) :: Change color successfully in '" .. self.configFileName .. "' for '" .. materialName .. "' to r, g, b, [4], materialId = " .. colorName[1] .. ", " .. colorName[2] .. ", " .. colorName[3] .. ", " .. tostring(colorName[4]) .. ", " .. tostring(materialId) .. ".", 1, true);
							else
								printError("(colorChanges) :: Failed to load color '" .. tostring(color) .. "' in '" .. self.configFileName .. "'! Stop coloring '" .. materialName .. "'!", false, false);
							end;
						end;
					end;
					if string.find(shaderParameterName, "6") then 
						printDebug("shaderParameterName colorMat6", 1, true)
						
						if not doStop then
							if colorName == nil then
								colorName = ConfigurationUtil.getColorFromString(color);
							end;

							if colorName ~= nil then
								self:setBaseMaterialColor(materialName, "colorMat6", colorName, Utils.getNoNil(materialId, Utils.getNoNil(colorName[4], 0)));
							
								printDebug("(colorChanges) :: Change color successfully in '" .. self.configFileName .. "' for '" .. materialName .. "' to r, g, b, [4], materialId = " .. colorName[1] .. ", " .. colorName[2] .. ", " .. colorName[3] .. ", " .. tostring(colorName[4]) .. ", " .. tostring(materialId) .. ".", 1, true);
							else
								printError("(colorChanges) :: Failed to load color '" .. tostring(color) .. "' in '" .. self.configFileName .. "'! Stop coloring '" .. materialName .. "'!", false, false);
							end;
						end;
					end;
					if string.find(shaderParameterName, "7") then 
						printDebug("shaderParameterName colorMat7", 1, true)
						
						if not doStop then
							if colorName == nil then
								colorName = ConfigurationUtil.getColorFromString(color);
							end;

							if colorName ~= nil then
								self:setBaseMaterialColor(materialName, "colorMat7", colorName, Utils.getNoNil(materialId, Utils.getNoNil(colorName[4], 0)));
							
								printDebug("(colorChanges) :: Change color successfully in '" .. self.configFileName .. "' for '" .. materialName .. "' to r, g, b, [4], materialId = " .. colorName[1] .. ", " .. colorName[2] .. ", " .. colorName[3] .. ", " .. tostring(colorName[4]) .. ", " .. tostring(materialId) .. ".", 1, true);
							else
								printError("(colorChanges) :: Failed to load color '" .. tostring(color) .. "' in '" .. self.configFileName .. "'! Stop coloring '" .. materialName .. "'!", false, false);
							end;
						end;
					end;
					
			else
				printError("(colorChanges) :: Missing 'materialName' in '" .. self.configFileName .. "'! Stop coloring this vehicle body!", false, false);
			end;

			colorNumber = colorNumber + 1;
		end;

		--## change crawler color

		local crawlerColorNumber = 0;

		while true do
			local crawlerColorKey = configKey .. ".colorChanges.crawler(" .. tostring(crawlerColorNumber) .. ")";

			if not self.xmlFile:hasProperty(crawlerColorKey) then
				break;
			end;


			local specCrawlers = self.spec_crawlers;
		
			if specCrawlers ~= nil then
				local crawlerColorStr = self.xmlFile:getString(crawlerColorKey .. "#color");
				local getColorFromConfigCrawler = self.xmlFile:getString(crawlerColorKey .. "#getColorFromConfig");
				local materialId = self.xmlFile:getInt(crawlerColorKey .. "#materialId");
				local shaderParameterName = Utils.getNoNil(self.xmlFile:getString(crawlerColorKey .. "#shaderParameterName"), "colorMat0");
				local isColorConfig = false;
				local isColorConfig2 = false;

				if crawlerColorStr ~= nil or getColorFromConfigCrawler ~= nil then
	--				crawlerColor = g_brandColorManager:getBrandColorByName(crawlerColorStr);
					local crawlerColor;
					if getColorFromConfigCrawler ~= nil then
						if self.configurations[getColorFromConfigCrawler] ~= nil then	
							for _, newConfguration in pairs(AddConfig.newConfgurations) do
								if getColorFromConfigCrawler == newConfguration.configName then
									isColorConfig = newConfguration.isColorConfig;
									isColorConfig2 = newConfguration.isColorConfig2;

									break;
								end;
							end;

							for _, defaultColorConfiguration in pairs(AddConfig.defaultColorConfigurations) do
								if getColorFromConfigCrawler == defaultColorConfiguration then
									isColorConfig = true;

									break;
								end;
							end;
							for _, defaultColorConfiguration in pairs(AddConfig.defaultColor1Configurations) do
								if getColorFromConfigCrawler == defaultColorConfiguration then
									isColorConfig = true;

									break;
								end;
							end;


							if isColorConfig or isColorConfig2 then
								crawlerColor = ConfigurationUtil.getColorByConfigId(self, getColorFromConfigCrawler, self.configurations[getColorFromConfigCrawler]);
							else
								printError("(colorChanges) :: The configuration '" .. getColorFromConfigCrawler .. "' is not an color configuration! '!", false, true);
							end;
						else
							printError("(colorChanges) :: Can't find configuration '" .. getColorFromConfigCrawler .. "' in vehicle '" .. self.configFileName .. "'! Stop coloring part '!", false, true);
						end;
					else
						crawlerColor = g_brandColorManager:getBrandColorByName(crawlerColorStr);
					end;
				
					if crawlerColor == nil then
						crawlerColor = string.getVectorN(crawlerColorStr, 3);
					end;
				
				
					for _, crawler in pairs(specCrawlers.crawlers) do
						I3DUtil.setShaderParameterRec(crawler.loadedCrawler, shaderParameterName, crawlerColor[1], crawlerColor[2], crawlerColor[3], Utils.getNoNil(materialId, Utils.getNoNil(crawlerColor[4], 0)));

						printDebug("(colorChanges) :: Change crawler color '" .. shaderParameterName .. "' successfully in '" .. self.configFileName .. "' to  '" .. getColorFromConfigCrawler .. "'  for '" .. getName(crawler.loadedCrawler) .. "'.", 1, true);

						for _, scrollerNode in pairs(crawler.scrollerNodes) do
							--## fix for not coloring the track..
							setShaderParameter(scrollerNode.node, "colorMat0", 0.028, 0.025, 0.023, 5, false);

							printDebug("(colorChanges) :: Stop coloring successfully in '" .. self.configFileName .. "' for '" .. getName(scrollerNode.node) .. "'.", 1, true);
						end;
					end;
				end;
			end;

			crawlerColorNumber = crawlerColorNumber + 1;
		end;
			
		--## change top arm color

		local topArmColorNumber = 0;

		while true do
			local topArmColorKey = configKey .. ".colorChanges.topArm(" .. tostring(topArmColorNumber) .. ")";

			if not self.xmlFile:hasProperty(topArmColorKey) then
				break;
			end;

			-- local attacherJointIndices = {StringUtil.getVectorFromString(self.xmlFile:getString(topArmColorKey .. "#attacherJointIndices"))};
			local attacherJointIndices = {string.getVector(self.xmlFile:getString(topArmColorKey .. "#attacherJointIndices"))};
			local topArmColorStr = self.xmlFile:getString(topArmColorKey .. "#color");
			local getColorFromConfigTopArm = self.xmlFile:getString(topArmColorKey .. "#getColorFromConfig");
			local materialId = self.xmlFile:getInt(topArmColorKey .. "#materialId");
			local shaderParameterName = Utils.getNoNil(self.xmlFile:getString(topArmColorKey .. "#shaderParameterName"), "colorMat0");
			local isColorConfig = false;
			local isColorConfig2 = false;
			
			if topArmColorStr ~= nil or getColorFromConfigTopArm ~= nil then
				local topArmColor;
					if getColorFromConfigTopArm ~= nil then
						if self.configurations[getColorFromConfigTopArm] ~= nil then	
							for _, newConfguration in pairs(AddConfig.newConfgurations) do
								if getColorFromConfigTopArm == newConfguration.configName then
									isColorConfig = newConfguration.isColorConfig;
									isColorConfig2 = newConfguration.isColorConfig2;

									break;
								end;
							end;

							for _, defaultColorConfiguration in pairs(AddConfig.defaultColorConfigurations) do
								if getColorFromConfigTopArm == defaultColorConfiguration then
									isColorConfig = true;

									break;
								end;
							end;
							for _, defaultColorConfiguration in pairs(AddConfig.defaultColor1Configurations) do
								if getColorFromConfigTopArm == defaultColorConfiguration then
									isColorConfig = true;

									break;
								end;
							end;


							if isColorConfig or isColorConfig2 then
								topArmColor = ConfigurationUtil.getColorByConfigId(self, getColorFromConfigTopArm, self.configurations[getColorFromConfigTopArm]);
							else
								printError("(colorChanges) :: The configuration '" .. getColorFromConfigTopArm .. "' is not an color configuration! '!", false, true);
							end;
						else
							printError("(colorChanges) :: Can't find configuration '" .. getColorFromConfigTopArm .. "' in vehicle '" .. self.configFileName .. "'! Stop coloring part '!", false, true);
						end;
					else
						topArmColor = g_brandColorManager:getBrandColorByName(topArmColorStr);
					end;

				if topArmColor == nil then
					topArmColor = string.getVectorN(topArmColorStr, 3);
				end;

				if attacherJointIndices ~= nil then
					for _, attacherJointIndice in pairs(attacherJointIndices) do
						local baseName = string.format("vehicle.attacherJoints.attacherJoint(" .. attacherJointIndice - 1 .. ")");

						if self.xmlFile:hasProperty(baseName) then
							local baseNode = I3DUtil.indexToObject(self.components, self.xmlFile:getString(baseName.. ".topArm#baseNode"), self.i3dMappings);

							if baseNode ~= nil then
								printDebug("load attacherJoint: ", 1, true)
								AddConfig.Logging_table(attacherJointIndice)
								AddConfig.Logging_table(self.spec_attacherJoints.attacherJoints[attacherJointIndice].sharedLoadRequestIdTopArm)

								
								I3DUtil.setShaderParameterRec(baseNode, shaderParameterName, topArmColor[1], topArmColor[2], topArmColor[3], Utils.getNoNil(materialId, Utils.getNoNil(topArmColor[4], 0)));

								printDebug("(colorChanges) :: Change top arm color (" .. shaderParameterName .. ") successfully in '" .. self.configFileName .. "' to r, g, b, [4], materialId = " .. topArmColor[1] .. ", " .. topArmColor[2] .. ", " .. topArmColor[3] .. ", " .. tostring(topArmColor[4]) .. ", " .. tostring(materialId) .. "  for '" .. getName(baseNode) .. "'.", 1, true);

							end;
						end;
					end;
				end;
			end;
			topArmColorNumber = topArmColorNumber + 1;
		end;

		--## change starfire color

		local starfireNumber = 0;

		while true do
			local starfireKey = configKey .. ".colorChanges.starfires.starfire(" .. tostring(starfireNumber) .. ")";

			if not self.xmlFile:hasProperty(starfireKey) then
				break;
			end;

			local starfire = I3DUtil.indexToObject(self.components, self.xmlFile:getString(starfireKey .. "#node"), self.i3dMappings);

			if starfire ~= nil then
				local starfireColorStr = self.xmlFile:getString(starfireKey .. "#color");
				local shaderParameterName = Utils.getNoNil(self.xmlFile:getString(starfireKey .. "#shaderParameterName"), "colorMat0");
				local getColorFromConfigStarfire = self.xmlFile:getString(starfireKey .. "#getColorFromConfig");
				local isColorConfig = false;
				local isColorConfig2 = false;


				if starfireColorStr ~= nil or getColorFromConfigStarfire ~= nil then
					local starfireColor;
				
					if getColorFromConfigStarfire ~= nil then
						if self.configurations[getColorFromConfigStarfire] ~= nil then	
							for _, newConfguration in pairs(AddConfig.newConfgurations) do
								if getColorFromConfigStarfire == newConfguration.configName then
									isColorConfig = newConfguration.isColorConfig;
									isColorConfig2 = newConfguration.isColorConfig2;

									break;
								end;
							end;

							for _, defaultColorConfiguration in pairs(AddConfig.defaultColorConfigurations) do
								if getColorFromConfigStarfire == defaultColorConfiguration then
									isColorConfig = true;

									break;
								end;
							end;
							for _, defaultColorConfiguration in pairs(AddConfig.defaultColor1Configurations) do
								if getColorFromConfigStarfire == defaultColorConfiguration then
									isColorConfig = true;

									break;
								end;
							end;


							if isColorConfig or isColorConfig2 then
								starfireColor = ConfigurationUtil.getColorByConfigId(self, getColorFromConfigStarfire, self.configurations[getColorFromConfigStarfire]);
							else
								printError("(colorChanges) :: The configuration '" .. getColorFromConfigStarfire .. "' is not an color configuration! '!", false, true);
							end;
						else
							printError("(colorChanges) :: Can't find configuration '" .. getColorFromConfigStarfire .. "' in vehicle '" .. self.configFileName .. "'! Stop coloring part '!", false, true);
						end;
					else
						starfireColor = g_brandColorManager:getBrandColorByName(starfireColorStr);
					end;
				
					if starfireColor == nil then
						starfireColor = string.getVectorN(starfireColorStr, 3);
					end;

					local materialId = self.xmlFile:getInt(starfireKey .. "#materialId");

					if starfireColor ~= nil then

						I3DUtil.setShaderParameterRec(starfire, shaderParameterName, starfireColor[1], starfireColor[2], starfireColor[3], Utils.getNoNil(materialId, Utils.getNoNil(starfireColor[4], 0)));

						printDebug("(colorChanges) :: Change starfire color (" .. shaderParameterName .. ") successfully in '" .. self.configFileName .. "' to r, g, b, [4], materialId = " .. starfireColor[1] .. ", " .. starfireColor[2] .. ", " .. starfireColor[3] .. ", " .. tostring(starfireColor[4]) .. ", " .. tostring(materialId) .. "  for '" .. getName(starfire) .. "'.", 1, true);
					else
						printError("(colorChanges) :: Failed to load color (colorMat0) '" .. tostring(starfireColor) .. "' in '" .. self.configFileName .. "'! Stop coloring starfire!", false, false);
					end;

				end;

				local decalMaterialHolderNode = I3DUtil.indexToObject(self.components, self.xmlFile:getString(starfireKey .. "#decalMaterialHolderNode"), self.i3dMappings);

				if decalMaterialHolderNode ~= nil then
					local decalIndex = Utils.getNoNil(self.xmlFile:getInt(starfireKey .. "#decalIndex"), 0);
					local getChildFromStarfire = Utils.getNoNil(self.xmlFile:getBool(starfireKey .. "#getChildFromStarfire"), true);
					local starfireNode = starfire;

					if getChildFromStarfire then
						starfireNode = getChildAt(starfire, 0);
					end;
					
					if getHasClassId(starfireNode, ClassIds.SHAPE) then
						if getHasClassId(getChildAt(starfireNode, decalIndex), ClassIds.SHAPE) then
							local newMaterial = getMaterial(decalMaterialHolderNode, 0);

							setMaterial(getChildAt(starfireNode, decalIndex), newMaterial, 0);

							printDebug("(colorChanges) :: Change starfire decal color successfully in '" .. self.configFileName .. "' for node '" .. getName(getChildAt(starfireNode, decalIndex)) .. "'.", 1, true);
						else
							printError("(colorChanges) :: The decal node  '" .. getName(getChildAt(starfireNode, decalIndex)) .. "' is not a shape in '" .. self.configFileName .. "'! Stop change starfire decal!", false, false);
						end;
					else
						printError("(colorChanges) :: The parent node  '" .. getName(starfireNode) .. "' is not a shape in '" .. self.configFileName .. "'! Stop change starfire decal!", false, false);
					end;
        		end;
			end;

			starfireNumber = starfireNumber + 1;
		end;
		
		
		--## change rim and axis color
		if self.spec_wheels ~= nil then
			local innerRimColor = self.xmlFile:getString(configKey .. ".colorChanges.innerRim#color");
			local outerRimColor = self.xmlFile:getString(configKey .. ".colorChanges.outerRim#color");
			local additionalColor = Utils.getNoNil(self.xmlFile:getString(configKey .. ".colorChanges.additional#color"), self.xmlFile:getString(configKey .. ".colorChanges.rim#color"));
			local getColorFromConfigInn = self.xmlFile:getString(configKey .. ".colorChanges.innerRim#getColorFromConfig");
			local getColorFromConfigOut = self.xmlFile:getString(configKey .. ".colorChanges.outerRim#getColorFromConfig");
			local getColorFromConfigAdd = self.xmlFile:getString(configKey .. ".colorChanges.additional#getColorFromConfig");
			local isColorConfig = false;
			local isColorConfig2 = false;

			if additionalColor ~= nil or getColorFromConfigAdd ~= nil then
				local materialId = self.xmlFile:getInt(configKey .. ".colorChanges.additional#materialId");
				local shaderParameterName = Utils.getNoNil(self.xmlFile:getString(configKey .. ".colorChanges.additional#shaderParameterName"), "colorMat0");
--				local additionalColorName = g_brandColorManager:getBrandColorByName(additionalColor);
				local additionalColorName;

					if getColorFromConfigAdd ~= nil then
						if self.configurations[getColorFromConfigAdd] ~= nil then	
							for _, newConfguration in pairs(AddConfig.newConfgurations) do
								if getColorFromConfigAdd == newConfguration.configName then
									isColorConfig = newConfguration.isColorConfig;
									isColorConfig2 = newConfguration.isColorConfig2;

									break;
								end;
							end;

							for _, defaultColorConfiguration in pairs(AddConfig.defaultColorConfigurations) do
								if getColorFromConfigAdd == defaultColorConfiguration then
									isColorConfig = true;

									break;
								end;
							end;
							for _, defaultColorConfiguration in pairs(AddConfig.defaultColor1Configurations) do
								if getColorFromConfigAdd == defaultColorConfiguration then
									isColorConfig = true;

									break;
								end;
							end;


							if isColorConfig or isColorConfig2 then
								additionalColorName = ConfigurationUtil.getColorByConfigId(self, getColorFromConfigAdd, self.configurations[getColorFromConfigAdd]);
							else
								printError("(colorChanges) :: The configuration '" .. getColorFromConfigAdd .. "' is not an color configuration! Stop coloring additional wheels!", false, true);
							end;
						else
							printError("(colorChanges) :: Can't find configuration '" .. getColorFromConfigAdd .. "' in vehicle '" .. self.configFileName .. "'! Stop coloring additional wheels!", false, true);
						end;
					else
						additionalColorName = g_brandColorManager:getBrandColorByName(additionalColor);
					end;

				if additionalColorName == nil then
					additionalColorName = ConfigurationUtil.getColorFromString(additionalColor);
				end;
				
				if additionalColorName ~= nil then
					local r, g, b, _ = unpack(additionalColorName);

					for _, wheel in pairs(self.spec_wheels.wheels) do
						if wheel.wheelAdditional ~= nil then
							if materialId == nil then
								_, _, _, materialId = getShaderParameter(wheel.wheelAdditional, shaderParameterName);
							end;

							setShaderParameter(wheel.wheelAdditional, shaderParameterName, r, g, b, materialId, false);

							printDebug("(colorChanges) :: Change additional wheel color (" .. shaderParameterName .. ") successfully in '" .. self.configFileName .. "' to r, g, b, [4], materialId = " .. additionalColorName[1] .. ", " .. additionalColorName[2] .. ", " .. additionalColorName[3] .. ", " .. tostring(additionalColorName[4]) .. ", " .. tostring(materialId) .. ".", 1, true);
						end;
					end;
				else
					printError("(colorChanges) :: Failed to load color '" .. tostring(additionalColor) .. "' in '" .. self.configFileName .. "'! Stop coloring additional wheels!", false, false);
				end;
			end;

			local hubColorNumber = 0;

			while true do
				local hubColorKey = configKey .. ".colorChanges.hub(" .. tostring(hubColorNumber) .. ")";

				if not self.xmlFile:hasProperty(hubColorKey) then
					break;
				end;

				local getColorFromConfig = self.xmlFile:getString(hubColorKey .. "#getColorFromConfig");
				local hubColor = self.xmlFile:getString(hubColorKey .. "#color");
				local hubColorName;

				if getColorFromConfig ~= nil then
					if self.configurations[getColorFromConfig] ~= nil then	
						for _, newConfguration in pairs(AddConfig.newConfgurations) do
							if getColorFromConfig == newConfguration.configName then
								isColorConfig = newConfguration.isColorConfig;
								isColorConfig2 = newConfguration.isColorConfig2;

								break;
							end;
						end;

						for _, defaultColorConfiguration in pairs(AddConfig.defaultColorConfigurations) do
							if getColorFromConfig == defaultColorConfiguration then
								isColorConfig = true;

								break;
							end;
						end;	
						for _, defaultColorConfiguration in pairs(AddConfig.defaultColor1Configurations) do
							if getColorFromConfig == defaultColorConfiguration then
								isColorConfig = true;

								break;
							end;
						end;	


						if isColorConfig or isColorConfig2 then
							hubColorName = ConfigurationUtil.getColorByConfigId(self, getColorFromConfig, self.configurations[getColorFromConfig]);
						else
							printError("(colorChanges) :: The configuration '" .. getColorFromConfig .. "' is not an color configuration! Stop coloring rims!", false, true);

							doStop = true;
						end;
					else
						printError("(colorChanges) :: Can't find the configuration '" .. getColorFromConfig .. "' in vehicle '" .. self.configFileName .. "'! Stop coloring rims!", false, true);

						doStop = true;
					end;
				end;

				if hubColor ~= nil or hubColorName ~= nil then			
					local materialId = self.xmlFile:getInt(hubColorKey .. "#materialId");
					local shaderParameterName = Utils.getNoNil(self.xmlFile:getString(hubColorKey .. "#shaderParameterName"), "colorMat0");

					if hubColor ~= nil then
						hubColorName = g_brandColorManager:getBrandColorByName(hubColor);

						if hubColorName == nil then
							hubColorName = ConfigurationUtil.getColorFromString(hubColor);
						end;
					end;

					if hubColorName ~= nil then
						local r, g, b, mat = unpack(hubColorName);

						for _, hub in pairs(self.spec_wheels.hubs) do
							if hub.node ~= nil then
								if getHasShaderParameter(hub.node, shaderParameterName) then	
									if materialId == nil then
										materialId = mat;
									
										if materialId == nil then	
											_, _, _, materialId = getShaderParameter(hub.node, shaderParameterName);
										end;
									end;
								
									setShaderParameter(hub.node, shaderParameterName, r, g, b, materialId, false);
								
									-- printDebug("(colorChanges) :: Change outer rim color (shaderParameterName = '" .. shaderParameterName .. "') successfully in '" .. self.configFileName .. "'.", 1, true);
									printDebug("(colorChanges) :: Change hub color (" .. shaderParameterName .. ") successfully in '" .. self.configFileName .. "' to r, g, b, [4], materialId = " .. hubColorName[1] .. ", " .. hubColorName[2] .. ", " .. hubColorName[3] .. ", " .. tostring(hubColorName[4]) .. ", " .. tostring(materialId) .. ".", 1, true);
								else
									printError("(colorChanges) :: Failed to load shader parameter '" .. tostring(shaderParameterName) .. "' in '" .. self.configFileName .. "'! Stop coloring outer rims!", false, false);
								end;
							end;

						end;
					else
						printError("(colorChanges) :: Failed to load color '" .. tostring(hubColor) .. "' in '" .. self.configFileName .. "'! Stop coloring rims!", false, false);
					end;
				end;
				
				hubColorNumber = hubColorNumber + 1;
			end;
			
			local rimColorNumber = 0;

			while true do
				local rimColorKey = configKey .. ".colorChanges.rim(" .. tostring(rimColorNumber) .. ")";

				if not self.xmlFile:hasProperty(rimColorKey) then
					break;
				end;

				local getColorFromConfig = self.xmlFile:getString(rimColorKey .. "#getColorFromConfig");
				local rimColor = self.xmlFile:getString(rimColorKey .. "#color");
				local rimColorName;
				local isColorConfig = false;
				local isColorConfig2 = false;

				if getColorFromConfig ~= nil then
					if self.configurations[getColorFromConfig] ~= nil then	
						for _, newConfguration in pairs(AddConfig.newConfgurations) do
							if getColorFromConfig == newConfguration.configName then
								isColorConfig = newConfguration.isColorConfig;
								isColorConfig2 = newConfguration.isColorConfig2;

								break;
							end;
						end;

						for _, defaultColorConfiguration in pairs(AddConfig.defaultColorConfigurations) do
							if getColorFromConfig == defaultColorConfiguration then
								isColorConfig = true;

								break;
							end;
						end;	

						for _, defaultColorConfiguration in pairs(AddConfig.defaultColor1Configurations) do
							if getColorFromConfig == defaultColorConfiguration then
								isColorConfig = true;

								break;
							end;
						end;	


						if isColorConfig or isColorConfig2 then
							rimColorName = ConfigurationUtil.getColorByConfigId(self, getColorFromConfig, self.configurations[getColorFromConfig]);
						else
							printError("(colorChanges) :: The configuration '" .. getColorFromConfig .. "' is not an color configuration! Stop coloring rims!", false, true);

							doStop = true;
						end;
					else
						printError("(colorChanges) :: Can't find the configuration '" .. getColorFromConfig .. "' in vehicle '" .. self.configFileName .. "'! Stop coloring rims!", false, true);

						doStop = true;
					end;
				end;

				if rimColor ~= nil or rimColorName ~= nil then			
					local materialId = self.xmlFile:getInt(rimColorKey .. "#materialId");
					local shaderParameterName = Utils.getNoNil(self.xmlFile:getString(rimColorKey .. "#shaderParameterName"), "colorMat0");

					if rimColor ~= nil then
						rimColorName = g_brandColorManager:getBrandColorByName(rimColor);

						if rimColorName == nil then
							rimColorName = ConfigurationUtil.getColorFromString(rimColor);
						end;
					end;

					if rimColorName ~= nil then
						local r, g, b, mat = unpack(rimColorName);

						for _, wheel in pairs(self.spec_wheels.wheels) do
							if wheel.wheelOuterRim ~= nil then
								if getHasShaderParameter(wheel.wheelOuterRim, shaderParameterName) then	
									if materialId == nil then
										materialId = mat;
									
										if materialId == nil then	
											_, _, _, materialId = getShaderParameter(wheel.wheelOuterRim, shaderParameterName);
										end;
									end;
								
									setShaderParameter(wheel.wheelOuterRim, shaderParameterName, r, g, b, materialId, false);
								
									-- printDebug("(colorChanges) :: Change outer rim color (shaderParameterName = '" .. shaderParameterName .. "') successfully in '" .. self.configFileName .. "'.", 1, true);
									printDebug("(colorChanges) :: Change outer rim color (" .. shaderParameterName .. ") successfully in '" .. self.configFileName .. "' to r, g, b, [4], materialId = " .. rimColorName[1] .. ", " .. rimColorName[2] .. ", " .. rimColorName[3] .. ", " .. tostring(rimColorName[4]) .. ", " .. tostring(materialId) .. ".", 1, true);
								else
									printError("(colorChanges) :: Failed to load shader parameter '" .. tostring(shaderParameterName) .. "' in '" .. self.configFileName .. "'! Stop coloring outer rims!", false, false);
								end;
							end;

							if wheel.wheelInnerRim ~= nil then
								if getHasShaderParameter(wheel.wheelInnerRim, shaderParameterName) then
									if materialId == nil then
										materialId = mat;
									
										if materialId == nil then	
											_, _, _, materialId = getShaderParameter(wheel.wheelInnerRim, shaderParameterName);
										end;
									end;
								
									setShaderParameter(wheel.wheelInnerRim, shaderParameterName, r, g, b, materialId, false);
								
									-- printDebug("(colorChanges) :: Change inner rim color (shaderParameterName = '" .. shaderParameterName .. "') successfully in '" .. self.configFileName .. "'.", 1, true);
									printDebug("(colorChanges) :: Change inner rim color (" .. shaderParameterName .. ") successfully in '" .. self.configFileName .. "' to r, g, b, [4], materialId = " .. rimColorName[1] .. ", " .. rimColorName[2] .. ", " .. rimColorName[3] .. ", " .. tostring(rimColorName[4]) .. ", " .. tostring(materialId) .. ".", 1, true);
								else
									printError("(colorChanges) :: Failed to load shader parameter '" .. tostring(shaderParameterName) .. "' in '" .. self.configFileName .. "'! Stop coloring inner rims!", false, false);
								end;
							end;

							if wheel.additionalWheels ~= nil then
								for _, additionalWheel in pairs(wheel.additionalWheels) do	
									if additionalWheel.wheelOuterRim ~= nil then	
										if getHasShaderParameter(additionalWheel.wheelOuterRim, shaderParameterName) then	
											if materialId == nil then
												materialId = mat;
											
												if materialId == nil then	
													_, _, _, materialId = getShaderParameter(additionalWheel.wheelOuterRim, shaderParameterName);
												end;
											end;
										
											setShaderParameter(additionalWheel.wheelOuterRim, shaderParameterName, r, g, b, materialId, false);

											-- printDebug("(colorChanges) :: Change additional outer rim color (shaderParameterName = '" .. shaderParameterName .. "') successfully in '" .. self.configFileName .. "'.", 1, true);
											printDebug("(colorChanges) :: Change additional outer rim color (" .. shaderParameterName .. ") successfully in '" .. self.configFileName .. "' to r, g, b, [4], materialId = " .. rimColorName[1] .. ", " .. rimColorName[2] .. ", " .. rimColorName[3] .. ", " .. tostring(rimColorName[4]) .. ", " .. tostring(materialId) .. ".", 1, true);
										else
											printError("(colorChanges) :: Failed to load shader parameter '" .. tostring(shaderParameterName) .. "' in '" .. self.configFileName .. "'! Stop coloring additional outer rims!", false, false);
										end;
									end;

									if additionalWheel.wheelInnerRim ~= nil then
										if getHasShaderParameter(additionalWheel.wheelInnerRim, shaderParameterName) then
											if materialId == nil then
												materialId = mat;
											
												if materialId == nil then	
													_, _, _, materialId = getShaderParameter(additionalWheel.wheelInnerRim, shaderParameterName);
												end;
											end;
										
											setShaderParameter(additionalWheel.wheelInnerRim, shaderParameterName, r, g, b, materialId, false);

											printDebug("(colorChanges) :: Change additional inner rim color (" .. shaderParameterName .. ") successfully in '" .. self.configFileName .. "' to r, g, b, [4], materialId = " .. rimColorName[1] .. ", " .. rimColorName[2] .. ", " .. rimColorName[3] .. ", " .. tostring(rimColorName[4]) .. ", " .. tostring(materialId) .. ".", 1, true);
											-- printDebug("(colorChanges) :: Change inner rim color (shaderParameterName = '" .. shaderParameterName .. "') successfully in '" .. self.configFileName .. "'.", 1, true);
										else
											printError("(colorChanges) :: Failed to load shader parameter '" .. tostring(shaderParameterName) .. "' in '" .. self.configFileName .. "'! Stop coloring additional inner rims!", false, false);
										end;
									end;

									if additionalWheel.connector ~= nil and additionalWheel.connector.node ~= nil then	
										if getHasShaderParameter(additionalWheel.connector.node, shaderParameterName) then
											if materialId == nil then
												materialId = mat;
											
												if materialId == nil then
													_, _, _, materialId = getShaderParameter(additionalWheel.connector.node, shaderParameterName);
												end;
											end;
										
											setShaderParameter(additionalWheel.connector.node, shaderParameterName, r, g, b, materialId, false);

											printDebug("(colorChanges) :: Change additional connector color (" .. shaderParameterName .. ") successfully in '" .. self.configFileName .. "' to r, g, b, [4], materialId = " .. rimColorName[1] .. ", " .. rimColorName[2] .. ", " .. rimColorName[3] .. ", " .. tostring(rimColorName[4]) .. ", " .. tostring(materialId) .. ".", 1, true);
											-- printDebug("(colorChanges) :: Change additional connector color (shaderParameterName = '" .. shaderParameterName .. "') successfully in '" .. self.configFileName .. "'.", 1, true);
										else
											printError("(colorChanges) :: Failed to load shader parameter '" .. tostring(shaderParameterName) .. "' in '" .. self.configFileName .. "'! Stop coloring additional connector!", false, false);
										end;
									end;
								end;
							end;
						end;
					else
						printError("(colorChanges) :: Failed to load color '" .. tostring(rimColor) .. "' in '" .. self.configFileName .. "'! Stop coloring rims!", false, false);
					end;
				end;
				
				rimColorNumber = rimColorNumber + 1;
			end;

			if innerRimColor ~= nil or getColorFromConfigInn ~= nil then
				local materialId = self.xmlFile:getInt(configKey .. ".colorChanges.innerRimColor#materialId");
				local shaderParameterName = Utils.getNoNil(self.xmlFile:getString(configKey .. ".colorChanges.innerRimColor#shaderParameterName"), "colorMat0");
--				local additionalColorName = g_brandColorManager:getBrandColorByName(additionalColor);
				local innerRimColorName;
				local isColorConfig = false;
				local isColorConfig2 = false;

					if getColorFromConfigInn ~= nil then
						if self.configurations[getColorFromConfigInn] ~= nil then	
							for _, newConfguration in pairs(AddConfig.newConfgurations) do
								if getColorFromConfigInn == newConfguration.configName then
									isColorConfig = newConfguration.isColorConfig;
									isColorConfig2 = newConfguration.isColorConfig2;

									break;
								end;
							end;

							for _, defaultColorConfiguration in pairs(AddConfig.defaultColorConfigurations) do
								if getColorFromConfigInn == defaultColorConfiguration then
									isColorConfig = true;

									break;
								end;
							end;

							for _, defaultColorConfiguration in pairs(AddConfig.defaultColor1Configurations) do
								if getColorFromConfigInn == defaultColorConfiguration then
									isColorConfig = true;

									break;
								end;
							end;


							if isColorConfig or isColorConfig2 then
								additionalColorName = ConfigurationUtil.getColorByConfigId(self, getColorFromConfigInn, self.configurations[getColorFromConfigInn]);
							else
								printError("(colorChanges) :: The configuration '" .. getColorFromConfigInn .. "' is not an color configuration! Stop coloring inner rims!", false, true);
							end;
						else
							printError("(colorChanges) :: Can't find configuration '" .. getColorFromConfigInn .. "' in vehicle '" .. self.configFileName .. "'! Stop coloring part inner rims!", false, true);
						end;
					else
						innerRimColorName = g_brandColorManager:getBrandColorByName(innerRimColor);
					end;

				if innerRimColorName == nil then
					innerRimColorName = ConfigurationUtil.getColorFromString(innerRimColor);
				end;

				if innerRimColorName ~= nil then
					local r, g, b, mat = unpack(innerRimColorName);
					
					for _, wheel in pairs(self.spec_wheels.wheels) do
						if wheel.wheelInnerRim ~= nil then
							if getHasShaderParameter(wheel.wheelInnerRim, shaderParameterName) then
								if materialId == nil then
									materialId = mat;

									if materialId == nil then	
										_, _, _, materialId = getShaderParameter(wheel.wheelInnerRim, shaderParameterName);
									end;
								end;
							
								setShaderParameter(wheel.wheelInnerRim, shaderParameterName, r, g, b, materialId, false);
							
						-- printDebug("(colorChanges) :: Change starfire color (" .. shaderParameterName .. ") successfully in '" .. self.configFileName .. "' to r, g, b, [4], materialId = " .. starfireColor[1] .. ", " .. starfireColor[2] .. ", " .. starfireColor[3] .. ", " .. tostring(starfireColor[4]) .. ", " .. tostring(materialId) .. "  for '" .. getName(starfire) .. "'.", 1, true);
								printDebug("(colorChanges) :: Change inner rim color successfully in '" .. self.configFileName .. "'.", 1, true);
							else
								printError("(colorChanges) :: Failed to load shader parameter '" .. tostring(shaderParameterName) .. "' in '" .. self.configFileName .. "'! Stop coloring inner rims!", false, false);
							end;
						end;

						if wheel.additionalWheels ~= nil then
							for _, additionalWheel in pairs(wheel.additionalWheels) do	
								if additionalWheel.wheelInnerRim ~= nil then
									if getHasShaderParameter(additionalWheel.wheelInnerRim, shaderParameterName) then
										if materialId == nil then
											materialId = mat;
										
											if materialId == nil then	
												_, _, _, materialId = getShaderParameter(additionalWheel.wheelInnerRim, shaderParameterName);
											end;
										end;
									
										setShaderParameter(additionalWheel.wheelInnerRim, shaderParameterName, r, g, b, materialId, false);

						-- printDebug("(colorChanges) :: Change starfire color (" .. shaderParameterName .. ") successfully in '" .. self.configFileName .. "' to r, g, b, [4], materialId = " .. starfireColor[1] .. ", " .. starfireColor[2] .. ", " .. starfireColor[3] .. ", " .. tostring(starfireColor[4]) .. ", " .. tostring(materialId) .. "  for '" .. getName(starfire) .. "'.", 1, true);
										printDebug("(colorChanges) :: Change additional inner rim color successfully in '" .. self.configFileName .. "'.", 1, true);
									else
										printError("(colorChanges) :: Failed to load shader parameter '" .. tostring(shaderParameterName) .. "' in '" .. self.configFileName .. "'! Stop coloring additional inner rims!", false, false);
									end;
								end;
							end;
						end;
					end;
				else
					printError("(colorChanges) :: Failed to load color '" .. tostring(innerRimColor) .. "' in '" .. self.configFileName .. "'! Stop coloring inner rims!", false, false);
				end;
			end;

			if outerRimColor ~= nil or getColorFromConfigOut ~= nil then
				local materialId = self.xmlFile:getInt(configKey .. ".colorChanges.outerRimColor#materialId");
				local shaderParameterName = Utils.getNoNil(self.xmlFile:getString(configKey .. ".colorChanges.outerRimColor#shaderParameterName"), "colorMat0");
--				local additionalColorName = g_brandColorManager:getBrandColorByName(additionalColor);
				local outerRimColorName;
				local isColorConfig = false;
				local isColorConfig2 = false;

					if getColorFromConfigOut ~= nil then
						if self.configurations[getColorFromConfigOut] ~= nil then	
							for _, newConfguration in pairs(AddConfig.newConfgurations) do
								if getColorFromConfigOut == newConfguration.configName then
									isColorConfig = newConfguration.isColorConfig;
									isColorConfig2 = newConfguration.isColorConfig2;

									break;
								end;
							end;

							for _, defaultColorConfiguration in pairs(AddConfig.defaultColorConfigurations) do
								if getColorFromConfigOut == defaultColorConfiguration then
									isColorConfig = true;

									break;
								end;
							end;

							for _, defaultColorConfiguration in pairs(AddConfig.defaultColor1Configurations) do
								if getColorFromConfigOut == defaultColorConfiguration then
									isColorConfig = true;

									break;
								end;
							end;


							if isColorConfig or isColorConfig2 then
								additionalColorName = ConfigurationUtil.getColorByConfigId(self, getColorFromConfigOut, self.configurations[getColorFromConfigOut]);
							else
								printError("(colorChanges) :: The configuration '" .. getColorFromConfigOut .. "' is not an color configuration! Stop coloring part outer rims!", false, true);
							end;
						else
							printError("(colorChanges) :: Can't find configuration '" .. getColorFromConfigOut .. "' in vehicle '" .. self.configFileName .. "'! Stop coloring part outer rims!", false, true);
						end;
					else
						outerRimColorName = g_brandColorManager:getBrandColorByName(outerRimColor);
					end;


				if outerRimColorName == nil then
					outerRimColorName = ConfigurationUtil.getColorFromString(outerRimColor);
				end;

				if outerRimColorName ~= nil then
					local r, g, b, mat = unpack(outerRimColorName);
					
					for _, wheel in pairs(self.spec_wheels.wheels) do
						if wheel.wheelOuterRim ~= nil then
							if getHasShaderParameter(wheel.wheelOuterRim, shaderParameterName) then
								if materialId == nil then
									materialId = mat;

									if materialId == nil then
										_, _, _, materialId = getShaderParameter(wheel.wheelOuterRim, shaderParameterName);
									end;
								end;
							
								setShaderParameter(wheel.wheelOuterRim, shaderParameterName, r, g, b, materialId, false);
							
						-- printDebug("(colorChanges) :: Change starfire color (" .. shaderParameterName .. ") successfully in '" .. self.configFileName .. "' to r, g, b, [4], materialId = " .. starfireColor[1] .. ", " .. starfireColor[2] .. ", " .. starfireColor[3] .. ", " .. tostring(starfireColor[4]) .. ", " .. tostring(materialId) .. "  for '" .. getName(starfire) .. "'.", 1, true);
								printDebug("(colorChanges) :: Change outer rim color successfully in '" .. self.configFileName .. "'.", 1, true);
							else
								printError("(colorChanges) :: Failed to load shader parameter '" .. tostring(shaderParameterName) .. "' in '" .. self.configFileName .. "'! Stop coloring outer rims!", false, false);
							end;
						end;

						if wheel.additionalWheels ~= nil then
							for _, additionalWheel in pairs(wheel.additionalWheels) do	
								if additionalWheel.wheelOuterRim ~= nil then
									if getHasShaderParameter(additionalWheel.wheelOuterRim, shaderParameterName) then
										if materialId == nil then
											materialId = mat;
										
											if materialId == nil then	
												_, _, _, materialId = getShaderParameter(additionalWheel.wheelOuterRim, shaderParameterName);
											end;
										end;
									
										setShaderParameter(additionalWheel.wheelOuterRim, shaderParameterName, r, g, b, materialId, false);

						-- printDebug("(colorChanges) :: Change starfire color (" .. shaderParameterName .. ") successfully in '" .. self.configFileName .. "' to r, g, b, [4], materialId = " .. starfireColor[1] .. ", " .. starfireColor[2] .. ", " .. starfireColor[3] .. ", " .. tostring(starfireColor[4]) .. ", " .. tostring(materialId) .. "  for '" .. getName(starfire) .. "'.", 1, true);
										printDebug("(colorChanges) :: Change additional outer rim color successfully in '" .. self.configFileName .. "'.", 1, true);
									else
										printError("(colorChanges) :: Failed to load shader parameter '" .. tostring(shaderParameterName) .. "' in '" .. self.configFileName .. "'! Stop coloring additional outer rims!", false, false);
									end;
								end;

								if additionalWheel.connector ~= nil and additionalWheel.connector.node ~= nil then	
									if getHasShaderParameter(additionalWheel.connector.node, shaderParameterName) then
										if materialId == nil then
											materialId = mat;
										
											if materialId == nil then
												_, _, _, materialId = getShaderParameter(additionalWheel.connector.node, shaderParameterName);
											end;
										end;
									
										setShaderParameter(additionalWheel.connector.node, shaderParameterName, r, g, b, materialId, false);

										-- printDebug("(colorChanges) :: Change starfire color (" .. shaderParameterName .. ") successfully in '" .. self.configFileName .. "' to r, g, b, [4], materialId = " .. outerRimColorName[1] .. ", " .. outerRimColorName[2] .. ", " .. outerRimColorName[3] .. ", " .. tostring(outerRimColorName[4]) .. ", " .. tostring(materialId) .. "  for '" .. getName(starfire) .. "'.", 1, true);
										printDebug("(colorChanges) :: Change additional connector color successfully in '" .. self.configFileName .. "'.", 1, true);
									else
										printError("(colorChanges) :: Failed to load shader parameter '" .. tostring(shaderParameterName) .. "' in '" .. self.configFileName .. "'! Stop coloring additional connector!", false, false);
									end;
								end;
							end;
						end;
					end;
				else
					printError("(colorChanges) :: Failed to load color '" .. tostring(outerRimColor) .. "' in '" .. self.configFileName .. "'! Stop coloring outer rims!", false, false);
				end;
			end;
		end;

		ObjectChangeUtil.updateObjectChanges(self.xmlFile, "vehicle." .. configName .. "Configurations." .. secondConfigName .. "Configuration", configId, self.components, self);
	end;
end;


