internal PassengerCarAIConnection(FindParkingSpaceDelegate findParkingSpaceDelegate,
                                   FindParkingSpacePropDelegate findParkingSpacePropDelegate,
                                   FindParkingSpaceRoadSideDelegate findParkingSpaceRoadSideDelegate,
                                   GetDriverInstanceDelegate getDriverInstanceDelegate)
 {
     FindParkingSpace         = findParkingSpaceDelegate ?? throw new ArgumentNullException(nameof(findParkingSpaceDelegate));
     FindParkingSpaceProp     = findParkingSpacePropDelegate ?? throw new ArgumentNullException(nameof(findParkingSpacePropDelegate));
     FindParkingSpaceRoadSide = findParkingSpaceRoadSideDelegate ?? throw new ArgumentNullException(nameof(findParkingSpaceRoadSideDelegate));
     GetDriverInstance        = getDriverInstanceDelegate ?? throw new ArgumentNullException(nameof(getDriverInstanceDelegate));
 }
Example #2
0
        /// <summary>Updates the origin building display.</summary>
        /// <param name="instance">The game object instance to get the information from.</param>
        public override void UpdateCustomInfo(ref InstanceID instance)
        {
            ushort instanceId = 0;

            try
            {
                if (passengerCarAIGetDriverInstance == null || bicycleAIGetDriverInstance == null)
                {
                    return;
                }

                if (instance.Type != InstanceType.Vehicle || instance.Vehicle == 0)
                {
                    return;
                }

                ushort vehicleId = instance.Vehicle;
                vehicleId = VehicleManager.instance.m_vehicles.m_buffer[vehicleId].GetFirstVehicle(vehicleId);
                if (vehicleId == 0)
                {
                    return;
                }

                var vehicleInfo = VehicleManager.instance.m_vehicles.m_buffer[vehicleId].Info;

                try
                {
                    switch (vehicleInfo.m_vehicleAI)
                    {
                    case BicycleAI bicycleAI:
                        instanceId = bicycleAIGetDriverInstance(bicycleAI, vehicleId, ref VehicleManager.instance.m_vehicles.m_buffer[vehicleId]);
                        break;

                    case PassengerCarAI passengerCarAI:
                        instanceId = passengerCarAIGetDriverInstance(passengerCarAI, vehicleId, ref VehicleManager.instance.m_vehicles.m_buffer[vehicleId]);
                        break;

                    default:
                        return;
                    }
                }
                catch
                {
                    passengerCarAIGetDriverInstance = null;
                    bicycleAIGetDriverInstance      = null;
                }
            }
            finally
            {
                uint citizenId = instanceId == 0
                    ? 0u
                    : CitizenManager.instance.m_instances.m_buffer[instanceId].m_citizen;
                UpdateCitizenInfo(citizenId);
            }
        }
Example #3
0
 private CustomVehicleInfoPanel(string panelName)
     : base(panelName)
 {
     try
     {
         passengerCarAIGetDriverInstance = FastDelegate.Create <PassengerCarAI, GetDriverInstanceDelegate <PassengerCarAI> >(GetDriverInstanceMethodName);
         bicycleAIGetDriverInstance      = FastDelegate.Create <BicycleAI, GetDriverInstanceDelegate <BicycleAI> >(GetDriverInstanceMethodName);
     }
     catch (Exception ex)
     {
         Debug.LogError($"The 'Snooper' mod failed to obtain at least one of the GetDriverInstance methods. Error message: " + ex);
     }
 }
Example #4
0
        private CustomVehicleInfoPanel(string panelName, RealTimeResidentAI <ResidentAI, Citizen> residentAI, ILocalizationProvider localizationProvider)
            : base(panelName, residentAI, localizationProvider)
        {
            try
            {
                passengerCarAIGetDriverInstance = FastDelegateFactory.Create <GetDriverInstanceDelegate <PassengerCarAI> >(
                    typeof(PassengerCarAI),
                    GetDriverInstanceMethodName,
                    true);

                bicycleAIGetDriverInstance = FastDelegateFactory.Create <GetDriverInstanceDelegate <BicycleAI> >(
                    typeof(BicycleAI),
                    GetDriverInstanceMethodName,
                    true);
            }
            catch (Exception ex)
            {
                Debug.LogError("The 'Real Time' mod failed to obtain at least one of the GetDriverInstance methods. Error message: " + ex);
            }
        }
        internal static PassengerCarAIConnection GetConnection()
        {
            try {
                FindParkingSpaceDelegate findParkingSpaceDelegate =
                    AccessTools.MethodDelegate <FindParkingSpaceDelegate>(TargetMethod());
                FindParkingSpacePropDelegate findParkingSpacePropDelegate =
                    AccessTools.MethodDelegate <FindParkingSpacePropDelegate>(TargetMethodProp());
                FindParkingSpaceRoadSideDelegate findParkingSpaceRoadSideDelegate =
                    AccessTools.MethodDelegate <FindParkingSpaceRoadSideDelegate>(TargetMethodRoadSide());
                GetDriverInstanceDelegate getDriverInstanceDelegate =
                    TranspilerUtil.CreateDelegate <GetDriverInstanceDelegate>(typeof(PassengerCarAI), "GetDriverInstance", true);

                return(new PassengerCarAIConnection(findParkingSpaceDelegate,
                                                    findParkingSpacePropDelegate,
                                                    findParkingSpaceRoadSideDelegate,
                                                    getDriverInstanceDelegate));
            } catch (Exception e) {
                Log.Error(e.Message);
                return(null);
            }
        }
Example #6
0
 public static void Prepare()
 {
     GetDriverInstance = GameConnectionManager.Instance.PassengerCarAIConnection.GetDriverInstance;
 }