From d43b73178b0ba6babcc4e4bf0e082c1fd12597ae Mon Sep 17 00:00:00 2001
From: Alecu100 <lui_alecu@yahoo.co.uk>
Date: Wed, 25 Jan 2012 21:59:55 +0200
Subject: [PATCH] added a new overload for the AddInterpolatorMethod in the
 NiControllerSequence class to fix a bug when it would export the string
 pallete for fallout 3 nif versions.

---
 include/obj/NiControllerSequence.h |  9 +++++
 src/obj/NiControllerSequence.cpp   | 57 ++++++++++++++++++++++++++++++
 2 files changed, 66 insertions(+)

diff --git a/include/obj/NiControllerSequence.h b/include/obj/NiControllerSequence.h
index 107ea1e2..56fbb5c9 100644
--- a/include/obj/NiControllerSequence.h
+++ b/include/obj/NiControllerSequence.h
@@ -114,6 +114,15 @@ public:
 	 */
 	NIFLIB_API void AddInterpolator( NiSingleInterpController * obj, byte priority = 0 );
 
+	/*!
+	 * Attatches an interpolator to this KF file for a KF file of version greater than 10.2.0.0.  Versions below this use controllers.
+	 * \param[in] obj A reference to the new controller which has an interpolator to attach.
+	 * \param[in] priority Used only in Oblivion to set the priority of one controller over another when the two are merged.
+	 * \param[in] include_string_pallete Indicates if the resulting ControllerLinks will hold reference to the NiStringPallete in the NiControllerSequence
+	 * \sa NiControllerSequence::ClearChildren, NiControllerSequence::AddController
+	 */
+	NIFLIB_API void AddInterpolator( NiSingleInterpController * obj, byte priority , bool include_string_pallete );
+
 	/*! 
 	 * Removes all controllers and interpolators from this Kf file root object.
 	 * \sa NiControllerSequence::AddController, NiControllerSequence::AddInterpolator
diff --git a/src/obj/NiControllerSequence.cpp b/src/obj/NiControllerSequence.cpp
index 7fcde4ee..38e00161 100644
--- a/src/obj/NiControllerSequence.cpp
+++ b/src/obj/NiControllerSequence.cpp
@@ -377,6 +377,63 @@ void NiControllerSequence::AddInterpolator( NiSingleInterpController * obj, byte
 	controlledBlocks.push_back( cl );
 }
 
+
+void NiControllerSequence::AddInterpolator( NiSingleInterpController * obj, byte priority , bool include_string_pallete ) {
+	//Make sure the link isn't null
+	if ( obj == NULL ) {
+		throw runtime_error("Attempted to add a null controller to NiControllerSequence block.");
+	}
+
+	NiInterpolatorRef interp = obj->GetInterpolator();
+	if ( interp == NULL ) {
+		throw runtime_error("Controller must have an interpolator attached to be added to a NiControllerSequence with the AddInterpolator function.");
+	}
+
+	NiObjectNETRef target = obj->GetTarget();
+	if ( target == NULL ) {
+		throw runtime_error("Controller must have a target to be added to a NiControllerSequence.");
+	}
+
+
+
+	//Make a new ControllerLink and fill out necessary data
+	ControllerLink cl;
+
+	NiPropertyRef prop = DynamicCast<NiProperty>(target);
+
+	cl.interpolator = interp;
+	cl.priority = priority;
+	if(include_string_pallete == true) {
+		//If there are existing ControllerLinks, use the same StringPalette they're using
+		if ( stringPalette == NULL ) {
+			stringPalette = new NiStringPalette;
+		}
+
+		cl.stringPalette = stringPalette;
+		cl.nodeNameOffset = stringPalette->AddSubStr( target->GetName() );
+		
+		if ( prop != NULL ) {
+			cl.propertyTypeOffset = stringPalette->AddSubStr( prop->GetType().GetTypeName() );
+		}
+
+		cl.controllerTypeOffset = stringPalette->AddSubStr( obj->GetType().GetTypeName() );
+
+	} else {
+		cl.stringPalette = NULL;
+		cl.nodeName = target->GetName();
+		if(prop != NULL) {
+			cl.propertyType = prop->GetType().GetTypeName();
+		}
+		cl.controllerType = obj->GetType().GetTypeName();
+	}
+
+
+	//Add finished ControllerLink to list
+	controlledBlocks.push_back( cl );
+}
+
+
+
 void NiControllerSequence::ClearControllerData() {
 	
 	throw runtime_error("The AddInterpolator function cannot be implemented until problems in the XML are solved.");
-- 
GitLab