Browse Source

- Added IPA updating

- Added colour to console
pull/46/head
artman41 6 years ago
parent
commit
0e4543a746
3 changed files with 48 additions and 24 deletions
  1. +12
    -8
      IPA/Patcher/Patcher.cs
  2. +34
    -14
      IPA/Program.cs
  3. +2
    -2
      IPA/Properties/AssemblyInfo.cs

+ 12
- 8
IPA/Patcher/Patcher.cs View File

@ -15,6 +15,11 @@ namespace IPA.Patcher
private FileInfo _File;
private ModuleDefinition _Module;
internal struct PatchData {
public bool IsPatched;
public Version Version;
}
public static PatchedModule Load(string engineFile)
{
return new PatchedModule(engineFile);
@ -39,23 +44,22 @@ namespace IPA.Patcher
_Module = ModuleDefinition.ReadModule(_File.FullName, parameters);
}
public bool IsPatched
public PatchData Data
{
get
{
foreach (var @ref in _Module.AssemblyReferences)
{
if (@ref.Name == "IllusionInjector") return true;
foreach (var @ref in _Module.AssemblyReferences) {
if (@ref.Name == "IllusionInjector") return new PatchData { IsPatched = true, Version = @ref.Version};
}
return false;
return new PatchData { IsPatched = false, Version = null};
}
}
public void Patch()
public void Patch(Version v)
{
// First, let's add the reference
var nameReference = new AssemblyNameReference("IllusionInjector", new Version(1, 0, 0, 0));
var nameReference = new AssemblyNameReference("IllusionInjector", v);
var injectorPath = Path.Combine(_File.DirectoryName, "IllusionInjector.dll");
var injector = ModuleDefinition.ReadModule(injectorPath);


+ 34
- 14
IPA/Program.cs View File

@ -21,6 +21,8 @@ namespace IPA
Unknown
}
private static Version Version => new Version(Application.ProductVersion);
static void Main(string[] args) {
PatchContext context;
@ -72,8 +74,20 @@ namespace IPA
try
{
var backup = new BackupUnit(context);
//new version check
var patchedModule = PatchedModule.Load(context.EngineFile);
var isCurrentNewer = Version.CompareTo(patchedModule.Data.Version) > 0;
if (isCurrentNewer) {
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine($"Preparing for update, {(patchedModule.Data.Version == null ? "UnPatched" : patchedModule.Data.Version.ToString())} => {Version}");
Console.WriteLine("--- Starting ---");
Revert(context, new []{"newVersion"});
Console.ResetColor();
}
// Copying
Console.ForegroundColor = ConsoleColor.Magenta;
Console.WriteLine("Updating files... ");
var nativePluginFolder = Path.Combine(context.DataPathDst, "Plugins");
bool isFlat = Directory.Exists(nativePluginFolder) && Directory.GetFiles(nativePluginFolder).Any(f => f.EndsWith(".dll"));
@ -92,32 +106,35 @@ namespace IPA
Console.WriteLine("Creating plugins folder... ");
Directory.CreateDirectory(context.PluginsFolder);
}
Console.ResetColor();
// Patching
var patchedModule = PatchedModule.Load(context.EngineFile);
if (!patchedModule.IsPatched)
if (!patchedModule.Data.IsPatched || isCurrentNewer)
{
Console.Write("Patching UnityEngine.dll... ");
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine($"Patching UnityEngine.dll with Version {Application.ProductVersion}... ");
backup.Add(context.EngineFile);
patchedModule.Patch();
patchedModule.Patch(Version);
Console.WriteLine("Done!");
Console.ResetColor();
}
// Virtualizing
if (File.Exists(context.AssemblyFile))
{
var virtualizedModule = VirtualizedModule.Load(context.AssemblyFile);
if (!virtualizedModule.IsVirtualized)
{
Console.Write("Virtualizing Assembly-Csharp.dll... ");
if (!virtualizedModule.IsVirtualized) {
Console.ForegroundColor = ConsoleColor.Blue;
Console.WriteLine("Virtualizing Assembly-Csharp.dll... ");
backup.Add(context.AssemblyFile);
virtualizedModule.Virtualize();
Console.WriteLine("Done!");
Console.ResetColor();
}
}
// Creating shortcut
if(!File.Exists(context.ShortcutPath))
/*if(!File.Exists(context.ShortcutPath))
{
Console.Write("Creating shortcut to IPA ({0})... ", context.IPA);
try
@ -136,7 +153,7 @@ namespace IPA
{
Console.Error.WriteLine("Failed to create shortcut, but game was patched!");
}
}
}*/
}
catch (Exception e)
{
@ -147,11 +164,13 @@ namespace IPA
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("Finished!");
Console.ResetColor();
Console.ReadLine();
}
private static void Revert(PatchContext context)
{
private static void Revert(PatchContext context, string[] args = null) {
Console.ForegroundColor = ConsoleColor.Cyan;
bool isNewVersion = (args != null && args.Contains("newVersion"));
Console.Write("Restoring backup... ");
if(BackupManager.Restore(context))
{
@ -171,11 +190,12 @@ namespace IPA
Console.WriteLine("");
Console.WriteLine("--- Done reverting ---");
if (!Environment.CommandLine.Contains("--nowait"))
if (!Environment.CommandLine.Contains("--nowait") && !isNewVersion)
{
Console.WriteLine("\n\n[Press any key to quit]");
Console.ReadKey();
}
Console.ResetColor();
}
private static void StartIfNeedBe(PatchContext context)


+ 2
- 2
IPA/Properties/AssemblyInfo.cs View File

@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("3.1.1.0")]
[assembly: AssemblyFileVersion("3.1.1.0")]
[assembly: AssemblyVersion("3.7")]
[assembly: AssemblyFileVersion("3.7")]

Loading…
Cancel
Save