1
0
mirror of synced 2024-11-23 22:30:56 +01:00

il2cpp transition (this commit is still in mono)

fix ipc touch not working under il2cpp;
fix bat wont start under il2cpp;
This commit is contained in:
xpeng 2022-11-08 23:43:35 +01:00
parent 92ef73ee3a
commit d23ae3be82
15 changed files with 548 additions and 286 deletions

View File

@ -105,9 +105,9 @@ Material:
m_Ints: []
m_Floats:
- _AlphaClip: 0
- _Alpha_Brightness: 0.5
- _Alpha_Contrast: 0.55
- _Alpha_Multiplier: 2.68
- _Alpha_Brightness: 0.7
- _Alpha_Contrast: 1
- _Alpha_Multiplier: 2
- _Blend: 0
- _BumpScale: 1
- _ClearCoatMask: 0
@ -121,7 +121,7 @@ Material:
- _Fresnel: 1.24
- _Fresnel_1: 5
- _Fresnel_Power: 1
- _Fresnel_Radius: 0.5
- _Fresnel_Radius: 0.65
- _Fresnel_Size: -5
- _Fresnel_Strength: 1
- _GlossMapScale: 0

View File

@ -102,7 +102,7 @@ Material:
- _DetailAlbedoMapScale: 1
- _DetailNormalMapScale: 1
- _DstBlend: 0
- _EmissionStrength: 1.35
- _EmissionStrength: 1.25
- _EnvironmentReflections: 1
- _GlossMapScale: 1
- _Glossiness: 0

View File

@ -684,7 +684,7 @@ Transform:
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 13
m_RootOrder: 14
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!65 &89868841
BoxCollider:
@ -3775,7 +3775,7 @@ Transform:
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 16
m_RootOrder: 17
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!65 &487003802
BoxCollider:
@ -6479,13 +6479,13 @@ Transform:
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 728980769}
m_LocalRotation: {x: -0, y: 1, z: -0, w: 0}
m_LocalPosition: {x: 0.0421, y: 1.0341, z: -0.055}
m_LocalScale: {x: 0.1, y: 0.1, z: 0.1}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 0, y: 0, z: 0}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 12
m_RootOrder: 13
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!65 &732294716
BoxCollider:
@ -7744,7 +7744,7 @@ Transform:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 910165456}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 1.6783333, y: 1.6758862, z: 2.988133}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
@ -11397,6 +11397,50 @@ MeshCollider:
m_Convex: 0
m_CookingOptions: 30
m_Mesh: {fileID: -4216441611952776256, guid: cf8684b3c4f47b94aa7cb23ce498caf3, type: 3}
--- !u!1 &1213404430
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1213404432}
- component: {fileID: 1213404431}
m_Layer: 0
m_Name: SerialManager
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!114 &1213404431
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1213404430}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 11a72a89f00d44f45a354a22a3e862d5, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!4 &1213404432
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1213404430}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 11
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &1216452012
MonoBehaviour:
m_ObjectHideFlags: 0
@ -12493,14 +12537,14 @@ Transform:
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1251312950}
m_LocalRotation: {x: -0.7071068, y: 0, z: 0, w: 0.7071068}
m_LocalPosition: {x: 0, y: 0.95, z: -0.524}
m_LocalScale: {x: 0.15, y: 0, z: 0.005}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 0, y: 0, z: 0}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 11
m_LocalEulerAnglesHint: {x: -90, y: 0, z: 0}
m_RootOrder: 12
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1257458054 stripped
GameObject:
m_CorrespondingSourceObject: {fileID: -9179824638859959421, guid: cf8684b3c4f47b94aa7cb23ce498caf3,
@ -12963,7 +13007,7 @@ PrefabInstance:
- target: {fileID: 288245633637051364, guid: 0ff442244da79eb4b80cbf1df4230a0f,
type: 3}
propertyPath: m_Value
value: 1.3
value: 1.2
objectReference: {fileID: 0}
- target: {fileID: 288245633637051364, guid: 0ff442244da79eb4b80cbf1df4230a0f,
type: 3}
@ -43387,7 +43431,7 @@ Transform:
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 14
m_RootOrder: 15
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &1972244961
MonoBehaviour:
@ -44031,7 +44075,7 @@ Transform:
- {fileID: 986642662}
- {fileID: 1414750230}
m_Father: {fileID: 0}
m_RootOrder: 15
m_RootOrder: 16
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1981983055 stripped
GameObject:

View File

@ -28,7 +28,7 @@ public class Config
public bool TouchAirWall = false;
public bool UseIPCLighting = true;
public bool UseIPCTouch = true;
public float LightStrength = 1.35f;
public float LightStrength = 1.25f;
public int TestKeyBind = 40;
public int ServiceKeyBind = 41;
public int CoinKeyBind = 31;

View File

@ -4,7 +4,6 @@
"references": [
"GUID:56dd35f9b6f21364494ed8365264cbf6",
"GUID:6055be8ebefd69e48b49212b09b47b2f",
"GUID:2dcfcfc00d4ac7749bb60698b85f1dc2",
"GUID:fe685ec1767f73d42b749ea8045bfe43",
"GUID:75469ad4d38634e559750d17036d5f7c",
"GUID:e9ef0e10f8c2b264e9705f57f028b9e8"

View File

@ -3,12 +3,15 @@ using System.Collections.Generic;
using UnityEngine;
using System.Diagnostics;
using System.IO;
using Lavender.Systems;
public class StartBatchManager : MonoBehaviour
{
private void Start()
{
ConfigManager.EnsureInitialization();
Process.Start(Path.GetFullPath(ConfigManager.config.batFileLocation));
if (ConfigManager.config.batFileLocation != "")
StartExternalProcess.Start(ConfigManager.config.batFileLocation);
//Process.Start(Path.GetFullPath(ConfigManager.config.batFileLocation));
}
}

View File

@ -0,0 +1,156 @@
#if UNITY_STANDALONE_WIN || UNITY_EDITOR_WIN
using System;
using System.ComponentModel;
using System.Runtime.InteropServices;
// ReSharper disable FieldCanBeMadeReadOnly.Local
// ReSharper disable InconsistentNaming
// ReSharper disable UnusedMember.Local
// ReSharper disable MemberCanBePrivate.Local
namespace Lavender.Systems
{
public static class StartExternalProcess
{
[DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
private static extern bool CreateProcessW(
string lpApplicationName,
[In] string lpCommandLine,
IntPtr procSecAttrs,
IntPtr threadSecAttrs,
bool bInheritHandles,
ProcessCreationFlags dwCreationFlags,
IntPtr lpEnvironment,
string lpCurrentDirectory,
ref STARTUPINFO lpStartupInfo,
ref PROCESS_INFORMATION lpProcessInformation
);
[DllImport("kernel32.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
private static extern bool CloseHandle(IntPtr hObject);
[DllImport("kernel32.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
private static extern bool TerminateProcess(IntPtr processHandle, uint exitCode);
[DllImport("kernel32.dll", SetLastError = true)]
private static extern IntPtr OpenProcess(ProcessAccessRights access, bool inherit, uint processId);
[Flags]
private enum ProcessAccessRights : uint
{
PROCESS_CREATE_PROCESS = 0x0080, // Required to create a process.
PROCESS_CREATE_THREAD = 0x0002, // Required to create a thread.
PROCESS_DUP_HANDLE = 0x0040, // Required to duplicate a handle using DuplicateHandle.
PROCESS_QUERY_INFORMATION = 0x0400, // Required to retrieve certain information about a process, such as its token, exit code, and priority class (see OpenProcessToken, GetExitCodeProcess, GetPriorityClass, and IsProcessInJob).
PROCESS_QUERY_LIMITED_INFORMATION = 0x1000, // Required to retrieve certain information about a process (see QueryFullProcessImageName). A handle that has the PROCESS_QUERY_INFORMATION access right is automatically granted PROCESS_QUERY_LIMITED_INFORMATION. Windows Server 2003 and Windows XP/2000: This access right is not supported.
PROCESS_SET_INFORMATION = 0x0200, // Required to set certain information about a process, such as its priority class (see SetPriorityClass).
PROCESS_SET_QUOTA = 0x0100, // Required to set memory limits using SetProcessWorkingSetSize.
PROCESS_SUSPEND_RESUME = 0x0800, // Required to suspend or resume a process.
PROCESS_TERMINATE = 0x0001, // Required to terminate a process using TerminateProcess.
PROCESS_VM_OPERATION = 0x0008, // Required to perform an operation on the address space of a process (see VirtualProtectEx and WriteProcessMemory).
PROCESS_VM_READ = 0x0010, // Required to read memory in a process using ReadProcessMemory.
PROCESS_VM_WRITE = 0x0020, // Required to write to memory in a process using WriteProcessMemory.
DELETE = 0x00010000, // Required to delete the object.
READ_CONTROL = 0x00020000, // Required to read information in the security descriptor for the object, not including the information in the SACL. To read or write the SACL, you must request the ACCESS_SYSTEM_SECURITY access right. For more information, see SACL Access Right.
SYNCHRONIZE = 0x00100000, // The right to use the object for synchronization. This enables a thread to wait until the object is in the signaled state.
WRITE_DAC = 0x00040000, // Required to modify the DACL in the security descriptor for the object.
WRITE_OWNER = 0x00080000, // Required to change the owner in the security descriptor for the object.
STANDARD_RIGHTS_REQUIRED = 0x000f0000,
PROCESS_ALL_ACCESS = STANDARD_RIGHTS_REQUIRED | SYNCHRONIZE | 0xFFF // All possible access rights for a process object.
}
[StructLayout(LayoutKind.Sequential)]
private struct PROCESS_INFORMATION
{
internal IntPtr hProcess;
internal IntPtr hThread;
internal uint dwProcessId;
internal uint dwThreadId;
}
[StructLayout(LayoutKind.Sequential)]
private struct STARTUPINFO
{
internal uint cb;
internal IntPtr lpReserved;
internal IntPtr lpDesktop;
internal IntPtr lpTitle;
internal uint dwX;
internal uint dwY;
internal uint dwXSize;
internal uint dwYSize;
internal uint dwXCountChars;
internal uint dwYCountChars;
internal uint dwFillAttribute;
internal uint dwFlags;
internal ushort wShowWindow;
internal ushort cbReserved2;
internal IntPtr lpReserved2;
internal IntPtr hStdInput;
internal IntPtr hStdOutput;
internal IntPtr hStdError;
}
[Flags]
private enum ProcessCreationFlags : uint
{
NONE = 0,
CREATE_BREAKAWAY_FROM_JOB = 0x01000000,
CREATE_DEFAULT_ERROR_MODE = 0x04000000,
CREATE_NEW_CONSOLE = 0x00000010,
CREATE_NEW_PROCESS_GROUP = 0x00000200,
CREATE_NO_WINDOW = 0x08000000,
CREATE_PROTECTED_PROCESS = 0x00040000,
CREATE_PRESERVE_CODE_AUTHZ_LEVEL = 0x02000000,
CREATE_SECURE_PROCESS = 0x00400000,
CREATE_SEPARATE_WOW_VDM = 0x00000800,
CREATE_SHARED_WOW_VDM = 0x00001000,
CREATE_SUSPENDED = 0x00000004,
CREATE_UNICODE_ENVIRONMENT = 0x00000400,
DEBUG_ONLY_THIS_PROCESS = 0x00000002,
DEBUG_PROCESS = 0x00000001,
DETACHED_PROCESS = 0x00000008,
EXTENDED_STARTUPINFO_PRESENT = 0x00080000,
INHERIT_PARENT_AFFINITY = 0x00010000
}
public static uint Start(string path, string dir = null, bool hidden = false)
{
ProcessCreationFlags flags = hidden ? ProcessCreationFlags.CREATE_NO_WINDOW : ProcessCreationFlags.NONE;
STARTUPINFO startupinfo = new STARTUPINFO
{
cb = (uint)Marshal.SizeOf<STARTUPINFO>()
};
PROCESS_INFORMATION processinfo = new PROCESS_INFORMATION();
if (!CreateProcessW(null, path, IntPtr.Zero, IntPtr.Zero, false, flags, IntPtr.Zero, dir, ref startupinfo, ref processinfo))
{
throw new Win32Exception();
}
return processinfo.dwProcessId;
}
public static int KillProcess(uint pid)
{
IntPtr handle = OpenProcess(ProcessAccessRights.PROCESS_ALL_ACCESS, false, pid);
if (handle == IntPtr.Zero)
{
return -1;
}
if (!TerminateProcess(handle, 0))
{
throw new Win32Exception();
}
if (!CloseHandle(handle))
{
throw new Win32Exception();
}
return 0;
}
}
}
#endif

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 25465c8bb0d210e40869f0e309b12fde
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -9,6 +9,7 @@ public class IPCManager : MonoBehaviour
public static MemoryMappedFile sharedBuffer;
public static MemoryMappedViewAccessor sharedBufferAccessor;
public static bool isInitialized = false;
public static bool[] TouchData = new bool[240];
private void Awake()
{
@ -83,18 +84,21 @@ public class IPCManager : MonoBehaviour
Debug.Log("IPC Disposed");
}
public static void SetTouchData(bool[] bytes)
private static void SetTouchData(bool[] datas)
{
EnsureInitialization();
IPCManager.sharedBufferAccessor.WriteArray<bool>(4, bytes, 0, 240);
IPCManager.sharedBufferAccessor.WriteArray<bool>(4, datas, 0, 240);
}
public static void SetTouch(int index, bool value)
public static void SetTouch(int Area, bool State)
{
EnsureInitialization();
if (value)
IPCManager.sharedBufferAccessor.Write(4 + index, 1);
else
IPCManager.sharedBufferAccessor.Write(4 + index, 0);
Area -= 1; //0-239
if (Area < 120) //right side
TouchData[Area + 120] = State;
else if (Area >= 120) //left side
TouchData[Area - 120] = State;
SetTouchData(TouchData);
}
}

View File

@ -67,7 +67,6 @@ public class LightManager : MonoBehaviour
}
private void CheckIPCState(byte[] data)
{
Debug.Log(data[3]);
if (data[3] == 0)
isIPCIdle = true;
else

View File

@ -9,7 +9,6 @@ public class ColliderToTouch : MonoBehaviour
{
public LightManager LightManager;
private int _insideColliderCount = 0;
public static event Action touchDidChange;
private int Area;
private void Start()
{
@ -19,7 +18,6 @@ public class ColliderToTouch : MonoBehaviour
{
_insideColliderCount += 1;
TouchManager.SetTouch(Area, true);
touchDidChange?.Invoke();
LightManager.UpdateFadeLight(Area, true);
}
@ -30,7 +28,6 @@ public class ColliderToTouch : MonoBehaviour
if (_insideColliderCount == 0)
{
TouchManager.SetTouch(Area, false);
touchDidChange?.Invoke();
LightManager.UpdateFadeLight(Area, false);
}
}

View File

@ -0,0 +1,279 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Threading;
using System.IO.Ports;
using System.Linq;
using UnityEngine;
using UnityEngine.UI;
public class SerialManager : MonoBehaviour
{
const byte CMD_GET_SYNC_BOARD_VER = 0xa0;
const byte CMD_NEXT_READ = 0x72;
const byte CMD_GET_UNIT_BOARD_VER = 0xa8;
const byte CMD_MYSTERY1 = 0xa2;
const byte CMD_MYSTERY2 = 0x94;
const byte CMD_START_AUTO_SCAN = 0xc9;
const byte CMD_BEGIN_WRITE = 0x77;
const byte CMD_NEXT_WRITE = 0x20;
private Thread _touchThread;
private Queue _touchQueue;
static SerialPort ComL = new SerialPort ("COM5", 115200);
static SerialPort ComR = new SerialPort ("COM6", 115200);
byte inByte;
string SYNC_BOARD_VER = "190523";
string UNIT_BOARD_VER = "190514";
string read1 = " 0 0 1 2 3 4 5 15 15 15 15 15 15 11 11 11";
string read2 = " 11 11 11 128 103 103 115 138 127 103 105 111 126 113 95 100";
string read3 = " 101 115 98 86 76 67 68 48 117 0 82 154 0 6 35 4";
byte[] SettingData_160 = new byte[8] {160, 49, 57, 48, 53, 50, 51, 44};
byte[] SettingData_162 = new byte[3] {162, 63, 29};
byte[] SettingData_148 = new byte[3] {148, 0, 20};
byte[] SettingData_201 = new byte[3] {201, 0, 73};
static byte[] TouchPackL = new byte[36];
static byte[] TouchPackR = new byte[36];
bool StartUp = false;
void Start()
{
//if game is not running using mono, destroy this object
if (Type.GetType("Mono.Runtime") == null)
{
Destroy(this);
return;
}
try
{
ComL.Open();
ComR.Open();
}
catch (Exception ex)
{
Console.WriteLine($"Failed to Open Serial Ports: {ex}");
Destroy(this);
}
Debug.Log("Touch Serial Initializing..");
//Send touch update periodically to keep "read" alive
_touchQueue = Queue.Synchronized(new Queue());
_touchThread = new Thread(TouchThreadLoop);
InvokeRepeating("PingTouchThread", 0, 1);
//Send touch updates whenever actual state changes to achieve desired update frequency without overloading
TouchManager.touchDidChange += PingTouchThread;
}
private void PingTouchThread()
{
_touchQueue.Enqueue(1);
}
private void TouchThreadLoop()
{
while(true)
{
if(_touchQueue.Count > 0)
{
_touchQueue.Dequeue();
SendTouchState();
}
}
}
private void OnDestroy()
{
ComL.Close();
ComR.Close();
}
void Update()
{
if(ComL.IsOpen)
ReadHead(ComL, 0);
if (ComR.IsOpen)
ReadHead(ComR, 1);
//following are touch test code
//if (Input.GetKeyDown(KeyCode.M))
//StartCoroutine(TouchTest(true));
//if (Input.GetKeyDown(KeyCode.M) && StartUp)
//SendTouchState();
}
private void SendTouchState()
{
if(StartUp)
{
//Debug.Log("Sending Touch State");
// Debug.Log("Sending Left");
SendTouch(ComL, TouchPackL);
// Debug.Log("Sending Right");
SendTouch(ComR, TouchPackR);
}
}
IEnumerator TouchTest(bool State) //this is a touch test code
{
for (int i = 0; i < 240; i++)
{
SetTouch(i, true);
Debug.Log(i);
yield return new WaitForSeconds(0.05f);
SetTouch(i, false);
yield return new WaitForSeconds(0.05f);
}
}
void ReadHead(SerialPort Serial, int side) //Read head byte
{
if(Serial.BytesToRead > 0)
{
inByte = Convert.ToByte(Serial.ReadByte());
var data = Serial.ReadExisting();
SendResp(Serial, side, data);
}
}
void SendResp(SerialPort Serial, int side, string data)
{
switch(inByte)
{
case CMD_GET_SYNC_BOARD_VER:
//Response: cmd byte + sync board ver + checksum
StartUp = false;
List<byte> syncbytes = new List<byte>();
syncbytes.Add(inByte);
syncbytes.AddRange(ByteHelper.ConvertStringToByteArray(SYNC_BOARD_VER));
byte syncCheckSum = (byte)44;
syncbytes.Add(syncCheckSum);
Serial.Write(syncbytes.ToArray(), 0, syncbytes.Count);
//Debug.Log($"GET SYNC BOARD VER {side}");
break;
case CMD_NEXT_READ:
//Response: corresponding read bytes + checksum
StartUp = false;
//Debug.Log($"Side {side} NEXT READ {Convert.ToByte(data[2])}");
switch (Convert.ToByte(data[2]))
{
case 0x30:
var bytes = ByteHelper.ConvertStringToByteArray(read1);
bytes.Add(ByteHelper.CalCheckSum(bytes.ToArray(), bytes.Count));
//Debug.Log("Read 1");
Serial.Write(bytes.ToArray(), 0, bytes.Count);
break;
case 0x31:
var bytes2 = ByteHelper.ConvertStringToByteArray(read2);
bytes2.Add(ByteHelper.CalCheckSum(bytes2.ToArray(), bytes2.Count));
//Debug.Log("Read 2");
Serial.Write(bytes2.ToArray(), 0, bytes2.Count);
break;
case 0x33:
var bytes3 = ByteHelper.ConvertStringToByteArray(read3);
bytes3.Add(ByteHelper.CalCheckSum(bytes3.ToArray(), bytes3.Count));
//Debug.Log("Read 3");
Serial.Write(bytes3.ToArray(), 0, bytes3.Count);
break;
default:
//Debug.Log("Extra Read");
break;
}
break;
case CMD_GET_UNIT_BOARD_VER:
//Response: cmd byte + sync board ver bytes + 'L'/'R' based on side + unit board ver bytes x6 + checksum
StartUp = false;
List<byte> unitBytes = new List<byte>();
byte sideByte = (side == 0 ? Convert.ToByte('R') : Convert.ToByte('L'));
byte unitCheckSum = (side == 0 ? (byte)118 : (byte)104);
unitBytes.Add(inByte);
unitBytes.AddRange(ByteHelper.ConvertStringToByteArray(SYNC_BOARD_VER));
unitBytes.Add(sideByte);
for (int i = 0; i < 6; i++)
unitBytes.AddRange(ByteHelper.ConvertStringToByteArray(UNIT_BOARD_VER));
unitBytes.Add(unitCheckSum);
Serial.Write(unitBytes.ToArray(), 0, unitBytes.Count);
//Debug.Log($"GET UNIT BOARD VER {side}");
break;
case CMD_MYSTERY1:
StartUp = false;
Serial.Write(SettingData_162, 0, 3);
//Debug.Log($"MYSTERY 1 SIDE {side}");
break;
case CMD_MYSTERY2:
StartUp = false;
Serial.Write(SettingData_148, 0, 3);
//Debug.Log($"MYSTERY 2 SIDE {side}");
break;
case CMD_START_AUTO_SCAN:
Serial.Write(SettingData_201.ToArray(), 0, 3);
//Debug.Log($"START AUTO SCAN SIDE {side}");
StartUp = true;
if (!_touchThread.IsAlive)
_touchThread.Start();
break;
case CMD_BEGIN_WRITE:
// Debug.Log($"Begin Write For Side {side}");
break;
case CMD_NEXT_WRITE:
// Debug.Log($"Continue Write For Side {side}");
break;
case 154:
StartUp = false;
//Debug.Log("BAD");
break;
}
}
byte[] GetTouchPack(byte[] Pack) //convert touch to right format for game
{
Pack[0] = 129;
Pack[34] = Pack[34]++;
Pack[35] = 128;
Pack[35] = ByteHelper.CalCheckSum(Pack, 36);
if (Pack[34] > 127)
Pack[34] = 0;
return Pack;
}
void SendTouch(SerialPort Serial, byte[] Pack) //Send touch data to serial
{
if (StartUp)
Serial.Write(GetTouchPack(Pack), 0, 36);
}
public static void SetTouch(int Area, bool State) //set touch data 1-240
{
Area -= 1; //0-239
if (Area < 120) //right side
{
Area += Area / 5 * 3 + 7;
ByteHelper.SetBit(TouchPackR, Area, State);
}
else if (Area >= 120) //left side
{
Area -= 120;
Area += Area / 5 * 3 + 7;
ByteHelper.SetBit(TouchPackL, Area, State);
}
}
}
public static class ByteHelper
{
public static byte[] SetBit(this byte[] self, int index, bool value)
{
var bitArray = new BitArray(self);
bitArray.Set(index, value);
bitArray.CopyTo(self, 0);
return self;
}
public static byte CalCheckSum(byte[] _PacketData,int PacketLength)
{
Byte _CheckSumByte = 0x00;
for (int i = 0; i < PacketLength; i++)
_CheckSumByte ^= _PacketData[i];
return _CheckSumByte;
}
public static List<byte> ConvertStringToByteArray(string data)
{
List<byte> tempList = new List<byte>(100);
for(int i = 0; i < data.Length; i++)
tempList.Add(Convert.ToByte(data[i]));
return tempList;
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 11a72a89f00d44f45a354a22a3e862d5
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -8,36 +8,7 @@ using UnityEngine;
using UnityEngine.UI;
public class TouchManager : MonoBehaviour
{
const byte CMD_GET_SYNC_BOARD_VER = 0xa0;
const byte CMD_NEXT_READ = 0x72;
const byte CMD_GET_UNIT_BOARD_VER = 0xa8;
const byte CMD_MYSTERY1 = 0xa2;
const byte CMD_MYSTERY2 = 0x94;
const byte CMD_START_AUTO_SCAN = 0xc9;
const byte CMD_BEGIN_WRITE = 0x77;
const byte CMD_NEXT_WRITE = 0x20;
private Thread _touchThread;
private Queue _touchQueue;
static SerialPort ComL = new SerialPort ("COM5", 115200);
static SerialPort ComR = new SerialPort ("COM6", 115200);
byte inByte;
string SYNC_BOARD_VER = "190523";
string UNIT_BOARD_VER = "190514";
string read1 = " 0 0 1 2 3 4 5 15 15 15 15 15 15 11 11 11";
string read2 = " 11 11 11 128 103 103 115 138 127 103 105 111 126 113 95 100";
string read3 = " 101 115 98 86 76 67 68 48 117 0 82 154 0 6 35 4";
byte[] SettingData_160 = new byte[8] {160, 49, 57, 48, 53, 50, 51, 44};
byte[] SettingData_162 = new byte[3] {162, 63, 29};
byte[] SettingData_148 = new byte[3] {148, 0, 20};
byte[] SettingData_201 = new byte[3] {201, 0, 73};
static byte[] TouchPackL = new byte[36];
static byte[] TouchPackR = new byte[36];
static bool[] TouchPackAll = new bool[240];
bool StartUp = false;
public static event Action touchDidChange;
static bool useIPCTouch = true;
void Start()
{
@ -47,69 +18,6 @@ public class TouchManager : MonoBehaviour
useIPCTouch = value;
});
toggle.onValueChanged.Invoke(useIPCTouch);
try
{
ComL.Open();
ComR.Open();
}
catch (Exception ex)
{
Console.WriteLine($"Failed to Open Serial Ports: {ex}");
}
Debug.Log("Touch Serial Initializing..");
//Send touch update periodically to keep "read" alive
_touchQueue = Queue.Synchronized(new Queue());
_touchThread = new Thread(TouchThreadLoop);
InvokeRepeating("PingTouchThread", 0, 1);
//Send touch updates whenever actual state changes to achieve desired update frequency without overloading
ColliderToTouch.touchDidChange += PingTouchThread;
}
private void PingTouchThread()
{
_touchQueue.Enqueue(1);
}
private void TouchThreadLoop()
{
while(true)
{
if(_touchQueue.Count > 0)
{
_touchQueue.Dequeue();
SendTouchState();
}
}
}
private void OnDestroy()
{
ComL.Close();
ComR.Close();
}
void Update()
{
if(ComL.IsOpen)
ReadHead(ComL, 0);
if (ComR.IsOpen)
ReadHead(ComR, 1);
//following are touch test code
//if (Input.GetKeyDown(KeyCode.M))
//StartCoroutine(TouchTest(true));
//if (Input.GetKeyDown(KeyCode.M) && StartUp)
//SendTouchState();
}
private void SendTouchState()
{
if(StartUp)
{
//Debug.Log("Sending Touch State");
// Debug.Log("Sending Left");
SendTouch(ComL, TouchPackL);
// Debug.Log("Sending Right");
SendTouch(ComR, TouchPackR);
}
}
IEnumerator TouchTest(bool State) //this is a touch test code
@ -123,164 +31,13 @@ public class TouchManager : MonoBehaviour
yield return new WaitForSeconds(0.05f);
}
}
void ReadHead(SerialPort Serial, int side) //Read head byte
{
if(Serial.BytesToRead > 0)
{
inByte = Convert.ToByte(Serial.ReadByte());
var data = Serial.ReadExisting();
SendResp(Serial, side, data);
}
}
void SendResp(SerialPort Serial, int side, string data)
{
switch(inByte)
{
case CMD_GET_SYNC_BOARD_VER:
//Response: cmd byte + sync board ver + checksum
StartUp = false;
List<byte> syncbytes = new List<byte>();
syncbytes.Add(inByte);
syncbytes.AddRange(ByteHelper.ConvertStringToByteArray(SYNC_BOARD_VER));
byte syncCheckSum = (byte)44;
syncbytes.Add(syncCheckSum);
Serial.Write(syncbytes.ToArray(), 0, syncbytes.Count);
//Debug.Log($"GET SYNC BOARD VER {side}");
break;
case CMD_NEXT_READ:
//Response: corresponding read bytes + checksum
StartUp = false;
//Debug.Log($"Side {side} NEXT READ {Convert.ToByte(data[2])}");
switch (Convert.ToByte(data[2]))
{
case 0x30:
var bytes = ByteHelper.ConvertStringToByteArray(read1);
bytes.Add(ByteHelper.CalCheckSum(bytes.ToArray(), bytes.Count));
//Debug.Log("Read 1");
Serial.Write(bytes.ToArray(), 0, bytes.Count);
break;
case 0x31:
var bytes2 = ByteHelper.ConvertStringToByteArray(read2);
bytes2.Add(ByteHelper.CalCheckSum(bytes2.ToArray(), bytes2.Count));
//Debug.Log("Read 2");
Serial.Write(bytes2.ToArray(), 0, bytes2.Count);
break;
case 0x33:
var bytes3 = ByteHelper.ConvertStringToByteArray(read3);
bytes3.Add(ByteHelper.CalCheckSum(bytes3.ToArray(), bytes3.Count));
//Debug.Log("Read 3");
Serial.Write(bytes3.ToArray(), 0, bytes3.Count);
break;
default:
//Debug.Log("Extra Read");
break;
}
break;
case CMD_GET_UNIT_BOARD_VER:
//Response: cmd byte + sync board ver bytes + 'L'/'R' based on side + unit board ver bytes x6 + checksum
StartUp = false;
List<byte> unitBytes = new List<byte>();
byte sideByte = (side == 0 ? Convert.ToByte('R') : Convert.ToByte('L'));
byte unitCheckSum = (side == 0 ? (byte)118 : (byte)104);
unitBytes.Add(inByte);
unitBytes.AddRange(ByteHelper.ConvertStringToByteArray(SYNC_BOARD_VER));
unitBytes.Add(sideByte);
for (int i = 0; i < 6; i++)
unitBytes.AddRange(ByteHelper.ConvertStringToByteArray(UNIT_BOARD_VER));
unitBytes.Add(unitCheckSum);
Serial.Write(unitBytes.ToArray(), 0, unitBytes.Count);
//Debug.Log($"GET UNIT BOARD VER {side}");
break;
case CMD_MYSTERY1:
StartUp = false;
Serial.Write(SettingData_162, 0, 3);
//Debug.Log($"MYSTERY 1 SIDE {side}");
break;
case CMD_MYSTERY2:
StartUp = false;
Serial.Write(SettingData_148, 0, 3);
//Debug.Log($"MYSTERY 2 SIDE {side}");
break;
case CMD_START_AUTO_SCAN:
Serial.Write(SettingData_201.ToArray(), 0, 3);
//Debug.Log($"START AUTO SCAN SIDE {side}");
StartUp = true;
if (!_touchThread.IsAlive)
_touchThread.Start();
break;
case CMD_BEGIN_WRITE:
// Debug.Log($"Begin Write For Side {side}");
break;
case CMD_NEXT_WRITE:
// Debug.Log($"Continue Write For Side {side}");
break;
case 154:
StartUp = false;
//Debug.Log("BAD");
break;
}
}
byte[] GetTouchPack(byte[] Pack) //convert touch to right format for game
{
Pack[0] = 129;
Pack[34] = Pack[34]++;
Pack[35] = 128;
Pack[35] = ByteHelper.CalCheckSum(Pack, 36);
if (Pack[34] > 127)
Pack[34] = 0;
return Pack;
}
void SendTouch(SerialPort Serial, byte[] Pack) //Send touch data to serial
{
if (StartUp)
Serial.Write(GetTouchPack(Pack), 0, 36);
}
public static void SetTouch(int Area, bool State) //set touch data 1-240
{
Area -= 1; //0-239
if (Area < 120) //right side
{
TouchPackAll[Area + 120] = State; //save R touch for IPC
Area += Area / 5 * 3 + 7;
ByteHelper.SetBit(TouchPackR, Area, State);
}
else if (Area >= 120) //left side
{
TouchPackAll[Area - 120] = State; //save L touch for IPC
Area -= 120;
Area += Area / 5 * 3 + 7;
ByteHelper.SetBit(TouchPackL, Area, State);
}
if (useIPCTouch)
IPCManager.SetTouchData(TouchPackAll); //send touch data to IPC
IPCManager.SetTouch(Area, State); //send touch data to IPC
else
SerialManager.SetTouch(Area, State); //send touch data to Serial
touchDidChange?.Invoke();
}
}
public static class ByteHelper
{
public static byte[] SetBit(this byte[] self, int index, bool value)
{
var bitArray = new BitArray(self);
bitArray.Set(index, value);
bitArray.CopyTo(self, 0);
return self;
}
public static byte CalCheckSum(byte[] _PacketData,int PacketLength)
{
Byte _CheckSumByte = 0x00;
for (int i = 0; i < PacketLength; i++)
_CheckSumByte ^= _PacketData[i];
return _CheckSumByte;
}
public static List<byte> ConvertStringToByteArray(string data)
{
List<byte> tempList = new List<byte>(100);
for(int i = 0; i < data.Length; i++)
tempList.Add(Convert.ToByte(data[i]));
return tempList;
}
}
}

View File

@ -34,8 +34,9 @@
## Repositories used
- [Brokenithm-iOS](https://github.com/esterTion/Brokenithm-iOS)
- [uWindowCapture](https://github.com/hecomi/uWindowCapture)
- [IL2cppStartProcess](https://github.com/josh4364/IL2cppStartProcess)
- [MaiDXR](https://github.com/xiaopeng12138/MaiDXR)
- [uWindowCapture](https://github.com/hecomi/uWindowCapture)
## Disclaimers
- This project is not-for-profit and some resources came from the Internet!
@ -68,6 +69,7 @@
A ``config.json`` file is automatically created in WACVR's root directory on startup.
- You can change this file via the in-game config panel. Please take a step back: the controller pointer will automatically be disabled when the controller is too close to the cabinet.
- You can change ``batFileLocation`` in ``config.json`` to the location of your start.bat file. The start.bat will automatically run when you start WACVR.
- Some options in ``config.json`` are only the index of the dropdown in the panel.
- You can use the pointer to point the 3rd-person camera and move it to the position you want it to be.