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

Major Profile Mode improvements #1443

Closed
wants to merge 15 commits into from
Closed
Show file tree
Hide file tree
Changes from 13 commits
Commits
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
20 changes: 11 additions & 9 deletions UndertaleModLib/Compiler/AssemblyWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
using UndertaleModLib.Decompiler;
using UndertaleModLib.Models;
using static UndertaleModLib.Models.UndertaleInstruction;
Expand All @@ -27,7 +28,7 @@ public class CodeWriter
public List<VariablePatch> varPatches = new List<VariablePatch>();
public List<FunctionPatch> funcPatches = new List<FunctionPatch>();
public List<StringPatch> stringPatches = new List<StringPatch>();

public Parser.Statement currentFunctionContext = null;
public CodeWriter(CompileContext context)
{
compileContext = context;
Expand Down Expand Up @@ -279,7 +280,6 @@ bool hasLocal(string name)
NameStringID = childNameIndex,
Autogenerated = true
};

compileContext.Data.Functions.Add(childFunction);

compileContext.Data.KnownSubFunctions.Add(patch.Name, childFunction);
Expand Down Expand Up @@ -1308,9 +1308,11 @@ private static void AssembleExpression(CodeWriter cw, Parser.Statement e, Parser
isNewFunc = true
});
}

cw.loopContexts.Push(new LoopContext(endPatch, startPatch));
var oldFuncContext = cw.currentFunctionContext;
cw.currentFunctionContext = e;
AssembleStatement(cw, e.Children[1]); // body
cw.currentFunctionContext = oldFuncContext;
AssembleExit(cw);
cw.loopContexts.Pop();
endPatch.Finish(cw);
Expand Down Expand Up @@ -1786,14 +1788,14 @@ private static void AssembleVariablePush(CodeWriter cw, Parser.Statement e, out
switch (id)
{
case -1:
if (cw.compileContext.BuiltInList.GlobalArray.ContainsKey(name) || cw.compileContext.BuiltInList.GlobalNotArray.ContainsKey(name))
if (cw.compileContext.BuiltInList.GlobalArray.ContainsKey(name) || cw.compileContext.BuiltInList.GlobalNotArray.ContainsKey(name) || (cw.currentFunctionContext != null && cw.compileContext.LocalArgs[cw.currentFunctionContext].ContainsKey(name)))
{
if (CompileContext.GMS2_3 &&
name.In(
(name.In(
"argument0", "argument1", "argument2", "argument3",
"argument4", "argument5", "argument6", "argument7",
"argument8", "argument9", "argument10", "argument11",
"argument12", "argument13", "argument14", "argument15"))
"argument12", "argument13", "argument14", "argument15", "a")))
{
// 2.3 argument (excuse the condition... the ID seems to be lost, so this is the easiest way to check)
cw.varPatches.Add(new VariablePatch()
Expand Down Expand Up @@ -2084,13 +2086,13 @@ private static void AssembleStoreVariable(CodeWriter cw, Parser.Statement s, Dat
int id = s.Children[0].ID;
if (id >= 100000)
id -= 100000;
if (CompileContext.GMS2_3 && (cw.compileContext.BuiltInList.GlobalArray.ContainsKey(s.Children[0].Text) || cw.compileContext.BuiltInList.GlobalNotArray.ContainsKey(s.Children[0].Text)))
if (CompileContext.GMS2_3 && (cw.compileContext.BuiltInList.GlobalArray.ContainsKey(s.Children[0].Text) || cw.compileContext.BuiltInList.GlobalNotArray.ContainsKey(s.Children[0].Text)) || (cw.currentFunctionContext != null && cw.compileContext.LocalArgs[cw.currentFunctionContext].ContainsKey(s.Children[0].Text)))
{
if (s.Children[0].Text.In(
if ((s.Children[0].Text.In(
"argument0", "argument1", "argument2", "argument3",
"argument4", "argument5", "argument6", "argument7",
"argument8", "argument9", "argument10", "argument11",
"argument12", "argument13", "argument14", "argument15"))
"argument12", "argument13", "argument14", "argument15")))
{
cw.varPatches.Add(new VariablePatch()
{
Expand Down
1 change: 1 addition & 0 deletions UndertaleModLib/Compiler/Compiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public class CompileContext
public int LastCompiledArgumentCount = 0;
public Dictionary<string, string> LocalVars = new Dictionary<string, string>();
public Dictionary<string, string> GlobalVars = new Dictionary<string, string>();
public Dictionary<Compiler.Parser.Statement, Dictionary<string, int>> LocalArgs = new();
public Dictionary<string, Dictionary<string, int>> Enums = new Dictionary<string, Dictionary<string, int>>();
public UndertaleCode OriginalCode;
public IList<UndertaleVariable> OriginalReferencedLocalVars;
Expand Down
17 changes: 12 additions & 5 deletions UndertaleModLib/Compiler/Parser.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
Expand Down Expand Up @@ -439,6 +440,7 @@ public static Statement ParseTokens(CompileContext context, List<Lexer.Token> to
context.LocalVars["arguments"] = "arguments";
context.GlobalVars.Clear();
context.Enums.Clear();
context.LocalArgs.Clear();
hasError = false;

// Ensuring an EOF exists
Expand Down Expand Up @@ -672,12 +674,15 @@ private static Statement ParseFunction(CompileContext context)
}

EnsureTokenKind(TokenKind.OpenParen);

var i = 0;
Dictionary<string, int> argsDict = new();
while (remainingStageOne.Count > 0 && !hasError && !IsNextToken(TokenKind.EOF, TokenKind.CloseParen))
{
Statement expr = ParseExpression(context);
if (expr != null)
args.Children.Add(expr);
var token = EnsureTokenKind(TokenKind.ProcVariable);
if (token == null)
return null;
argsDict.Add(token.Text, i);
i++;
if (!IsNextTokenDiscard(TokenKind.Comma))
{
if (!IsNextToken(TokenKind.CloseParen))
Expand All @@ -691,7 +696,9 @@ private static Statement ParseFunction(CompileContext context)

if (EnsureTokenKind(TokenKind.CloseParen) == null) return null;

result.Children.Add(ParseStatement(context));
result.Children.Add(ParseStatement(context)); // most likely parses the body.
context.LocalArgs.Add(result, argsDict);

if (expressionMode)
return result;
else // Whatever you call non-anonymous definitions
Expand Down
6 changes: 3 additions & 3 deletions UndertaleModTool/Editors/UndertaleCodeEditor.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -690,7 +690,7 @@ private async Task DecompileCode(UndertaleCode code, bool first, LoaderDialog ex
{
if (match.Success)
{
if (gettext.TryGetValue(match.Groups[1].Value, out string text))
if (gettext.TryGetValue(match.Groups[1].Value, out string text) && !decompiled.Contains($" // {text}"))
decompiledLines[i] += $" // {text}";
}
}
Expand All @@ -707,7 +707,7 @@ private async Task DecompileCode(UndertaleCode code, bool first, LoaderDialog ex
{
if (match.Success)
{
if (gettextJSON.TryGetValue(match.Groups[^1].Value, out string text))
if (gettextJSON.TryGetValue(match.Groups[^1].Value, out string text) && !decompiled.Contains($" // {text}"))
decompiledLines[i] += $" // {text}";
}
}
Expand Down Expand Up @@ -1193,7 +1193,7 @@ public class NameGenerator : VisualLineElementGenerator
private static readonly SolidColorBrush GlobalBrush = new(Color.FromRgb(0xF9, 0x7B, 0xF9));
private static readonly SolidColorBrush ConstantBrush = new(Color.FromRgb(0xFF, 0x80, 0x80));
private static readonly SolidColorBrush InstanceBrush = new(Color.FromRgb(0x58, 0xE3, 0x5A));
private static readonly SolidColorBrush LocalBrush = new(Color.FromRgb(0xFF, 0xF8, 0x99));
private static readonly SolidColorBrush LocalBrush = new(Color.FromRgb(0xFF, 0xF8, 0x99)); // new(Color.FromRgb(0x58, 0xF8, 0x99)); -> this color is pretty cool

private static ContextMenuDark contextMenu;

Expand Down
41 changes: 40 additions & 1 deletion UndertaleModTool/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@
Height="450" Width="800" Loaded="Window_Loaded"
AllowDrop="True" Drop="Window_Drop">
<Window.Title>
<MultiBinding StringFormat="{}{0} - {1} [{2}]">
<MultiBinding StringFormat="{}{0} - {1} [{2}] {3}">
<Binding Path="TitleMain"/>
<Binding Path="Data.GeneralInfo" FallbackValue="No game loaded"/>
<Binding Path="FilePath"/>
<Binding Path="CurrentProfileName"/>
</MultiBinding>
</Window.Title>
<Window.Resources>
Expand Down Expand Up @@ -105,6 +106,7 @@
</MenuItem>
<Separator/>
<MenuItem Header="Generate o_ffset map" Click="MenuItem_OffsetMap_Click"/>
<MenuItem Header="Export to GameMaker project" Click="MenuItem_GameMaker_Click"/>
<Separator/>
<MenuItem Header="S_ettings" Command="Properties"/>
<MenuItem Header="_Close" Command="Close" InputGestureText="Ctrl+Q"/>
Expand Down Expand Up @@ -713,5 +715,42 @@
</Grid>
</Grid>
</DockPanel>
<Border Background="Black" Name="room_dogcheck" Visibility="Collapsed">
<Grid RenderOptions.BitmapScalingMode="NearestNeighbor">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="2*"/>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="2*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="2*"/>
<RowDefinition Height="1*"/>
<RowDefinition Height="2*"/>
</Grid.RowDefinitions>
<Image Grid.Row="1" Grid.Column="1">
<Image.Triggers>
<EventTrigger RoutedEvent="Loaded">
<BeginStoryboard>
<Storyboard RepeatBehavior="Forever">
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Source"
Duration="0:0:0.4">
<DiscreteObjectKeyFrame KeyTime="0:0:0.00">
<DiscreteObjectKeyFrame.Value>
<BitmapImage UriSource="Resources/spr_tobdogl/0.png"/>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is still dogcheck related

</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
<DiscreteObjectKeyFrame KeyTime="0:0:0.2">
<DiscreteObjectKeyFrame.Value>
<BitmapImage UriSource="Resources/spr_tobdogl/1.png"/>
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Image.Triggers>
</Image>
</Grid>
</Border>
</Grid>
</Window>
Loading
Loading