Skip to content

Commit

Permalink
v0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
OCircles committed Jul 17, 2020
1 parent 99961ab commit fdeb71f
Show file tree
Hide file tree
Showing 15 changed files with 1,317 additions and 977 deletions.
77 changes: 77 additions & 0 deletions JK4Life/AssemblyPatcher.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Xml;

namespace JK4Life
{

class AssemblyPatcher
{

public static List<Patch> ReadPatchList(string gameName, List<string> patches, string xml)
{
XmlDocument doc = new XmlDocument();
doc.LoadXml(xml);

List<Patch> injects = new List<Patch>();

foreach (string patchName in patches)
{

XmlNode patch = doc.DocumentElement.SelectSingleNode("/games/" + gameName + "/patch[@name='" + patchName + "']");

foreach (XmlNode inject in patch.SelectNodes("injects/inject"))
{

uint address = Convert.ToUInt32(inject.SelectSingleNode("address").InnerText, 16);
string instruction = inject.SelectSingleNode("instruction").InnerText;

instruction = Regex.Replace(instruction, @"\s+", "");

injects.Add(new Patch(address, Utility.stringToByteArrayFastest(instruction)));

}
}

return injects;
}

public static void PatchExecutable(List<Patch> patchList, string targetPath, string outputPath)
{
string gamePath = Path.GetDirectoryName( targetPath );

if (File.Exists( outputPath )) File.Delete( outputPath );

File.Copy(targetPath, outputPath);


using (BinaryWriter b = new BinaryWriter(File.OpenWrite(outputPath)))
{
foreach (var inject in patchList)
{
b.BaseStream.Seek(inject.offset, SeekOrigin.Begin);
b.Write(inject.patch);
}
}
}

}

class Patch
{
public uint offset;
public byte[] patch;

public Patch(uint offset, byte[] patch)
{
this.offset = offset;
this.patch = patch;
}

}
}
551 changes: 0 additions & 551 deletions JK4Life/Form1.Designer.cs

This file was deleted.

Loading

0 comments on commit fdeb71f

Please sign in to comment.