Exemplo n.º 1
0
            private static IEnumerable <CodeInstruction> UseShieldTargeter(IEnumerable <CodeInstruction> instructions,
                                                                           ILGenerator il)
            {
                var patcher = new Patcher(il);

                return(patcher.Apply(instructions));
            }
Exemplo n.º 2
0
        public void Restore(PatchModel patch)
        {
            var patcher = new Patcher();

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

            patcher.Apply(this.ExeFileName, false);
        }
Exemplo n.º 3
0
        public void Apply(PatchModel patch)
        {
            var patcher = new Patcher();

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

            patcher.Apply(this.ExeFileName, true);
        }
Exemplo n.º 4
0
        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);
        }
Exemplo n.º 5
0
        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();
        }
Exemplo n.º 6
0
        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);
        }
Exemplo n.º 7
0
        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);
        }
Exemplo n.º 8
0
        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);
        }
Exemplo n.º 9
0
        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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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();
        }
Exemplo n.º 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();
        }
Exemplo n.º 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");
        }
Exemplo n.º 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);
                }
            }
        }