mirror of
https://github.com/nefarius/ViGEmBus.git
synced 2025-08-10 00:52:17 +00:00
Removed unused code
This commit is contained in:
216
sys/ByteArray.c
216
sys/ByteArray.c
@@ -1,216 +0,0 @@
|
||||
/*
|
||||
* Virtual Gamepad Emulation Framework - Windows kernel-mode bus driver
|
||||
*
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2016-2020 Nefarius Software Solutions e.U. and Contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
|
||||
#include "ByteArray.h"
|
||||
|
||||
//
|
||||
// Helpers
|
||||
//
|
||||
|
||||
ULONG_PTR align_to_page_size(ULONG_PTR val)
|
||||
{
|
||||
return (val + (PAGE_SIZE - 1)) & -PAGE_SIZE;
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Forward declarations
|
||||
//
|
||||
|
||||
NTSTATUS IncreaseCapacityByteArray(IN PBYTE_ARRAY Array, IN ULONG NumElements);
|
||||
|
||||
|
||||
//
|
||||
// Implementation
|
||||
//
|
||||
|
||||
NTSTATUS InitByteArray(IN OUT PBYTE_ARRAY Array)
|
||||
{
|
||||
//
|
||||
// Initialize size and default capacity
|
||||
Array->Size = 0;
|
||||
Array->Capacity = INITIAL_ARRAY_CAPACITY;
|
||||
|
||||
//
|
||||
// Allocate memory
|
||||
Array->Data = (UCHAR*)ExAllocatePoolWithTag(PagedPool, Array->Capacity, ARRAY_POOL_TAG);
|
||||
if (Array->Data == NULL)
|
||||
return STATUS_INSUFFICIENT_RESOURCES;
|
||||
|
||||
return STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
NTSTATUS AppendElementByteArray(IN PBYTE_ARRAY Array, IN PVOID Element)
|
||||
{
|
||||
//
|
||||
// Make sure there is room to expand into
|
||||
if (((Array->Size + 1) * sizeof(UCHAR)) > Array->Capacity)
|
||||
{
|
||||
//
|
||||
// Increase capacity
|
||||
NTSTATUS status = IncreaseCapacityByteArray(Array, sizeof(UCHAR));
|
||||
if (!NT_SUCCESS(status))
|
||||
return status;
|
||||
}
|
||||
|
||||
//
|
||||
// Append the element and increment the size
|
||||
RtlCopyMemory(Array->Data + (Array->Size * sizeof(UCHAR)), Element, sizeof(UCHAR));
|
||||
|
||||
//
|
||||
// Increment size
|
||||
Array->Size += 1;
|
||||
|
||||
return STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
NTSTATUS AppendElementsByteArray(IN PBYTE_ARRAY Array, IN PVOID Elements, IN ULONG NumElements)
|
||||
{
|
||||
//
|
||||
// Make sure there is room to expand into
|
||||
if ((Array->Size + NumElements) * sizeof(UCHAR) > Array->Capacity)
|
||||
{
|
||||
//
|
||||
// Increase capacity
|
||||
NTSTATUS status = IncreaseCapacityByteArray(Array, NumElements);
|
||||
if (!NT_SUCCESS(status))
|
||||
return status;
|
||||
}
|
||||
|
||||
//
|
||||
// Append the elements and increase the size
|
||||
RtlCopyMemory(Array->Data + (Array->Size * sizeof(UCHAR)), Elements, NumElements * sizeof(UCHAR));
|
||||
|
||||
//
|
||||
// Increase size
|
||||
Array->Size += NumElements;
|
||||
|
||||
return STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
NTSTATUS IncreaseCapacityByteArray(IN PBYTE_ARRAY Array, IN ULONG NumElements)
|
||||
{
|
||||
UCHAR* NewData = NULL;
|
||||
|
||||
//
|
||||
// Align new size to the immediate next page boundary
|
||||
Array->Capacity = align_to_page_size((Array->Size + NumElements) * sizeof(UCHAR));
|
||||
|
||||
//
|
||||
// Allocate new data with new capacity
|
||||
NewData = (UCHAR*)ExAllocatePoolWithTag(PagedPool, Array->Capacity, ARRAY_POOL_TAG);
|
||||
if (NewData == NULL)
|
||||
return STATUS_INSUFFICIENT_RESOURCES;
|
||||
|
||||
//
|
||||
// Copy old data over
|
||||
RtlCopyMemory(NewData, Array->Data, Array->Size * sizeof(UCHAR));
|
||||
|
||||
//
|
||||
// Free old data
|
||||
ExFreePoolWithTag(Array->Data, ARRAY_POOL_TAG);
|
||||
|
||||
//
|
||||
// Set data pointer to new allocation
|
||||
Array->Data = NewData;
|
||||
|
||||
return STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
NTSTATUS GetElementByteArray(IN PBYTE_ARRAY Array, IN ULONG Index, OUT PVOID Element)
|
||||
{
|
||||
//
|
||||
// Check array bounds
|
||||
if (Index >= Array->Size || (LONG)Index < 0)
|
||||
return STATUS_ARRAY_BOUNDS_EXCEEDED;
|
||||
|
||||
//
|
||||
// Copy data over
|
||||
RtlCopyMemory(Element, Array->Data + (Index * sizeof(UCHAR)), sizeof(UCHAR));
|
||||
|
||||
return STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
NTSTATUS GetElementsByteArray(IN PBYTE_ARRAY Array, IN ULONG Index, OUT PVOID Elements, IN ULONG NumElements)
|
||||
{
|
||||
//
|
||||
// Check array bounds
|
||||
if (Index >= Array->Size || (LONG)Index < 0)
|
||||
return STATUS_ARRAY_BOUNDS_EXCEEDED;
|
||||
|
||||
//
|
||||
// Copy data over
|
||||
RtlCopyMemory(Elements, Array->Data + (Index * sizeof(UCHAR)), NumElements * sizeof(UCHAR));
|
||||
|
||||
return STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
NTSTATUS SetElementByteArray(IN PBYTE_ARRAY Array, IN ULONG Index, IN PVOID Element)
|
||||
{
|
||||
//
|
||||
// Check array bounds
|
||||
if (Index >= Array->Size || (LONG)Index < 0)
|
||||
return STATUS_ARRAY_BOUNDS_EXCEEDED;
|
||||
|
||||
//
|
||||
// Copy data over
|
||||
RtlCopyMemory(Array->Data + (Index * sizeof(UCHAR)), Element, sizeof(UCHAR));
|
||||
|
||||
return STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
NTSTATUS SetElementsByteArray(IN PBYTE_ARRAY Array, IN ULONG Index, IN PVOID Elements, IN ULONG NumElements)
|
||||
{
|
||||
//
|
||||
// Check array bounds
|
||||
if (Index >= Array->Size || (LONG)Index < 0)
|
||||
return STATUS_ARRAY_BOUNDS_EXCEEDED;
|
||||
|
||||
//
|
||||
// Copy data over
|
||||
RtlCopyMemory(Array->Data + (Index * sizeof(UCHAR)), Elements, NumElements * sizeof(UCHAR));
|
||||
|
||||
return STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
NTSTATUS FreeByteArray(IN PBYTE_ARRAY Array)
|
||||
{
|
||||
if (Array->Data == NULL)
|
||||
return STATUS_MEMORY_NOT_ALLOCATED;
|
||||
|
||||
//
|
||||
// Free data
|
||||
ExFreePoolWithTag(Array->Data, ARRAY_POOL_TAG);
|
||||
|
||||
//
|
||||
// Null out everything
|
||||
Array->Data = NULL;
|
||||
Array->Size = 0;
|
||||
Array->Capacity = 0;
|
||||
|
||||
return STATUS_SUCCESS;
|
||||
}
|
||||
@@ -1,60 +0,0 @@
|
||||
/*
|
||||
* Virtual Gamepad Emulation Framework - Windows kernel-mode bus driver
|
||||
*
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2016-2020 Nefarius Software Solutions e.U. and Contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <ntifs.h>
|
||||
|
||||
EXTERN_C_START
|
||||
|
||||
#define INITIAL_ARRAY_CAPACITY PAGE_SIZE
|
||||
#define ARRAY_POOL_TAG 'arrA'
|
||||
|
||||
typedef struct _BYTE_ARRAY
|
||||
{
|
||||
UCHAR* Data; //> array of data we're storing
|
||||
ULONG_PTR Size; //> slots used so far
|
||||
ULONG_PTR Capacity; //> total available memory
|
||||
} BYTE_ARRAY, *PBYTE_ARRAY;
|
||||
|
||||
NTSTATUS InitByteArray(IN OUT PBYTE_ARRAY Array);
|
||||
|
||||
NTSTATUS AppendElementByteArray(IN PBYTE_ARRAY Array, IN PVOID Element);
|
||||
|
||||
NTSTATUS AppendElementsByteArray(IN PBYTE_ARRAY Array, IN PVOID Elements, IN ULONG NumElements);
|
||||
|
||||
NTSTATUS GetElementByteArray(IN PBYTE_ARRAY Array, IN ULONG Index, OUT PVOID Element);
|
||||
|
||||
NTSTATUS GetElementsByteArray(IN PBYTE_ARRAY Array, IN ULONG Index, OUT PVOID Elements, IN ULONG NumElements);
|
||||
|
||||
NTSTATUS SetElementByteArray(IN PBYTE_ARRAY Array, IN ULONG Index, IN PVOID Element);
|
||||
|
||||
NTSTATUS SetElementsByteArray(IN PBYTE_ARRAY Array, IN ULONG Index, IN PVOID Elements, IN ULONG NumElements);
|
||||
|
||||
NTSTATUS FreeByteArray(IN PBYTE_ARRAY Array);
|
||||
|
||||
EXTERN_C_END
|
||||
@@ -1,95 +0,0 @@
|
||||
/*
|
||||
* Virtual Gamepad Emulation Framework - Windows kernel-mode bus driver
|
||||
*
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2016-2020 Nefarius Software Solutions e.U. and Contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
|
||||
#pragma once
|
||||
|
||||
|
||||
|
||||
//
|
||||
// FDO (bus device) context data
|
||||
//
|
||||
typedef struct _FDO_DEVICE_DATA
|
||||
{
|
||||
//
|
||||
// Counter of interface references
|
||||
//
|
||||
LONG InterfaceReferenceCounter;
|
||||
|
||||
//
|
||||
// Next SessionId to assign to a file handle
|
||||
//
|
||||
LONG NextSessionId;
|
||||
|
||||
//
|
||||
// Periodic timer sweeping up orphaned requests
|
||||
//
|
||||
WDFTIMER PendingPluginRequestsCleanupTimer;
|
||||
|
||||
} FDO_DEVICE_DATA, *PFDO_DEVICE_DATA;
|
||||
|
||||
#define FDO_FIRST_SESSION_ID 100
|
||||
|
||||
WDF_DECLARE_CONTEXT_TYPE_WITH_NAME(FDO_DEVICE_DATA, FdoGetData)
|
||||
|
||||
//
|
||||
// Context data associated with file objects created by user mode applications
|
||||
//
|
||||
typedef struct _FDO_FILE_DATA
|
||||
{
|
||||
//
|
||||
// SessionId associated with file handle. Used to map file handles to emulated gamepad devices
|
||||
//
|
||||
LONG SessionId;
|
||||
|
||||
} FDO_FILE_DATA, *PFDO_FILE_DATA;
|
||||
|
||||
WDF_DECLARE_CONTEXT_TYPE_WITH_NAME(FDO_FILE_DATA, FileObjectGetData)
|
||||
|
||||
//
|
||||
// Context data for plugin requests
|
||||
//
|
||||
typedef struct _FDO_PLUGIN_REQUEST_DATA
|
||||
{
|
||||
//
|
||||
// Unique serial number of the device on the bus
|
||||
//
|
||||
ULONG Serial;
|
||||
|
||||
//
|
||||
// High resolution timestamp taken when this request got moved to pending state
|
||||
//
|
||||
LARGE_INTEGER Timestamp;
|
||||
|
||||
//
|
||||
// Performance counter system frequency taken upon fetching timestamp
|
||||
//
|
||||
LARGE_INTEGER Frequency;
|
||||
|
||||
} FDO_PLUGIN_REQUEST_DATA, *PFDO_PLUGIN_REQUEST_DATA;
|
||||
|
||||
WDF_DECLARE_CONTEXT_TYPE_WITH_NAME(FDO_PLUGIN_REQUEST_DATA, PluginRequestGetData)
|
||||
|
||||
@@ -27,13 +27,6 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
//
|
||||
// Returns the current caller process id.
|
||||
//
|
||||
#define CURRENT_PROCESS_ID() ((DWORD)((DWORD_PTR)PsGetCurrentProcessId() & 0xFFFFFFFF))
|
||||
|
||||
#define IS_OWNER(_pdo_) (_pdo_->OwnerProcessId == CURRENT_PROCESS_ID())
|
||||
|
||||
//
|
||||
// Represents a MAC address.
|
||||
//
|
||||
|
||||
@@ -188,8 +188,6 @@
|
||||
<ClInclude Include="$(SolutionDir)\Include\ViGEmBusDriver.h" />
|
||||
<ClInclude Include="..\client\include\ViGEm\km\BusShared.h" />
|
||||
<ClInclude Include="busenum.h" />
|
||||
<ClInclude Include="ByteArray.h" />
|
||||
<ClInclude Include="Context.h" />
|
||||
<ClInclude Include="CRTCPP.hpp" />
|
||||
<ClInclude Include="Ds4Pdo.hpp" />
|
||||
<ClInclude Include="EmulationTargetPDO.hpp" />
|
||||
@@ -205,7 +203,6 @@
|
||||
<ItemGroup>
|
||||
<ClCompile Include="busenum.cpp" />
|
||||
<ClCompile Include="buspdo.cpp" />
|
||||
<ClCompile Include="ByteArray.c" />
|
||||
<ClCompile Include="Driver.cpp" />
|
||||
<ClCompile Include="Ds4Pdo.cpp" />
|
||||
<ClCompile Include="EmulationTargetPDO.cpp" />
|
||||
@@ -213,9 +210,6 @@
|
||||
<ClCompile Include="Util.c" />
|
||||
<ClCompile Include="XusbPdo.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="cpp.hint" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
|
||||
@@ -39,15 +39,9 @@
|
||||
<ClInclude Include="busenum.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Context.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Util.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="ByteArray.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="$(SolutionDir)\Include\ViGEmBusDriver.h">
|
||||
<Filter>Header Files\Common</Filter>
|
||||
</ClInclude>
|
||||
@@ -80,9 +74,6 @@
|
||||
<ClCompile Include="Util.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="ByteArray.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="XusbPdo.cpp">
|
||||
<Filter>Source Files\Targets</Filter>
|
||||
</ClCompile>
|
||||
@@ -110,7 +101,4 @@
|
||||
<Filter>Resource Files</Filter>
|
||||
</ResourceCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="cpp.hint" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -39,27 +39,51 @@
|
||||
#include "Queue.hpp"
|
||||
#include <usb.h>
|
||||
#include <usbbusif.h>
|
||||
#include "Context.h"
|
||||
#include "Util.h"
|
||||
|
||||
|
||||
|
||||
#pragma region Macros
|
||||
|
||||
#define HID_LANGUAGE_ID_LENGTH 0x04
|
||||
|
||||
|
||||
|
||||
#define VIGEM_POOL_TAG 0x45476956 // "EGiV"
|
||||
#define DRIVERNAME "ViGEm: "
|
||||
|
||||
#define ORC_PC_FREQUENCY_DIVIDER 1000
|
||||
#define ORC_TIMER_START_DELAY 500 // ms
|
||||
#define ORC_TIMER_PERIODIC_DUE_TIME 500 // ms
|
||||
#define ORC_REQUEST_MAX_AGE 500 // ms
|
||||
|
||||
#pragma endregion
|
||||
|
||||
//
|
||||
// FDO (bus device) context data
|
||||
//
|
||||
typedef struct _FDO_DEVICE_DATA
|
||||
{
|
||||
//
|
||||
// Counter of interface references
|
||||
//
|
||||
LONG InterfaceReferenceCounter;
|
||||
|
||||
//
|
||||
// Next SessionId to assign to a file handle
|
||||
//
|
||||
LONG NextSessionId;
|
||||
|
||||
} FDO_DEVICE_DATA, * PFDO_DEVICE_DATA;
|
||||
|
||||
#define FDO_FIRST_SESSION_ID 100
|
||||
|
||||
WDF_DECLARE_CONTEXT_TYPE_WITH_NAME(FDO_DEVICE_DATA, FdoGetData)
|
||||
|
||||
//
|
||||
// Context data associated with file objects created by user mode applications
|
||||
//
|
||||
typedef struct _FDO_FILE_DATA
|
||||
{
|
||||
//
|
||||
// SessionId associated with file handle. Used to map file handles to emulated gamepad devices
|
||||
//
|
||||
LONG SessionId;
|
||||
|
||||
} FDO_FILE_DATA, * PFDO_FILE_DATA;
|
||||
|
||||
WDF_DECLARE_CONTEXT_TYPE_WITH_NAME(FDO_FILE_DATA, FileObjectGetData)
|
||||
|
||||
|
||||
EXTERN_C_START
|
||||
@@ -78,10 +102,6 @@ EVT_WDF_CHILD_LIST_CREATE_DEVICE Bus_EvtDeviceListCreatePdo;
|
||||
|
||||
EVT_WDF_CHILD_LIST_IDENTIFICATION_DESCRIPTION_COMPARE Bus_EvtChildListIdentificationDescriptionCompare;
|
||||
|
||||
EVT_WDF_DEVICE_PREPARE_HARDWARE Pdo_EvtDevicePrepareHardware;
|
||||
|
||||
EVT_WDF_IO_QUEUE_IO_INTERNAL_DEVICE_CONTROL Pdo_EvtIoInternalDeviceControl;
|
||||
|
||||
EVT_WDF_OBJECT_CONTEXT_CLEANUP Bus_EvtDriverContextCleanup;
|
||||
|
||||
#pragma endregion
|
||||
|
||||
Reference in New Issue
Block a user