Skip to content

Commit

Permalink
A lot of bug fixes and new stuffs
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikou27 committed Apr 11, 2022
1 parent b854b92 commit 8a0086c
Show file tree
Hide file tree
Showing 18 changed files with 872 additions and 590 deletions.
2 changes: 1 addition & 1 deletion Master/NucleusCoopTool/Forms/MainForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

385 changes: 139 additions & 246 deletions Master/NucleusCoopTool/Forms/MainForm.cs

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions Master/NucleusCoopTool/Forms/ScriptDownloader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -671,6 +671,7 @@ private void btn_Download_Click(object sender, EventArgs e)

DownloadPrompt downloadPrompt = new DownloadPrompt(handler, mainForm, null);
downloadPrompt.ShowDialog();

}
}

Expand Down
6 changes: 0 additions & 6 deletions Master/NucleusCoopTool/Forms/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
using System.Net.Sockets;
using System.Text.RegularExpressions;
using System.Windows.Forms;
using System.Media;
using System.Diagnostics;

namespace Nucleus.Coop
{
Expand Down Expand Up @@ -830,8 +828,6 @@ private void tabControl2_SelectedIndexChanged(object sender, EventArgs e)
}
}



private void RefreshAudioList()
{
audioDevices = new Dictionary<string, string>();
Expand Down Expand Up @@ -913,7 +909,5 @@ private void scaleOptionCbx_CheckedChanged(object sender, EventArgs e)
}

}


}
}
6 changes: 6 additions & 0 deletions Master/NucleusCoopTool/Nucleus.Coop.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,9 @@
<None Include="copyoutput\utils\XInputPlus\x86\xinput1_3.dl_" />
<None Include="copyoutput\utils\XInputPlus\XInputPlus.ini" />
<None Include="copyoutput\utils\XInputPlus\XInputPlus_Default.ini" />
<None Include="gui\icons\icons.ini">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="gui\theme\default\theme.ini">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
Expand Down Expand Up @@ -441,6 +444,9 @@
<Content Include="gui\covers\covers here.txt">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="gui\icons\default.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="gui\screenshots\screenshots here.txt">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
Expand Down
14 changes: 14 additions & 0 deletions Master/NucleusCoopTool/Program.cs
Original file line number Diff line number Diff line change
@@ -1,20 +1,34 @@
using Nucleus.Gaming;
using Nucleus.Gaming.Windows;
using System;
using System.IO;
using System.Windows.Forms;

namespace Nucleus.Coop
{
static class Program
{

private static readonly IniFile ini = new IniFile(Path.Combine(Directory.GetCurrentDirectory(), "Settings.ini"));

[STAThread]
static void Main()
{
if (!Convert.ToBoolean(ini.IniReadValue("Misc", "NucleusMultiInstances")))
{
if (StartChecks.IsAlredyRunning())
{
return;
}
}

if (!StartChecks.StartCheck())
{
return;
}

StartChecks.CheckFilesIntegrity();
StartChecks.CheckUserEnvironment();
// initialize DPIManager BEFORE setting
// the application to be DPI aware
DPIManager.PreInitialize();
Expand Down
164 changes: 163 additions & 1 deletion Master/NucleusCoopTool/StartChecks.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,170 @@
using System.Windows.Forms;
using Microsoft.Win32;
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Windows.Forms;

namespace Nucleus.Coop
{
internal static class StartChecks
{

static bool isRunning = false;
private static void ExportRegistry(string strKey, string filepath)
{
try
{
using (Process proc = new Process())
{
proc.StartInfo.FileName = "reg.exe";
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.RedirectStandardOutput = true;
proc.StartInfo.RedirectStandardError = true;
proc.StartInfo.CreateNoWindow = true;
proc.StartInfo.Arguments = "export \"" + strKey + "\" \"" + filepath + "\" /y";
proc.Start();
string stdout = proc.StandardOutput.ReadToEnd();
string stderr = proc.StandardError.ReadToEnd();
proc.WaitForExit();
}
}
catch (Exception)
{
// handle exception
}
}

public static bool IsAlredyRunning()
{

if (Process.GetProcessesByName("NucleusCoop").Length > 1)
{
MessageBox.Show("Nucleus Co-op is already running, if you don't see the Nucleus Co-op window it might be running in the background, close the process using task manager.", "Nucleus Co-op is already running", MessageBoxButtons.OK, MessageBoxIcon.Information);
isRunning = true;
}

return isRunning;
}

public static void CheckFilesIntegrity()
{
string[] ncFiles = { "DotNetZip.dll", "EasyHook.dll", "EasyHook32.dll", "EasyHook32Svc.exe", "EasyHook64.dll", "EasyHook64Svc.exe", "EasyHookSvc.exe", "Jint.dll", "NAudio.dll", "Newtonsoft.Json.dll", "Nucleus.Gaming.dll", "Nucleus.Hook32.dll", "Nucleus.Hook64.dll", "Nucleus.IJx64.exe", "Nucleus.IJx86.exe", "Nucleus.SHook32.dll", "Nucleus.SHook64.dll", "openxinput1_3.dll", "ProtoInputHooks32.dll", "ProtoInputHooks64.dll", "ProtoInputHooks64.dll", "ProtoInputHost.exe", "ProtoInputIJ32.exe", "ProtoInputIJ64.exe", "ProtoInputIJP32.dll", "ProtoInputIJP64.dll", "ProtoInputLoader32.dll", "ProtoInputLoader64.dll", "ProtoInputUtilDynamic32.dll", "ProtoInputUtilDynamic64.dll", "SharpDX.DirectInput.dll", "SharpDX.dll", "SharpDX.XInput.dll", "StartGame.exe", "WindowScrape.dll" };

foreach (string file in ncFiles)
{
if (!File.Exists(Path.Combine(Application.StartupPath, file)))
{
MessageBox.Show(file + " is missing from your Nucleus Co-op installation folder.", "Missing file(s)", MessageBoxButtons.OK, MessageBoxIcon.Error);

Process[] processes = Process.GetProcessesByName("NucleusCoop");

foreach (Process NucleusCoop in processes)
{
NucleusCoop.Kill();
}
}
}

if (!Directory.Exists(Path.Combine(Application.StartupPath, @"gui\covers")))
{
Directory.CreateDirectory((Path.Combine(Application.StartupPath, @"gui\covers")));
}

if (!Directory.Exists(Path.Combine(Application.StartupPath, @"gui\screenshots")))
{
Directory.CreateDirectory((Path.Combine(Application.StartupPath, @"gui\screenshots")));
}
}

public static void CheckUserEnvironment()
{
System.Threading.Tasks.Task.Run(() =>
{
try
{
RegistryKey dkey = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders", true);
string mydocPath = dkey.GetValue("Personal").ToString();
if (mydocPath.Contains("NucleusCoop"))
{
string[] environmentRegFileBackup = Directory.GetFiles(Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), "utils\\backup"), "*.reg", SearchOption.AllDirectories);
if (environmentRegFileBackup.Length > 0)
{
foreach (string environmentRegFilePathBackup in environmentRegFileBackup)
{
if (environmentRegFilePathBackup.Contains("User Shell Folders"))
{
Process regproc = new Process();
try
{
regproc.StartInfo.FileName = "reg.exe";
regproc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
regproc.StartInfo.CreateNoWindow = true;
regproc.StartInfo.UseShellExecute = false;
string command = "import \"" + environmentRegFilePathBackup + "\"";
regproc.StartInfo.Arguments = command;
regproc.Start();
regproc.WaitForExit();
}
catch (Exception)
{
regproc.Dispose();
}
}
}
Console.WriteLine("Registry has been restored");
}
}
else if (!File.Exists(Path.Combine(Application.StartupPath, @"utils\backup\User Shell Folders.reg")))
{
ExportRegistry(@"HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders", Path.Combine(Application.StartupPath, @"utils\backup\User Shell Folders.reg"));
}
else
{
if (!Directory.Exists(Path.Combine(Application.StartupPath, @"utils\backup\Temp")))
{
Directory.CreateDirectory((Path.Combine(Application.StartupPath, @"utils\backup\Temp")));
}
ExportRegistry(@"HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders", Path.Combine(Application.StartupPath, @"utils\backup\Temp\User Shell Folders.reg"));
FileStream currentEnvPathBackup = new FileStream(Path.Combine(Application.StartupPath, @"utils\backup\User Shell Folders.reg"), FileMode.Open);
FileStream TempEnvPathBackup = new FileStream(Path.Combine(Application.StartupPath, @"utils\backup\Temp\User Shell Folders.reg"), FileMode.Open);
if (currentEnvPathBackup.Length == TempEnvPathBackup.Length)
{
TempEnvPathBackup.Dispose();
currentEnvPathBackup.Dispose();
File.Delete(Path.Combine(Application.StartupPath, @"utils\backup\Temp\User Shell Folders.reg"));
Directory.Delete(Path.Combine(Application.StartupPath, @"utils\backup\Temp"));
Console.WriteLine("Registry backup is up-to-date");
}
else
{
TempEnvPathBackup.Dispose();
currentEnvPathBackup.Dispose();
File.Delete(Path.Combine(Application.StartupPath, @"utils\backup\User Shell Folders.reg"));
File.Move(Path.Combine(Application.StartupPath, @"utils\backup\Temp\User Shell Folders.reg"), Path.Combine(Application.StartupPath, @"utils\backup\User Shell Folders.reg"));
File.Delete(Path.Combine(Application.StartupPath, @"utils\backup\Temp\User Shell Folders.reg"));
Directory.Delete(Path.Combine(Application.StartupPath, @"utils\backup\Temp"));
Console.WriteLine("Registry has been updated");
}
}
}
catch (Exception)
{
}
});
}

public static bool StartCheck()
{
return CheckInstallFolder();
Expand Down Expand Up @@ -36,5 +197,6 @@ private static bool CheckInstallFolder()

return true;
}

}
}
1 change: 1 addition & 0 deletions Master/NucleusCoopTool/copyoutput/Settings.ini
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,4 @@ Theme=default
[Dev]
SplashScreen_On=True
MouseClick=True
DisableOfflineIcon=False
Loading

0 comments on commit 8a0086c

Please sign in to comment.