From 31f98570921225d22e2338852fd3dcf696422031 Mon Sep 17 00:00:00 2001 From: xan1242 <8014093+xan1242@users.noreply.github.com> Date: Sun, 2 Oct 2022 22:57:36 +0200 Subject: [PATCH] custom steering handler --- Config-UG/EventReference.txt | 22 ++- Config-UG/NFSU_XtendedInput.ini | 37 ++-- Config-UG2/EventReference.txt | 24 ++- Config-UG2/NFSU_XtendedInput.ini | 287 +++++-------------------------- NFSU2_Addresses.h | 4 + NFSU_Addresses.h | 4 + dllmain.cpp | 267 ++++++++++++++-------------- 7 files changed, 245 insertions(+), 400 deletions(-) diff --git a/Config-UG/EventReference.txt b/Config-UG/EventReference.txt index 92fe6dc..5b89d3f 100644 --- a/Config-UG/EventReference.txt +++ b/Config-UG/EventReference.txt @@ -67,6 +67,24 @@ Both ports are monitored for XInput separately, whereas on keyboard they're not NOTE: some events (such as quitting with Q key or launching the tutorial video with LT) are hardcoded due to the way they're coded in the game +== STEER INPUT SPECIAL NOTES == + +Due to the buggy nature of the steer input handler, its code had to be rewritten. +This *only* affects regular races, as drag races use a different event. +This also enables higher resolution readout from the gamepad axis, as well as the ability to assign steering to both the analog axis and the digital buttons. + +These are the special assignments available for steering input (gamepad): +SteerLeftButton -- you may only assign buttons to these, not analog axis +SteerRightButton +SteerLeftAxis -- you may only assign analog axis to these, not buttons +SteerRightAxis + +These are the special assignments available for steering input (keyboard): +KeyboardSteerLeft +KeyboardSteerRight + +== REGULAR EVENTS == + JOY_EVENT_NULL JOY_EVENT_TYPE_CHANGED JOY_EVENT_EXIT_DEMO_DISC @@ -200,8 +218,8 @@ JOY_EVENT_REPLAY_HIDE_TIMELINE JOY_EVENT_REPLAY_MARK_DEMO JOY_EVENT_REPLAY_TEST_DEMO JOY_EVENT_REPLAY_ERASE_DEMO -JOY_EVENT_STEER -- you may only assign an analog axis or DPAD, nothing else -JOY_EVENT_STEER_ANALOG -- breaks right after using JOY_EVENT_STEER (JOY_EVENT_STEER is analog as well anyway) +JOY_EVENT_STEER -- steer input is NOT handled by the game code, therefore this event is not read +JOY_EVENT_STEER_ANALOG -- same as previous steer event - not handled by game code, not parsed JOY_EVENT_THROTTLE JOY_EVENT_THROTTLE_ANALOG JOY_EVENT_THROTTLE_ANALOG_ALTERNATE diff --git a/Config-UG/NFSU_XtendedInput.ini b/Config-UG/NFSU_XtendedInput.ini index 3366ff0..3d6df9a 100644 --- a/Config-UG/NFSU_XtendedInput.ini +++ b/Config-UG/NFSU_XtendedInput.ini @@ -16,7 +16,7 @@ ControllerIconMode = 0 // 0 = Xbox, 1 = PlayStation 4 -- MAKE SURE TO DISABLE WI FirstControlDevice = 0 // 0 = Keyboard, 1 = Controller -- for setting the first state [Events] -// FE controls +; FE controls JOY_EVENT_FENG_PAD_UP = XINPUT_GAMEPAD_DPAD_UP JOY_EVENT_FENG_PAD_DOWN = XINPUT_GAMEPAD_DPAD_DOWN JOY_EVENT_FENG_PAD_LEFT = XINPUT_GAMEPAD_DPAD_LEFT @@ -55,15 +55,16 @@ JOY_EVENT_CARSEL_CHANGE_MODE = XINPUT_GAMEPAD_RT JOY_EVENT_START = XINPUT_GAMEPAD_START JOY_EVENT_SELECT = XINPUT_GAMEPAD_A JOY_EVENT_SKIP = XINPUT_GAMEPAD_A -// In-Game controls +; In-Game controls +SteerLeftButton = 0 +SteerRightButton = 0 +SteerLeftAxis = XINPUT_GAMEPAD_LS_LEFT +SteerRightAxis = XINPUT_GAMEPAD_LS_RIGHT JOY_EVENT_THROTTLE_ANALOG = XINPUT_GAMEPAD_RT JOY_EVENT_BRAKE_ANALOG = XINPUT_GAMEPAD_LT -JOY_EVENT_STEER = XINPUT_GAMEPAD_LS_X -// commented out analog because it causes issues, when regular steer is activated, analog steering dies -//JOY_EVENT_STEER_ANALOG = XINPUT_GAMEPAD_LS_X -// horribly broken - goes full left or right... -//JOY_EVENT_DRAG_RACE_CHANGE_LANE_LEFT_ANALOG = XINPUT_GAMEPAD_LS_X -//JOY_EVENT_DRAG_RACE_CHANGE_LANE_RIGHT_ANALOG = XINPUT_GAMEPAD_LS_X +; horribly broken - goes full left or right... +;JOY_EVENT_DRAG_RACE_CHANGE_LANE_LEFT_ANALOG = XINPUT_GAMEPAD_LS_X +;JOY_EVENT_DRAG_RACE_CHANGE_LANE_RIGHT_ANALOG = XINPUT_GAMEPAD_LS_X JOY_EVENT_DRAG_RACE_CHANGE_LANE_LEFT = XINPUT_GAMEPAD_LS_LEFT JOY_EVENT_DRAG_RACE_CHANGE_LANE_RIGHT = XINPUT_GAMEPAD_LS_RIGHT JOY_EVENT_SHIFTUP = XINPUT_GAMEPAD_RS_UP @@ -74,13 +75,13 @@ JOY_EVENT_CAMERA_LOOKBACK = XINPUT_GAMEPAD_X JOY_EVENT_CAMERA_POV_CHANGE = XINPUT_GAMEPAD_Y JOY_EVENT_PAUSE = XINPUT_GAMEPAD_START JOY_EVENT_RESET_CAR = XINPUT_GAMEPAD_BACK -// HP2 leftovers -- these all work +; HP2 leftovers -- these all work JOY_EVENT_ZONE_PREVIEW = XINPUT_GAMEPAD_RIGHT_SHOULDER JOY_EVENT_ZONE_FREEZE = XINPUT_GAMEPAD_LEFT_SHOULDER JOY_EVENT_HONK_HORN = XINPUT_GAMEPAD_LEFT_THUMB JOY_EVENT_CYCLE_HUD = XINPUT_GAMEPAD_DPAD_UP JOY_EVENT_ZONE_SLOMO = XINPUT_GAMEPAD_DPAD_DOWN -// debug camera -- only on port 2 +; debug camera -- only on port 2 JOY_EVENT_CHANGE_DEBUG_CAMERA = XINPUT_GAMEPAD_BACK JOY_EVENT_DEBUG_CAMERA_DROP_CAR = XINPUT_GAMEPAD_START JOY_EVENT_DEBUG_CAMERA_INOUT = XINPUT_GAMEPAD_LS_Y @@ -112,7 +113,7 @@ JOY_EVENT_DEBUG_CAMERA_SLOW = XINPUT_GAMEPAD_LEFT_THUMB JOY_EVENT_DEBUG_CAMERA_FORWARD_BLINK = XINPUT_GAMEPAD_DPAD_UP JOY_EVENT_DEBUG_CAMERA_BACKWARD_BLINK = XINPUT_GAMEPAD_DPAD_DOWN [EventsKB] -// FE controls +; FE controls JOY_EVENT_FENG_PAD_UP = VK_UP JOY_EVENT_FENG_PAD_DOWN = VK_DOWN JOY_EVENT_FENG_PAD_LEFT = VK_LEFT @@ -123,7 +124,7 @@ JOY_EVENT_FENG_BUTTON0 = G JOY_EVENT_FENG_BUTTON1 = F JOY_EVENT_FENG_BUTTON2 = 9 JOY_EVENT_FENG_BUTTON3 = 0 -//JOY_EVENT_FENG_START = VK_ESCAPE +;JOY_EVENT_FENG_START = VK_ESCAPE JOY_EVENT_FENG_HELP = H JOY_EVENT_FENG_LTRIGGER = 9 JOY_EVENT_FENG_RTRIGGER = 0 @@ -136,13 +137,13 @@ JOY_EVENT_MENU_R1 = 0 JOY_EVENT_MENU_R2 = P JOY_EVENT_MENU_SQUARE = Z JOY_EVENT_CARSEL_UNLOCK = U -//JOY_EVENT_START = VK_ESCAPE +;JOY_EVENT_START = VK_ESCAPE JOY_EVENT_SELECT = VK_RETURN JOY_EVENT_CARSEL_ORBIT_UP = W JOY_EVENT_CARSEL_ORBIT_DOWN = S JOY_EVENT_CARSEL_ORBIT_RIGHT = A JOY_EVENT_CARSEL_ORBIT_LEFT = D -// In-Game controls +; In-Game controls KeyboardSteerLeft = VK_LEFT KeyboardSteerRight = VK_RIGHT JOY_EVENT_THROTTLE = VK_UP @@ -158,13 +159,13 @@ JOY_EVENT_CAMERA_POV_CHANGE = C JOY_EVENT_RESET_CAR = R JOY_EVENT_DRAG_RACE_CHANGE_LANE_LEFT = VK_LEFT JOY_EVENT_DRAG_RACE_CHANGE_LANE_RIGHT = VK_RIGHT -// HP2 leftovers -- these all work +; HP2 leftovers -- these all work JOY_EVENT_ZONE_PREVIEW = VK_DELETE JOY_EVENT_ZONE_FREEZE = VK_NEXT JOY_EVENT_HONK_HORN = H -//JOY_EVENT_CYCLE_HUD = XINPUT_GAMEPAD_DPAD_UP -//JOY_EVENT_ZONE_SLOMO = XINPUT_GAMEPAD_DPAD_DOWN -// debug camera +;JOY_EVENT_CYCLE_HUD = XINPUT_GAMEPAD_DPAD_UP +;JOY_EVENT_ZONE_SLOMO = XINPUT_GAMEPAD_DPAD_DOWN +; debug camera JOY_EVENT_CHANGE_DEBUG_CAMERA = M JOY_EVENT_DEBUG_CAMERA_DROP_CAR = 5 JOY_EVENT_DEBUG_CAMERA_MOVE_FWD = W diff --git a/Config-UG2/EventReference.txt b/Config-UG2/EventReference.txt index 064108b..79a0c44 100644 --- a/Config-UG2/EventReference.txt +++ b/Config-UG2/EventReference.txt @@ -67,6 +67,24 @@ Both ports are monitored for XInput separately, whereas on keyboard they're not NOTE: some events (such as quitting with Q key) are hardcoded due to the way they're coded in the game +== STEER INPUT SPECIAL NOTES == + +Due to the buggy nature of the steer input handler, its code had to be rewritten. +This *only* affects regular races, as drag races use a different event. +This also enables higher resolution readout from the gamepad axis, as well as the ability to assign steering to both the analog axis and the digital buttons. + +These are the special assignments available for steering input (gamepad): +SteerLeftButton -- you may only assign buttons to these, not analog axis +SteerRightButton +SteerLeftAxis -- you may only assign analog axis to these, not buttons +SteerRightAxis + +These are the special assignments available for steering input (keyboard): +KeyboardSteerLeft +KeyboardSteerRight + +== REGULAR EVENTS == + JOY_EVENT_NULL JOY_EVENT_TYPE_CHANGED JOY_EVENT_LIVE_TYPE_CHANGED @@ -202,8 +220,8 @@ JOY_EVENT_REPLAY_HIDE_TIMELINE JOY_EVENT_REPLAY_MARK_DEMO JOY_EVENT_REPLAY_TEST_DEMO JOY_EVENT_REPLAY_ERASE_DEMO -JOY_EVENT_STEER -- you may only assign an analog axis or DPAD, nothing else -JOY_EVENT_STEER_ANALOG -- breaks right after using JOY_EVENT_STEER (JOY_EVENT_STEER is analog as well anyway) +JOY_EVENT_STEER -- steer input is NOT handled by the game code, therefore this event is not read +JOY_EVENT_STEER_ANALOG -- same as previous steer event - not handled by game code, not parsed JOY_EVENT_THROTTLE JOY_EVENT_THROTTLE_ANALOG JOY_EVENT_THROTTLE_ANALOG_ALTERNATE @@ -289,4 +307,4 @@ JOY_EVENT_CAMERA_EDITOR_BUBBLE_BACK_FORTH JOY_EVENT_CAMERA_EDITOR_SHAKE_MAG JOY_EVENT_CAMERA_EDITOR_SHAKE_FRQ JOY_EVENT_CAMERA_EDITOR_SHUTTLE_LEFT_RIGHT -JOY_EVENT_CAMERA_EDITOR_SHUTTLE_SPEED \ No newline at end of file +JOY_EVENT_CAMERA_EDITOR_SHUTTLE_SPEED diff --git a/Config-UG2/NFSU_XtendedInput.ini b/Config-UG2/NFSU_XtendedInput.ini index 81b5019..e288931 100644 --- a/Config-UG2/NFSU_XtendedInput.ini +++ b/Config-UG2/NFSU_XtendedInput.ini @@ -14,7 +14,7 @@ DeadzonePercent_AnalogStickDigital = 0.50 // deadzone for analog sticks digital DeadzonePercent_AnalogTriggerDigital = 0.12 // same for triggers [Events] -// FE controls +; FE controls JOY_EVENT_FENG_PAD_UP = XINPUT_GAMEPAD_DPAD_UP JOY_EVENT_FENG_PAD_DOWN = XINPUT_GAMEPAD_DPAD_DOWN JOY_EVENT_FENG_PAD_LEFT = XINPUT_GAMEPAD_DPAD_LEFT @@ -53,15 +53,16 @@ JOY_EVENT_CARSEL_CHANGE_MODE = XINPUT_GAMEPAD_RT JOY_EVENT_START = XINPUT_GAMEPAD_START JOY_EVENT_SELECT = XINPUT_GAMEPAD_A JOY_EVENT_SKIP = XINPUT_GAMEPAD_A -// In-Game controls +; In-Game controls +SteerLeftButton = 0 +SteerRightButton = 0 +SteerLeftAxis = XINPUT_GAMEPAD_LS_LEFT +SteerRightAxis = XINPUT_GAMEPAD_LS_RIGHT JOY_EVENT_THROTTLE_ANALOG = XINPUT_GAMEPAD_RT JOY_EVENT_BRAKE_ANALOG = XINPUT_GAMEPAD_LT -JOY_EVENT_STEER = XINPUT_GAMEPAD_LS_X -// commented out analog because it causes issues, when regular steer is activated, analog steering dies -//JOY_EVENT_STEER_ANALOG = XINPUT_GAMEPAD_LS_X -// horribly broken - goes full left or right... -//JOY_EVENT_DRAG_RACE_CHANGE_LANE_LEFT_ANALOG = XINPUT_GAMEPAD_LS_X -//JOY_EVENT_DRAG_RACE_CHANGE_LANE_RIGHT_ANALOG = XINPUT_GAMEPAD_LS_X +; horribly broken - goes full left or right... +;JOY_EVENT_DRAG_RACE_CHANGE_LANE_LEFT_ANALOG = XINPUT_GAMEPAD_LS_X +;JOY_EVENT_DRAG_RACE_CHANGE_LANE_RIGHT_ANALOG = XINPUT_GAMEPAD_LS_X JOY_EVENT_DRAG_RACE_CHANGE_LANE_LEFT = XINPUT_GAMEPAD_LS_LEFT JOY_EVENT_DRAG_RACE_CHANGE_LANE_RIGHT = XINPUT_GAMEPAD_LS_RIGHT JOY_EVENT_SHIFTUP = XINPUT_GAMEPAD_RS_UP @@ -72,36 +73,36 @@ JOY_EVENT_CAMERA_LOOKBACK = XINPUT_GAMEPAD_X JOY_EVENT_CAMERA_POV_CHANGE = XINPUT_GAMEPAD_Y JOY_EVENT_PAUSE = XINPUT_GAMEPAD_START JOY_EVENT_RESET_CAR = XINPUT_GAMEPAD_BACK -// HP2 leftovers -- only slomo works properly -//JOY_EVENT_ZONE_PREVIEW = XINPUT_GAMEPAD_RIGHT_SHOULDER -//JOY_EVENT_ZONE_FREEZE = XINPUT_GAMEPAD_LEFT_SHOULDER +; HP2 leftovers -- only slomo works properly +;JOY_EVENT_ZONE_PREVIEW = XINPUT_GAMEPAD_RIGHT_SHOULDER +;JOY_EVENT_ZONE_FREEZE = XINPUT_GAMEPAD_LEFT_SHOULDER JOY_EVENT_HONK_HORN = XINPUT_GAMEPAD_LEFT_THUMB -//JOY_EVENT_CYCLE_HUD = XINPUT_GAMEPAD_DPAD_UP -//JOY_EVENT_ZONE_SLOMO = XINPUT_GAMEPAD_DPAD_DOWN -// UG2 stuff +;JOY_EVENT_CYCLE_HUD = XINPUT_GAMEPAD_DPAD_UP +;JOY_EVENT_ZONE_SLOMO = XINPUT_GAMEPAD_DPAD_DOWN +; UG2 stuff JOY_EVENT_REQUEST_ENGAGE_INFO = XINPUT_GAMEPAD_DPAD_UP JOY_EVENT_REQUEST_WORLD_MAP = XINPUT_GAMEPAD_DPAD_LEFT JOY_EVENT_REQUEST_LEGEND = XINPUT_GAMEPAD_DPAD_DOWN JOY_EVENT_REQUEST_MESSAGE_SYSTEM = XINPUT_GAMEPAD_DPAD_RIGHT -// put on the opposite stick because it's kinda hard to hold the stick pressed and move it at the same time +; put on the opposite stick because it's kinda hard to hold the stick pressed and move it at the same time JOY_EVENT_HYDRAULIC_PRESSURIZE = XINPUT_GAMEPAD_LEFT_THUMB JOY_EVENT_HYDRAULIC_PRESSURIZE_ANALOG_UD = XINPUT_GAMEPAD_RS_Y JOY_EVENT_HYDRAULIC_PRESSURIZE_ANALOG_LR = XINPUT_GAMEPAD_RS_X JOY_EVENT_HYDRAULIC_BOUNCE = XINPUT_GAMEPAD_RIGHT_THUMB JOY_EVENT_HYDRAULIC_BOUNCE_ANALOG_UD = XINPUT_GAMEPAD_LS_Y JOY_EVENT_HYDRAULIC_BOUNCE_ANALOG_LR = XINPUT_GAMEPAD_LS_X -// actually these aren't used... -// FEng is responsible for replay control, but it doesn't respond on PC version -//JOY_EVENT_REPLAY_PREVIOUS_MARKER = XINPUT_GAMEPAD_LEFT_SHOULDER -//JOY_EVENT_REPLAY_NEXT_MARKER = XINPUT_GAMEPAD_RIGHT_SHOULDER -//JOY_EVENT_REPLAY_PAUSE = XINPUT_GAMEPAD_A -//JOY_EVENT_REPLAY_HIDE_TIMELINE = XINPUT_GAMEPAD_BACK -//JOY_EVENT_REPLAY_PLAYBACK_SPEED = XINPUT_GAMEPAD_X -//JOY_EVENT_REPLAY_CAMERA_ANGLE = XINPUT_GAMEPAD_Y -//JOY_EVENT_REPLAY_HELP = XINPUT_GAMEPAD_RIGHT_THUMB -//JOY_EVENT_REPLAY_SKIP = XINPUT_GAMEPAD_START -//JOY_EVENT_REPLAY_CAMERA_TARGET = XINPUT_GAMEPAD_LEFT_THUMB -// debug camera -- only on port 2 +; actually these aren't used... +; FEng is responsible for replay control, but it doesn't respond on PC version +;JOY_EVENT_REPLAY_PREVIOUS_MARKER = XINPUT_GAMEPAD_LEFT_SHOULDER +;JOY_EVENT_REPLAY_NEXT_MARKER = XINPUT_GAMEPAD_RIGHT_SHOULDER +;JOY_EVENT_REPLAY_PAUSE = XINPUT_GAMEPAD_A +;JOY_EVENT_REPLAY_HIDE_TIMELINE = XINPUT_GAMEPAD_BACK +;JOY_EVENT_REPLAY_PLAYBACK_SPEED = XINPUT_GAMEPAD_X +;JOY_EVENT_REPLAY_CAMERA_ANGLE = XINPUT_GAMEPAD_Y +;JOY_EVENT_REPLAY_HELP = XINPUT_GAMEPAD_RIGHT_THUMB +;JOY_EVENT_REPLAY_SKIP = XINPUT_GAMEPAD_START +;JOY_EVENT_REPLAY_CAMERA_TARGET = XINPUT_GAMEPAD_LEFT_THUMB +; debug camera -- only on port 2 JOY_EVENT_CHANGE_DEBUG_CAMERA = XINPUT_GAMEPAD_BACK JOY_EVENT_DEBUG_CAMERA_DROP_CAR = XINPUT_GAMEPAD_START JOY_EVENT_DEBUG_CAMERA_INOUT = XINPUT_GAMEPAD_LS_Y @@ -133,7 +134,7 @@ JOY_EVENT_DEBUG_CAMERA_SLOW = XINPUT_GAMEPAD_LEFT_THUMB JOY_EVENT_DEBUG_CAMERA_FORWARD_BLINK = XINPUT_GAMEPAD_DPAD_UP JOY_EVENT_DEBUG_CAMERA_BACKWARD_BLINK = XINPUT_GAMEPAD_DPAD_DOWN [EventsKB] -// FE controls +; FE controls JOY_EVENT_FENG_PAD_UP = VK_UP JOY_EVENT_FENG_PAD_DOWN = VK_DOWN JOY_EVENT_FENG_PAD_LEFT = VK_LEFT @@ -144,7 +145,7 @@ JOY_EVENT_FENG_BUTTON0 = G JOY_EVENT_FENG_BUTTON1 = F JOY_EVENT_FENG_BUTTON2 = 9 JOY_EVENT_FENG_BUTTON3 = 0 -//JOY_EVENT_FENG_START = VK_ESCAPE +;JOY_EVENT_FENG_START = VK_ESCAPE JOY_EVENT_FENG_HELP = H JOY_EVENT_FENG_LTRIGGER = 9 JOY_EVENT_FENG_RTRIGGER = 0 @@ -157,14 +158,14 @@ JOY_EVENT_MENU_R1 = 0 JOY_EVENT_MENU_R2 = P JOY_EVENT_MENU_SQUARE = Z JOY_EVENT_CARSEL_UNLOCK = U -//JOY_EVENT_START = VK_ESCAPE +;JOY_EVENT_START = VK_ESCAPE JOY_EVENT_SELECT = VK_RETURN JOY_EVENT_CARSEL_ORBIT_UP = W JOY_EVENT_CARSEL_ORBIT_DOWN = S JOY_EVENT_CARSEL_ORBIT_RIGHT = A JOY_EVENT_CARSEL_ORBIT_LEFT = D JOY_EVENT_SKIP = VK_RETURN -// In-Game controls +; In-Game controls KeyboardSteerLeft = VK_LEFT KeyboardSteerRight = VK_RIGHT JOY_EVENT_THROTTLE = VK_UP @@ -180,13 +181,13 @@ JOY_EVENT_CAMERA_POV_CHANGE = C JOY_EVENT_RESET_CAR = R JOY_EVENT_DRAG_RACE_CHANGE_LANE_LEFT = VK_LEFT JOY_EVENT_DRAG_RACE_CHANGE_LANE_RIGHT = VK_RIGHT -// HP2 leftovers -- these all work -//JOY_EVENT_ZONE_PREVIEW = VK_DELETE -//JOY_EVENT_ZONE_FREEZE = VK_NEXT +; HP2 leftovers -- these all work +;JOY_EVENT_ZONE_PREVIEW = VK_DELETE +;JOY_EVENT_ZONE_FREEZE = VK_NEXT JOY_EVENT_HONK_HORN = H -//JOY_EVENT_CYCLE_HUD = XINPUT_GAMEPAD_DPAD_UP -//JOY_EVENT_ZONE_SLOMO = XINPUT_GAMEPAD_DPAD_DOWN -// debug camera +;JOY_EVENT_CYCLE_HUD = XINPUT_GAMEPAD_DPAD_UP +;JOY_EVENT_ZONE_SLOMO = XINPUT_GAMEPAD_DPAD_DOWN +; debug camera JOY_EVENT_CHANGE_DEBUG_CAMERA = M JOY_EVENT_DEBUG_CAMERA_DROP_CAR = 5 JOY_EVENT_DEBUG_CAMERA_MOVE_FWD = W @@ -211,218 +212,8 @@ JOY_EVENT_DEBUG_CAMERA_FOLLOW_CHOPPER = F JOY_EVENT_DEBUG_CAMERA_TURBO = VK_LSHIFT JOY_EVENT_DEBUG_CAMERA_SUPER_TURBO = F JOY_EVENT_DEBUG_CAMERA_SLOW = VK_CAPITAL -// UG2 stuff +; UG2 stuff JOY_EVENT_REQUEST_ENGAGE_INFO = VK_RETURN JOY_EVENT_REQUEST_WORLD_MAP = M JOY_EVENT_REQUEST_LEGEND = L JOY_EVENT_REQUEST_MESSAGE_SYSTEM = VK_TAB -======= -[Input] -KeyboardReadingMode = 0 // 0 = async unbuffered, 1 = buffered, 2 = raw unbuffered -AllowTwoPlayerKB = 0 // allow for the second player to be assigned to the second detected keyboard (RAW ONLY) -ConfineMouse = 0 // confine mouse within the game window - -[Events] -// FE controls -JOY_EVENT_FENG_PAD_UP = XINPUT_GAMEPAD_DPAD_UP -JOY_EVENT_FENG_PAD_DOWN = XINPUT_GAMEPAD_DPAD_DOWN -JOY_EVENT_FENG_PAD_LEFT = XINPUT_GAMEPAD_DPAD_LEFT -JOY_EVENT_FENG_PAD_RIGHT = XINPUT_GAMEPAD_DPAD_RIGHT -JOY_EVENT_FENG_SELECT = XINPUT_GAMEPAD_A -JOY_EVENT_FENG_CANCEL = XINPUT_GAMEPAD_B -JOY_EVENT_FENG_BUTTON0 = XINPUT_GAMEPAD_Y -JOY_EVENT_FENG_BUTTON1 = XINPUT_GAMEPAD_X -JOY_EVENT_FENG_BUTTON2 = XINPUT_GAMEPAD_LT -JOY_EVENT_FENG_BUTTON3 = XINPUT_GAMEPAD_RT -JOY_EVENT_FENG_START = XINPUT_GAMEPAD_START -JOY_EVENT_FENG_HELP = XINPUT_GAMEPAD_RIGHT_THUMB -JOY_EVENT_FENG_LTRIGGER = XINPUT_GAMEPAD_LEFT_SHOULDER -JOY_EVENT_FENG_RTRIGGER = XINPUT_GAMEPAD_RIGHT_SHOULDER -JOY_EVENT_FENG_PAD_UP_ALTERNATE = XINPUT_GAMEPAD_LS_UP -JOY_EVENT_FENG_PAD_DOWN_ALTERNATE = XINPUT_GAMEPAD_LS_DOWN -JOY_EVENT_FENG_PAD_LEFT_ALTERNATE = XINPUT_GAMEPAD_LS_LEFT -JOY_EVENT_FENG_PAD_RIGHT_ALTERNATE = XINPUT_GAMEPAD_LS_RIGHT -JOY_EVENT_FENG_QUIT = XINPUT_GAMEPAD_BACK -JOY_EVENT_MENU_SELECT = XINPUT_GAMEPAD_A -JOY_EVENT_MENU_CANCEL = XINPUT_GAMEPAD_B -JOY_EVENT_MENU_L1 = XINPUT_GAMEPAD_LEFT_SHOULDER -JOY_EVENT_MENU_L2 = XINPUT_GAMEPAD_LT -JOY_EVENT_MENU_R1 = XINPUT_GAMEPAD_RIGHT_SHOULDER -JOY_EVENT_MENU_R2 = XINPUT_GAMEPAD_RT -JOY_EVENT_MENU_SQUARE = XINPUT_GAMEPAD_X -JOY_EVENT_MENU_ANALOG_UP = XINPUT_GAMEPAD_LS_UP -JOY_EVENT_MENU_ANALOG_DOWN = XINPUT_GAMEPAD_LS_DOWN -JOY_EVENT_MENU_ANALOG_LEFT = XINPUT_GAMEPAD_LS_LEFT -JOY_EVENT_MENU_ANALOG_RIGHT = XINPUT_GAMEPAD_LS_RIGHT -JOY_EVENT_CARSEL_ORBIT_LEFTRIGHT = XINPUT_GAMEPAD_RS_X -JOY_EVENT_CARSEL_ORBIT_UPDOWN = XINPUT_GAMEPAD_RS_Y -JOY_EVENT_CARSEL_ORBIT_INOUT = XINPUT_GAMEPAD_LS_Y -JOY_EVENT_CARSEL_UNLOCK = XINPUT_GAMEPAD_LT -JOY_EVENT_CARSEL_CHANGE_MODE = XINPUT_GAMEPAD_RT -JOY_EVENT_START = XINPUT_GAMEPAD_START -JOY_EVENT_SELECT = XINPUT_GAMEPAD_A -JOY_EVENT_SKIP = XINPUT_GAMEPAD_A -// In-Game controls -JOY_EVENT_THROTTLE_ANALOG = XINPUT_GAMEPAD_RT -JOY_EVENT_BRAKE_ANALOG = XINPUT_GAMEPAD_LT -JOY_EVENT_STEER = XINPUT_GAMEPAD_LS_X -// commented out analog because it causes issues, when regular steer is activated, analog steering dies -//JOY_EVENT_STEER_ANALOG = XINPUT_GAMEPAD_LS_X -// horribly broken - goes full left or right... -//JOY_EVENT_DRAG_RACE_CHANGE_LANE_LEFT_ANALOG = XINPUT_GAMEPAD_LS_X -//JOY_EVENT_DRAG_RACE_CHANGE_LANE_RIGHT_ANALOG = XINPUT_GAMEPAD_LS_X -JOY_EVENT_DRAG_RACE_CHANGE_LANE_LEFT = XINPUT_GAMEPAD_LS_LEFT -JOY_EVENT_DRAG_RACE_CHANGE_LANE_RIGHT = XINPUT_GAMEPAD_LS_RIGHT -JOY_EVENT_SHIFTUP = XINPUT_GAMEPAD_RS_UP -JOY_EVENT_SHIFTDOWN = XINPUT_GAMEPAD_RS_DOWN -JOY_EVENT_NITRO_BOOST = XINPUT_GAMEPAD_B -JOY_EVENT_EBRAKE = XINPUT_GAMEPAD_A -JOY_EVENT_CAMERA_LOOKBACK = XINPUT_GAMEPAD_X -JOY_EVENT_CAMERA_POV_CHANGE = XINPUT_GAMEPAD_Y -JOY_EVENT_PAUSE = XINPUT_GAMEPAD_START -JOY_EVENT_RESET_CAR = XINPUT_GAMEPAD_BACK -// HP2 leftovers -- only slomo works properly -//JOY_EVENT_ZONE_PREVIEW = XINPUT_GAMEPAD_RIGHT_SHOULDER -//JOY_EVENT_ZONE_FREEZE = XINPUT_GAMEPAD_LEFT_SHOULDER -JOY_EVENT_HONK_HORN = XINPUT_GAMEPAD_LEFT_THUMB -//JOY_EVENT_CYCLE_HUD = XINPUT_GAMEPAD_DPAD_UP -//JOY_EVENT_ZONE_SLOMO = XINPUT_GAMEPAD_DPAD_DOWN -// UG2 stuff -JOY_EVENT_REQUEST_ENGAGE_INFO = XINPUT_GAMEPAD_DPAD_UP -JOY_EVENT_REQUEST_WORLD_MAP = XINPUT_GAMEPAD_DPAD_LEFT -JOY_EVENT_REQUEST_LEGEND = XINPUT_GAMEPAD_DPAD_DOWN -JOY_EVENT_REQUEST_MESSAGE_SYSTEM = XINPUT_GAMEPAD_DPAD_RIGHT -// put on the opposite stick because it's kinda hard to hold the stick pressed and move it at the same time -JOY_EVENT_HYDRAULIC_PRESSURIZE = XINPUT_GAMEPAD_LEFT_THUMB -JOY_EVENT_HYDRAULIC_PRESSURIZE_ANALOG_UD = XINPUT_GAMEPAD_RS_Y -JOY_EVENT_HYDRAULIC_PRESSURIZE_ANALOG_LR = XINPUT_GAMEPAD_RS_X -JOY_EVENT_HYDRAULIC_BOUNCE = XINPUT_GAMEPAD_RIGHT_THUMB -JOY_EVENT_HYDRAULIC_BOUNCE_ANALOG_UD = XINPUT_GAMEPAD_LS_Y -JOY_EVENT_HYDRAULIC_BOUNCE_ANALOG_LR = XINPUT_GAMEPAD_LS_X -// actually these aren't used... -// FEng is responsible for replay control, but it doesn't respond on PC version -//JOY_EVENT_REPLAY_PREVIOUS_MARKER = XINPUT_GAMEPAD_LEFT_SHOULDER -//JOY_EVENT_REPLAY_NEXT_MARKER = XINPUT_GAMEPAD_RIGHT_SHOULDER -//JOY_EVENT_REPLAY_PAUSE = XINPUT_GAMEPAD_A -//JOY_EVENT_REPLAY_HIDE_TIMELINE = XINPUT_GAMEPAD_BACK -//JOY_EVENT_REPLAY_PLAYBACK_SPEED = XINPUT_GAMEPAD_X -//JOY_EVENT_REPLAY_CAMERA_ANGLE = XINPUT_GAMEPAD_Y -//JOY_EVENT_REPLAY_HELP = XINPUT_GAMEPAD_RIGHT_THUMB -//JOY_EVENT_REPLAY_SKIP = XINPUT_GAMEPAD_START -//JOY_EVENT_REPLAY_CAMERA_TARGET = XINPUT_GAMEPAD_LEFT_THUMB -// debug camera -- only on port 2 -JOY_EVENT_CHANGE_DEBUG_CAMERA = XINPUT_GAMEPAD_BACK -JOY_EVENT_DEBUG_CAMERA_DROP_CAR = XINPUT_GAMEPAD_START -JOY_EVENT_DEBUG_CAMERA_INOUT = XINPUT_GAMEPAD_LS_Y -JOY_EVENT_DEBUG_CAMERA_STRAFE_LEFTRIGHT = XINPUT_GAMEPAD_LS_X -JOY_EVENT_DEBUG_CAMERA_ROTATE_UPDOWN = XINPUT_GAMEPAD_RS_Y -JOY_EVENT_DEBUG_CAMERA_ROTATE_LEFTRIGHT = XINPUT_GAMEPAD_RS_X -JOY_EVENT_DEBUG_CAMERA_MOVE_FWD = XINPUT_GAMEPAD_A -JOY_EVENT_DEBUG_CAMERA_MOVE_BACK = XINPUT_GAMEPAD_Y -JOY_EVENT_DEBUG_CAMERA_MOVE_LEFT = XINPUT_GAMEPAD_X -JOY_EVENT_DEBUG_CAMERA_MOVE_RIGHT = XINPUT_GAMEPAD_B -JOY_EVENT_DEBUG_CAMERA_MOVE_UP = XINPUT_GAMEPAD_LEFT_SHOULDER -JOY_EVENT_DEBUG_CAMERA_MOVE_DOWN = XINPUT_GAMEPAD_LT -JOY_EVENT_DEBUG_CAMERA_TURN_UP = XINPUT_GAMEPAD_DPAD_UP -JOY_EVENT_DEBUG_CAMERA_TURN_DOWN = XINPUT_GAMEPAD_DPAD_DOWN -JOY_EVENT_DEBUG_CAMERA_TURN_LEFT = XINPUT_GAMEPAD_DPAD_LEFT -JOY_EVENT_DEBUG_CAMERA_TURN_RIGHT = XINPUT_GAMEPAD_DPAD_RIGHT -JOY_EVENT_DEBUG_CAMERA_ROTATE_UP = XINPUT_GAMEPAD_DPAD_UP -JOY_EVENT_DEBUG_CAMERA_ROTATE_DOWN = XINPUT_GAMEPAD_DPAD_DOWN -JOY_EVENT_DEBUG_CAMERA_ROTATE_LEFT = XINPUT_GAMEPAD_DPAD_LEFT -JOY_EVENT_DEBUG_CAMERA_ROTATE_RIGHT = XINPUT_GAMEPAD_DPAD_RIGHT -JOY_EVENT_DEBUG_CAMERA_MOVE_CLOSER = XINPUT_GAMEPAD_RIGHT_SHOULDER -JOY_EVENT_DEBUG_CAMERA_MOVE_FARTHER = XINPUT_GAMEPAD_LEFT_SHOULDER -JOY_EVENT_DEBUG_CAMERA_NEXT_CAR = XINPUT_GAMEPAD_RT -JOY_EVENT_DEBUG_CAMERA_PREV_CAR = XINPUT_GAMEPAD_LT -JOY_EVENT_DEBUG_CAMERA_FOLLOW_CHOPPER = XINPUT_GAMEPAD_X -JOY_EVENT_DEBUG_CAMERA_TURBO = XINPUT_GAMEPAD_RIGHT_SHOULDER -JOY_EVENT_DEBUG_CAMERA_SUPER_TURBO = XINPUT_GAMEPAD_RT -JOY_EVENT_DEBUG_CAMERA_SLOW = XINPUT_GAMEPAD_LEFT_THUMB -JOY_EVENT_DEBUG_CAMERA_FORWARD_BLINK = XINPUT_GAMEPAD_DPAD_UP -JOY_EVENT_DEBUG_CAMERA_BACKWARD_BLINK = XINPUT_GAMEPAD_DPAD_DOWN -[EventsKB] -// FE controls -JOY_EVENT_FENG_PAD_UP = VK_UP -JOY_EVENT_FENG_PAD_DOWN = VK_DOWN -JOY_EVENT_FENG_PAD_LEFT = VK_LEFT -JOY_EVENT_FENG_PAD_RIGHT = VK_RIGHT -JOY_EVENT_FENG_SELECT = VK_RETURN -JOY_EVENT_FENG_CANCEL = VK_ESCAPE -JOY_EVENT_FENG_BUTTON0 = G -JOY_EVENT_FENG_BUTTON1 = F -JOY_EVENT_FENG_BUTTON2 = 9 -JOY_EVENT_FENG_BUTTON3 = 0 -//JOY_EVENT_FENG_START = VK_ESCAPE -JOY_EVENT_FENG_HELP = H -JOY_EVENT_FENG_LTRIGGER = 9 -JOY_EVENT_FENG_RTRIGGER = 0 -JOY_EVENT_FENG_QUIT = Q -JOY_EVENT_MENU_SELECT = VK_RETURN -JOY_EVENT_MENU_CANCEL = VK_ESCAPE -JOY_EVENT_MENU_L1 = 9 -JOY_EVENT_MENU_L2 = O -JOY_EVENT_MENU_R1 = 0 -JOY_EVENT_MENU_R2 = P -JOY_EVENT_MENU_SQUARE = Z -JOY_EVENT_CARSEL_UNLOCK = U -//JOY_EVENT_START = VK_ESCAPE -JOY_EVENT_SELECT = VK_RETURN -JOY_EVENT_CARSEL_ORBIT_UP = W -JOY_EVENT_CARSEL_ORBIT_DOWN = S -JOY_EVENT_CARSEL_ORBIT_RIGHT = A -JOY_EVENT_CARSEL_ORBIT_LEFT = D -JOY_EVENT_SKIP = VK_RETURN -// In-Game controls -KeyboardSteerLeft = VK_LEFT -KeyboardSteerRight = VK_RIGHT -JOY_EVENT_THROTTLE = VK_UP -JOY_EVENT_BRAKE = VK_DOWN -JOY_EVENT_PAUSE = VK_ESCAPE -JOY_EVENT_MENU_SELECT = VK_RETURN -JOY_EVENT_SHIFTUP = VK_LSHIFT -JOY_EVENT_SHIFTDOWN = VK_LCONTROL -JOY_EVENT_NITRO_BOOST = VK_LMENU -JOY_EVENT_EBRAKE = VK_SPACE -JOY_EVENT_CAMERA_LOOKBACK = X -JOY_EVENT_CAMERA_POV_CHANGE = C -JOY_EVENT_RESET_CAR = R -JOY_EVENT_DRAG_RACE_CHANGE_LANE_LEFT = VK_LEFT -JOY_EVENT_DRAG_RACE_CHANGE_LANE_RIGHT = VK_RIGHT -// HP2 leftovers -- these all work -//JOY_EVENT_ZONE_PREVIEW = VK_DELETE -//JOY_EVENT_ZONE_FREEZE = VK_NEXT -JOY_EVENT_HONK_HORN = H -//JOY_EVENT_CYCLE_HUD = XINPUT_GAMEPAD_DPAD_UP -//JOY_EVENT_ZONE_SLOMO = XINPUT_GAMEPAD_DPAD_DOWN -// debug camera -JOY_EVENT_CHANGE_DEBUG_CAMERA = VK_BACK -JOY_EVENT_DEBUG_CAMERA_DROP_CAR = 5 -JOY_EVENT_DEBUG_CAMERA_MOVE_FWD = W -JOY_EVENT_DEBUG_CAMERA_MOVE_BACK = S -JOY_EVENT_DEBUG_CAMERA_MOVE_LEFT = A -JOY_EVENT_DEBUG_CAMERA_MOVE_RIGHT = D -JOY_EVENT_DEBUG_CAMERA_MOVE_UP = VK_SPACE -JOY_EVENT_DEBUG_CAMERA_MOVE_DOWN = VK_LCONTROL -JOY_EVENT_DEBUG_CAMERA_TURN_UP = I -JOY_EVENT_DEBUG_CAMERA_TURN_DOWN = K -JOY_EVENT_DEBUG_CAMERA_TURN_LEFT = J -JOY_EVENT_DEBUG_CAMERA_TURN_RIGHT = L -JOY_EVENT_DEBUG_CAMERA_ROTATE_UP = W -JOY_EVENT_DEBUG_CAMERA_ROTATE_DOWN = S -JOY_EVENT_DEBUG_CAMERA_ROTATE_LEFT = A -JOY_EVENT_DEBUG_CAMERA_ROTATE_RIGHT = D -JOY_EVENT_DEBUG_CAMERA_MOVE_CLOSER = VK_LSHIFT -JOY_EVENT_DEBUG_CAMERA_MOVE_FARTHER = VK_LCONTROL -JOY_EVENT_DEBUG_CAMERA_NEXT_CAR = E -JOY_EVENT_DEBUG_CAMERA_PREV_CAR = Q -JOY_EVENT_DEBUG_CAMERA_FOLLOW_CHOPPER = F -JOY_EVENT_DEBUG_CAMERA_TURBO = VK_LSHIFT -JOY_EVENT_DEBUG_CAMERA_SUPER_TURBO = F -JOY_EVENT_DEBUG_CAMERA_SLOW = VK_CAPITAL -// UG2 stuff -JOY_EVENT_REQUEST_ENGAGE_INFO = VK_RETURN -JOY_EVENT_REQUEST_WORLD_MAP = M -JOY_EVENT_REQUEST_LEGEND = 1 -JOY_EVENT_REQUEST_MESSAGE_SYSTEM = VK_TAB ->>>>>>> 7823b234e6ea6efea6d84cfe1e716490a22e41ac diff --git a/NFSU2_Addresses.h b/NFSU2_Addresses.h index e9f05b9..aff6d83 100644 --- a/NFSU2_Addresses.h +++ b/NFSU2_Addresses.h @@ -39,3 +39,7 @@ void(*FESendKeystroke)(unsigned int key) = (void(*)(unsigned int))0x0055DBD0; #define LASTCONTROLLED_CONTROLLER 1 unsigned int LastControlledDevice = 0; // 0 = keyboard, 1 = controller unsigned int LastControlledDeviceOldState = 0; + +#define STEER_HANDLER_ADDR1 0x0041E083 +#define STEER_HANDLER_ADDR2 0x0041E09A +#define REALDRIVER_STEER_OFFSET 0x2C8 diff --git a/NFSU_Addresses.h b/NFSU_Addresses.h index 6d3c1de..975f1f8 100644 --- a/NFSU_Addresses.h +++ b/NFSU_Addresses.h @@ -50,3 +50,7 @@ #define OPTIONSSELECTOR_VTABLE_FUNC_ADDR 0x006C3E54 #define WNDPROC_POINTER_ADDR 0x4088FC + +#define STEER_HANDLER_ADDR1 0x00461213 +#define STEER_HANDLER_ADDR2 0x00461229 +#define REALDRIVER_STEER_OFFSET 0x28C diff --git a/dllmain.cpp b/dllmain.cpp index d8df2d2..1d98aa6 100644 --- a/dllmain.cpp +++ b/dllmain.cpp @@ -56,6 +56,12 @@ WORD bQuitButtonOldState = 0; WORD bYButtonOldState = 0; WORD bXButtonOldState = 0; +// steering axis & buttons +WORD SteerLeftButton = 0; // defaulting digital steer to 0 because of predefined functions +WORD SteerRightButton = 0; +WORD SteerLeftAxis = XINPUT_GAMEPAD_LS_LEFT_CONFIGDEF; +WORD SteerRightAxis = XINPUT_GAMEPAD_LS_RIGHT_CONFIGDEF; + struct CONTROLLER_STATE { XINPUT_STATE state; @@ -349,7 +355,7 @@ int Scanner_DigitalUpOrDown_RawKB(void* EventNode, unsigned int* unk1, unsigned ci = 1; // throttle is very time sensitive, so we return all the time - if ((inScannerConfig->JoyEvent == JOY_EVENT_THROTTLE) || (inScannerConfig->JoyEvent == JOY_EVENT_BRAKE) || (inScannerConfig->JoyEvent == JOY_EVENT_THROTTLE_ANALOG) || (inScannerConfig->JoyEvent == JOY_EVENT_THROTTLE_ANALOG_ALTERNATE) || (inScannerConfig->JoyEvent == JOY_EVENT_BRAKE_ANALOG) || (inScannerConfig->JoyEvent == JOY_EVENT_BRAKE_ANALOG_ALTERNATE) || (inScannerConfig->JoyEvent == JOY_EVENT_STEER_ANALOG) || (inScannerConfig->JoyEvent == JOY_EVENT_STEER)) + if ((inScannerConfig->JoyEvent == JOY_EVENT_THROTTLE) || (inScannerConfig->JoyEvent == JOY_EVENT_BRAKE) || (inScannerConfig->JoyEvent == JOY_EVENT_THROTTLE_ANALOG) || (inScannerConfig->JoyEvent == JOY_EVENT_THROTTLE_ANALOG_ALTERNATE) || (inScannerConfig->JoyEvent == JOY_EVENT_BRAKE_ANALOG) || (inScannerConfig->JoyEvent == JOY_EVENT_BRAKE_ANALOG_ALTERNATE)) { if (VKeyStates[ci][inScannerConfig->keycode]) @@ -391,7 +397,7 @@ int Scanner_DigitalUpOrDown_SyncKB(void* EventNode, unsigned int* unk1, unsigned bool bKeyState = VKeyStates[0][inScannerConfig->keycode] >> 7; // throttle is very time sensitive, so we return all the time - if ((inScannerConfig->JoyEvent == JOY_EVENT_THROTTLE) || (inScannerConfig->JoyEvent == JOY_EVENT_BRAKE) || (inScannerConfig->JoyEvent == JOY_EVENT_THROTTLE_ANALOG) || (inScannerConfig->JoyEvent == JOY_EVENT_THROTTLE_ANALOG_ALTERNATE) || (inScannerConfig->JoyEvent == JOY_EVENT_BRAKE_ANALOG) || (inScannerConfig->JoyEvent == JOY_EVENT_BRAKE_ANALOG_ALTERNATE) || (inScannerConfig->JoyEvent == JOY_EVENT_STEER_ANALOG) || (inScannerConfig->JoyEvent == JOY_EVENT_STEER)) + if ((inScannerConfig->JoyEvent == JOY_EVENT_THROTTLE) || (inScannerConfig->JoyEvent == JOY_EVENT_BRAKE) || (inScannerConfig->JoyEvent == JOY_EVENT_THROTTLE_ANALOG) || (inScannerConfig->JoyEvent == JOY_EVENT_THROTTLE_ANALOG_ALTERNATE) || (inScannerConfig->JoyEvent == JOY_EVENT_BRAKE_ANALOG) || (inScannerConfig->JoyEvent == JOY_EVENT_BRAKE_ANALOG_ALTERNATE)) { if (bKeyState) { @@ -487,116 +493,6 @@ int Scanner_DigitalUpOrDown(void* EventNode, unsigned int* unk1, unsigned int un return Scanner_DigitalUpOrDown_XInput(EventNode, unk1, unk2, inScannerConfig, Joystick) | Scanner_DigitalUpOrDown_KB(EventNode, unk1, unk2, inScannerConfig, Joystick); } -int Scanner_DigitalSteer(void* EventNode, unsigned int* unk1, unsigned int unk2, ScannerConfig* inScannerConfig, void* Joystick) -{ - int ci = 0; - if ((int)Joystick == JOY2_ADDR) - ci = 1; - - WORD wButtons = g_Controllers[ci].state.Gamepad.wButtons; - - // D-Pad steering - // we only accept dpad in this case (and read left/right), if it's any other button, ignore - if (inScannerConfig->BitmaskStuff2 != XINPUT_GAMEPAD_DPAD_CONFIGDEF) - return inScannerConfig->JoyEvent + ((inScannerConfig->param / 2) << 8); - // if a direction is pressed - if (((wButtons & XINPUT_GAMEPAD_DPAD_LEFT) || (wButtons & XINPUT_GAMEPAD_DPAD_RIGHT)) != EventStates[ci][inScannerConfig->JoyEvent]) - { - // on change to TRUE - if ((wButtons & XINPUT_GAMEPAD_DPAD_LEFT) || (wButtons & XINPUT_GAMEPAD_DPAD_RIGHT)) - { - if ((wButtons & XINPUT_GAMEPAD_DPAD_LEFT)) - { - EventStates[ci][inScannerConfig->JoyEvent] = (wButtons & XINPUT_GAMEPAD_DPAD_LEFT) || (wButtons & XINPUT_GAMEPAD_DPAD_RIGHT); - return inScannerConfig->JoyEvent; // steer left = 0 - } - if ((wButtons & XINPUT_GAMEPAD_DPAD_RIGHT)) - { - EventStates[ci][inScannerConfig->JoyEvent] = (wButtons & XINPUT_GAMEPAD_DPAD_LEFT) || (wButtons & XINPUT_GAMEPAD_DPAD_RIGHT); - return inScannerConfig->JoyEvent + (inScannerConfig->param << 8); // steer right = max param = 0xFF - } - } - // on change to FALSE -- return JoyEvent number + parameter / 2 = center - if (!((wButtons & XINPUT_GAMEPAD_DPAD_LEFT) || (wButtons & XINPUT_GAMEPAD_DPAD_RIGHT))) - { - EventStates[ci][inScannerConfig->JoyEvent] = ((wButtons & XINPUT_GAMEPAD_DPAD_LEFT) || (wButtons & XINPUT_GAMEPAD_DPAD_RIGHT)); - return inScannerConfig->JoyEvent + ((inScannerConfig->param / 2) << 8); // center steer = param / 2 = 0x7F - } - } - - return 0; -} - -int Scanner_DigitalSteer_RawKB(void* EventNode, unsigned int* unk1, unsigned int unk2, ScannerConfig* inScannerConfig, void* Joystick) -{ - int ci = 0; - if ((int)Joystick == 0x73B3EC) - ci = 1; - - unsigned int outparam = inScannerConfig->param / 2; - - // if a direction is pressed - if ((VKeyStates[ci][SteerLeftVKey] || VKeyStates[ci][SteerRightVKey])) - { - if (VKeyStates[ci][SteerLeftVKey]) - outparam = outparam - inScannerConfig->param / 2; - if (VKeyStates[ci][SteerRightVKey]) - outparam = outparam + inScannerConfig->param / 2; - } - - return inScannerConfig->JoyEvent + (outparam << 8); -} - -int Scanner_DigitalSteer_SyncKB(void* EventNode, unsigned int* unk1, unsigned int unk2, ScannerConfig* inScannerConfig, void* Joystick) -{ - bool bKeyStateLeft = VKeyStates[0][SteerLeftVKey] >> 7; - bool bKeyStateRight = VKeyStates[0][SteerRightVKey] >> 7; - unsigned int outparam = inScannerConfig->param / 2; - - // if a direction is pressed - if ((bKeyStateLeft || bKeyStateRight)) - { - if (bKeyStateLeft) - outparam = outparam - inScannerConfig->param / 2; - if (bKeyStateRight) - outparam = outparam + inScannerConfig->param / 2; - } - - return inScannerConfig->JoyEvent + (outparam << 8); -} - -int Scanner_DigitalSteer_AsyncKB(void* EventNode, unsigned int* unk1, unsigned int unk2, ScannerConfig* inScannerConfig, void* Joystick) -{ - bool bKeyStateLeft = GetAsyncKeyState(SteerLeftVKey) >> 15; - bool bKeyStateRight = GetAsyncKeyState(SteerRightVKey) >> 15; - unsigned int outparam = inScannerConfig->param / 2; - - // if a direction is pressed - if ((bKeyStateLeft || bKeyStateRight)) - { - if (bKeyStateLeft) - outparam = outparam - inScannerConfig->param / 2; - if (bKeyStateRight) - outparam = outparam + inScannerConfig->param / 2; - } - - return inScannerConfig->JoyEvent + (outparam << 8); -} - -int Scanner_DigitalSteer_KB(void* EventNode, unsigned int* unk1, unsigned int unk2, ScannerConfig* inScannerConfig, void* Joystick) -{ - switch (KeyboardReadingMode) - { - case KB_READINGMODE_UNBUFFERED_RAW: - return Scanner_DigitalSteer_RawKB(EventNode, unk1, unk2, inScannerConfig, Joystick); - case KB_READINGMODE_BUFFERED: - return Scanner_DigitalSteer_SyncKB(EventNode, unk1, unk2, inScannerConfig, Joystick); - case KB_READINGMODE_UNBUFFERED_ASYNC: - default: - return Scanner_DigitalSteer_AsyncKB(EventNode, unk1, unk2, inScannerConfig, Joystick); - } -} - // same thing as DigitalUpOrDown except no KEY UP detection, only KEY DOWN int Scanner_DigitalDown_XInput(void* EventNode, unsigned int* unk1, unsigned int unk2, ScannerConfig* inScannerConfig, void* Joystick) { @@ -1028,22 +924,127 @@ int Scanner_Analog_DragSteer(void* EventNode, unsigned int* unk1, unsigned int u return 0; } -int Scanner_CombinedSteering(void* EventNode, unsigned int* unk1, unsigned int unk2, ScannerConfig* inScannerConfig, void* Joystick) +// STEERING HANDLER +float GetAnalogStickValue(int index, WORD bind) { - int result = Scanner_Analog(EventNode, unk1, unk2, inScannerConfig, Joystick); - - if (LastControlledDevice == LASTCONTROLLED_KB) - return Scanner_DigitalSteer_KB(EventNode, unk1, unk2, inScannerConfig, Joystick); - + float result = 0.0f; + int rdi = index; + switch (bind) + { + case XINPUT_GAMEPAD_LT_CONFIGDEF: + result = g_Controllers[rdi].state.Gamepad.bLeftTrigger / 255.0f; + break; + case XINPUT_GAMEPAD_RT_CONFIGDEF: + result = g_Controllers[rdi].state.Gamepad.bRightTrigger / 255.0f; + break; + case XINPUT_GAMEPAD_LS_X_CONFIGDEF: + result = g_Controllers[rdi].state.Gamepad.sThumbLX / (float)(0x7FFF); + break; + case XINPUT_GAMEPAD_RS_X_CONFIGDEF: + result = g_Controllers[rdi].state.Gamepad.sThumbRX / (float)(0x7FFF); + break; + case XINPUT_GAMEPAD_LS_Y_CONFIGDEF: + result = g_Controllers[rdi].state.Gamepad.sThumbLY / (float)(0x7FFF); + break; + case XINPUT_GAMEPAD_RS_Y_CONFIGDEF: + result = g_Controllers[rdi].state.Gamepad.sThumbRY / (float)(0x7FFF); + break; + case XINPUT_GAMEPAD_LS_UP_CONFIGDEF: + if (g_Controllers[rdi].state.Gamepad.sThumbLY > 0) + result = g_Controllers[rdi].state.Gamepad.sThumbLY / (float)(0x7FFF); + break; + case XINPUT_GAMEPAD_LS_DOWN_CONFIGDEF: + if (g_Controllers[rdi].state.Gamepad.sThumbLY < 0) + result = -g_Controllers[rdi].state.Gamepad.sThumbLY / (float)(0x7FFF); + break; + case XINPUT_GAMEPAD_LS_LEFT_CONFIGDEF: + if (g_Controllers[rdi].state.Gamepad.sThumbLX < 0) + result = -g_Controllers[rdi].state.Gamepad.sThumbLX / (float)(0x7FFF); + break; + case XINPUT_GAMEPAD_LS_RIGHT_CONFIGDEF: + if (g_Controllers[rdi].state.Gamepad.sThumbLX > 0) + result = g_Controllers[rdi].state.Gamepad.sThumbLX / (float)(0x7FFF); + break; + case XINPUT_GAMEPAD_RS_UP_CONFIGDEF: + if (g_Controllers[rdi].state.Gamepad.sThumbRY > 0) + result = g_Controllers[rdi].state.Gamepad.sThumbRY / (float)(0x7FFF); + break; + case XINPUT_GAMEPAD_RS_DOWN_CONFIGDEF: + if (g_Controllers[rdi].state.Gamepad.sThumbRY < 0) + result = -g_Controllers[rdi].state.Gamepad.sThumbRY / (float)(0x7FFF); + break; + case XINPUT_GAMEPAD_RS_LEFT_CONFIGDEF: + if (g_Controllers[rdi].state.Gamepad.sThumbRX < 0) + result = -g_Controllers[rdi].state.Gamepad.sThumbRX / (float)(0x7FFF); + break; + case XINPUT_GAMEPAD_RS_RIGHT_CONFIGDEF: + if (g_Controllers[rdi].state.Gamepad.sThumbRX > 0) + result = g_Controllers[rdi].state.Gamepad.sThumbRX / (float)(0x7FFF); + break; + default: + break; + } return result; } -int Scanner_CombinedDigitalSteering(void* EventNode, unsigned int* unk1, unsigned int unk2, ScannerConfig* inScannerConfig, void* Joystick) +void RealDriver_JoyHandler_Steer(int JoystickPort, int JoyEvent, char Value, void* RealDriver) { - if (LastControlledDevice == LASTCONTROLLED_KB) - return Scanner_DigitalSteer_KB(EventNode, unk1, unk2, inScannerConfig, Joystick); + float* SteerVal = (float*)((int)RealDriver + REALDRIVER_STEER_OFFSET); + float AnalogSteerValue = GetAnalogStickValue(JoystickPort, SteerLeftAxis) - GetAnalogStickValue(JoystickPort, SteerRightAxis); + float DigitalSteerValue = 0.0f; + float DigitalSteerValueKB = 0.0f; + float FinalSteerValue; + + // get gamepad digital steering + WORD wButtons = g_Controllers[JoystickPort].state.Gamepad.wButtons; + if (wButtons & SteerLeftButton) + { + DigitalSteerValue = DigitalSteerValue + 1.0; + } + if (wButtons & SteerRightButton) + { + DigitalSteerValue = DigitalSteerValue - 1.0; + } - return Scanner_DigitalSteer(EventNode, unk1, unk2, inScannerConfig, Joystick); + // get KB digital steering + switch (KeyboardReadingMode) + { + case KB_READINGMODE_UNBUFFERED_RAW: + if (VKeyStates[JoystickPort][SteerLeftVKey]) + DigitalSteerValueKB = DigitalSteerValueKB + 1.0; + if (VKeyStates[JoystickPort][SteerRightVKey]) + DigitalSteerValueKB = DigitalSteerValueKB - 1.0; + break; + case KB_READINGMODE_BUFFERED: + if (VKeyStates[0][SteerLeftVKey] >> 7) + DigitalSteerValueKB = DigitalSteerValueKB + 1.0; + if (VKeyStates[0][SteerRightVKey] >> 7) + DigitalSteerValueKB = DigitalSteerValueKB - 1.0; + break; + case KB_READINGMODE_UNBUFFERED_ASYNC: + default: + if (GetAsyncKeyState(SteerLeftVKey) >> 15) + DigitalSteerValueKB = DigitalSteerValueKB + 1.0; + if (GetAsyncKeyState(SteerRightVKey) >> 15) + DigitalSteerValueKB = DigitalSteerValueKB - 1.0; + break; + } + + FinalSteerValue = AnalogSteerValue + DigitalSteerValue + DigitalSteerValueKB; + + // cap the min/max + if (FinalSteerValue > 1.0) + FinalSteerValue = 1.0; + if (FinalSteerValue < -1.0) + FinalSteerValue = -1.0; + + *SteerVal = FinalSteerValue; +} + +int Scanner_CombinedSteering(void* EventNode, unsigned int* unk1, unsigned int unk2, ScannerConfig* inScannerConfig, void* Joystick) +{ + // always return a value to trigger polling + return inScannerConfig->JoyEvent + (1 << 8); } int Scanner_TypeChanged(void* EventNode, unsigned int* unk1, unsigned int unk2, ScannerConfig* inScannerConfig, void* Joystick) @@ -1097,20 +1098,24 @@ void SetupScannerConfig() } // JOY_EVENT_STEER - if (i == JOY_EVENT_STEER) + if ((i == JOY_EVENT_STEER) || (i == JOY_EVENT_STEER_ANALOG)) { - if (inXInputConfigDef == XINPUT_GAMEPAD_DPAD_CONFIGDEF) - ScannerConfigs[i].ScannerFunctionPointer = (unsigned int)&Scanner_CombinedDigitalSteering; - else - ScannerConfigs[i].ScannerFunctionPointer = (unsigned int)&Scanner_CombinedSteering; + ScannerConfigs[i].ScannerFunctionPointer = (unsigned int)&Scanner_CombinedSteering; } } + ScannerConfigs[JOY_EVENT_TYPE_CHANGED].ScannerFunctionPointer = (unsigned int)&Scanner_TypeChanged; #ifdef GAME_UG2 ScannerConfigs[JOY_EVENT_LIVE_TYPE_CHANGED].ScannerFunctionPointer = (unsigned int)&Scanner_TypeChanged; #endif //ScannerConfigs[JOY_EVENT_ANY].ScannerFunctionPointer = (unsigned int)&Scanner_DigitalAnyButton; + // read steering axis & buttons + SteerLeftButton = ConvertXInputNameToBitmask(inireader.ReadString("Events", "SteerLeftButton", "")); + SteerRightButton = ConvertXInputNameToBitmask(inireader.ReadString("Events", "SteerRightButton", "")); + SteerLeftAxis = ConvertXInputOtherConfigDef(inireader.ReadString("Events", "SteerLeftAxis", "XINPUT_GAMEPAD_LS_LEFT")); + SteerRightAxis = ConvertXInputOtherConfigDef(inireader.ReadString("Events", "SteerRightAxis", "XINPUT_GAMEPAD_LS_RIGHT")); + // read steering VK codes SteerLeftVKey = ConvertVKNameToValue(inireader.ReadString("EventsKB", "KeyboardSteerLeft", "VK_LEFT")); if (SteerLeftVKey == 0) @@ -1118,7 +1123,7 @@ void SetupScannerConfig() // try checking for single-char char lettercheck[32]; strcpy(lettercheck, inireader.ReadString("EventsKB", "KeyboardSteerLeft", "VK_LEFT")); - if (strlen(lettercheck) == 1) + if (lettercheck[1] == '\0') SteerLeftVKey = toupper(lettercheck[0]); } SteerRightVKey = ConvertVKNameToValue(inireader.ReadString("EventsKB", "KeyboardSteerRight", "VK_RIGHT")); @@ -1127,7 +1132,7 @@ void SetupScannerConfig() // try checking for single-char char lettercheck[32]; strcpy(lettercheck, inireader.ReadString("EventsKB", "KeyboardSteerRight", "VK_RIGHT")); - if (strlen(lettercheck) == 1) + if (lettercheck[1] == '\0') SteerRightVKey = toupper(lettercheck[0]); } } @@ -1333,6 +1338,10 @@ int Init() injector::WriteMemory(0x0050B4EA, 0, true); #endif + // custom steering handler + injector::WriteMemory(STEER_HANDLER_ADDR1, (int)&RealDriver_JoyHandler_Steer, true); + injector::WriteMemory(STEER_HANDLER_ADDR2, (int)&DummyFunc, true); + // kill DInput8 joypad reading & event generation injector::MakeJMP(EVENTGEN_JMP_ADDR_ENTRY, EVENTGEN_JMP_ADDR_EXIT, true); // this kills DInput enumeration COMPLETELY -- even the keyboard