Skip to content

Commit

Permalink
First Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
DecidedX committed Sep 17, 2024
1 parent b403637 commit e827212
Show file tree
Hide file tree
Showing 24 changed files with 1,182 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.vs
obj
bin
14 changes: 14 additions & 0 deletions App.xaml
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>
17 changes: 17 additions & 0 deletions App.xaml.cs
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
{
}
}
11 changes: 11 additions & 0 deletions AssemblyInfo.cs
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)

)]
95 changes: 95 additions & 0 deletions Cemuhook/Protocol.cs
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));
}
}
}
35 changes: 35 additions & 0 deletions Cemuhook/Utils.cs
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);
}
}
}
Loading

0 comments on commit e827212

Please sign in to comment.