Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/ClusterM/hakchi2.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--FelLib/Fel.cs53
-rw-r--r--GameGenie.cs2
-rw-r--r--NesFile.cs2
-rw-r--r--NesGame.cs1
-rw-r--r--Program.cs92
-rw-r--r--SearchForm.cs6
-rw-r--r--Settings.cs28
-rw-r--r--UnsupportedFourScreenException.cs3
-rw-r--r--UnsupportedMapperException.cs31
-rw-r--r--WaitingForm.cs8
-rw-r--r--WorkerForm.cs47
-rw-r--r--hakchi_gui.csproj1
12 files changed, 111 insertions, 163 deletions
diff --git a/FelLib/Fel.cs b/FelLib/Fel.cs
index 549e71b8..ba618d6d 100644
--- a/FelLib/Fel.cs
+++ b/FelLib/Fel.cs
@@ -11,7 +11,7 @@ namespace com.clusterrr.FelLib
public class Fel
{
public byte[] Fes1Bin;
- public byte[] UBootBin;
+ byte[] uBootBin;
public enum CurrentAction { RunningCommand, ReadingMemory, WritingMemory }
public delegate void OnFelProgress(CurrentAction action, string command);
@@ -25,20 +25,40 @@ namespace com.clusterrr.FelLib
UInt16 vid, pid;
bool DramInitDone = false;
- const UInt32 cmdOffset = 0x604FF;
- const UInt32 fes1_base_m = 0x2000;
- const UInt32 dram_base = 0x40000000;
- const UInt32 flash_mem_base = 0x43800000;
- const UInt32 flash_mem_size = 0x20;
- const UInt32 uboot_base_m = 0x47000000u;
- const UInt32 sector_size = 0x20000;
- const UInt32 uboot_base_f = 0x100000;
- const UInt32 kernel_base_f = (sector_size * 0x30);
- const UInt32 kernel_base_m = flash_mem_base;
- const UInt32 kernel_max_size = (uboot_base_m - flash_mem_base);
- const UInt32 kernel_max_flash_size = (sector_size * 0x20);
+ int cmdOffset = -1;
+ public const UInt32 fes1_base_m = 0x2000;
+ public const UInt32 dram_base = 0x40000000;
+ public const UInt32 flash_mem_base = 0x43800000;
+ public const UInt32 flash_mem_size = 0x20;
+ public const UInt32 uboot_base_m = 0x47000000u;
+ public const UInt32 sector_size = 0x20000;
+ public const UInt32 uboot_base_f = 0x100000;
+ public const UInt32 kernel_base_f = (sector_size * 0x30);
+ public const UInt32 kernel_base_m = flash_mem_base;
+ public const UInt32 kernel_max_size = (uboot_base_m - flash_mem_base);
+ public const UInt32 kernel_max_flash_size = (sector_size * 0x20);
const string fastboot = "fastboot_test";
+ public byte[] UBootBin
+ {
+ get
+ {
+ return uBootBin;
+ }
+
+ set
+ {
+ uBootBin = value;
+ var prefix = "bootcmd=";
+ for (int i = 0; i < uBootBin.Length - prefix.Length; i++)
+ if (Encoding.ASCII.GetString(uBootBin, i, prefix.Length) == prefix)
+ {
+ cmdOffset = i + prefix.Length;
+ break;
+ }
+ }
+ }
+
public static bool DeviceExists(UInt16 vid, UInt16 pid)
{
var fel = new Fel();
@@ -82,14 +102,14 @@ namespace com.clusterrr.FelLib
{
inEndp = pipe.Address;
#if DEBUG
- DebugLog("IN endpoint found: "+ inEndp);
+ DebugLog("IN endpoint found: " + inEndp);
#endif
}
else
{
outEndp = pipe.Address;
#if DEBUG
- DebugLog("Out endpoint found: "+outEndp);
+ DebugLog("Out endpoint found: " + outEndp);
#endif
}
}
@@ -329,7 +349,8 @@ namespace com.clusterrr.FelLib
public void RunUbootCmd(string command, bool noreturn = false, OnFelProgress callback = null)
{
- if (callback != null) callback(CurrentAction.RunningCommand, command);
+ callback?.Invoke(CurrentAction.RunningCommand, command);
+ if (cmdOffset < 0) throw new Exception("Invalid Unoot binary, command variable not found");
const UInt32 testSize = 0x20;
if (UBootBin == null || UBootBin.Length < testSize)
throw new FelException("Can't init Uboot, incorrect Uboot binary");
diff --git a/GameGenie.cs b/GameGenie.cs
index d9be83eb..1d2c11d8 100644
--- a/GameGenie.cs
+++ b/GameGenie.cs
@@ -1,8 +1,6 @@
using System;
using System.Collections.Generic;
-using System.Linq;
using System.Text;
-using System.Windows.Forms;
namespace com.clusterrr.Famicom
{
diff --git a/NesFile.cs b/NesFile.cs
index 5e114486..7dd62d58 100644
--- a/NesFile.cs
+++ b/NesFile.cs
@@ -1,8 +1,6 @@
using System;
using System.Collections.Generic;
using System.IO;
-using System.Linq;
-using System.Text;
using System.Security.Cryptography;
namespace com.clusterrr.Famicom
diff --git a/NesGame.cs b/NesGame.cs
index 76ae8687..c4f38936 100644
--- a/NesGame.cs
+++ b/NesGame.cs
@@ -7,7 +7,6 @@ using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Linq;
-using System.Text;
using System.Text.RegularExpressions;
using System.Windows.Forms;
using System.Xml.XPath;
diff --git a/Program.cs b/Program.cs
index d25745a6..594d8542 100644
--- a/Program.cs
+++ b/Program.cs
@@ -1,47 +1,45 @@
-using System;
-using System.Collections.Generic;
-using System.Diagnostics;
-using System.Linq;
-using System.Runtime.InteropServices;
-using System.Threading;
-using System.Windows.Forms;
-
-namespace com.clusterrr.hakchi_gui
-{
- static class Program
- {
- [DllImport("user32.dll")]
- [return: MarshalAs(UnmanagedType.Bool)]
- static extern bool SetForegroundWindow(IntPtr hWnd);
-
- /// <summary>
- /// The main entry point for the application.
- /// </summary>
- [STAThread]
- static void Main()
- {
- bool createdNew = true;
- using (Mutex mutex = new Mutex(true, "hakchi2", out createdNew))
- {
- if (createdNew)
- {
- Application.EnableVisualStyles();
- Application.SetCompatibleTextRenderingDefault(false);
- Application.Run(new MainForm());
- }
- else
- {
- Process current = Process.GetCurrentProcess();
- foreach (Process process in Process.GetProcessesByName(current.ProcessName))
- {
- if (process.Id != current.Id)
- {
- SetForegroundWindow(process.MainWindowHandle);
- break;
- }
- }
- }
- }
- }
- }
-}
+using System;
+using System.Diagnostics;
+using System.Runtime.InteropServices;
+using System.Threading;
+using System.Windows.Forms;
+
+namespace com.clusterrr.hakchi_gui
+{
+ static class Program
+ {
+ [DllImport("user32.dll")]
+ [return: MarshalAs(UnmanagedType.Bool)]
+ static extern bool SetForegroundWindow(IntPtr hWnd);
+
+ /// <summary>
+ /// The main entry point for the application.
+ /// </summary>
+ [STAThread]
+ static void Main()
+ {
+ bool createdNew = true;
+ using (Mutex mutex = new Mutex(true, "hakchi2", out createdNew))
+ {
+ if (createdNew)
+ {
+ Application.EnableVisualStyles();
+ Application.SetCompatibleTextRenderingDefault(false);
+ Application.Run(new MainForm());
+ }
+ else
+ {
+ Process current = Process.GetCurrentProcess();
+ foreach (Process process in Process.GetProcessesByName(current.ProcessName))
+ {
+ if (process.Id != current.Id)
+ {
+ SetForegroundWindow(process.MainWindowHandle);
+ break;
+ }
+ }
+ }
+ }
+ }
+ }
+}
diff --git a/SearchForm.cs b/SearchForm.cs
index 096ce643..00b15a7f 100644
--- a/SearchForm.cs
+++ b/SearchForm.cs
@@ -1,10 +1,4 @@
using System;
-using System.Collections.Generic;
-using System.ComponentModel;
-using System.Data;
-using System.Drawing;
-using System.Linq;
-using System.Text;
using System.Windows.Forms;
namespace com.clusterrr.hakchi_gui
diff --git a/Settings.cs b/Settings.cs
deleted file mode 100644
index 7859f599..00000000
--- a/Settings.cs
+++ /dev/null
@@ -1,28 +0,0 @@
-namespace com.clusterrr.hakchi_gui.Properties {
-
-
- // This class allows you to handle specific events on the settings class:
- // The SettingChanging event is raised before a setting's value is changed.
- // The PropertyChanged event is raised after a setting's value is changed.
- // The SettingsLoaded event is raised after the setting values are loaded.
- // The SettingsSaving event is raised before the setting values are saved.
- internal sealed partial class Settings {
-
- public Settings() {
- // // To add event handlers for saving and changing settings, uncomment the lines below:
- //
- // this.SettingChanging += this.SettingChangingEventHandler;
- //
- // this.SettingsSaving += this.SettingsSavingEventHandler;
- //
- }
-
- private void SettingChangingEventHandler(object sender, System.Configuration.SettingChangingEventArgs e) {
- // Add code to handle the SettingChangingEvent event here.
- }
-
- private void SettingsSavingEventHandler(object sender, System.ComponentModel.CancelEventArgs e) {
- // Add code to handle the SettingsSaving event here.
- }
- }
-}
diff --git a/UnsupportedFourScreenException.cs b/UnsupportedFourScreenException.cs
index 6af75a7a..d1a4fa34 100644
--- a/UnsupportedFourScreenException.cs
+++ b/UnsupportedFourScreenException.cs
@@ -1,8 +1,5 @@
using com.clusterrr.Famicom;
using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
namespace com.clusterrr.hakchi_gui
{
diff --git a/UnsupportedMapperException.cs b/UnsupportedMapperException.cs
index 5929114a..4d71ec36 100644
--- a/UnsupportedMapperException.cs
+++ b/UnsupportedMapperException.cs
@@ -1,17 +1,14 @@
-using com.clusterrr.Famicom;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-
-namespace com.clusterrr.hakchi_gui
-{
- public class UnsupportedMapperException : Exception
- {
- public readonly NesFile ROM;
- public UnsupportedMapperException(NesFile nesFile)
- {
- ROM = nesFile;
- }
- }
-}
+using com.clusterrr.Famicom;
+using System;
+
+namespace com.clusterrr.hakchi_gui
+{
+ public class UnsupportedMapperException : Exception
+ {
+ public readonly NesFile ROM;
+ public UnsupportedMapperException(NesFile nesFile)
+ {
+ ROM = nesFile;
+ }
+ }
+}
diff --git a/WaitingForm.cs b/WaitingForm.cs
index 7b19d1d2..77ac2ba7 100644
--- a/WaitingForm.cs
+++ b/WaitingForm.cs
@@ -2,15 +2,9 @@
using com.clusterrr.hakchi_gui.Properties;
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.Management;
-using System.Text;
-using System.Threading;
using System.Windows.Forms;
namespace com.clusterrr.hakchi_gui
@@ -29,7 +23,7 @@ namespace com.clusterrr.hakchi_gui
public static bool WaitForDevice(UInt16 vid, UInt16 pid)
{
- if (/*DeviceExists(vid, pid) &&*/ Fel.DeviceExists(vid, pid)) return true;
+ if (Fel.DeviceExists(vid, pid)) return true;
var form = new WaitingForm(vid, pid);
form.ShowDialog();
return form.DialogResult == DialogResult.OK;
diff --git a/WorkerForm.cs b/WorkerForm.cs
index 8cb8575a..204e74f5 100644
--- a/WorkerForm.cs
+++ b/WorkerForm.cs
@@ -1,13 +1,8 @@
using com.clusterrr.Famicom;
using com.clusterrr.FelLib;
using com.clusterrr.hakchi_gui.Properties;
-using MadWizard.WinUSBNet;
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.Text;
@@ -34,19 +29,6 @@ namespace com.clusterrr.hakchi_gui
const UInt16 vid = 0x1F3A;
const UInt16 pid = 0xEFE8;
- const UInt32 cmdOffset = 0x604FF;
- const UInt32 cmdLen = 50;
- const UInt32 fes1_base_m = 0x2000;
- const UInt32 flash_mem_base = 0x43800000;
- const UInt32 flash_mem_size = 0x20;
- const UInt32 uboot_base_m = 0x47000000u;
- const UInt32 sector_size = 0x20000;
- const UInt32 uboot_base_f = 0x100000;
- const UInt32 kernel_base_f = (sector_size * 0x30);
- const UInt32 kernel_base_m = flash_mem_base;
- const UInt32 kernel_max_size = (uboot_base_m - flash_mem_base);
- const UInt32 kernel_max_flash_size = (sector_size * 0x20);
-
readonly string fes1Path;
readonly string ubootPath;
readonly string tempDirectory;
@@ -64,7 +46,6 @@ namespace com.clusterrr.hakchi_gui
readonly string gamesDirectory;
string[] correctKernels;
- bool? waitDeviceResult = null;
public WorkerForm()
{
@@ -215,7 +196,7 @@ namespace com.clusterrr.hakchi_gui
SetProgress(progress, maxProgress);
SetStatus(Resources.DumpingKernel);
- var kernel = fel.ReadFlash(kernel_base_f, sector_size * 0x20,
+ var kernel = fel.ReadFlash(Fel.kernel_base_f, Fel.sector_size * 0x20,
delegate (Fel.CurrentAction action, string command)
{
switch (action)
@@ -233,7 +214,7 @@ namespace com.clusterrr.hakchi_gui
);
var size = CalKernelSize(kernel);
- if (size == 0 || size > kernel_max_size)
+ if (size == 0 || size > Fel.kernel_max_size)
throw new Exception(Resources.InvalidKernelSize + " " + size);
if (kernel.Length > size)
{
@@ -277,11 +258,11 @@ namespace com.clusterrr.hakchi_gui
else
kernel = File.ReadAllBytes(KernelDump);
var size = CalKernelSize(kernel);
- if (size > kernel.Length || size > kernel_max_size)
+ if (size > kernel.Length || size > Fel.kernel_max_size)
throw new Exception(Resources.InvalidKernelSize + " " + size);
- size = (size + sector_size - 1) / sector_size;
- size = size * sector_size;
+ size = (size + Fel.sector_size - 1) / Fel.sector_size;
+ size = size * Fel.sector_size;
if (kernel.Length != size)
{
var newK = new byte[size];
@@ -289,7 +270,7 @@ namespace com.clusterrr.hakchi_gui
kernel = newK;
}
- fel.WriteFlash(kernel_base_f, kernel,
+ fel.WriteFlash(Fel.kernel_base_f, kernel,
delegate (Fel.CurrentAction action, string command)
{
switch (action)
@@ -305,7 +286,7 @@ namespace com.clusterrr.hakchi_gui
SetProgress(progress, maxProgress);
}
);
- var r = fel.ReadFlash((UInt32)kernel_base_f, (UInt32)kernel.Length,
+ var r = fel.ReadFlash((UInt32)Fel.kernel_base_f, (UInt32)kernel.Length,
delegate (Fel.CurrentAction action, string command)
{
switch (action)
@@ -326,7 +307,7 @@ namespace com.clusterrr.hakchi_gui
if (string.IsNullOrEmpty(Mod))
{
- var shutdownCommand = string.Format("shutdown", kernel_base_m);
+ var shutdownCommand = string.Format("shutdown", Fel.kernel_base_m);
SetStatus(Resources.ExecutingCommand + " " + shutdownCommand);
fel.RunUbootCmd(shutdownCommand, true);
}
@@ -346,10 +327,10 @@ namespace com.clusterrr.hakchi_gui
else
kernel = File.ReadAllBytes(KernelDump);
var size = CalKernelSize(kernel);
- if (size > kernel.Length || size > kernel_max_size)
+ if (size > kernel.Length || size > Fel.kernel_max_size)
throw new Exception(Resources.InvalidKernelSize + " " + size);
- size = (size + sector_size - 1) / sector_size;
- size = size * sector_size;
+ size = (size + Fel.sector_size - 1) / Fel.sector_size;
+ size = size * Fel.sector_size;
if (kernel.Length != size)
{
var newK = new byte[size];
@@ -362,7 +343,7 @@ namespace com.clusterrr.hakchi_gui
SetProgress(progress, maxProgress);
SetStatus(Resources.UploadingKernel);
- fel.WriteMemory(flash_mem_base, kernel,
+ fel.WriteMemory(Fel.flash_mem_base, kernel,
delegate (Fel.CurrentAction action, string command)
{
switch (action)
@@ -376,7 +357,7 @@ namespace com.clusterrr.hakchi_gui
}
);
- var bootCommand = string.Format("boota {0:x}", kernel_base_m);
+ var bootCommand = string.Format("boota {0:x}", Fel.kernel_base_m);
SetStatus(Resources.ExecutingCommand + " " + bootCommand);
fel.RunUbootCmd(bootCommand, true);
SetStatus(Resources.Done);
@@ -488,7 +469,7 @@ namespace com.clusterrr.hakchi_gui
var result = File.ReadAllBytes(kernelPatched);
Directory.Delete(tempDirectory, true);
- if (result.Length > kernel_max_size) throw new Exception("Kernel is too big");
+ if (result.Length > Fel.kernel_max_size) throw new Exception("Kernel is too big");
return result;
}
diff --git a/hakchi_gui.csproj b/hakchi_gui.csproj
index e562c49b..56ce76ef 100644
--- a/hakchi_gui.csproj
+++ b/hakchi_gui.csproj
@@ -130,7 +130,6 @@
<Compile Include="SearchForm.Designer.cs">
<DependentUpon>SearchForm.cs</DependentUpon>
</Compile>
- <Compile Include="Settings.cs" />
<Compile Include="UnsupportedFourScreenException.cs" />
<Compile Include="UnsupportedMapperException.cs" />
<Compile Include="WaitingForm.cs">