mirror of
https://github.com/GittyMac/OpenFK.git
synced 2026-08-05 12:01:56 -05:00
USB support added
This commit is contained in:
parent
a30d8fc169
commit
4863d83e92
22
OpenFK/ConfigForm.Designer.cs
generated
22
OpenFK/ConfigForm.Designer.cs
generated
|
|
@ -35,6 +35,7 @@
|
|||
this.ExitButton = new System.Windows.Forms.Button();
|
||||
this.header = new System.Windows.Forms.Label();
|
||||
this.rdfToggle = new System.Windows.Forms.CheckBox();
|
||||
this.USBToggle = new System.Windows.Forms.CheckBox();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// QualityCB
|
||||
|
|
@ -44,7 +45,7 @@
|
|||
"0 - High",
|
||||
"1 - Medium",
|
||||
"2 - Low"});
|
||||
this.QualityCB.Location = new System.Drawing.Point(12, 104);
|
||||
this.QualityCB.Location = new System.Drawing.Point(12, 129);
|
||||
this.QualityCB.Name = "QualityCB";
|
||||
this.QualityCB.Size = new System.Drawing.Size(121, 21);
|
||||
this.QualityCB.TabIndex = 0;
|
||||
|
|
@ -80,7 +81,7 @@
|
|||
"1 - Crop 4:3",
|
||||
"2 - Stretch 4:3",
|
||||
"3 - Dot by Dot"});
|
||||
this.ScaleCB.Location = new System.Drawing.Point(12, 131);
|
||||
this.ScaleCB.Location = new System.Drawing.Point(12, 156);
|
||||
this.ScaleCB.Name = "ScaleCB";
|
||||
this.ScaleCB.Size = new System.Drawing.Size(121, 21);
|
||||
this.ScaleCB.TabIndex = 3;
|
||||
|
|
@ -88,7 +89,7 @@
|
|||
//
|
||||
// ExitButton
|
||||
//
|
||||
this.ExitButton.Location = new System.Drawing.Point(12, 158);
|
||||
this.ExitButton.Location = new System.Drawing.Point(12, 183);
|
||||
this.ExitButton.Name = "ExitButton";
|
||||
this.ExitButton.Size = new System.Drawing.Size(75, 23);
|
||||
this.ExitButton.TabIndex = 4;
|
||||
|
|
@ -116,11 +117,23 @@
|
|||
this.rdfToggle.UseVisualStyleBackColor = true;
|
||||
this.rdfToggle.CheckedChanged += new System.EventHandler(this.rdfToggle_CheckedChanged);
|
||||
//
|
||||
// USBToggle
|
||||
//
|
||||
this.USBToggle.AutoSize = true;
|
||||
this.USBToggle.Location = new System.Drawing.Point(15, 104);
|
||||
this.USBToggle.Name = "USBToggle";
|
||||
this.USBToggle.Size = new System.Drawing.Size(88, 17);
|
||||
this.USBToggle.TabIndex = 8;
|
||||
this.USBToggle.Text = "USB Support";
|
||||
this.USBToggle.UseVisualStyleBackColor = true;
|
||||
this.USBToggle.CheckedChanged += new System.EventHandler(this.USBToggle_CheckedChanged);
|
||||
//
|
||||
// ConfigForm
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(173, 193);
|
||||
this.ClientSize = new System.Drawing.Size(173, 218);
|
||||
this.Controls.Add(this.USBToggle);
|
||||
this.Controls.Add(this.rdfToggle);
|
||||
this.Controls.Add(this.header);
|
||||
this.Controls.Add(this.ExitButton);
|
||||
|
|
@ -146,5 +159,6 @@
|
|||
private System.Windows.Forms.Button ExitButton;
|
||||
private System.Windows.Forms.Label header;
|
||||
private System.Windows.Forms.CheckBox rdfToggle;
|
||||
private System.Windows.Forms.CheckBox USBToggle;
|
||||
}
|
||||
}
|
||||
|
|
@ -20,6 +20,7 @@ namespace OpenFK
|
|||
rdfToggle.Checked = Properties.Settings.Default.RDF;
|
||||
QualityCB.SelectedIndex = Properties.Settings.Default.Quality;
|
||||
ScaleCB.SelectedIndex = Properties.Settings.Default.ScaleMode;
|
||||
USBToggle.Checked = Properties.Settings.Default.USBSupport;
|
||||
}
|
||||
|
||||
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
|
||||
|
|
@ -71,5 +72,16 @@ namespace OpenFK
|
|||
Properties.Settings.Default.RDF = false;
|
||||
Properties.Settings.Default.Save();
|
||||
}
|
||||
|
||||
private void USBToggle_CheckedChanged(object sender, EventArgs e)
|
||||
{
|
||||
if (USBToggle.Checked)
|
||||
{
|
||||
Properties.Settings.Default.USBSupport = true;
|
||||
}
|
||||
else
|
||||
Properties.Settings.Default.USBSupport = false;
|
||||
Properties.Settings.Default.Save();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
106
OpenFK/Form1.cs
106
OpenFK/Form1.cs
|
|
@ -8,9 +8,11 @@ using System.Data;
|
|||
using System.Diagnostics;
|
||||
using System.Drawing;
|
||||
using System.IO;
|
||||
using System.IO.Pipes;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
|
@ -50,6 +52,19 @@ namespace OpenFK
|
|||
public bool DebugMB;
|
||||
public bool DebugOnline;
|
||||
|
||||
//MegaByte Data
|
||||
private System.Windows.Forms.Timer bittyTimer; //Timer to check connected bitty.
|
||||
|
||||
[DllImport("kernel32.dll")]
|
||||
public static extern IntPtr OpenProcess(int dwDesiredAccess, bool bInheritHandle, int dwProcessId);
|
||||
|
||||
[DllImport("kernel32.dll")]
|
||||
public static extern bool ReadProcessMemory(int hProcess, int lpBaseAddress, byte[] lpBuffer, int dwSize, ref int lpNumberOfBytesRead);
|
||||
const int PROCESS_WM_READ = 0x0010;
|
||||
|
||||
public string bittyID; //Current bitty connected.
|
||||
|
||||
|
||||
//Items
|
||||
public XmlDocument bittyData;
|
||||
public DiscordRpcClient client;
|
||||
|
|
@ -124,26 +139,75 @@ namespace OpenFK
|
|||
|
||||
//USB Initialization
|
||||
|
||||
//MegaByte (Not functional)
|
||||
|
||||
DebugMB = false;
|
||||
|
||||
if (DebugMB == true)
|
||||
if (Settings.Default.USBSupport == true)
|
||||
{
|
||||
Process MBRun = new Process();
|
||||
ProcessStartInfo MBData = new ProcessStartInfo();
|
||||
MBData.FileName = Directory.GetParent(Directory.GetCurrentDirectory()) + @"\MegaByte\" + "MegaByte.exe";
|
||||
MBData.Arguments = "-MBRun -MBDebug";
|
||||
MBData.RedirectStandardOutput = true;
|
||||
MBData.RedirectStandardInput = true;
|
||||
MBData.UseShellExecute = false;
|
||||
MBRun.StartInfo = MBData;
|
||||
MBRun.Start();
|
||||
InitTimer();
|
||||
}
|
||||
|
||||
//End of USB Initialization
|
||||
}
|
||||
|
||||
//
|
||||
//USB READING
|
||||
//
|
||||
public void InitTimer()
|
||||
{
|
||||
bittyTimer = new System.Windows.Forms.Timer();
|
||||
bittyTimer.Tick += new EventHandler(bittyT_Tick);
|
||||
bittyTimer.Interval = 1000;
|
||||
bittyTimer.Start();
|
||||
}
|
||||
|
||||
private void bittyT_Tick(object sender, EventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
Process process = Process.GetProcessesByName("MegaByte")[0]; //Get the process
|
||||
int bytesRead = 0;
|
||||
IntPtr processHandle = OpenProcess(PROCESS_WM_READ, false, process.Id);
|
||||
byte[] buffer = new byte[4]; //BittyID is 4 bytes
|
||||
|
||||
//This reads the memory to fetch the current bittyID
|
||||
ReadProcessMemory((int)processHandle, 0x0049F020, buffer, buffer.Length, ref bytesRead);
|
||||
Int32 baseValue = BitConverter.ToInt32(buffer, 0);
|
||||
|
||||
Int32 firstAddress = baseValue + 0xF88;
|
||||
ReadProcessMemory((int)processHandle, firstAddress, buffer, buffer.Length, ref bytesRead);
|
||||
Int32 firstValue = BitConverter.ToInt32(buffer, 0);
|
||||
|
||||
ReadProcessMemory((int)processHandle, firstValue, buffer, buffer.Length, ref bytesRead);
|
||||
|
||||
//Converts bytes to BittyID
|
||||
int bittyIDInt = BitConverter.ToInt32(buffer, 0);
|
||||
string s = bittyIDInt.ToString("X").PadLeft(8, '0');
|
||||
if (s == "00000000") //If no bitty is connected.
|
||||
{
|
||||
s = "FFFFFFF0";
|
||||
}
|
||||
if (s != bittyID) //If it's still the same, it won't repeat the actions
|
||||
{
|
||||
Debug.WriteLine("BittyID - " + s);
|
||||
bittyID = s;
|
||||
setBitty(s);
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
//
|
||||
//END OF USB READING
|
||||
//
|
||||
|
||||
|
||||
private void flashPlayerAS3_FlashCall(object sender, _IShockwaveFlashEvents_FlashCallEvent e)
|
||||
{
|
||||
Debug.WriteLine("NEW AS3 CALL!" + " - " + e.request);
|
||||
|
|
@ -331,6 +395,11 @@ namespace OpenFK
|
|||
{
|
||||
client.Dispose(); //Disposes RP
|
||||
}
|
||||
if(Settings.Default.USBSupport == true)
|
||||
{
|
||||
Process process = Process.GetProcessesByName("MegaByte")[0];
|
||||
process.Kill();
|
||||
}
|
||||
Application.Exit(); //Closes OpenFK
|
||||
Debug.WriteLine("radicaclose called, goodbye!"); //Debug output
|
||||
}
|
||||
|
|
@ -438,6 +507,11 @@ namespace OpenFK
|
|||
{
|
||||
client.Dispose(); //Disposes RP
|
||||
}
|
||||
if (Settings.Default.USBSupport == true)
|
||||
{
|
||||
Process process = Process.GetProcessesByName("MegaByte")[0];
|
||||
process.Kill();
|
||||
}
|
||||
Application.Exit(); //Closes OpenFK
|
||||
}
|
||||
}
|
||||
|
|
@ -524,12 +598,22 @@ namespace OpenFK
|
|||
{
|
||||
setVar(@"<bitybyte id=""" + bittyID + "00000000" + @""" />");
|
||||
currentBitty = bittyID.ToLower();
|
||||
XmlNodeList nodes = bittyData.SelectNodes("//funkey[@id='" + bittyID + "']");
|
||||
foreach (XmlNode xn in nodes)
|
||||
if (Settings.Default.RPC == true)
|
||||
{
|
||||
currentBittyName = xn.Attributes["name"].Value;
|
||||
try
|
||||
{
|
||||
XmlNodeList nodes = bittyData.SelectNodes("//funkey[@id='" + bittyID + "']");
|
||||
foreach (XmlNode xn in nodes)
|
||||
{
|
||||
currentBittyName = xn.Attributes["name"].Value;
|
||||
}
|
||||
setRP(currentWorld, currentActivity, currentBitty, currentBittyName);
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
setRP(currentWorld, currentActivity, currentBitty, currentBittyName);
|
||||
}
|
||||
|
||||
//
|
||||
|
|
|
|||
14
OpenFK/Properties/Settings.Designer.cs
generated
14
OpenFK/Properties/Settings.Designer.cs
generated
|
|
@ -37,7 +37,7 @@ namespace OpenFK.Properties {
|
|||
|
||||
[global::System.Configuration.UserScopedSettingAttribute()]
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||
[global::System.Configuration.DefaultSettingValueAttribute("True")]
|
||||
[global::System.Configuration.DefaultSettingValueAttribute("False")]
|
||||
public bool RPC {
|
||||
get {
|
||||
return ((bool)(this["RPC"]));
|
||||
|
|
@ -82,5 +82,17 @@ namespace OpenFK.Properties {
|
|||
this["RDF"] = value;
|
||||
}
|
||||
}
|
||||
|
||||
[global::System.Configuration.UserScopedSettingAttribute()]
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||
[global::System.Configuration.DefaultSettingValueAttribute("False")]
|
||||
public bool USBSupport {
|
||||
get {
|
||||
return ((bool)(this["USBSupport"]));
|
||||
}
|
||||
set {
|
||||
this["USBSupport"] = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
<Value Profile="(Default)">True</Value>
|
||||
</Setting>
|
||||
<Setting Name="RPC" Type="System.Boolean" Scope="User">
|
||||
<Value Profile="(Default)">True</Value>
|
||||
<Value Profile="(Default)">False</Value>
|
||||
</Setting>
|
||||
<Setting Name="Quality" Type="System.Int32" Scope="User">
|
||||
<Value Profile="(Default)">0</Value>
|
||||
|
|
@ -17,5 +17,8 @@
|
|||
<Setting Name="RDF" Type="System.Boolean" Scope="User">
|
||||
<Value Profile="(Default)">True</Value>
|
||||
</Setting>
|
||||
<Setting Name="USBSupport" Type="System.Boolean" Scope="User">
|
||||
<Value Profile="(Default)">False</Value>
|
||||
</Setting>
|
||||
</Settings>
|
||||
</SettingsFile>
|
||||
|
|
@ -1,17 +1,17 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<configuration>
|
||||
<configSections>
|
||||
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
|
||||
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<section name="OpenFK.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
|
||||
</sectionGroup>
|
||||
</configSections>
|
||||
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/></startup><userSettings>
|
||||
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" /></startup><userSettings>
|
||||
<OpenFK.Properties.Settings>
|
||||
<setting name="customF" serializeAs="String">
|
||||
<value>True</value>
|
||||
</setting>
|
||||
<setting name="RPC" serializeAs="String">
|
||||
<value>True</value>
|
||||
<value>False</value>
|
||||
</setting>
|
||||
<setting name="Quality" serializeAs="String">
|
||||
<value>0</value>
|
||||
|
|
@ -22,6 +22,17 @@
|
|||
<setting name="RDF" serializeAs="String">
|
||||
<value>True</value>
|
||||
</setting>
|
||||
<setting name="USBSupport" serializeAs="String">
|
||||
<value>False</value>
|
||||
</setting>
|
||||
</OpenFK.Properties.Settings>
|
||||
</userSettings>
|
||||
<runtime>
|
||||
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Buffers" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-4.0.3.0" newVersion="4.0.3.0" />
|
||||
</dependentAssembly>
|
||||
</assemblyBinding>
|
||||
</runtime>
|
||||
</configuration>
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user