Example #1
0
        static int Main(string[] args)
        {
            // Operation
            string invokedOperation = "";
            // Options for that operation
            object invokedOperationOptions = null;

            var opts = new Options();

            // Must check for null, because the parser won't..
            if (args == null || args.Length == 0)
            {
                Console.WriteLine(opts.GetUsage("help"));
                goto ERROR;
            }
            if (!CommandLine.Parser.Default.ParseArgumentsStrict(args, opts,
                                                                 (verb, subOptions) =>
            {
                invokedOperation = verb;
                invokedOperationOptions = subOptions;
            },
                                                                 () =>
            {
                // Console.WriteLine("Failed to parse arguments!");
                // Failed to parse, exit the program
                Environment.Exit(-2);
            }))
            {
                // The parser will have written usage information.
                // This might happen because options were misspelled or not given.
                goto ERROR;
            }

            try
            {
                // Process general options
                Prepare((GeneralOptions)invokedOperationOptions);
            }
            catch (Exception e)
            {
                Log.Exception(e.Message, e);
                goto ERROR;
            }

            try
            {
                switch (invokedOperation)
                {
                case OPERATION_HOOK:
                    var hookHelper = new HookHelper((HookSubOptions)invokedOperationOptions);
                    hookHelper.TryHook();
                    Log.Info("Succesfully hooked the game libraries!");
                    break;

                case OPERATION_RESTORE:
                    var restore = new Restore((RestoreSubOptions)invokedOperationOptions);
                    restore.TryRestore();
                    Log.Info("Succesfully restored the original game libraries!");
                    break;

                default:
                    // Error happened
                    throw new ArgumentException("Invalid verb processed");
                }
            }
            catch (Exception e)
            {
                Log.Exception(EXCEPTION_MSG, e);
                goto ERROR;
            }

            // All OK
            return(0);

ERROR:
            return(1);
        }
Example #2
0
        static int Main(string[] args)
        {
            bool succeeded = YanderePrepare.PrepareMod();

            if (!succeeded)
            {
                Console.ReadLine();
                return(0);
            }
            if (File.Exists(Environment.CurrentDirectory + "\\hooked"))
            {
                LaunchGame();
                return(0);
            }

            string[] actions = CustomArgs(args);
            //Console.ReadLine();
            // Operation
            string invokedOperation = "";
            // General options.
            GeneralOptions generalOptions = null;
            // Options specific to the action to perform.
            object invokedOperationOptions = null;

            var opts = new Options();

            // Must check for null, because the parser won't..
            if (actions == null || actions.Length == 0)
            {
                Console.WriteLine(opts.GetUsage("help"));
                goto ERROR;
            }

            CommandLine.Parser.Default.ParseArgumentsStrict(actions, opts, (verb, subOptions) =>
            {
                // Action to store correct information for further instructing the processor.
                invokedOperation        = verb;
                invokedOperationOptions = subOptions;
            }, () =>
            {
                // Failed attempt at parsing the provided arguments.
                Environment.Exit(-2);
            });

            try
            {
                // Process general options
                generalOptions = (GeneralOptions)invokedOperationOptions;
                Prepare(generalOptions);
            }
            catch (Exception e)
            {
                Log.Exception(e.Message, e);
                goto ERROR;
            }

            // Use knowledge about the game HearthStone. Game knowledge is defined in the shared code
            // project KnowledgeBase. See `GameKnowledgeBase.HSKB` for more information.
            // Change the following line if you want to hook another game.
            var gameKnowledge = new GameKB(generalOptions.GamePath, new YandereSimulatorKB());

            try
            {
                switch (invokedOperation)
                {
                case OPERATION_HOOK:
                    Log.Info("Hooking operation started!\n");
                    var hookHelper = new HookHelper((HookSubOptions)invokedOperationOptions);
                    hookHelper.TryHook(gameKnowledge);
                    Log.Info("Hooked the game libraries!");

                    break;

                case OPERATION_RESTORE:
                    Log.Info("Restore operation started!\n");
                    var restore = new Restore((RestoreSubOptions)invokedOperationOptions);
                    restore.TryRestore(gameKnowledge);
                    Log.Info("Restored the original game libraries!");
                    break;

                default:
                    throw new ArgumentException("Invalid verb processed");
                }
            }
            catch (Exception e)
            {
                Log.Exception(EXCEPTION_MSG, e);
                goto ERROR;
            }

            //Console.ReadLine();
            // All OK
            if (args.Length == 0)
            {
                LaunchGame();
            }
            return(0);

ERROR:
            var tprocess = new System.Diagnostics.Process();
            var tstartInfo = new System.Diagnostics.ProcessStartInfo
            {
                FileName = Environment.CurrentDirectory + "\\unhook.bat"
            };

            tprocess.StartInfo = tstartInfo;
            tprocess.Start();
            Console.ReadLine();
            return(1);
        }
Example #3
0
        static int Main(string[] args)
        {
            // Operation
            string invokedOperation = "";
            // General options.
            GeneralOptions generalOptions = null;
            // Options specific to the action to perform.
            object invokedOperationOptions = null;

            var opts = new Options();

            // Must check for null, because the parser won't..
            if (args == null || args.Length == 0)
            {
                Console.WriteLine(opts.GetUsage("help"));
                goto ERROR;
            }

            CommandLine.Parser.Default.ParseArgumentsStrict(args, opts, (verb, subOptions) =>
            {
                // Action to store correct information for further instructing the processor.
                invokedOperation        = verb;
                invokedOperationOptions = subOptions;
            }, () =>
            {
                // Failed attempt at parsing the provided arguments.
                Environment.Exit(-2);
            });

            try
            {
                // Process general options
                generalOptions = (GeneralOptions)invokedOperationOptions;
                Prepare(generalOptions);
            }
            catch (Exception e)
            {
                Log.Exception(e.Message, e);
                goto ERROR;
            }

            // Use knowledge about the game HearthStone. Game knowledge is defined in the shared code
            // project KnowledgeBase. See `GameKnowledgeBase.HSKB` for more information.
            // Change the following line if you want to hook another game.
            GameKB gameKnowledge = HSKB.Get(generalOptions.GamePath);

            try
            {
                switch (invokedOperation)
                {
                case OPERATION_HOOK:
                    var hookHelper = new HookHelper((HookSubOptions)invokedOperationOptions);
                    hookHelper.TryHook(gameKnowledge);
                    Log.Info("Succesfully hooked the game libraries!");
                    break;

                case OPERATION_RESTORE:
                    var restore = new Restore((RestoreSubOptions)invokedOperationOptions);
                    restore.TryRestore(gameKnowledge);
                    Log.Info("Succesfully restored the original game libraries!");
                    break;

                default:
                    throw new ArgumentException("Invalid verb processed");
                }
            }
            catch (Exception e)
            {
                Log.Exception(EXCEPTION_MSG, e);
                goto ERROR;
            }

            // All OK
            return(0);

ERROR:
            return(1);
        }