Skip to content

Commit

Permalink
Add FreePIE plugin project.
Browse files Browse the repository at this point in the history
  • Loading branch information
polygraphene committed Jun 24, 2018
1 parent a54f522 commit 2d2648d
Show file tree
Hide file tree
Showing 5 changed files with 318 additions and 0 deletions.
14 changes: 14 additions & 0 deletions ALVR.sln
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "alvr_server", "alvr_server\
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "CUDA", "CUDA\CUDA.vcxproj", "{12336478-A663-42F8-8D52-8D093CD99992}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ALVRFreePIE", "ALVRFreePIE\ALVRFreePIE.csproj", "{D39838EE-67A1-4D76-8CFA-C1AAE99C2920}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -61,6 +63,18 @@ Global
{12336478-A663-42F8-8D52-8D093CD99992}.Release|Win32.ActiveCfg = Release|x64
{12336478-A663-42F8-8D52-8D093CD99992}.Release|x64.ActiveCfg = Release|x64
{12336478-A663-42F8-8D52-8D093CD99992}.Release|x64.Build.0 = Release|x64
{D39838EE-67A1-4D76-8CFA-C1AAE99C2920}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D39838EE-67A1-4D76-8CFA-C1AAE99C2920}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D39838EE-67A1-4D76-8CFA-C1AAE99C2920}.Debug|Win32.ActiveCfg = Debug|Any CPU
{D39838EE-67A1-4D76-8CFA-C1AAE99C2920}.Debug|Win32.Build.0 = Debug|Any CPU
{D39838EE-67A1-4D76-8CFA-C1AAE99C2920}.Debug|x64.ActiveCfg = Debug|Any CPU
{D39838EE-67A1-4D76-8CFA-C1AAE99C2920}.Debug|x64.Build.0 = Debug|Any CPU
{D39838EE-67A1-4D76-8CFA-C1AAE99C2920}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D39838EE-67A1-4D76-8CFA-C1AAE99C2920}.Release|Any CPU.Build.0 = Release|Any CPU
{D39838EE-67A1-4D76-8CFA-C1AAE99C2920}.Release|Win32.ActiveCfg = Release|Any CPU
{D39838EE-67A1-4D76-8CFA-C1AAE99C2920}.Release|Win32.Build.0 = Release|Any CPU
{D39838EE-67A1-4D76-8CFA-C1AAE99C2920}.Release|x64.ActiveCfg = Release|Any CPU
{D39838EE-67A1-4D76-8CFA-C1AAE99C2920}.Release|x64.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
50 changes: 50 additions & 0 deletions ALVRFreePIE/ALVRFreePIE.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?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>{D39838EE-67A1-4D76-8CFA-C1AAE99C2920}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>ALVRFreePIE</RootNamespace>
<AssemblyName>ALVRFreePIE</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="FreePIE.Core.Contracts">
<HintPath>..\..\..\Program Files (x86)\FreePIE\FreePIE.Core.Contracts.dll</HintPath>
</Reference>
<Reference Include="System" />
<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="ALVRFreePIEPlugin.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
215 changes: 215 additions & 0 deletions ALVRFreePIE/ALVRFreePIEPlugin.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,215 @@
using FreePIE.Core.Contracts;
using System;
using System.Collections.Generic;
using System.IO;
using System.IO.MemoryMappedFiles;
using System.Threading;

namespace ALVRFreePIE
{
[GlobalType(Type = typeof(ALVRFreePIEPlugin))]
public class ALVRFreePIEPlugin
{
ALVRFreePIEPluginGlobal global;
public object CreateGlobal()
{
return global = new ALVRFreePIEPluginGlobal(this);
}

public Action Start()
{
return null;
}

public void Stop()
{
}

public event EventHandler Started;

public string FriendlyName
{
get { return "ALVR FreePIE Plugin"; }
}

public bool GetProperty(int index, IPluginProperty property)
{
return false;
}

public bool SetProperties(Dictionary<string, object> properties)
{
return true;
}

public void DoBeforeNextExecute()
{
CheckMemoryMappedFileExistence();
if (memoryMappedFile != null)
{
try
{
mutex.WaitOne(0);

UInt32 flags = 0;
UInt32 controllerOverrideButtons = 0;
UInt32 controllerButtons = 0;

using (var mappedStream = memoryMappedFile.CreateViewStream())
{
var reader = new BinaryReader(mappedStream);

UInt32 version = reader.ReadUInt32();
if (version == ALVR_FREEPIE_SIGNATURE_V1)
{
flags = reader.ReadUInt32();
// Head orientation
double yaw = reader.ReadDouble();
double pitch = reader.ReadDouble();
double roll = reader.ReadDouble();
// Head position
double[] head_position = new double[3];
head_position[0] = reader.ReadDouble();
head_position[1] = reader.ReadDouble();
head_position[2] = reader.ReadDouble();

controllerOverrideButtons = reader.ReadUInt32();
controllerButtons = reader.ReadUInt32();
}
}

using (var mappedStream = memoryMappedFile.CreateViewStream())
{
mappedStream.Seek(sizeof(UInt32), SeekOrigin.Current);
if (global.override_head_orientation) {
flags |= ALVR_FREEPIE_FLAG_OVERRIDE_HEAD_ORIENTATION;
}
if (global.override_head_position)
{
flags |= ALVR_FREEPIE_FLAG_OVERRIDE_HEAD_POSITION;
}
if (global.override_controller_orientation)
{
flags |= ALVR_FREEPIE_FLAG_OVERRIDE_CONTROLLER_ORIENTATION;
}
if (global.override_controller_position)
{
flags |= ALVR_FREEPIE_FLAG_OVERRIDE_CONTROLLER_POSITION;
}

mappedStream.Write(BitConverter.GetBytes(flags), 0, sizeof(UInt32));

if (global.override_head_orientation)
{
mappedStream.Write(BitConverter.GetBytes(global.head_orientation[0]), 0, sizeof(double));
mappedStream.Write(BitConverter.GetBytes(global.head_orientation[1]), 0, sizeof(double));
mappedStream.Write(BitConverter.GetBytes(global.head_orientation[2]), 0, sizeof(double));
}
else
{
mappedStream.Seek(sizeof(double) * 3, SeekOrigin.Current);
}
if (global.override_head_position)
{
mappedStream.Write(BitConverter.GetBytes(global.head_position[0]), 0, sizeof(double));
mappedStream.Write(BitConverter.GetBytes(global.head_position[1]), 0, sizeof(double));
mappedStream.Write(BitConverter.GetBytes(global.head_position[2]), 0, sizeof(double));
}
else
{
mappedStream.Seek(sizeof(double) * 3, SeekOrigin.Current);
}
if (global.override_controller_orientation)
{
mappedStream.Write(BitConverter.GetBytes(global.controller_orientation[0]), 0, sizeof(double));
mappedStream.Write(BitConverter.GetBytes(global.controller_orientation[1]), 0, sizeof(double));
mappedStream.Write(BitConverter.GetBytes(global.controller_orientation[2]), 0, sizeof(double));
}
else
{
mappedStream.Seek(sizeof(double) * 3, SeekOrigin.Current);
}
if (global.override_controller_position)
{
mappedStream.Write(BitConverter.GetBytes(global.controller_position[0]), 0, sizeof(double));
mappedStream.Write(BitConverter.GetBytes(global.controller_position[1]), 0, sizeof(double));
mappedStream.Write(BitConverter.GetBytes(global.controller_position[2]), 0, sizeof(double));
}
else
{
mappedStream.Seek(sizeof(double) * 3, SeekOrigin.Current);
}

UInt32 newOverrideButtons = global.override_application_menu ? ALVR_FREEPIE_BUTTON_APPLICATION_MENU : 0;
UInt32 newButtons = global.application_menu ? ALVR_FREEPIE_BUTTON_APPLICATION_MENU : 0;

mappedStream.Write(BitConverter.GetBytes(newOverrideButtons), 0, sizeof(UInt32));
mappedStream.Write(BitConverter.GetBytes(newOverrideButtons), 0, sizeof(UInt32));
}
}
finally
{
mutex.ReleaseMutex();
}
}
}

private void CheckMemoryMappedFileExistence()
{
if (memoryMappedFile != null)
{
return;
}
try
{
memoryMappedFile = MemoryMappedFile.OpenExisting(ALVR_FREEPIE_FILEMAPPING_NAME);
mutex = new Mutex(false, ALVR_FREEPIE_MUTEX_NAME);
}
catch (Exception e)
{
}
}

static readonly string ALVR_FREEPIE_FILEMAPPING_NAME = "ALVR_FREEPIE_FILEMAPPING_13B65572-591A-4248-A2F6-BAC2D89EE3B8";
static readonly string ALVR_FREEPIE_MUTEX_NAME = "ALVR_FREEPIE_MUTEX_AA77F1C3-86E4-4EF9-AAA2-5C40CF380D7A";

static readonly UInt32 ALVR_FREEPIE_SIGNATURE_V1 = 0x11223344;

static readonly UInt32 ALVR_FREEPIE_FLAG_OVERRIDE_HEAD_ORIENTATION = 1 << 0;
static readonly UInt32 ALVR_FREEPIE_FLAG_OVERRIDE_HEAD_POSITION = 1 << 1;
static readonly UInt32 ALVR_FREEPIE_FLAG_OVERRIDE_CONTROLLER_ORIENTATION = 1 << 2;
static readonly UInt32 ALVR_FREEPIE_FLAG_OVERRIDE_CONTROLLER_POSITION = 1 << 3;

static readonly UInt32 ALVR_FREEPIE_BUTTON_APPLICATION_MENU = 1 << 0;

MemoryMappedFile memoryMappedFile;
Mutex mutex;
}

[Global(Name = "alvr")]
public class ALVRFreePIEPluginGlobal
{
private readonly ALVRFreePIEPlugin plugin;

public ALVRFreePIEPluginGlobal(ALVRFreePIEPlugin plugin)
{
this.plugin = plugin;
}

public bool override_application_menu;
public bool application_menu;
public bool override_head_orientation;
public bool override_head_position;
public bool override_controller_orientation;
public bool override_controller_position;

// yaw pitch roll
public double[] head_orientation = new double[3];
// x y z
public double[] head_position = new double[3];
// yaw pitch roll
public double[] controller_orientation = new double[3];
// x y z
public double[] controller_position = new double[3];
}
}
36 changes: 36 additions & 0 deletions ALVRFreePIE/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;

// アセンブリに関する一般情報は以下の属性セットをとおして制御されます。
// アセンブリに関連付けられている情報を変更するには、
// これらの属性値を変更してください。
[assembly: AssemblyTitle("ALVRFreePIE")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ALVRFreePIE")]
[assembly: AssemblyCopyright("Copyright © 2018")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// ComVisible を false に設定すると、このアセンブリ内の型は COM コンポーネントから
// 参照できなくなります。COM からこのアセンブリ内の型にアクセスする必要がある場合は、
// その型の ComVisible 属性を true に設定してください。
[assembly: ComVisible(false)]

// このプロジェクトが COM に公開される場合、次の GUID が typelib の ID になります
[assembly: Guid("d39838ee-67a1-4d76-8cfa-c1aae99c2920")]

// アセンブリのバージョン情報は次の 4 つの値で構成されています:
//
// メジャー バージョン
// マイナー バージョン
// ビルド番号
// Revision
//
// すべての値を指定するか、次を使用してビルド番号とリビジョン番号を既定に設定できます
// 以下のように '*' を使用します:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
3 changes: 3 additions & 0 deletions alvr_server/resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,6 @@

#define APP_MUTEX_NAME "ALVR_DRIVER_MUTEX_67F10C68-E26D-4ABE-AE25-32BF346D877B"
#define APP_FILEMAPPING_NAME "ALVR_DRIVER_FILEMAPPING_0B124897-7730-4B84-AA32-088E9B92851F"

#define ALVR_FREEPIE_FILEMAPPING_NAME "ALVR_FREEPIE_FILEMAPPING_13B65572-591A-4248-A2F6-BAC2D89EE3B8"
#define ALVR_FREEPIE_MUTEX_NAME "ALVR_FREEPIE_MUTEX_AA77F1C3-86E4-4EF9-AAA2-5C40CF380D7A"

0 comments on commit 2d2648d

Please sign in to comment.