Skip to content

Commit

Permalink
pc
Browse files Browse the repository at this point in the history
  • Loading branch information
qnnnnez committed May 28, 2018
1 parent ee1fe9e commit fc24537
Show file tree
Hide file tree
Showing 6 changed files with 358 additions and 0 deletions.
63 changes: 63 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
###############################################################################
# Set default behavior to automatically normalize line endings.
###############################################################################
* text=auto

###############################################################################
# Set default behavior for command prompt diff.
#
# This is need for earlier builds of msysgit that does not have it on by
# default for csharp files.
# Note: This is only used by command line
###############################################################################
#*.cs diff=csharp

###############################################################################
# Set the merge driver for project and solution files
#
# Merging from the command prompt will add diff markers to the files if there
# are conflicts (Merging from VS is not affected by the settings below, in VS
# the diff markers are never inserted). Diff markers may cause the following
# file extensions to fail to load in VS. An alternative would be to treat
# these files as binary and thus will always conflict and require user
# intervention with every merge. To do so, just uncomment the entries below
###############################################################################
#*.sln merge=binary
#*.csproj merge=binary
#*.vbproj merge=binary
#*.vcxproj merge=binary
#*.vcproj merge=binary
#*.dbproj merge=binary
#*.fsproj merge=binary
#*.lsproj merge=binary
#*.wixproj merge=binary
#*.modelproj merge=binary
#*.sqlproj merge=binary
#*.wwaproj merge=binary

###############################################################################
# behavior for image files
#
# image files are treated as binary by default.
###############################################################################
#*.jpg binary
#*.png binary
#*.gif binary

###############################################################################
# diff behavior for common document formats
#
# Convert binary document formats to text before diffing them. This feature
# is only available from the command line. Turn it on by uncommenting the
# entries below.
###############################################################################
#*.doc diff=astextplain
#*.DOC diff=astextplain
#*.docx diff=astextplain
#*.DOCX diff=astextplain
#*.dot diff=astextplain
#*.DOT diff=astextplain
#*.pdf diff=astextplain
#*.PDF diff=astextplain
#*.rtf diff=astextplain
#*.RTF diff=astextplain
10 changes: 10 additions & 0 deletions pc/App.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
</startup>
<appSettings>
<add key="bindAddr" value="0.0.0.0" />
<add key="bindPort" value="51237" />
</appSettings>
</configuration>
167 changes: 167 additions & 0 deletions pc/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Nefarius.ViGEm.Client;
using Nefarius.ViGEm.Client.Targets;
using Nefarius.ViGEm.Client.Targets.Xbox360;
using Nefarius.ViGEm.Client.Targets.DualShock4;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.Threading;
using System.Net;
using System.Net.Sockets;
using System.Configuration;

namespace X3DS
{
struct CirclePosition
{
public Int16 dx;
public Int16 dy;
}

struct TouchPosition
{
public UInt16 px;
public UInt16 py;
}

struct InputStatus
{
public UInt32 kDown;
public UInt32 kHeld;
public UInt32 kUp;
public CirclePosition pad;
public CirclePosition cstick;
public TouchPosition touch;
}



class Program
{
static Xbox360Buttons?[] X3DSMap = new Xbox360Buttons?[] {
Xbox360Buttons.A,
Xbox360Buttons.B,
Xbox360Buttons.Back,
Xbox360Buttons.Start,
Xbox360Buttons.Right,
Xbox360Buttons.Left,
Xbox360Buttons.Up,
Xbox360Buttons.Down,
Xbox360Buttons.RightShoulder,
Xbox360Buttons.LeftShoulder,
Xbox360Buttons.X,
Xbox360Buttons.Y,
null, null,
null, //zl
null, //zr
null, null, null, null,
null, //touch
null, null, null, null, //cstick right left up down
null, null, null, null, //pad
null, null, null, null, null
};

static void Main(string[] args)
{
var client = new ViGEmClient();
var x360 = new Xbox360Controller(client);

IPEndPoint ipep = new IPEndPoint(IPAddress.Parse(ConfigurationManager.AppSettings["bindAddr"]), UInt16.Parse(ConfigurationManager.AppSettings["bindPort"]));
UdpClient newsock = new UdpClient(ipep);
IPEndPoint senderep = new IPEndPoint(IPAddress.Any, 0);

x360.FeedbackReceived +=
(sender, eventArgs) =>
{

};

x360.Connect();
Console.WriteLine("Controller connected.");

Console.WriteLine("Listening on {0}", ipep);

var report = new Xbox360Report();
var lastRecv = DateTime.Now;
float tt = 0;
int second_counter = 0;
while (true)
{
var dt_t = DateTime.Now - lastRecv;
lastRecv = DateTime.Now;
float dt = dt_t.Milliseconds / 1000.0f;
InputStatus status;
unsafe
{
fixed(byte *data = &newsock.Receive(ref senderep)[0])
{
InputStatus* s = (InputStatus*)data;
status = *s;
}
}
report.Buttons = 0;
for (int i=0; i<32; ++i)
{
if ((status.kHeld & (1 << i)) != 0)
{
Xbox360Buttons? button = X3DSMap[i];
if (button != null)
{
report.SetButtons(button.Value);
}
}
}
if (status.touch.px > 0 && status.touch.py > 0)
{
if (status.touch.px < 320 / 3)
{
report.SetButtons(Xbox360Buttons.LeftThumb);
}
else if (status.touch.px > 320 / 3 * 2)
{
report.SetButtons(Xbox360Buttons.RightThumb);
}
else
{
report.SetButtons(Xbox360Buttons.LeftThumb, Xbox360Buttons.RightThumb);
}
}
report.SetAxis(Xbox360Axes.LeftThumbX, (short)((float)status.pad.dx * Int16.MaxValue / 160.0f));
report.SetAxis(Xbox360Axes.LeftThumbY, (short)((float)status.pad.dy * Int16.MaxValue / 160.0f));
report.SetAxis(Xbox360Axes.RightThumbX, (short)((float)status.cstick.dx * Int16.MaxValue / 160.0f));
report.SetAxis(Xbox360Axes.RightThumbY, (short)((float)status.cstick.dy * Int16.MaxValue / 160.0f));
if ((status.kHeld & (1 << 14)) != 0)
{
report.SetAxis(Xbox360Axes.LeftTrigger, Int16.MaxValue);
}
else
{
report.SetAxis(Xbox360Axes.LeftTrigger, Int16.MinValue);
}
if ((status.kHeld & (1 << 15)) != 0)
{
report.SetAxis(Xbox360Axes.RightTrigger, Int16.MaxValue);
}
else
{
report.SetAxis(Xbox360Axes.RightTrigger, Int16.MinValue);
}
x360.SendReport(report);

second_counter++;
tt += dt;
if (tt > 1.0f)
{
Console.WriteLine("{0} packet received", second_counter);
tt = 0;
second_counter = 0;
}
}
Console.ReadKey();
}
}
}
36 changes: 36 additions & 0 deletions pc/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("X3DS")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("X3DS")]
[assembly: AssemblyCopyright("Copyright © 2018")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("4b3c911d-4d60-4767-b555-3543327050ea")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
76 changes: 76 additions & 0 deletions pc/X3DS.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{4B3C911D-4D60-4767-B555-3543327050EA}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>X3DS</RootNamespace>
<AssemblyName>X3DS</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Costura, Version=1.6.2.0, Culture=neutral, PublicKeyToken=9919ef960d84173d, processorArchitecture=MSIL">
<HintPath>packages\Costura.Fody.1.6.2\lib\dotnet\Costura.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="Nefarius.ViGEmClient, Version=1.15.16.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>packages\Nefarius.ViGEmClient.1.15.16\lib\net452\Nefarius.ViGEmClient.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Configuration" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<None Include="FodyWeavers.xml" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="packages\Fody.2.2.0\build\net452\Fody.targets" Condition="Exists('packages\Fody.2.2.0\build\net452\Fody.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('packages\Fody.2.2.0\build\net452\Fody.targets')" Text="$([System.String]::Format('$(ErrorText)', 'packages\Fody.2.2.0\build\net452\Fody.targets'))" />
<Error Condition="!Exists('packages\Costura.Fody.1.6.2\build\dotnet\Costura.Fody.targets')" Text="$([System.String]::Format('$(ErrorText)', 'packages\Costura.Fody.1.6.2\build\dotnet\Costura.Fody.targets'))" />
</Target>
<Import Project="packages\Costura.Fody.1.6.2\build\dotnet\Costura.Fody.targets" Condition="Exists('packages\Costura.Fody.1.6.2\build\dotnet\Costura.Fody.targets')" />
</Project>
6 changes: 6 additions & 0 deletions pc/packages.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Costura.Fody" version="1.6.2" targetFramework="net461" developmentDependency="true" />
<package id="Fody" version="2.2.0" targetFramework="net461" developmentDependency="true" />
<package id="Nefarius.ViGEmClient" version="1.15.16" targetFramework="net461" />
</packages>

0 comments on commit fc24537

Please sign in to comment.