Skip to content

Commit

Permalink
Add TouchControlsEnabler.csx (and a script to fix alphys lab crash) (#…
Browse files Browse the repository at this point in the history
…1415)

* Add TouchControlsEnabler.csx

* Add FixAlphysLabCrashAndroid.csx

* Update syntax

* Update FixAlphysLabCrashAndroid.csx

* Update gml_Object_obj_mobilecontrols_Other_4.gml

* Update gml_Object_obj_mobilecontrols_Other_4.gml

* Update TouchControlsEnabler.csx

* Update gml_Object_obj_mobilecontrols_Create_0.gml

* Update TouchControlsEnabler.csx

* Update gml_Object_obj_mobilecontrols_Step_0.gml

* Turn picture into size of 2 or smth

* Update SCRIPTS.md

* Add credit

* Add credit

* merge commit from @Miepee

Co-authored-by: Miepee <[email protected]>

* Update SCRIPTS.md

Co-authored-by: Vladislav Stepanov <[email protected]>

* Data? -> Data

Co-authored-by: Vladislav Stepanov <[email protected]>

* Data? -> Data (TouchControlsEnabler.csx)

---------

Co-authored-by: Miepee <[email protected]>
Co-authored-by: Vladislav Stepanov <[email protected]>
  • Loading branch information
3 people authored Dec 30, 2023
1 parent 2114c81 commit 979db25
Show file tree
Hide file tree
Showing 8 changed files with 371 additions and 6 deletions.
15 changes: 9 additions & 6 deletions SCRIPTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ They are relatively self-explanatory, but there are also some helpful general-pu
- `EditGMS2TileData.csx`: A temporary script to help edit tile data in GMS2 games.
- `ExternalizeAllOGGs.csx`: Script to externalize all OGG sound effects from a game.
- `FancyRoomSelect.csx`: Script to make selecting and teleporting to different rooms in a game very user-friendly.
- `FixAlphysLabCrashAndroid.csx`: Script that fixes a crash at Alphys's lab on Android devices.
- `ReloadDeltaruneJSON.csx`: Script to add a hotkey to Deltarune, which reloads the language JSON.
- `TouchControlsEnabler.csx`: Adds mobile touch controls to an Undertale or Deltarune data.win.
- `TTFFonts (Deltarune).csx`: Marks all fonts in Deltarune to be externally loaded. Does not handle Japanese text.
- `UndertaleWithJSONs.csx`: This script JSONifies all Undertale versions with Japanese support, 1.05+. Switch languages using F11. Reload text for curent language from JSON on command using F12. Reloading from JSON may take about 10 seconds.

Expand Down Expand Up @@ -77,14 +79,15 @@ For individual script credits, look at the source for any given script. Often, c

Here is the list of contributors as of writing:
- Agentalex9
- BenjaminUrquhart
- colinator27
- Grossley
- Kneesnap
- krzys_h
- [BenjaminUrquhart](https://github.com/BenjaminUrquhart)
- [colinator27](https://github.com/colinator27)
- [GitMuslim](https://github.com/GitMuslim)
- [Grossley](https://github.com/Grossley)
- [Kneesnap](https://github.com/Kneesnap)
- [krzys_h](https://github.com/krzys-h)
- Lassebq
- mono21400
- nik (the cat)
- [nik (the cat)](https://github.com/nkrapivin)
- samuelroy21 (among others from the DSG team)
- Yokim (Jockeholm)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Made by GitMuslim

using System;
using System.IO;
using System.Threading.Tasks;
using System.Linq;
using UndertaleModLib.Util;

EnsureDataLoaded();

if (Data.GeneralInfo?.DisplayName?.Content.ToLower() != "undertale")
{
ScriptError("Error 0: Compatible with Undertale only");
return;
}
ReplaceTextInGML("gml_Object_obj_labdarkness_Create_0", "glowamt = 0.5\nif (global.plot > 125)\n instance_destroy()\nif (scr_murderlv() >= 12)\n instance_destroy()", "");
ReplaceTextInGML("gml_Object_obj_labdarkness_Draw_0", "x1 = (obj_mainchara.x - 10)\nx2 = (obj_mainchara.x + 30)\ny1 = (obj_mainchara.y - 5)\ny2 = (obj_mainchara.y + 35)\ndraw_sprite_ext(spr_darkhalo_big, 0, x1, y1, 1, 1, 0, c_white, glowamt)\ndraw_set_alpha(1)", "");
ReplaceTextInGML("gml_Object_obj_labcamera_Create_0", "if (global.osflavor == 2)", "if (global.osflavor == 4)");
110 changes: 110 additions & 0 deletions UndertaleModTool/Scripts/Community Scripts/TouchControlsEnabler.csx
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
// Made by GitMuslim

using System;
using System.IO;
using System.Threading.Tasks;
using System.Linq;
using UndertaleModLib.Util;

EnsureDataLoaded();

string displayName = Data.GeneralInfo?.DisplayName?.Content.ToLower();

if (displayName != "deltarune chapter 1 & 2" && displayName != "deltarune chapter 1&2" && displayName != "undertale")
{
ScriptError("Error 0: Only compatible with Undertale & Deltarune");
return;
}

string dataPath = Path.Combine(Path.GetDirectoryName(ScriptPath), "TouchControls_data");

Dictionary<string, UndertaleEmbeddedTexture> textures = new Dictionary<string, UndertaleEmbeddedTexture>();

UndertaleEmbeddedTexture controlsTexturePage = new UndertaleEmbeddedTexture();
controlsTexturePage.TextureData.TextureBlob = File.ReadAllBytes(Path.Combine(dataPath, "controls.png"));
Data.EmbeddedTextures.Add(controlsTexturePage);
textures.Add(Path.GetFileName(Path.Combine(dataPath, "controls.png")), controlsTexturePage);

UndertaleTexturePageItem AddNewTexturePageItem(ushort sourceX, ushort sourceY, ushort sourceWidth, ushort sourceHeight)
{
ushort targetX = 0;
ushort targetY = 0;
ushort targetWidth = sourceWidth;
ushort targetHeight = sourceHeight;
ushort boundingWidth = sourceWidth;
ushort boundingHeight = sourceHeight;
var texturePage = textures["controls.png"];

UndertaleTexturePageItem tpItem = new UndertaleTexturePageItem { SourceX = sourceX, SourceY = sourceY, SourceWidth = sourceWidth, SourceHeight = sourceHeight, TargetX = targetX, TargetY = targetY, TargetWidth = targetWidth, TargetHeight = targetHeight, BoundingWidth = boundingWidth, BoundingHeight = boundingHeight, TexturePage = texturePage };
Data.TexturePageItems.Add(tpItem);
return tpItem;
}

UndertaleTexturePageItem pg_joybase1 = AddNewTexturePageItem(0, 0, 59, 59);
UndertaleTexturePageItem pg_joybase2 = AddNewTexturePageItem(0, 61, 59, 59);
UndertaleTexturePageItem pg_joystick = AddNewTexturePageItem(61, 0, 41, 41);
UndertaleTexturePageItem pg_joystick2 = AddNewTexturePageItem(0, 122, 41, 41);
UndertaleTexturePageItem pg_settings_n = AddNewTexturePageItem(61, 43, 19, 24);
UndertaleTexturePageItem pg_settings_p = AddNewTexturePageItem(83, 43, 19, 24);
UndertaleTexturePageItem pg_zbutton = AddNewTexturePageItem(104, 0, 27, 29);
UndertaleTexturePageItem pg_zbutton_p = AddNewTexturePageItem(104, 31, 27, 29);
UndertaleTexturePageItem pg_xbutton = AddNewTexturePageItem(133, 0, 27, 29);
UndertaleTexturePageItem pg_xbutton_p = AddNewTexturePageItem(133, 31, 27, 29);
UndertaleTexturePageItem pg_cbutton = AddNewTexturePageItem(162, 0, 27, 29);
UndertaleTexturePageItem pg_cbutton_p = AddNewTexturePageItem(162, 31, 27, 29);
UndertaleTexturePageItem pg_controls_config = AddNewTexturePageItem(61, 68, 100, 13);
UndertaleTexturePageItem pg_button_scale = AddNewTexturePageItem(61, 83, 79, 9);
UndertaleTexturePageItem pg_analog_scale = AddNewTexturePageItem(61, 94, 79, 12);
UndertaleTexturePageItem pg_analog_type = AddNewTexturePageItem(61, 108, 72, 12);
UndertaleTexturePageItem pg_reset_config = AddNewTexturePageItem(61, 122, 79, 12);
UndertaleTexturePageItem pg_controls_opacity = AddNewTexturePageItem(61, 136, 107, 13);
UndertaleTexturePageItem pg_arrow_leftright = AddNewTexturePageItem(142, 83, 41, 9);
UndertaleTexturePageItem pg_black = AddNewTexturePageItem(189, 0, 640, 480);

void AddNewUndertaleSprite(string spriteName, ushort width, ushort height, UndertaleTexturePageItem[] spriteTextures)
{
var name = Data.Strings.MakeString(spriteName);
ushort marginLeft = 0;
int marginRight = width - 1;
ushort marginTop = 0;
int marginBottom = height - 1;

var sItem = new UndertaleSprite { Name = name, Width = width, Height = height, MarginLeft = marginLeft, MarginRight = marginRight, MarginTop = marginTop, MarginBottom = marginBottom };
foreach (var spriteTexture in spriteTextures) {
sItem.Textures.Add(new UndertaleSprite.TextureEntry() { Texture = spriteTexture });
};
Data.Sprites.Add(sItem);
}

AddNewUndertaleSprite("spr_joybase", 59, 59, new UndertaleTexturePageItem[] {pg_joybase1, pg_joybase2});
AddNewUndertaleSprite("spr_joystick", 42, 42, new UndertaleTexturePageItem[] {pg_joystick, pg_joystick2});
AddNewUndertaleSprite("spr_z_button", 27, 29, new UndertaleTexturePageItem[] {pg_zbutton, pg_zbutton_p});
AddNewUndertaleSprite("spr_x_button", 27, 29, new UndertaleTexturePageItem[] {pg_xbutton, pg_xbutton_p});
AddNewUndertaleSprite("spr_c_button", 27, 29, new UndertaleTexturePageItem[] {pg_cbutton, pg_cbutton_p});
AddNewUndertaleSprite("spr_settings", 19, 24, new UndertaleTexturePageItem[] {pg_settings_n, pg_settings_p});
AddNewUndertaleSprite("spr_controls_config", 100, 13, new UndertaleTexturePageItem[] {pg_controls_config});
AddNewUndertaleSprite("spr_button_scale", 79, 9, new UndertaleTexturePageItem[] {pg_button_scale});
AddNewUndertaleSprite("spr_analog_scale", 79, 12, new UndertaleTexturePageItem[] {pg_analog_scale});
AddNewUndertaleSprite("spr_analog_type", 72, 12, new UndertaleTexturePageItem[] {pg_analog_type});
AddNewUndertaleSprite("spr_reset_config", 79, 12, new UndertaleTexturePageItem[] {pg_reset_config});
AddNewUndertaleSprite("spr_controls_opacity", 107, 13, new UndertaleTexturePageItem[] {pg_controls_opacity});
AddNewUndertaleSprite("spr_arrow_leftright", 41, 9, new UndertaleTexturePageItem[] {pg_arrow_leftright});
AddNewUndertaleSprite("spr_black", 640, 480, new UndertaleTexturePageItem[] {pg_black});

ImportGMLFile(Path.Combine(dataPath, "gml_Object_obj_mobilecontrols_Create_0.gml"), true, false, true);
ImportGMLFile(Path.Combine(dataPath, "gml_Object_obj_mobilecontrols_Draw_64.gml"), true, false, true);
ImportGMLFile(Path.Combine(dataPath, "gml_Object_obj_mobilecontrols_Other_4.gml"), true, false, true);
Data.Scripts.Add(new UndertaleScript() { Name = Data.Strings.MakeString("scr_add_keys"), Code = Data.Code.ByName("gml_Object_obj_mobilecontrols_Other_4") });
ImportGMLFile(Path.Combine(dataPath, "gml_Object_obj_mobilecontrols_Step_0.gml"), true, false, true);

var mobileControls = Data.GameObjects.ByName("obj_mobilecontrols");
mobileControls.Persistent = true;

if (displayName == "deltarune chapter 1 & 2" || displayName == "deltarune chapter 1&2")
{
Data.Code.ByName("gml_Object_obj_gamecontroller_Create_0").AppendGML("instance_create(0, 0, obj_mobilecontrols);", Data);
}
else if (displayName == "undertale")
{
Data.Code.ByName("gml_Object_obj_time_Create_0").AppendGML("instance_create(0, 0, obj_mobilecontrols);", Data);
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
if (string_lower(game_display_name) == "undertale")
{
settings_font = fnt_main
settings_num_x = 477
}
else
{
settings_font = fnt_mainbig
settings_num_x = 502
}
zx = 510
zy = 340
xx = 560
xy = 280
cx = 610
cy = 220
button_scale = 2.5
analog_scale = 3.3
analog_posx = -42
analog_posy = 232.5
analog_edit_selected = 0
analog_center_x = (analog_posx + (((59 * analog_scale) / 2) - ((41 * analog_scale) / 2)))
analog_center_y = (analog_posy + (((59 * analog_scale) / 2) - ((41 * analog_scale) / 2)))
arrowkeys_area_size = 19.675
arrowkeys_back_area_size = 45
joystick_type = 0
settingsx = 5
settingsy = 5
edit = 0
black_fade = 0
text_black_fade = 0
controls_opacity = 0.5
if file_exists("touchconfig.ini")
{
ini_open("touchconfig.ini")
zx = ini_read_real("CONFIG", "zx", zx)
zy = ini_read_real("CONFIG", "zy", zy)
xx = ini_read_real("CONFIG", "xx", xx)
xy = ini_read_real("CONFIG", "xy", xy)
cx = ini_read_real("CONFIG", "cx", cx)
cy = ini_read_real("CONFIG", "cy", cy)
analog_posx = ini_read_real("CONFIG", "analog_posx", analog_posx)
analog_posy = ini_read_real("CONFIG", "analog_posy", analog_posy)
button_scale = ini_read_real("CONFIG", "button_scale", button_scale)
analog_scale = ini_read_real("CONFIG", "analog_scale", analog_scale)
joystick_type = ini_read_real("CONFIG", "joystick_type", joystick_type)
controls_opacity = ini_read_real("CONFIG", "controls_opacity", controls_opacity)
ini_close()
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
draw_sprite_ext(spr_black, 0, 0, 0, 1, 1, 0, c_white, black_fade)
draw_set_font(settings_font)
draw_sprite_ext(spr_controls_config, 0, 220, 22.5, 2, 2, 0, c_white, text_black_fade)
draw_sprite_ext(spr_button_scale, 0, 120.5, 75, 2, 2, 0, c_white, text_black_fade)
draw_sprite_ext(spr_arrow_leftright, 0, 459.5, 75, 2, 2, 0, c_white, text_black_fade)
draw_sprite_ext(spr_analog_scale, 0, 120.5, 121, 2, 2, 0, c_white, text_black_fade)
draw_sprite_ext(spr_arrow_leftright, 0, 459.5, 121, 2, 2, 0, c_white, text_black_fade)
draw_sprite_ext(spr_analog_type, 0, 124, 167, 2, 2, 0, c_white, text_black_fade)
draw_sprite_ext(spr_arrow_leftright, 0, 459.5, 167, 2, 2, 0, c_white, text_black_fade)
draw_sprite_ext(spr_controls_opacity, 0, 106.5, 213, 2, 2, 0, c_white, text_black_fade)
draw_sprite_ext(spr_arrow_leftright, 0, 459.5, 213, 2, 2, 0, c_white, text_black_fade)
draw_sprite_ext(spr_reset_config, 0, 241, 412.25, 2, 2, 0, c_white, text_black_fade)
draw_text_colour(settings_num_x, 67, button_scale, c_white, c_white, c_white, c_white, text_black_fade)
draw_text_colour(settings_num_x, 113, analog_scale, c_white, c_white, c_white, c_white, text_black_fade)
draw_text_colour(settings_num_x, 159, joystick_type, c_white, c_white, c_white, c_white, text_black_fade)
draw_text_colour(settings_num_x, 205, controls_opacity, c_white, c_white, c_white, c_white, text_black_fade)
draw_sprite_ext(spr_z_button, keyboard_check(ord("Z")), zx, zy, button_scale, button_scale, 0, c_white, controls_opacity)
draw_sprite_ext(spr_x_button, keyboard_check(ord("X")), xx, xy, button_scale, button_scale, 0, c_white, controls_opacity)
draw_sprite_ext(spr_c_button, keyboard_check(ord("C")), cx, cy, button_scale, button_scale, 0, c_white, controls_opacity)
draw_sprite_ext(spr_joybase, joystick_type, analog_posx, analog_posy, analog_scale, analog_scale, 0, c_white, controls_opacity)
draw_sprite_ext(spr_joystick, joystick_type, analog_center_x, analog_center_y, analog_scale, analog_scale, 0, c_white, controls_opacity)
draw_sprite_ext(spr_settings, keyboard_check(92), settingsx, settingsy, button_scale, button_scale, 0, c_white, controls_opacity)
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
virtual_key_zp = virtual_key_add(zx, zy, (27 * button_scale), (29 * button_scale), 125)
virtual_key_xp = virtual_key_add(xx, xy, (27 * button_scale), (29 * button_scale), 124)
virtual_key_cp = virtual_key_add(cx, cy, (27 * button_scale), (29 * button_scale), 94)
virtual_key_analogp = virtual_key_add(analog_posx, analog_posy, (59 * analog_scale), (59 * analog_scale), 93)
virtual_key_settings = virtual_key_add(settingsx, settingsy, (19 * button_scale), (25 * button_scale), 92)

if (edit != 0) return;

virtual_key_z = virtual_key_add(zx, zy, (27 * button_scale), (29 * button_scale), 90)
virtual_key_x = virtual_key_add(xx, xy, (27 * button_scale), (29 * button_scale), 88)
virtual_key_c = virtual_key_add(cx, cy, (27 * button_scale), (29 * button_scale), 67)
virtual_key_up = virtual_key_add((analog_posx - (arrowkeys_back_area_size * analog_scale)), (analog_posy - (arrowkeys_back_area_size * analog_scale)), ((arrowkeys_back_area_size * analog_scale) + ((59 * analog_scale) + (arrowkeys_back_area_size * analog_scale))), ((arrowkeys_area_size * analog_scale) + (arrowkeys_back_area_size * analog_scale)), 38)
virtual_key_right = virtual_key_add(((analog_posx + (59 * analog_scale)) - (arrowkeys_area_size * analog_scale)), (analog_posy - (arrowkeys_back_area_size * analog_scale)), ((arrowkeys_area_size * analog_scale) + (arrowkeys_back_area_size * analog_scale)), (((arrowkeys_back_area_size * analog_scale) + (59 * analog_scale)) + (arrowkeys_back_area_size * analog_scale)), 39)
virtual_key_left = virtual_key_add((analog_posx - (arrowkeys_back_area_size * analog_scale)), (analog_posy - (arrowkeys_back_area_size * analog_scale)), ((arrowkeys_area_size * analog_scale) + (arrowkeys_back_area_size * analog_scale)), ((arrowkeys_back_area_size * analog_scale) + ((59 * analog_scale) + (arrowkeys_back_area_size * analog_scale))), 37)
virtual_key_down = virtual_key_add((analog_posx - (arrowkeys_back_area_size * analog_scale)), ((analog_posy + (59 * analog_scale)) - (arrowkeys_area_size * analog_scale)), (((arrowkeys_back_area_size * analog_scale) + (59 * analog_scale)) + (arrowkeys_back_area_size * analog_scale)), ((arrowkeys_area_size * analog_scale) + (arrowkeys_back_area_size * analog_scale)), 40)
virtual_key_analog = virtual_key_add((analog_posx - (arrowkeys_back_area_size * analog_scale)), (analog_posy - (arrowkeys_back_area_size * analog_scale)), (((59 + arrowkeys_back_area_size) * analog_scale) + (arrowkeys_back_area_size * analog_scale)), (((59 + arrowkeys_back_area_size) * analog_scale) + (arrowkeys_back_area_size * analog_scale)), 126)
Loading

0 comments on commit 979db25

Please sign in to comment.