Skip to content

Commit

Permalink
Automatic gettext resolving for Deltarune, closes #39
Browse files Browse the repository at this point in the history
  • Loading branch information
krzys-h committed Nov 11, 2018
1 parent 71f63c7 commit 43e5945
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 9 deletions.
2 changes: 2 additions & 0 deletions UndertaleModLib/Decompiler/AssetTypeResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,8 @@ internal class AssetTypeResolver
{ "draw_vertex_colour", new AssetIDType[] { AssetIDType.Other, AssetIDType.Other, AssetIDType.Color, AssetIDType.Other } },
{ "draw_vertex_texture_colour", new AssetIDType[] { AssetIDType.Other, AssetIDType.Other, AssetIDType.Other, AssetIDType.Other, AssetIDType.Color, AssetIDType.Other } },

{ "distance_to_object", new AssetIDType[] { AssetIDType.GameObject } },

// TODO: 3D drawing, didn't bother

// TODO: surface drawing
Expand Down
44 changes: 44 additions & 0 deletions UndertaleModTool/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,48 @@
<add key="graphVizLocation" value=".\graphviz\bin" />
<add key="GameMakerStudioPath" value="%appdata%\GameMaker-Studio" />
</appSettings>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.IO.FileSystem" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.3.0" newVersion="4.0.3.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Security.Cryptography.Algorithms" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.3.0.0" newVersion="4.3.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.ValueTuple" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.2.0" newVersion="4.0.2.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Security.Cryptography.Primitives" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.2.0" newVersion="4.0.2.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.IO.FileSystem.Primitives" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.3.0" newVersion="4.0.3.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Xml.ReaderWriter" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.1.1.0" newVersion="4.1.1.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.IO.Compression" publicKeyToken="b77a5c561934e089" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.2.0.0" newVersion="4.2.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Xml.XPath.XDocument" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.1.0.0" newVersion="4.1.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Console" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.2.0" newVersion="4.0.2.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Diagnostics.StackTrace" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.1.0.0" newVersion="4.1.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
41 changes: 32 additions & 9 deletions UndertaleModTool/Editors/UndertaleCodeEditor.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
using GraphVizWrapper;
using GraphVizWrapper.Commands;
using GraphVizWrapper.Queries;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
Expand Down Expand Up @@ -217,6 +219,12 @@ private void UpdateGettext(UndertaleCode gettextCode)
}
}

private static Dictionary<string, string> gettextJSON = null;
private void UpdateGettextJSON(string json)
{
gettextJSON = JsonConvert.DeserializeObject<Dictionary<string, string>>(json);
}

private async void DecompileCode(UndertaleCode code)
{
LoaderDialog dialog = new LoaderDialog("Decompiling", "Decompiling, please wait... This can take a while on complex scripts");
Expand All @@ -231,6 +239,8 @@ private async void DecompileCode(UndertaleCode code)
if (gettext == null)
gettextCode = (Application.Current.MainWindow as MainWindow).Data.Code.ByName("gml_Script_textdata_en");

string gettextJsonPath = System.IO.Path.Combine(System.IO.Path.GetDirectoryName((Application.Current.MainWindow as MainWindow).FilePath), "lang/lang_en.json");

var dataa = (Application.Current.MainWindow as MainWindow).Data;
Task t = Task.Run(() =>
{
Expand All @@ -248,6 +258,9 @@ private async void DecompileCode(UndertaleCode code)
if (gettextCode != null)
UpdateGettext(gettextCode);

if (gettextJSON == null)
UpdateGettextJSON(File.ReadAllText(gettextJsonPath));

Dispatcher.Invoke(() =>
{
if (e != null)
Expand Down Expand Up @@ -313,7 +326,7 @@ private async void DecompileCode(UndertaleCode code)
if (tok != "")
split.Add(tok);

Dictionary<string, UndertaleObject> usedObjects = new Dictionary<string, UndertaleObject>();
Dictionary<string, object> usedObjects = new Dictionary<string, object>();
for (int i = 0; i < split.Count; i++)
{
string token = split[i];
Expand All @@ -338,20 +351,29 @@ private async void DecompileCode(UndertaleCode code)
{
par.Inlines.Add(new Run(token) { Foreground = assetBrush, Cursor = Cursors.Hand });
par.Inlines.LastInline.MouseDown += (sender, ev) => (Application.Current.MainWindow as MainWindow).ChangeSelection(dataa.ByName(token));
}
else if (funcs.ContainsKey(token))
{
par.Inlines.Add(new Run(token) { Foreground = funcBrush, Cursor = Cursors.Hand });
par.Inlines.LastInline.MouseDown += (sender, ev) => (Application.Current.MainWindow as MainWindow).ChangeSelection(funcs[token]);
if (token == "scr_gettext" && gettext != null)
{
if (split[i + 1] == "(" && split[i + 2].StartsWith("\"") && split[i + 3].StartsWith("@") && split[i + 4] == ")")
{
string id = split[i + 2].Substring(1, split[i + 2].Length - 2);
if(!usedObjects.ContainsKey(id))
if (!usedObjects.ContainsKey(id))
usedObjects.Add(id, (Application.Current.MainWindow as MainWindow).Data.Strings[gettext[id]]);
}
}
if (token == "scr_84_get_lang_string" && gettextJSON != null)
{
if (split[i + 1] == "(" && split[i + 2].StartsWith("\"") && split[i + 3].StartsWith("@") && split[i + 4] == ")")
{
string id = split[i + 2].Substring(1, split[i + 2].Length - 2);
if (!usedObjects.ContainsKey(id))
usedObjects.Add(id, gettextJSON[id]);
}
}
}
else if (funcs.ContainsKey(token))
{
par.Inlines.Add(new Run(token) { Foreground = funcBrush, Cursor = Cursors.Hand });
par.Inlines.LastInline.MouseDown += (sender, ev) => (Application.Current.MainWindow as MainWindow).ChangeSelection(funcs[token]);
}
else if (Char.IsDigit(token[0]))
{
Expand Down Expand Up @@ -423,8 +445,9 @@ private async void DecompileCode(UndertaleCode code)
par.Inlines.Add(new Run(" // ") { Foreground = commentBrush });
par.Inlines.Add(new Run(gt.Key) { Foreground = commentBrush });
par.Inlines.Add(new Run(" = ") { Foreground = commentBrush });
par.Inlines.Add(new Run(gt.Value.ToString()) { Foreground = commentBrush, Cursor = Cursors.Hand });
par.Inlines.LastInline.MouseDown += (sender, ev) => (Application.Current.MainWindow as MainWindow).ChangeSelection(gt.Value);
par.Inlines.Add(new Run(gt.Value is string ? "\"" + (string)gt.Value + "\"" : gt.Value.ToString()) { Foreground = commentBrush, Cursor = Cursors.Hand });
if (gt.Value is UndertaleObject)
par.Inlines.LastInline.MouseDown += (sender, ev) => (Application.Current.MainWindow as MainWindow).ChangeSelection(gt.Value);
}
par.Inlines.Add(new Run("\n"));
}
Expand Down
3 changes: 3 additions & 0 deletions UndertaleModTool/UndertaleModTool.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@
<Reference Include="Microsoft.WindowsAPICodePack.Shell, Version=1.1.3.3, Culture=neutral, PublicKeyToken=8985beaab7ea3f04, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft-WindowsAPICodePack-Shell.1.1.3.3\lib\net452\Microsoft.WindowsAPICodePack.Shell.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json, Version=11.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.11.0.2\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.AppContext, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\System.AppContext.4.3.0\lib\net46\System.AppContext.dll</HintPath>
Expand Down
1 change: 1 addition & 0 deletions UndertaleModTool/packages.config
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<package id="Microsoft.CodeAnalysis.Scripting.Common" version="2.9.0" targetFramework="net461" />
<package id="Microsoft-WindowsAPICodePack-Core" version="1.1.3.3" targetFramework="net461" />
<package id="Microsoft-WindowsAPICodePack-Shell" version="1.1.3.3" targetFramework="net461" />
<package id="Newtonsoft.Json" version="11.0.2" targetFramework="net461" />
<package id="System.AppContext" version="4.3.0" targetFramework="net461" />
<package id="System.Collections" version="4.3.0" targetFramework="net461" />
<package id="System.Collections.Concurrent" version="4.3.0" targetFramework="net461" />
Expand Down

0 comments on commit 43e5945

Please sign in to comment.