private void ProcessItem1(CustomPathFind.BufferItem item, ushort nodeID, ref NetNode node, byte connectOffset, bool isMiddle, ref PathUnit data)
        {
            NetManager instance = Singleton<NetManager>.instance;
            bool flag = false;
            int num = 0;
            NetInfo info = instance.m_segments.m_buffer[(int)item.m_position.m_segment].Info;
            if ((int)item.m_position.m_lane < info.m_lanes.Length)
            {
                NetInfo.Lane lane = info.m_lanes[(int)item.m_position.m_lane];
                flag = (lane.m_laneType == NetInfo.LaneType.Pedestrian);
                if ((byte)(lane.m_finalDirection & NetInfo.Direction.Forward) != 0)
                {
                    num = lane.m_similarLaneIndex;
                }
                else
                {
                    num = lane.m_similarLaneCount - lane.m_similarLaneIndex - 1;
                }
            }
            if (isMiddle)
            {
                for (int j = 0; j < 8; j++)
                {
                    ushort segmentID = node.GetSegment(j);
                    if (segmentID != 0)
                    {
                        this.ProcessItem4(item, nodeID, segmentID, ref instance.m_segments.m_buffer[(int)segmentID],
                        ref num, connectOffset, !flag, flag);
                    }
                }
            }
            else if (flag)
            {
                ushort segment2 = item.m_position.m_segment;
                int lane2 = (int)item.m_position.m_lane;
                if (node.Info.m_class.m_service != ItemClass.Service.Beautification)
                {
                    bool flag2 = (node.m_flags & (NetNode.Flags.End | NetNode.Flags.Bend | NetNode.Flags.Junction)) != NetNode.Flags.None;
                    int laneIndex;
                    int laneIndex2;
                    uint num2;
                    uint num3;
                    instance.m_segments.m_buffer[(int)segment2].GetLeftAndRightLanes(nodeID, NetInfo.LaneType.Pedestrian, VehicleInfo.VehicleType.None, lane2, out laneIndex, out laneIndex2, out num2, out num3);
                    ushort num4 = segment2;
                    ushort num5 = segment2;
                    if (num2 == 0u || num3 == 0u)
                    {
                        ushort leftSegment;
                        ushort rightSegment;
                        instance.m_segments.m_buffer[(int)segment2].GetLeftAndRightSegments(nodeID, out leftSegment, out rightSegment);
                        int num6 = 0;
                        while (leftSegment != 0 && leftSegment != segment2 && num2 == 0u)
                        {
                            int num7;
                            int num8;
                            uint num9;
                            uint num10;
                            instance.m_segments.m_buffer[(int)leftSegment].GetLeftAndRightLanes(nodeID, NetInfo.LaneType.Pedestrian, VehicleInfo.VehicleType.None, -1, out num7, out num8, out num9, out num10);
                            if (num10 != 0u)
                            {
                                num4 = leftSegment;
                                laneIndex = num8;
                                num2 = num10;
                            }
                            else
                            {
                                leftSegment = instance.m_segments.m_buffer[(int)leftSegment].GetLeftSegment(nodeID);
                            }
                            if (++num6 == 8)
                            {
                                break;
                            }
                        }
                        num6 = 0;
                        while (rightSegment != 0 && rightSegment != segment2 && num3 == 0u)
                        {
                            int num11;
                            int num12;
                            uint num13;
                            uint num14;
                            instance.m_segments.m_buffer[(int)rightSegment].GetLeftAndRightLanes(nodeID, NetInfo.LaneType.Pedestrian, VehicleInfo.VehicleType.None, -1, out num11, out num12, out num13, out num14);
                            if (num13 != 0u)
                            {
                                num5 = rightSegment;
                                laneIndex2 = num11;
                                num3 = num13;
                            }
                            else
                            {
                                rightSegment = instance.m_segments.m_buffer[(int)rightSegment].GetRightSegment(nodeID);
                            }
                            if (++num6 == 8)
                            {
                                break;
                            }
                        }
                    }
                    if (num2 != 0u && (num4 != segment2 || flag2))
                    {
                        this.ProcessItem5(item, nodeID, num4, ref instance.m_segments.m_buffer[(int)num4], connectOffset, laneIndex, num2);
                    }
                    if (num3 != 0u && num3 != num2 && (num5 != segment2 || flag2))
                    {
                        this.ProcessItem5(item, nodeID, num5, ref instance.m_segments.m_buffer[(int)num5], connectOffset, laneIndex2, num3);
                    }
                }
                else
                {
                    for (int j = 0; j < 8; j++)
                    {
                        ushort segment3 = node.GetSegment(j);
                        if (segment3 != 0 && segment3 != segment2)
                        {
                            this.ProcessItem4(item, nodeID, segment3, ref instance.m_segments.m_buffer[(int)segment3], ref num, connectOffset, false, true);
                        }
                    }
                }
                NetInfo.LaneType laneType = this.m_laneTypes & ~NetInfo.LaneType.Pedestrian;
                laneType &= ~(item.m_lanesUsed & NetInfo.LaneType.Vehicle);
                int num15;
                uint lane3;
                if (laneType != NetInfo.LaneType.None && instance.m_segments.m_buffer[(int)segment2].GetClosestLane(lane2, laneType, this.m_vehicleTypes, out num15, out lane3))
                {
                    NetInfo.Lane lane4 = info.m_lanes[num15];
                    byte connectOffset2;
                    if ((instance.m_segments.m_buffer[(int)segment2].m_flags & NetSegment.Flags.Invert) != NetSegment.Flags.None == ((byte)(lane4.m_finalDirection & NetInfo.Direction.Backward) != 0))
                    {
                        connectOffset2 = 1;
                    }
                    else
                    {
                        connectOffset2 = 254;
                    }
                    this.ProcessItem5(item, nodeID, segment2, ref instance.m_segments.m_buffer[(int)segment2], connectOffset2, num15, lane3);
                }
            }
            else
            {
                bool flag3 = (node.m_flags & (NetNode.Flags.End | NetNode.Flags.OneWayOut)) != NetNode.Flags.None;
                bool flag4 = (byte)(this.m_laneTypes & NetInfo.LaneType.Pedestrian) != 0;
                byte connectOffset3 = 0;
                if (flag4)
                {
                    if (this.m_vehicleLane != 0u)
                    {
                        if (this.m_vehicleLane != item.m_laneID)
                        {
                            flag4 = false;
                        }
                        else
                        {
                            connectOffset3 = this.m_vehicleOffset;
                        }
                    }
                    else if (this.m_stablePath)
                    {
                        connectOffset3 = 128;
                    }
                    else
                    {
                        connectOffset3 = (byte)this.m_pathRandomizer.UInt32(1u, 254u);
                    }
                }

                ushort num16 = instance.m_segments.m_buffer[(int)item.m_position.m_segment].GetRightSegment(nodeID);
                for (int k = 0; k < 8; k++)
                {
                    if (num16 == 0 || num16 == item.m_position.m_segment)
                    {
                        break;
                    }

                    if (TrafficPriority.isPrioritySegment(nodeID, num16) && data.m_position00.m_segment != num16)
                    {
                        var segment = instance.m_segments.m_buffer[num16];

                        var info2 = segment.Info;

                        uint segmentLanes = segment.m_lanes;
                        int infoLanes = 0;

                        var lanes = 0;

                        int[] laneNums = new int[16];
                        uint[] laneIds = new uint[16];

                        NetInfo.Direction dir = NetInfo.Direction.Forward;
                        if (segment.m_startNode == nodeID)
                            dir = NetInfo.Direction.Backward;
                        var dir2 = ((segment.m_flags & NetSegment.Flags.Invert) == NetSegment.Flags.None) ? dir : NetInfo.InvertDirection(dir);
                        var dir3 = TrafficPriority.leftHandDrive ? NetInfo.InvertDirection(dir2) : dir2;

                        var m_lanes = info2.m_lanes;

                        if (TrafficPriority.leftHandDrive)
                        {
                            m_lanes.Reverse();
                        }

                        var laneArrows = 0;

                        while (infoLanes < m_lanes.Length && segmentLanes != 0u)
                        {
                            if (((NetLane.Flags)instance.m_lanes.m_buffer[segmentLanes].m_flags & NetLane.Flags.Left) ==
                                NetLane.Flags.Left || ((NetLane.Flags)instance.m_lanes.m_buffer[segmentLanes].m_flags & NetLane.Flags.Right) ==
                                        NetLane.Flags.Right || ((NetLane.Flags)instance.m_lanes.m_buffer[segmentLanes].m_flags & NetLane.Flags.Forward) ==
                                        NetLane.Flags.Forward)
                            {
                                laneArrows++;
                            }

                            if (m_lanes[infoLanes].m_laneType == NetInfo.LaneType.Vehicle && m_lanes[infoLanes].m_direction == dir3)
                            {
                                if (TrafficPriority.isLeftSegment(num16, item.m_position.m_segment, nodeID))
                                {
                                    if (((NetLane.Flags)instance.m_lanes.m_buffer[segmentLanes].m_flags & NetLane.Flags.Left) ==
                                        NetLane.Flags.Left)
                                    {
                                        laneNums[lanes] = infoLanes;
                                        laneIds[lanes] = segmentLanes;
                                        lanes++;
                                    }
                                }
                                else if (TrafficPriority.isRightSegment(num16, item.m_position.m_segment, nodeID))
                                {
                                    if (((NetLane.Flags)instance.m_lanes.m_buffer[segmentLanes].m_flags & NetLane.Flags.Right) ==
                                        NetLane.Flags.Right)
                                    {
                                        laneNums[lanes] = infoLanes;
                                        laneIds[lanes] = segmentLanes;
                                        lanes++;
                                    }
                                }
                                else
                                {
                                    if (((NetLane.Flags)instance.m_lanes.m_buffer[segmentLanes].m_flags & NetLane.Flags.Forward) ==
                                        NetLane.Flags.Forward)
                                    {
                                        laneNums[lanes] = infoLanes;
                                        laneIds[lanes] = segmentLanes;
                                        lanes++;
                                    }
                                }
                            }

                            segmentLanes = instance.m_lanes.m_buffer[(int)((UIntPtr)segmentLanes)].m_nextLane;
                            infoLanes++;
                        }

                        if (laneArrows > 0)
                        {
                            var newLaneNum = 0;
                            var newLaneId = 0u;
                            var newLane = -1;

                            if (lanes > 0)
                            {
                                if (lanes == 1)
                                {
                                    newLaneNum = laneNums[0];
                                    newLaneId = laneIds[0];
                                }
                                else
                                {
                                    var laneFound = false;

                                    if (info2.m_lanes.Length == info.m_lanes.Length)
                                    {

                                        for (var i = 0; i < laneNums.Length; i++)
                                        {
                                            if (laneNums[i] == item.m_position.m_lane)
                                            {
                                                newLaneNum = laneNums[i];
                                                newLaneId = laneIds[i];
                                                laneFound = true;
                                                break;
                                            }
                                        }
                                    }

                                    if (!laneFound)
                                    {
                                        var lanePos = Mathf.Abs(info.m_lanes[item.m_position.m_lane].m_position);
                                        var closest = 100f;
                                        for (var i = 0; i < lanes; i++)
                                        {
                                            var newLanePos = Mathf.Abs(info2.m_lanes[laneNums[i]].m_position);

                                            if (Math.Abs(newLanePos - lanePos) < closest)
                                            {
                                                closest = Mathf.Abs(newLanePos - lanePos);
                                                newLane = i;
                                            }
                                        }

                                        if (newLane == -1)
                                        {
                                            newLaneNum = laneNums[0];
                                            newLaneId = laneIds[0];
                                        }
                                        else
                                        {
                                            newLaneNum = laneNums[newLane];
                                            newLaneId = laneIds[newLane];
                                        }
                                    }
                                }

                                this.ProcessItem2(item, nodeID, num16, ref instance.m_segments.m_buffer[(int)num16],
                                    ref num,
                                    connectOffset, true, false, newLaneId, newLaneNum);
                            }
                        }
                        else
                        {
                            if (this.ProcessItem4(item, nodeID, num16, ref instance.m_segments.m_buffer[(int)num16], ref num,
                                connectOffset, true, false))
                            {
                                flag3 = true;
                            }
                        }
                    }
                    //else if (TrafficRoadRestrictions.isSegment(num16))
                    //{
                    //    var restSegment = TrafficRoadRestrictions.getSegment(num16);

                    //    var preferedLaneAllows = 100;
                    //    uint preferedLaneId = 0;
                    //    int preferedLaneNum = 0;

                    //    NetInfo.Lane lane = info.m_lanes[(int)item.m_position.m_lane];

                    //    for (var i = 0; i < restSegment.lanes.Count; i++)
                    //    {
                    //        if ((byte) (lane.m_finalDirection & NetInfo.Direction.Forward) != 0)
                    //        {
                    //            if ((byte) (restSegment.lanes[i].direction & NetInfo.Direction.Forward) == 0)
                    //            {
                    //                continue;
                    //            }
                    //        }
                    //        else
                    //        {
                    //            if ((byte) (restSegment.lanes[i].direction & NetInfo.Direction.Backward) == 0)
                    //            {
                    //                continue;
                    //            }
                    //        }

                    //        if (this.m_vehicleType == TrafficRoadRestrictions.VehicleType.Car)
                    //        {
                    //            if (restSegment.lanes[i].enableCars)
                    //            {
                    //                if (restSegment.lanes[i].laneNum == num)
                    //                {
                    //                    preferedLaneId = restSegment.lanes[i].laneID;
                    //                    preferedLaneNum = restSegment.lanes[i].laneNum;
                    //                    break;
                    //                }
                    //                else if (restSegment.lanes[i].enabledTypes < preferedLaneAllows)
                    //                {
                    //                    preferedLaneId = restSegment.lanes[i].laneID;
                    //                    preferedLaneNum = restSegment.lanes[i].laneNum;
                    //                    preferedLaneAllows = restSegment.lanes[i].enabledTypes;
                    //                }
                    //            }
                    //        }
                    //        else if (this.m_vehicleType == TrafficRoadRestrictions.VehicleType.Service)
                    //        {
                    //            if (restSegment.lanes[i].enableService)
                    //            {
                    //                if (restSegment.lanes[i].laneNum == num)
                    //                {
                    //                    preferedLaneId = restSegment.lanes[i].laneID;
                    //                    preferedLaneNum = restSegment.lanes[i].laneNum;
                    //                    break;
                    //                }
                    //                else if (restSegment.lanes[i].enabledTypes < preferedLaneAllows)
                    //                {
                    //                    preferedLaneId = restSegment.lanes[i].laneID;
                    //                    preferedLaneNum = restSegment.lanes[i].laneNum;
                    //                    preferedLaneAllows = restSegment.lanes[i].enabledTypes;
                    //                }
                    //            }
                    //        }
                    //        else if (this.m_vehicleType == TrafficRoadRestrictions.VehicleType.Cargo)
                    //        {
                    //            if (restSegment.lanes[i].enableCargo)
                    //            {
                    //                if (restSegment.lanes[i].laneNum == num)
                    //                {
                    //                    preferedLaneId = restSegment.lanes[i].laneID;
                    //                    preferedLaneNum = restSegment.lanes[i].laneNum;
                    //                    break;
                    //                }
                    //                else if (restSegment.lanes[i].enabledTypes < preferedLaneAllows)
                    //                {
                    //                    preferedLaneId = restSegment.lanes[i].laneID;
                    //                    preferedLaneNum = restSegment.lanes[i].laneNum;
                    //                    preferedLaneAllows = restSegment.lanes[i].enabledTypes;
                    //                }
                    //            }
                    //        }
                    //        else if (this.m_vehicleType == TrafficRoadRestrictions.VehicleType.Transport)
                    //        {
                    //            if (restSegment.lanes[i].enableTransport)
                    //            {
                    //                if (restSegment.lanes[i].laneNum == num)
                    //                {
                    //                    preferedLaneId = restSegment.lanes[i].laneID;
                    //                    preferedLaneNum = restSegment.lanes[i].laneNum;
                    //                    break;
                    //                }
                    //                else if (restSegment.lanes[i].enabledTypes < preferedLaneAllows)
                    //                {
                    //                    preferedLaneId = restSegment.lanes[i].laneID;
                    //                    preferedLaneNum = restSegment.lanes[i].laneNum;
                    //                    preferedLaneAllows = restSegment.lanes[i].enabledTypes;
                    //                }
                    //            }
                    //        }
                    //    }

                    //    if (preferedLaneId != 0)
                    //    {
                    //        this.ProcessItem2(item, nodeID, num16, ref instance.m_segments.m_buffer[(int)num16],
                    //            ref num,
                    //            connectOffset, true, false, preferedLaneId, preferedLaneNum);
                    //    }
                    //}
                    else
                    {
                        if (this.ProcessItem4(item, nodeID, num16, ref instance.m_segments.m_buffer[(int)num16], ref num,
                            connectOffset, true, false))
                        {
                            flag3 = true;
                        }
                    }

                    num16 = instance.m_segments.m_buffer[(int)num16].GetRightSegment(nodeID);
                }
                if (flag3)
                {
                    num16 = item.m_position.m_segment;
                    this.ProcessItem4(item, nodeID, num16, ref instance.m_segments.m_buffer[(int)num16], ref num, connectOffset, true, false);
                }
                int laneIndex3;
                uint lane5;
                if (flag4 && instance.m_segments.m_buffer[(int)num16].GetClosestLane((int)item.m_position.m_lane, NetInfo.LaneType.Pedestrian, this.m_vehicleTypes, out laneIndex3, out lane5))
                {
                    this.ProcessItem5(item, nodeID, num16, ref instance.m_segments.m_buffer[(int)num16], connectOffset3, laneIndex3, lane5);
                }
            }
            if (node.m_lane != 0u)
            {
                bool targetDisabled = (node.m_flags & NetNode.Flags.Disabled) != NetNode.Flags.None;
                ushort segment4 = instance.m_lanes.m_buffer[(int)((UIntPtr)node.m_lane)].m_segment;
                if (segment4 != 0 && segment4 != item.m_position.m_segment)
                {
                    this.ProcessItem3(item, nodeID, targetDisabled, segment4, ref instance.m_segments.m_buffer[(int)segment4], node.m_lane, node.m_laneOffset, connectOffset);
                }
            }
        }
 private void AddBufferItem(CustomPathFind.BufferItem item, PathUnit.Position target)
 {
     uint num = this.m_laneLocation[(int)((UIntPtr)item.m_laneID)];
     uint num2 = num >> 16;
     int num3 = (int)(num & 65535u);
     int num6;
     if (num2 == this.m_pathFindIndex)
     {
         if (item.m_comparisonValue >= this.m_buffer[num3].m_comparisonValue)
         {
             return;
         }
         int num4 = num3 >> 6;
         int num5 = num3 & -64;
         if (num4 < this.m_bufferMinPos || (num4 == this.m_bufferMinPos && num5 < this.m_bufferMin[num4]))
         {
             return;
         }
         num6 = Mathf.Max(Mathf.RoundToInt(item.m_comparisonValue * 1024f), this.m_bufferMinPos);
         if (num6 == num4)
         {
             this.m_buffer[num3] = item;
             this.m_laneTarget[(int)((UIntPtr)item.m_laneID)] = target;
             return;
         }
         int num7 = num4 << 6 | this.m_bufferMax[num4]--;
         CustomPathFind.BufferItem bufferItem = this.m_buffer[num7];
         this.m_laneLocation[(int)((UIntPtr)bufferItem.m_laneID)] = num;
         this.m_buffer[num3] = bufferItem;
     }
     else
     {
         num6 = Mathf.Max(Mathf.RoundToInt(item.m_comparisonValue * 1024f), this.m_bufferMinPos);
     }
     if (num6 >= 1024)
     {
         return;
     }
     while (this.m_bufferMax[num6] == 63)
     {
         num6++;
         if (num6 == 1024)
         {
             return;
         }
     }
     if (num6 > this.m_bufferMaxPos)
     {
         this.m_bufferMaxPos = num6;
     }
     num3 = (num6 << 6 | ++this.m_bufferMax[num6]);
     this.m_buffer[num3] = item;
     this.m_laneLocation[(int)((UIntPtr)item.m_laneID)] = (this.m_pathFindIndex << 16 | (uint)num3);
     this.m_laneTarget[(int)((UIntPtr)item.m_laneID)] = target;
 }
        private bool ProcessItem4(CustomPathFind.BufferItem item, ushort targetNode, ushort segmentID, ref NetSegment segment, ref int currentTargetIndex, byte connectOffset, bool enableVehicle, bool enablePedestrian)
        {
            bool result = false;
            if ((segment.m_flags & (NetSegment.Flags.PathFailed | NetSegment.Flags.Flooded)) != NetSegment.Flags.None)
            {
                return result;
            }
            NetManager instance = Singleton<NetManager>.instance;
            NetInfo info = segment.Info;
            NetInfo info2 = instance.m_segments.m_buffer[(int)item.m_position.m_segment].Info;
            int num = info.m_lanes.Length;
            uint num2 = segment.m_lanes;
            NetInfo.Direction direction = (targetNode != segment.m_startNode) ? NetInfo.Direction.Forward : NetInfo.Direction.Backward;
            NetInfo.Direction direction2 = ((segment.m_flags & NetSegment.Flags.Invert) == NetSegment.Flags.None) ? direction : NetInfo.InvertDirection(direction);
            float num3 = 0.01f - Mathf.Min(info.m_maxTurnAngleCos, info2.m_maxTurnAngleCos);
            if (num3 < 1f)
            {
                Vector3 vector;
                if (targetNode == instance.m_segments.m_buffer[(int)item.m_position.m_segment].m_startNode)
                {
                    vector = instance.m_segments.m_buffer[(int)item.m_position.m_segment].m_startDirection;
                }
                else
                {
                    vector = instance.m_segments.m_buffer[(int)item.m_position.m_segment].m_endDirection;
                }
                Vector3 vector2;
                if ((byte)(direction & NetInfo.Direction.Forward) != 0)
                {
                    vector2 = segment.m_endDirection;
                }
                else
                {
                    vector2 = segment.m_startDirection;
                }
                float num4 = vector.x * vector2.x + vector.z * vector2.z;
                if (num4 >= num3)
                {
                    return result;
                }
            }
            float num5 = 1f;
            float num6 = 1f;
            NetInfo.LaneType laneType = NetInfo.LaneType.None;
            VehicleInfo.VehicleType vehicleType = VehicleInfo.VehicleType.None;
            if ((int)item.m_position.m_lane < info2.m_lanes.Length)
            {
                NetInfo.Lane lane = info2.m_lanes[(int)item.m_position.m_lane];
                laneType = lane.m_laneType;
                vehicleType = lane.m_vehicleType;
                num5 = lane.m_speedLimit;
                num6 = this.CalculateLaneSpeed(connectOffset, item.m_position.m_offset, ref instance.m_segments.m_buffer[(int)item.m_position.m_segment], lane);
            }
            float num7 = instance.m_segments.m_buffer[(int)item.m_position.m_segment].m_averageLength;
            if (!this.m_stablePath)
            {
                Randomizer randomizer = new Randomizer(this.m_pathFindIndex << 16 | (uint)item.m_position.m_segment);
                num7 *= (float)(randomizer.Int32(900, 1000 + (int)(instance.m_segments.m_buffer[(int)item.m_position.m_segment].m_trafficDensity * 10)) + this.m_pathRandomizer.Int32(20u)) * 0.001f;
            }
            if (this.m_isHeavyVehicle && (instance.m_segments.m_buffer[(int)item.m_position.m_segment].m_flags & NetSegment.Flags.HeavyBan) != NetSegment.Flags.None)
            {
                num7 *= 10f;
            }
            float num8 = (float)Mathf.Abs((int)(connectOffset - item.m_position.m_offset)) * 0.003921569f * num7;
            float num9 = item.m_methodDistance + num8;
            float num10 = item.m_comparisonValue + num8 / (num6 * this.m_maxLength);
            Vector3 b = instance.m_lanes.m_buffer[(int)((UIntPtr)item.m_laneID)].CalculatePosition((float)connectOffset * 0.003921569f);
            int num11 = currentTargetIndex;
            bool flag = (instance.m_nodes.m_buffer[(int)targetNode].m_flags & NetNode.Flags.Transition) != NetNode.Flags.None;
            NetInfo.LaneType laneType2 = this.m_laneTypes;
            if (!enableVehicle)
            {
                laneType2 &= ~NetInfo.LaneType.Vehicle;
            }
            if (!enablePedestrian)
            {
                laneType2 &= ~NetInfo.LaneType.Pedestrian;
            }
            int num12 = 0;
            while (num12 < num && num2 != 0u)
            {
                NetInfo.Lane lane2 = info.m_lanes[num12];
                if ((byte)(lane2.m_finalDirection & direction2) != 0)
                {
                    if (lane2.CheckType(laneType2, this.m_vehicleTypes) && (segmentID != item.m_position.m_segment || num12 != (int)item.m_position.m_lane) && (byte)(lane2.m_finalDirection & direction2) != 0)
                    {
                        Vector3 a;
                        if ((byte)(direction & NetInfo.Direction.Forward) != 0)
                        {
                            a = instance.m_lanes.m_buffer[(int)((UIntPtr)num2)].m_bezier.d;
                        }
                        else
                        {
                            a = instance.m_lanes.m_buffer[(int)((UIntPtr)num2)].m_bezier.a;
                        }
                        float num13 = Vector3.Distance(a, b);
                        if (flag)
                        {
                            num13 *= 2f;
                        }
                        float num14 = num13 / ((num5 + lane2.m_speedLimit) * 0.5f * this.m_maxLength);
                        CustomPathFind.BufferItem item2;
                        item2.m_position.m_segment = segmentID;
                        item2.m_position.m_lane = (byte)num12;
                        item2.m_position.m_offset = (byte)(((byte)(direction & NetInfo.Direction.Forward) == 0) ? 0 : 255);
                        if (laneType != lane2.m_laneType)
                        {
                            item2.m_methodDistance = 0f;
                        }
                        else
                        {
                            item2.m_methodDistance = num9 + num13;
                        }
                        if (lane2.m_laneType != NetInfo.LaneType.Pedestrian || item2.m_methodDistance < 1000f)
                        {
                            item2.m_comparisonValue = num10 + num14;
                            if (num2 == this.m_startLaneA)
                            {
                                float num15 = this.CalculateLaneSpeed(this.m_startOffsetA, item2.m_position.m_offset, ref segment, lane2);
                                float num16 = (float)Mathf.Abs((int)(item2.m_position.m_offset - this.m_startOffsetA)) * 0.003921569f;
                                item2.m_comparisonValue += num16 * segment.m_averageLength / (num15 * this.m_maxLength);
                            }
                            if (num2 == this.m_startLaneB)
                            {
                                float num17 = this.CalculateLaneSpeed(this.m_startOffsetB, item2.m_position.m_offset, ref segment, lane2);
                                float num18 = (float)Mathf.Abs((int)(item2.m_position.m_offset - this.m_startOffsetB)) * 0.003921569f;
                                item2.m_comparisonValue += num18 * segment.m_averageLength / (num17 * this.m_maxLength);
                            }
                            if (!this.m_ignoreBlocked && (segment.m_flags & NetSegment.Flags.Blocked) != NetSegment.Flags.None && lane2.m_laneType == NetInfo.LaneType.Vehicle)
                            {
                                item2.m_comparisonValue += 0.1f;
                                result = true;
                            }
                            item2.m_direction = direction;
                            item2.m_lanesUsed = (item.m_lanesUsed | lane2.m_laneType);
                            item2.m_laneID = num2;
                            if (lane2.m_laneType == laneType && lane2.m_vehicleType == vehicleType)
                            {
                                int firstTarget = (int)instance.m_lanes.m_buffer[(int)((UIntPtr)num2)].m_firstTarget;
                                int lastTarget = (int)instance.m_lanes.m_buffer[(int)((UIntPtr)num2)].m_lastTarget;
                                if (currentTargetIndex < firstTarget || currentTargetIndex >= lastTarget)
                                {
                                    item2.m_comparisonValue += Mathf.Max(1f, num13 * 3f - 3f) / ((num5 + lane2.m_speedLimit) * 0.5f * this.m_maxLength);
                                }
                            }

                            this.AddBufferItem(item2, item.m_position);
                        }
                    }
                }
                else if (lane2.m_laneType == laneType && lane2.m_vehicleType == vehicleType)
                {
                    num11++;
                }
                num2 = instance.m_lanes.m_buffer[(int)((UIntPtr)num2)].m_nextLane;
                num12++;
            }
            currentTargetIndex = num11;
            return result;
        }
 private void ProcessItem5(CustomPathFind.BufferItem item, ushort targetNode, ushort segmentID, ref NetSegment segment, byte connectOffset, int laneIndex, uint lane)
 {
     if ((segment.m_flags & (NetSegment.Flags.PathFailed | NetSegment.Flags.Flooded)) != NetSegment.Flags.None)
     {
         return;
     }
     NetManager instance = Singleton<NetManager>.instance;
     NetInfo info = segment.Info;
     NetInfo info2 = instance.m_segments.m_buffer[(int)item.m_position.m_segment].Info;
     int num = info.m_lanes.Length;
     float num2;
     byte offset;
     if (segmentID == item.m_position.m_segment)
     {
         Vector3 b = instance.m_lanes.m_buffer[(int)((UIntPtr)item.m_laneID)].CalculatePosition((float)connectOffset * 0.003921569f);
         Vector3 a = instance.m_lanes.m_buffer[(int)((UIntPtr)lane)].CalculatePosition((float)connectOffset * 0.003921569f);
         num2 = Vector3.Distance(a, b);
         offset = connectOffset;
     }
     else
     {
         NetInfo.Direction direction = (targetNode != segment.m_startNode) ? NetInfo.Direction.Forward : NetInfo.Direction.Backward;
         Vector3 b2 = instance.m_lanes.m_buffer[(int)((UIntPtr)item.m_laneID)].CalculatePosition((float)connectOffset * 0.003921569f);
         Vector3 a2;
         if ((byte)(direction & NetInfo.Direction.Forward) != 0)
         {
             a2 = instance.m_lanes.m_buffer[(int)((UIntPtr)lane)].m_bezier.d;
         }
         else
         {
             a2 = instance.m_lanes.m_buffer[(int)((UIntPtr)lane)].m_bezier.a;
         }
         num2 = Vector3.Distance(a2, b2);
         offset = (byte)(((byte)(direction & NetInfo.Direction.Forward) == 0) ? 0 : 255);
     }
     float num3 = 1f;
     float num4 = 1f;
     NetInfo.LaneType laneType = NetInfo.LaneType.None;
     if ((int)item.m_position.m_lane < info2.m_lanes.Length)
     {
         NetInfo.Lane lane2 = info2.m_lanes[(int)item.m_position.m_lane];
         num3 = lane2.m_speedLimit;
         laneType = lane2.m_laneType;
         num4 = this.CalculateLaneSpeed(connectOffset, item.m_position.m_offset, ref instance.m_segments.m_buffer[(int)item.m_position.m_segment], lane2);
     }
     float averageLength = instance.m_segments.m_buffer[(int)item.m_position.m_segment].m_averageLength;
     float num5 = (float)Mathf.Abs((int)(connectOffset - item.m_position.m_offset)) * 0.003921569f * averageLength;
     float num6 = item.m_methodDistance + num5;
     float num7 = item.m_comparisonValue + num5 / (num4 * this.m_maxLength);
     if (laneIndex < num)
     {
         NetInfo.Lane lane3 = info.m_lanes[laneIndex];
         CustomPathFind.BufferItem item2;
         item2.m_position.m_segment = segmentID;
         item2.m_position.m_lane = (byte)laneIndex;
         item2.m_position.m_offset = offset;
         if (laneType != lane3.m_laneType)
         {
             item2.m_methodDistance = 0f;
         }
         else
         {
             item2.m_methodDistance = num6 + num2;
         }
         if (lane3.m_laneType != NetInfo.LaneType.Pedestrian || item2.m_methodDistance < 1000f)
         {
             item2.m_comparisonValue = num7 + num2 / ((num3 + lane3.m_speedLimit) * 0.25f * this.m_maxLength);
             if (lane == this.m_startLaneA)
             {
                 float num8 = this.CalculateLaneSpeed(this.m_startOffsetA, item2.m_position.m_offset, ref segment, lane3);
                 float num9 = (float)Mathf.Abs((int)(item2.m_position.m_offset - this.m_startOffsetA)) * 0.003921569f;
                 item2.m_comparisonValue += num9 * segment.m_averageLength / (num8 * this.m_maxLength);
             }
             if (lane == this.m_startLaneB)
             {
                 float num10 = this.CalculateLaneSpeed(this.m_startOffsetB, item2.m_position.m_offset, ref segment, lane3);
                 float num11 = (float)Mathf.Abs((int)(item2.m_position.m_offset - this.m_startOffsetB)) * 0.003921569f;
                 item2.m_comparisonValue += num11 * segment.m_averageLength / (num10 * this.m_maxLength);
             }
             if ((segment.m_flags & NetSegment.Flags.Invert) != NetSegment.Flags.None)
             {
                 item2.m_direction = NetInfo.InvertDirection(lane3.m_finalDirection);
             }
             else
             {
                 item2.m_direction = lane3.m_finalDirection;
             }
             item2.m_laneID = lane;
             item2.m_lanesUsed = (item.m_lanesUsed | lane3.m_laneType);
             this.AddBufferItem(item2, item.m_position);
         }
     }
 }
 private void ProcessItem3(CustomPathFind.BufferItem item, ushort targetNode, bool targetDisabled, ushort segmentID, ref NetSegment segment, uint lane, byte offset, byte connectOffset)
 {
     if ((segment.m_flags & (NetSegment.Flags.PathFailed | NetSegment.Flags.Flooded)) != NetSegment.Flags.None)
     {
         return;
     }
     NetManager instance = Singleton<NetManager>.instance;
     if (targetDisabled && ((instance.m_nodes.m_buffer[(int)segment.m_startNode].m_flags | instance.m_nodes.m_buffer[(int)segment.m_endNode].m_flags) & NetNode.Flags.Disabled) == NetNode.Flags.None)
     {
         return;
     }
     NetInfo info = segment.Info;
     NetInfo info2 = instance.m_segments.m_buffer[(int)item.m_position.m_segment].Info;
     int num = info.m_lanes.Length;
     uint num2 = segment.m_lanes;
     float num3 = 1f;
     float num4 = 1f;
     NetInfo.LaneType laneType = NetInfo.LaneType.None;
     if ((int)item.m_position.m_lane < info2.m_lanes.Length)
     {
         NetInfo.Lane lane2 = info2.m_lanes[(int)item.m_position.m_lane];
         num3 = lane2.m_speedLimit;
         laneType = lane2.m_laneType;
         num4 = this.CalculateLaneSpeed(connectOffset, item.m_position.m_offset, ref instance.m_segments.m_buffer[(int)item.m_position.m_segment], lane2);
     }
     float averageLength = instance.m_segments.m_buffer[(int)item.m_position.m_segment].m_averageLength;
     float num5 = (float)Mathf.Abs((int)(connectOffset - item.m_position.m_offset)) * 0.003921569f * averageLength;
     float num6 = item.m_methodDistance + num5;
     float num7 = item.m_comparisonValue + num5 / (num4 * this.m_maxLength);
     Vector3 b = instance.m_lanes.m_buffer[(int)((UIntPtr)item.m_laneID)].CalculatePosition((float)connectOffset * 0.003921569f);
     int num8 = 0;
     while (num8 < num && num2 != 0u)
     {
         if (lane == num2)
         {
             NetInfo.Lane lane3 = info.m_lanes[num8];
             if (lane3.CheckType(this.m_laneTypes, this.m_vehicleTypes))
             {
                 Vector3 a = instance.m_lanes.m_buffer[(int)((UIntPtr)lane)].CalculatePosition((float)offset * 0.003921569f);
                 float num9 = Vector3.Distance(a, b);
                 CustomPathFind.BufferItem item2;
                 item2.m_position.m_segment = segmentID;
                 item2.m_position.m_lane = (byte)num8;
                 item2.m_position.m_offset = offset;
                 if (laneType != lane3.m_laneType)
                 {
                     item2.m_methodDistance = 0f;
                 }
                 else
                 {
                     item2.m_methodDistance = num6 + num9;
                 }
                 if (lane3.m_laneType != NetInfo.LaneType.Pedestrian || item2.m_methodDistance < 1000f)
                 {
                     item2.m_comparisonValue = num7 + num9 / ((num3 + lane3.m_speedLimit) * 0.5f * this.m_maxLength);
                     if (lane == this.m_startLaneA)
                     {
                         float num10 = this.CalculateLaneSpeed(this.m_startOffsetA, item2.m_position.m_offset, ref segment, lane3);
                         float num11 = (float)Mathf.Abs((int)(item2.m_position.m_offset - this.m_startOffsetA)) * 0.003921569f;
                         item2.m_comparisonValue += num11 * segment.m_averageLength / (num10 * this.m_maxLength);
                     }
                     if (lane == this.m_startLaneB)
                     {
                         float num12 = this.CalculateLaneSpeed(this.m_startOffsetB, item2.m_position.m_offset, ref segment, lane3);
                         float num13 = (float)Mathf.Abs((int)(item2.m_position.m_offset - this.m_startOffsetB)) * 0.003921569f;
                         item2.m_comparisonValue += num13 * segment.m_averageLength / (num12 * this.m_maxLength);
                     }
                     if ((segment.m_flags & NetSegment.Flags.Invert) != NetSegment.Flags.None)
                     {
                         item2.m_direction = NetInfo.InvertDirection(lane3.m_finalDirection);
                     }
                     else
                     {
                         item2.m_direction = lane3.m_finalDirection;
                     }
                     item2.m_laneID = lane;
                     item2.m_lanesUsed = (item.m_lanesUsed | lane3.m_laneType);
                     this.AddBufferItem(item2, item.m_position);
                 }
             }
             return;
         }
         num2 = instance.m_lanes.m_buffer[(int)((UIntPtr)num2)].m_nextLane;
         num8++;
     }
 }