Formatting (#362)

* adds editorconfig to ensure coherent code style
* formats according to editorconfig
This commit is contained in:
Robert Borg 2020-05-21 16:19:53 +02:00 committed by GitHub
parent 06d51bc176
commit 5290a152da
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 403 additions and 333 deletions

View file

@ -0,0 +1,119 @@
# To learn more about .editorconfig see https://aka.ms/editorconfigdocs
###############################
# Core EditorConfig Options #
###############################
root = true
# All files
[*]
indent_style = tab
# Code files
[*.{cs,csx,vb,vbx}]
indent_size = 4
end_of_line = crlf
insert_final_newline = true
charset = utf-8-bom
###############################
# .NET Coding Conventions #
###############################
[*.{cs,vb}]
# Organize usings
dotnet_sort_system_directives_first = true
# this. preferences
dotnet_style_qualification_for_field = false:silent
dotnet_style_qualification_for_property = false:silent
dotnet_style_qualification_for_method = false:silent
dotnet_style_qualification_for_event = false:silent
# Language keywords vs BCL types preferences
dotnet_style_predefined_type_for_locals_parameters_members = true:silent
dotnet_style_predefined_type_for_member_access = true:silent
# Parentheses preferences
dotnet_style_parentheses_in_arithmetic_binary_operators = always_for_clarity:silent
dotnet_style_parentheses_in_relational_binary_operators = always_for_clarity:silent
dotnet_style_parentheses_in_other_binary_operators = always_for_clarity:silent
dotnet_style_parentheses_in_other_operators = never_if_unnecessary:silent
# Modifier preferences
dotnet_style_require_accessibility_modifiers = for_non_interface_members:silent
dotnet_style_readonly_field = true:suggestion
# Expression-level preferences
dotnet_style_object_initializer = true:suggestion
dotnet_style_collection_initializer = true:suggestion
dotnet_style_explicit_tuple_names = true:suggestion
dotnet_style_null_propagation = true:suggestion
dotnet_style_coalesce_expression = true:suggestion
dotnet_style_prefer_is_null_check_over_reference_equality_method = true:silent
dotnet_style_prefer_inferred_tuple_names = true:suggestion
dotnet_style_prefer_inferred_anonymous_type_member_names = true:suggestion
dotnet_style_prefer_auto_properties = true:silent
dotnet_style_prefer_conditional_expression_over_assignment = true:silent
dotnet_style_prefer_conditional_expression_over_return = true:silent
###############################
# Naming Conventions #
###############################
# Style Definitions
dotnet_naming_style.pascal_case_style.capitalization = pascal_case
# Use PascalCase for constant fields
dotnet_naming_rule.constant_fields_should_be_pascal_case.severity = suggestion
dotnet_naming_rule.constant_fields_should_be_pascal_case.symbols = constant_fields
dotnet_naming_rule.constant_fields_should_be_pascal_case.style = pascal_case_style
dotnet_naming_symbols.constant_fields.applicable_kinds = field
dotnet_naming_symbols.constant_fields.applicable_accessibilities = *
dotnet_naming_symbols.constant_fields.required_modifiers = const
###############################
# C# Coding Conventions #
###############################
[*.cs]
# var preferences
csharp_style_var_for_built_in_types = true:silent
csharp_style_var_when_type_is_apparent = true:silent
csharp_style_var_elsewhere = true:silent
# Expression-bodied members
csharp_style_expression_bodied_methods = false:silent
csharp_style_expression_bodied_constructors = false:silent
csharp_style_expression_bodied_operators = false:silent
csharp_style_expression_bodied_properties = true:silent
csharp_style_expression_bodied_indexers = true:silent
csharp_style_expression_bodied_accessors = true:silent
# Pattern matching preferences
csharp_style_pattern_matching_over_is_with_cast_check = true:suggestion
csharp_style_pattern_matching_over_as_with_null_check = true:suggestion
# Null-checking preferences
csharp_style_throw_expression = true:suggestion
csharp_style_conditional_delegate_call = true:suggestion
# Modifier preferences
csharp_preferred_modifier_order = public,private,protected,internal,static,extern,new,virtual,abstract,sealed,override,readonly,unsafe,volatile,async:suggestion
# Expression-level preferences
csharp_prefer_braces = true:silent
csharp_style_deconstructed_variable_declaration = true:suggestion
csharp_prefer_simple_default_expression = true:suggestion
csharp_style_pattern_local_over_anonymous_function = true:suggestion
csharp_style_inlined_variable_declaration = true:suggestion
###############################
# C# Formatting Rules #
###############################
# New line preferences
csharp_new_line_before_open_brace = false
csharp_new_line_before_else = false
csharp_new_line_before_catch = false
csharp_new_line_before_finally = false
csharp_new_line_before_members_in_object_initializers = true
csharp_new_line_before_members_in_anonymous_types = true
csharp_new_line_between_query_expression_clauses = true
# Indentation preferences
csharp_indent_case_contents = true
csharp_indent_switch_labels = true
csharp_indent_labels = flush_left
# Space preferences
csharp_space_after_cast = false
csharp_space_after_keywords_in_control_flow_statements = true
csharp_space_between_method_call_parameter_list_parentheses = false
csharp_space_between_method_declaration_parameter_list_parentheses = false
csharp_space_between_parentheses = false
csharp_space_before_colon_in_inheritance_clause = true
csharp_space_after_colon_in_inheritance_clause = true
csharp_space_around_binary_operators = before_and_after
csharp_space_between_method_declaration_empty_parameter_list_parentheses = false
csharp_space_between_method_call_name_and_opening_parenthesis = false
csharp_space_between_method_call_empty_parameter_list_parentheses = false
# Wrapping preferences
csharp_preserve_single_line_statements = true
csharp_preserve_single_line_blocks = true

View file

@ -1,9 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BetterJoyForCemu { namespace BetterJoyForCemu {
public static class Config { // stores dynamic configuration, including public static class Config { // stores dynamic configuration, including
@ -13,7 +10,7 @@ namespace BetterJoyForCemu {
const int settingsNum = 10; // currently - ProgressiveScan, StartInTray + special buttons const int settingsNum = 10; // currently - ProgressiveScan, StartInTray + special buttons
public static string GetDefaultValue(string s) { public static string GetDefaultValue(string s) {
switch(s) { switch (s) {
case "ProgressiveScan": case "ProgressiveScan":
return "1"; return "1";
case "capture": case "capture":
@ -32,7 +29,7 @@ namespace BetterJoyForCemu {
int lineNO = 0; int lineNO = 0;
using (StreamReader file = new StreamReader(PATH)) { using (StreamReader file = new StreamReader(PATH)) {
string line = String.Empty; string line = String.Empty;
while ((line = file.ReadLine()) != null) { while ((line = file.ReadLine()) != null) {
string[] vs = line.Split(); string[] vs = line.Split();
try { try {
@ -56,7 +53,7 @@ namespace BetterJoyForCemu {
lineNO++; lineNO++;
} }
} }
// if old settings // if old settings
@ -125,4 +122,4 @@ namespace BetterJoyForCemu {
File.WriteAllLines(PATH, txt); File.WriteAllLines(PATH, txt);
} }
} }
} }

View file

@ -1,192 +1,173 @@
using Nefarius.ViGEm.Client.Targets; using System;
using Nefarius.ViGEm.Client.Targets;
using Nefarius.ViGEm.Client.Targets.DualShock4; using Nefarius.ViGEm.Client.Targets.DualShock4;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms.VisualStyles;
using System.Xml.Serialization;
namespace BetterJoyForCemu.Controller namespace BetterJoyForCemu.Controller {
{ public enum DpadDirection {
public enum DpadDirection None,
{ Northwest,
None, West,
Northwest, Southwest,
West, South,
Southwest, Southeast,
South, East,
Southeast, Northeast,
East, North,
Northeast, }
North,
}
public struct OutputControllerDualShock4InputState public struct OutputControllerDualShock4InputState {
{ public bool triangle;
public bool triangle; public bool circle;
public bool circle; public bool cross;
public bool cross; public bool square;
public bool square;
public bool trigger_left; public bool trigger_left;
public bool trigger_right; public bool trigger_right;
public bool shoulder_left; public bool shoulder_left;
public bool shoulder_right; public bool shoulder_right;
public bool options; public bool options;
public bool share; public bool share;
public bool ps; public bool ps;
public bool touchpad; public bool touchpad;
public bool thumb_left; public bool thumb_left;
public bool thumb_right; public bool thumb_right;
public DpadDirection dPad; public DpadDirection dPad;
public byte thumb_left_x; public byte thumb_left_x;
public byte thumb_left_y; public byte thumb_left_y;
public byte thumb_right_x; public byte thumb_right_x;
public byte thumb_right_y; public byte thumb_right_y;
public byte trigger_left_value; public byte trigger_left_value;
public byte trigger_right_value; public byte trigger_right_value;
public bool IsEqual(OutputControllerDualShock4InputState other) { public bool IsEqual(OutputControllerDualShock4InputState other) {
bool buttons = triangle == other.triangle bool buttons = triangle == other.triangle
&& circle == other.circle && circle == other.circle
&& cross == other.cross && cross == other.cross
&& square == other.square && square == other.square
&& trigger_left == other.trigger_left && trigger_left == other.trigger_left
&& trigger_right == other.trigger_right && trigger_right == other.trigger_right
&& shoulder_left == other.shoulder_left && shoulder_left == other.shoulder_left
&& shoulder_right == other.shoulder_right && shoulder_right == other.shoulder_right
&& options == other.options && options == other.options
&& share == other.share && share == other.share
&& ps == other.ps && ps == other.ps
&& touchpad == other.touchpad && touchpad == other.touchpad
&& thumb_left == other.thumb_left && thumb_left == other.thumb_left
&& thumb_right == other.thumb_right && thumb_right == other.thumb_right
&& dPad == other.dPad; && dPad == other.dPad;
bool axis = thumb_left_x == other.thumb_left_x bool axis = thumb_left_x == other.thumb_left_x
&& thumb_left_y == other.thumb_left_y && thumb_left_y == other.thumb_left_y
&& thumb_right_x == other.thumb_right_x && thumb_right_x == other.thumb_right_x
&& thumb_right_y == other.thumb_right_y; && thumb_right_y == other.thumb_right_y;
bool triggers = trigger_left_value == other.trigger_left_value bool triggers = trigger_left_value == other.trigger_left_value
&& trigger_right_value == other.trigger_right_value; && trigger_right_value == other.trigger_right_value;
return buttons && axis && triggers; return buttons && axis && triggers;
} }
} }
public class OutputControllerDualShock4 public class OutputControllerDualShock4 {
{ private IDualShock4Controller controller;
private IDualShock4Controller controller;
private OutputControllerDualShock4InputState current_state; private OutputControllerDualShock4InputState current_state;
public delegate void DualShock4FeedbackReceivedEventHandler(DualShock4FeedbackReceivedEventArgs e); public delegate void DualShock4FeedbackReceivedEventHandler(DualShock4FeedbackReceivedEventArgs e);
public event DualShock4FeedbackReceivedEventHandler FeedbackReceived; public event DualShock4FeedbackReceivedEventHandler FeedbackReceived;
public OutputControllerDualShock4() public OutputControllerDualShock4() {
{ controller = Program.emClient.CreateDualShock4Controller();
controller = Program.emClient.CreateDualShock4Controller(); Init();
Init(); }
}
public OutputControllerDualShock4(ushort vendor_id, ushort product_id) public OutputControllerDualShock4(ushort vendor_id, ushort product_id) {
{ controller = Program.emClient.CreateDualShock4Controller(vendor_id, product_id);
controller = Program.emClient.CreateDualShock4Controller(vendor_id, product_id); Init();
Init(); }
}
private void Init() private void Init() {
{ controller.AutoSubmitReport = false;
controller.AutoSubmitReport = false; controller.FeedbackReceived += FeedbackReceivedRcv;
controller.FeedbackReceived += FeedbackReceivedRcv; }
}
private void FeedbackReceivedRcv(object _sender, DualShock4FeedbackReceivedEventArgs e) private void FeedbackReceivedRcv(object _sender, DualShock4FeedbackReceivedEventArgs e) {
{ FeedbackReceived(e);
FeedbackReceived(e); }
}
public void Connect() { public void Connect() {
controller.Connect(); controller.Connect();
} }
public void Disconnect() {
controller.Disconnect();
}
public bool UpdateInput(OutputControllerDualShock4InputState new_state) public void Disconnect() {
{ controller.Disconnect();
if(current_state.IsEqual(new_state)) }
{
return false;
}
DoUpdateInput(new_state); public bool UpdateInput(OutputControllerDualShock4InputState new_state) {
if (current_state.IsEqual(new_state)) {
return false;
}
return true; DoUpdateInput(new_state);
}
private void DoUpdateInput(OutputControllerDualShock4InputState new_state) return true;
{ }
controller.SetButtonState(DualShock4Button.Triangle, new_state.triangle);
controller.SetButtonState(DualShock4Button.Circle, new_state.circle);
controller.SetButtonState(DualShock4Button.Cross, new_state.cross);
controller.SetButtonState(DualShock4Button.Square, new_state.square);
controller.SetButtonState(DualShock4Button.ShoulderLeft, new_state.shoulder_left); private void DoUpdateInput(OutputControllerDualShock4InputState new_state) {
controller.SetButtonState(DualShock4Button.ShoulderRight, new_state.shoulder_right); controller.SetButtonState(DualShock4Button.Triangle, new_state.triangle);
controller.SetButtonState(DualShock4Button.Circle, new_state.circle);
controller.SetButtonState(DualShock4Button.Cross, new_state.cross);
controller.SetButtonState(DualShock4Button.Square, new_state.square);
controller.SetButtonState(DualShock4Button.TriggerLeft, new_state.trigger_left); controller.SetButtonState(DualShock4Button.ShoulderLeft, new_state.shoulder_left);
controller.SetButtonState(DualShock4Button.TriggerRight, new_state.trigger_right); controller.SetButtonState(DualShock4Button.ShoulderRight, new_state.shoulder_right);
controller.SetButtonState(DualShock4Button.ThumbLeft, new_state.thumb_left); controller.SetButtonState(DualShock4Button.TriggerLeft, new_state.trigger_left);
controller.SetButtonState(DualShock4Button.ThumbRight, new_state.thumb_left); controller.SetButtonState(DualShock4Button.TriggerRight, new_state.trigger_right);
controller.SetButtonState(DualShock4Button.Share, new_state.share); controller.SetButtonState(DualShock4Button.ThumbLeft, new_state.thumb_left);
controller.SetButtonState(DualShock4Button.Options, new_state.options); controller.SetButtonState(DualShock4Button.ThumbRight, new_state.thumb_left);
controller.SetButtonState(DualShock4SpecialButton.Ps, new_state.ps);
controller.SetButtonState(DualShock4SpecialButton.Touchpad, new_state.touchpad);
controller.SetDPadDirection(MapDPadDirection(new_state.dPad)); controller.SetButtonState(DualShock4Button.Share, new_state.share);
controller.SetButtonState(DualShock4Button.Options, new_state.options);
controller.SetButtonState(DualShock4SpecialButton.Ps, new_state.ps);
controller.SetButtonState(DualShock4SpecialButton.Touchpad, new_state.touchpad);
controller.SetAxisValue(DualShock4Axis.LeftThumbX, new_state.thumb_left_x); controller.SetDPadDirection(MapDPadDirection(new_state.dPad));
controller.SetAxisValue(DualShock4Axis.LeftThumbY, new_state.thumb_left_y);
controller.SetAxisValue(DualShock4Axis.RightThumbX, new_state.thumb_right_x);
controller.SetAxisValue(DualShock4Axis.RightThumbY, new_state.thumb_right_y);
controller.SetSliderValue(DualShock4Slider.LeftTrigger, new_state.trigger_left_value); controller.SetAxisValue(DualShock4Axis.LeftThumbX, new_state.thumb_left_x);
controller.SetSliderValue(DualShock4Slider.RightTrigger, new_state.trigger_right_value); controller.SetAxisValue(DualShock4Axis.LeftThumbY, new_state.thumb_left_y);
controller.SetAxisValue(DualShock4Axis.RightThumbX, new_state.thumb_right_x);
controller.SetAxisValue(DualShock4Axis.RightThumbY, new_state.thumb_right_y);
controller.SubmitReport(); controller.SetSliderValue(DualShock4Slider.LeftTrigger, new_state.trigger_left_value);
controller.SetSliderValue(DualShock4Slider.RightTrigger, new_state.trigger_right_value);
current_state = new_state; controller.SubmitReport();
}
private DualShock4DPadDirection MapDPadDirection(DpadDirection dPad) current_state = new_state;
{ }
switch(dPad)
{ private DualShock4DPadDirection MapDPadDirection(DpadDirection dPad) {
case DpadDirection.None: return DualShock4DPadDirection.None; switch (dPad) {
case DpadDirection.North: return DualShock4DPadDirection.North; case DpadDirection.None: return DualShock4DPadDirection.None;
case DpadDirection.Northeast: return DualShock4DPadDirection.Northeast; case DpadDirection.North: return DualShock4DPadDirection.North;
case DpadDirection.East: return DualShock4DPadDirection.East; case DpadDirection.Northeast: return DualShock4DPadDirection.Northeast;
case DpadDirection.Southeast: return DualShock4DPadDirection.Southeast; case DpadDirection.East: return DualShock4DPadDirection.East;
case DpadDirection.South: return DualShock4DPadDirection.South; case DpadDirection.Southeast: return DualShock4DPadDirection.Southeast;
case DpadDirection.Southwest: return DualShock4DPadDirection.Southwest; case DpadDirection.South: return DualShock4DPadDirection.South;
case DpadDirection.West: return DualShock4DPadDirection.West; case DpadDirection.Southwest: return DualShock4DPadDirection.Southwest;
case DpadDirection.Northwest: return DualShock4DPadDirection.Northwest; case DpadDirection.West: return DualShock4DPadDirection.West;
default: throw new NotImplementedException(); case DpadDirection.Northwest: return DualShock4DPadDirection.Northwest;
} default: throw new NotImplementedException();
} }
} }
}
} }

View file

@ -1,163 +1,150 @@
using Nefarius.ViGEm.Client.Targets; using Nefarius.ViGEm.Client.Targets;
using Nefarius.ViGEm.Client.Targets.Xbox360; using Nefarius.ViGEm.Client.Targets.Xbox360;
using System.Web.UI;
namespace BetterJoyForCemu.Controller namespace BetterJoyForCemu.Controller {
{ public struct OutputControllerXbox360InputState {
public struct OutputControllerXbox360InputState // buttons
{ public bool thumb_stick_left;
// buttons public bool thumb_stick_right;
public bool thumb_stick_left;
public bool thumb_stick_right;
public bool y; public bool y;
public bool x; public bool x;
public bool b; public bool b;
public bool a; public bool a;
public bool start; public bool start;
public bool back; public bool back;
public bool guide; public bool guide;
public bool shoulder_left; public bool shoulder_left;
public bool shoulder_right; public bool shoulder_right;
// dpad // dpad
public bool dpad_up; public bool dpad_up;
public bool dpad_right; public bool dpad_right;
public bool dpad_down; public bool dpad_down;
public bool dpad_left; public bool dpad_left;
// axis // axis
public short axis_left_x; public short axis_left_x;
public short axis_left_y; public short axis_left_y;
public short axis_right_x; public short axis_right_x;
public short axis_right_y; public short axis_right_y;
// triggers // triggers
public byte trigger_left; public byte trigger_left;
public byte trigger_right; public byte trigger_right;
public bool IsEqual(OutputControllerXbox360InputState other) public bool IsEqual(OutputControllerXbox360InputState other) {
{ bool buttons = thumb_stick_left == other.thumb_stick_left
bool buttons = thumb_stick_left == other.thumb_stick_left && thumb_stick_right == other.thumb_stick_right
&& thumb_stick_right == other.thumb_stick_right && y == other.y
&& y == other.y && x == other.x
&& x == other.x && b == other.b
&& b == other.b && a == other.a
&& a == other.a && start == other.start
&& start == other.start && back == other.back
&& back == other.back && guide == other.guide
&& guide == other.guide && shoulder_left == other.shoulder_left
&& shoulder_left == other.shoulder_left && shoulder_right == other.shoulder_right;
&& shoulder_right == other.shoulder_right;
bool dpad = dpad_up == other.dpad_up bool dpad = dpad_up == other.dpad_up
&& dpad_right == other.dpad_right && dpad_right == other.dpad_right
&& dpad_down == other.dpad_down && dpad_down == other.dpad_down
&& dpad_left == other.dpad_left; && dpad_left == other.dpad_left;
bool axis = axis_left_x == other.axis_left_x bool axis = axis_left_x == other.axis_left_x
&& axis_left_y == other.axis_left_y && axis_left_y == other.axis_left_y
&& axis_right_x == other.axis_right_x && axis_right_x == other.axis_right_x
&& axis_right_y == other.axis_right_y; && axis_right_y == other.axis_right_y;
bool triggers = trigger_left == other.trigger_left bool triggers = trigger_left == other.trigger_left
&& trigger_right == other.trigger_right; && trigger_right == other.trigger_right;
return buttons && dpad && axis && triggers; return buttons && dpad && axis && triggers;
} }
} }
public class OutputControllerXbox360 public class OutputControllerXbox360 {
{ private IXbox360Controller xbox_controller;
private IXbox360Controller xbox_controller; private OutputControllerXbox360InputState current_state;
private OutputControllerXbox360InputState current_state;
public delegate void Xbox360FeedbackReceivedEventHandler(Xbox360FeedbackReceivedEventArgs e); public delegate void Xbox360FeedbackReceivedEventHandler(Xbox360FeedbackReceivedEventArgs e);
public event Xbox360FeedbackReceivedEventHandler FeedbackReceived; public event Xbox360FeedbackReceivedEventHandler FeedbackReceived;
public OutputControllerXbox360() public OutputControllerXbox360() {
{ xbox_controller = Program.emClient.CreateXbox360Controller();
xbox_controller = Program.emClient.CreateXbox360Controller(); Init();
Init(); }
}
public OutputControllerXbox360(ushort vendor_id, ushort product_id) public OutputControllerXbox360(ushort vendor_id, ushort product_id) {
{ xbox_controller = Program.emClient.CreateXbox360Controller(vendor_id, product_id);
xbox_controller = Program.emClient.CreateXbox360Controller(vendor_id, product_id); Init();
Init(); }
}
private void Init() private void Init() {
{ xbox_controller.FeedbackReceived += FeedbackReceivedRcv;
xbox_controller.FeedbackReceived += FeedbackReceivedRcv; xbox_controller.AutoSubmitReport = false;
xbox_controller.AutoSubmitReport = false; }
}
private void FeedbackReceivedRcv(object _sender, Xbox360FeedbackReceivedEventArgs e) private void FeedbackReceivedRcv(object _sender, Xbox360FeedbackReceivedEventArgs e) {
{ FeedbackReceived(e);
FeedbackReceived(e); }
}
public bool UpdateInput(OutputControllerXbox360InputState new_state) { public bool UpdateInput(OutputControllerXbox360InputState new_state) {
if (current_state.IsEqual(new_state)) if (current_state.IsEqual(new_state)) {
{ return false;
return false; }
}
DoUpdateInput(new_state); DoUpdateInput(new_state);
return true;
}
public void Connect() return true;
{ }
xbox_controller.Connect();
DoUpdateInput(new OutputControllerXbox360InputState());
}
public void Disconnect() public void Connect() {
{ xbox_controller.Connect();
xbox_controller.Disconnect(); DoUpdateInput(new OutputControllerXbox360InputState());
} }
private void DoUpdateInput(OutputControllerXbox360InputState new_state) public void Disconnect() {
{ xbox_controller.Disconnect();
xbox_controller.SetButtonState(Xbox360Button.LeftThumb, new_state.thumb_stick_left); }
xbox_controller.SetButtonState(Xbox360Button.RightThumb, new_state.thumb_stick_right);
xbox_controller.SetButtonState(Xbox360Button.Y, new_state.y); private void DoUpdateInput(OutputControllerXbox360InputState new_state) {
xbox_controller.SetButtonState(Xbox360Button.X, new_state.x); xbox_controller.SetButtonState(Xbox360Button.LeftThumb, new_state.thumb_stick_left);
xbox_controller.SetButtonState(Xbox360Button.B, new_state.b); xbox_controller.SetButtonState(Xbox360Button.RightThumb, new_state.thumb_stick_right);
xbox_controller.SetButtonState(Xbox360Button.A, new_state.a);
xbox_controller.SetButtonState(Xbox360Button.Start, new_state.start); xbox_controller.SetButtonState(Xbox360Button.Y, new_state.y);
xbox_controller.SetButtonState(Xbox360Button.Back, new_state.back); xbox_controller.SetButtonState(Xbox360Button.X, new_state.x);
xbox_controller.SetButtonState(Xbox360Button.Guide, new_state.guide); xbox_controller.SetButtonState(Xbox360Button.B, new_state.b);
xbox_controller.SetButtonState(Xbox360Button.A, new_state.a);
xbox_controller.SetButtonState(Xbox360Button.Up, new_state.dpad_up); xbox_controller.SetButtonState(Xbox360Button.Start, new_state.start);
xbox_controller.SetButtonState(Xbox360Button.Right, new_state.dpad_right); xbox_controller.SetButtonState(Xbox360Button.Back, new_state.back);
xbox_controller.SetButtonState(Xbox360Button.Down, new_state.dpad_down); xbox_controller.SetButtonState(Xbox360Button.Guide, new_state.guide);
xbox_controller.SetButtonState(Xbox360Button.Left, new_state.dpad_left);
xbox_controller.SetButtonState(Xbox360Button.LeftShoulder, new_state.shoulder_left); xbox_controller.SetButtonState(Xbox360Button.Up, new_state.dpad_up);
xbox_controller.SetButtonState(Xbox360Button.RightShoulder, new_state.shoulder_right); xbox_controller.SetButtonState(Xbox360Button.Right, new_state.dpad_right);
xbox_controller.SetButtonState(Xbox360Button.Down, new_state.dpad_down);
xbox_controller.SetButtonState(Xbox360Button.Left, new_state.dpad_left);
xbox_controller.SetAxisValue(Xbox360Axis.LeftThumbX, new_state.axis_left_x); xbox_controller.SetButtonState(Xbox360Button.LeftShoulder, new_state.shoulder_left);
xbox_controller.SetAxisValue(Xbox360Axis.LeftThumbY, new_state.axis_left_y); xbox_controller.SetButtonState(Xbox360Button.RightShoulder, new_state.shoulder_right);
xbox_controller.SetAxisValue(Xbox360Axis.RightThumbX, new_state.axis_right_x);
xbox_controller.SetAxisValue(Xbox360Axis.RightThumbY, new_state.axis_right_y);
xbox_controller.SetSliderValue(Xbox360Slider.LeftTrigger, new_state.trigger_left); xbox_controller.SetAxisValue(Xbox360Axis.LeftThumbX, new_state.axis_left_x);
xbox_controller.SetSliderValue(Xbox360Slider.RightTrigger, new_state.trigger_right); xbox_controller.SetAxisValue(Xbox360Axis.LeftThumbY, new_state.axis_left_y);
xbox_controller.SetAxisValue(Xbox360Axis.RightThumbX, new_state.axis_right_x);
xbox_controller.SetAxisValue(Xbox360Axis.RightThumbY, new_state.axis_right_y);
xbox_controller.SubmitReport(); xbox_controller.SetSliderValue(Xbox360Slider.LeftTrigger, new_state.trigger_left);
xbox_controller.SetSliderValue(Xbox360Slider.RightTrigger, new_state.trigger_right);
current_state = new_state; xbox_controller.SubmitReport();
}
} current_state = new_state;
}
}
} }

View file

@ -3,11 +3,11 @@ using System.Runtime.InteropServices;
namespace BetterJoyForCemu { namespace BetterJoyForCemu {
public class HIDapi { public class HIDapi {
#if LINUX #if LINUX
const string dll = "libhidapi.so"; const string dll = "libhidapi.so";
#else #else
const string dll = "hidapi.dll"; const string dll = "hidapi.dll";
#endif #endif
public struct hid_device_info { public struct hid_device_info {
[MarshalAs(UnmanagedType.LPStr)] [MarshalAs(UnmanagedType.LPStr)]
@ -40,10 +40,10 @@ namespace BetterJoyForCemu {
public static extern void hid_free_enumeration(IntPtr phid_device_info); public static extern void hid_free_enumeration(IntPtr phid_device_info);
[DllImport(dll, CallingConvention = CallingConvention.Cdecl)] [DllImport(dll, CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr hid_open(ushort vendor_id, ushort product_id, [MarshalAs(UnmanagedType.LPWStr)]string serial_number); public static extern IntPtr hid_open(ushort vendor_id, ushort product_id, [MarshalAs(UnmanagedType.LPWStr)] string serial_number);
[DllImport(dll, CallingConvention = CallingConvention.Cdecl)] [DllImport(dll, CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr hid_open_path([MarshalAs(UnmanagedType.LPStr)]string path); public static extern IntPtr hid_open_path([MarshalAs(UnmanagedType.LPStr)] string path);
[DllImport(dll, CallingConvention = CallingConvention.Cdecl)] [DllImport(dll, CallingConvention = CallingConvention.Cdecl)]
public static extern int hid_write(IntPtr device, byte[] data, UIntPtr length); public static extern int hid_write(IntPtr device, byte[] data, UIntPtr length);
@ -67,16 +67,16 @@ namespace BetterJoyForCemu {
public static extern void hid_close(IntPtr device); public static extern void hid_close(IntPtr device);
[DllImport(dll, CallingConvention = CallingConvention.Cdecl)] [DllImport(dll, CallingConvention = CallingConvention.Cdecl)]
public static extern int hid_get_manufacturer_string(IntPtr device, [MarshalAs(UnmanagedType.LPWStr)]string string_, UIntPtr maxlen); public static extern int hid_get_manufacturer_string(IntPtr device, [MarshalAs(UnmanagedType.LPWStr)] string string_, UIntPtr maxlen);
[DllImport(dll, CallingConvention = CallingConvention.Cdecl)] [DllImport(dll, CallingConvention = CallingConvention.Cdecl)]
public static extern int hid_get_product_string(IntPtr device, [MarshalAs(UnmanagedType.LPWStr)]string string_, UIntPtr maxlen); public static extern int hid_get_product_string(IntPtr device, [MarshalAs(UnmanagedType.LPWStr)] string string_, UIntPtr maxlen);
[DllImport(dll, CallingConvention = CallingConvention.Cdecl)] [DllImport(dll, CallingConvention = CallingConvention.Cdecl)]
public static extern int hid_get_serial_number_string(IntPtr device, [MarshalAs(UnmanagedType.LPWStr)]string string_, UIntPtr maxlen); public static extern int hid_get_serial_number_string(IntPtr device, [MarshalAs(UnmanagedType.LPWStr)] string string_, UIntPtr maxlen);
[DllImport(dll, CallingConvention = CallingConvention.Cdecl)] [DllImport(dll, CallingConvention = CallingConvention.Cdecl)]
public static extern int hid_get_indexed_string(IntPtr device, int string_index, [MarshalAs(UnmanagedType.LPWStr)]string string_, UIntPtr maxlen); public static extern int hid_get_indexed_string(IntPtr device, int string_index, [MarshalAs(UnmanagedType.LPWStr)] string string_, UIntPtr maxlen);
[DllImport(dll, CallingConvention = CallingConvention.Cdecl)] [DllImport(dll, CallingConvention = CallingConvention.Cdecl)]
[return: MarshalAs(UnmanagedType.LPWStr)] [return: MarshalAs(UnmanagedType.LPWStr)]
@ -112,4 +112,4 @@ namespace BetterJoyForCemu {
return _getDevicePath(hid_enumerate(vendorId, productId), usagePage, usage); return _getDevicePath(hid_enumerate(vendorId, productId), usagePage, usage);
} }
} }
} }

View file

@ -1,21 +1,15 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Configuration;
using System.Diagnostics; using System.Diagnostics;
using System.Linq; using System.Linq;
using System.Net.NetworkInformation; using System.Net.NetworkInformation;
using System.Numerics; using System.Numerics;
using System.Configuration;
using System.Threading; using System.Threading;
using System.Threading.Tasks;
using Nefarius.ViGEm.Client;
using Nefarius.ViGEm.Client.Targets;
using Nefarius.ViGEm.Client.Targets.Xbox360;
using System.Runtime.InteropServices;
using System.Windows.Forms; using System.Windows.Forms;
using WindowsInput;
using Nefarius.ViGEm.Client.Targets.DualShock4;
using BetterJoyForCemu.Controller; using BetterJoyForCemu.Controller;
using Nefarius.ViGEm.Client.Targets.DualShock4;
using Nefarius.ViGEm.Client.Targets.Xbox360;
namespace BetterJoyForCemu { namespace BetterJoyForCemu {
public class Joycon { public class Joycon {
@ -1392,4 +1386,4 @@ namespace BetterJoyForCemu {
return output; return output;
} }
} }
} }

View file

@ -1,24 +1,20 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Runtime.InteropServices;
using System.Timers;
using System.Net.NetworkInformation;
using System.Diagnostics;
using static BetterJoyForCemu.HIDapi;
using Nefarius.ViGEm.Client;
using System.Net;
using System.Configuration; using System.Configuration;
using System.Net.Http; using System.Diagnostics;
using System.IO; using System.IO;
using System.Windows.Forms; using System.Linq;
using System.Net;
using System.Net.Http;
using System.Net.NetworkInformation;
using System.Runtime.InteropServices;
using System.ServiceProcess; using System.ServiceProcess;
using System.Text;
using System.Threading;
using System.Timers;
using System.Windows.Forms;
using Nefarius.ViGEm.Client;
using static BetterJoyForCemu.HIDapi;
namespace BetterJoyForCemu { namespace BetterJoyForCemu {
public class JoyconManager { public class JoyconManager {
@ -112,7 +108,7 @@ namespace BetterJoyForCemu {
if (enumerate.serial_number == null) { if (enumerate.serial_number == null) {
ptr = enumerate.next; // can't believe it took me this long to figure out why USB connections used up so much CPU. ptr = enumerate.next; // can't believe it took me this long to figure out why USB connections used up so much CPU.
// it was getting stuck in an inf loop here! // it was getting stuck in an inf loop here!
continue; continue;
} }
@ -173,7 +169,7 @@ namespace BetterJoyForCemu {
bool isPro = enumerate.product_id == product_pro; bool isPro = enumerate.product_id == product_pro;
bool isSnes = enumerate.product_id == product_snes; bool isSnes = enumerate.product_id == product_snes;
j.Add(new Joycon(handle, EnableIMU, EnableLocalize & EnableIMU, 0.05f, isLeft, enumerate.path, enumerate.serial_number, j.Count, isPro, isSnes)); j.Add(new Joycon(handle, EnableIMU, EnableLocalize & EnableIMU, 0.05f, isLeft, enumerate.path, enumerate.serial_number, j.Count, isPro, isSnes));
foundNew = true; foundNew = true;
j.Last().form = form; j.Last().form = form;
@ -539,4 +535,4 @@ namespace BetterJoyForCemu {
} }
} }
} }
} }

View file

@ -1,14 +1,10 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Configuration;
using System.Text;
using System.Threading.Tasks;
using Force.Crc32;
using System.Net; using System.Net;
using System.Net.NetworkInformation; using System.Net.NetworkInformation;
using System.Net.Sockets; using System.Net.Sockets;
using System.Configuration; using Force.Crc32;
namespace BetterJoyForCemu { namespace BetterJoyForCemu {
class UdpServer { class UdpServer {