From 94ce35b94459a75880f7bbfc6d374f7a7db79cd2 Mon Sep 17 00:00:00 2001
From: Amorilia <amorilia@users.sourceforge.net>
Date: Wed, 21 Sep 2011 19:56:13 +0100
Subject: [PATCH] Small update, also let helper recurse into children.

---
 include/niflib.h |  2 +-
 src/niflib.cpp   | 10 +++++++++-
 2 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/include/niflib.h b/include/niflib.h
index f2335433..a14357d9 100644
--- a/include/niflib.h
+++ b/include/niflib.h
@@ -121,7 +121,7 @@ NIFLIB_API list<Ref<NiObject> > ProcessMissingLinkStack(
  * \param info Optionally, a NifInfo structure pointer can be passed in, and it will be filled with information from the header of the NIF file.
  * \return All the NIF objects read from the stream.
  */
-NIFLIB_API vector<Ref<NiObject> > ReadNifList( istream & in, const list<Ref<NiObject> > & missing_link_stack, NifInfo * info );
+NIFLIB_API vector<Ref<NiObject> > ReadNifList( istream & in, list<Ref<NiObject> > & missing_link_stack, NifInfo * info );
 
 /*!
  * Reads the given file by file name and returns a vector of object references
diff --git a/src/niflib.cpp b/src/niflib.cpp
index 03355192..9c573985 100644
--- a/src/niflib.cpp
+++ b/src/niflib.cpp
@@ -123,7 +123,7 @@ vector<NiObjectRef> ReadNifList( istream & in, NifInfo * info ) {
 	return ReadNifList(in, missing_link_stack, info);
 }
 
-vector<NiObjectRef> ReadNifList( istream & in, const list<NiObjectRef> & missing_link_stack, NifInfo * info ) {
+vector<NiObjectRef> ReadNifList( istream & in, list<NiObjectRef> & missing_link_stack, NifInfo * info ) {
 
 	//Ensure that objects are registered
 	if ( g_objects_registered == false ) {
@@ -410,6 +410,14 @@ NiObjectRef _ProcessMissingLinkStackHelper(NiObjectRef root, NiObject *obj) {
 		if (!(rootnode->GetName().empty()) && rootnode->GetName() == objnode->GetName()) {
 			return StaticCast<NiObject>(rootnode);
 		}
+	} else if (root != NULL) {
+		list<NiObjectRef> children = root->GetRefs();
+		for (list<NiObjectRef>::iterator child = children.begin(); child != children.end(); ++child) {
+			NiObjectRef result = _ProcessMissingLinkStackHelper(*child, obj);
+			if (result != NULL) {
+				return result;
+			}
+		}
 	}
 	// nothing found
 	return NiObjectRef();
-- 
GitLab