-
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
Showing
24 changed files
with
1,182 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.vs | ||
obj | ||
bin |
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,14 @@ | ||
<Application x:Class="EMotion.App" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:local="clr-namespace:EMotion" | ||
StartupUri="MainWindow.xaml"> | ||
<Application.Resources> | ||
<ResourceDictionary> | ||
<ResourceDictionary.MergedDictionaries> | ||
<ResourceDictionary Source="pack://application:,,,/HandyControl;component/Themes/SkinDefault.xaml"/> | ||
<ResourceDictionary Source="pack://application:,,,/HandyControl;component/Themes/Theme.xaml"/> | ||
</ResourceDictionary.MergedDictionaries> | ||
</ResourceDictionary> | ||
</Application.Resources> | ||
</Application> |
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,17 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Configuration; | ||
using System.Data; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using System.Windows; | ||
|
||
namespace EMotion | ||
{ | ||
/// <summary> | ||
/// Interaction logic for App.xaml | ||
/// </summary> | ||
public partial class App : Application | ||
{ | ||
} | ||
} |
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,11 @@ | ||
using System.Windows; | ||
|
||
[assembly: ThemeInfo( | ||
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located | ||
//(used if a resource is not found in the page, | ||
// or application resource dictionaries) | ||
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located | ||
//(used if a resource is not found in the page, | ||
// app, or any theme specific resource dictionaries) | ||
|
||
)] |
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,95 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using System.IO.Hashing; | ||
|
||
namespace EMotion.Cemuhook | ||
{ | ||
|
||
struct Header | ||
{ | ||
internal string magicString; | ||
internal ushort version; | ||
internal ushort length; | ||
internal uint id; | ||
internal byte[] bytes | ||
{ | ||
get | ||
{ | ||
byte[] bytes = new byte[16]; | ||
Encoding.Default.GetBytes(magicString).CopyTo(bytes, 0); | ||
BitConverter.GetBytes(version).CopyTo(bytes, 4); | ||
BitConverter.GetBytes(length).CopyTo(bytes, 6); | ||
BitConverter.GetBytes(id).CopyTo(bytes, 12); | ||
return bytes; | ||
} | ||
} | ||
|
||
|
||
internal Header(string magicString, ushort version, ushort length, uint id) | ||
{ | ||
this.magicString = magicString; | ||
this.version = version; | ||
this.length = length; | ||
this.id = id; | ||
} | ||
internal Header(byte[] header) | ||
{ | ||
magicString = BitConverter.ToString(header.Take(4).ToArray()); | ||
version = (ushort) BitConverter.ToInt16(header, 4); | ||
length = (ushort) BitConverter.ToInt16(header, 6); | ||
id = (uint) BitConverter.ToInt32(header, 12); | ||
} | ||
|
||
} | ||
|
||
internal class Protocol | ||
{ | ||
|
||
internal static byte[] generateActualDataReqMsg(uint id) | ||
{ | ||
byte[] bytes = new byte[28]; | ||
new Header("DSUC", 1001, 12, id).bytes.CopyTo(bytes, 0); | ||
uint messageType = 0x100002; | ||
BitConverter.GetBytes(messageType).CopyTo(bytes, 16); | ||
return bytes; | ||
} | ||
|
||
internal static byte[] generateInformationReqMsg(uint id, byte slot) | ||
{ | ||
byte[] bytes = new byte[28]; | ||
new Header("DSUC", 1001, 12, id).bytes.CopyTo(bytes, 0); | ||
uint messageType = 0x100001; | ||
BitConverter.GetBytes(messageType).CopyTo(bytes, 16); | ||
BitConverter.GetBytes(1).CopyTo(bytes, 20); | ||
bytes[24] = slot; | ||
return bytes; | ||
} | ||
|
||
internal static byte[] generateMotorMsg(uint id, byte largeMotor) | ||
{ | ||
byte[] bytes = new byte[30]; | ||
new Header("DSUC", 1001, 12, id).bytes.CopyTo(bytes, 0); | ||
uint messageType = 0x110002; | ||
BitConverter.GetBytes(messageType).CopyTo(bytes, 16); | ||
bytes[29] = largeMotor; | ||
return bytes; | ||
} | ||
|
||
internal static byte[] doCrc32(byte[] bytes) | ||
{ | ||
byte[] crc32 = Crc32.Hash(bytes); | ||
crc32.CopyTo(bytes, 8); | ||
return bytes; | ||
} | ||
|
||
internal static bool verifyCrc32(byte[] bytes) | ||
{ | ||
byte[] crc = bytes.Skip(8).Take(4).ToArray(); | ||
Array.Clear(bytes, 8, 4); | ||
return crc.SequenceEqual(Crc32.Hash(bytes)); | ||
} | ||
} | ||
} |
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,35 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace EMotion.Cemuhook | ||
{ | ||
internal class Utils | ||
{ | ||
internal static byte[] uint16ToBytes(ushort value) | ||
{ | ||
byte[] bytes = BitConverter.GetBytes(value); | ||
return bytes; | ||
} | ||
|
||
internal static byte[] uint32ToBytes(uint value) | ||
{ | ||
byte[] bytes = BitConverter.GetBytes(value); | ||
return bytes; | ||
} | ||
|
||
internal static byte[] int32ToBytes(int value) | ||
{ | ||
byte[] bytes = BitConverter.GetBytes(value); | ||
return bytes; | ||
} | ||
|
||
internal static uint bytesToUint32(byte[] bytes) | ||
{ | ||
Array.Reverse(bytes); | ||
return BitConverter.ToUInt32(bytes,0); | ||
} | ||
} | ||
} |
Oops, something went wrong.