forked from polygraphene/ALVR
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a54f522
commit 2d2648d
Showing
5 changed files
with
318 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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")] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters