<commit_before>﻿using System;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Mono.Cecil;
using Mono.Cecil.Cil;
using Mono.Collections.Generic;

namespace GnoPatch
{
    class Program
    {

        private static Patch _patch = new Patch()
        {
            Name = "Fix crash when deconstructing steam engine",
            Info = "Base class already nulls mSFX, this removes the extra call that generates a nullref exception.",
            MinVersion = "1.0.0.0",
            MaxVersion = "1.0.0.0",
            Operations = new[]
            {
                new PatchOperation()
                {
                    TypeName = "Game.SteamEngine",
                    Method = "OnDelete",
                    Offset = new OffsetDef(6, 3),
                    Matches = new[]
                    {
                        new InstructionDef()
                        {
                            OpCode = Code.Ldarg_0,
                            OperandType = "type",
                            OperandTargetType = "something something",
                            OperandFullName = "msfx something",
                            HasConstant = false,
                            OperandConstant = null
                        },
                        new InstructionDef()
                        {
                            OpCode = Code.Ldfld,
                            OperandType = "type",
                            OperandTargetType = "something something",
                            OperandFullName = "msfx something",
                            HasConstant = false,
                            OperandConstant = null
                        }
                    },
                    Replacements = new[]
                    {
                        new InstructionDef()
                        {
                            OpCode = Code.Nop,
                            
                        }
                    }
                }
            }
        };

        static void Main(string[] args)
        {
            //SaveFile();

            // var patches = Patches.Load("patches.json");

            var patches = new PatchGroup()
            {
                Target = "Gnomoria.exe",
                Description = "this should patch the steam engine deconstruction crash",
                Patches = new[]
                {
                    new Patch()
                    {
                        Operations = new[]
                        {
                            new PatchOperation()
                            {
                                TypeName = "Game.SteamEngine",
                                Method = "OnDelete",
                                Offset = new OffsetDef(6, 3),
                                Replacements = new[]
                                {
                                    new InstructionDef(Code.Nop), 
                                }
                            }, 
                        }
                    }, 
                }
                
            };

            
            var path = "c:\\program files (x86)\\steam\\steamapps\\common\\gnomoria";
            
            var patcher = new Patcher();
            
            var result = patcher.Apply(patches, new[] { path, Environment.CurrentDirectory });

            if (result.Success)
            {
                Console.WriteLine($"File '{result.FinalAssembly}' written to disk.");
                Console.WriteLine("Done! Press any key to exit.");
            }
            else
            {
                Console.WriteLine("Patching failed. Details:");
                result.Details.ForEach(d => Console.WriteLine(d.Message));
                Console.WriteLine("Press any key to exit.");
            }

            Console.Read();
        }

        
        static void SaveFile()
        {
            var tests = new PatchGroup()
            {
                Description = "blah",
                Target = "Gnomoria.exe",<commit_msg>So it seems I didn't set my email address before... bummer.<commit_after>﻿using System;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Mono.Cecil;
using Mono.Cecil.Cil;
using Mono.Collections.Generic;

namespace GnoPatch
{
    class Program
    {

        private static Patch _patch = new Patch()
        {
            Name = "Fix crash when deconstructing steam engine",
            Info = "Base class already nulls mSFX, this removes the extra call that generates a nullref exception.",
            MinVersion = "1.0.0.0",
            MaxVersion = "1.0.0.0",
            Operations = new[]
            {
                new PatchOperation()
                {
                    TypeName = "Game.SteamEngine",
                    Method = "OnDelete",
                    Offset = new OffsetDef(6, 3),
                    Matches = new[]
                    {
                        new InstructionDef()
                        {
                            OpCode = Code.Ldarg_0,
                            OperandType = "type",
                            OperandTargetType = "something something",
                            OperandFullName = "msfx something",
                            HasConstant = false,
                            OperandConstant = null
                        },
                        new InstructionDef()
                        {
                            OpCode = Code.Ldfld,
                            OperandType = "type",
                            OperandTargetType = "something something",
                            OperandFullName = "msfx something",
                            HasConstant = false,
                            OperandConstant = null
                        }
                    },
                    Replacements = new[]
                    {
                        new InstructionDef()
                        {
                            OpCode = Code.Nop,
                            
                        }
                    }
                }
            }
        };

        static void Main(string[] args)
        {
            //SaveFile();

            // var patches = Patches.Load("patches.json");

            // this is the default patch we'll apply for the steam engine patch.
            var patches = new PatchGroup()
            {
                Target = "Gnomoria.exe",
                Description = "this should patch the steam engine deconstruction crash",
                Patches = new[]
                {
                    new Patch()
                    {
                        Operations = new[]
                        {
                            new PatchOperation()
                            {
                                TypeName = "Game.SteamEngine",
                                Method = "OnDelete",
                                Offset = new OffsetDef(6, 3),
                                Replacements = new[]
                                {
                                    new InstructionDef(Code.Nop), 
                                }
                            }, 
                        }
                    }, 
                }
                
            };
            
            // I'll get rid of this hardcoded path soon
            var path = "c:\\program files (x86)\\steam\\steamapps\\common\\gnomoria";
            
            var patcher = new Patcher();
            
            var result = patcher.Apply(patches, new[] { path, Environment.CurrentDirectory });

            if (result.Success)
            {
                Console.WriteLine($"File '{result.FinalAssembly}' written to disk.");
                Console.WriteLine("Done! Press any key to exit.");
            }
            else
            {
                Console.WriteLine("Patching failed. Details:");
                result.Details.ForEach(d => Console.WriteLine(d.Message));
                Console.WriteLine("Press any key to exit.");
            }

            Console.Read();
        }

        
        static void SaveFile()
        {
            var tests = new PatchGroup()
            {
                Description = "blah",
                Target = "Gnomoria.exe",
{'fraction_non_alphanumeric': 0.07982688146188988, 'fraction_numerical': 0.0036066362106275548, 'mean_word_length': 0.8239421179565884, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 4, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7417975', 'n_tokens_mistral': 1880, 'n_tokens_neox': 1725, 'n_words': 427}