aboutsummaryrefslogtreecommitdiff
path: root/contrib/Connection Patcher/Patcher.cs
diff options
context:
space:
mode:
authorbloerwald <bloerwald@googlemail.com>2014-10-28 18:33:19 +0000
committerDDuarte <dnpd.dd@gmail.com>2014-10-28 18:33:19 +0000
commitff0f84e3aa23a32106e88e84c7abe10229200e9e (patch)
tree7aafb946356dc4f82031badbcbbfbe53eac3e5d0 /contrib/Connection Patcher/Patcher.cs
parent6b6b6e8f09732ef0306b2cf3c6d5f8953a4fddca (diff)
Tools/connection_patcher: remove c# code, add c++ code with minor modification, move to tools, integrate into cmake
note: no longer downloads nonexistent modules note: now throws on not finding patterns new dependency: boost.filesystem Closes #13471
Diffstat (limited to 'contrib/Connection Patcher/Patcher.cs')
-rw-r--r--contrib/Connection Patcher/Patcher.cs130
1 files changed, 0 insertions, 130 deletions
diff --git a/contrib/Connection Patcher/Patcher.cs b/contrib/Connection Patcher/Patcher.cs
deleted file mode 100644
index 8e73997365c..00000000000
--- a/contrib/Connection Patcher/Patcher.cs
+++ /dev/null
@@ -1,130 +0,0 @@
-/*
- * Copyright (C) 2012-2014 Arctium Emulation <http://arctium.org>
- * Copyright (C) 2008-2014 TrinityCore <http://www.trinitycore.org/>
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-using Connection_Patcher.Constants;
-using System;
-using System.IO;
-
-namespace Connection_Patcher
-{
- class Patcher : IDisposable
- {
- public string Binary { get; set; }
- public bool Initialized { get; private set; }
- public BinaryTypes Type { get; private set; }
-
- public byte[] binary;
- bool success;
-
- public Patcher(string file)
- {
- Initialized = false;
- success = false;
-
- using (var stream = new MemoryStream(File.ReadAllBytes(file)))
- {
- Binary = file;
- binary = stream.ToArray();
-
- if (binary != null)
- {
- Type = Helper.GetBinaryType(binary);
-
- Initialized = true;
- }
- }
- }
-
- public void Patch(byte[] bytes, byte[] pattern, long address = 0)
- {
- if (Initialized && (address != 0 || binary.Length >= pattern.Length))
- {
- var offset = pattern == null ? address : SearchOffset(pattern);
- Console.WriteLine("Found offset {0}", offset);
-
- if (offset != 0 && binary.Length >= bytes.Length)
- {
- try
- {
- for (int i = 0; i < bytes.Length; i++)
- binary[offset + i] = bytes[i];
- }
- catch (Exception ex)
- {
- throw new NotSupportedException(ex.Message);
- }
- }
- }
- }
-
- long SearchOffset(byte[] pattern)
- {
- var matches = 0;
-
- for (long i = 0; i < binary.Length; i++)
- {
- matches = 0;
-
- for (int j = 0; j < pattern.Length; j++)
- {
- if (pattern.Length > (binary.Length - i))
- return 0;
-
- if (pattern[j] == 0)
- {
- matches++;
- continue;
- }
-
- if (binary[i + j] != pattern[j])
- break;
-
- matches++;
- }
-
- if (matches == pattern.Length)
- return i;
- }
-
- return 0;
- }
-
- public void Finish()
- {
- success = true;
- }
-
- public void Dispose()
- {
- try
- {
- if (File.Exists(Binary))
- File.Delete(Binary);
-
- if (success)
- File.WriteAllBytes(Binary, binary);
- }
- catch (UnauthorizedAccessException)
- {
-
- }
-
- binary = null;
- }
- }
-}