Ejemplo n.º 1
0
		// --- inherited functions ---
		
		/// <summary>Is called when the system should initialize.</summary>
		/// <param name="mode">The initialization mode.</param>
		internal override void Initialize(InitializationModes mode) {
			if (mode == InitializationModes.OffEmergency) {
				this.State = States.Suppressed;
			} else {
				this.State = States.Normal;
			}
		}
Ejemplo n.º 2
0
 internal override void BeginJump(InitializationModes mode)
 {
     try {
         Win32Initialize((int)mode);
     } catch (Exception ex) {
         base.LastException = ex;
         throw;
     }
 }
Ejemplo n.º 3
0
        /// <summary>Is called when the plugin should initialize or reinitialize.</summary>
        /// <param name="mode">The mode of initialization.</param>
        public void Initialize(InitializationModes mode)
        {
            handleManager = new TrainHandleManager(trainSpecs);

            closedSignalDevice = new ClosedSignal(soundManager,handleManager, cabControlManager);
            vacma = new Vacma(soundManager,handleManager, cabControlManager);
            speedControl = new KVB(soundManager,handleManager,cabControlManager);

            speedControl.setParameters(new Speed(33.33), 400, 0.8, TrainTypes.V);
        }
Ejemplo n.º 4
0
 public override void BeginJump(InitializationModes mode)
 {
     if (mode == InitializationModes.OffEmergency)
     {
         currentStep = 0;
         doorStart   = false;
     }
     else
     {
         currentStep = 100;
     }
 }
Ejemplo n.º 5
0
        // --- inherited functions ---

        /// <summary>Is called when the system should initialize.</summary>
        /// <param name="mode">The initialization mode.</param>
        internal override void Initialize(InitializationModes mode)
        {
            if (mode == InitializationModes.OffEmergency)
            {
                this.State = States.Suppressed;
            }
            else
            {
                this.State       = States.Ats;
                this.StateSwitch = true;
            }
        }
Ejemplo n.º 6
0
 public void BeginJump(InitializationModes mode)
 {
     try
     {
         Console.WriteLine(@"Starting jump with mode: " + mode);
         Win32Initialize((int)mode);
     }
     catch (Exception ex)
     {
         Callback.ReportError(ex.ToString());
     }
 }
Ejemplo n.º 7
0
 internal override void BeginJump(InitializationModes mode)
 {
     try
     {
         Win32Initialize((int)mode);
     }
     catch (Exception ex)
     {
         base.LastException = ex;
         throw;
     }
 }
Ejemplo n.º 8
0
        // --- functions ---
        public override bool Load(VehicleSpecs specs, InitializationModes mode)
        {
            LoadProperties properties = new LoadProperties(this.PluginFolder, this.TrainFolder, this.PlaySound, this.PlaySound, this.AddInterfaceMessage, this.AddScore);
            bool           success;

            try {
                success         = this.Api.Load(properties);
                base.SupportsAI = properties.AISupport == AISupport.Basic;
            } catch (Exception ex) {
                if (ex is ThreadStateException)
                {
                    //TTC plugin, broken when multi-threading is used
                    success = false;
                    properties.FailureReason = "This plugin does not function correctly with current versions of openBVE. Please ask the plugin developer to fix this.";
                }
                else
                {
                    success = false;
                    properties.FailureReason = ex.Message;
                }
            }
            if (success)
            {
                base.Panel = properties.Panel ?? new int[] { };
                                #if !DEBUG
                try {
                                        #endif
                Api.SetVehicleSpecs(specs);
                Api.Initialize(mode);
                                        #if !DEBUG
            }
            catch (Exception ex) {
                base.LastException = ex;
                throw;
            }
                                #endif
                UpdatePower();
                UpdateBrake();
                UpdateReverser();
                return(true);
            }
            else if (properties.FailureReason != null)
            {
                Interface.AddMessage(MessageType.Error, false, "The train plugin " + base.PluginTitle + " failed to load for the following reason: " + properties.FailureReason);
                return(false);
            }
            else
            {
                Interface.AddMessage(MessageType.Error, false, "The train plugin " + base.PluginTitle + " failed to load for an unspecified reason.");
                return(false);
            }
        }
Ejemplo n.º 9
0
 internal override void Initialize(InitializationModes mode)
 {
     if (numberofdrops > 0)
     {
         //Create arrays with number of drops
         droparray = new bool[numberofdrops];
     }
     else
     {
         Enabled = false;
     }
     currentwiperposition = (int)wiperholdposition;
 }
Ejemplo n.º 10
0
 internal override void BeginJump(InitializationModes mode)
 {
     #if !DEBUG
     try {
         #endif
         this.Api.Initialize(mode);
         #if !DEBUG
     } catch (Exception ex) {
         base.LastException = ex;
         throw;
     }
     #endif
 }
Ejemplo n.º 11
0
 internal override void BeginJump(InitializationModes mode)
 {
                 #if !DEBUG
     try {
                         #endif
     this.Api.Initialize(mode);
                         #if !DEBUG
 }
 catch (Exception ex) {
     base.LastException = ex;
     throw;
 }
                 #endif
 }
Ejemplo n.º 12
0
 // --- 継承された関数 ---
 /// <summary>
 /// ゲーム開始時に呼び出される関数
 /// </summary>
 /// <param name="mode">初期化モード</param>
 internal override void Initialize(InitializationModes mode)
 {
     ac_voltage_    = 25;
     cv_voltage_    = 100;
     digital_clock_ = new int[6];
     analog_clock_  = new int[3];
     current_list_  = new int[4];
     speedometer_   = new int[28];
     switch_        = new int[LoadSwitch.ALL_SWITCH];
     for (int i = 0; i < LoadSwitch.ALL_SWITCH; i++)
     {
         switch_[i] = LoadSwitch.switch_config_[i].switch_init_;
     }
 }
Ejemplo n.º 13
0
 internal void Reinitialise(InitializationModes mode)
 {
     this.osslastspeed       = 0;
     this.brakesappliedtimer = (int)this.brakesappliedtimeout;
     this.overridetimer      = (int)this.overridetimeout;
     this.tssndactive        = false;
     this.tssndlastlocation  = 0;
     this.tssodactive        = false;
     this.tssodlastlocation  = 0;
     this.ossndtimer         = 0;
     this.ossndtimeractive   = false;
     this.ossodtimer         = 0;
     this.ossodtimeractive   = false;
     this.MySafetyState      = SafetyStates.None;
 }
Ejemplo n.º 14
0
        // --- functions ---
        internal override bool Load(VehicleSpecs specs, InitializationModes mode)
        {
            LoadProperties properties = new LoadProperties(this.PluginFolder, this.TrainFolder, this.PlaySound, this.PlaySound, this.AddInterfaceMessage, this.AddScore);
            bool           success;

                        #if !DEBUG
            try {
                                #endif
            success         = this.Api.Load(properties);
            base.SupportsAI = properties.AISupport == AISupport.Basic;
                                #if !DEBUG
        }
        catch (Exception ex) {
            base.LastException = ex;
            throw;
        }
                        #endif
            if (success)
            {
                base.Panel = properties.Panel ?? new int[] { };
                                #if !DEBUG
                try {
                                        #endif
                Api.SetVehicleSpecs(specs);
                Api.Initialize(mode);
                                        #if !DEBUG
            }
            catch (Exception ex) {
                base.LastException = ex;
                throw;
            }
                                #endif
                UpdatePower();
                UpdateBrake();
                UpdateReverser();
                return(true);
            }
            else if (properties.FailureReason != null)
            {
                Interface.AddMessage(Interface.MessageType.Error, false, "The train plugin " + base.PluginTitle + " failed to load for the following reason: " + properties.FailureReason);
                return(false);
            }
            else
            {
                Interface.AddMessage(Interface.MessageType.Error, false, "The train plugin " + base.PluginTitle + " failed to load for an unspecified reason.");
                return(false);
            }
        }
Ejemplo n.º 15
0
        //<param name="mode">The initialization mode.</param>
        internal override void Initialize(InitializationModes mode)
        {
            //Load indicators default values

            //Initialise Default Paramaters
            beacon_speed    = 500;
            speed           = 500;
            alertspeed      = 500;
            beacon_type     = 44004;
            beacon_signal   = new SignalData(4, 0);
            beacon_44005    = 4;
            beacon_distance = 0;
            SCMT_Alert      = true;
            flagbrake       = false;
            tgtraz_active   = false;
        }
Ejemplo n.º 16
0
 public override void BeginJump(InitializationModes mode)
 {
     try
     {
         Win32Initialize((int)mode);
     }
     catch (Exception ex)
     {
         base.LastException = ex;
         throw;
     }
     if (SupportsAI == AISupport.Program)
     {
         AI.BeginJump(mode);
     }
 }
Ejemplo n.º 17
0
 public override bool Load(VehicleSpecs specs, InitializationModes mode)
 {
     if (externalCrashed)
     {
         //Most likely the plugin proxy app failed to launch or something
         return(false);
     }
     if (pipeProxy.Load(specs, mode))
     {
         UpdatePower();
         UpdateBrake();
         UpdateReverser();
         return(true);
     }
     return(false);
 }
Ejemplo n.º 18
0
        // --- inherited functions ---

        /// <summary>Is called when the system should initialize.</summary>
        /// <param name="mode">The initialization mode.</param>
        internal override void Initialize(InitializationModes mode)
        {
            if (mode == InitializationModes.OffEmergency)
            {
                this.State = States.Suppressed;
            }
            else
            {
                this.State = States.Standby;
            }
            foreach (Pattern pattern in this.Patterns)
            {
                if (Math.Abs(this.Train.State.Speed.MetersPerSecond) >= pattern.WarningPattern)
                {
                    pattern.Clear();
                }
            }
        }
Ejemplo n.º 19
0
 internal override void Initialize(InitializationModes mode)
 {
     if (mode != InitializationModes.OffEmergency)
     {
         this.State = AtsP.States.Standby;
     }
     else
     {
         this.State = AtsP.States.Suppressed;
     }
     AtsP.Pattern[] patterns = this.Patterns;
     for (int i = 0; i < (int)patterns.Length; i++)
     {
         AtsP.Pattern pattern = patterns[i];
         if (Math.Abs(this.Train.State.Speed.MetersPerSecond) >= pattern.WarningPattern)
         {
             pattern.Clear();
         }
     }
 }
Ejemplo n.º 20
0
		// --- functions ---
		internal override bool Load(VehicleSpecs specs, InitializationModes mode) {
			LoadProperties properties = new LoadProperties(this.PluginFolder, this.TrainFolder, this.PlaySound);
			bool success;
			#if !DEBUG
			try {
				#endif
				success = this.Api.Load(properties);
				base.SupportsAI = properties.AISupport == AISupport.Basic;
				#if !DEBUG
			} catch (Exception ex) {
				base.LastException = ex;
				throw;
			}
			#endif
			if (success) {
				base.Panel = properties.Panel ?? new int[] { };
				#if !DEBUG
				try {
					#endif
					Api.SetVehicleSpecs(specs);
					Api.Initialize(mode);
					#if !DEBUG
				} catch (Exception ex) {
					base.LastException = ex;
					throw;
				}
				#endif
				UpdatePower();
				UpdateBrake();
				UpdateReverser();
				return true;
			}
			if (properties.FailureReason != null) {
				Debug.AddMessage(Debug.MessageType.Error, false, "The train plugin " + base.PluginTitle + " failed to load for the following reason: " + properties.FailureReason);
				return false;
			}
			Debug.AddMessage(Debug.MessageType.Error, false, "The train plugin " + base.PluginTitle + " failed to load for an unspecified reason.");
			return false;
		}
Ejemplo n.º 21
0
        /// <summary>
        /// Logic performed during initialization of the application.
        /// </summary>
        /// <param name="mode">Mode indicates how this app instance is being run.</param>
        /// <returns>Awaitable task is returned.</returns>
        public override async Task AppInitializingAsync(InitializationModes mode)
        {
            // Call to base.AppInitializing is required to be executed first so all adapters and the framework are properly initialized
            await base.AppInitializingAsync(mode);

            // Your custom app logic which you want to always run at start of
            // your app should be placed here.

            if (this.ViewModel == null)
            {
                this.ViewModel = new MainViewModel();
            }

            if (mode == InitializationModes.New)
            {
                // Check for previous app crashes
                await Platform.Current.Logger.CheckForFatalErrorReportsAsync(this.ViewModel);

                // Check to see if the user should be prompted to rate the application
                await Platform.Current.Ratings.CheckForRatingsPromptAsync(this.ViewModel);
            }
        }
Ejemplo n.º 22
0
        //<param name="mode">The initialization mode.</param>
        internal override void Initialize(InitializationModes mode)
        {
            stm_reverser       = 0;
            stm_power          = 0;
            cutoff             = 30;
            cutoffstate        = 0;
            stm_boilerpressure = (int)boilermaxpressure;
            if (boilerstartwaterlevel == -1)
            {
                stm_boilerwater = (int)boilermaxwaterlevel;
            }
            else
            {
                stm_boilerwater = (int)boilerstartwaterlevel;
            }
            fuel             = (int)fuelstartamount;
            this.cutofftimer = 0.0;
            this.maintimer   = 0.0;

            InternalFunctions.ParseStringToIntArray(heatingrate, ref heatingarray, "heatingrate");

            //Calculate the water to steam rate and store it here, don't call every frame
            calculatedsteamrate = (int)boilerwatertosteamrate / 60;
            //Set the starting fire mass
            if (firestartmass == -1)
            {
                firemass = (int)maximumfiremass;
            }
            else
            {
                firemass = (int)firestartmass;
            }
            firetemp  = (int)firestartemp;
            LastPower = 0;
            if (Blowoff.BlowoffTime != 0)
            {
                Blowoff.BlowoffRate = (Blowoff.TriggerPressure - boilermaxpressure) / Blowoff.BlowoffTime;
            }
        }
Ejemplo n.º 23
0
 internal override void Initialize(InitializationModes mode)
 {
     if (Train.WesternDiesel != null)
     {
         Train.AWS.Enabled  = false;
         Train.TPWS.Enabled = false;
         return;
     }
     if (Train.AWS.Enabled == false && Train.TPWS.Enabled == false)
     {
         //Set to initialised if no AWS/ TPWS is installed
         MySequenceState          = SequenceStates.Initialised;
         SunflowerState           = AWS.SunflowerStates.Clear;
         AWS.startuphorntriggered = false;
     }
     else if (mode == InitializationModes.OnService)
     {
         MySequenceTimer          = SequenceDuration;
         MySequenceState          = SequenceStates.Initialised;
         SunflowerState           = AWS.SunflowerStates.Clear;
         AWS.startuphorntriggered = false;
         Train.MasterSwitch       = true;
     }
     else if (mode == InitializationModes.OnEmergency)
     {
         MySequenceTimer          = SequenceDuration;
         MySequenceState          = SequenceStates.Pending;
         SunflowerState           = AWS.SunflowerStates.Warn;
         AWS.startuphorntriggered = false;
     }
     else if (mode == InitializationModes.OffEmergency)
     {
         MySequenceTimer          = SequenceDuration;
         MySequenceState          = SequenceStates.Pending;
         SunflowerState           = AWS.SunflowerStates.Warn;
         AWS.startuphorntriggered = false;
     }
 }
Ejemplo n.º 24
0
        internal void Initialize(InitializationModes mode)
        {
            switch (mode)
            {
            case InitializationModes.OffEmergency:
                trainModeSelected = TrainModes.Off;
                break;

            case InitializationModes.OnEmergency:
                trainModeSelected = TrainModes.CodedManual;
                break;

            case InitializationModes.OnService:
                trainModeSelected = TrainModes.CodedManual;
                break;
            }
            trainModeActual = trainModeSelected;

            foreach (Device device in devices.Values)
            {
                device.Initialize(mode);
            }
        }
Ejemplo n.º 25
0
		// --- inherited functions ---
		
		/// <summary>Is called when the system should initialize.</summary>
		/// <param name="mode">The initialization mode.</param>
		internal override void Initialize(InitializationModes mode) {
			this.Counter = 0.0;
		}
Ejemplo n.º 26
0
        /// <summary>Loads the specified plugin for the specified train.</summary>
        /// <param name="train">The train to attach the plugin to.</param>
        /// <param name="pluginFile">The file to the plugin.</param>
        /// <param name="trainFolder">The train folder.</param>
        /// <returns>Whether the plugin was loaded successfully.</returns>
        private static bool LoadPlugin(TrainManager.Train train, string pluginFile, string trainFolder)
        {
            string pluginTitle = System.IO.Path.GetFileName(pluginFile);

            if (!System.IO.File.Exists(pluginFile))
            {
                Interface.AddMessage(MessageType.Error, true, "The train plugin " + pluginTitle + " could not be found.");
                return(false);
            }

            /*
             * Unload plugin if already loaded.
             * */
            if (train.Plugin != null)
            {
                UnloadPlugin(train);
            }

            /*
             * Prepare initialization data for the plugin.
             * */
            BrakeTypes brakeType = (BrakeTypes)train.Cars[train.DriverCar].CarBrake.brakeType;
            int        brakeNotches;
            int        powerNotches;
            bool       hasHoldBrake;

            if (brakeType == BrakeTypes.AutomaticAirBrake)
            {
                brakeNotches = 2;
                powerNotches = train.Handles.Power.MaximumNotch;
                hasHoldBrake = false;
            }
            else
            {
                brakeNotches = train.Handles.Brake.MaximumNotch + (train.Handles.HasHoldBrake ? 1 : 0);
                powerNotches = train.Handles.Power.MaximumNotch;
                hasHoldBrake = train.Handles.HasHoldBrake;
            }

            bool                hasLocoBrake = train.Handles.HasLocoBrake;
            int                 cars         = train.Cars.Length;
            VehicleSpecs        specs        = new VehicleSpecs(powerNotches, brakeType, brakeNotches, hasHoldBrake, hasLocoBrake, cars);
            InitializationModes mode         = (InitializationModes)Game.TrainStart;

            /*
             * Check if the plugin is a .NET plugin.
             * */
            Assembly assembly;

            try
            {
                assembly = Assembly.LoadFile(pluginFile);
            }
            catch (BadImageFormatException)
            {
                assembly = null;
            }
            catch (Exception ex)
            {
                Interface.AddMessage(MessageType.Error, false, "The train plugin " + pluginTitle + " could not be loaded due to the following exception: " + ex.Message);
                return(false);
            }
            if (assembly != null)
            {
                Type[] types;
                try
                {
                    types = assembly.GetTypes();
                }
                catch (ReflectionTypeLoadException ex)
                {
                    foreach (Exception e in ex.LoaderExceptions)
                    {
                        Interface.AddMessage(MessageType.Error, false, "The train plugin " + pluginTitle + " raised an exception on loading: " + e.Message);
                    }
                    return(false);
                }
                foreach (Type type in types)
                {
                    if (typeof(IRuntime).IsAssignableFrom(type))
                    {
                        if (type.FullName == null)
                        {
                            //Should never happen, but static code inspection suggests that it's possible....
                            throw new InvalidOperationException();
                        }
                        IRuntime api = assembly.CreateInstance(type.FullName) as IRuntime;
                        train.Plugin = new NetPlugin(pluginFile, trainFolder, api, train);
                        if (train.Plugin.Load(specs, mode))
                        {
                            return(true);
                        }
                        else
                        {
                            train.Plugin = null;
                            return(false);
                        }
                    }
                }
                Interface.AddMessage(MessageType.Error, false, "The train plugin " + pluginTitle + " does not export a train interface and therefore cannot be used with openBVE.");
                return(false);
            }

            /*
             * Check if the plugin is a Win32 plugin.
             *
             */
            try
            {
                if (!CheckWin32Header(pluginFile))
                {
                    Interface.AddMessage(MessageType.Error, false, "The train plugin " + pluginTitle + " is of an unsupported binary format and therefore cannot be used with openBVE.");
                    return(false);
                }
            }
            catch (Exception ex)
            {
                Interface.AddMessage(MessageType.Error, false, "The train plugin " + pluginTitle + " could not be read due to the following reason: " + ex.Message);
                return(false);
            }
            if (!Program.CurrentlyRunningOnWindows | IntPtr.Size != 4)
            {
                Interface.AddMessage(MessageType.Warning, false, "The train plugin " + pluginTitle + " can only be used on 32-bit Microsoft Windows or compatible.");
                return(false);
            }
            if (Program.CurrentlyRunningOnWindows && !System.IO.File.Exists(AppDomain.CurrentDomain.BaseDirectory + "\\AtsPluginProxy.dll"))
            {
                Interface.AddMessage(MessageType.Warning, false, "AtsPluginProxy.dll is missing or corrupt- Please reinstall.");
                return(false);
            }
            train.Plugin = new Win32Plugin(pluginFile, train);
            if (train.Plugin.Load(specs, mode))
            {
                return(true);
            }
            else
            {
                train.Plugin = null;
                Interface.AddMessage(MessageType.Error, false, "The train plugin " + pluginTitle + " does not export a train interface and therefore cannot be used with openBVE.");
                return(false);
            }
        }
Ejemplo n.º 27
0
 internal override void Initialize(InitializationModes mode)
 {
 }
Ejemplo n.º 28
0
        internal void Initialize(InitializationModes mode)
        {
            trainFail = false;
            switch (mode) {
                case InitializationModes.OnService:
            //					handleReverser = 1;
                    handlePower = 0;
                    handleBrake = vSpec.BrakeNotches;
                    break;
                case InitializationModes.OnEmergency:
            //					handleReverser = 1;
                    handlePower = 0;
                    handleBrake = vSpec.BrakeNotches + 1;
                    break;
                case InitializationModes.OffEmergency:
            //					handleReverser = 0;
                    handlePower = 0;
                    handleBrake = vSpec.BrakeNotches + 1;
                    break;
            }

            //			handlePower = driverSetPower;
            //			handleBrake = driverSetBrake;
        }
Ejemplo n.º 29
0
 /// <summary>Called before the train jumps to a different location.</summary>
 /// <param name="mode">The initialization mode of the train.</param>
 internal abstract void BeginJump(InitializationModes mode);
Ejemplo n.º 30
0
 /// <summary>ゲーム開始時に呼び出される関数</summary>
 /// <param name="mode">初期化モード</param>
 public void Initialize(InitializationModes mode)
 {
     this.Train.Initialize(mode);
 }
Ejemplo n.º 31
0
        // --- inherited functions ---

        /// <summary>Is called when the system should initialize.</summary>
        /// <param name="mode">The initialization mode.</param>
        internal override void Initialize(InitializationModes mode)
        {
            this.State = mode == InitializationModes.OffEmergency ? States.Suppressed : States.Normal;
        }
Ejemplo n.º 32
0
        internal void Initialize(InitializationModes mode)
        {
            switch(mode)
            {
                case InitializationModes.OffEmergency:
                    trainModeSelected = TrainModes.Off;
                    break;
                case InitializationModes.OnEmergency:
                    trainModeSelected = TrainModes.CodedManual;
                    break;
                case InitializationModes.OnService:
                    trainModeSelected = TrainModes.CodedManual;
                    break;
            }
            trainModeActual = trainModeSelected;

            foreach(Device device in devices.Values)
            {
                device.Initialize(mode);
            }
        }
Ejemplo n.º 33
0
        /// <summary>
        /// Logic performed during initialization of the application.
        /// </summary>
        /// <param name="mode">Mode indicates how this app instance is being run.</param>
        /// <returns>Awaitable task is returned.</returns>
        public override async Task AppInitializingAsync(InitializationModes mode)
        {
            // Call to base.AppInitializing is required to be executed first so all adapters and the framework are properly initialized
            await base.AppInitializingAsync(mode);

            // Your custom app logic which you want to always run at start of
            // your app should be placed here.

            if (this.ViewModel == null)
                this.ViewModel = new MainViewModel();

            if (mode == InitializationModes.New)
            {
                // Check for previous app crashes
                await Platform.Current.Logger.CheckForFatalErrorReportsAsync(this.ViewModel);

                // Check to see if the user should be prompted to rate the application
                await Platform.Current.Ratings.CheckForRatingsPromptAsync(this.ViewModel);
            }
        }
Ejemplo n.º 34
0
 /// <summary>Is called when the plugin should initialize or reinitialize.</summary>
 /// <param name="mode">The mode of initialization.</param>
 public void Initialize(InitializationModes mode)
 {
 }
Ejemplo n.º 35
0
 /// <summary>Is called when the plugin should initialize or reinitialize.</summary>
 /// <param name="mode">The mode of initialization.</param>
 public void Initialize(InitializationModes mode)
 {
     ms.Initialize(mode);
     tims.Initialise(mode);
 }
Ejemplo n.º 36
0
 /// <summary>Is called when the device should initialize.</summary>
 /// <param name="mode">The initialization mode.</param>
 internal abstract void Initialize(InitializationModes mode);
Ejemplo n.º 37
0
 internal void Initialise(InitializationModes mode)
 {
 }
Ejemplo n.º 38
0
        // --- functions ---
        internal override bool Load(VehicleSpecs specs, InitializationModes mode)
        {
            int  result;
            bool retry = true;

retryLoad:
            try {
                result = Win32LoadDLL(this.PluginFile, this.PluginFile);
            } catch (Exception ex) {
                base.LastException = ex;
                throw;
            }
            if (result == 0)
            {
                if (retry)
                {
                    /*
                     * Win32 plugin loading is unreliable on some systems
                     * Unable to reproduce this, but let's try a sleep & single retry attempt
                     */
                    Thread.Sleep(100);
                    retry = false;
                    goto retryLoad;
                }
                int    errorCode    = Marshal.GetLastWin32Error();
                string errorMessage = new Win32Exception(errorCode).Message;
                Interface.AddMessage(MessageType.Error, true,
                                     String.Format("Error loading Win32 plugin: {0} (0x{1})", errorMessage, errorCode.ToString("x")));
                return(false);
            }
            try {
                Win32Load();
            } catch (Exception ex) {
                base.LastException = ex;
                throw;
            }
            int version;

            try {
                version = Win32GetPluginVersion();
            } catch (Exception ex) {
                base.LastException = ex;
                throw;
            }
            if (version != 131072)
            {
                Interface.AddMessage(MessageType.Error, false, "The train plugin " + base.PluginTitle + " is of an unsupported version.");
                try {
                    Win32Dispose();
                } catch (Exception ex) {
                    base.LastException = ex;
                    throw;
                }
                Win32UnloadDLL();
                return(false);
            }
            try {
                Win32VehicleSpec win32Spec;
                win32Spec.BrakeNotches = specs.BrakeNotches;
                win32Spec.PowerNotches = specs.PowerNotches;
                win32Spec.AtsNotch     = specs.AtsNotch;
                win32Spec.B67Notch     = specs.B67Notch;
                win32Spec.Cars         = specs.Cars;
                Win32SetVehicleSpec(ref win32Spec.BrakeNotches);
            } catch (Exception ex) {
                base.LastException = ex;
                throw;
            }
            try {
                Win32Initialize((int)mode);
            } catch (Exception ex) {
                base.LastException = ex;
                throw;
            }
            UpdatePower();
            UpdateBrake();
            UpdateReverser();
            if (PanelHandle.IsAllocated)
            {
                PanelHandle.Free();
            }
            if (SoundHandle.IsAllocated)
            {
                SoundHandle.Free();
            }
            PanelHandle = GCHandle.Alloc(Panel, GCHandleType.Pinned);
            SoundHandle = GCHandle.Alloc(Sound, GCHandleType.Pinned);
            return(true);
        }
Ejemplo n.º 39
0
		/// <summary>Is called when the system should initialize.</summary>
		/// <param name="mode">The initialization mode.</param>
		internal void Initialize(InitializationModes mode) {
			this.PluginInitializing = true;
			for (int i = this.Devices.Length - 1; i >= 0; i--) {
				this.Devices[i].Initialize(mode);
			}
		}
Ejemplo n.º 40
0
 /// <summary>
 /// ゲーム開始時に呼び出される関数
 /// </summary>
 /// <param name="mode">初期化モード</param>
 internal abstract void Initialize(InitializationModes mode);
Ejemplo n.º 41
0
 // --- inherited functions ---
 /// <summary>Is called when the system should initialize.</summary>
 /// <param name="mode">The initialization mode.</param>
 internal override void Initialize(InitializationModes mode)
 {
     if (mode == InitializationModes.OffEmergency) {
         this.State = States.Suppressed;
     } else {
         this.State = States.Ats;
         this.StateSwitch = true;
     }
 }
Ejemplo n.º 42
0
		/// <summary>Is called when the plugin should initialize or reinitialize.</summary>
		/// <param name="mode">The mode of initialization.</param>
		public void Initialize(InitializationModes mode) {
			// TODO: Your old Initialize code goes here.
		}
Ejemplo n.º 43
0
 /// <summary>
 /// Logic performed during initialization of the application.
 /// </summary>
 /// <param name="mode">Mode indicates how this app instance is being run.</param>
 /// <returns>Awaitable task is returned.</returns>
 protected override Task OnAppInitializingAsync(InitializationModes mode)
 {
     // Your custom app logic which you want to run on launch of
     // your app should be placed here.
     return(Task.CompletedTask);
 }
Ejemplo n.º 44
0
			/// <summary>Called before the train jumps to a different location.</summary>
			/// <param name="mode">The initialization mode of the train.</param>
			internal abstract void BeginJump(InitializationModes mode);
Ejemplo n.º 45
0
 internal override void Initialize(InitializationModes mode)
 {
 }
Ejemplo n.º 46
0
 // --- inherited functions ---
 /// <summary>Is called when the system should initialize.</summary>
 /// <param name="mode">The initialization mode.</param>
 internal override void Initialize(InitializationModes mode)
 {
     if (mode == InitializationModes.OffEmergency) {
         this.State = States.Suppressed;
     } else {
         this.State = States.Standby;
     }
     foreach (Pattern pattern in this.Patterns) {
         if (Math.Abs(this.Train.State.Speed.MetersPerSecond) >= pattern.WarningPattern) {
             pattern.Clear();
         }
     }
 }
Ejemplo n.º 47
0
			// --- functions ---
			/// <summary>Called to load and initialize the plugin.</summary>
			/// <param name="specs">The train specifications.</param>
			/// <param name="mode">The initialization mode of the train.</param>
			/// <returns>Whether loading the plugin was successful.</returns>
			internal abstract bool Load(VehicleSpecs specs, InitializationModes mode);
Ejemplo n.º 48
0
 // --- functions ---
 /// <summary>Called to load and initialize the plugin.</summary>
 /// <param name="specs">The train specifications.</param>
 /// <param name="mode">The initialization mode of the train.</param>
 /// <returns>Whether loading the plugin was successful.</returns>
 internal abstract bool Load(VehicleSpecs specs, InitializationModes mode);
Ejemplo n.º 49
0
		// --- inherited functions ---
		
		/// <summary>Is called when the system should initialize.</summary>
		/// <param name="mode">The initialization mode.</param>
		internal override void Initialize(InitializationModes mode)
		{
			this.State = mode == InitializationModes.OffEmergency ? States.Suppressed : States.Normal;
		}
Ejemplo n.º 50
0
		// --- functions ---
		internal override bool Load(VehicleSpecs specs, InitializationModes mode) {
			int result;
			try {
				result = Win32LoadDLL(this.PluginFile, this.PluginFile);
			} catch (Exception ex) {
				base.LastException = ex;
				throw;
			}
			if (result == 0) {
				return false;
			}
			try {
				Win32Load();
			} catch (Exception ex) {
				base.LastException = ex;
				throw;
			}
			int version;
			try {
				version = Win32GetPluginVersion();
			} catch (Exception ex) {
				base.LastException = ex;
				throw;
			}
			if (version != 131072) {
				Debug.AddMessage(Debug.MessageType.Error, false, "The train plugin " + base.PluginTitle + " is of an unsupported version.");
				try {
					Win32Dispose();
				} catch (Exception ex) {
					base.LastException = ex;
					throw;
				}
				Win32UnloadDLL();
				return false;
			}
			try {
				Win32VehicleSpec win32Spec;
				win32Spec.BrakeNotches = specs.BrakeNotches;
				win32Spec.PowerNotches = specs.PowerNotches;
				win32Spec.AtsNotch = specs.AtsNotch;
				win32Spec.B67Notch = specs.B67Notch;
				win32Spec.Cars = specs.Cars;
				Win32SetVehicleSpec(ref win32Spec.BrakeNotches);
			} catch (Exception ex) {
				base.LastException = ex;
				throw;
			}
			try {
				Win32Initialize((int)mode);
			} catch (Exception ex) {
				base.LastException = ex;
				throw;
			}
			UpdatePower();
			UpdateBrake();
			UpdateReverser();
			if (PanelHandle.IsAllocated) {
				PanelHandle.Free();
			}
			if (SoundHandle.IsAllocated) {
				SoundHandle.Free();
			}
			PanelHandle = GCHandle.Alloc(Panel, GCHandleType.Pinned);
			SoundHandle = GCHandle.Alloc(Sound, GCHandleType.Pinned);
			return true;
		}
Ejemplo n.º 51
0
        /// <summary>Loads the specified plugin for the specified train.</summary>
        /// <param name="pluginFile">The file to the plugin.</param>
        /// <param name="trainFolder">The train folder.</param>
        /// <returns>Whether the plugin was loaded successfully.</returns>
        public bool LoadPlugin(string pluginFile, string trainFolder)
        {
            string pluginTitle = System.IO.Path.GetFileName(pluginFile);

            if (!System.IO.File.Exists(pluginFile))
            {
                TrainManagerBase.currentHost.AddMessage(MessageType.Error, true, "The train plugin " + pluginTitle + " could not be found.");
                return(false);
            }

            /*
             * Unload plugin if already loaded.
             * */
            if (Plugin != null)
            {
                UnloadPlugin();
            }

            /*
             * Prepare initialization data for the plugin.
             * */

            InitializationModes mode = (InitializationModes)TrainManagerBase.CurrentOptions.TrainStart;

            /*
             * Check if the plugin is a .NET plugin.
             * */
            Assembly assembly;

            try
            {
                assembly = Assembly.LoadFile(pluginFile);
            }
            catch (BadImageFormatException)
            {
                assembly = null;
                try
                {
                    AssemblyName myAssembly = AssemblyName.GetAssemblyName(pluginFile);
                    if (IntPtr.Size != 4 && myAssembly.ProcessorArchitecture == ProcessorArchitecture.X86)
                    {
                        TrainManagerBase.currentHost.AddMessage(MessageType.Error, false, "The train plugin " + pluginTitle + " can only be used with the 32-bit version of OpenBVE");
                        return(false);
                    }
                }
                catch
                {
                    //ignored
                }
            }
            catch (Exception ex)
            {
                TrainManagerBase.currentHost.AddMessage(MessageType.Error, false, "The train plugin " + pluginTitle + " could not be loaded due to the following exception: " + ex.Message);
                return(false);
            }

            if (assembly != null)
            {
                Type[] types;
                try
                {
                    types = assembly.GetTypes();
                }
                catch (ReflectionTypeLoadException ex)
                {
                    foreach (Exception e in ex.LoaderExceptions)
                    {
                        TrainManagerBase.currentHost.AddMessage(MessageType.Error, false, "The train plugin " + pluginTitle + " raised an exception on loading: " + e.Message);
                    }

                    return(false);
                }

                foreach (Type type in types)
                {
                    if (typeof(IRuntime).IsAssignableFrom(type))
                    {
                        if (type.FullName == null)
                        {
                            //Should never happen, but static code inspection suggests that it's possible....
                            throw new InvalidOperationException();
                        }

                        IRuntime api = assembly.CreateInstance(type.FullName) as IRuntime;
                        Plugin = new NetPlugin(pluginFile, trainFolder, api, this);
                        if (Plugin.Load(vehicleSpecs(), mode))
                        {
                            return(true);
                        }
                        else
                        {
                            Plugin = null;
                            return(false);
                        }
                    }
                }

                TrainManagerBase.currentHost.AddMessage(MessageType.Error, false, "The train plugin " + pluginTitle + " does not export a train interface and therefore cannot be used with openBVE.");
                return(false);
            }

            /*
             * Check if the plugin is a Win32 plugin.
             *
             */
            try
            {
                if (!Win32Plugin.CheckHeader(pluginFile))
                {
                    TrainManagerBase.currentHost.AddMessage(MessageType.Error, false, "The train plugin " + pluginTitle + " is of an unsupported binary format and therefore cannot be used with openBVE.");
                    return(false);
                }
            }
            catch (Exception ex)
            {
                TrainManagerBase.currentHost.AddMessage(MessageType.Error, false, "The train plugin " + pluginTitle + " could not be read due to the following reason: " + ex.Message);
                return(false);
            }

            if (TrainManagerBase.currentHost.Platform != HostPlatform.MicrosoftWindows | IntPtr.Size != 4)
            {
                if (TrainManagerBase.currentHost.Platform == HostPlatform.MicrosoftWindows && IntPtr.Size != 4)
                {
                    //We can't load the plugin directly on x64 Windows, so use the proxy interface
                    Plugin = new ProxyPlugin(pluginFile, this);
                    if (Plugin.Load(vehicleSpecs(), mode))
                    {
                        return(true);
                    }

                    Plugin = null;
                    TrainManagerBase.currentHost.AddMessage(MessageType.Error, false, "The train plugin " + pluginTitle + " failed to load.");
                    return(false);
                }

                //WINE doesn't seem to like the WCF proxy :(
                TrainManagerBase.currentHost.AddMessage(MessageType.Warning, false, "The train plugin " + pluginTitle + " can only be used on Microsoft Windows or compatible.");
                return(false);
            }

            if (TrainManagerBase.currentHost.Platform == HostPlatform.MicrosoftWindows && !System.IO.File.Exists(AppDomain.CurrentDomain.BaseDirectory + "\\AtsPluginProxy.dll"))
            {
                TrainManagerBase.currentHost.AddMessage(MessageType.Warning, false, "AtsPluginProxy.dll is missing or corrupt- Please reinstall.");
                return(false);
            }

            Plugin = new Win32Plugin(pluginFile, this);
            if (Plugin.Load(vehicleSpecs(), mode))
            {
                return(true);
            }
            else
            {
                Plugin = null;
                TrainManagerBase.currentHost.AddMessage(MessageType.Error, false, "The train plugin " + pluginTitle + " does not export a train interface and therefore cannot be used with openBVE.");
                return(false);
            }
        }
Ejemplo n.º 52
0
		/// <summary>Is called when the plugin should initialize or reinitialize.</summary>
		/// <param name="mode">The mode of initialization.</param>
		public void Initialize(InitializationModes mode) {
			this.Train.Initialize(mode);
		}
Ejemplo n.º 53
0
        // --- inherited functions ---

        /// <summary>Is called when the system should initialize.</summary>
        /// <param name="mode">The initialization mode.</param>
        internal override void Initialize(InitializationModes mode)
        {
            this.Counter = 0.0;
        }
Ejemplo n.º 54
0
		// --- functions ---
		internal override bool Load(VehicleSpecs specs, InitializationModes mode) {
			int result;
			try {
				result = Win32LoadDLL(this.PluginFile, this.PluginFile);
			} catch (Exception ex) {
				base.LastException = ex;
				throw;
			}
			if (result == 0) {
				int errorCode = Marshal.GetLastWin32Error();
				string errorMessage = new Win32Exception(errorCode).Message;
				Interface.AddMessage(Interface.MessageType.Error, true,
					String.Format("Error loading Win32 plugin: {0} (0x{1})", errorMessage, errorCode.ToString("x")));
				return false;
			}
			try {
				Win32Load();
			} catch (Exception ex) {
				base.LastException = ex;
				throw;
			}
			int version;
			try {
				version = Win32GetPluginVersion();
			} catch (Exception ex) {
				base.LastException = ex;
				throw;
			}
			if (version != 131072) {
				Interface.AddMessage(Interface.MessageType.Error, false, "The train plugin " + base.PluginTitle + " is of an unsupported version.");
				try {
					Win32Dispose();
				} catch (Exception ex) {
					base.LastException = ex;
					throw;
				}
				Win32UnloadDLL();
				return false;
			}
			try {
				Win32VehicleSpec win32Spec;
				win32Spec.BrakeNotches = specs.BrakeNotches;
				win32Spec.PowerNotches = specs.PowerNotches;
				win32Spec.AtsNotch = specs.AtsNotch;
				win32Spec.B67Notch = specs.B67Notch;
				win32Spec.Cars = specs.Cars;
				Win32SetVehicleSpec(ref win32Spec.BrakeNotches);
			} catch (Exception ex) {
				base.LastException = ex;
				throw;
			}
			try {
				Win32Initialize((int)mode);
			} catch (Exception ex) {
				base.LastException = ex;
				throw;
			}
			UpdatePower();
			UpdateBrake();
			UpdateReverser();
			if (PanelHandle.IsAllocated) {
				PanelHandle.Free();
			}
			if (SoundHandle.IsAllocated) {
				SoundHandle.Free();
			}
			PanelHandle = GCHandle.Alloc(Panel, GCHandleType.Pinned);
			SoundHandle = GCHandle.Alloc(Sound, GCHandleType.Pinned);
			return true;
		}