示例#1
0
            private static IEnumerable <CodeInstruction> UseShieldTargeter(IEnumerable <CodeInstruction> instructions,
                                                                           ILGenerator il)
            {
                var patcher = new Patcher(il);

                return(patcher.Apply(instructions));
            }
示例#2
0
        public void Restore(PatchModel patch)
        {
            var patcher = new Patcher();

            patcher.Patches.Add(patch.ToPatch());

            patcher.Apply(this.ExeFileName, false);
        }
示例#3
0
        public void Apply(PatchModel patch)
        {
            var patcher = new Patcher();

            patcher.Patches.Add(patch.ToPatch());

            patcher.Apply(this.ExeFileName, true);
        }
        public void Can_Patch_NullableGuidProperty_From_JsonString()
        {
            Guid?guid            = Guid.NewGuid();
            var  testObject      = new TestObject();
            var  patchDictionary = new Dictionary <string, object>
            {
                { "NullableGuidProperty", JsonConvert.SerializeObject(guid) }
            };

            Patcher.Apply(testObject, patchDictionary);
            testObject.NullableGuidProperty.Should().Be(guid);
        }
        public void Not_Exists_Field_Patching_Does_Not_Throws_Exception()
        {
            const string notExistsField  = "ImNotExists";
            var          testObject      = new TestObject();
            var          patchDictionary = new Dictionary <string, object>
            {
                { notExistsField, "some value" }
            };
            Action applyAction = () => Patcher.Apply(testObject, patchDictionary);

            applyAction.Should().NotThrow();
        }
        public void Can_Patch_NullableDateTimeProperty_CaseInsensitive(string key)
        {
            DateTime?guid            = DateTime.UtcNow;
            var      testObject      = new TestObject();
            var      patchDictionary = new Dictionary <string, object>
            {
                { key, guid }
            };

            Patcher.Apply(testObject, patchDictionary);
            testObject.NullableDateTimeProperty.Should().Be(guid);
        }
        public void Can_Patch_NullableGuidProperty_CaseInsensitive(string key)
        {
            Guid?guid            = Guid.NewGuid();
            var  testObject      = new TestObject();
            var  patchDictionary = new Dictionary <string, object>
            {
                { key, guid }
            };

            Patcher.Apply(testObject, patchDictionary);
            testObject.NullableGuidProperty.Should().Be(guid);
        }
        public void Can_Patch_NullableDateTimeProperty_From_JsonString()
        {
            DateTime?dateTime        = DateTime.UtcNow;
            var      testObject      = new TestObject();
            var      patchDictionary = new Dictionary <string, object>
            {
                { "NullableDateTimeProperty", JsonConvert.SerializeObject(dateTime) }
            };

            Patcher.Apply(testObject, patchDictionary);
            testObject.NullableDateTimeProperty.Should().Be(dateTime);
        }
        public void Can_Patch_StringField_CaseInsensitive(string key)
        {
            const string newValue        = "new value";
            var          testObject      = new TestObject();
            var          patchDictionary = new Dictionary <string, object>
            {
                { key, newValue }
            };

            Patcher.Apply(testObject, patchDictionary);
            testObject.StringField.Should().Be(newValue);
        }
示例#10
0
        public void Can_Patch_DateTimeProperty_CaseInsensitive(string key)
        {
            var dateTime        = DateTime.UtcNow;
            var testObject      = new TestObject();
            var patchDictionary = new Dictionary <string, object>
            {
                { key, dateTime }
            };

            Patcher.Apply(testObject, patchDictionary);
            testObject.DateTimeProperty.Should().Be(dateTime);
        }
示例#11
0
        public override void Init(ITorchBase torch)
        {
            base.Init(torch);
            //Grab Settings
            string path = Path.Combine(StoragePath, "QuantumHangar.cfg");

            _config = Persistent <Settings> .Load(path);

            if (Config.FolderDirectory == null || Config.FolderDirectory == "")
            {
                Config.FolderDirectory = Path.Combine(StoragePath, "QuantumHangar");
            }

            TorchSession = Torch.Managers.GetManager <TorchSessionManager>();
            if (TorchSession != null)
            {
                TorchSession.SessionStateChanged += SessionChanged;
            }


            Tracker = new GridTracker();



            if (Config.GridMarketEnabled)
            {
                Market = new GridMarket(StoragePath);
                Market.InitilizeGridMarket();
            }
            else
            {
                Debug("Starting plugin WITHOUT the Hangar Market!", null, ErrorType.Warn);
            }


            try
            {
            }
            catch (Exception e)
            {
                Log.Info("Unable to load grid market files! " + e);
            }

            EnableDebug = Config.AdvancedDebug;
            Dir         = Config.FolderDirectory;


            PatchManager manager = DependencyProviderExtensions.GetManager <PatchManager>(Torch.Managers);
            Patcher      patcher = new Patcher();

            patcher.Apply(manager.AcquireContext(), this);
            //Load files
        }
示例#12
0
        public void PrivateProperty_CanNot_BePatched()
        {
            const string newValue        = "new value";
            var          testObject      = new TestObject();
            var          oldValue        = testObject.GetPrivateStringProperty();
            var          patchDictionary = new Dictionary <string, object>
            {
                { "PrivateStringProperty", newValue }
            };

            Patcher.Apply(testObject, patchDictionary);
            testObject.GetPrivateStringProperty().Should().Be(oldValue);
        }
示例#13
0
        public void GetOnlyProperty_CanNot_BePatched()
        {
            const string newValue        = "new value";
            var          testObject      = new TestObject();
            var          oldValue        = testObject.PropertyWithGetOnly;
            var          patchDictionary = new Dictionary <string, object>
            {
                { "PropertyWithGetOnly", newValue }
            };

            Patcher.Apply(testObject, patchDictionary);
            testObject.PropertyWithGetOnly.Should().Be(oldValue);
        }
示例#14
0
        public void Can_Patch_NullableGuidProperty_WithNullValue()
        {
            var testObject = new TestObject
            {
                NullableGuidProperty = Guid.NewGuid()
            };
            var patchDictionary = new Dictionary <string, object>
            {
                { "NullableGuidProperty", null }
            };

            Patcher.Apply(testObject, patchDictionary);
            testObject.NullableGuidProperty.Should().BeNull();
        }
示例#15
0
        public override void Init(ITorchBase torch)
        {
            //Settings S = new Settings();

            base.Init(torch);
            //Grab Settings
            string path = Path.Combine(StoragePath, "QuantumHangar.cfg");

            _config = Persistent <Settings> .Load(path);

            if (Config.FolderDirectory == null || Config.FolderDirectory == "")
            {
                Config.FolderDirectory = Path.Combine(StoragePath, "QuantumHangar");
                Directory.CreateDirectory(Config.FolderDirectory);
            }

            MainPlayerDirectory = Path.Combine(Config.FolderDirectory, "PlayerHangars");
            Directory.CreateDirectory(MainPlayerDirectory);


            TorchSession = Torch.Managers.GetManager <TorchSessionManager>();
            if (TorchSession != null)
            {
                TorchSession.SessionStateChanged += SessionChanged;
            }


            if (Config.GridMarketEnabled)
            {
                Controller = new HangarMarketController();
            }
            else
            {
                Log.Info("Starting plugin WITHOUT the Hangar Market!");
            }



            PatchManager manager = DependencyProviderExtensions.GetManager <PatchManager>(Torch.Managers);
            Patcher      patcher = new Patcher();

            patcher.Apply(manager.AcquireContext(), this);
            //Load files

            MigrateHangar();
        }
示例#16
0
        private static void ApplyPatch(Patch patch)
        {
            Console.WriteLine($"{DateTime.Now:yyyy-MM-dd HH:mm:ss} Applying patch...");

            using (var stream = File.Open(@"e:\Work\RE\Notepad\notepad_3.bin", FileMode.Open, FileAccess.ReadWrite, FileShare.Read))
            {
                using (var bakStream = File.OpenWrite(@"e:\Work\RE\Notepad\notepad_3.bin.bak"))
                {
                    stream.CopyTo(bakStream);
                    stream.Position = 0;
                }

                using (var patcher = new Patcher(stream))
                {
                    var result = patcher.Apply(patch);
                    Console.WriteLine(result.IsSuccess ? "Patch is applied" : "Patch is NOT applied: " + result.Message);
                }
            }

            Console.WriteLine($"{DateTime.Now:yyyy-MM-dd HH:mm:ss} Application completed");
        }
示例#17
0
        protected override void ProcessRecord()
        {
            base.ProcessRecord();
            // TODO: Process item in pipeline

            using (var stream = File.Open(TargetFile, FileMode.Open, FileAccess.ReadWrite, FileShare.Read))
            {
                using (var bakStream = File.OpenWrite(TargetFile + ".bak"))
                {
                    stream.CopyTo(bakStream);
                    stream.Position = 0;
                }

                var patch = Patch.Parse(File.ReadAllLines(PatchFile));

                using (var patcher = new Patcher(stream))
                {
                    var result = patcher.Apply(patch);
                    WriteInformation(result.IsSuccess ? "Patch is applied" : "Patch is NOT applied: " + result.Message, null);
                }
            }
        }