Skip to content

Commit

Permalink
Address suggestions, improve comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Dobby233Liu authored and colinator27 committed Aug 23, 2024
1 parent fb82caf commit 0cea983
Showing 1 changed file with 36 additions and 36 deletions.
72 changes: 36 additions & 36 deletions UndertaleModTool/Scripts/Builtin Scripts/RunSwitchAndXboxOnPC.csx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ bool isXbox = Data.Rooms.ByName("room_xbox_engagement") is not null;

if (isXbox)
{
// Fix initialization code not running
// Fix cruical initialization code not running.
ReplaceTextInGML("gml_Object_obj_time_Create_0", """
if (os_type == os_xboxone)
{
Expand All @@ -35,20 +35,24 @@ if (isXbox)
otherEvents.Remove(gameStartEvent);
}

// Disables interpolation. Only necessary for NX version.
// Disables interpolation. Only necessary for the NX version.
Data.GeneralInfo.Info &= ~UndertaleGeneralInfo.InfoFlags.Interpolate;

// Use new gamepad functions, because the compatibility ones are completely broken
// Use console gamepad code paths to use the new gamepad functions,
// because the compatibility ones are completely broken.

// use NX routine for joypad detection
// Use the NX code path for gamepad detection.
ReplaceTextInGML("gml_Object_obj_time_Create_0", "if (global.osflavor >= 4)", "if (true)");
// Make the game not pretend a controller is there initially on PC?
// Why did they do this?
ReplaceTextInGML("gml_Object_obj_time_Create_0", """
else
j_ch = 1
""", """
else if (global.osflavor >= 4)
j_ch = 1
""");
// The os_switch constant changed after the NX version.
string os_switch = "os_switch" + (!isXbox ? "_beta" : "");
ReplaceTextInGML("gml_Object_obj_time_Step_1", "global.osflavor <= 2", "false");
ReplaceTextInGML("gml_Object_obj_time_Step_1", $"os_type == {os_switch}", "true");
Expand All @@ -61,7 +65,9 @@ ReplaceTextInGML("gml_Object_obj_time_Step_1", """
missing_controller_timeout = 0
""");

// Use Xbox default buttons
// Use the Xbox default buttons on PC.
// We have to map the joystick_* button constants to the gamepad_*
// button constants anyway.
ReplaceTextInGML("gml_Object_obj_time_Create_0", """
global.button0 = 2
global.button1 = 1
Expand All @@ -81,7 +87,7 @@ ReplaceTextInGML("gml_Object_obj_joypadmenu_Draw_0", """
global.button2 = gp_face4
""");

// axis check
// Use the console path for the axis check.
ReplaceTextInGML("gml_Object_obj_time_Step_1", """
if (global.osflavor >= 4)
{
Expand All @@ -92,14 +98,14 @@ ReplaceTextInGML("gml_Object_obj_time_Step_1", """
if (gamepad_button_check
""");

// button check
// Use the console path for the button checks.
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");

// Fix Joystick Menu
// Make the Joystick Menu use the new gamepad functions.
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
// TODO: gamepad_button_count(obj_time.j_ch - 1) might work better?
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, gp_face1 + i)");
for (var i = 0; i < 3; i++)
Expand All @@ -108,13 +114,7 @@ for (var i = 0; i < 3; i++)
ReplaceTextInGML("gml_Object_obj_joypadmenu_Draw_0", $"string_hash_to_newline(global.button{i})", $"string(global.button{i} - gp_face1)");
}

// 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
// Make the Mad Mew Mew heart halves accept both kinds of input.
foreach (char half in new[] {'l', 'r'})
{
foreach (char side in new[] {'u', 'd', 'l', 'r'})
Expand All @@ -128,45 +128,45 @@ if (ScriptQuestion("Enable the Dog Shrine?"))
{
if (isXbox)
{
// This enables the Dog Shrine's entrance.
// This enables the entrance to the Dog Shrine.
ReplaceTextInGML("gml_Object_obj_kitchenchecker_Create_0", "global.osflavor == 4 || global.osflavor == 5 || global.osflavor == 6", "true");
ReplaceTextInGML("gml_Object_obj_kitchenchecker_Alarm_2", "(global.osflavor == 4 || global.osflavor == 5 || global.osflavor == 6) && ", "");
// if in NX version, the door will get you into the ruined dog shrine
// This patch is unnecessary in the NX version, as the door will get you into the ruined Dog Shrine.
ReplaceTextInGML("gml_Object_obj_doorXmusicfade_Alarm_2", "if (global.osflavor == 6)", "else");

// Enable donation box trash
// Enable the donation box trash in Waterfall.
ReplaceTextInGML("gml_Object_obj_npc_room_Create_0", "global.osflavor != 4 && global.osflavor != 6", "false");
}
else
{
// This enables the Dog Shrine's entrance.
// This enables the entrance to the Dog Shrine.
ReplaceTextInGML("gml_Object_obj_kitchenchecker_Create_0", "global.osflavor == 4 || global.osflavor == 5", "true");
ReplaceTextInGML("gml_Object_obj_kitchenchecker_Alarm_2", "(global.osflavor == 4 || global.osflavor == 5) && ", "");

// Enable donation box trash
// Enable the donation box trash in Waterfall.
ReplaceTextInGML("gml_Object_obj_npc_room_Create_0", "(global.osflavor != 4 && global.osflavor != 5) || ", "");
}
}

// Done.
ScriptMessage("""
string requiredFiles = !isXbox ? """
Copy "mus_mewmew.ogg", "mus_sfx_dogseal.ogg",
and "DELTARUNE.exe" (from the 2018 Ch1 demo)
to the folder you will save this data file to.
Then use the Deltarune runner to run the game.
""" : """
Copy "mus_mewmew.ogg", "mus_sfx_dogseal.ogg",
"mus_dogshrine_xbox.ogg", and a GMS2 2.2.2-2.2.5
runner to the folder you will save this data file to.
Then use the new runner to run the game.
""";
ScriptMessage($"""
NXTALE Enabler by Kneesnap
Xbox and gamepad fixes by Dobby233Liu

NOTE: You're not done yet!

For Switch version:
Copy "mus_mewmew.ogg", "mus_sfx_dogseal.ogg",
and "DELTARUNE.exe" (from SURVEY_PROGRAM/the 2018 version)
to the folder you will save this data file to.
Then use the Deltarune runner to run Undertale.

For Xbox version:
Copy "mus_mewmew.ogg", "mus_sfx_dogseal.ogg"
and "mus_dogshrine_xbox.ogg"
to the folder you will save this data file to.
Then use a GMS2 2.2.2-2.2.5 runner to run Undertale.
{requiredFiles}

Due to button constant changes, you might want to reset
the joystick settings.
Due to gamepad code changes, you might want to reset the
gamepad settings.
""");

0 comments on commit 0cea983

Please sign in to comment.