do

# Brute51: I sometimes need to change the blueprint to fix something. Some support functionality here, no bug fixes.


local CBFP_oldModBlueprints = ModBlueprints
function ModBlueprints(all_bps)
    CBFP_oldModBlueprints(all_bps)
    for id, bp in all_bps.Unit do

        if bp.ResolvePath then  # a convinient way to lookup certain files, required for a flexible mod name
            bp = ResolvePaths(bp)
        end

        if bp.AddCategories and bp.Categories then  # adds new categories, used for mod compatible blueprint categories manipulation
            for k, cat in bp.AddCategories do
                table.insert( bp.Categories, cat)
            end
            bp.AddCategories = nil
        end

        if bp.DelCategories and bp.Categories then  # deletes categories, used for mod compatible blueprint categories manipulation
            for k, cat in bp.DelCategories do
                table.removeByValue( bp.Categories, cat )
            end
            bp.DelCategories = nil
        end

        if bp.AI.AddTargetBones and bp.AI.TargetBones then
            for k, bone in bp.AI.AddTargetBones do
                table.insert( bp.AI.TargetBones, bone)
            end
            bp.AI.AddTargetBones = nil
        end

        if bp.AI.DelTargetBones and bp.AI.TargetBones then
            for k, bone in bp.AI.DelTargetBones do
                table.removeByValue( bp.AI.TargetBones, bone )
            end
            bp.AI.DelTargetBones = nil
        end

        if bp.Display.AddAbilities and bp.Display.Abilities then
            for k, ab in bp.Display.AddAbilities do
                table.insert( bp.Display.Abilities, ab)
            end
            bp.Display.AddAbilities = nil
        end

        if bp.Display.DelAbilities and bp.Display.Abilities then
            for k, ab in bp.Display.DelAbilities do
                table.removeByValue( bp.Display.Abilities, ab )
            end
            bp.Display.DelAbilities = nil
        end
    end
end

# finds a path that starts with [...] , finds the specified file and then corrects the path
function ResolvePaths(bpTable)
    for k, v in bpTable do
        if type(v) == 'table' then
            bpTable[k] = ResolvePaths(v)
            continue
        elseif type(v) != 'string' or string.len(v) < 8 or string.sub(v, 1, 5) != '[...]' then
            continue
        end
        local partialPath = string.sub(v, 6) # v needs to be > 6 for this, checking v >= 8 two lines up
        local path = ''
        local foundResult = false
        LOG('Resolving full path for '..repr(partialPath))
        for i, m in __active_mods do
            for _,file in DiskFindFiles(m.location, partialPath) do
                path = file
                foundResult = true
                break
            end
            if foundResult then
                break
            end
        end
        if not foundResult then
            WARN('Cannot resolve full path for partial path '..repr(partialPath))
            continue
        end
        bpTable[k] = path
    end
    return bpTable
end


end




