Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using Microsoft.Win32;
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Diagnostics;
- using System.Drawing;
- using System.IO;
- using System.Linq;
- using System.Runtime.InteropServices;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- namespace TrucksuPatcher
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- [DllImport("kernel32.dll", SetLastError = true)]
- [return: MarshalAs(UnmanagedType.I1)]
- private static extern bool CreateSymbolicLink(
- string lpSymlinkFileName, string lpTargetFileName, SymbolicLink dwFlags);
- private enum SymbolicLink
- {
- File = 0,
- Directory = 1
- }
- public string CopyFolder;
- private List<string> de4dot = new List<string>(new string[] { "de4dot.exe", "de4dot.exe.config" });
- private List<string> de4dotdll =
- new List<string>(new string[]
- {
- "AssemblyData.dll", "de4dot.code.dll", "de4dot.cui.dll", "de4dot.mdecrypt.dll", "de4dot.blocks.dll",
- "dnlib.dll"
- });
- private List<string> de4dotcopy =
- new List<string>(new string[]
- {
- "COPYING", "LICENSE.de4dot.txt", "LICENSE.dnlib.txt", "LICENSE.ICSharpCode.SharpZipLib.txt",
- "LICENSE.lzmat.txt", "LICENSE.QuickLZ.txt", "LICENSE.randomc.txt"
- });
- FolderBrowserDialog fbd = new FolderBrowserDialog();
- private void Form1_Load(object sender, EventArgs e)
- {
- RegistryKey osuKey = Registry.ClassesRoot.OpenSubKey("osu\\DefaultIcon");
- string osuPath = osuKey.GetValue("").ToString().Split('"')[1] + "\\osu!.exe";
- DirectoryInfo osuDir = Directory.GetParent(osuPath);
- path.Text = Convert.ToString(osuDir);
- }
- private void destBtn_Click(object sender, EventArgs e)
- {
- DialogResult result = fbd.ShowDialog();
- if (!string.IsNullOrWhiteSpace(fbd.SelectedPath))
- {
- string[] files = Directory.GetFiles(fbd.SelectedPath);
- //System.Windows.Forms.MessageBox.Show("Files found: " + files.Length.ToString(), "Message");
- path.Text = fbd.SelectedPath;
- }
- }
- private void patchBtn_Click(object sender, EventArgs e)
- {
- UnpackDe4dot(System.IO.Path.GetDirectoryName(openFileDialog1.FileName));
- if (
- System.IO.File.Exists(System.IO.Path.GetDirectoryName(openFileDialog1.FileName) +
- "\\LICENSES\\LICENSE.randomc.txt"))
- {
- RunProcess();
- //p.Start(System.IO.Path.GetDirectoryName(openFileDialog1.FileName) + "\\de4dot.exe", openFileDialog1.FileName);
- }
- string destination = path.Text;
- osuPatch(destination);
- }
- private void RunProcess()
- {
- StringBuilder outputBuilder = new StringBuilder();
- ;
- ProcessStartInfo processStartInfo = new ProcessStartInfo();
- processStartInfo.UseShellExecute = false;
- processStartInfo.CreateNoWindow = true;
- processStartInfo.RedirectStandardOutput = true;
- processStartInfo.RedirectStandardInput = true;
- processStartInfo.Arguments = openFileDialog1.FileName;
- processStartInfo.FileName = System.IO.Path.GetDirectoryName(openFileDialog1.FileName) + "\\de4dot.exe";
- Process p = new Process();
- p.StartInfo = processStartInfo;
- p.EnableRaisingEvents = true;
- // attach the event handler for OutputDataReceived before starting the process
- p.OutputDataReceived += new DataReceivedEventHandler
- (
- delegate (object sender, DataReceivedEventArgs e)
- {
- // append the new data to the data already read-in
- outputBuilder.Append(e.Data);
- }
- );
- label3.Text = "Unpacking...";
- p.Start();
- p.BeginOutputReadLine();
- p.WaitForExit();
- p.CancelOutputRead();
- label3.Text = outputBuilder.ToString();
- }
- private void UnpackDe4dot(string Dir)
- {
- string prefix = "NosuePatcher.Resources";
- System.IO.Directory.CreateDirectory(Dir + "\\bin");
- System.IO.Directory.CreateDirectory(Dir + "\\LICENSES");
- ExtractEmbeddedResource(Dir, prefix, de4dot);
- ExtractEmbeddedResource(Dir + "\\bin", prefix, de4dotdll);
- ExtractEmbeddedResource(Dir + "\\LICENSES", prefix, de4dotcopy);
- }
- private static void ExtractEmbeddedResource(string outputDir, string resourceLocation, List<string> files)
- {
- foreach (string file in files)
- {
- using (
- System.IO.Stream stream =
- System.Reflection.Assembly.GetExecutingAssembly()
- .GetManifestResourceStream(resourceLocation + @"." + file))
- {
- using (
- System.IO.FileStream fileStream =
- new System.IO.FileStream(System.IO.Path.Combine(outputDir, file), System.IO.FileMode.Create)
- )
- {
- for (int i = 0; i < stream.Length; i++)
- {
- fileStream.WriteByte((byte)stream.ReadByte());
- }
- fileStream.Close();
- }
- }
- }
- }
- public bool IsDirectoryEmpty(string path)
- {
- return !Directory.EnumerateFileSystemEntries(path).Any();
- }
- private void osuPatch(string Path)
- {
- if (System.IO.File.Exists(Path + "\\osu!-cleaned.exe"))
- {
- byte[] osu = System.IO.File.ReadAllBytes(Path + "\\osu!-cleaned.exe");
- //c.ppy.sh
- var bancho = new byte[]
- {0x63, 0x00, 0x2e, 0x00, 0x70, 0x00, 0x70, 0x00, 0x79, 0x00, 0x2e, 0x00, 0x73, 0x00, 0x68};
- //c1.ppy.sh
- var bancho2 = new byte[]
- {0x63, 0x00, 0x31, 0x00, 0x2e, 0x00, 0x70, 0x00, 0x70, 0x00, 0x79, 0x00, 0x2e, 0x00, 0x73, 0x00, 0x68};
- //osu.ppy.sh
- var osush = new byte[]
- {
- 0x6f, 0x00, 0x73, 0x00, 0x75, 0x00, 0x2e, 0x00, 0x70, 0x00, 0x70, 0x00, 0x79, 0x00, 0x2e, 0x00, 0x73,
- 0x00,
- 0x68
- };
- //a.ppy.sh
- var ash = new byte[]
- {0x61, 0x00, 0x2e, 0x00, 0x70, 0x00, 0x70, 0x00, 0x79, 0x00, 0x2e, 0x00, 0x73, 0x00, 0x68};
- //---------------------------------------------------------------------------------------------\\
- //ash -> a
- var atrucksu = new byte[]
- {
- 0x61, 0x00, 0x2e, 0x00, 0x74, 0x00, 0x72, 0x00, 0x75, 0x00, 0x63, 0x00, 0x6b, 0x00, 0x73, 0x00, 0x75,
- 0x00, 0x2e, 0x00, 0x63, 0x00, 0x6f, 0x00, 0x6d, 0x00
- };
- //bancho -> c
- var ctrucksu = new byte[]
- {
- 0x63, 0x00, 0x31, 0x00, 0x2e, 0x00, 0x74, 0x00, 0x72, 0x00, 0x75, 0x00, 0x63, 0x00, 0x6b, 0x00, 0x73,
- 0x00, 0x75, 0x00, 0x2e, 0x00, 0x63, 0x00, 0x6f, 0x00, 0x6d, 0x00
- };
- //bancho2 -> c1
- var c1trucksu = new byte[]
- {
- 0x63, 0x00, 0x2e, 0x00, 0x74, 0x00, 0x72, 0x00, 0x75, 0x00, 0x63, 0x00, 0x6b, 0x00, 0x73, 0x00, 0x75,
- 0x00, 0x2e, 0x00, 0x63, 0x00, 0x6f, 0x00, 0x6d, 0x00
- };
- //osush -> osu
- var osutrucksu = new byte[]
- {
- 0x6f, 0x00, 0x73, 0x00, 0x75, 0x00, 0x2e, 0x00, 0x74, 0x00, 0x72, 0x00, 0x75, 0x00, 0x63, 0x00, 0x6b,
- 0x00, 0x73, 0x00, 0x75, 0x00, 0x2e, 0x00,0x63, 0x00, 0x6f, 0x00, 0x6d, 0x00
- };
- osu = Replace(osu, bancho, ctrucksu);
- osu = Replace(osu, bancho2, c1trucksu);
- osu = Replace(osu, osush, osutrucksu);
- osu = Replace(osu, ash, atrucksu);
- System.IO.File.WriteAllBytes(Path + "\\trucksu!.exe", osu);
- }
- }
- private static byte[] Replace(byte[] input, byte[] pattern, byte[] replacement)
- {
- if (pattern.Length == 0)
- {
- return input;
- }
- List<byte> result = new List<byte>();
- int i;
- for (i = 0; i <= input.Length - pattern.Length; i++)
- {
- bool foundMatch = true;
- for (int j = 0; j < pattern.Length; j++)
- {
- if (input[i + j] != pattern[j])
- {
- foundMatch = false;
- break;
- }
- }
- if (foundMatch)
- {
- result.AddRange(replacement);
- i += pattern.Length - 1;
- }
- else
- {
- result.Add(input[i]);
- }
- }
- for (; i < input.Length; i++)
- {
- result.Add(input[i]);
- }
- return result.ToArray();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement