Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace GML decompiler with Underanalyzer #1862

Open
wants to merge 44 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
0f151b3
Initial port of Underanalyzer from fork
colinator27 Jul 11, 2024
2bc80f9
Remove old decompiler from codebase
colinator27 Jul 13, 2024
8218e55
Update CLI project for new decompiler
colinator27 Jul 13, 2024
3be4855
Remove builtin code correction files
colinator27 Jul 13, 2024
5273349
Merge remote-tracking branch 'origin/master' into underanalyzer
colinator27 Jul 14, 2024
dcd2a1a
Small merge fix
colinator27 Jul 14, 2024
6395ad7
Add README to corrections folder, to prevent error
colinator27 Jul 14, 2024
57cba9b
Initial pass on updating scripts, and some fixes
colinator27 Jul 19, 2024
a46f44f
Merge remote-tracking branch 'origin/master' into underanalyzer
colinator27 Jul 19, 2024
52adfe2
Update builtin macro resolutions
colinator27 Jul 20, 2024
0c4269a
Update UndertaleWithJSONs to use AST
colinator27 Jul 20, 2024
220c81b
Second pass on upgrading scripts
colinator27 Jul 20, 2024
5e69bf0
Fix missing parentheses
colinator27 Jul 20, 2024
361aec3
Implement named instance IDs, update highlighting
colinator27 Jul 21, 2024
7a72203
Remove old comments from disassembly
colinator27 Jul 21, 2024
59d958c
Merge remote-tracking branch 'origin/master' into underanalyzer
colinator27 Jul 21, 2024
04bcd7e
Add two networking constant types
colinator27 Jul 23, 2024
e6384ad
Implement GML (de)compiler settings window
colinator27 Jul 23, 2024
ae1c74e
Cleanup, fix instance ID prefix not being instant
colinator27 Jul 23, 2024
05786fd
Merge remote-tracking branch 'origin/master' into underanalyzer
colinator27 Jul 23, 2024
9cf9f1a
Fix decompiler settings resetting after downgrade
colinator27 Jul 24, 2024
0f1dd48
Update Underanalyzer
colinator27 Jul 24, 2024
5ee564c
Fix room instance ID variables, and code clean up
colinator27 Jul 24, 2024
07317f4
Add "persistent" to builtin JSON
colinator27 Jul 25, 2024
24aca34
Small additions to builtin types
colinator27 Jul 27, 2024
3a63da0
Merge remote-tracking branch 'origin/master' into underanalyzer
colinator27 Jul 27, 2024
3d305dc
Merge remote-tracking branch 'origin/master' into underanalyzer
colinator27 Jul 29, 2024
298514a
Externalize game-specific data
colinator27 Aug 4, 2024
557d4ae
Better handle base directory in game-specific data
colinator27 Aug 4, 2024
6d5ec52
Merge remote-tracking branch 'origin/master' into underanalyzer
colinator27 Aug 9, 2024
834b4ea
Add some comments to AssetReferenceTypes
colinator27 Aug 12, 2024
41fbb43
Merge remote-tracking branch 'origin/master' into underanalyzer
colinator27 Aug 12, 2024
caa6cc8
Update Underanalyzer
colinator27 Aug 12, 2024
939e4d8
Attempt workflow fix for GameSpecificData
colinator27 Aug 12, 2024
390de70
Fix #1863
colinator27 Aug 12, 2024
8c5462c
Fix ExportAllCode
colinator27 Aug 15, 2024
34c0dec
remove struct keyword
ChronoVortex Sep 18, 2024
8377c5a
Merge pull request #1919 from ChronoVortex/struct-fix
Miepee Oct 6, 2024
49b3ada
Merge branch 'master' into underanalyzer
colinator27 Nov 23, 2024
9c178ee
Merge branch 'master' into underanalyzer
colinator27 Nov 25, 2024
989a173
Update UA to add local var declaration cleanup
colinator27 Dec 1, 2024
282ecca
Merge branch 'master' into underanalyzer
colinator27 Dec 1, 2024
1c286c4
Update Underanalyzer
colinator27 Dec 2, 2024
73230b7
Merge branch 'master' into underanalyzer
colinator27 Dec 2, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
1 change: 1 addition & 0 deletions .github/workflows/publish_cli.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ jobs:
run: |
cp ./README.md ./CLI-${{ matrix.os }}/
cp ./LICENSE.txt ./CLI-${{ matrix.os }}/
cp -r ./UndertaleModLib/GameSpecificData/ ./CLI-${{ matrix.os }}/GameSpecificData/
- name: Upload ${{ matrix.os }} CLI
uses: actions/upload-artifact@v4
with:
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/publish_gui.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ jobs:
cp ./README.md ./${{ matrix.os }}
cp ./SCRIPTS.md ./${{ matrix.os }}
cp ./LICENSE.txt ./${{ matrix.os }}
cp -r ./UndertaleModLib/GameSpecificData/ ./${{ matrix.os }}/GameSpecificData/
- name: Upload ${{ matrix.os }} GUI
uses: actions/upload-artifact@v4
with:
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/publish_gui_nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ jobs:
cp ./README.md ./${{ matrix.os }}
cp ./SCRIPTS.md ./${{ matrix.os }}
cp ./LICENSE.txt ./${{ matrix.os }}
cp -r ./UndertaleModLib/GameSpecificData/ ./${{ matrix.os }}/GameSpecificData/
- name: Create zip for nightly release Windows GUI
run: |
7z a -tzip GUI-${{ matrix.os }}-${{ matrix.configuration }}-isBundled-${{ matrix.bundled }}-isSingleFile-${{ matrix.singlefile }}.zip ./${{ matrix.os }}/* -mx0
Expand Down Expand Up @@ -90,6 +91,7 @@ jobs:
run: |
cp ./README.md ./CLI-${{ matrix.os }}/
cp ./LICENSE.txt ./CLI-${{ matrix.os }}/
cp -r ./UndertaleModLib/GameSpecificData/ ./CLI-${{ matrix.os }}/GameSpecificData/
- name: Create zip for nightly release CLI
run: |
7z a -tzip CLI-${{ matrix.os }}-${{ matrix.configuration }}-isBundled-${{ matrix.bundled }}.zip ./CLI-${{ matrix.os }}/* -mx0
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/publish_gui_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ jobs:
cp ./README.md ./${{ matrix.os }}
cp ./SCRIPTS.md ./${{ matrix.os }}
cp ./LICENSE.txt ./${{ matrix.os }}
cp -r ./UndertaleModLib/GameSpecificData/ ./${{ matrix.os }}/GameSpecificData/
- name: Create zip for stable release Windows GUI
run: |
7z a -tzip GUI-${{ matrix.os }}-${{ matrix.configuration }}-isBundled-${{ matrix.bundled }}-isSingleFile-${{ matrix.singlefile }}.zip ./${{ matrix.os }}/* -mx0
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/publish_pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ jobs:
cp ./README.md ./${{ matrix.os }}
cp ./SCRIPTS.md ./${{ matrix.os }}
cp ./LICENSE.txt ./${{ matrix.os }}
cp -r ./UndertaleModLib/GameSpecificData/ ./${{ matrix.os }}/GameSpecificData/
- name: Upload ${{ matrix.os }} GUI
uses: actions/upload-artifact@v4
with:
Expand Down Expand Up @@ -85,6 +86,7 @@ jobs:
run: |
cp ./README.md ./CLI-${{ matrix.os }}/
cp ./LICENSE.txt ./CLI-${{ matrix.os }}/
cp -r ./UndertaleModLib/GameSpecificData/ ./CLI-${{ matrix.os }}/GameSpecificData/
- name: Upload ${{ matrix.os }} CLI
uses: actions/upload-artifact@v4
with:
Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "Underanalyzer"]
path = Underanalyzer
url = https://github.com/UnderminersTeam/Underanalyzer.git
1 change: 1 addition & 0 deletions Underanalyzer
Submodule Underanalyzer added at 310642
25 changes: 14 additions & 11 deletions UndertaleModCli/Program.UMTLibInherited.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.CSharp.Scripting;
using Microsoft.CodeAnalysis.Scripting;
using Underanalyzer.Decompiler;
using UndertaleModLib;
using UndertaleModLib.Decompiler;
using UndertaleModLib.Models;
Expand Down Expand Up @@ -293,7 +294,7 @@ public void ReapplyProfileCode()
}

/// <inheritdoc/>
public async Task<bool> GenerateGMLCache(ThreadLocal<GlobalDecompileContext> decompileContext = null, object dialog = null, bool isSaving = false)
public async Task<bool> GenerateGMLCache(GlobalDecompileContext decompileContext = null, object dialog = null, bool isSaving = false)
{
await Task.Delay(1); //dummy await

Expand Down Expand Up @@ -410,21 +411,23 @@ public string PromptLoadFile(string defaultExt, string filter)
}

/// <inheritdoc/>
public string GetDecompiledText(string codeName, GlobalDecompileContext context = null)
public string GetDecompiledText(string codeName, GlobalDecompileContext context = null, IDecompileSettings settings = null)
{
return GetDecompiledText(Data.Code.ByName(codeName), context);
return GetDecompiledText(Data.Code.ByName(codeName), context, settings);
}

/// <inheritdoc/>
public string GetDecompiledText(UndertaleCode code, GlobalDecompileContext context = null)
public string GetDecompiledText(UndertaleCode code, GlobalDecompileContext context = null, IDecompileSettings settings = null)
{
if (code.ParentEntry is not null)
return $"// This code entry is a reference to an anonymous function within \"{code.ParentEntry.Name.Content}\", decompile that instead.";

GlobalDecompileContext decompileContext = context is null ? new(Data, false) : context;
GlobalDecompileContext decompileContext = context is null ? new(Data) : context;
try
{
return code != null ? Decompiler.Decompile(code, decompileContext) : "";
return code != null
? new Underanalyzer.Decompiler.DecompileContext(decompileContext, code, settings ?? Data.ToolInfo.DecompilerSettings).DecompileToString()
: "";
}
catch (Exception e)
{
Expand Down Expand Up @@ -633,17 +636,17 @@ public void ImportASMFile(string fileName, bool doParse = true, bool destroyASM
}

/// <inheritdoc/>
public void ReplaceTextInGML(string codeName, string keyword, string replacement, bool caseSensitive = false, bool isRegex = false, GlobalDecompileContext context = null)
public void ReplaceTextInGML(string codeName, string keyword, string replacement, bool caseSensitive = false, bool isRegex = false, GlobalDecompileContext context = null, IDecompileSettings settings = null)
{
UndertaleCode code = Data.Code.ByName(codeName);
if (code is null)
throw new ScriptException($"No code named \"{codeName}\" was found!");

ReplaceTextInGML(code, keyword, replacement, caseSensitive, isRegex, context);
ReplaceTextInGML(code, keyword, replacement, caseSensitive, isRegex, context, settings);
}

/// <inheritdoc/>
public void ReplaceTextInGML(UndertaleCode code, string keyword, string replacement, bool caseSensitive = false, bool isRegex = false, GlobalDecompileContext context = null)
public void ReplaceTextInGML(UndertaleCode code, string keyword, string replacement, bool caseSensitive = false, bool isRegex = false, GlobalDecompileContext context = null, IDecompileSettings settings = null)
{
if (code == null) throw new ArgumentNullException(nameof(code));
if (code.ParentEntry is not null)
Expand All @@ -652,7 +655,7 @@ public void ReplaceTextInGML(UndertaleCode code, string keyword, string replacem
EnsureDataLoaded();

string passBack = "";
GlobalDecompileContext decompileContext = context is null ? new(Data, false) : context;
GlobalDecompileContext decompileContext = context is null ? new(Data) : context;

if (!Data.ToolInfo.ProfileMode)
{
Expand All @@ -661,7 +664,7 @@ public void ReplaceTextInGML(UndertaleCode code, string keyword, string replacem
// It would just be recompiling an empty string and messing with null entries seems bad
if (code is null)
return;
string originalCode = Decompiler.Decompile(code, decompileContext);
string originalCode = new Underanalyzer.Decompiler.DecompileContext(decompileContext, code, settings ?? Data.ToolInfo.DecompilerSettings).DecompileToString();
passBack = GetPassBack(originalCode, keyword, replacement, caseSensitive, isRegex);
// No need to compile something unchanged
if (passBack == originalCode)
Expand Down
5 changes: 3 additions & 2 deletions UndertaleModCli/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,8 @@
typeof(JsonConvert).GetTypeInfo().Assembly,
typeof(System.Text.RegularExpressions.Regex).GetTypeInfo().Assembly,
typeof(TextureWorker).GetTypeInfo().Assembly,
typeof(ImageMagick.MagickImage).GetTypeInfo().Assembly)
typeof(ImageMagick.MagickImage).GetTypeInfo().Assembly,
typeof(Underanalyzer.Decompiler.DecompileContext).Assembly)
// "WithEmitDebugInformation(true)" not only lets us to see a script line number which threw an exception,
// but also provides other useful debug info when we run UMT in "Debug".
.WithEmitDebugInformation(true);
Expand Down Expand Up @@ -732,7 +733,7 @@
/// Evaluates and executes given C# code.
/// </summary>
/// <param name="code">The C# string to execute</param>
/// <param name="scriptFile">The path to the script file where <see cref="code"/> was executed from.

Check warning on line 736 in UndertaleModCli/Program.cs

View workflow job for this annotation

GitHub Actions / publish_cli (macOS-latest, Debug, false)

XML comment has cref attribute 'code' that could not be resolved

Check warning on line 736 in UndertaleModCli/Program.cs

View workflow job for this annotation

GitHub Actions / publish_cli (macOS-latest, Debug, false)

XML comment has cref attribute 'code' that could not be resolved

Check warning on line 736 in UndertaleModCli/Program.cs

View workflow job for this annotation

GitHub Actions / publish_cli (ubuntu-latest, Debug, false)

XML comment has cref attribute 'code' that could not be resolved

Check warning on line 736 in UndertaleModCli/Program.cs

View workflow job for this annotation

GitHub Actions / publish_cli (ubuntu-latest, Debug, false)

XML comment has cref attribute 'code' that could not be resolved

Check warning on line 736 in UndertaleModCli/Program.cs

View workflow job for this annotation

GitHub Actions / publish_cli (windows-latest, Debug, false)

XML comment has cref attribute 'code' that could not be resolved

Check warning on line 736 in UndertaleModCli/Program.cs

View workflow job for this annotation

GitHub Actions / publish_cli (windows-latest, Debug, false)

XML comment has cref attribute 'code' that could not be resolved
/// Leave as null, if it wasn't executed from a script file</param>
private void RunCSharpCode(string code, string scriptFile = null)
{
Expand Down Expand Up @@ -871,4 +872,4 @@
Thread.Sleep(100); //10 times per second
}
}
}
}
1 change: 1 addition & 0 deletions UndertaleModCli/UndertaleModCli.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Underanalyzer\Underanalyzer\Underanalyzer.csproj" />
<ProjectReference Include="..\UndertaleModLib\UndertaleModLib.csproj" />
</ItemGroup>

Expand Down
Loading
Loading