Hand-converted the four .vcproj projects to .vcxproj (Win32, v143, Windows 11 SDK + DXSDK June 2010 for d3dx9/dxerr only). WinTesla.sln now builds the v143 projects; the legacy solution is kept as WinTesla_vc9.sln. Kept: /Zp1 in Munga_L4+RP_L4, Unicode, x86, /DYNAMICBASE:NO, /FORCE:MULTIPLE (header-defined globals still duplicated across TUs). Changed: CRT unified to /MD(d); import libs linked by the exes instead of merged into Munga_L4.lib; WINDOWS_IGNORE_PACKING_MISMATCH and _SILENCE_STDEXT_HASH_DEPRECATION_WARNINGS defined; legacy_stdio_definitions.lib for the June-2010 dxerr.lib. Source fixes, all behavior-preserving: Time gains standard (non-volatile) copy-ctor/assignment overloads (rvalues cannot bind to volatile& in standard C++); operator==(SOCKADDR_IN&,...) made inline; L4DINPUT's Enum*Callback pair renamed DIEnum* (collided with L4CTRL's under LTCG); std::ios.in -> std::ios::in in CAMMGR.cpp. Verified: VC9 baseline rebuilt from this tree first, then the v143 build compared against it in a sandboxed game working copy - identical logs and behavior through RIO init (against vRIO) and mission load, including the same pre-existing AV in d3d_OBJECT::LoadTexture (L4D3D.cpp:262) that both toolchains hit; documented in BUILD.md 4 as the next debugging target. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
195 lines
4.8 KiB
C++
195 lines
4.8 KiB
C++
#include "mungal4.h"
|
|
#pragma hdrstop
|
|
|
|
#include "l4dinput.h"
|
|
|
|
#define DI_TRIGGER 0
|
|
#define DI_THUMB1 2
|
|
#define DI_THUMB2 1
|
|
#define DI_THUMB3 3
|
|
|
|
DIJoystick::DIJoystick(HINSTANCE hInstance, HWND hWnd)
|
|
{
|
|
mDI = NULL;
|
|
mJoystick = NULL;
|
|
|
|
if (SUCCEEDED(DirectInput8Create(hInstance, DIRECTINPUT_VERSION, IID_IDirectInput8, (void**)&mDI, NULL)))
|
|
{
|
|
mDI->EnumDevices(DI8DEVCLASS_GAMECTRL, DIEnumJoysticksCallback, this, DIEDFL_ATTACHEDONLY);
|
|
if (mJoystick)
|
|
if (SUCCEEDED(mJoystick->SetDataFormat(&c_dfDIJoystick2)))
|
|
if (SUCCEEDED(mJoystick->SetCooperativeLevel(hWnd, DISCL_EXCLUSIVE | DISCL_BACKGROUND)))
|
|
if (SUCCEEDED(mJoystick->EnumObjects(DIEnumAxesCallback, this, DIDFT_AXIS)))
|
|
return;
|
|
}
|
|
|
|
if (mDI)
|
|
{
|
|
mDI->Release();
|
|
mDI = NULL;
|
|
}
|
|
if (mJoystick)
|
|
{
|
|
mJoystick->Release();
|
|
mJoystick = NULL;
|
|
}
|
|
}
|
|
|
|
DIJoystick::~DIJoystick()
|
|
{
|
|
if (mJoystick)
|
|
{
|
|
mJoystick->Unacquire();
|
|
mJoystick->Release();
|
|
mJoystick = NULL;
|
|
}
|
|
|
|
if (mDI)
|
|
{
|
|
mDI->Release();
|
|
mDI = NULL;
|
|
}
|
|
}
|
|
|
|
BOOL CALLBACK DIEnumJoysticksCallback(const DIDEVICEINSTANCE* pdidInstance, VOID* pContext)
|
|
{
|
|
DIJoystick *joystick = (DIJoystick*)pContext;
|
|
if (FAILED(joystick->mDI->CreateDevice(pdidInstance->guidInstance, &joystick->mJoystick, NULL)))
|
|
return DIENUM_CONTINUE;
|
|
|
|
return DIENUM_STOP;
|
|
}
|
|
|
|
BOOL CALLBACK DIEnumAxesCallback(LPCDIDEVICEOBJECTINSTANCE lpddoi, LPVOID pvRef)
|
|
{
|
|
DIJoystick *joystick = (DIJoystick*)pvRef;
|
|
DIPROPRANGE diprg;
|
|
diprg.diph.dwSize = sizeof(DIPROPRANGE);
|
|
diprg.diph.dwHeaderSize = sizeof(DIPROPHEADER);
|
|
diprg.diph.dwHow = DIPH_BYID;
|
|
diprg.diph.dwObj = lpddoi->dwType;
|
|
diprg.lMax = diprg.lMax = 0;
|
|
|
|
if (lpddoi->guidType == GUID_XAxis)
|
|
{
|
|
if (SUCCEEDED(joystick->mJoystick->GetProperty(DIPROP_RANGE, &diprg.diph)))
|
|
{
|
|
joystick->xAxisMin = diprg.lMin;
|
|
joystick->xAxisMax = diprg.lMax;
|
|
}
|
|
}
|
|
else if (lpddoi->guidType == GUID_YAxis)
|
|
{
|
|
if (SUCCEEDED(joystick->mJoystick->GetProperty(DIPROP_RANGE, &diprg.diph)))
|
|
{
|
|
joystick->yAxisMin = diprg.lMin;
|
|
joystick->yAxisMax = diprg.lMax;
|
|
}
|
|
}
|
|
else if (lpddoi->guidType == GUID_ZAxis)
|
|
{
|
|
if (SUCCEEDED(joystick->mJoystick->GetProperty(DIPROP_RANGE, &diprg.diph)))
|
|
{
|
|
joystick->zAxisMin = diprg.lMin;
|
|
joystick->zAxisMax = diprg.lMax;
|
|
}
|
|
}
|
|
else if (lpddoi->guidType == GUID_RxAxis)
|
|
{
|
|
}
|
|
else if (lpddoi->guidType == GUID_RyAxis)
|
|
{
|
|
}
|
|
else if (lpddoi->guidType == GUID_RzAxis)
|
|
{
|
|
if (SUCCEEDED(joystick->mJoystick->GetProperty(DIPROP_RANGE, &diprg.diph)))
|
|
{
|
|
joystick->rzAxisMin = diprg.lMin;
|
|
joystick->rzAxisMax = diprg.lMax;
|
|
}
|
|
}
|
|
else if (lpddoi->guidType == GUID_Slider)
|
|
{
|
|
if (SUCCEEDED(joystick->mJoystick->GetProperty(DIPROP_RANGE, &diprg.diph)))
|
|
{
|
|
joystick->zAxisMin = diprg.lMin;
|
|
joystick->zAxisMax = diprg.lMax;
|
|
}
|
|
}
|
|
|
|
return DIENUM_CONTINUE;
|
|
}
|
|
|
|
bool DIJoystick::Poll()
|
|
{
|
|
HRESULT hr;
|
|
if (mJoystick)
|
|
{
|
|
hr = mJoystick->Poll();
|
|
if (FAILED(hr))
|
|
{
|
|
DEBUG_STREAM << "Poll failed: HR = " << hr << std::endl << std::flush;
|
|
hr = mJoystick->Acquire();
|
|
while (hr == DIERR_INPUTLOST)
|
|
{
|
|
DEBUG_STREAM << "Acquire failed: HR = " << hr << std::endl << std::flush;
|
|
hr = mJoystick->Acquire();
|
|
}
|
|
return false;
|
|
}
|
|
|
|
if (FAILED(hr = mJoystick->GetDeviceState(sizeof(DIJOYSTATE2), &mJoystate)))
|
|
{
|
|
DEBUG_STREAM << "GetState failed: HR = " << hr << std::endl << std::flush;
|
|
return false;
|
|
}
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
void DIJoystick::Update()
|
|
{
|
|
if (Poll())
|
|
{
|
|
// Handle analog data
|
|
Value.x = ((Scalar)(mJoystate.lX - xAxisMin) / (Scalar)(xAxisMax - xAxisMin)) * 2.0f - 1.0f;
|
|
Value.y = ((Scalar)(mJoystate.lY - yAxisMin) / (Scalar)(yAxisMax - yAxisMin)) * 2.0f - 1.0f;
|
|
LONG z = (mJoystate.lZ == 0 ? mJoystate.rglSlider[0] : mJoystate.lZ);
|
|
ExtendedValue.y = 1.0f - (Scalar)(z - zAxisMin) / (Scalar)(zAxisMax - zAxisMin);
|
|
// full left rotation = 0, center rotation = 1/2 range, full right = full range
|
|
LONG rot = (Scalar)(mJoystate.lRz - rzAxisMin);
|
|
Scalar half = (Scalar)(rzAxisMax - rzAxisMin) / 2.0f;
|
|
Rotation.x = (Scalar)0;
|
|
Rotation.y = (Scalar)0;
|
|
if (rot <= half)
|
|
Rotation.x = ((half - rot) / half) * 470.0;
|
|
else
|
|
Rotation.y = ((rot - half) / half) * 470.0;
|
|
|
|
// Handle button changes
|
|
int newButtons = 0;
|
|
if (mJoystate.rgbButtons[DI_TRIGGER])
|
|
newButtons |= Joystick::Trigger;
|
|
if (mJoystate.rgbButtons[DI_THUMB1])
|
|
newButtons |= Joystick::Thumb1;
|
|
if (mJoystate.rgbButtons[DI_THUMB2])
|
|
newButtons |= Joystick::Thumb2;
|
|
if (mJoystate.rgbButtons[DI_THUMB3])
|
|
newButtons |= Joystick::Thumb3;
|
|
if (mJoystate.rgdwPOV[0] == 0)
|
|
newButtons |= Joystick::HatUp;
|
|
if (mJoystate.rgdwPOV[0] == 9000)
|
|
newButtons |= Joystick::HatRight;
|
|
if (mJoystate.rgdwPOV[0] == 18000)
|
|
newButtons |= Joystick::HatDown;
|
|
if (mJoystate.rgdwPOV[0] == 27000)
|
|
newButtons |= Joystick::HatLeft;
|
|
|
|
ButtonPressed = (oldButtons ^ newButtons) & newButtons;
|
|
ButtonReleased = (oldButtons ^ newButtons) & oldButtons;
|
|
oldButtons = newButtons;
|
|
}
|
|
}
|
|
|