Skip to content

Commit

Permalink
added support for shader/external sounds
Browse files Browse the repository at this point in the history
  • Loading branch information
burnedpopcorn committed Dec 13, 2024
1 parent 6694d8b commit 4643e2c
Show file tree
Hide file tree
Showing 4 changed files with 904 additions and 3 deletions.
41 changes: 39 additions & 2 deletions Export2GMS1FIXED/Export2GMS1FIXED_UA.csx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
- Script now uses UnderAnalyzer instead of UTMT
Export2GMS1FIXED Changes:
- (NEW) Added support for decompiling Shaders
- Fixed Script being unable to further Decompile the project if a single script/object failed to
- Script now asks if User wants to delete old decompilation project and continue if a previous attempt to decompile was detected
- Added ability to log scripts and objects that failed to decompile to a text file
Expand Down Expand Up @@ -61,7 +63,7 @@ int progress = 0;
string projFolder = GetFolder(FilePath) + GameName + ".gmx" + Path.DirectorySeparatorChar;
TextureWorker worker = new TextureWorker();
string gmxDeclaration = "This Document is generated by GameMaker, if you edit it by hand then you do so at your own risk!";
string eol = "\n"; // Linux: "\n", Windows: "\r\n"
string eol = "\n"; // Linux: "\n", Windows: "\r\n";

// UnderAnalyzer Variable Definitions
GlobalDecompileContext decompileContext = new(Data);
Expand Down Expand Up @@ -102,7 +104,8 @@ var resourceNum = Data.Sprites.Count +
Data.Scripts.Count +
Data.Fonts.Count +
Data.Paths.Count +
Data.Timelines.Count;
Data.Timelines.Count +
Data.Shaders.Count; // new one

// Export sprites
await ExportSprites();
Expand Down Expand Up @@ -131,6 +134,9 @@ await ExportPaths();
// Export timelines
await ExportTimelines();

// (NEW) Export shaders
await ExportShaders();

// Generate project file
GenerateProjectFile();

Expand Down Expand Up @@ -602,6 +608,9 @@ void ExportSound(UndertaleSound sound)
// Save sound files
if (sound.AudioFile != null)
File.WriteAllBytes(projFolder + "/sound/audio/" + sound.File.Content, sound.AudioFile.Data);
// if sound file is external, add them
else if (File.Exists($"{Path.GetDirectoryName(FilePath)}\\" + sound.File.Content))
File.Copy($"{Path.GetDirectoryName(FilePath)}\\" + sound.File.Content, projFolder + "/sound/audio/" + sound.File.Content, true);
}

// --------------- Export Script ---------------
Expand Down Expand Up @@ -765,6 +774,32 @@ void ExportTimeline(UndertaleTimeline timeline)
File.WriteAllText(projFolder + "/timelines/" + timeline.Name.Content + ".timeline.gmx", gmx.ToString() + eol);
}

// --------------- Export Shaders ---------------
async Task ExportShaders()
{
Directory.CreateDirectory(projFolder + "/shaders");
await Task.Run(() => Parallel.ForEach(Data.Shaders, ExportShader));
}
void ExportShader(UndertaleShader shader)
{
// Vertex and Fragment shit
var vertex = shader.GLSL_ES_Vertex.Content;
var fragment = shader.GLSL_ES_Fragment.Content;

// to avoid declaring useless shit
if (vertex != null && fragment != null)
{
string splitter = "#define _YY_GLSLES_ 1\n";
if (vertex.Contains(splitter))
vertex = vertex.Substring(vertex.IndexOf(splitter) + splitter.Length);
if (fragment.Contains(splitter))
fragment = fragment.Substring(fragment.IndexOf(splitter) + splitter.Length);
}

UpdateProgressBar(null, $"Exporting Script: {shader.Name.Content}", progress++, resourceNum);
File.WriteAllText(projFolder + "/shaders/" + shader.Name.Content + ".shader", vertex + "\n//######################_==_YOYO_SHADER_MARKER_==_######################@~//\n" + fragment);
}


// --------------- Generate project file ---------------
void GenerateProjectFile()
Expand All @@ -786,6 +821,8 @@ void GenerateProjectFile()
WriteIndexes<UndertaleRoom>(gmx.Element("assets"), "rooms", "rooms", Data.Rooms, "room", "rooms\\");
WriteIndexes<UndertalePath>(gmx.Element("assets"), "paths", "paths", Data.Paths, "path", "paths\\");
WriteIndexes<UndertaleTimeline>(gmx.Element("assets"), "timelines", "timelines", Data.Timelines, "timeline", "timelines\\");
// for shader support
WriteIndexes<UndertaleShader>(gmx.Element("assets"), "shaders", "shaders", Data.Shaders, "shader", "shaders\\", ".shader");

File.WriteAllText(projFolder + GameName + ".project.gmx", gmx.ToString() + eol);
}
Expand Down
38 changes: 37 additions & 1 deletion Export2GMS1FIXED/Export2GMS1FIXED_UTMT.csx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
Original Fixed Version by CST1229
Export2GMS1FIXED Changes:
- (NEW) Added support for decompiling Shaders
- Fixed Script being unable to further Decompile the project if a single script/object failed to
- Script now asks if User wants to delete old decompilation project and continue if a previous attempt to decompile was detected
- Added ability to log scripts and objects that failed to decompile to a text file
Expand Down Expand Up @@ -87,7 +89,8 @@ var resourceNum = Data.Sprites.Count +
Data.Scripts.Count +
Data.Fonts.Count +
Data.Paths.Count +
Data.Timelines.Count;
Data.Timelines.Count +
Data.Shaders.Count; // new one

// Export sprites
await ExportSprites();
Expand Down Expand Up @@ -116,6 +119,9 @@ await ExportPaths();
// Export timelines
await ExportTimelines();

// (NEW) Export shaders
await ExportShaders();

// Generate project file
GenerateProjectFile();

Expand Down Expand Up @@ -587,6 +593,9 @@ void ExportSound(UndertaleSound sound)
// Save sound files
if (sound.AudioFile != null)
File.WriteAllBytes(projFolder + "/sound/audio/" + sound.File.Content, sound.AudioFile.Data);
// if sound file is external, add them
else if (File.Exists($"{Path.GetDirectoryName(FilePath)}\\" + sound.File.Content))
File.Copy($"{Path.GetDirectoryName(FilePath)}\\" + sound.File.Content, projFolder + "/sound/audio/" + sound.File.Content, true);
}

// --------------- Export Script ---------------
Expand Down Expand Up @@ -750,6 +759,31 @@ void ExportTimeline(UndertaleTimeline timeline)
File.WriteAllText(projFolder + "/timelines/" + timeline.Name.Content + ".timeline.gmx", gmx.ToString() + eol);
}

// --------------- Export Shaders ---------------
async Task ExportShaders()
{
Directory.CreateDirectory(projFolder + "/shaders");
await Task.Run(() => Parallel.ForEach(Data.Shaders, ExportShader));
}
void ExportShader(UndertaleShader shader)
{
// Vertex and Fragment shit
var vertex = shader.GLSL_ES_Vertex.Content;
var fragment = shader.GLSL_ES_Fragment.Content;

// to avoid declaring useless shit
if (vertex != null && fragment != null)
{
string splitter = "#define _YY_GLSLES_ 1\n";
if (vertex.Contains(splitter))
vertex = vertex.Substring(vertex.IndexOf(splitter) + splitter.Length);
if (fragment.Contains(splitter))
fragment = fragment.Substring(fragment.IndexOf(splitter) + splitter.Length);
}

UpdateProgressBar(null, $"Exporting Script: {shader.Name.Content}", progress++, resourceNum);
File.WriteAllText(projFolder + "/shaders/" + shader.Name.Content + ".shader", vertex + "\n//######################_==_YOYO_SHADER_MARKER_==_######################@~//\n" + fragment);
}

// --------------- Generate project file ---------------
void GenerateProjectFile()
Expand All @@ -771,6 +805,8 @@ void GenerateProjectFile()
WriteIndexes<UndertaleRoom>(gmx.Element("assets"), "rooms", "rooms", Data.Rooms, "room", "rooms\\");
WriteIndexes<UndertalePath>(gmx.Element("assets"), "paths", "paths", Data.Paths, "path", "paths\\");
WriteIndexes<UndertaleTimeline>(gmx.Element("assets"), "timelines", "timelines", Data.Timelines, "timeline", "timelines\\");
// for shader support
WriteIndexes<UndertaleShader>(gmx.Element("assets"), "shaders", "shaders", Data.Shaders, "shader", "shaders\\", ".shader");

File.WriteAllText(projFolder + GameName + ".project.gmx", gmx.ToString() + eol);
}
Expand Down
Loading

0 comments on commit 4643e2c

Please sign in to comment.