Skip to content

Commit db90d83

Browse files
committed
Version 4 - Added HidGuardian support and implemented a GUI
1 parent 32aca0a commit db90d83

9 files changed

Lines changed: 1705 additions & 25 deletions

File tree

BetterJoyForCemu/App.config

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,10 @@
3030
<!--Also swaps buttons when using "Also use for buttons/axes"-->
3131
<!--On is "true"; off is "false". Default: false -->
3232
<add key="SwapButtons" value="false" />
33+
34+
<!-- Determines whether or not HidGuardian's process whitelist is purged on start-up -->
35+
<!-- Can interfere with other programs using HidGuardian, but prevents whitelist from being clogged from crashed instances -->
36+
<!-- Default: true -->
37+
<add key="PurgeWhitelist" value="true"/>
3338
</appSettings>
3439
</configuration>

BetterJoyForCemu/BetterJoyForCemu.csproj

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
66
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
77
<ProjectGuid>{1BF709E9-C133-41DF-933A-C9FF3F664C7B}</ProjectGuid>
8-
<OutputType>Exe</OutputType>
8+
<OutputType>WinExe</OutputType>
99
<RootNamespace>BetterJoyForCemu</RootNamespace>
1010
<AssemblyName>BetterJoyForCemu</AssemblyName>
1111
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
@@ -71,13 +71,23 @@
7171
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
7272
<Prefer32Bit>true</Prefer32Bit>
7373
</PropertyGroup>
74+
<PropertyGroup>
75+
<StartupObject>
76+
</StartupObject>
77+
</PropertyGroup>
78+
<PropertyGroup>
79+
<ApplicationIcon>betterjoyforcemu_icon.ico</ApplicationIcon>
80+
</PropertyGroup>
7481
<ItemGroup>
7582
<Reference Include="Crc32.NET, Version=1.0.0.0, Culture=neutral, PublicKeyToken=dc0b95cf99bf4e99, processorArchitecture=MSIL">
7683
<HintPath>..\packages\Crc32.NET.1.2.0\lib\net20\Crc32.NET.dll</HintPath>
7784
</Reference>
7885
<Reference Include="System" />
7986
<Reference Include="System.Core" />
87+
<Reference Include="System.Drawing" />
8088
<Reference Include="System.Numerics" />
89+
<Reference Include="System.ServiceProcess" />
90+
<Reference Include="System.Windows.Forms" />
8191
<Reference Include="System.Xml.Linq" />
8292
<Reference Include="System.Data.DataSetExtensions" />
8393
<Reference Include="Microsoft.CSharp" />
@@ -88,6 +98,12 @@
8898
<ItemGroup>
8999
<Compile Include="HIDapi.cs" />
90100
<Compile Include="Joycon.cs" />
101+
<Compile Include="MainForm.cs">
102+
<SubType>Form</SubType>
103+
</Compile>
104+
<Compile Include="MainForm.Designer.cs">
105+
<DependentUpon>MainForm.cs</DependentUpon>
106+
</Compile>
91107
<Compile Include="Program.cs" />
92108
<Compile Include="Properties\AssemblyInfo.cs" />
93109
<Compile Include="UpdServer.cs" />
@@ -97,6 +113,7 @@
97113
<None Include="packages.config" />
98114
</ItemGroup>
99115
<ItemGroup>
116+
<Content Include="betterjoyforcemu_icon.ico" />
100117
<Content Include="hidapi.dll">
101118
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
102119
</Content>
@@ -107,5 +124,10 @@
107124
<Name>ViGEmClient</Name>
108125
</ProjectReference>
109126
</ItemGroup>
127+
<ItemGroup>
128+
<EmbeddedResource Include="MainForm.resx">
129+
<DependentUpon>MainForm.cs</DependentUpon>
130+
</EmbeddedResource>
131+
</ItemGroup>
110132
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
111133
</Project>

BetterJoyForCemu/Joycon.cs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,8 @@ public byte[] GetData() {
211211

212212
bool toRumble = Boolean.Parse(ConfigurationSettings.AppSettings["EnableRumble"]);
213213

214+
public MainForm form;
215+
214216
public Joycon(IntPtr handle_, bool imu, bool localize, float alpha, bool left, int id = 0, bool isPro=false, bool usb = false) {
215217
handle = handle_;
216218
imu_enabled = imu;
@@ -243,7 +245,7 @@ public void ReceiveRumble(object sender, Nefarius.ViGEm.Client.Targets.Xbox360.X
243245
public void DebugPrint(String s, DebugType d) {
244246
if (debug_type == DebugType.NONE) return;
245247
if (d == DebugType.ALL || d == debug_type || debug_type == DebugType.ALL) {
246-
Console.WriteLine(s);
248+
form.console.Text += s + "\r\n";
247249
}
248250
}
249251
public bool GetButtonDown(Button b) {
@@ -285,7 +287,7 @@ public int Attach(byte leds_ = 0x0) {
285287
Subcommand(0x03, new byte[] { 0x3f }, 1, false);
286288

287289
a = Enumerable.Repeat((byte)0, 64).ToArray();
288-
Console.WriteLine("Using USB.");
290+
form.console.Text += "Using USB.\r\n";
289291

290292
a[0] = 0x80;
291293
a[1] = 0x01;
@@ -378,7 +380,7 @@ private int ReceiveRaw() {
378380
}
379381

380382
if (ts_en == raw_buf[1]) {
381-
Console.WriteLine("Duplicate timestamp enqueued.");
383+
form.console.Text += "Duplicate timestamp enqueued.\r\n";
382384
DebugPrint(string.Format("Duplicate timestamp enqueued. TS: {0:X2}", ts_en), DebugType.THREADING);
383385
}
384386
ts_en = raw_buf[1];
@@ -399,7 +401,7 @@ private void Poll() {
399401
attempts = 0;
400402
} else if (attempts > 1000) {
401403
state = state_.DROPPED;
402-
Console.WriteLine("Dropped");
404+
//form.console.Text += "Dropped\r\n";
403405
DebugPrint("Connection lost. Is the Joy-Con connected?", DebugType.ALL);
404406
break;
405407
} else {
@@ -609,7 +611,7 @@ public void Begin() {
609611
PollThreadObj = new Thread(new ThreadStart(Poll));
610612
PollThreadObj.Start();
611613

612-
Console.WriteLine("Starting poll thread.");
614+
form.console.Text += "Starting poll thread.\r\n";
613615
}
614616
}
615617

@@ -675,13 +677,13 @@ private void dump_calibration_data() {
675677
bool found = false;
676678
for (int i = 0; i < 9; ++i) {
677679
if (buf_[i] != 0xff) {
678-
Console.WriteLine("Using user stick calibration data.");
680+
form.console.Text += "Using user stick calibration data.\r\n";
679681
found = true;
680682
break;
681683
}
682684
}
683685
if (!found) {
684-
Console.WriteLine("Using factory stick calibration data.");
686+
form.console.Text += "Using factory stick calibration data.\r\n";
685687
buf_ = ReadSPI(0x60, (isLeft ? (byte)0x3d : (byte)0x46), 9); // get user calibration data if possible
686688
}
687689
stick_cal[isLeft ? 0 : 2] = (UInt16)((buf_[1] << 8) & 0xF00 | buf_[0]); // X Axis Max above center
@@ -698,13 +700,13 @@ private void dump_calibration_data() {
698700
found = false;
699701
for (int i = 0; i < 9; ++i) {
700702
if (buf_[i] != 0xff) {
701-
Console.WriteLine("Using user stick calibration data.");
703+
form.console.Text += "Using user stick calibration data.\r\n";
702704
found = true;
703705
break;
704706
}
705707
}
706708
if (!found) {
707-
Console.WriteLine("Using factory stick calibration data.");
709+
form.console.Text += "Using factory stick calibration data.\r\n";
708710
buf_ = ReadSPI(0x60, (!isLeft ? (byte)0x3d : (byte)0x46), 9); // get user calibration data if possible
709711
}
710712
stick2_cal[!isLeft ? 0 : 2] = (UInt16)((buf_[1] << 8) & 0xF00 | buf_[0]); // X Axis Max above center

BetterJoyForCemu/MainForm.Designer.cs

Lines changed: 118 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

BetterJoyForCemu/MainForm.cs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.ComponentModel;
4+
using System.Data;
5+
using System.Drawing;
6+
using System.Linq;
7+
using System.Text;
8+
using System.Threading.Tasks;
9+
using System.Windows.Forms;
10+
11+
namespace BetterJoyForCemu {
12+
public partial class MainForm : Form {
13+
public MainForm() {
14+
InitializeComponent();
15+
}
16+
17+
private void MainForm_Resize(object sender, EventArgs e) {
18+
if (this.WindowState == FormWindowState.Minimized) {
19+
notifyIcon.Visible = true;
20+
notifyIcon.ShowBalloonTip(1);
21+
this.ShowInTaskbar = false;
22+
}
23+
}
24+
25+
private void notifyIcon_MouseDoubleClick(object sender, MouseEventArgs e) {
26+
this.WindowState = FormWindowState.Normal;
27+
this.ShowInTaskbar = true;
28+
notifyIcon.Visible = false;
29+
}
30+
31+
private void MainForm_Load(object sender, EventArgs e) {
32+
this.ShowInTaskbar = true;
33+
notifyIcon.Visible = false;
34+
35+
Program.Start();
36+
}
37+
38+
private void MainForm_FormClosing(object sender, FormClosingEventArgs e) {
39+
Program.Stop();
40+
}
41+
42+
private void exitToolStripMenuItem_Click(object sender, EventArgs e) {
43+
Program.Stop();
44+
Application.Exit();
45+
}
46+
}
47+
}

0 commit comments

Comments
 (0)