From d5235760d539b0decbbee65355053ef52c5bd20d Mon Sep 17 00:00:00 2001
From: agmas <Maxlion360@gmail.com>
Date: Sun, 5 Jan 2025 16:36:59 +0400
Subject: [PATCH 1/7] start some work

---
 flixel/input/gamepad/FlxGamepad.hx    | 51 +++++++++++++++++++++++++++
 flixel/system/replay/FlxReplay.hx     | 12 +++++++
 flixel/system/replay/FrameRecord.hx   | 37 +++++++++++++++++--
 flixel/system/replay/GamepadRecord.hx | 31 ++++++++++++++++
 4 files changed, 129 insertions(+), 2 deletions(-)
 create mode 100644 flixel/system/replay/GamepadRecord.hx

diff --git a/flixel/input/gamepad/FlxGamepad.hx b/flixel/input/gamepad/FlxGamepad.hx
index a6dfdd2726..239f46f705 100644
--- a/flixel/input/gamepad/FlxGamepad.hx
+++ b/flixel/input/gamepad/FlxGamepad.hx
@@ -1,5 +1,7 @@
 package flixel.input.gamepad;
 
+import flixel.system.replay.GamepadRecord;
+import flixel.system.replay.CodeValuePair;
 import flixel.input.FlxInput.FlxInputState;
 import flixel.input.gamepad.FlxGamepadMappedInput;
 import flixel.input.gamepad.lists.FlxGamepadAnalogList;
@@ -908,6 +910,55 @@ class FlxGamepad implements IFlxDestroyable
 			LabelValuePair.weak("deadZone", deadZone)
 		]);
 	}
+	/**
+	 * If any buttons are not "released",
+	 * this function will return an array indicating
+	 * which buttons are pressed and what state they are in.
+	 *
+	 * @return	An array of button state data. Null if there is no data.
+	 */
+	@:allow(flixel.system.replay.FlxReplay)
+	function record():GamepadRecord
+	{
+		var data:Array<CodeValuePair> = null;
+		
+		for (button in buttons)
+		{
+			if (button == null || button.released)
+			{
+				continue;
+			}
+			
+			if (data == null)
+			{
+				data = new Array<CodeValuePair>();
+			}
+			
+			data.push(new CodeValuePair(button.ID, button.current));
+		}
+		
+		return new GamepadRecord(id, data);
+	}
+	
+	/**
+	 * Part of the keystroke recording system.
+	 * Takes data about key presses and sets it into array.
+	 *
+	 * @param	Record	Array of data about key states.
+	 */
+	@:allow(flixel.system.replay.FlxReplay)
+	function playback(record:Array<CodeValuePair>):Void
+	{
+		var i = 0;
+		final len = record.length;
+		
+		while (i < len)
+		{
+			final keyRecord = record[i++];
+			final id = getButton(keyRecord.code);
+			id.current = keyRecord.value;
+		}
+	}
 }
 
 enum FlxGamepadDeadZoneMode
diff --git a/flixel/system/replay/FlxReplay.hx b/flixel/system/replay/FlxReplay.hx
index 74d0f5ba5d..65e0c57c2f 100644
--- a/flixel/system/replay/FlxReplay.hx
+++ b/flixel/system/replay/FlxReplay.hx
@@ -165,6 +165,18 @@ class FlxReplay
 			continueFrame = false;
 		#end
 
+		#if FLX_GAMEINPUT_API
+		var gamepadRecords:Array<GamepadRecord> = new Array();
+		for (gamepad in FlxG.gamepads.getActiveGamepads())
+		{
+			var gamepadRecord:GamepadRecord = gamepad.record();
+			if (gamepadRecord != null)
+			{
+				continueFrame = false;
+			}
+		}
+		#end
+
 		if (continueFrame)
 		{
 			frame++;
diff --git a/flixel/system/replay/FrameRecord.hx b/flixel/system/replay/FrameRecord.hx
index 438e62ce01..15c5a5ebc1 100644
--- a/flixel/system/replay/FrameRecord.hx
+++ b/flixel/system/replay/FrameRecord.hx
@@ -20,6 +20,11 @@ class FrameRecord
 	 */
 	public var mouse:MouseRecord;
 
+	/**
+	 * An array containing all the gamepad inputs.
+	 */
+	public var gamepad:Array<GamepadRecord>;
+
 	/**
 	 * Instantiate array new frame record.
 	 */
@@ -28,6 +33,7 @@ class FrameRecord
 		frame = 0;
 		keys = null;
 		mouse = null;
+		gamepad = null;
 	}
 
 	/**
@@ -37,11 +43,12 @@ class FrameRecord
 	 * @param Mouse		Mouse data from the mouse manager.
 	 * @return A reference to this FrameRecord object.
 	 */
-	public function create(Frame:Float, ?Keys:Array<CodeValuePair>, ?Mouse:MouseRecord):FrameRecord
+	public function create(Frame:Float, ?Keys:Array<CodeValuePair>, ?Mouse:MouseRecord, ?Gamepad:Array<GamepadRecord>):FrameRecord
 	{
 		frame = Math.floor(Frame);
 		keys = Keys;
 		mouse = Mouse;
+		gamepad = Gamepad;
 
 		return this;
 	}
@@ -53,6 +60,7 @@ class FrameRecord
 	{
 		keys = null;
 		mouse = null;
+		gamepad = null;
 	}
 
 	/**
@@ -85,6 +93,29 @@ class FrameRecord
 			output += mouse.x + "," + mouse.y + "," + mouse.button + "," + mouse.wheel;
 		}
 
+		for (record in gamepad)
+		{
+			output += "g";
+			if (record != null)
+			{
+				output += record.gamepadID + ",";
+				var object:CodeValuePair;
+				var i:Int = 0;
+				var l:Int = keys.length;
+				while (i < l)
+				{
+					if (i > 0)
+					{
+						output += ",";
+					}
+					object = record.buttons[i++];
+					output += object.code + ":" + object.value;
+				}
+			}
+		}
+		
+		trace(output);
+
 		return output;
 	}
 
@@ -103,8 +134,10 @@ class FrameRecord
 
 		// split up keyboard and mouse data
 		array = array[1].split("m");
+		var gamepadArray:Array<String> = array[1].split("g");
+
 		var keyData:String = array[0];
-		var mouseData:String = array[1];
+		var mouseData:String = gamepadArray.splice(0, 1)[0];
 
 		// parse keyboard data
 		if (keyData.length > 0)
diff --git a/flixel/system/replay/GamepadRecord.hx b/flixel/system/replay/GamepadRecord.hx
new file mode 100644
index 0000000000..54703d0457
--- /dev/null
+++ b/flixel/system/replay/GamepadRecord.hx
@@ -0,0 +1,31 @@
+package flixel.system.replay;
+
+import flixel.input.FlxInput.FlxInputState;
+
+/**
+ * A helper class for the frame records, part of the replay/demo/recording system.
+ */
+class GamepadRecord
+{
+	/**
+	 * The ID of the gamepad being recorded.
+	 */
+	public var gamepadID(default, null):Int;
+
+	/**
+	 * An array referring to digital gamepad buttons and it's state.
+	 */
+	public var buttons(default, null):Array<CodeValuePair>;
+
+	/**
+	 * Instantiate a new mouse input record.
+	 *
+	 * @param   GamepadID	The ID of the gamepad being recorded
+	 * @param	Buttons		An array referring to digital gamepad buttons and it's state.
+	 */
+	public function new(gamepadID:Int, buttons:Array<CodeValuePair>)
+	{
+		this.gamepadID =gamepadID;
+		this.buttons = buttons;	
+	}
+}

From 54ed73d17c6975955f4e861aa639ad5f8739156d Mon Sep 17 00:00:00 2001
From: agmas <Maxlion360@gmail.com>
Date: Sun, 5 Jan 2025 16:41:25 +0400
Subject: [PATCH 2/7] will this fix it

---
 flixel/system/replay/FlxReplay.hx | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/flixel/system/replay/FlxReplay.hx b/flixel/system/replay/FlxReplay.hx
index 65e0c57c2f..4cf0aebfea 100644
--- a/flixel/system/replay/FlxReplay.hx
+++ b/flixel/system/replay/FlxReplay.hx
@@ -165,7 +165,6 @@ class FlxReplay
 			continueFrame = false;
 		#end
 
-		#if FLX_GAMEINPUT_API
 		var gamepadRecords:Array<GamepadRecord> = new Array();
 		for (gamepad in FlxG.gamepads.getActiveGamepads())
 		{
@@ -175,7 +174,6 @@ class FlxReplay
 				continueFrame = false;
 			}
 		}
-		#end
 
 		if (continueFrame)
 		{
@@ -190,6 +188,7 @@ class FlxReplay
 		#if FLX_KEYBOARD
 		frameRecorded.keys = keysRecord;
 		#end
+		frameRecorded.gamepad = gamepadRecords;
 
 		_frames[frameCount++] = frameRecorded;
 

From c1871654e1e5876ba79943862ae6bc13a3793af1 Mon Sep 17 00:00:00 2001
From: agmas <Maxlion360@gmail.com>
Date: Sun, 5 Jan 2025 19:16:57 +0400
Subject: [PATCH 3/7] finished?

---
 flixel/input/gamepad/FlxGamepad.hx        |  40 ++++++++-
 flixel/input/gamepad/FlxGamepadManager.hx |   6 ++
 flixel/system/replay/FlxReplay.hx         |  24 +++++
 flixel/system/replay/FrameRecord.hx       | 103 +++++++++++++++++++---
 flixel/system/replay/GamepadRecord.hx     |   9 +-
 flixel/system/replay/IntegerFloatPair.hx  |  13 +++
 6 files changed, 175 insertions(+), 20 deletions(-)
 create mode 100644 flixel/system/replay/IntegerFloatPair.hx

diff --git a/flixel/input/gamepad/FlxGamepad.hx b/flixel/input/gamepad/FlxGamepad.hx
index 239f46f705..b59fdf650f 100644
--- a/flixel/input/gamepad/FlxGamepad.hx
+++ b/flixel/input/gamepad/FlxGamepad.hx
@@ -1,5 +1,6 @@
 package flixel.input.gamepad;
 
+import flixel.system.replay.IntegerFloatPair;
 import flixel.system.replay.GamepadRecord;
 import flixel.system.replay.CodeValuePair;
 import flixel.input.FlxInput.FlxInputState;
@@ -122,6 +123,11 @@ class FlxGamepad implements IFlxDestroyable
 	 */
 	public var pointer(default, null):FlxGamepadPointerValueList;
 
+	/**
+	 * Returns axis values from the `axis` list, as if gamepads were turned off.
+	**/
+	public var recording:Bool = false;
+
 	#if FLX_JOYSTICK_API
 	public var hat(default, null):FlxPoint = FlxPoint.get();
 	public var ball(default, null):FlxPoint = FlxPoint.get();
@@ -704,6 +710,15 @@ class FlxGamepad implements IFlxDestroyable
 
 	function getAxisValue(AxisID:Int):Float
 	{
+		if (recording)
+		{
+			if (AxisID < 0 || AxisID >= axis.length)
+			{
+				return 0;
+			}
+			return axis[AxisID];
+		}
+		
 		var axisValue:Float = 0;
 
 		#if FLX_GAMEINPUT_API
@@ -724,6 +739,7 @@ class FlxGamepad implements IFlxDestroyable
 		axisValue = axis[AxisID];
 		#end
 
+
 		if (isAxisForAnalogStick(AxisID))
 		{
 			axisValue = applyAxisFlip(axisValue, AxisID);
@@ -937,7 +953,15 @@ class FlxGamepad implements IFlxDestroyable
 			data.push(new CodeValuePair(button.ID, button.current));
 		}
 		
-		return new GamepadRecord(id, data);
+		var analogData:Array<IntegerFloatPair> = new Array<IntegerFloatPair>();
+		
+		for (i in 0...axis.length)
+		{
+			var axisValue = getAxisValue(i);
+			analogData.push(new IntegerFloatPair(i, axisValue));
+		}
+		
+		return new GamepadRecord(id, data, analogData);
 	}
 	
 	/**
@@ -947,17 +971,25 @@ class FlxGamepad implements IFlxDestroyable
 	 * @param	Record	Array of data about key states.
 	 */
 	@:allow(flixel.system.replay.FlxReplay)
-	function playback(record:Array<CodeValuePair>):Void
+	function playback(record:GamepadRecord):Void
 	{
 		var i = 0;
-		final len = record.length;
+		final len = record.buttons.length;
 		
 		while (i < len)
 		{
-			final keyRecord = record[i++];
+			final keyRecord = record.buttons[i++];
 			final id = getButton(keyRecord.code);
 			id.current = keyRecord.value;
 		}
+		i = 0;
+		final len = record.analog.length;
+		
+		while (i < len)
+		{
+			final keyRecord = record.analog[i++];
+			axis[keyRecord.code] = keyRecord.value;
+		}
 	}
 }
 
diff --git a/flixel/input/gamepad/FlxGamepadManager.hx b/flixel/input/gamepad/FlxGamepadManager.hx
index 0477304e5c..b73088aa54 100644
--- a/flixel/input/gamepad/FlxGamepadManager.hx
+++ b/flixel/input/gamepad/FlxGamepadManager.hx
@@ -371,6 +371,12 @@ class FlxGamepadManager implements IFlxInputManager
 		return -1;
 	}
 
+	public function addPlaybackGamepad(gamepad:FlxGamepad)
+	{
+		_gamepads[gamepad.id] = gamepad;
+		_activeGamepads.push(gamepad);
+	}
+
 	function addGamepad(Device:GameInputDevice):Void
 	{
 		if (Device == null)
diff --git a/flixel/system/replay/FlxReplay.hx b/flixel/system/replay/FlxReplay.hx
index 4cf0aebfea..8b4fdbbda8 100644
--- a/flixel/system/replay/FlxReplay.hx
+++ b/flixel/system/replay/FlxReplay.hx
@@ -1,5 +1,6 @@
 package flixel.system.replay;
 
+import flixel.input.gamepad.FlxGamepad;
 import flixel.FlxG;
 import flixel.util.FlxArrayUtil;
 
@@ -171,6 +172,7 @@ class FlxReplay
 			var gamepadRecord:GamepadRecord = gamepad.record();
 			if (gamepadRecord != null)
 			{
+				gamepadRecords.push(gamepadRecord);
 				continueFrame = false;
 			}
 		}
@@ -199,6 +201,8 @@ class FlxReplay
 		}
 	}
 
+	var fakeGamepads:Map<Int, FlxGamepad> = [];
+
 	/**
 	 * Get the current frame record data and load it into the input managers.
 	 */
@@ -231,6 +235,26 @@ class FlxReplay
 			FlxG.mouse.playback(fr.mouse);
 		}
 		#end
+		if (fr.gamepad != null)
+		{
+			for (record in fr.gamepad)
+			{
+				var gamepad = null;
+				if (fakeGamepads.exists(record.gamepadID))
+				{
+					gamepad = fakeGamepads.get(record.gamepadID);
+				}
+				else
+				{
+					gamepad = new FlxGamepad(-record.gamepadID, FlxG.gamepads, FlxGamepadModel.UNKNOWN, null);
+					FlxG.gamepads.addPlaybackGamepad(gamepad);
+					gamepad.recording = true;
+					fakeGamepads.set(record.gamepadID, gamepad);
+				}
+				
+				gamepad.playback(record);
+			}
+		}
 	}
 
 	/**
diff --git a/flixel/system/replay/FrameRecord.hx b/flixel/system/replay/FrameRecord.hx
index 15c5a5ebc1..f22d88727b 100644
--- a/flixel/system/replay/FrameRecord.hx
+++ b/flixel/system/replay/FrameRecord.hx
@@ -93,28 +93,43 @@ class FrameRecord
 			output += mouse.x + "," + mouse.y + "," + mouse.button + "," + mouse.wheel;
 		}
 
-		for (record in gamepad)
+		if (gamepad != null)
 		{
-			output += "g";
-			if (record != null)
+			for (record in gamepad)
 			{
-				output += record.gamepadID + ",";
-				var object:CodeValuePair;
-				var i:Int = 0;
-				var l:Int = keys.length;
-				while (i < l)
+				output += "g";
+				if (record != null)
 				{
-					if (i > 0)
+					output += record.gamepadID + ",";
+					var object:CodeValuePair;
+					var i:Int = 0;
+					var l:Int = record.buttons.length;
+					while (i < l)
+					{
+						if (i > 0)
+						{
+							output += ",";
+						}
+						object = record.buttons[i++];
+						output += object.code + ":" + object.value;
+					}
+					output += "/";
+					var object:IntegerFloatPair;
+					var i:Int = 0;
+					var l:Int = record.analog.length;
+					while (i < l)
 					{
-						output += ",";
+						if (i > 0)
+						{
+							output += ",";
+						}
+						object = record.analog[i++];
+						output += object.code + ":" + object.value;
 					}
-					object = record.buttons[i++];
-					output += object.code + ":" + object.value;
 				}
 			}
 		}
-		
-		trace(output);
+
 
 		return output;
 	}
@@ -173,6 +188,66 @@ class FrameRecord
 			}
 		}
 
+		if (gamepadArray.length > 0)
+		{
+			for (gamepadString in gamepadArray)
+			{
+				array = gamepadString.split(",");
+				var currentGamepad:GamepadRecord = new GamepadRecord(Std.parseInt(array[0]), [], []);
+				
+				var inputsArray:Array<String> = gamepadString.substring(array[0].length + 1).split("/");
+				var buttonsArray:Array<String> = inputsArray[0].split(",");
+				var analogArray:Array<String> = inputsArray[1].split(",");
+				
+				// go through each data pair and enter it into this frame's button state
+				var buttonPair:Array<String>;
+				i = 0;
+				l = inputsArray[0].length;
+				while (i < l)
+				{
+					var pairString = buttonsArray[i++];
+					if (pairString != null)
+					{
+						buttonPair = pairString.split(":");
+						if (buttonPair.length == 2)
+						{
+							if (gamepad == null)
+							{
+								gamepad = new Array<GamepadRecord>();
+							}
+							currentGamepad.buttons.push(new CodeValuePair(Std.parseInt(buttonPair[0]), Std.parseInt(buttonPair[1])));
+						}
+					}
+				}
+				
+				// go through each data pair and enter it into this frame's analog state
+				if (analogArray.length > 0)
+				{
+					var analogPair:Array<String>;
+					i = 0;
+					l = inputsArray[0].length;
+					while (i < l)
+					{
+						var pairString = analogArray[i++];
+						if (pairString != null)
+						{
+							analogPair = pairString.split(":");
+							if (analogPair.length == 2)
+							{
+								if (gamepad == null)
+								{
+									gamepad = new Array<GamepadRecord>();
+								}
+								currentGamepad.analog.push(new IntegerFloatPair(Std.parseInt(analogPair[0]), Std.parseFloat(analogPair[1])));
+							}
+						}
+					}
+				}
+				
+				this.gamepad.push(currentGamepad);
+			}
+		}
+
 		return this;
 	}
 }
diff --git a/flixel/system/replay/GamepadRecord.hx b/flixel/system/replay/GamepadRecord.hx
index 54703d0457..bb553d95ff 100644
--- a/flixel/system/replay/GamepadRecord.hx
+++ b/flixel/system/replay/GamepadRecord.hx
@@ -16,6 +16,10 @@ class GamepadRecord
 	 * An array referring to digital gamepad buttons and it's state.
 	 */
 	public var buttons(default, null):Array<CodeValuePair>;
+	/**
+	 * An array referring to analog gamepad inputs and their state.
+	 */
+	public var analog(default, null):Array<IntegerFloatPair>;
 
 	/**
 	 * Instantiate a new mouse input record.
@@ -23,9 +27,10 @@ class GamepadRecord
 	 * @param   GamepadID	The ID of the gamepad being recorded
 	 * @param	Buttons		An array referring to digital gamepad buttons and it's state.
 	 */
-	public function new(gamepadID:Int, buttons:Array<CodeValuePair>)
+	public function new(gamepadID:Int, buttons:Array<CodeValuePair>, analog:Array<IntegerFloatPair>)
 	{
-		this.gamepadID =gamepadID;
+		this.gamepadID = gamepadID;
 		this.buttons = buttons;	
+		this.analog = analog;
 	}
 }
diff --git a/flixel/system/replay/IntegerFloatPair.hx b/flixel/system/replay/IntegerFloatPair.hx
new file mode 100644
index 0000000000..6b35c97c24
--- /dev/null
+++ b/flixel/system/replay/IntegerFloatPair.hx
@@ -0,0 +1,13 @@
+package flixel.system.replay;
+
+class IntegerFloatPair
+{
+	public var code:Int;
+	public var value:Float;
+
+	public function new(code:Int, value:Float)
+	{
+		this.code = code;
+		this.value = value;
+	}
+}

From 0c2d60c985d99c6bb23dd253281e10fa02ee54cd Mon Sep 17 00:00:00 2001
From: agmas <Maxlion360@gmail.com>
Date: Sun, 5 Jan 2025 19:23:11 +0400
Subject: [PATCH 4/7] refactor some comments

---
 flixel/input/gamepad/FlxGamepad.hx    | 4 ++--
 flixel/system/replay/GamepadRecord.hx | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/flixel/input/gamepad/FlxGamepad.hx b/flixel/input/gamepad/FlxGamepad.hx
index b59fdf650f..b9f1d11436 100644
--- a/flixel/input/gamepad/FlxGamepad.hx
+++ b/flixel/input/gamepad/FlxGamepad.hx
@@ -965,8 +965,8 @@ class FlxGamepad implements IFlxDestroyable
 	}
 	
 	/**
-	 * Part of the keystroke recording system.
-	 * Takes data about key presses and sets it into array.
+	 * Part of the gamepad recording system.
+	 * Takes data about analog and buttons and sets it into array.
 	 *
 	 * @param	Record	Array of data about key states.
 	 */
diff --git a/flixel/system/replay/GamepadRecord.hx b/flixel/system/replay/GamepadRecord.hx
index bb553d95ff..18578445da 100644
--- a/flixel/system/replay/GamepadRecord.hx
+++ b/flixel/system/replay/GamepadRecord.hx
@@ -22,7 +22,7 @@ class GamepadRecord
 	public var analog(default, null):Array<IntegerFloatPair>;
 
 	/**
-	 * Instantiate a new mouse input record.
+	 * Instantiate a new gamepad input record.
 	 *
 	 * @param   GamepadID	The ID of the gamepad being recorded
 	 * @param	Buttons		An array referring to digital gamepad buttons and it's state.

From aee4fc982b32fb5bfc7c5d618158ce3f4e5b3aaa Mon Sep 17 00:00:00 2001
From: agmas <Maxlion360@gmail.com>
Date: Sun, 5 Jan 2025 19:31:41 +0400
Subject: [PATCH 5/7] only save inputs when using gameinput_api

---
 flixel/system/replay/FlxReplay.hx | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/flixel/system/replay/FlxReplay.hx b/flixel/system/replay/FlxReplay.hx
index 8b4fdbbda8..c91ba3b351 100644
--- a/flixel/system/replay/FlxReplay.hx
+++ b/flixel/system/replay/FlxReplay.hx
@@ -166,6 +166,7 @@ class FlxReplay
 			continueFrame = false;
 		#end
 
+		#if FLX_GAMEINPUT_API
 		var gamepadRecords:Array<GamepadRecord> = new Array();
 		for (gamepad in FlxG.gamepads.getActiveGamepads())
 		{
@@ -176,6 +177,7 @@ class FlxReplay
 				continueFrame = false;
 			}
 		}
+		#end
 
 		if (continueFrame)
 		{
@@ -190,7 +192,9 @@ class FlxReplay
 		#if FLX_KEYBOARD
 		frameRecorded.keys = keysRecord;
 		#end
+		#if FLX_GAMEINPUT_API
 		frameRecorded.gamepad = gamepadRecords;
+		#end
 
 		_frames[frameCount++] = frameRecorded;
 
@@ -235,6 +239,7 @@ class FlxReplay
 			FlxG.mouse.playback(fr.mouse);
 		}
 		#end
+		#if FLX_GAMEINPUT_API
 		if (fr.gamepad != null)
 		{
 			for (record in fr.gamepad)
@@ -255,6 +260,7 @@ class FlxReplay
 				gamepad.playback(record);
 			}
 		}
+		#end
 	}
 
 	/**

From be04f009bd6e15688f4047b93db0670a58e00074 Mon Sep 17 00:00:00 2001
From: agmas <Maxlion360@gmail.com>
Date: Sun, 5 Jan 2025 20:19:50 +0400
Subject: [PATCH 6/7] don't give 0-axis values

---
 flixel/input/gamepad/FlxGamepad.hx  |  9 +++++++--
 flixel/system/replay/FrameRecord.hx | 25 +++++++++++--------------
 2 files changed, 18 insertions(+), 16 deletions(-)

diff --git a/flixel/input/gamepad/FlxGamepad.hx b/flixel/input/gamepad/FlxGamepad.hx
index b9f1d11436..62c342b732 100644
--- a/flixel/input/gamepad/FlxGamepad.hx
+++ b/flixel/input/gamepad/FlxGamepad.hx
@@ -958,7 +958,9 @@ class FlxGamepad implements IFlxDestroyable
 		for (i in 0...axis.length)
 		{
 			var axisValue = getAxisValue(i);
-			analogData.push(new IntegerFloatPair(i, axisValue));
+			if (axisValue != 0)
+				analogData.push(new IntegerFloatPair(i, axisValue));
+
 		}
 		
 		return new GamepadRecord(id, data, analogData);
@@ -984,7 +986,10 @@ class FlxGamepad implements IFlxDestroyable
 		}
 		i = 0;
 		final len = record.analog.length;
-		
+		for (i in 0...axis.length)
+		{
+			axis[i] = 0;
+		}
 		while (i < len)
 		{
 			final keyRecord = record.analog[i++];
diff --git a/flixel/system/replay/FrameRecord.hx b/flixel/system/replay/FrameRecord.hx
index f22d88727b..5035eeafe5 100644
--- a/flixel/system/replay/FrameRecord.hx
+++ b/flixel/system/replay/FrameRecord.hx
@@ -221,25 +221,22 @@ class FrameRecord
 				}
 				
 				// go through each data pair and enter it into this frame's analog state
-				if (analogArray.length > 0)
+				var analogPair:Array<String>;
+				i = 0;
+				l = inputsArray[0].length;
+				while (i < l)
 				{
-					var analogPair:Array<String>;
-					i = 0;
-					l = inputsArray[0].length;
-					while (i < l)
+					var pairString = analogArray[i++];
+					if (pairString != null)
 					{
-						var pairString = analogArray[i++];
-						if (pairString != null)
+						analogPair = pairString.split(":");
+						if (analogPair.length == 2)
 						{
-							analogPair = pairString.split(":");
-							if (analogPair.length == 2)
+							if (gamepad == null)
 							{
-								if (gamepad == null)
-								{
-									gamepad = new Array<GamepadRecord>();
-								}
-								currentGamepad.analog.push(new IntegerFloatPair(Std.parseInt(analogPair[0]), Std.parseFloat(analogPair[1])));
+								gamepad = new Array<GamepadRecord>();
 							}
+							currentGamepad.analog.push(new IntegerFloatPair(Std.parseInt(analogPair[0]), Std.parseFloat(analogPair[1])));
 						}
 					}
 				}

From 623e68e006d41ba6ef24bf1bebd2ad7fd7c7c357 Mon Sep 17 00:00:00 2001
From: George Kurelic <Gkurelic@gmail.com>
Date: Thu, 23 Jan 2025 13:00:07 -0600
Subject: [PATCH 7/7] change FLX_GAMEINPUT_API to FLX_GAMEPAD

FLX_GAMEPAD is the opposite of FLX_NO_GAMEPAD, where FLX_GAMEINPUT_API is the opposite of  FLX_JOYSTICK_API which, I think, uses a different input system
---
 flixel/system/replay/FlxReplay.hx | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/flixel/system/replay/FlxReplay.hx b/flixel/system/replay/FlxReplay.hx
index c91ba3b351..3ada38f233 100644
--- a/flixel/system/replay/FlxReplay.hx
+++ b/flixel/system/replay/FlxReplay.hx
@@ -166,7 +166,7 @@ class FlxReplay
 			continueFrame = false;
 		#end
 
-		#if FLX_GAMEINPUT_API
+		#if FLX_GAMEPAD
 		var gamepadRecords:Array<GamepadRecord> = new Array();
 		for (gamepad in FlxG.gamepads.getActiveGamepads())
 		{
@@ -192,7 +192,7 @@ class FlxReplay
 		#if FLX_KEYBOARD
 		frameRecorded.keys = keysRecord;
 		#end
-		#if FLX_GAMEINPUT_API
+		#if FLX_GAMEPAD
 		frameRecorded.gamepad = gamepadRecords;
 		#end
 
@@ -239,7 +239,7 @@ class FlxReplay
 			FlxG.mouse.playback(fr.mouse);
 		}
 		#end
-		#if FLX_GAMEINPUT_API
+		#if FLX_GAMEPAD
 		if (fr.gamepad != null)
 		{
 			for (record in fr.gamepad)