static IEnumerable <CodeInstruction> Transpiler(
            IEnumerable <CodeInstruction> instructions)
        {
            int n = 0;

            foreach (var code in instructions)
            {
                //if(code.Calls(mset_atlas) || code.Calls(mset_spriteName)) {
                //    yield return new CodeInstruction(OpCodes.Pop);// pop value
                //    yield return new CodeInstruction(OpCodes.Pop);// pop instance
                //} else
                if (code.opcode == OpCodes.Rem)
                {
                    n++;
                    yield return(new CodeInstruction(OpCodes.Pop));

                    yield return(new CodeInstruction(OpCodes.Ldc_I4, 100));

                    yield return(code);
                }
                else
                {
                    yield return(code);
                }
            }
            Assertion.AssertEqual(n, 2);
        }
Пример #2
0
        public static byte[] ReadToEnd(this Stream s)
        {
            int n    = (int)(s.Length - s.Position);
            var data = new byte[n];
            int n2   = s.Read(data, 0, n);

            Assertion.AssertEqual(n, n2);
            return(data);
        }
Пример #3
0
        // pass in segmentID for the sake of MOM lane problem.
        public void UpdateLane(LaneData lane, ushort segmentID)
        {
            Assertion.AssertEqual(LaneData.LaneID, lane.LaneID, "lane id");
            if (lane.Lane.m_segment != 0 && lane.Lane.m_segment != segmentID)
            {
                Log.Error($"lane segment mismatch: {LaneData} parentSegment:{segmentID}");
            }
            lane.Lane.m_segment = segmentID; // fix MOM lane issue

            try {
                LaneData = lane;

                bool parkingAllowed = LaneData.LaneInfo.m_laneType == NetInfo.LaneType.Parking;
                if (PMan != null)
                {
                    parkingAllowed &= PMan.IsParkingAllowed(LaneData.SegmentID, LaneData.LaneInfo.m_finalDirection);
                }
                m_flags = m_flags.SetFlags(Flags.ParkingAllowed, parkingAllowed);

                ExtVehicleType mask = 0;
                if (VRMan != null)
                {
                    mask = VRMan.GetAllowedVehicleTypes(
                        segmentId: segmentID,
                        segmentInfo: segmentID.ToSegment().Info,
                        laneIndex: (uint)LaneData.LaneIndex,
                        laneInfo: LaneData.LaneInfo,
                        busLaneMode: VehicleRestrictionsMode.Configured);
                }

                m_flags = m_flags.SetFlags(Flags.Car, VRMan.IsPassengerCarAllowed(mask));
                m_flags = m_flags.SetFlags(Flags.SOS, VRMan.IsEmergencyAllowed(mask));
                m_flags = m_flags.SetFlags(Flags.Bus, VRMan.IsBusAllowed(mask));
                m_flags = m_flags.SetFlags(Flags.CargoTruck, VRMan.IsCargoTruckAllowed(mask));
                m_flags = m_flags.SetFlags(Flags.Taxi, VRMan.IsTaxiAllowed(mask));
                m_flags = m_flags.SetFlags(Flags.Service, VRMan.IsServiceAllowed(mask));
                m_flags = m_flags.SetFlags(Flags.CargoTrain, VRMan.IsCargoTrainAllowed(mask));
                m_flags = m_flags.SetFlags(Flags.PassengerTrain, VRMan.IsPassengerTrainAllowed(mask));

                if (SLMan != null)
                {
                    SpeedLimit = (SLMan as SpeedLimitManager).GetGameSpeedLimit(LaneData.LaneID);
                }
                else
                {
                    SpeedLimit = lane.LaneInfo.m_speedLimit;
                }

                //TODO lane connections

                //Log.Debug("NetLaneExt.UpdateLane() result: " + this);
            } catch (Exception ex) {
                Log.Exception(ex, this.ToString(), false);
                throw ex;
            }
        }
Пример #4
0
        public static byte[] Version2Bytes(Version version)
        {
            var ret = BitConverter.GetBytes(version.Major)
                      .Concat(BitConverter.GetBytes(version.Minor))
                      .Concat(BitConverter.GetBytes(version.Build))
                      .Concat(BitConverter.GetBytes(version.Revision))
                      .ToArray();

            Assertion.AssertEqual(ret.Length, VERSION_SIZE);
            return(ret);
        }
Пример #5
0
        public static IEnumerable <CodeInstruction> Transpiler(IEnumerable <CodeInstruction> instructions)
        {
            int count = 0;

            foreach (var code in instructions)
            {
                if (code.Calls(mForcedAssetStateChanged))
                {
                    count++;
                    yield return(new CodeInstruction(code)
                    {
                        operand = mTriger
                    }                                                            // inherits labels
                                 .LogRet($"replaced {code} with "));
                }
                else
                {
                    yield return(code);
                }
            }
            Assertion.AssertEqual(count, 1, "count");
        }