Skip to content
Snippets Groups Projects
Commit b4f77a4e authored by Tazpn's avatar Tazpn
Browse files

Fix issues with NiControllerSequence in niflib.

1. StringOffset now defaults to -1
2. Search in StringPalette now finds exact matches rather than partial matches.
3. Reuse same StringPalette for Controller and all child blocks
parent 527943c2
No related branches found
No related tags found
No related merge requests found
...@@ -9,7 +9,7 @@ All rights reserved. Please see niflib.h for licence. */ ...@@ -9,7 +9,7 @@ All rights reserved. Please see niflib.h for licence. */
using namespace Niflib; using namespace Niflib;
//Constructor //Constructor
ControllerLink::ControllerLink() : controller(NULL), interpolator(NULL), unknownLink2(NULL), unknownShort0((ushort)0), priority_((byte)0), stringPalette(NULL), nodeNameOffset((uint)0), propertyTypeOffset((uint)0), controllerTypeOffset((uint)0), variableOffset1((uint)0), variableOffset2((uint)0) {}; ControllerLink::ControllerLink() : controller(NULL), interpolator(NULL), unknownLink2(NULL), unknownShort0((ushort)0), priority_((byte)0), stringPalette(NULL), nodeNameOffset((uint)-1), propertyTypeOffset((uint)-1), controllerTypeOffset((uint)-1), variableOffset1((uint)-1), variableOffset2((uint)-1) {};
//Destructor //Destructor
ControllerLink::~ControllerLink() {}; ControllerLink::~ControllerLink() {};
...@@ -104,12 +104,8 @@ void NiControllerSequence::AddInterpolator( const Ref<NiSingleInterpolatorContro ...@@ -104,12 +104,8 @@ void NiControllerSequence::AddInterpolator( const Ref<NiSingleInterpolatorContro
} }
//If there are existing ControllerLinks, use the same StringPalette they're using //If there are existing ControllerLinks, use the same StringPalette they're using
NiStringPaletteRef str_pal; if ( stringPalette == NULL ) {
if ( controlledBlocks.size() > 0 ) { stringPalette = new NiStringPalette;
str_pal = controlledBlocks[0].stringPalette;
} else {
//No existing ones, so make a new one
str_pal = new NiStringPalette;
} }
//Make a new ControllerLink and fill out necessary data //Make a new ControllerLink and fill out necessary data
...@@ -117,15 +113,15 @@ void NiControllerSequence::AddInterpolator( const Ref<NiSingleInterpolatorContro ...@@ -117,15 +113,15 @@ void NiControllerSequence::AddInterpolator( const Ref<NiSingleInterpolatorContro
cl.interpolator = interp; cl.interpolator = interp;
cl.priority_ = priority; cl.priority_ = priority;
cl.stringPalette = str_pal; cl.stringPalette = stringPalette;
cl.nodeNameOffset = str_pal->AddSubStr( target->GetName() ); cl.nodeNameOffset = stringPalette->AddSubStr( target->GetName() );
NiPropertyRef prop = DynamicCast<NiProperty>(target); NiPropertyRef prop = DynamicCast<NiProperty>(target);
if ( prop != NULL ) { if ( prop != NULL ) {
cl.propertyTypeOffset = str_pal->AddSubStr( prop->GetType().GetTypeName() ); cl.propertyTypeOffset = stringPalette->AddSubStr( prop->GetType().GetTypeName() );
} }
cl.controllerTypeOffset = str_pal->AddSubStr( obj->GetType().GetTypeName() ); cl.controllerTypeOffset = stringPalette->AddSubStr( obj->GetType().GetTypeName() );
//Add finished ControllerLink to list //Add finished ControllerLink to list
controlledBlocks.push_back( cl ); controlledBlocks.push_back( cl );
......
...@@ -64,7 +64,8 @@ string NiStringPalette::GetSubStr( short offset ) const { ...@@ -64,7 +64,8 @@ string NiStringPalette::GetSubStr( short offset ) const {
unsigned int NiStringPalette::AddSubStr( const string & n ) { unsigned int NiStringPalette::AddSubStr( const string & n ) {
//Search for the string //Search for the string
uint offset = (uint)palette.palette.find( n ); // When searching for strings also search for ending null.
uint offset = (uint)palette.palette.find( n.c_str(), 0, n.size()+1 );
//If string was not found, append it //If string was not found, append it
if ( offset == 0xFFFFFFFF ) { if ( offset == 0xFFFFFFFF ) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment