예제 #1
0
        /// <summary>Process the result from an instruction handler.</summary>
        /// <param name="mod">The mod being analysed.</param>
        /// <param name="handler">The instruction handler.</param>
        /// <param name="result">The result returned by the handler.</param>
        /// <param name="loggedMessages">The messages already logged for the current mod.</param>
        /// <param name="assumeCompatible">Assume the mod is compatible, even if incompatible code is detected.</param>
        /// <param name="logPrefix">A string to prefix to log messages.</param>
        /// <param name="filename">The assembly filename for log messages.</param>
        private void ProcessInstructionHandleResult(IModMetadata mod, IInstructionHandler handler, InstructionHandleResult result, HashSet <string> loggedMessages, string logPrefix, bool assumeCompatible, string filename)
        {
            switch (result)
            {
            case InstructionHandleResult.Rewritten:
                this.Monitor.LogOnce(loggedMessages, $"{logPrefix}Rewrote {filename} to fix {handler.NounPhrase}...");
                break;

            case InstructionHandleResult.NotCompatible:
                if (!assumeCompatible)
                {
                    throw new IncompatibleInstructionException(handler.NounPhrase, $"Found an incompatible CIL instruction ({handler.NounPhrase}) while loading assembly {filename}.");
                }
                this.Monitor.LogOnce(loggedMessages, $"{logPrefix}Found an incompatible CIL instruction ({handler.NounPhrase}) while loading assembly {filename}, but SMAPI is configured to allow it anyway. The mod may crash or behave unexpectedly.", LogLevel.Warn);
                break;

            case InstructionHandleResult.DetectedGamePatch:
                this.Monitor.LogOnce(loggedMessages, $"{logPrefix}Detected game patcher ({handler.NounPhrase}) in assembly {filename}.");
                this.Monitor.LogOnce(loggedMessages, $"{mod.DisplayName} patches the game, which may impact game stability. If you encounter problems, try removing this mod first.", LogLevel.Warn);
                break;

            case InstructionHandleResult.DetectedSaveSerialiser:
                this.Monitor.LogOnce(loggedMessages, $"{logPrefix}Detected possible save serialiser change ({handler.NounPhrase}) in assembly {filename}.");
                this.Monitor.LogOnce(loggedMessages, $"{mod.DisplayName} seems to change the save serialiser. It may change your saves in such a way that they won't work without this mod in the future.", LogLevel.Warn);
                break;

            case InstructionHandleResult.None:
                break;

            default:
                throw new NotSupportedException($"Unrecognised instruction handler result '{result}'.");
            }
        }
        internal static void Run(IInstructionHandler handler, List<Cell> cells,
			Action<ExecutionContext> before, Action<ExecutionContext, string> after,
			TextReader reader)
        {
            using (var random = new SecureRandom())
            {
                InstructionHandlerTests.Run(handler, cells, before, after,
                    random, reader);
            }
        }
        internal static void Run(IInstructionHandler handler, List<Cell> cells,
			Action<ExecutionContext> before, Action<ExecutionContext, string> after,
			SecureRandom randomizer)
        {
            using (var reader = new StringReader(string.Empty))
            {
                InstructionHandlerTests.Run(handler, cells, before, after,
                    randomizer, reader);
            }
        }
예제 #4
0
        /// <summary>Process the result from an instruction handler.</summary>
        /// <param name="mod">The mod being analyzed.</param>
        /// <param name="handler">The instruction handler.</param>
        /// <param name="result">The result returned by the handler.</param>
        /// <param name="loggedMessages">The messages already logged for the current mod.</param>
        /// <param name="logPrefix">A string to prefix to log messages.</param>
        /// <param name="filename">The assembly filename for log messages.</param>
        private void ProcessInstructionHandleResult(IModMetadata mod, IInstructionHandler handler, InstructionHandleResult result, HashSet <string> loggedMessages, string logPrefix, string filename)
        {
            switch (result)
            {
            case InstructionHandleResult.Rewritten:
                this.Monitor.LogOnce(loggedMessages, $"{logPrefix}Rewrote {filename} to fix {handler.NounPhrase}...");
                break;

            case InstructionHandleResult.NotCompatible:
                this.Monitor.LogOnce(loggedMessages, $"{logPrefix}Broken code in {filename}: {handler.NounPhrase}.");
                mod.SetWarning(ModWarning.BrokenCodeLoaded);
                break;

            case InstructionHandleResult.DetectedGamePatch:
                this.Monitor.LogOnce(loggedMessages, $"{logPrefix}Detected game patcher ({handler.NounPhrase}) in assembly {filename}.");
                mod.SetWarning(ModWarning.PatchesGame);
                break;

            case InstructionHandleResult.DetectedSaveSerializer:
                this.Monitor.LogOnce(loggedMessages, $"{logPrefix}Detected possible save serializer change ({handler.NounPhrase}) in assembly {filename}.");
                mod.SetWarning(ModWarning.ChangesSaveSerializer);
                break;

            case InstructionHandleResult.DetectedUnvalidatedUpdateTick:
                this.Monitor.LogOnce(loggedMessages, $"{logPrefix}Detected reference to {handler.NounPhrase} in assembly {filename}.");
                mod.SetWarning(ModWarning.UsesUnvalidatedUpdateTick);
                break;

            case InstructionHandleResult.DetectedDynamic:
                this.Monitor.LogOnce(loggedMessages, $"{logPrefix}Detected 'dynamic' keyword ({handler.NounPhrase}) in assembly {filename}.");
                mod.SetWarning(ModWarning.UsesDynamic);
                break;

            case InstructionHandleResult.DetectedConsoleAccess:
                this.Monitor.LogOnce(loggedMessages, $"{logPrefix}Detected direct console access ({handler.NounPhrase}) in assembly {filename}.");
                mod.SetWarning(ModWarning.AccessesConsole);
                break;

            case InstructionHandleResult.DetectedFilesystemAccess:
                this.Monitor.LogOnce(loggedMessages, $"{logPrefix}Detected filesystem access ({handler.NounPhrase}) in assembly {filename}.");
                mod.SetWarning(ModWarning.AccessesFilesystem);
                break;

            case InstructionHandleResult.DetectedShellAccess:
                this.Monitor.LogOnce(loggedMessages, $"{logPrefix}Detected shell or process access ({handler.NounPhrase}) in assembly {filename}.");
                mod.SetWarning(ModWarning.AccessesShell);
                break;

            case InstructionHandleResult.None:
                break;

            default:
                throw new NotSupportedException($"Unrecognized instruction handler result '{result}'.");
            }
        }
예제 #5
0
 public InstructionService(
     IInstructionReceiveService instructionReceiveService,
     ILogger logger, 
     IAppSocketSessionManager appSocketSessionManager,
     IInstructionHandler instructionHandler)
 {
     _appSocketSessionManager = appSocketSessionManager;
     _instructionReceiveService = instructionReceiveService;
     _instructionReceiveService.Received += OnReceived;
     _instructionHandler = instructionHandler;
     _logger = logger;
 }
예제 #6
0
        /// <summary>Process the result from an instruction handler.</summary>
        /// <param name="mod">The mod being analysed.</param>
        /// <param name="handler">The instruction handler.</param>
        /// <param name="result">The result returned by the handler.</param>
        /// <param name="loggedMessages">The messages already logged for the current mod.</param>
        /// <param name="assumeCompatible">Assume the mod is compatible, even if incompatible code is detected.</param>
        /// <param name="logPrefix">A string to prefix to log messages.</param>
        /// <param name="filename">The assembly filename for log messages.</param>
        private void ProcessInstructionHandleResult(IModMetadata mod, IInstructionHandler handler, InstructionHandleResult result, HashSet <string> loggedMessages, string logPrefix, bool assumeCompatible, string filename)
        {
            switch (result)
            {
            case InstructionHandleResult.Rewritten:
                this.Monitor.LogOnce(loggedMessages, $"{logPrefix}Rewrote {filename} to fix {handler.NounPhrase}...");
                break;

            case InstructionHandleResult.NotCompatible:
                this.Monitor.LogOnce(loggedMessages, $"{logPrefix}Broken code in {filename}: {handler.NounPhrase}.");
                if (!assumeCompatible)
                {
                    throw new IncompatibleInstructionException(handler.NounPhrase, $"Found an incompatible CIL instruction ({handler.NounPhrase}) while loading assembly {filename}.");
                }
                this.Monitor.LogOnce(loggedMessages, $"{logPrefix}Found broken code ({handler.NounPhrase}) while loading assembly {filename}, but SMAPI is configured to allow it anyway. The mod may crash or behave unexpectedly.", LogLevel.Warn);
                break;

            case InstructionHandleResult.DetectedGamePatch:
                this.Monitor.LogOnce(loggedMessages, $"{logPrefix}Detected game patcher ({handler.NounPhrase}) in assembly {filename}.");
                this.Monitor.LogOnce(loggedMessages, $"{mod.DisplayName} patches the game, which may impact game stability. If you encounter problems, try removing this mod first.", LogLevel.Warn);
                break;

            case InstructionHandleResult.DetectedSaveSerialiser:
                this.Monitor.LogOnce(loggedMessages, $"{logPrefix}Detected possible save serialiser change ({handler.NounPhrase}) in assembly {filename}.");
                this.Monitor.LogOnce(loggedMessages, $"{mod.DisplayName} seems to change the save serialiser. It may change your saves in such a way that they won't work without this mod in the future.", LogLevel.Warn);
                break;

            case InstructionHandleResult.DetectedUnvalidatedUpdateTick:
                this.Monitor.LogOnce(loggedMessages, $"{logPrefix}Detected reference to {handler.NounPhrase} in assembly {filename}.");
                this.Monitor.LogOnce(loggedMessages, $"{mod.DisplayName} uses a specialised SMAPI event that may crash the game or corrupt your save file. If you encounter problems, try removing this mod first.", LogLevel.Warn);
                break;

            case InstructionHandleResult.DetectedDynamic:
                this.Monitor.LogOnce(loggedMessages, $"{logPrefix}Detected 'dynamic' keyword ({handler.NounPhrase}) in assembly {filename}.");
                this.Monitor.LogOnce(loggedMessages, $"{mod.DisplayName} uses the 'dynamic' keyword, which isn't compatible with Stardew Valley on Linux or Mac.",
#if SMAPI_FOR_WINDOWS
                                     this.IsDeveloperMode ? LogLevel.Warn : LogLevel.Debug
#else
                                     LogLevel.Warn
#endif
                                     );
                break;

            case InstructionHandleResult.None:
                break;

            default:
                throw new NotSupportedException($"Unrecognised instruction handler result '{result}'.");
            }
        }
예제 #7
0
        /// <summary>Process the result from an instruction handler.</summary>
        /// <param name="mod">The mod being analysed.</param>
        /// <param name="handler">The instruction handler.</param>
        /// <param name="result">The result returned by the handler.</param>
        /// <param name="loggedMessages">The messages already logged for the current mod.</param>
        /// <param name="assumeCompatible">Assume the mod is compatible, even if incompatible code is detected.</param>
        /// <param name="logPrefix">A string to prefix to log messages.</param>
        /// <param name="filename">The assembly filename for log messages.</param>
        private void ProcessInstructionHandleResult(IModMetadata mod, IInstructionHandler handler, InstructionHandleResult result, HashSet <string> loggedMessages, string logPrefix, bool assumeCompatible, string filename)
        {
            switch (result)
            {
            case InstructionHandleResult.Rewritten:
                this.Monitor.LogOnce(loggedMessages, $"{logPrefix}Rewrote {filename} to fix {handler.NounPhrase}...");
                break;

            case InstructionHandleResult.NotCompatible:
                this.Monitor.LogOnce(loggedMessages, $"{logPrefix}Broken code in {filename}: {handler.NounPhrase}.");
                if (!assumeCompatible)
                {
                    throw new IncompatibleInstructionException(handler.NounPhrase, $"Found an incompatible CIL instruction ({handler.NounPhrase}) while loading assembly {filename}.");
                }
                mod.SetWarning(ModWarning.BrokenCodeLoaded);
                break;

            case InstructionHandleResult.DetectedGamePatch:
                this.Monitor.LogOnce(loggedMessages, $"{logPrefix}Detected game patcher ({handler.NounPhrase}) in assembly {filename}.");
                mod.SetWarning(ModWarning.PatchesGame);
                break;

            case InstructionHandleResult.DetectedSaveSerialiser:
                this.Monitor.LogOnce(loggedMessages, $"{logPrefix}Detected possible save serialiser change ({handler.NounPhrase}) in assembly {filename}.");
                mod.SetWarning(ModWarning.ChangesSaveSerialiser);
                break;

            case InstructionHandleResult.DetectedUnvalidatedUpdateTick:
                this.Monitor.LogOnce(loggedMessages, $"{logPrefix}Detected reference to {handler.NounPhrase} in assembly {filename}.");
                mod.SetWarning(ModWarning.UsesUnvalidatedUpdateTick);
                break;

            case InstructionHandleResult.DetectedDynamic:
                this.Monitor.LogOnce(loggedMessages, $"{logPrefix}Detected 'dynamic' keyword ({handler.NounPhrase}) in assembly {filename}.");
                mod.SetWarning(ModWarning.UsesDynamic);
                break;

            case InstructionHandleResult.None:
                break;

            default:
                throw new NotSupportedException($"Unrecognised instruction handler result '{result}'.");
            }
        }
        private static void Run(IInstructionHandler handler, List<Cell> cells,
			Action<ExecutionContext> before, Action<ExecutionContext, string> after,
			SecureRandom randomizer, TextReader reader)
        {
            using (var writer = new StringWriter(CultureInfo.CurrentCulture))
            {
                using (reader)
                {
                    var context = new ExecutionContext(cells, reader, writer, randomizer);

                    before?.Invoke(context);

                    handler.Handle(context);
                    var result = writer.GetStringBuilder().ToString();

                    after?.Invoke(context, result);
                }
            }
        }
예제 #9
0
        /// <summary>Process the result from an instruction handler.</summary>
        /// <param name="mod">The mod being analyzed.</param>
        /// <param name="handler">The instruction handler.</param>
        /// <param name="result">The result returned by the handler.</param>
        /// <param name="loggedMessages">The messages already logged for the current mod.</param>
        /// <param name="logPrefix">A string to prefix to log messages.</param>
        /// <param name="filename">The assembly filename for log messages.</param>
        private void ProcessInstructionHandleResult(IModMetadata mod, IInstructionHandler handler, InstructionHandleResult result, HashSet <string> loggedMessages, string logPrefix, string filename)
        {
            // get message template
            // ($phrase is replaced with the noun phrase or messages)
            string template = null;

            switch (result)
            {
            case InstructionHandleResult.Rewritten:
                template = $"{logPrefix}Rewrote {filename} to fix $phrase...";
                break;

            case InstructionHandleResult.NotCompatible:
                template = $"{logPrefix}Broken code in {filename}: $phrase.";
                mod.SetWarning(ModWarning.BrokenCodeLoaded);
                break;

            case InstructionHandleResult.DetectedGamePatch:
                template = $"{logPrefix}Detected game patcher ($phrase) in assembly {filename}.";
                mod.SetWarning(ModWarning.PatchesGame);
                break;

            case InstructionHandleResult.DetectedSaveSerializer:
                template = $"{logPrefix}Detected possible save serializer change ($phrase) in assembly {filename}.";
                mod.SetWarning(ModWarning.ChangesSaveSerializer);
                break;

            case InstructionHandleResult.DetectedUnvalidatedUpdateTick:
                template = $"{logPrefix}Detected reference to $phrase in assembly {filename}.";
                mod.SetWarning(ModWarning.UsesUnvalidatedUpdateTick);
                break;

            case InstructionHandleResult.DetectedDynamic:
                template = $"{logPrefix}Detected 'dynamic' keyword ($phrase) in assembly {filename}.";
                mod.SetWarning(ModWarning.UsesDynamic);
                break;

            case InstructionHandleResult.DetectedConsoleAccess:
                template = $"{logPrefix}Detected direct console access ($phrase) in assembly {filename}.";
                mod.SetWarning(ModWarning.AccessesConsole);
                break;

            case InstructionHandleResult.DetectedFilesystemAccess:
                template = $"{logPrefix}Detected filesystem access ($phrase) in assembly {filename}.";
                mod.SetWarning(ModWarning.AccessesFilesystem);
                break;

            case InstructionHandleResult.DetectedShellAccess:
                template = $"{logPrefix}Detected shell or process access ($phrase) in assembly {filename}.";
                mod.SetWarning(ModWarning.AccessesShell);
                break;

            case InstructionHandleResult.None:
                break;

            default:
                throw new NotSupportedException($"Unrecognized instruction handler result '{result}'.");
            }
            if (template == null)
            {
                return;
            }

            // format messages
            if (handler.Phrases.Any())
            {
                foreach (string message in handler.Phrases)
                {
                    this.Monitor.LogOnce(loggedMessages, template.Replace("$phrase", message));
                }
            }
            else
            {
                this.Monitor.LogOnce(loggedMessages, template.Replace("$phrase", handler.DefaultPhrase ?? handler.GetType().Name));
            }
        }
예제 #10
0
파일: Rover.cs 프로젝트: odw1/Katas
 public Rover(Position initialPosition, Plateau plateau, IInstructionHandler instructionHandler)
 {
     Position = initialPosition;
     _plateau = plateau;
     _instructionHandler = instructionHandler;
 }
예제 #11
0
파일: RoverTests.cs 프로젝트: odw1/Katas
 public void SetUp()
 {
     _plateau = new Plateau(5, 5);
     _instructionHandler = MockRepository.GenerateMock<IInstructionHandler>();
 }