Scriptname RaceMenuPluginSoS extends RaceMenuBase

;Common Schlongs of Skyrim nodes
string Property NINODE_SOS_BASE = "NPC GenitalsBase [GenBase]" AutoReadOnly
string Property NINODE_SOS_SCROTUM = "NPC GenitalsScrotum [GenScrot]" AutoReadOnly
string Property NINODE_SOS_GENITALS_01 = "NPC Genitals01 [Gen01]" AutoReadOnly
string Property NINODE_SOS_GENITALS_02 = "NPC Genitals02 [Gen02]" AutoReadOnly
string Property NINODE_SOS_GENITALS_03 = "NPC Genitals03 [Gen03]" AutoReadOnly
string Property NINODE_SOS_GENITALS_04 = "NPC Genitals04 [Gen04]" AutoReadOnly
string Property NINODE_SOS_GENITALS_05 = "NPC Genitals05 [Gen05]" AutoReadOnly
string Property NINODE_SOS_GENITALS_06 = "NPC Genitals06 [Gen06]" AutoReadOnly

;XPMSE Specific
string Property NINODE_SOS_SCROTUM_LEFT = "NPC L GenitalsScrotum [LGenScrot]" AutoReadOnly
string Property NINODE_SOS_SCROTUM_RIGHT = "NPC R GenitalsScrotum [RGenScrot]" AutoReadOnly

string Property NINODE_SOS_BASE_CME = "CME GenitalsBase [GenBase]" AutoReadOnly
string Property NINODE_SOS_SCROTUM_CME = "CME GenitalsScrotum [GenScrot]" AutoReadOnly
string Property NINODE_SOS_GENITALS_01_CME = "CME Genitals01 [Gen01]" AutoReadOnly
string Property NINODE_SOS_GENITALS_02_CME = "CME Genitals02 [Gen02]" AutoReadOnly
string Property NINODE_SOS_GENITALS_03_CME = "CME Genitals03 [Gen03]" AutoReadOnly
string Property NINODE_SOS_GENITALS_04_CME = "CME Genitals04 [Gen04]" AutoReadOnly
string Property NINODE_SOS_GENITALS_05_CME = "CME Genitals05 [Gen05]" AutoReadOnly

;Callbacks Table
string Property CALLBACK_SOS_BASE_SCALE = "XPMSEChangeGenitalsBaseSize" AutoReadOnly
string Property CALLBACK_SOS_SCROTUM_SCALE = "XPMSEChangeGenitalsScrotumSize" AutoReadOnly
string Property CALLBACK_SOS_SCROTUM_LEFT_SCALE = "XPMSEChangeGenitalsScrotumLeftSize" AutoReadOnly
string Property CALLBACK_SOS_SCROTUM_RIGHT_SCALE = "XPMSEChangeGenitalsScrotumRightSize" AutoReadOnly
string Property CALLBACK_SOS_GENITALS_01_SCALE = "XPMSEChangeGenitals1Size" AutoReadOnly
string Property CALLBACK_SOS_GENITALS_02_SCALE = "XPMSEChangeGenitals2Size" AutoReadOnly
string Property CALLBACK_SOS_GENITALS_03_SCALE = "XPMSEChangeGenitals3Size" AutoReadOnly
string Property CALLBACK_SOS_GENITALS_04_SCALE = "XPMSEChangeGenitals4Size" AutoReadOnly
string Property CALLBACK_SOS_GENITALS_05_SCALE = "XPMSEChangeGenitals5Size" AutoReadOnly
string Property CALLBACK_SOS_GENITALS_06_SCALE = "XPMSEChangeGenitals6Size" AutoReadOnly
string Property CALLBACK_SOS_ERECTION = "XPMSEChangeErectionLevel" AutoReadOnly
string Property CALLBACK_SOS_GENITALS_01_THICK = "XPMSEChangeGenitals1Thick" AutoReadOnly
string Property CALLBACK_SOS_GENITALS_02_THICK = "XPMSEChangeGenitals2Thick" AutoReadOnly
string Property CALLBACK_SOS_GENITALS_03_THICK = "XPMSEChangeGenitals3Thick" AutoReadOnly
string Property CALLBACK_SOS_GENITALS_04_THICK = "XPMSEChangeGenitals4Thick" AutoReadOnly
string Property CALLBACK_SOS_GENITALS_05_THICK = "XPMSEChangeGenitals5Thick" AutoReadOnly
string Property CALLBACK_SOS_GENITALS_01_LENGTH = "XPMSEChangeGenitals1Length" AutoReadOnly
string Property CALLBACK_SOS_GENITALS_02_LENGTH = "XPMSEChangeGenitals2Length" AutoReadOnly
string Property CALLBACK_SOS_GENITALS_03_LENGTH = "XPMSEChangeGenitals3Length" AutoReadOnly
string Property CALLBACK_SOS_GENITALS_04_LENGTH = "XPMSEChangeGenitals4Length" AutoReadOnly
string Property CALLBACK_SOS_GENITALS_05_LENGTH = "XPMSEChangeGenitals5Length" AutoReadOnly
string Property CALLBACK_SOS_GENITALS_01_ROTY = "XPMSEChangeGenitals1RotY" AutoReadOnly
string Property CALLBACK_SOS_GENITALS_01_ROTP = "XPMSEChangeGenitals1RotP" AutoReadOnly
string Property CALLBACK_SOS_GENITALS_01_ROTR = "XPMSEChangeGenitals1RotR" AutoReadOnly
string Property CALLBACK_SOS_GENITALS_02_ROTY = "XPMSEChangeGenitals2RotY" AutoReadOnly
string Property CALLBACK_SOS_GENITALS_02_ROTP = "XPMSEChangeGenitals2RotP" AutoReadOnly
string Property CALLBACK_SOS_GENITALS_02_ROTR = "XPMSEChangeGenitals2RotR" AutoReadOnly
string Property CALLBACK_SOS_GENITALS_03_ROTY = "XPMSEChangeGenitals3RotY" AutoReadOnly
string Property CALLBACK_SOS_GENITALS_03_ROTP = "XPMSEChangeGenitals3RotP" AutoReadOnly
string Property CALLBACK_SOS_GENITALS_03_ROTR = "XPMSEChangeGenitals3RotR" AutoReadOnly
string Property CALLBACK_SOS_GENITALS_04_ROTY = "XPMSEChangeGenitals4RotY" AutoReadOnly
string Property CALLBACK_SOS_GENITALS_04_ROTP = "XPMSEChangeGenitals4RotP" AutoReadOnly
string Property CALLBACK_SOS_GENITALS_04_ROTR = "XPMSEChangeGenitals4RotR" AutoReadOnly
string Property CALLBACK_SOS_GENITALS_05_ROTY = "XPMSEChangeGenitals5RotY" AutoReadOnly
string Property CALLBACK_SOS_GENITALS_05_ROTP = "XPMSEChangeGenitals5RotP" AutoReadOnly
string Property CALLBACK_SOS_GENITALS_05_ROTR = "XPMSEChangeGenitals5RotR" AutoReadOnly

; If you are making your own scaling mod, use your own key name
string Property MOD_OVERRIDE_KEY = "SoSPlugin" AutoReadOnly
string Property SOS_THICKNESS_KEY = "SoS_Thickness" AutoReadOnly

string Property CATEGORY_GENITALS = "rsm_genitals" AutoReadOnly

; NiOverride version data
int Property NIOVERRIDE_VERSION = 3 AutoReadOnly
int Property NIOVERRIDE_SCRIPT_VERSION = 2 AutoReadOnly

;Arrays
float[] _SOS_Genitals_01_Position
float[] _SOS_Genitals_01_Rotation
float[] _SOS_Genitals_02_Position
float[] _SOS_Genitals_02_Rotation
float[] _SOS_Genitals_03_Position
float[] _SOS_Genitals_03_Rotation
float[] _SOS_Genitals_04_Position
float[] _SOS_Genitals_04_Rotation
float[] _SOS_Genitals_05_Position
float[] _SOS_Genitals_05_Rotation

;Variables
int _erectionLevel = 0


bool _versionValid = false

Event OnCategoryRequest()
	AddCategory(CATEGORY_GENITALS, "$CATEGORY GENITALS")
EndEvent

Event OnStartup()
	parent.OnStartup()

	int nioverrideVersion = SKSE.GetPluginVersion("NiOverride")
	int nioverrideScriptVersion = NiOverride.GetScriptVersion()

	; Check NiOverride version, disable most features if this fails
	if nioverrideVersion >= NIOVERRIDE_VERSION && nioverrideScriptVersion >= NIOVERRIDE_SCRIPT_VERSION
		_versionValid = true
		RegisterForMenu(RACESEX_MENU)
	Else
		_versionValid = false
	Endif
EndEvent

Event OnMenuOpen(string menuName)
	If menuName == RACESEX_MENU
		HandleErection()
	EndIf
EndEvent

; Add Custom sliders here
Event OnSliderRequest(Actor target, ActorBase targetBase, Race actorRace, bool isFemale)
	If NetImmerse.HasNode(target, NINODE_SOS_BASE, false)
		AddSliderEx("$SOS Genitals Base", CATEGORY_GENITALS, CALLBACK_SOS_BASE_SCALE, 0.01, 5.00, 0.01, GetNodeScale(target, isFemale, NINODE_SOS_BASE))
	Endif
	If NetImmerse.HasNode(target, NINODE_SOS_SCROTUM, false)
		AddSliderEx("$SOS Genitals Scrotum", CATEGORY_GENITALS, CALLBACK_SOS_SCROTUM_SCALE, 0.01, 5.00, 0.01, GetNodeScale(target, isFemale, NINODE_SOS_SCROTUM))
	Endif
	If NetImmerse.HasNode(target, NINODE_SOS_SCROTUM_LEFT, false)
		AddSliderEx("$SOS Genitals Left Scrotum", CATEGORY_GENITALS, CALLBACK_SOS_SCROTUM_LEFT_SCALE, 0.01, 5.00, 0.01, GetNodeScale(target, isFemale, NINODE_SOS_SCROTUM_LEFT))
	Endif
	If NetImmerse.HasNode(target, NINODE_SOS_SCROTUM_RIGHT, false)
		AddSliderEx("$SOS Genitals Right Scrotum", CATEGORY_GENITALS, CALLBACK_SOS_SCROTUM_RIGHT_SCALE, 0.01, 5.00, 0.01, GetNodeScale(target, isFemale, NINODE_SOS_SCROTUM_RIGHT))
	Endif
	If NetImmerse.HasNode(target, NINODE_SOS_GENITALS_01, false)
		AddSliderEx("$SOS Genitals 1", CATEGORY_GENITALS, CALLBACK_SOS_GENITALS_01_SCALE, 0.01, 5.00, 0.01, GetNodeScale(target, isFemale, NINODE_SOS_GENITALS_01))
		If NetImmerse.HasNode(target, NINODE_SOS_GENITALS_01_CME, false)
			AddSliderEx("$SOS Genitals 1 Thick", CATEGORY_GENITALS, CALLBACK_SOS_GENITALS_01_THICK, 0.1, 5.00, 0.01, GetNodeScaleEX(target, isFemale, NINODE_SOS_GENITALS_01, SOS_THICKNESS_KEY))
			_SOS_Genitals_01_Position = GetNodePosition(target, isFemale, NINODE_SOS_GENITALS_01_CME)
			AddSliderEx("$SOS Genitals 1 Lenght", CATEGORY_GENITALS, CALLBACK_SOS_GENITALS_01_LENGTH, 0.0, 5.00, 0.01, _SOS_Genitals_01_Position[1])
			_SOS_Genitals_01_Rotation = GetNodeRotation(target, isFemale, NINODE_SOS_GENITALS_01_CME)
			AddSliderEx("$SOS Genitals 1 Rot Y", CATEGORY_GENITALS, CALLBACK_SOS_GENITALS_01_ROTY, -80.0, 80.00, 1.00, _SOS_Genitals_01_Rotation[0])
			AddSliderEx("$SOS Genitals 1 Rot P", CATEGORY_GENITALS, CALLBACK_SOS_GENITALS_01_ROTP, -80.0, 80.00, 1.00, _SOS_Genitals_01_Rotation[1])	
			AddSliderEx("$SOS Genitals 1 Rot R", CATEGORY_GENITALS, CALLBACK_SOS_GENITALS_01_ROTR, -80.0, 80.00, 1.00, _SOS_Genitals_01_Rotation[2])
		Endif
	Endif
	If NetImmerse.HasNode(target, NINODE_SOS_GENITALS_02, false)
		AddSliderEx("$SOS Genitals 2", CATEGORY_GENITALS, CALLBACK_SOS_GENITALS_02_SCALE, 0.01, 5.00, 0.01, GetNodeScale(target, isFemale, NINODE_SOS_GENITALS_02))
		If NetImmerse.HasNode(target, NINODE_SOS_GENITALS_02_CME, false)
			AddSliderEx("$SOS Genitals 2 Thick", CATEGORY_GENITALS, CALLBACK_SOS_GENITALS_02_THICK, 0.1, 5.00, 0.01, GetNodeScaleEX(target, isFemale, NINODE_SOS_GENITALS_02, SOS_THICKNESS_KEY))
			_SOS_Genitals_02_Position = GetNodePosition(target, isFemale, NINODE_SOS_GENITALS_02_CME)
			AddSliderEx("$SOS Genitals 2 Lenght", CATEGORY_GENITALS, CALLBACK_SOS_GENITALS_02_LENGTH, 0.0, 5.00, 0.01, _SOS_Genitals_02_Position[1])
			_SOS_Genitals_02_Rotation = GetNodeRotation(target, isFemale, NINODE_SOS_GENITALS_02_CME)
			AddSliderEx("$SOS Genitals 2 Rot Y", CATEGORY_GENITALS, CALLBACK_SOS_GENITALS_02_ROTY, -80.0, 80.00, 1.00, _SOS_Genitals_02_Rotation[0])
			AddSliderEx("$SOS Genitals 2 Rot P", CATEGORY_GENITALS, CALLBACK_SOS_GENITALS_02_ROTP, -80.0, 80.00, 1.00, _SOS_Genitals_02_Rotation[1])	
			AddSliderEx("$SOS Genitals 2 Rot R", CATEGORY_GENITALS, CALLBACK_SOS_GENITALS_02_ROTR, -80.0, 80.00, 1.00, _SOS_Genitals_02_Rotation[2])
		Endif
	Endif
	If NetImmerse.HasNode(target, NINODE_SOS_GENITALS_03, false)
		AddSliderEx("$SOS Genitals 3", CATEGORY_GENITALS, CALLBACK_SOS_GENITALS_03_SCALE, 0.01, 5.00, 0.01, GetNodeScale(target, isFemale, NINODE_SOS_GENITALS_03))
		If NetImmerse.HasNode(target, NINODE_SOS_GENITALS_03_CME, false)
			AddSliderEx("$SOS Genitals 3 Thick", CATEGORY_GENITALS, CALLBACK_SOS_GENITALS_03_THICK, 0.1, 5.00, 0.01, GetNodeScaleEX(target, isFemale, NINODE_SOS_GENITALS_03, SOS_THICKNESS_KEY))
			_SOS_Genitals_03_Position = GetNodePosition(target, isFemale, NINODE_SOS_GENITALS_03_CME)
			AddSliderEx("$SOS Genitals 3 Lenght", CATEGORY_GENITALS, CALLBACK_SOS_GENITALS_03_LENGTH, 0.0, 5.00, 0.01, _SOS_Genitals_03_Position[1])
			_SOS_Genitals_03_Rotation = GetNodeRotation(target, isFemale, NINODE_SOS_GENITALS_03_CME)
			AddSliderEx("$SOS Genitals 3 Rot Y", CATEGORY_GENITALS, CALLBACK_SOS_GENITALS_03_ROTY, -80.0, 80.00, 1.00, _SOS_Genitals_03_Rotation[0])
			AddSliderEx("$SOS Genitals 3 Rot P", CATEGORY_GENITALS, CALLBACK_SOS_GENITALS_03_ROTP, -80.0, 80.00, 1.00, _SOS_Genitals_03_Rotation[1])	
			AddSliderEx("$SOS Genitals 3 Rot R", CATEGORY_GENITALS, CALLBACK_SOS_GENITALS_03_ROTR, -80.0, 80.00, 1.00, _SOS_Genitals_03_Rotation[2])
		Endif
	EndIf
	If NetImmerse.HasNode(target, NINODE_SOS_GENITALS_04, false)
		AddSliderEx("$SOS Genitals 4", CATEGORY_GENITALS, CALLBACK_SOS_GENITALS_04_SCALE, 0.01, 5.00, 0.01, GetNodeScale(target, isFemale, NINODE_SOS_GENITALS_04))
		If NetImmerse.HasNode(target, NINODE_SOS_GENITALS_04_CME, false)
			AddSliderEx("$SOS Genitals 4 Thick", CATEGORY_GENITALS, CALLBACK_SOS_GENITALS_04_THICK, 0.1, 5.00, 0.01, GetNodeScaleEX(target, isFemale, NINODE_SOS_GENITALS_04, SOS_THICKNESS_KEY))
			_SOS_Genitals_04_Position = GetNodePosition(target, isFemale, NINODE_SOS_GENITALS_04_CME)
			AddSliderEx("$SOS Genitals 4 Lenght", CATEGORY_GENITALS, CALLBACK_SOS_GENITALS_04_LENGTH, 0.0, 5.00, 0.01, _SOS_Genitals_04_Position[1])
			_SOS_Genitals_04_Rotation = GetNodeRotation(target, isFemale, NINODE_SOS_GENITALS_04_CME)
			AddSliderEx("$SOS Genitals 4 Rot Y", CATEGORY_GENITALS, CALLBACK_SOS_GENITALS_04_ROTY, -80.0, 80.00, 1.00, _SOS_Genitals_04_Rotation[0])
			AddSliderEx("$SOS Genitals 4 Rot P", CATEGORY_GENITALS, CALLBACK_SOS_GENITALS_04_ROTP, -80.0, 80.00, 1.00, _SOS_Genitals_04_Rotation[1])	
			AddSliderEx("$SOS Genitals 4 Rot R", CATEGORY_GENITALS, CALLBACK_SOS_GENITALS_04_ROTR, -80.0, 80.00, 1.00, _SOS_Genitals_04_Rotation[2])
		Endif
	EndIf
	If NetImmerse.HasNode(target, NINODE_SOS_GENITALS_05, false)
		AddSliderEx("$SOS Genitals 5", CATEGORY_GENITALS, CALLBACK_SOS_GENITALS_05_SCALE, 0.01, 5.00, 0.01, GetNodeScale(target, isFemale, NINODE_SOS_GENITALS_05))
		If NetImmerse.HasNode(target, NINODE_SOS_GENITALS_05_CME, false)
			AddSliderEx("$SOS Genitals 5 Thick", CATEGORY_GENITALS, CALLBACK_SOS_GENITALS_05_THICK, 0.1, 5.00, 0.01, GetNodeScaleEX(target, isFemale, NINODE_SOS_GENITALS_05, SOS_THICKNESS_KEY))
			_SOS_Genitals_05_Position = GetNodePosition(target, isFemale, NINODE_SOS_GENITALS_05_CME)
			AddSliderEx("$SOS Genitals 5 Lenght", CATEGORY_GENITALS, CALLBACK_SOS_GENITALS_05_LENGTH, 0.0, 5.00, 0.01, _SOS_Genitals_05_Position[1])
			_SOS_Genitals_05_Rotation = GetNodeRotation(target, isFemale, NINODE_SOS_GENITALS_05_CME)
			AddSliderEx("$SOS Genitals 5 Rot Y", CATEGORY_GENITALS, CALLBACK_SOS_GENITALS_05_ROTY, -80.0, 80.00, 1.00, _SOS_Genitals_05_Rotation[0])
			AddSliderEx("$SOS Genitals 5 Rot P", CATEGORY_GENITALS, CALLBACK_SOS_GENITALS_05_ROTP, -80.0, 80.00, 1.00, _SOS_Genitals_05_Rotation[1])	
			AddSliderEx("$SOS Genitals 5 Rot R", CATEGORY_GENITALS, CALLBACK_SOS_GENITALS_05_ROTR, -80.0, 80.00, 1.00, _SOS_Genitals_05_Rotation[2])
		Endif
	Endif
	If NetImmerse.HasNode(target, NINODE_SOS_GENITALS_06, false)
		AddSliderEx("$SOS Genitals 6", CATEGORY_GENITALS, CALLBACK_SOS_GENITALS_06_SCALE, 0.01, 5.00, 0.01, GetNodeScale(target, isFemale, NINODE_SOS_GENITALS_06))
	Endif
	AddSliderEx("$SOS Erection", CATEGORY_GENITALS, CALLBACK_SOS_ERECTION, -10, 9, 1, _erectionLevel)
EndEvent

Event OnSliderChanged(string callback, float value)
	bool isFemale = _targetActorBase.GetSex() as bool
	If _versionValid
		If callback == CALLBACK_SOS_BASE_SCALE
			SetNodeScale(_targetActor, isFemale, NINODE_SOS_BASE, value)
		ElseIf callback == CALLBACK_SOS_SCROTUM_SCALE
			SetNodeScale(_targetActor, isFemale, NINODE_SOS_SCROTUM, value)
		ElseIf callback == CALLBACK_SOS_SCROTUM_LEFT_SCALE
			SetNodeScale(_targetActor, isFemale, NINODE_SOS_SCROTUM_LEFT, value)
		ElseIf callback == CALLBACK_SOS_SCROTUM_RIGHT_SCALE
			SetNodeScale(_targetActor, isFemale, NINODE_SOS_SCROTUM_RIGHT, value)
		Elseif callback == CALLBACK_SOS_GENITALS_01_SCALE
			SetNodeScale(_targetActor, isFemale, NINODE_SOS_GENITALS_01, value)
		Elseif callback == CALLBACK_SOS_GENITALS_02_SCALE
			SetNodeScale(_targetActor, isFemale, NINODE_SOS_GENITALS_02, value)
		Elseif callback == CALLBACK_SOS_GENITALS_03_SCALE
			SetNodeScale(_targetActor, isFemale, NINODE_SOS_GENITALS_03, value)
		Elseif callback == CALLBACK_SOS_GENITALS_04_SCALE
			SetNodeScale(_targetActor, isFemale, NINODE_SOS_GENITALS_04, value)
		Elseif callback == CALLBACK_SOS_GENITALS_05_SCALE
			SetNodeScale(_targetActor, isFemale, NINODE_SOS_GENITALS_05, value)
		Elseif callback == CALLBACK_SOS_GENITALS_06_SCALE
			SetNodeScale(_targetActor, isFemale, NINODE_SOS_GENITALS_06, value)
		Elseif callback == CALLBACK_SOS_ERECTION
			_erectionLevel = value As Int
			HandleErection()
		Elseif callback == CALLBACK_SOS_GENITALS_01_THICK
			SetNodeScaleEX(_targetActor, isFemale, NINODE_SOS_GENITALS_01, value, SOS_THICKNESS_KEY)
			SetNodeScaleEX(_targetActor, isFemale, NINODE_SOS_GENITALS_01_CME, 1/value, SOS_THICKNESS_KEY)
		Elseif callback == CALLBACK_SOS_GENITALS_02_THICK
			SetNodeScaleEX(_targetActor, isFemale, NINODE_SOS_GENITALS_02, value, SOS_THICKNESS_KEY)
			SetNodeScaleEX(_targetActor, isFemale, NINODE_SOS_GENITALS_02_CME, 1/value, SOS_THICKNESS_KEY)
		Elseif callback == CALLBACK_SOS_GENITALS_03_THICK
			SetNodeScaleEX(_targetActor, isFemale, NINODE_SOS_GENITALS_03, value, SOS_THICKNESS_KEY)
			SetNodeScaleEX(_targetActor, isFemale, NINODE_SOS_GENITALS_03_CME, 1/value, SOS_THICKNESS_KEY)
		Elseif callback == CALLBACK_SOS_GENITALS_04_THICK
			SetNodeScaleEX(_targetActor, isFemale, NINODE_SOS_GENITALS_04, value, SOS_THICKNESS_KEY)
			SetNodeScaleEX(_targetActor, isFemale, NINODE_SOS_GENITALS_04_CME, 1/value, SOS_THICKNESS_KEY)
		Elseif callback == CALLBACK_SOS_GENITALS_05_THICK
			SetNodeScaleEX(_targetActor, isFemale, NINODE_SOS_GENITALS_05, value, SOS_THICKNESS_KEY)
			SetNodeScaleEX(_targetActor, isFemale, NINODE_SOS_GENITALS_05_CME, 1/value, SOS_THICKNESS_KEY)
		Elseif callback == CALLBACK_SOS_GENITALS_01_LENGTH
			_SOS_Genitals_01_Position[1] = value
			SetNodePosition(_targetActor, isFemale, NINODE_SOS_GENITALS_01_CME, _SOS_Genitals_01_Position)
		Elseif callback == CALLBACK_SOS_GENITALS_02_LENGTH
			_SOS_Genitals_02_Position[1] = value
			SetNodePosition(_targetActor, isFemale, NINODE_SOS_GENITALS_02_CME, _SOS_Genitals_02_Position)
		Elseif callback == CALLBACK_SOS_GENITALS_03_LENGTH
			_SOS_Genitals_03_Position[1] = value
			SetNodePosition(_targetActor, isFemale, NINODE_SOS_GENITALS_03_CME, _SOS_Genitals_03_Position)
		Elseif callback == CALLBACK_SOS_GENITALS_04_LENGTH
			_SOS_Genitals_04_Position[1] = value
			SetNodePosition(_targetActor, isFemale, NINODE_SOS_GENITALS_04_CME, _SOS_Genitals_04_Position)
		Elseif callback == CALLBACK_SOS_GENITALS_05_LENGTH
			_SOS_Genitals_05_Position[1] = value
			SetNodePosition(_targetActor, isFemale, NINODE_SOS_GENITALS_05_CME, _SOS_Genitals_05_Position)
		Elseif callback == CALLBACK_SOS_GENITALS_01_ROTY || callback == CALLBACK_SOS_GENITALS_01_ROTP || callback == CALLBACK_SOS_GENITALS_01_ROTR
			If callback == CALLBACK_SOS_GENITALS_01_ROTY
				_SOS_Genitals_01_Rotation[0] = value
			ElseIf callback == CALLBACK_SOS_GENITALS_01_ROTP
				_SOS_Genitals_01_Rotation[1] = value
			ElseIf callback == CALLBACK_SOS_GENITALS_01_ROTR
				_SOS_Genitals_01_Rotation[2] = value
			EndIf
			SetNodeRotation(_targetActor, isFemale, NINODE_SOS_GENITALS_01_CME, _SOS_Genitals_01_Rotation)
		Elseif callback == CALLBACK_SOS_GENITALS_02_ROTY || callback == CALLBACK_SOS_GENITALS_02_ROTP || callback == CALLBACK_SOS_GENITALS_02_ROTR
			If callback == CALLBACK_SOS_GENITALS_02_ROTY
				_SOS_Genitals_02_Rotation[0] = value
			ElseIf callback == CALLBACK_SOS_GENITALS_02_ROTP
				_SOS_Genitals_02_Rotation[1] = value
			ElseIf callback == CALLBACK_SOS_GENITALS_02_ROTR
				_SOS_Genitals_02_Rotation[2] = value
			EndIf
			SetNodeRotation(_targetActor, isFemale, NINODE_SOS_GENITALS_02_CME, _SOS_Genitals_02_Rotation)		
		Elseif callback == CALLBACK_SOS_GENITALS_03_ROTY || callback == CALLBACK_SOS_GENITALS_03_ROTP || callback == CALLBACK_SOS_GENITALS_03_ROTR
			If callback == CALLBACK_SOS_GENITALS_03_ROTY
				_SOS_Genitals_03_Rotation[0] = value
			ElseIf callback == CALLBACK_SOS_GENITALS_03_ROTP
				_SOS_Genitals_03_Rotation[1] = value
			ElseIf callback == CALLBACK_SOS_GENITALS_03_ROTR
				_SOS_Genitals_03_Rotation[2] = value
			EndIf
			SetNodeRotation(_targetActor, isFemale, NINODE_SOS_GENITALS_03_CME, _SOS_Genitals_03_Rotation)
		Elseif callback == CALLBACK_SOS_GENITALS_04_ROTY || callback == CALLBACK_SOS_GENITALS_04_ROTP || callback == CALLBACK_SOS_GENITALS_04_ROTR
			If callback == CALLBACK_SOS_GENITALS_04_ROTY
				_SOS_Genitals_04_Rotation[0] = value
			ElseIf callback == CALLBACK_SOS_GENITALS_04_ROTP
				_SOS_Genitals_04_Rotation[1] = value
			ElseIf callback == CALLBACK_SOS_GENITALS_04_ROTR
				_SOS_Genitals_04_Rotation[2] = value
			EndIf
			SetNodeRotation(_targetActor, isFemale, NINODE_SOS_GENITALS_04_CME, _SOS_Genitals_04_Rotation)
		Elseif callback == CALLBACK_SOS_GENITALS_05_ROTY || callback == CALLBACK_SOS_GENITALS_05_ROTP || callback == CALLBACK_SOS_GENITALS_05_ROTR
			If callback == CALLBACK_SOS_GENITALS_05_ROTY
				_SOS_Genitals_05_Rotation[0] = value
			ElseIf callback == CALLBACK_SOS_GENITALS_05_ROTP
				_SOS_Genitals_05_Rotation[1] = value
			ElseIf callback == CALLBACK_SOS_GENITALS_05_ROTR
				_SOS_Genitals_05_Rotation[2] = value
			EndIf
			SetNodeRotation(_targetActor, isFemale, NINODE_SOS_GENITALS_05_CME, _SOS_Genitals_05_Rotation)		
		Endif
	Endif
EndEvent

Function SetNodeScale(Actor akActor, bool isFemale, string nodeName, float value)
	If value != 1.0
		NiOverride.AddNodeTransformScale(akActor, false, isFemale, nodeName, MOD_OVERRIDE_KEY, value)
		NiOverride.AddNodeTransformScale(akActor, true, isFemale, nodeName, MOD_OVERRIDE_KEY, value)
	Else
		NiOverride.RemoveNodeTransformScale(akActor, false, isFemale, nodeName, MOD_OVERRIDE_KEY)
		NiOverride.RemoveNodeTransformScale(akActor, true, isFemale, nodeName, MOD_OVERRIDE_KEY)
	Endif
	NiOverride.UpdateNodeTransform(akActor, false, isFemale, nodeName)
	NiOverride.UpdateNodeTransform(akActor, true, isFemale, nodeName)
EndFunction

Function SetNodeScaleEX(Actor akActor, bool isFemale, string nodeName, float value, string modkey)
	If value != 1.0
		NiOverride.AddNodeTransformScale(akActor, false, isFemale, nodeName, modkey, value)
		NiOverride.AddNodeTransformScale(akActor, true, isFemale, nodeName, modkey, value)
	Else
		NiOverride.RemoveNodeTransformScale(akActor, false, isFemale, nodeName, modkey)
		NiOverride.RemoveNodeTransformScale(akActor, true, isFemale, nodeName, modkey)
	Endif
	NiOverride.UpdateNodeTransform(akActor, false, isFemale, nodeName)
	NiOverride.UpdateNodeTransform(akActor, true, isFemale, nodeName)
EndFunction

Function SetNodeRotation(Actor akActor, bool isFemale, string nodeName, float[] values)
	If values[0] != 0.0 || values[1] != 0.0 || values[2] != 0.0
		NiOverride.AddNodeTransformRotation(akActor, false, isFemale, nodeName, MOD_OVERRIDE_KEY, values)
		NiOverride.AddNodeTransformRotation(akActor, true, isFemale, nodeName, MOD_OVERRIDE_KEY, values)
	Else
		NiOverride.RemoveNodeTransformRotation(akActor, false, isFemale, nodeName, MOD_OVERRIDE_KEY)
		NiOverride.RemoveNodeTransformRotation(akActor, true, isFemale, nodeName, MOD_OVERRIDE_KEY)
	Endif
	NiOverride.UpdateNodeTransform(akActor, false, isFemale, nodeName)
	NiOverride.UpdateNodeTransform(akActor, true, isFemale, nodeName)
EndFunction

Function SetNodePosition(Actor akActor, bool isFemale, string nodeName, float[] values)
	If values[0] != 0.0 || values[1] != 0.0 || values[2] != 0.0
		NiOverride.AddNodeTransformPosition(akActor, false, isFemale, nodeName, MOD_OVERRIDE_KEY, values)
		NiOverride.AddNodeTransformPosition(akActor, true, isFemale, nodeName, MOD_OVERRIDE_KEY, values)
	Else
		NiOverride.RemoveNodeTransformPosition(akActor, false, isFemale, nodeName, MOD_OVERRIDE_KEY)
		NiOverride.RemoveNodeTransformPosition(akActor, true, isFemale, nodeName, MOD_OVERRIDE_KEY)
	Endif
	NiOverride.UpdateNodeTransform(akActor, false, isFemale, nodeName)
	NiOverride.UpdateNodeTransform(akActor, true, isFemale, nodeName)
EndFunction

float Function GetNodeScale(Actor akActor, bool isFemale, string nodeName)
	return NiOverride.GetNodeTransformScale(akActor, false, isFemale, nodeName, MOD_OVERRIDE_KEY)
EndFunction

float Function GetNodeScaleEX(Actor akActor, bool isFemale, string nodeName, string modkey)
	return NiOverride.GetNodeTransformScale(akActor, false, isFemale, nodeName, modkey)
EndFunction

float[] Function GetNodeRotation(Actor akActor, bool isFemale, string nodeName)
	return NiOverride.GetNodeTransformRotation(akActor, false, isFemale, nodeName, MOD_OVERRIDE_KEY)
EndFunction

float[] Function GetNodePosition(Actor akActor, bool isFemale, string nodeName)
	return NiOverride.GetNodeTransformPosition(akActor, false, isFemale, nodeName, MOD_OVERRIDE_KEY)
EndFunction

Function HandleErection()
	If _erectionLevel == -10
		Debug.sendAnimationEvent(_targetActor, "SOSFlaccid")
	Else
		Debug.sendAnimationEvent(_targetActor, "SOSBend" + _erectionLevel)
	EndIf
EndFunction