Skip to content

Commit

Permalink
Updated title editing to store process IDs and show windows that have…
Browse files Browse the repository at this point in the history
… been renamed.
  • Loading branch information
Mr-Technician committed Apr 26, 2020
1 parent e7d0de9 commit d7655ea
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 8 deletions.
14 changes: 11 additions & 3 deletions BorderlessMinecraft/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ namespace BorderlessMinecraft
public partial class Form1 : Form
{
Process[] minecraftProcesses; //initializes an array of processess
List<int> renamedProcesses = new List<int>(); //PIDs that are renamed

public Form1()
{
Expand Down Expand Up @@ -87,11 +88,11 @@ private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs

if (checkBox3.Checked) //if the checkbox is checked, no title filtering will occur
{
minecraftProcesses = Program.getProcesses();
minecraftProcesses = Program.getProcesses(renamedProcesses);
}
else //if not, filter titles by the word "minecraft"
{
minecraftProcesses = Program.getProcesses("Minecraft");
minecraftProcesses = Program.getProcesses(renamedProcesses, "Minecraft");
}

foreach (Process proc in minecraftProcesses)
Expand Down Expand Up @@ -185,19 +186,26 @@ private void listBox1_SelectedIndexChanged_1(object sender, EventArgs e)
private void button3_Click(object sender, EventArgs e) //edit title button
{
IntPtr handle = minecraftProcesses[listBox1.SelectedIndex].MainWindowHandle; //gets the minecraft process by index, and then its handle
int PID = minecraftProcesses[listBox1.SelectedIndex].Id;
string currentTitle = minecraftProcesses[listBox1.SelectedIndex].MainWindowTitle; //gets the minecraft process by index, and then its title
string title;
if (textBox5.Text != "") //if the textbox has content, use for title
{
title = currentTitle + " " + textBox5.Text;
title = textBox5.Text;

}
else //if the textbox is empty, use default
{
title = currentTitle + " (Second Account)";
}
Program.setTitle(handle, title);
if (!renamedProcesses.Contains(PID)) //if the renamed handle is not currently stored, add it. This allows borderless minecraft to detect windows that have been renamed
{
renamedProcesses.Add(PID);
}

addProcesses(); //after rename, refresh the list
textBox5.Text = ""; //reset text
}

private void button4_Click(object sender, EventArgs e) //restore window button
Expand Down
22 changes: 17 additions & 5 deletions BorderlessMinecraft/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,31 @@ static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
Application.Run(new Form1()
{
Text = "Borderless Minecraft 1.2.2"
});
}

public static Process[] getProcesses(string startsWith = "")
public static Process[] getProcesses(List<int> processIDs, string startsWith = "")
{
Process[] allProcesses = Process.GetProcesses(); //gets an array of all system processes
ArrayList processes = new ArrayList();
List<Process> processes = new List<Process>();
foreach (Process proc in allProcesses)
{
if (proc.MainWindowTitle.StartsWith(startsWith) && proc.ProcessName == "javaw") //checks for Minecraft in the title and the java process
if (proc.MainWindowTitle.StartsWith(startsWith) && proc.ProcessName == "javaw" && !processIDs.Contains(proc.Id)) //checks for Minecraft in the title and the java process OR its handle matches
processes.Add(proc);
}
return processes.ToArray(typeof(Process)) as Process[]; //converts dynamic arraylist to static array

foreach (int PID in processIDs)
{
try
{
processes.Add(Process.GetProcessById(PID)); //adds each process by ID
}
catch (ArgumentException) { }
}
return processes.Distinct().ToArray() as Process[]; //converts dynamic arraylist to static array
}

[DllImport("user32.dll")]
Expand Down

0 comments on commit d7655ea

Please sign in to comment.