#include "UnionAfx.h"
namespace Gothic_I_Classic {
//********************************************************************
// Read NPS properties from archive (for G1)
//********************************************************************
//0x006A31E0 protected: virtual void __thiscall oCNpc::Unarchive(class zCArchiver &)
static void __fastcall Npc_Unarchive(oCNpc* _this, void* vt, zCArchiver& ar);
static CInvoke <void(__thiscall*)(oCNpc*, zCArchiver&)> pNpc_Unarchive(0x006A31E0, Npc_Unarchive, Union.GetEngineVersion() == TEngineVersion::Engine_G1 ? IVK_AUTO : IVK_DISABLED);
static void __fastcall Npc_Unarchive(oCNpc* _this, void* vt, zCArchiver& ar)
{
    // First call the original function
    pNpc_Unarchive(_this, ar);
    // If _this is a dead goblin
    if (_this && (_this->guild == NPC_GIL_GOBBO || _this->guild == NPC_GIL_SKELETON) && _this->attribute[NPC_ATR_HITPOINTS] == 0)
    {
        // get a pointer to the goblin model
        zCModel* pModel = _this->GetModel();
        // if there is no pointer, then exit
        if (!pModel) return;
        // get a pointer to the node of the right hand
        zCModelNodeInst* pNodeInst = pModel->SearchNode(NPC_NODE_RIGHTHAND);
      
        // if there is no pointer, then exit
        if (!pNodeInst)    return;
        // otherwise, erase the node's visual
        pModel->SetNodeVisual(pNodeInst, NULL, FALSE);
    }
}
}
namespace Gothic_I_Addon {
// 0x006D5AD0 protected: virtual void __thiscall oCNpc::Unarchive(class zCArchiver &)
static void __fastcall Npc_Unarchive(oCNpc* _this, void* vt, zCArchiver& ar);
static CInvoke <void(__thiscall*)(oCNpc*, zCArchiver&)> pNpc_Unarchive(0x006D5AD0, Npc_Unarchive, Union.GetEngineVersion() == TEngineVersion::Engine_G1A ? IVK_AUTO : IVK_DISABLED);
static void __fastcall Npc_Unarchive(oCNpc* _this, void* vt, zCArchiver& ar)
{
    pNpc_Unarchive(_this, ar);
    if (_this && (_this->guild == NPC_GIL_GOBBO || _this->guild == NPC_GIL_SKELETON) && _this->attribute[NPC_ATR_HITPOINTS] == 0)
    {
        zCModel* pModel = _this->GetModel();
        if (!pModel)
            return;
        zCModelNodeInst* pNodeInst = pModel->SearchNode(NPC_NODE_RIGHTHAND);
        if (!pNodeInst)
            return;
        pModel->SetNodeVisual(pNodeInst, NULL, FALSE);
    }
}
}
namespace Gothic_II_Classic {
// 0x006E8790 protected: virtual void __thiscall oCNpc::Unarchive(class zCArchiver &)
static void __fastcall Npc_Unarchive(oCNpc* _this, void* vt, zCArchiver& ar);
static CInvoke <void(__thiscall*)(oCNpc*, zCArchiver&)> pNpc_Unarchive(0x006E8790, Npc_Unarchive, Union.GetEngineVersion() == TEngineVersion::Engine_G2 ? IVK_AUTO : IVK_DISABLED);
static void __fastcall Npc_Unarchive(oCNpc* _this, void* vt, zCArchiver& ar)
{
    pNpc_Unarchive(_this, ar);
    if (_this && (_this->guild == NPC_GIL_GOBBO || _this->guild == NPC_GIL_GOBBO_SKELETON || _this->guild == NPC_GIL_SUMMONED_GOBBO_SKELETON) && _this->attribute[NPC_ATR_HITPOINTS] == 0)
    {
        zCModel* pModel = _this->GetModel();
        if (!pModel)
            return;
      
        // declare a null pointer to the node
        zCModelNodeInst* pNodeInst = NULL;
        // iterate over all nodes of the model
        for(int i = 0; i < pModel->nodeList.GetNum(); i++)
        {
            // check the pointer to the prototype of the node, if in order, then continue
            if (pModel->nodeList[i]->protoNode)
            {
                // retrieve node name
                string nodeName = pModel->nodeList[i]->protoNode->nodeName;
                // if it's a right hand node (names are compared)
                if (nodeName.Compare(NPC_NODE_RIGHTHAND))
                {
                    // remember the pointer to the node
                    pNodeInst = pModel->nodeList[i];
                    // exit the loop
                    break;
                }
            }
        }
        // if the pointer to the node of the right hand is not found
        if (!pNodeInst)
            // exit the function
            return;
        // otherwise, erase the node's visual
        pModel->SetNodeVisual(pNodeInst, NULL, FALSE);
    }
}
}
namespace Gothic_II_Addon {
// 0x00747230 protected: virtual void __thiscall oCNpc::Unarchive(class zCArchiver &)
static void __fastcall Npc_Unarchive(oCNpc* _this, void* vt, zCArchiver& ar);
static CInvoke <void(__thiscall*)(oCNpc*, zCArchiver&)> pNpc_Unarchive(0x00747230, Npc_Unarchive, Union.GetEngineVersion() == TEngineVersion::Engine_G2A ? IVK_AUTO : IVK_DISABLED);
static void __fastcall Npc_Unarchive(oCNpc* _this, void* vt, zCArchiver& ar)
{
    pNpc_Unarchive(_this, ar);
  
    if (_this && (_this->guild == NPC_GIL_GOBBO || _this->guild == NPC_GIL_GOBBO_SKELETON || _this->guild == NPC_GIL_SUMMONED_GOBBO_SKELETON) && _this->attribute[NPC_ATR_HITPOINTS] == 0)
    {
        zCModel* pModel = _this->GetModel();
        if (!pModel)
            return;
        zCModelNodeInst* pNodeInst = pModel->SearchNode(NPC_NODE_RIGHTHAND);
        if (!pNodeInst)
            return;
      
        pModel->SetNodeVisual(pNodeInst, NULL, FALSE);
    }
}
}