support using chuniio.dll (maybe)

master
logchan 2020-02-13 11:33:54 -05:00
parent c5d684db64
commit 20e50491d7
3 changed files with 47 additions and 3 deletions

View File

@ -0,0 +1,39 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.IO.MemoryMappedFiles;
using System.Security.Principal;
namespace chuni_hands {
internal static class ChuniIO {
public static MemoryMappedFile _buffer;
public static MemoryMappedViewAccessor _accessor;
private static bool _init = false;
public static void Send(IList<Sensor> sensors) {
if (!_init) {
Initialize();
}
var data = new byte[6];
for (var i = 0; i < 6; ++i) {
data[i] = (byte) (sensors[i].Active ? 0x80 : 0x00);
}
_accessor.WriteArray<byte>(0, data, 0, 6);
}
private static void Initialize() {
var security = new MemoryMappedFileSecurity();
var sid = new SecurityIdentifier(WellKnownSidType.WorldSid, null);
var account = sid.Translate(typeof(NTAccount)) as NTAccount;
Debug.Assert(account != null);
security.AddAccessRule(new System.Security.AccessControl.AccessRule<MemoryMappedFileRights>(account.ToString(), MemoryMappedFileRights.FullControl, System.Security.AccessControl.AccessControlType.Allow));
_buffer = MemoryMappedFile.CreateOrOpen("Local\\BROKENITHM_SHARED_BUFFER", 1024, MemoryMappedFileAccess.ReadWrite, MemoryMappedFileOptions.None, security, System.IO.HandleInheritability.Inheritable);
_accessor = _buffer.CreateViewAccessor();
_init = true;
}
}
}

View File

@ -81,10 +81,14 @@ namespace chuni_hands {
switch (_config.SendKeyMode) {
case "be": {
var airKeys = String.Concat(from sensor in _sensors select sensor.Active ? "1" : "0");
_http.GetAsync(_config.EndPoint + "?k=" + airKeys);
}
var airKeys = String.Concat(from sensor in _sensors select sensor.Active ? "1" : "0");
_http.GetAsync(_config.EndPoint + "?k=" + airKeys);
break;
}
case "chuni_io": {
ChuniIO.Send(_sensors);
break;
}
default:
throw new Exception("unknown SendKeyMode");
}

View File

@ -89,6 +89,7 @@
<SubType>Designer</SubType>
</ApplicationDefinition>
<Compile Include="ChuniCanvas.cs" />
<Compile Include="ChuniIO.cs" />
<Compile Include="Config.cs" />
<Compile Include="Helpers.cs" />
<Compile Include="Logger.cs" />