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

Decompiler improvements #162

Merged
merged 74 commits into from
May 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
74 commits
Select commit Hold shift + click to select a range
4e4371b
Allow script access to UndertaleModTool namespace.
Kneesnap Apr 10, 2019
e7c9426
Add more useful imports.
Kneesnap Apr 10, 2019
fae02e6
Reverted accidental bug.
Kneesnap Apr 10, 2019
9d1664a
Improved decompiler accuracy
Kneesnap Apr 13, 2019
9e95254
Merge branch 'master' of https://github.com/Kneesnap/UndertaleModTool
Kneesnap Apr 13, 2019
9909d99
Made some fixes to the decompiler
Kneesnap Apr 13, 2019
6484a36
Fix keyboard decompilation, for loop accuracy
Kneesnap Apr 15, 2019
9c831fa
Fixed 'break' decompilation.
Kneesnap Apr 16, 2019
912cd21
Fixed a bug regarding my shoddy fix
Kneesnap Apr 16, 2019
f1e4cc8
Prevent using scientific notation in decompiler
Kneesnap Apr 17, 2019
8a11782
Support local vars, improve temp - constant fix
Kneesnap Apr 17, 2019
a1ae49f
Don't add self and local to decompilation
Kneesnap Apr 19, 2019
e6642fa
Add support for script progress-bars, hopefully. (Not complete, need …
Kneesnap Apr 19, 2019
dff8192
A temporary, nasty fix to object names replacing constants they shoul…
Kneesnap Apr 19, 2019
0a070ad
Update decompiler, use a better (more generalized) fix.
Kneesnap Apr 19, 2019
06fa8cc
Support && + ||
Kneesnap Apr 21, 2019
186ed1c
If-safety check
Kneesnap Apr 21, 2019
53d03c8
Support script ProgressBars.
Kneesnap Apr 23, 2019
5cd29a3
Made if (tempVar - 1) fix a bit more safe.
Kneesnap Apr 23, 2019
4dd6596
Fix ProgressBar close race condition
Kneesnap Apr 23, 2019
01ec8d5
Add UndertaleTexturePageItem export.
Kneesnap Apr 23, 2019
109d570
Add some variable types.
Kneesnap Apr 23, 2019
2f57166
Disabled last commit due to bugs.
Kneesnap Apr 23, 2019
4a3dee1
Re-enable variable types
Kneesnap Apr 24, 2019
9228e3b
Give scripts access to the json library
Kneesnap Apr 24, 2019
e9c7daf
Slap a band-aid on a decompilation bug which didn't appear in Undertale
Kneesnap Apr 25, 2019
38e30ca
Fix ShaderType names.
Kneesnap Apr 25, 2019
9eb6b0b
Add shader naming
Kneesnap Apr 25, 2019
184f522
Reduce console spam
Kneesnap Apr 25, 2019
619de0d
Fix a decompilation bug for users who had their system language set t…
Kneesnap Apr 25, 2019
dcb5f35
Add PreCreate object EventType
Kneesnap Apr 25, 2019
efbf88e
Minor bug-fix
Kneesnap Apr 27, 2019
7ef7799
Don't include string@number in decompiled output.
Kneesnap Apr 28, 2019
ff330ea
Better fix for system language formatting.
Kneesnap Apr 29, 2019
fadf090
Improved decompiler's GMS2 support.
Kneesnap Apr 29, 2019
f74beac
global.currentroom is type room
Kneesnap Apr 29, 2019
ce7d172
Moved currentroom down to the UT specific temp variables.
Kneesnap Apr 29, 2019
d7220a7
Note where the var prefix is applied.
Kneesnap Apr 29, 2019
121cb0a
Add Unknown13 EventType
Kneesnap Apr 29, 2019
2fa46d2
Update SepMasks data-type.
Kneesnap Apr 30, 2019
490ed25
Bring back proper MessageBox alert for a script error.
Kneesnap Apr 30, 2019
da69b94
Drop WindowsBase, use independent texture exporter.
Kneesnap May 1, 2019
fd8f4b9
Fix a minor texture export bug.
Kneesnap May 1, 2019
2554aa6
A slightly better fix to replace GetIntegerValue()
Kneesnap May 2, 2019
cc4b830
Remove PresentationCore
Kneesnap May 2, 2019
656a3d1
Fix script threading issues
Kneesnap May 2, 2019
bd55de0
Implement importing functionality in TextureWorker
Kneesnap May 3, 2019
37e06e3
Support for loops, and conditional while loops.
Kneesnap May 3, 2019
512e3b9
Temporary variables are marked as local variables, for safety.
Kneesnap May 3, 2019
88a3e24
Support repeat statements.
Kneesnap May 5, 2019
fca0da8
Fix a last-minute TextureWorker export bug.
Kneesnap May 5, 2019
66cdf74
Use if else if instead of nesting ifs.
Kneesnap May 5, 2019
b47626f
Fix some tempvars not getting dealt with.
Kneesnap May 5, 2019
2f38660
Fix relative variable updates, minor repeat loop update.
Kneesnap May 5, 2019
7d36b05
Whoops, last minute bug-fix.
Kneesnap May 5, 2019
66826ac
Add decompiler settings.
Kneesnap May 5, 2019
b5ec723
Apparently ++ and -- are not usable everywhere. Use += 1 and -= 1 ins…
Kneesnap May 5, 2019
33f60ea
Fix += bug
Kneesnap May 5, 2019
1a59493
Add ternary support. [GMS2 Only]
Kneesnap May 5, 2019
82e45b2
Add more decompiled window highlight keywords
Kneesnap May 5, 2019
4c9ab05
Allow parallel texture exporting, fix ternary and tempvars.
Kneesnap May 5, 2019
9020fb7
Remove +=, it was causing runtime bugs.
Kneesnap May 5, 2019
e89d349
Turns out SepMasks can be 0-2, and isn't just a boolean.
Kneesnap May 6, 2019
65d0ace
Add colinator27's GMS 2.2.2 bytecode support.
Kneesnap May 7, 2019
f22d4f9
Fix newlines and escaped quotes in code display
Kneesnap May 8, 2019
0901119
Add colinator27's decompiler fixes.
Kneesnap May 8, 2019
1779152
Improve if condition consolidation.
Kneesnap May 9, 2019
7901a56
Even fewer tempVar instances show up.
Kneesnap May 9, 2019
0371ab1
Significantly improve decompiler output.
Kneesnap May 9, 2019
ba22360
Fix bug decompiling mix1control in VA-11 HALL-A
Kneesnap May 9, 2019
07c10cf
Fix assembler string escaping.
Kneesnap May 9, 2019
33c7b3d
Support do while loops.
Kneesnap May 9, 2019
1c5b9ca
Change sprite properties OriginX and OriginY to be signed integers in…
colinator27 May 12, 2019
ca6d840
Remove unused variable
krzys-h May 12, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion UndertaleModLib/Decompiler/Assembler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ private static UndertaleResourceById<UndertaleString, UndertaleChunkSTRG> ParseS
{
if (str[0] != '"' || str[str.Length - 1] != '"')
throw new Exception("Bad string format");
str = str.Substring(1, str.Length - 2);
str = UndertaleString.UnescapeText(str.Substring(1, str.Length - 2));
}
UndertaleString strobj = id.HasValue ? strg[(int)id.Value] : null;
if (strobj != null)
Expand Down
57 changes: 38 additions & 19 deletions UndertaleModLib/Decompiler/AssetTypeResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UndertaleModLib.Models;

namespace UndertaleModLib.Decompiler
{
Expand All @@ -27,6 +28,7 @@ public enum AssetIDType
Room,
GameObject, // or GameObjectInstance or InstanceType, these are all interchangable
Script,
Shader,

Layer // GMS2
};
Expand Down Expand Up @@ -450,16 +452,21 @@ public class AssetTypeResolver

// TODO: surface drawing

// TODO: shaders
{ "shader_is_compiled", new AssetIDType[] { AssetIDType.Shader } },
{ "shader_set", new AssetIDType[] { AssetIDType.Shader } },
// { "shader_current", new AssetIDType[] { } }, returns shader.

// TODO: GMS2 tilemaps
// TODO: GMS2 layers

{ "io_clear", new AssetIDType[] { } },
{ "keyboard_multicheck", new AssetIDType[] { AssetIDType.KeyboardKey } },
{ "keyboard_multicheck_pressed", new AssetIDType[] { AssetIDType.KeyboardKey } },
{ "keyboard_check", new AssetIDType[] { AssetIDType.KeyboardKey } },
{ "keyboard_check_pressed", new AssetIDType[] { AssetIDType.KeyboardKey } },
{ "keyboard_check_released", new AssetIDType[] { AssetIDType.KeyboardKey } },
{ "keyboard_check_direct", new AssetIDType[] { AssetIDType.KeyboardKey } },
{ "keyboard_clear", new AssetIDType[] { AssetIDType.KeyboardKey } },
{ "keyboard_key_press", new AssetIDType[] { AssetIDType.KeyboardKey } },
{ "keyboard_key_release", new AssetIDType[] { AssetIDType.KeyboardKey } },
{ "keyboard_set_map", new AssetIDType[] { AssetIDType.KeyboardKey, AssetIDType.KeyboardKey } },
Expand Down Expand Up @@ -491,6 +498,21 @@ public class AssetTypeResolver
{ "keyboard_key", AssetIDType.KeyboardKey },
{ "keyboard_lastkey", AssetIDType.KeyboardKey },
{ "os_type", AssetIDType.Enum_OSType },

// These ones are ordinary variables with specific meaning within Undertale/Deltarune.
// It would probably be better to only use these if UT/DR are being loaded.
krzys-h marked this conversation as resolved.
Show resolved Hide resolved
{ "currentroom", AssetIDType.Room },
{ "dsprite", AssetIDType.Sprite },
{ "usprite", AssetIDType.Sprite },
{ "lsprite", AssetIDType.Sprite },
{ "rsprite", AssetIDType.Sprite },
{ "dtsprite", AssetIDType.Sprite },
{ "utsprite", AssetIDType.Sprite },
{ "ltsprite", AssetIDType.Sprite },
{ "rtsprite", AssetIDType.Sprite },
{ "normalsprite", AssetIDType.Sprite },
{ "hurtsprite", AssetIDType.Sprite },
{ "hurtsound", AssetIDType.Sound },
};

internal static bool AnnotateTypesForFunctionCall(string function_name, AssetIDType[] arguments, Dictionary<string, AssetIDType[]> scriptArgs)
Expand Down Expand Up @@ -544,24 +566,21 @@ internal static AssetIDType AnnotateTypeForVariable(string variable_name)
if (const_name.Length >= 1 && const_name[0] == '-')
return null; // that is not a constant either

OSType os_type;
if (Enum.TryParse(const_name, out os_type))
return (int)os_type;
GamepadButton gm_button;
if (Enum.TryParse(const_name, out gm_button))
return (int)gm_button;
HAlign halign;
if (Enum.TryParse(const_name, out halign))
return (int)halign;
VAlign valign;
if (Enum.TryParse(const_name, out valign))
return (int)valign;
e__VW vw;
if (Enum.TryParse(const_name, out vw))
return (int)vw;
e__BG bg;
if (Enum.TryParse(const_name, out bg))
return (int)bg;
// By avoiding Enum.TryParse, we avoid exception spam in the console, and there isn't any speed loss.
if (Enum.IsDefined(typeof(OSType), const_name))
return (int)Enum.Parse(typeof(OSType), const_name);
if (Enum.IsDefined(typeof(GamepadButton), const_name))
return (int)Enum.Parse(typeof(GamepadButton), const_name);
if (Enum.IsDefined(typeof(HAlign), const_name))
return (int)Enum.Parse(typeof(HAlign), const_name);
if (Enum.IsDefined(typeof(VAlign), const_name))
return (int)Enum.Parse(typeof(VAlign), const_name);
if (Enum.IsDefined(typeof(e__VW), const_name))
return (int)Enum.Parse(typeof(e__VW), const_name);
if (Enum.IsDefined(typeof(e__BG), const_name))
return (int)Enum.Parse(typeof(e__BG), const_name);
if (Enum.IsDefined(typeof(EventSubtypeKey), const_name))
return Convert.ToInt32((uint)Enum.Parse(typeof(EventSubtypeKey), const_name));

return null;
}
Expand Down
Loading