Ejemplo n.º 1
0
 private void Save(dnpatch.Patcher patcher)
 {
     try
     {
         patcher.Save(true);
     }
     catch (Exception ex)
     {
         _writer.WriteLine("Error while saving patched game assembly: " + ex);
         throw;
     }
 }
Ejemplo n.º 2
0
        public void PatchGame()
        {
            var patcher = new dnpatch.Patcher($"{_config.ManagedPath}/Assembly-CSharp.dll");
            var target  = new Target
            {
                Class  = "PermanentManager",
                Method = "Awake"
            };
            var newInstructions = new[]
            {
                Instruction.Create(OpCodes.Call, patcher.BuildCall(typeof(ModLoader.ModLoader), "LoadMods", typeof(void), new Type[] { })),
                Instruction.Create(OpCodes.Ret)
            };
            var instructions = patcher.GetInstructions(target).ToList();

            if (IsPatched(instructions))
            {
                ReplacePatchedInstructions(instructions, newInstructions);
            }
            else
            {
                AddNewInstructions(instructions, newInstructions);
            }
            target.Instructions = instructions.ToArray();
            try
            {
                patcher.Patch(target);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error while patching game assembly: " + ex);
                throw;
            }
            try
            {
                patcher.Save(true);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error while saving patched game assembly: " + ex);
                throw;
            }
        }