# Blender 3.2's FBX importer only makes bones of 'LimbNode' models; SKCombat's XSI exports skin their meshes to plain
# 'Null' models, so the skin was lost (meshes came in rigid, bones as empties). This reloads the importer with nodes
# that drive a skin cluster counted as bones too. Use: exec(open('fbxpatch.py').read()) before bpy.ops.import_scene.fbx.
import inspect
import io_scene_fbx.import_fbx as _fbx_imp
_src = inspect.getsource(_fbx_imp)
_old = "is_bone = fbx_obj.props[2] in {b'LimbNode', b'Limb'}"
_new = ("is_bone = fbx_obj.props[2] in {b'LimbNode', b'Limb'} or any("
        "(fbx_table_nodes.get(_p, (None, None))[0] is not None and fbx_table_nodes[_p][0].id == b'Deformer' and fbx_table_nodes[_p][0].props[2] == b'Cluster') "
        "for _p, _l in fbx_connection_map.get(a_uuid, ()))")
assert _src.count(_old) == 1, 'FBX importer changed: patch not applied'
exec(compile(_src.replace(_old, _new), _fbx_imp.__file__, 'exec'), _fbx_imp.__dict__)
