about summary refs log tree commit diff
path: root/pkgs/games/gimx
diff options
context:
space:
mode:
authorbb2020 <bb2020@users.noreply.github.com>2021-05-09 14:13:12 +0300
committerbb2020 <bb2020@users.noreply.github.com>2021-11-19 17:46:16 +0300
commit852a72a70b0e0805d5a4a03a412cd1b63393c7e3 (patch)
treeb78848d6d48d4458cecf5739fdfd998e9c9f2d75 /pkgs/games/gimx
parent6c3c8b1f80ce247be615384f38a0b3a138b4bc56 (diff)
gimx: refactor
Diffstat (limited to 'pkgs/games/gimx')
-rw-r--r--pkgs/games/gimx/conf.patch26
-rw-r--r--pkgs/games/gimx/custom/Dualshock4.xml104
-rw-r--r--pkgs/games/gimx/default.nix34
-rw-r--r--pkgs/games/gimx/env.patch30
-rw-r--r--pkgs/games/gimx/variant.nix14
5 files changed, 150 insertions, 58 deletions
diff --git a/pkgs/games/gimx/conf.patch b/pkgs/games/gimx/conf.patch
new file mode 100644
index 0000000000000..875cc68824ac6
--- /dev/null
+++ b/pkgs/games/gimx/conf.patch
@@ -0,0 +1,26 @@
+diff --git a/core/config_reader.c b/core/config_reader.c
+index 451fc48..ed45f4d 100644
+--- a/core/config_reader.c
++++ b/core/config_reader.c
+@@ -1355,7 +1355,7 @@ int read_config_file(const char* file)
+   char file_path[PATH_MAX];
+ 
+   snprintf(file_path, sizeof(file_path), "%s%s%s%s", gimx_params.homedir, GIMX_DIR, CONFIG_DIR, file);
+-
++  if(getenv("GIMXCONF")) { snprintf(file_path, sizeof(file_path), "%s", file); }
+   if(read_file(file_path) == -1)
+   {
+     gerror("read_file failed\n");
+diff --git a/core/gimx.c b/core/gimx.c
+index 700cae9..9143d8b 100755
+--- a/core/gimx.c
++++ b/core/gimx.c
+@@ -192,7 +192,7 @@ void show_config()
+   char file_path[PATH_MAX];
+ 
+   snprintf(file_path, sizeof(file_path), "%s%s%s%s", gimx_params.homedir, GIMX_DIR, CONFIG_DIR, gimx_params.config_file);
+-
++  if(getenv("GIMXCONF")) { snprintf(file_path, sizeof(file_path), "%s", gimx_params.config_file); }
+   FILE * fp = gfile_fopen(file_path, "r");
+   if (fp == NULL)
+   {
diff --git a/pkgs/games/gimx/custom/Dualshock4.xml b/pkgs/games/gimx/custom/Dualshock4.xml
new file mode 100644
index 0000000000000..45ee5ed7c1c16
--- /dev/null
+++ b/pkgs/games/gimx/custom/Dualshock4.xml
@@ -0,0 +1,104 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<root>
+  <controller id="1" dpi="0" type="DS4">
+    <configuration id="1">
+      <trigger type="" id="" name="" button_id="" switch_back="no" delay="0"/>
+      <mouse_options_list/>
+      <intensity_list/>
+      <button_map>
+        <button id="abs_axis_10" label="">
+          <device type="joystick" id="0" name="Sony Computer Entertainment Wireless Controller"/>
+          <event type="button" id="3"/>
+        </button>
+        <button id="abs_axis_9" label="">
+          <device type="joystick" id="0" name="Sony Computer Entertainment Wireless Controller"/>
+          <event type="button" id="0"/>
+        </button>
+        <button id="abs_axis_8" label="">
+          <device type="joystick" id="0" name="Sony Computer Entertainment Wireless Controller"/>
+          <event type="button" id="1"/>
+        </button>
+        <button id="abs_axis_7" label="">
+          <device type="joystick" id="0" name="Sony Computer Entertainment Wireless Controller"/>
+          <event type="button" id="2"/>
+        </button>
+        <button id="abs_axis_11" label="">
+          <device type="joystick" id="0" name="Sony Computer Entertainment Wireless Controller"/>
+          <event type="button" id="4"/>
+        </button>
+        <button id="abs_axis_12" label="">
+          <device type="joystick" id="0" name="Sony Computer Entertainment Wireless Controller"/>
+          <event type="button" id="5"/>
+        </button>
+        <button id="abs_axis_0" label="">
+          <device type="joystick" id="0" name="Sony Computer Entertainment Wireless Controller"/>
+          <event type="button" id="8"/>
+        </button>
+        <button id="abs_axis_1" label="">
+          <device type="joystick" id="0" name="Sony Computer Entertainment Wireless Controller"/>
+          <event type="button" id="9"/>
+        </button>
+        <button id="abs_axis_15" label="">
+          <device type="joystick" id="0" name="Sony Computer Entertainment Wireless Controller"/>
+          <event type="button" id="11"/>
+        </button>
+        <button id="abs_axis_16" label="">
+          <device type="joystick" id="0" name="Sony Computer Entertainment Wireless Controller"/>
+          <event type="button" id="12"/>
+        </button>
+        <button id="abs_axis_2" label="">
+          <device type="joystick" id="0" name="Sony Computer Entertainment Wireless Controller"/>
+          <event type="button" id="10"/>
+        </button>
+        <button id="abs_axis_3" label="">
+          <device type="joystick" id="0" name="Sony Computer Entertainment Wireless Controller"/>
+          <event type="button" id="13"/>
+        </button>
+        <button id="abs_axis_4" label="">
+          <device type="joystick" id="0" name="Sony Computer Entertainment Wireless Controller"/>
+          <event type="button" id="14"/>
+        </button>
+        <button id="abs_axis_5" label="">
+          <device type="joystick" id="0" name="Sony Computer Entertainment Wireless Controller"/>
+          <event type="button" id="15"/>
+        </button>
+        <button id="abs_axis_6" label="">
+          <device type="joystick" id="0" name="Sony Computer Entertainment Wireless Controller"/>
+          <event type="button" id="16"/>
+        </button>
+      </button_map>
+      <axis_map>
+        <axis id="rel_axis_0" label="">
+          <device type="joystick" id="0" name="Sony Computer Entertainment Wireless Controller"/>
+          <event type="axis" id="0" dead_zone="0" multiplier="0.004" exponent="1.00" shape=""/>
+        </axis>
+        <axis id="rel_axis_1" label="">
+          <device type="joystick" id="0" name="Sony Computer Entertainment Wireless Controller"/>
+          <event type="axis" id="1" dead_zone="0" multiplier="0.004" exponent="1.00" shape=""/>
+        </axis>
+        <axis id="rel_axis_2" label="">
+          <device type="joystick" id="0" name="Sony Computer Entertainment Wireless Controller"/>
+          <event type="axis" id="3" dead_zone="0" multiplier="0.004" exponent="1.00" shape=""/>
+        </axis>
+        <axis id="rel_axis_3" label="">
+          <device type="joystick" id="0" name="Sony Computer Entertainment Wireless Controller"/>
+          <event type="axis" id="4" dead_zone="0" multiplier="0.004" exponent="1.00" shape=""/>
+        </axis>
+        <axis id="abs_axis_13" label="">
+          <device type="joystick" id="0" name="Sony Computer Entertainment Wireless Controller"/>
+          <event type="axis" id="2" dead_zone="0" multiplier="0.008" exponent="1.00" shape=""/>
+        </axis>
+        <axis id="abs_axis_14" label="">
+          <device type="joystick" id="0" name="Sony Computer Entertainment Wireless Controller"/>
+          <event type="axis" id="5" dead_zone="0" multiplier="0.008" exponent="1.00" shape=""/>
+        </axis>
+      </axis_map>
+      <joystick_corrections_list/>
+      <force_feedback>
+        <device type="joystick" id="0" name="Sony Computer Entertainment Wireless Controller"/>
+        <inversion enable="no"/>
+        <gain rumble="0" constant="0" spring="0" damper="0"/>
+      </force_feedback>
+    </configuration>
+  </controller>
+</root>
diff --git a/pkgs/games/gimx/default.nix b/pkgs/games/gimx/default.nix
index 0ae5a7917096a..132169b711d7a 100644
--- a/pkgs/games/gimx/default.nix
+++ b/pkgs/games/gimx/default.nix
@@ -1,5 +1,5 @@
 { stdenv, lib, fetchFromGitHub, makeWrapper, curl, libusb1, xorg, libxml2
-, ncurses5, bluez, libmhash, gimxAuth ? "" }:
+, ncurses5, bluez, libmhash, gimxPDP ? false }:
 
 let
   gimx-config = fetchFromGitHub {
@@ -21,15 +21,21 @@ in stdenv.mkDerivation rec {
     sha256 = "0265gg6q7ymg76fb4pjrfdwjd280b3zzry96qy92w0h411slph85";
   };
 
+  patches = [ ./conf.patch ];
   nativeBuildInputs = [ makeWrapper ];
   buildInputs = [
     curl libusb1 bluez libxml2 ncurses5 libmhash
     xorg.libX11 xorg.libXi xorg.libXext
   ];
 
-  patches = [ ./env.patch ];
-  prePatch = (if gimxAuth == "afterglow" then (import ./variant.nix).afterglow
-              else "");
+  postPatch = lib.optionals gimxPDP ''
+    substituteInPlace ./shared/gimxcontroller/include/x360.h \
+      --replace "0x045e" "0x0e6f" --replace "0x028e" "0x0213"
+    substituteInPlace ./loader/firmware/EMU360.hex \
+      --replace "1B210001" "1B211001" \
+      --replace "09210001" "09211001" \
+      --replace "5E048E021001" "6F0E13020001"
+  '';
 
   makeFlags = "build-core";
   installPhase = ''
@@ -51,19 +57,19 @@ in stdenv.mkDerivation rec {
     mkdir -p $out/share
     cp -r ./loader/firmware $out/share/firmware
     cp -r ${gimx-config}/Linux $out/share/config
+    cp -r ${./custom} $out/share/custom
 
-    makeWrapper $out/bin/gimx $out/bin/gimx-with-confs \
-      --set GIMXCONF $out/share/config
+    makeWrapper $out/bin/gimx $out/bin/gimx-dualshock4 \
+      --set GIMXCONF 1 --add-flags "--nograb" --add-flags "-p /dev/ttyUSB0" \
+      --add-flags "-c $out/share/config/Dualshock4.xml"
 
-    makeWrapper $out/bin/gimx $out/bin/gimx-test-ds4 \
-      --set GIMXCONF $out/share/config \
-      --add-flags "--nograb" --add-flags "--curses" \
-      --add-flags "-p /dev/ttyUSB0" --add-flags "-c Dualshock4.xml"
+    makeWrapper $out/bin/gimx $out/bin/gimx-dualshock4-noff \
+      --set GIMXCONF 1 --add-flags "--nograb" --add-flags "-p /dev/ttyUSB0" \
+      --add-flags "-c $out/share/custom/Dualshock4.xml"
 
-    makeWrapper $out/bin/gimx $out/bin/gimx-test-xone \
-      --set GIMXCONF $out/share/config \
-      --add-flags "--nograb" --add-flags "--curses" \
-      --add-flags "-p /dev/ttyUSB0" --add-flags "-c XOnePadUsb.xml"
+    makeWrapper $out/bin/gimx $out/bin/gimx-xboxonepad \
+      --set GIMXCONF 1 --add-flags "--nograb" --add-flags "-p /dev/ttyUSB0" \
+      --add-flags "-c $out/share/config/XOnePadUsb.xml"
   '';
 
   meta = with lib; {
diff --git a/pkgs/games/gimx/env.patch b/pkgs/games/gimx/env.patch
deleted file mode 100644
index e1f8ed8bb6f14..0000000000000
--- a/pkgs/games/gimx/env.patch
+++ /dev/null
@@ -1,30 +0,0 @@
---- a/core/config_reader.c
-+++ b/core/config_reader.c
-@@ -1353,8 +1353,10 @@ static int read_file(char* file_path)
- int read_config_file(const char* file)
- {
-   char file_path[PATH_MAX];
--
--  snprintf(file_path, sizeof(file_path), "%s%s%s%s", gimx_params.homedir, GIMX_DIR, CONFIG_DIR, file);
-+  char* e = getenv("GIMXCONF"); if (e) { snprintf(file_path, sizeof(file_path), "%s/%s", e, file); }
-+  else {
-+    snprintf(file_path, sizeof(file_path), "%s%s%s%s", gimx_params.homedir, GIMX_DIR, CONFIG_DIR, file);
-+  }
- 
-   if(read_file(file_path) == -1)
-   {
---- a/core/gimx.c
-+++ b/core/gimx.c
-@@ -190,8 +190,10 @@ void show_config()
-   }
- 
-   char file_path[PATH_MAX];
--
--  snprintf(file_path, sizeof(file_path), "%s%s%s%s", gimx_params.homedir, GIMX_DIR, CONFIG_DIR, gimx_params.config_file);
-+  char* e = getenv("GIMXCONF"); if (e) { snprintf(file_path, sizeof(file_path), "%s/%s", e, gimx_params.config_file); }
-+  else {
-+    snprintf(file_path, sizeof(file_path), "%s%s%s%s", gimx_params.homedir, GIMX_DIR, CONFIG_DIR, gimx_params.config_file);
-+  }
- 
-   FILE * fp = gfile_fopen(file_path, "r");
-   if (fp == NULL)
diff --git a/pkgs/games/gimx/variant.nix b/pkgs/games/gimx/variant.nix
deleted file mode 100644
index 8396f72b4e77a..0000000000000
--- a/pkgs/games/gimx/variant.nix
+++ /dev/null
@@ -1,14 +0,0 @@
-{
-  afterglow = ''
-    substituteInPlace ./shared/gimxcontroller/include/x360.h \
-      --replace "0x045e" "0x0e6f" --replace "0x028e" "0x0213"
-
-    HEX="./loader/firmware/EMU360.hex"
-    sed -i '34s|1B2100|1B2110|' "$HEX"
-    sed -i '38s|092100|092110|' "$HEX"
-    sed -i '40s|5E048E021001|6F0E13020001|' "$HEX"
-    sed -i '34s|1C\r|0C\r|' "$HEX"
-    sed -i '38s|FE\r|EE\r|' "$HEX"
-    sed -i '40s|6D\r|DD\r|' "$HEX"
-  '';
-}