Author: Anonymous Language: text
Description: Cave Story configuration utility patch (fixes gamepad configuration) Timestamp: 2014-04-05 18:18:49 -0400
View raw paste Reply
diff -c DoConfigure-r2/DoConfig.cpp DoConfigure-r2-patched/DoConfig.cpp
*** DoConfigure-r2/DoConfig.cpp 2011-04-26 02:42:52.000000000 -0400
--- DoConfigure-r2-patched/DoConfig.cpp 2014-04-05 17:54:57.600039878 -0400
***************
*** 3,12 ****
   * and/or modify it under the terms of the Do What The F*** You Want
   * To Public License, Version 2, as published by Sam Hocevar. See
   * http://sam.zoy.org/wtfpl/COPYING for more details. */
!
  #include <cstdlib>
  #include <iostream>
! #include <fstream>
  #include <cstring>
  #include "FL/Fl.H"
  #include "FL/Fl_Window.H"
--- 3,12 ----
   * and/or modify it under the terms of the Do What The F*** You Want
   * To Public License, Version 2, as published by Sam Hocevar. See
   * http://sam.zoy.org/wtfpl/COPYING for more details. */
!
  #include <cstdlib>
  #include <iostream>
! #include <fstream>
  #include <cstring>
  #include "FL/Fl.H"
  #include "FL/Fl_Window.H"
***************
*** 66,71 ****
--- 66,163 ----
        this->buttons[input]->setonly();
  }
 
+ /**
+  * Action code values are a bit mixed up - on the screen they don't follow in the same
+  * way they are coded in Config.dat file.
+  *
+  * this is how hex dump of the last 4x8 bytes of the
+  * Config.dat file looks when the controller settings
+  * are saved in the following way:
+  * 1=[0]Jump(1)
+  * 2=[1]Attack(2)
+  * 3=[2]Weapon+(3)
+  * 4=[3]Weapon-(6)
+  * 5=[4]Items(4)
+  * 6=[5]Map(5)
+  * 7=[0]Jump(1)
+  * 8=[1]Attack(2)
+  *                       01 00 00 00 02 00 00 00 03 00 00 00
+  * 06 00 00 00 04 00 00 00 05 00 00 00 01 00 00 00
+  * 02 00 00 00
+  */
+ int screenIndexToFileIndex(int screenIndex) {
+       int fileIndex;
+       switch(screenIndex) {
+         case 0: // Jump on screen
+               fileIndex = 1; //Jump in file
+               break;
+         case 1: // Attack on screen
+               fileIndex = 2; // Attack in file
+               break;
+         case 2: // Weapon+ on screen
+               fileIndex = 3; // Weapon+ in file
+               break;
+         case 3: // Weapon- on screen
+               fileIndex = 6; // Weapon- in file
+               break;
+         case 4: // Items on screen
+               fileIndex = 4; // Items in file
+               break;
+         case 5: // Map on screen
+               fileIndex = 5; // Map in file
+               break;
+         default:
+               fileIndex = 0;
+       }
+       return fileIndex;
+ }
+
+ /**
+  * Action code values are a bit mixed up - on the screen they don't follow in the same
+  * way they are coded in Config.dat file.
+  *
+  * this is how hex dump of the last 4x8 bytes of the
+  * Config.dat file looks when the controller settings
+  * are saved in the following way:
+  * 1=[0]Jump(1)
+  * 2=[1]Attack(2)
+  * 3=[2]Weapon+(3)
+  * 4=[3]Weapon-(6)
+  * 5=[4]Items(4)
+  * 6=[5]Map(5)
+  * 7=[0]Jump(1)
+  * 8=[1]Attack(2)
+  *                       01 00 00 00 02 00 00 00 03 00 00 00
+  * 06 00 00 00 04 00 00 00 05 00 00 00 01 00 00 00
+  * 02 00 00 00
+  */
+ int fileIndexToScreenIndex(int fileIndex) {
+       int screenIndex;
+       switch(fileIndex) {
+         case 1: // Jump in file
+               screenIndex = 0; //Jump on screen
+               break;
+         case 2: // Attack in file
+               screenIndex = 1; // Attack on screen
+               break;
+         case 3: // Weapon+ in file
+               screenIndex = 2; // Weapon+ on screen
+               break;
+         case 4: // Items in file
+               screenIndex = 4; // Items on screen
+               break;
+         case 5: // Map in file
+               screenIndex = 5; // Map on screen
+               break;
+         case 6: // Weapon- in file
+               screenIndex = 3; // Weapon- on screen
+               break;
+         default:
+               screenIndex = 0;
+       }      
+       return screenIndex;
+ }
+
  Fl_Round_Button *movear;
  Fl_Round_Button *movegt;
 
***************
*** 117,126 ****
        if( !config.useJoy ){
                joystuffcontainer->deactivate();
        }
!       for(char i=0;i<8;i++){
!               if(config.buttons[i]<9 && config.buttons[i]>0){
!                       joyRows[i]->value(config.buttons[i] -1);
!               }
        }
        fd.close();
  }
--- 209,217 ----
        if( !config.useJoy ){
                joystuffcontainer->deactivate();
        }
!      
!       for(char i=0;i<8;i++){   
!               joyRows[i]->value(fileIndexToScreenIndex(config.buttons[i]));
        }
        fd.close();
  }
***************
*** 141,147 ****
        config.display = displaychoice->value();
        config.useJoy = joychoice->value();
        for(char i =0;i<8;i++){
!               config.buttons[i] = joyRows[i]->value();
        }
        fd.write((char*)&config, 148);
        fd.close();
--- 232,238 ----
        config.display = displaychoice->value();
        config.useJoy = joychoice->value();
        for(char i =0;i<8;i++){
!               config.buttons[i] = screenIndexToFileIndex(joyRows[i]->value());
        }
        fd.write((char*)&config, 148);
        fd.close();
***************
*** 175,181 ****
        Fl_Menu_Item screens[] = {
                {"Fullscreen 16-bit"},
                {"Windowed 320x240"},
!               {"Windowed 640x480"},
                {"Fullscreen 24-bit"},
                {"Fullscreen 32-bit"},
                {0}};
--- 266,272 ----
        Fl_Menu_Item screens[] = {
                {"Fullscreen 16-bit"},
                {"Windowed 320x240"},
!               {"Windowed 640x480"},
                {"Fullscreen 24-bit"},
                {"Fullscreen 32-bit"},
                {0}};
 
View raw paste Reply