--'HatDecap script' REFramework script for Resident Evil 4 Remake
--By taruo
--v0.3

local PlayerBodyPartsCutDriver = nil

local function getBhead_head()
    -- Get behead_head object from scene.　behead_head is not activated until decapitation occurs.
    scene_manager = sdk.get_native_singleton("via.SceneManager")
    if not scene_manager then
        return
    end
    scene = sdk.call_native_func(scene_manager, sdk.find_type_definition("via.SceneManager"), "get_CurrentScene")
    if not scene then
        return
    end
    return scene:call("findGameObject(System.String)", "behead_head")
end


sdk.hook(sdk.find_type_definition("chainsaw.PlayerBodyPartsCutDriver"):get_method("requestBehead"),
	function(args)
        PlayerBodyPartsCutDriver = sdk.to_managed_object(args[2]) --Save PartsCutDriver Object
	end,
	function(retval)
        local behead_head_Object = getBhead_head()
        PlayerBodyPartsCutDriver:call("setupBeheadHatBody",behead_head_Object)
		return retval
	end
)