Ejemplo n.º 1
0
        public void SetModuleEnabled(string moduleName, bool enabled)
        {
            if (moduleMap.ContainsKey(moduleName) == false)
            {
                return;
            }

            PatcherModule module = moduleMap[moduleName];

            module.enabled = enabled;
        }
Ejemplo n.º 2
0
        public void SetModuleArg(string moduleName, string argName, object value)
        {
            if (moduleMap.ContainsKey(moduleName) == false)
            {
                return;
            }

            PatcherModule module = moduleMap[moduleName];

            if (module.argMap.ContainsKey(argName) == false)
            {
                return;
            }

            module.argMap[argName].SetUserVal(value);
        }
Ejemplo n.º 3
0
        void ParsePatchConfig()
        {
            string resourceName = ResourceNameForVersion(Version);
            string config       = ReadResource(resourceName);

            if (config == null)
            {
                throw new System.NotSupportedException($"No patch config found for selected Version {Version}");
            }

            // Get all lines, filtering out comments and whitespace
            char[]        splitChars = new char[] { '\n' };
            List <string> lines      = config.Split(splitChars)
                                       .Select(x => x.Trim())
                                       .Where(x => x.Length > 0)
                                       .Where(x => x.StartsWith(";") == false)
                                       .ToList();

            PatcherModule currentModule = null;

            foreach (var line in lines)
            {
                char triggerChar = line[0];
                switch (triggerChar)
                {
                case '[':
                {
                    // Start module

                    if (REGEX_MODULE_NAME.IsMatch(line) == false)
                    {
                        throw new System.NotSupportedException("Malformed module name line");
                    }

                    var    match      = REGEX_MODULE_NAME.Match(line);
                    string moduleName = match.Groups[1].Value;

                    if (moduleMap.ContainsKey(moduleName))
                    {
                        throw new System.NotSupportedException("Repeat declaration of patcher module");
                    }

                    PatcherModule module = new PatcherModule(moduleName);
                    moduleList.Add(module);
                    moduleMap[moduleName] = module;
                    currentModule         = module;

                    break;
                }

                case '<':
                {
                    // Start arg declaration
                    if (currentModule == null)
                    {
                        throw new System.NotSupportedException("Argument declared without patch module");
                    }

                    if (REGEX_ARG_DECL.IsMatch(line) == false)
                    {
                        throw new System.NotSupportedException("Malformed arg declaration");
                    }

                    var match   = REGEX_ARG_DECL.Match(line);
                    var argName = match.Groups["ArgName"].Value;

                    if (currentModule.argMap.ContainsKey(argName) == true)
                    {
                        throw new System.NotSupportedException("Repeat declaration of argument");
                    }

                    PatcherArg arg = new PatcherArg();
                    arg.name = argName;
                    arg.ConfigureType(match.Groups["ArgType"].Value, match.Groups["ArgSize"].Value);
                    arg.ConfigureDefaultVal(match.Groups["DefaultVal"].Value);

                    currentModule.argList.Add(arg);
                    currentModule.argMap[argName] = arg;

                    break;
                }

                case '$':
                {
                    // Start injection declaration
                    if (currentModule == null)
                    {
                        throw new System.NotSupportedException("Injection declared without patch module");
                    }

                    string injCmd = line.Substring(1);

                    // Split by comma
                    var parts = injCmd.Split(',').ToList();
                    if (parts.Count != 3)
                    {
                        throw new System.NotSupportedException("Malformed injection declaration");
                    }

                    string partOffset  = parts[0].Trim();
                    string partSearch  = parts[1].Trim();
                    string partReplace = parts[2].Trim();

                    PatcherInjection injection = new PatcherInjection();
                    injection.offset        = uint.Parse(partOffset, System.Globalization.NumberStyles.HexNumber);
                    injection.searchPattern = partSearch;
                    injection.injectPattern = partReplace;

                    currentModule.injectionList.Add(injection);

                    break;
                }

                default:
                {
                    throw new System.NotSupportedException("Unsupported trigger char in patch config");
                }
                }
            }
        }