Skip to content

Commit

Permalink
Fix Joystick Menu and default buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
Dobby233Liu authored Aug 16, 2024
1 parent 8c69e79 commit dfc4c04
Showing 1 changed file with 51 additions and 9 deletions.
60 changes: 51 additions & 9 deletions UndertaleModTool/Scripts/Builtin Scripts/RunSwitchAndXboxOnPC.csx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ ReplaceTextInGML("gml_Object_obj_time_Create_0", @"if (global.osflavor >= 3)
ReplaceTextInGML("gml_Object_obj_time_Draw_77", "global.osflavor >= 3", "true");

// Use new gamepad functions, because the compatibility ones are completely broken
// use switch routine for joypad detection

// use NX routine for joypad detection
ReplaceTextInGML("gml_Object_obj_time_Create_0", @"if (global.osflavor >= 4)
{
i = 0
Expand All @@ -54,6 +55,7 @@ ReplaceTextInGML("gml_Object_obj_time_Create_0", @"
j_ch = 1", @"
else if (global.osflavor >= 4)
j_ch = 1");
string os_switch = "os_switch" + (!isXbox ? "_beta" : "");
ReplaceTextInGML("gml_Object_obj_time_Step_1", @"if (global.osflavor <= 2)
{
if (jt == 0)
Expand All @@ -80,7 +82,7 @@ ReplaceTextInGML("gml_Object_obj_time_Step_1", @"if (global.osflavor <= 2)
if (jt >= 8)
jt = 0
}
else if (os_type == os_switch)", "");
else if (os_type == " + os_switch + ")", "");
ReplaceTextInGML("gml_Object_obj_time_Step_1", @"
if (j_ch > 0)
missing_controller_timeout = 0
Expand All @@ -94,7 +96,7 @@ ReplaceTextInGML("gml_Object_obj_time_Step_1", @"
missing_controller_timeout = 0
}
}", @"
if (os_type == os_switch) {
if (os_type == " + os_switch + @") {
if (j_ch > 0)
missing_controller_timeout = 0
else if (missing_controller_timeout == 0)
Expand All @@ -108,15 +110,33 @@ ReplaceTextInGML("gml_Object_obj_time_Step_1", @"
}
}
}");

// Use Xbox default buttons
ReplaceTextInGML("gml_Object_obj_time_Create_0", @"global.button0 = 2
global.button1 = 1
global.button2 = 4", @"global.button0 = gp_face1
global.button1 = gp_face2
global.button2 = gp_face4");
ReplaceTextInGML("gml_Object_obj_joypadmenu_Draw_0", @"
global.button0 = 2
global.button1 = 1
global.button2 = 4", @"
global.button0 = gp_face1
global.button1 = gp_face2
global.button2 = gp_face4");

// axis check
ReplaceTextInGML("gml_Object_obj_time_Step_1", @"if (global.osflavor >= 4)
{
if (gamepad_button_check", @"if (true)
{
if (gamepad_button_check");

// button check
ReplaceTextInGML("gml_Script_control_update", "else if (obj_time.j_ch > 0)", "else if (false)");
ReplaceTextInGML("gml_Script_control_update", "global.osflavor >= 4", "obj_time.j_ch > 0");

/*
// this partially fixes joypadmenu
ReplaceTextInGML("gml_Script___joystick_2_gamepad", @"if (argument0 == 2)
return global.__jstick_pad2;
Expand All @@ -127,10 +147,33 @@ return obj_time.j_ch - 1;");
// show button config
ReplaceTextInGML("gml_Object_obj_settingsmenu_Draw_0", "global.osflavor <= 2", "false");
ReplaceTextInGML("gml_Object_obj_settingsmenu_Draw_0", "global.osflavor >= 4", "true");
*/

// Fix Joystick Menu
ReplaceTextInGML("gml_Script___joystick_2_gamepad", @"if (argument0 == 2)
return global.__jstick_pad2;
else
return global.__jstick_pad1;", @"show_debug_message(""Debug : __joystick_2_gamepad was called"")
if (argument0 != obj_time.j_ch)
show_debug_message(""Debug : passed in value other than j_ch while calling joystick functions"")
return obj_time.j_ch - 1;");
ReplaceTextInGML("gml_Object_obj_joypadmenu_Create_0", "joystick_has_pov(obj_time.j_ch)", "true");
ReplaceTextInGML("gml_Object_obj_joypadmenu_Draw_0", "joystick_has_pov(obj_time.j_ch)", "true");
// gamepad_button_count(obj_time.j_ch - 1) might work better but I'm not sure
ReplaceTextInGML("gml_Object_obj_joypadmenu_Draw_0", "joystick_buttons(obj_time.j_ch)", "11 + 1");
ReplaceTextInGML("gml_Object_obj_joypadmenu_Draw_0", "joystick_check_button(obj_time.j_ch, i)", "gamepad_button_check(obj_time.j_ch - 1, 32769 + i)");
for (var i = 0; i < 3; i++)
{
ReplaceTextInGML("gml_Object_obj_joypadmenu_Draw_0", $"global.button{i} = i", $"global.button{i} = 32769 + i");
ReplaceTextInGML("gml_Object_obj_joypadmenu_Draw_0", $"string_hash_to_newline(global.button{i})", $"string(global.button{i} - 32769)");
}

// Use Xbox or PS4 button sprites
if (isXbox)
ReplaceTextInGML("gml_Script_scr_getbuttonsprite", "os_type == os_xboxone", "true");
else
ReplaceTextInGML("gml_Script_scr_getbuttonsprite", "os_type == os_ps4", "true");

// Allow gamepad input for left/right heart halfs
foreach (string half in new List<string>{"l", "r"})
{
Expand All @@ -154,15 +197,15 @@ if (ScriptQuestion("Enable the Dog Shrine?"))
else
ReplaceTextInGML("gml_Object_obj_kitchenchecker_Alarm_2", "(global.osflavor == 4 || global.osflavor == 5) && ", "");

if (isXbox)
ReplaceTextInGML("gml_Object_obj_doorXmusicfade_Alarm_2", "if (global.osflavor == 6)", "else");
// if in NX version, the door will get you into the ruined dog shrine

// Enable donation box trash
if (isXbox)
ReplaceTextInGML("gml_Object_obj_npc_room_Create_0", "global.osflavor != 4 && global.osflavor != 6", "false");
else
ReplaceTextInGML("gml_Object_obj_npc_room_Create_0", "(global.osflavor != 4 && global.osflavor != 5) || ", "");

if (isXbox)
ReplaceTextInGML("gml_Object_obj_doorXmusicfade_Alarm_2", "if (global.osflavor == 6)", "else");
// if in NX version, the door will get you into the ruined dog shrine
}

// Done.
Expand All @@ -181,5 +224,4 @@ Copy 'mus_mewmew.ogg', 'mus_sfx_dogseal.ogg' and 'mus_dogshrine_xbox.ogg'
into the folder you will save this game archive.
Use a 2.2.2-2.2.5 runner to run Undertale.
Note that despite a border option showing up in the Settings,
borders are NOT enabled. Please use BorderEnabler_v1_11.csx.");
You might want to reset joystick settings.");

0 comments on commit dfc4c04

Please sign in to comment.