Skip to content

Instantly share code, notes, and snippets.

@DatZach
Last active September 2, 2020 14:48
Show Gist options
  • Save DatZach/23d71b1508040aef14d506ccdd93f907 to your computer and use it in GitHub Desktop.
Save DatZach/23d71b1508040aef14d506ccdd93f907 to your computer and use it in GitHub Desktop.
/// @function launch_instance()
/// @description Launches another instance of the game, detatching the debugging from the second if needed
/// @author DatZach, Nommiin
// NOTE Requires this extension:
// https://marketplace.yoyogames.com/assets/575/execute-shell
var _dataPath = "";
for(var i = 1; i < parameter_count(); i++) {
var _paramString = parameter_string(i);
if (filename_ext(_paramString) == ".win")
_dataPath = _paramString;
else if (_paramString == "--launch-guard")
return;
}
if (debug_mode == true) {
var _gamePath = environment_get_variable("localappdata") + "\\" + string_replace_all(game_project_name, " ", "_") + "\\";
if (!directory_exists(_gamePath))
directory_create(_gamePath);
_gamePath += "data.win";
file_delete(_gamePath);
file_copy(_dataPath, _gamePath);
var _dataBuffer = buffer_load(_gamePath);
buffer_seek(_dataBuffer, buffer_seek_start, 8);
while (buffer_tell(_dataBuffer) < buffer_get_size(_dataBuffer)) {
var _chunkName = buffer_read(_dataBuffer, buffer_u32);
var _chunkSize = buffer_read(_dataBuffer, buffer_s32);
if (_chunkName == 944653639) { // GEN8
buffer_poke(_dataBuffer, buffer_tell(_dataBuffer), buffer_u32, 0x11111111);
break;
}
buffer_seek(_dataBuffer, buffer_seek_relative, _chunkSize);
}
buffer_save(_dataBuffer, _gamePath);
buffer_delete(_dataBuffer);
}
// Launch the game
var _argString = "";
for(var i = 1; i < parameter_count(); i++) {
var _paramString = parameter_string(i);
if (_paramString == "-game") {
_argString += "-game \"";
_argString += debug_mode ? _gamePath : parameter_string(i + 1);
_argString += "\" ";
i++;
continue;
}
_argString += _paramString;
_argString += " ";
}
_argString += "--launch-guard";
execute_shell(parameter_string(0) + " " + _argString, false);
//shell_execute(parameter_string(0), _argString);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment