Merge pull request #125 from WinDurango/fixes

Add Local Multiplayer
This commit is contained in:
Darien Johnson
2025-01-16 01:27:50 -05:00
committed by GitHub
8 changed files with 72 additions and 37 deletions

View File

@@ -11,30 +11,50 @@ namespace winrt::Windows::Xbox::Input::implementation
{
winrt::Windows::Foundation::Collections::IVectorView<winrt::Windows::Xbox::Input::IGamepad> Gamepad::Gamepads()
{
IGamepad dummyGamepad = winrt::make<Gamepad>( );
auto vector = winrt::single_threaded_vector<IGamepad>( );
vector.Append(dummyGamepad);
return vector.GetView( );
wprintf(L"Gamepad || Gamepads Queried!\n");
if (staticGamepads == Foundation::Collections::IVector<winrt::Windows::Xbox::Input::IGamepad>(nullptr) || staticGamepads.Size( ) == 0) {
staticGamepads = winrt::single_threaded_vector<Input::IGamepad>( );
for (DWORD gamepad = 0; gamepad < XUSER_MAX_COUNT; gamepad++)
{
XINPUT_CAPABILITIES capabilities;
if (XInputGetCapabilities(gamepad, XINPUT_FLAG_GAMEPAD, &capabilities) == ERROR_SUCCESS)
{
wprintf(L"Gamepad || Gamepad %d Created!\n", gamepad);
IGamepad newGamepad = winrt::make<Gamepad>(gamepad);
staticGamepads.Append(newGamepad);
continue;
}
}
}
return staticGamepads.GetView( );
}
winrt::event_token Gamepad::GamepadAdded(winrt::Windows::Foundation::EventHandler<winrt::Windows::Xbox::Input::GamepadAddedEventArgs> const& handler)
{
wprintf(L"Gamepad || Gamepad Added!\n");
return {};
}
void Gamepad::GamepadAdded(winrt::event_token const& token) noexcept
{
wprintf(L"Gamepad || Gamepad Added!\n");
throw hresult_not_implemented();
}
winrt::event_token Gamepad::GamepadRemoved(winrt::Windows::Foundation::EventHandler<winrt::Windows::Xbox::Input::GamepadRemovedEventArgs> const& handler)
{
wprintf(L"Gamepad || Gamepad Removed!\n");
return {};
}
void Gamepad::GamepadRemoved(winrt::event_token const& token) noexcept
{
wprintf(L"Gamepad || Gamepad Removed!\n");
throw hresult_not_implemented();
}
uint64_t Gamepad::Id()
{
return 1;
wprintf(L"Gamepad || Gamepad ID ( %d ) Queried!\n", m_id);
return m_id;
}
hstring Gamepad::Type()
{
@@ -42,7 +62,8 @@ namespace winrt::Windows::Xbox::Input::implementation
}
winrt::Windows::Xbox::System::User Gamepad::User()
{
return System::implementation::User::Users( ).GetAt(0);
wprintf(L"Gamepad || User Queried!\n");
return System::implementation::User::Users( ).GetAt(Id());
}
winrt::Windows::Xbox::Input::INavigationReading Gamepad::GetNavigationReading()
{
@@ -69,7 +90,7 @@ namespace winrt::Windows::Xbox::Input::implementation
ZeroMemory(&vibration, sizeof(XINPUT_VIBRATION));
vibration.wLeftMotorSpeed = value.LeftMotorLevel * 65535;
vibration.wRightMotorSpeed = value.RightMotorLevel * 65535;
XInputSetState(0, &vibration);
XInputSetState(m_id, &vibration);
}
winrt::Windows::Xbox::Input::IGamepadReading Gamepad::GetCurrentReading()
{
@@ -99,28 +120,26 @@ namespace winrt::Windows::Xbox::Input::implementation
{ XINPUT_GAMEPAD_Y, GamepadButtons::Y },
};
for (DWORD user = 0; user < XUSER_MAX_COUNT; user++) {
if (XInputGetState(user, &xiState) == ERROR_SUCCESS)
if (XInputGetState(m_id, &xiState) == ERROR_SUCCESS)
{
for (int i = 0; i < ARRAYSIZE(buttons); i++)
{
for (int i = 0; i < ARRAYSIZE(buttons); i++)
if (xiState.Gamepad.wButtons & buttons[ i ].first)
{
if (xiState.Gamepad.wButtons & buttons[ i ].first)
{
reading.Buttons |= buttons[ i ].second;
}
reading.Buttons |= buttons[ i ].second;
}
reading.LeftTrigger = xiState.Gamepad.bLeftTrigger / 255.f;
reading.RightTrigger = xiState.Gamepad.bRightTrigger / 255.f;
reading.LeftThumbstickX = xiState.Gamepad.sThumbLX / 32768.f;
reading.LeftThumbstickY = xiState.Gamepad.sThumbLY / 32768.f;
reading.RightThumbstickX = xiState.Gamepad.sThumbRX / 32768.f;
reading.RightThumbstickY = xiState.Gamepad.sThumbRY / 32768.f;
}
//else {
// printf("Controller input failure: %x\n", XInputGetState(0, &xiState));
//}
}
reading.LeftTrigger = xiState.Gamepad.bLeftTrigger / 255.f;
reading.RightTrigger = xiState.Gamepad.bRightTrigger / 255.f;
reading.LeftThumbstickX = xiState.Gamepad.sThumbLX / 32768.f;
reading.LeftThumbstickY = xiState.Gamepad.sThumbLY / 32768.f;
reading.RightThumbstickX = xiState.Gamepad.sThumbRX / 32768.f;
reading.RightThumbstickY = xiState.Gamepad.sThumbRY / 32768.f;
}
//else {
// printf("Gamepad input failure: %x\n", XInputGetState(0, &xiState));
//}
if (GetAsyncKeyState('A'))
reading.Buttons |= GamepadButtons::A;

View File

@@ -6,6 +6,7 @@ namespace winrt::Windows::Xbox::Input::implementation
struct Gamepad : GamepadT<Gamepad>
{
Gamepad() = default;
Gamepad(uint64_t id) : m_id(id) {}
static winrt::Windows::Foundation::Collections::IVectorView<winrt::Windows::Xbox::Input::IGamepad> Gamepads();
static winrt::event_token GamepadAdded(winrt::Windows::Foundation::EventHandler<winrt::Windows::Xbox::Input::GamepadAddedEventArgs> const& handler);
@@ -25,6 +26,8 @@ namespace winrt::Windows::Xbox::Input::implementation
winrt::event_token ReadingChanged(winrt::Windows::Foundation::TypedEventHandler<winrt::Windows::Xbox::Input::Gamepad, winrt::Windows::Xbox::Input::IGamepadReadingChangedEventArgs> const& handler);
void ReadingChanged(winrt::event_token const& token) noexcept;
bool IsTrusted();
inline static winrt::Windows::Foundation::Collections::IVector<winrt::Windows::Xbox::Input::IGamepad> staticGamepads = { nullptr };
uint64_t m_id{ 0 };
};
}
namespace winrt::Windows::Xbox::Input::factory_implementation

View File

@@ -20,13 +20,17 @@ namespace winrt::Windows::Xbox::System::implementation
}
winrt::Windows::Foundation::Collections::IVectorView<winrt::Windows::Xbox::System::User> User::Users()
{
if (staticUser == System::User(nullptr))
staticUser = winrt::make<User>( );
if (staticUsers == Foundation::Collections::IVector<winrt::Windows::Xbox::System::User>(nullptr) || staticUsers.Size() == 0)
{
wprintf(L"User || Users Queried!\n");
if (staticUsers == Foundation::Collections::IVector<winrt::Windows::Xbox::System::User>(nullptr) || staticUsers.Size( ) == 0) {
staticUsers = winrt::single_threaded_vector<System::User>( );
staticUsers.Append(staticUser);
for (int i = 0; i < 4; i++)
{
wprintf(L"User || User %d Created!\n", i);
staticUser = winrt::make<User>(i);
staticUsers.Append(staticUser);
continue;
}
}
return staticUsers.GetView();
@@ -137,7 +141,7 @@ namespace winrt::Windows::Xbox::System::implementation
}
uint32_t User::Id()
{
return 1;
return m_id;
}
winrt::Windows::Foundation::Collections::IVectorView<winrt::Windows::Xbox::System::IAudioDeviceInfo> User::AudioDevices()
{
@@ -151,7 +155,8 @@ namespace winrt::Windows::Xbox::System::implementation
}
winrt::Windows::Xbox::System::UserDisplayInfo User::DisplayInfo()
{
return winrt::make<implementation::UserDisplayInfo>( );
hstring gamertag = to_hstring(m_id);
return winrt::make<implementation::UserDisplayInfo>(gamertag);
}
bool User::IsGuest()
{

View File

@@ -25,6 +25,7 @@ namespace winrt::Windows::Xbox::System::implementation
struct User : UserT<User>
{
User() = default;
User(uint64_t id) : m_id(id) {}
static winrt::Windows::Xbox::System::UserOnlineState OnlineState();
static winrt::event_token OnlineStateChanged(winrt::Windows::Foundation::EventHandler<winrt::Windows::Xbox::System::OnlineStateChangedEventArgs> const& handler);
@@ -66,6 +67,7 @@ namespace winrt::Windows::Xbox::System::implementation
winrt::Windows::Foundation::IAsyncOperation<winrt::Windows::Xbox::System::GetTokenAndSignatureResult> GetTokenAndSignatureAsync(hstring httpMethod, hstring url, hstring headers);
winrt::Windows::Foundation::IAsyncOperation<winrt::Windows::Xbox::System::GetTokenAndSignatureResult> GetTokenAndSignatureAsync(hstring httpMethod, hstring url, hstring headers, array_view<uint8_t const> body);
winrt::Windows::Foundation::IAsyncOperation<winrt::Windows::Xbox::System::GetTokenAndSignatureResult> GetTokenAndSignatureAsync(hstring httpMethod, hstring url, hstring headers, hstring body);
uint64_t m_id {0};
private:
inline static winrt::event<winrt::Windows::Foundation::EventHandler<winrt::Windows::Xbox::System::UserAddedEventArgs>> m_userAddedEvent;
inline static winrt::event<winrt::Windows::Foundation::EventHandler<winrt::Windows::Xbox::System::UserRemovedEventArgs>> m_userRemovedEvent;

View File

@@ -26,7 +26,8 @@ namespace winrt::Windows::Xbox::System::implementation
hstring UserDisplayInfo::Gamertag()
{
printf("!!!!! Windows.Xbox.System.UserDisplayInfo [Gamertag] NOT IMPLEMENTED !!!!\n");
return winrt::to_hstring("durangler");
hstring gamertag = L"durangler" + m_gamertag;
return gamertag;
}
uint32_t UserDisplayInfo::GamerScore()
{
@@ -41,7 +42,8 @@ namespace winrt::Windows::Xbox::System::implementation
hstring UserDisplayInfo::GameDisplayName()
{
printf("!!!!! Windows.Xbox.System.UserDisplayInfo [GameDisplayName] NOT IMPLEMENTED !!!!\n");
return winrt::to_hstring("durangler");
hstring gamertag = L"durangler" + m_gamertag;
return gamertag;
}
int32_t UserDisplayInfo::Reputation()
{
@@ -54,7 +56,7 @@ namespace winrt::Windows::Xbox::System::implementation
return UserAgeGroup::Unknown;
}
winrt::Windows::Foundation::Collections::IVectorView<uint32_t> UserDisplayInfo::Privileges()
{
{
printf("!!!!! Windows.Xbox.System.UserDisplayInfo [Privileges] NOT IMPLEMENTED !!!!\n");
auto vector = winrt::single_threaded_vector<uint32_t>();

View File

@@ -25,6 +25,7 @@ namespace winrt::Windows::Xbox::System::implementation
struct UserDisplayInfo : UserDisplayInfoT<UserDisplayInfo>
{
UserDisplayInfo() = default;
UserDisplayInfo(hstring gamertag) : m_gamertag(gamertag) {}
hstring Gamertag();
uint32_t GamerScore();
@@ -33,5 +34,6 @@ namespace winrt::Windows::Xbox::System::implementation
int32_t Reputation();
winrt::Windows::Xbox::System::UserAgeGroup AgeGroup();
winrt::Windows::Foundation::Collections::IVectorView<uint32_t> Privileges();
hstring m_gamertag{ 0 };
};
}

View File

@@ -25,6 +25,7 @@ namespace winrt::Windows::Xbox::UI::implementation
{
winrt::Windows::Xbox::System::IUser AccountPickerResult::User()
{
return System::User::Users( ).GetAt(0);
uint64_t count = signedInUsersCount + 1;
return System::User::Users( ).GetAt(count);
}
}

View File

@@ -26,6 +26,7 @@ namespace winrt::Windows::Xbox::UI::implementation
{
AccountPickerResult() = default;
uint64_t signedInUsersCount = 1;
winrt::Windows::Xbox::System::IUser User();
};
}