--[[
    ============================================================================
    MGS Attached Implement Interactive Control Bridge
    ----------------------------------------------------------------------------
    Author      : MyGameSteam
    Version     : 1.0.0.0
    Game        : Farming Simulator 25
	Date        : June 27th 2026

    Description:
    Provides custom Interactive Control functions that allow a tractor to
    operate compatible attached implements directly from the cab.

    Current Functions:
      - MGS_ATTACHED_BALER_UNLOAD
      - MGS_ATTACHED_BALEWRAPPER_UNLOAD

    The script recursively searches the attached implement hierarchy to locate
    the first compatible implement and forwards the corresponding action.

    Designed to be easily extended with additional attached implement functions
    in future updates without modifying the Interactive Control mod itself.

    ============================================================================
]]

MGSAttachedBaleIC={};local function v0() if (InteractiveFunctions~=nil) then return InteractiveFunctions;end if (g_interactiveControlModName~=nil) then local v15=87 -(48 + 39) ;local v16;while true do if (v15==0) then v16=_G[g_interactiveControlModName];if ((v16~=nil) and (v16.InteractiveFunctions~=nil)) then return v16.InteractiveFunctions;end break;end end end local v4=_G['FS25_interactiveControl'];if ((v4~=nil) and (v4.InteractiveFunctions~=nil)) then return v4.InteractiveFunctions;end return nil;end local function v1(v5,v6,v7) local v8=209 -(133 + 76) ;while true do if (v8==2) then return nil;end if (v8==(1656 -(1594 + 61))) then if v6(v5) then return v5;end if (v5.getAttachedImplements~=nil) then for v36,v37 in ipairs(v5:getAttachedImplements() or {} ) do local v38=1661 -(108 + 1553) ;local v39;while true do if (v38==(513 -(232 + 281))) then v39=v1(v37.object,v6,v7 + (1254 -(976 + 277)) );if (v39~=nil) then return v39;end break;end end end end v8=959 -(892 + 65) ;end if (v8==(0 -0)) then v7=v7 or (0 -0) ;if ((v5==nil) or (v7>20)) then return nil;end v8=1;end end end local function v2(v9,v10) local v11=v0();if ((v11==nil) or (v11.addFunction==nil)) then print("[MGSAttachedBaleIC] IC functions not found");return false;end if ((v11.getFunctionData~=nil) and (v11.getFunctionData(v9)~=nil)) then return true;end return v11.addFunction(v9,v10);end MGSAttachedBaleIC.register=function() local v12=0;local v13;local v14;while true do if (v12==(1 -0)) then v14=v2("MGS_ATTACHED_BALEWRAPPER_UNLOAD",{posFunc=function(v17,v18,v19) if v19 then return;end local v20=v1(v17,function(v33) return (v33~=nil) and (v33.spec_baleWrapper~=nil) ;end);if ((v20~=nil) and (BaleWrapper~=nil) and BaleWrapper.getIsBaleDropAllowed(v20)) then BaleWrapper.actionEventDrop(v20);end end,isBlockedFunc=function(v21,v22) local v23=350 -(87 + 263) ;local v24;while true do if (v23==0) then v24=v1(v21,function(v40) return (v40~=nil) and (v40.spec_baleWrapper~=nil) ;end);if ((v24==nil) or (v24.spec_baleWrapper==nil) or (BaleWrapper==nil)) then return false;end v23=1;end if (v23==(181 -(67 + 113))) then return BaleWrapper.getIsBaleDropAllowed(v24);end end end});if (v13 or v14) then local v34=0;while true do if (v34==(0 + 0)) then MGSAttachedBaleIC.registered=true;print("[MGSAttachedBaleIC] Custom IC functions registered");break;end end end break;end if (v12==(0 -0)) then if MGSAttachedBaleIC.registered then return;end v13=v2("MGS_ATTACHED_BALER_UNLOAD",{posFunc=function(v25,v26,v27) local v28=0 + 0 ;local v29;while true do if (v28==(0 -0)) then if v27 then return;end v29=v1(v25,function(v42) return (v42~=nil) and (v42.spec_baler~=nil) ;end);v28=953 -(802 + 150) ;end if (v28==(2 -1)) then if ((v29~=nil) and (Baler~=nil) and Baler.isUnloadingAllowed(v29)) then Baler.actionEventUnloading(v29);end break;end end end,isBlockedFunc=function(v30,v31) local v32=v1(v30,function(v35) return (v35~=nil) and (v35.spec_baler~=nil) ;end);if ((v32==nil) or (v32.spec_baler==nil) or (Baler==nil)) then return false;end return Baler.isUnloadingAllowed(v32);end});v12=1 -0 ;end end end;MGSAttachedBaleIC.register();