Skip to content
This repository has been archived by the owner on Jun 19, 2020. It is now read-only.

Commit

Permalink
Injector finished
Browse files Browse the repository at this point in the history
  • Loading branch information
holly-hacker committed May 4, 2016
1 parent 4c86a38 commit 6977d6f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 27 deletions.
1 change: 0 additions & 1 deletion osu! ingame background changer/Injector.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
Expand Down
47 changes: 21 additions & 26 deletions osu! ingame background changer/Program.cs
Original file line number Diff line number Diff line change
@@ -1,39 +1,44 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using EasyHook;

namespace osu_ibc_injector
{
class Program
{
public static Process osuProcess;
public static Process InjectProcess;
private const string DllName = "osu!ibc.dll";
private static string DllPath = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + "\\" + DllName;
private static readonly string DllPath = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + "\\" + DllName;

static void Main(string[] args)
{
//pretty stuff
Console.Title = "osu!ibc";
Console.WriteLine("osu!ibc - osu! ingame background changer");
Console.WriteLine();
Console.Write("Waiting for osu!...");
Console.Write("Looking for osu!...");

//get osu!
osuProcess = FindOsuProcess();
if (osuProcess == null) Exit(" did not find a single osu! process!", true);
Console.WriteLine(" found osu! (PID: " + osuProcess.Id + ")");
InjectProcess = FindOsuProcess();
Console.WriteLine(" found osu! (PID: " + InjectProcess.Id + ")");

//inject dll
//if not present, ask user to select dll
if (!File.Exists(DllPath)) {
//TODO: ask for file
Exit("DLL file not found");
}
RemoteHooking.Inject(osuProcess.Id, InjectionOptions.DoNotRequireStrongName, DllPath, DllPath);
//if not present, I could ask user to select dll
if (!File.Exists(DllPath)) Exit(DllName + " not found");

//inject DLL into osu!
RemoteHooking.Inject(InjectProcess.Id, InjectionOptions.DoNotRequireStrongName, DllPath, DllPath);
}

public static Process FindOsuProcess()
{
//could handle length>1 in another way if needed
Process[] processes = Process.GetProcessesByName("osu!");
if (processes.Length <= 0) Exit(" did not find a single osu! process!", true);
if (processes.Length == 1) return processes[0];
if (processes.Length >= 2) Exit(" multiple osu! processes found!", true);
return null; //should not occur
}

public static void Exit(string message = "Press any key to exit...", bool bad = false)
Expand All @@ -46,15 +51,5 @@ public static void Exit(string message = "Press any key to exit...", bool bad =
Console.ReadKey();
Environment.Exit(bad ? -1 : 0);
}

public static Process FindOsuProcess()
{
Process[] processes = Process.GetProcessesByName("osu!");
if (processes.Length == 0) return null;
if (processes.Length == 1) return processes[0];

//add handler for length >1?
return null;
}
}
}

0 comments on commit 6977d6f

Please sign in to comment.