From 26401aeb6c013559cf4c7b3ab377e1eb7e657715 Mon Sep 17 00:00:00 2001 From: HoLLy-HaCKeR Date: Thu, 5 May 2016 01:04:01 +0200 Subject: [PATCH] Finished DLL --- osu!ibc/FileSelectForm.cs | 30 +++++++------------- osu!ibc/Helper.cs | 25 ++++------------ osu!ibc/MainClass.cs | 60 +++++++++++++-------------------------- osu!ibc/osu!ibc.csproj | 1 - 4 files changed, 36 insertions(+), 80 deletions(-) diff --git a/osu!ibc/FileSelectForm.cs b/osu!ibc/FileSelectForm.cs index f426f4b..d98f48e 100644 --- a/osu!ibc/FileSelectForm.cs +++ b/osu!ibc/FileSelectForm.cs @@ -1,13 +1,6 @@ using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; -using System.Data.Odbc; using System.Diagnostics; using System.Drawing; -using System.Linq; -using System.Text; -using System.Threading.Tasks; using System.Windows.Forms; namespace osu_ibc @@ -25,13 +18,17 @@ public FileSelectForm() //snag icon from osu!, purely for esthetic purposes if (!UpdateFormIcon()) Icon = SystemIcons.Shield; + + //bring to front + BringToFront(); + Focus(); } public bool UpdateFormIcon() { try { - string path = Process.GetCurrentProcess().MainModule.FileName; //get osu! location - Icon = Icon.ExtractAssociatedIcon(path); //extract icon from file + string path = Process.GetCurrentProcess().MainModule.FileName; //get osu! location + Icon = Icon.ExtractAssociatedIcon(path); //extract icon from file return true; } catch (Exception ex) { @@ -46,22 +43,15 @@ private void btnSelect_Click(object sender, EventArgs e) OpenFileDialog ofd = new OpenFileDialog(); ofd.Filter = "Image Files|*.png;*.jpg;*.jpeg|All Files|*"; //allowing all files if users feel like experimenting if (ofd.ShowDialog() == DialogResult.OK) { - //set string value for path - SelectedFile = ofd.FileName; - - //update preview - pbPreview.ImageLocation = SelectedFile; - - //enable button - btnDone.Enabled = true; + SelectedFile = ofd.FileName; //set string value for path + pbPreview.ImageLocation = SelectedFile; //update preview + btnDone.Enabled = true; //enable button } } private void btnDone_Click(object sender, EventArgs e) { - //cleanup? - //set return value to OK - DialogResult = DialogResult.OK; + DialogResult = DialogResult.OK; //set return value to OK } } } diff --git a/osu!ibc/Helper.cs b/osu!ibc/Helper.cs index e844dd6..c92fd43 100644 --- a/osu!ibc/Helper.cs +++ b/osu!ibc/Helper.cs @@ -2,16 +2,13 @@ using System.Collections.Generic; using System.IO; using System.Linq; -using System.Windows.Forms; namespace osu_ibc { static class Helper { - public static string GetBackgroundFromBeatmap(string beatmapPath) //tested on: v9 + public static string GetBackgroundFromBeatmap(string beatmapPath) { - //[Events] - //0,0,"STBG.jpg" try { using (StreamReader sr = new StreamReader(File.OpenRead(beatmapPath))) { string line; @@ -21,7 +18,7 @@ static class Helper while ((line = sr.ReadLine()) != "[TimingPoints]") { if (string.IsNullOrWhiteSpace(line)) continue; //[X] bad line if (line.StartsWith("//")) continue; //[X] comments - if (line.StartsWith("0,")) return line.GetBetween('"'); //[v] proper line + if (line.StartsWith("0,")) return line.GetBetween('"'); //[v] background line } } } @@ -32,17 +29,14 @@ static class Helper return ""; } - public static bool AddBeatmapsToDictionary(string directory, ref Dictionary dicks) + public static bool AddBeatmapsToDictionary(string directory, ref Dictionary dictionary) { bool containsBeatmaps = false; foreach (string file in Directory.GetFiles(directory).Where(file => Path.GetExtension(file) == ".osu")) { containsBeatmaps = true; - if (dicks.ContainsKey(file)) continue; //ignore if already read - - string img = GetBackgroundFromBeatmap(file); //xxx.jpg, xxx.png - if (!string.IsNullOrEmpty(img)) { - dicks.Add(file, directory+img); - } + if (dictionary.ContainsKey(file)) continue; //ignore if already read + string img = GetBackgroundFromBeatmap(file); //get file name + if (!string.IsNullOrEmpty(img)) dictionary.Add(file, directory + img); //add to dictionary } return containsBeatmaps; } @@ -52,12 +46,5 @@ public static string GetBetween(this string str, char bounds) int firstIndex = str.IndexOf(bounds)+1; return str.Substring(firstIndex, str.LastIndexOf(bounds) - firstIndex); } - - public static void DebugLog(string message, string title = "DEBUG") - { -#if DEBUG - MessageBox.Show(message, title); -#endif - } } } diff --git a/osu!ibc/MainClass.cs b/osu!ibc/MainClass.cs index 8da6109..05c9e3f 100644 --- a/osu!ibc/MainClass.cs +++ b/osu!ibc/MainClass.cs @@ -1,11 +1,8 @@ using System; using System.Collections.Generic; using System.IO; -using System.Linq; using System.Runtime.InteropServices; -using System.Text; using System.Threading; -using System.Threading.Tasks; using System.Windows.Forms; using EasyHook; @@ -13,12 +10,11 @@ namespace osu_ibc { public class MainClass : IEntryPoint { - //TODO: create hkCreateFileA, in case W doesn't work completely - - public static string NewFilePath = ""; //TODO seperate png and jpeg - LocalHook hkCreateFileW; - static Dictionary fileDictionary = new Dictionary(); + public static string NewFilePath = ""; + LocalHook _hkCreateFileW; //ascii version not needed + static Dictionary _fileDictionary = new Dictionary(); + //Imports [DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)] public static extern IntPtr CreateFileW( [MarshalAs(UnmanagedType.LPWStr)] string filename, @@ -40,15 +36,15 @@ public class MainClass : IEntryPoint [MarshalAs(UnmanagedType.U4)] FileAttributes flagsAndAttributes, IntPtr templateFile); - public MainClass(RemoteHooking.IContext InContext) {} + public MainClass(RemoteHooking.IContext inContext) {} - public void Run(RemoteHooking.IContext InContext) //method that gets called + public void Run(RemoteHooking.IContext inContext) //method that gets called { //spawn FileSelectForm FileSelectForm fsf = new FileSelectForm(); if (fsf.ShowDialog() != DialogResult.OK) { //user didn't complete file selection, show warning - if (MessageBox.Show("You did not select a file.\nDo you want to use invalid files (yes) or exit (no)?","osu!ibc - Warning!",MessageBoxButtons.YesNo, MessageBoxIcon.Warning) != DialogResult.Yes) { + if (MessageBox.Show("You did not select a file.\nDo you want to remove all bg's (yes) or exit (no)?","osu!ibc - Warning!",MessageBoxButtons.YesNo, MessageBoxIcon.Warning) != DialogResult.Yes) { return; } } @@ -58,51 +54,35 @@ public class MainClass : IEntryPoint //create hooks for CreateFileA and CreateFileW try { - hkCreateFileW = LocalHook.Create(LocalHook.GetProcAddress("kernel32.dll", "CreateFileW"), new DCreateFileW(CreateFileWHook), this); - hkCreateFileW.ThreadACL.SetExclusiveACL(new[] {0}); + _hkCreateFileW = LocalHook.Create(LocalHook.GetProcAddress("kernel32.dll", "CreateFileW"), new DCreateFileW(CreateFileWHook), this); + _hkCreateFileW.ThreadACL.SetExclusiveACL(new[] {0}); RemoteHooking.WakeUpProcess(); - MessageBox.Show("Finished?"); } catch (Exception ex) { MessageBox.Show("Exception occured while creating hooks: " + ex.Message); } - while (true) - { - Thread.Sleep(1000); - } + while (true) Thread.Sleep(1000); //just sleeeep } - static IntPtr CreateFileWHook( - [MarshalAs(UnmanagedType.LPWStr)] string filename, - [MarshalAs(UnmanagedType.U4)] FileAccess access, - [MarshalAs(UnmanagedType.U4)] FileShare share, - IntPtr securityAttributes, - [MarshalAs(UnmanagedType.U4)] FileMode creationDisposition, - [MarshalAs(UnmanagedType.U4)] FileAttributes flagsAndAttributes, - IntPtr templateFile) + static IntPtr CreateFileWHook( [MarshalAs(UnmanagedType.LPWStr)] string filename, + [MarshalAs(UnmanagedType.U4)] FileAccess access, + [MarshalAs(UnmanagedType.U4)] FileShare share, + IntPtr securityAttributes, + [MarshalAs(UnmanagedType.U4)] FileMode creationDisposition, + [MarshalAs(UnmanagedType.U4)] FileAttributes flagsAndAttributes, + IntPtr templateFile) { string extension = Path.GetExtension(filename); - switch (extension) { + switch (extension?.ToLower()) { case ".png": case ".jpg": case ".jpeg": - - if (!Path.GetDirectoryName(filename).Contains("Songs")) { //TODO get songs directory by reading cfg file, return if not in it - goto end; - } - - //if image is read, check if folder contains a .osu file - if (Helper.AddBeatmapsToDictionary(Path.GetDirectoryName(filename), ref fileDictionary)) { - if (extension == Path.GetExtension(NewFilePath)) { - //TODO - } - } - + if (!Path.GetDirectoryName(filename).Contains("Songs")) break; + if (Helper.AddBeatmapsToDictionary(Path.GetDirectoryName(filename), ref _fileDictionary)) filename = NewFilePath; //this is a bg break; } - end: return CreateFileW(filename, access, share, securityAttributes, creationDisposition, flagsAndAttributes, templateFile); } } diff --git a/osu!ibc/osu!ibc.csproj b/osu!ibc/osu!ibc.csproj index 65d7ca7..a7f6ea3 100644 --- a/osu!ibc/osu!ibc.csproj +++ b/osu!ibc/osu!ibc.csproj @@ -43,7 +43,6 @@ -