Xbps.psm1

#if ($env:PROCESSOR_ARCHITECTURE -ne "X86" ) {
# throw "Cannot Load XBDM Module unless running in a 32-bit Process"
#}

. $psScriptRoot\Import-Library.ps1

. $psScriptRoot\XbdmWrapper.ps1


if ($env:PROCESSOR_ARCHITECTURE -eq "x86") {
    Get-Item $env:XEDK\bin\Win32\xDevKit.dll -ErrorAction SilentlyContinue | 
        Import-Module
} else {
    Get-Item $env:XEDK\bin\x64\xDevKit.dll -ErrorAction SilentlyContinue  | 
        Import-Module
}

$script:XbdmSuccess = [int]0x02da0000

Add-Type "
namespace XBPS {
    public enum XboxLocaleId {
        English = 1 ,
        Japanese = 2 ,
        German = 3,
        French = 4,
        Spanish =5 ,
        Italian =6 ,
        Korean = 7,
        TraditionalChinese =8,
        BrazilianPortuguese = 9,
        SimplifiedChinese = 10,
        Polish = 11,
        Russian = 12
    }
}"


$script:xbdm = Add-Type -Name XbDm -Namespace "XbDm$(Get-Random)" -UsingNamespace System.Text -MemberDefinition @'
[DllImport("xbdm.dll")]
public static extern int DmAutomationGetUserDefaultProfile(out UInt64 xuid);
'@
,@'
[DllImport("xbdm.dll")]
public static extern int DmAutomationSetUserDefaultProfile(UInt64 xuid);
'@
, @'
[DllImport("xbdm.dll")]
public static extern int DmSetUserAccess(string userName, uint access);
'@
, @'
[DllImport("xbdm.dll")]
public static extern int DmAddUser(string szUserName, uint dwAccess);
'@
, @'
[DllImport("xbdm.dll")]
public static extern int DmAutomationBindController(uint player, uint length);
'@
, @'
[DllImport("xbdm.dll")]
public static extern int DmAutomationClearGamepadQueue(uint player);
'@
, @'
[DllImport("xbdm.dll")]
public static extern int DmAutomationConnectController(uint player);
'@
, @'
[DllImport("xbdm.dll")]
public static extern int DmAutomationDisconnectController(uint player);
'@
, @'
[DllImport("xbdm.dll")]
public static extern int DmAutomationGetInputProcess(uint player, out bool Bound);
'@
, @'
[DllImport("xbdm.dll")]
public static extern int DmAutomationUnbindController(uint player);
'@
, @'
[DllImport("xbdm.dll")]
public static extern int DmGetConsoleType(out uint ConsoleType);
'@
, @'
[DllImport("xbdm.dll")]
public static extern int DmGetThreadList(ref uint[] Threads, ref uint ThreadCount);
'@
, @'
[DllImport("xbdm.dll")]
public static extern int DmResolveXboxName(out uint Address);
'@
, @'
[DllImport("xbdm.dll")]
public static extern int DmSendFile(string localName, string Remotename);
'@
, @'
[DllImport("xbdm.dll")]
public static extern int DmDeleteFile(string FileName, bool IsDirectory);
'@
, @'
[DllImport("xbdm.dll")]
public static extern int DmEnableGPUCounter(bool Enabled);
'@
, @'
[DllImport("xbdm.dll")]
public static extern int DmEnableSecurity(bool Enabled);
'@
, @'
[DllImport("xbdm.dll")]
static extern int DmGetPid(out uint pid);
'@
, @'
[DllImport("xbdm.dll")]
public static extern int DmRenameFile(string oldname, string newname);
'@
, @'
public static uint DmGetPid()
{
    uint pid = 0;
    DmGetPid(out pid);
    return pid;
}
'@
, @'
[DllImport("xbdm.dll")]
static extern int DmGetXboxName([Out]StringBuilder Response, ref uint ResponseSize);
'@
, @'
public static string DmGetXboxName() {
    StringBuilder XboxName = new StringBuilder( 256, 1024 );
    UInt32 NameLength = 256;
    DmGetXboxName(XboxName, ref NameLength);
    return XboxName.ToString();
}
'@
, @'
[DllImport("xbdm.dll")]
public static extern int DmPMCResetCounters();
'@
,@'
[DllImport("xbdm.dll")]
public static extern int DmPMCStart();
'@
,@'
[DllImport("xbdm.dll")]
public static extern int DmPMCStop();
'@
,@'
[DllImport("xbdm.dll")]
public static extern int DmPMCStopAndReport();
'@
,@'
[DllImport("xbdm.dll")]
public static extern int DmRebootEx( uint dwFlags, string szImagePath, string szMediaPath, string szDbgCmdLine);
'@
, @'
[DllImport("xbdm.dll")]
public static extern int DmGo();
'@
, @'
[DllImport("xbdm.dll")]
public static extern int DmGetUserAccess(string username, out uint access);
'@
, @'
[DllImport("xbdm.dll")]
public static extern int DmHaltThread(uint threadId);
'@
, @'
[DllImport("xbdm.dll")]
public static extern int DmIsDebuggerPresent();
'@
, @'
[DllImport("xbdm.dll")]
public static extern int DmIsFastCAPEnabled();
'@
,@'
[DllImport("xbdm.dll")]
public static extern int DmRemoveUser( string szUserName );
'@
, @'
[DllImport("xbdm.dll")]
public static extern int DmScreenShot( string filename );
'@
, @'
[DllImport("xbdm.dll")]
public static extern int DmIsSecurityEnabled(out bool Enabled);
'@
, @'
[DllImport("xbdm.dll")]
public static extern int DmLoadSymbolsForAllLoadedModules();
'@
, @'
[DllImport("xbdm.dll")]
public static extern int DmMapDevkitDrive();
'@
, @'
[DllImport("xbdm.dll")]
public static extern int DmSetSymbolSearchPath(string path);
'@
, @'
[DllImport("xbdm.dll")]
public static extern int DmUnloadSymbolsForModule(ulong BaseAddress);
'@
, @'
[DllImport("xbdm.dll")]
public static extern int DmMkdir(string directoryName);
'@
,@'
[DllImport("xbdm.dll")]
public static extern int DmSetAdminPassword(string password);
'@
, @'
[DllImport("xbdm.dll")]
public static extern ulong DmPMCGetCounter(ulong reg);
'@
, @'
[DllImport("xbdm.dll")]
public static extern ulong DmPgoSaveSnapshot(string phase, bool reset, int module);
'@
, @'
[DllImport("xbdm.dll")]
public static extern ulong DmPgoSetAllocScale(int module, uint buffersize);
'@
, @'
[DllImport("xbdm.dll")]
public static extern int DmPMCGetCounterCostEstimate(int Counter);
'@
, @'
[DllImport("xbdm.dll")]
public static extern int DmReboot(uint flags);
'@
, @'
[DllImport("xbdm.dll")]
public static extern int DmSetTitle(string szDir, string szTitle, string szCmdLine);
'@
, @'
[DllImport("xbdm.dll")]
public static extern int DmStartProfiling(string filename, uint buffersize);
'@
, @'
[DllImport("xbdm.dll")]
public static extern int DmStopProfiling();
'@
, @'
[DllImport("xbdm.dll")]
public static extern int DmStopOn(uint StopFlags, bool Stop);
'@
, @'
[DllImport("xbdm.dll")]
public static extern int DmSetFileSize(string filename,
    uint fileOffset,
    uint createDisposition);
'@
, @'
[DllImport("xbdm.dll")]
public static extern int DmSetDumpMode(uint dumpmode);
'@
, @'
[DllImport("xbdm.dll")]
static extern int DmSetXboxName(string name);
'@
, @'
public static int SetXBoxName(string name)
{
    return DmSetXboxName(name);
}
'@
,@'
[DllImport("xbdm.dll")]
static extern int DmSetXboxNameNoRegister(string name);
'@
, @'
public static int SetXBoxNameNoRegister(string name)
{
    return DmSetXboxNameNoRegister(name);
}
'@
, @'
[DllImport("xbdm.dll")]
public static extern int DmStop();
'@
, @'
[DllImport("xbdm.dll")]
static extern int DmTranslateError(int hr, [Out]StringBuilder buffer, out int BufferSize);
'@
, @'
public static string DmTranslateError(int hr) {
    int size = 0;
    StringBuilder buffer = new StringBuilder();
    DmTranslateError(hr, buffer, out size);
    return buffer.ToString();
}
'@
 -PassThru


& $psScriptRoot\XbdmEnums.ps1
if (-not $Request -or $Response) {
    & $psScriptRoot\XbpsController.ps1
}

. $psScriptRoot\ConvertTo-GamepadInput.ps1

. $psScriptRoot\Add-Xbox.ps1
. $psScriptRoot\Add-XboxUser.ps1
. $psScriptRoot\Connect-Xbox.ps1
. $psScriptRoot\Connect-XboxController.ps1
. $psScriptRoot\Connect-XboxDebugger.ps1
. $psScriptRoot\Disconnect-XboxController.ps1
. $psScriptRoot\Disconnect-XboxDebugger.ps1
. $psScriptRoot\Get-Xbox.ps1
. $psScriptRoot\Get-XboxTitlePid.ps1
. $psScriptRoot\Get-XboxScreenshot.ps1
. $psScriptRoot\Resume-XboxThread.ps1
. $psScriptRoot\Restart-Xbox.ps1
. $psScriptRoot\Remove-Xbox.ps1
. $psScriptRoot\Start-XboxCrashDump.ps1
. $psScriptRoot\Start-XboxProfiling.ps1
. $psScriptRoot\Set-Xbox.ps1
. $psScriptRoot\Set-XboxTitle.ps1
. $psScriptRoot\Send-Xbox.ps1
. $psScriptRoot\Stop-Xbox.ps1
. $psScriptRoot\Stop-XboxProfiling.ps1
. $psScriptRoot\Stop-XboxThread.ps1
. $psScriptRoot\Stop-ReceivingGamepadInput.ps1
. $psScriptRoot\Show-Dashboard.ps1
. $psScriptRoot\Test-XboxSecurityEnabled.ps1



#Export-ModuleMember -Function * -Variable xbdm