Skip to content

Commit

Permalink
Hack around failing to find local vars
Browse files Browse the repository at this point in the history
  • Loading branch information
Dobby233Liu committed Oct 13, 2024
1 parent d5da084 commit 02102c2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
4 changes: 3 additions & 1 deletion UndertaleModLib/Decompiler/Assembler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,8 @@ public static List<UndertaleInstruction> Assemble(string source, IList<Undertale
string[] aaa = line.Split(' ');
if (aaa[0] == ".localvar")
{
if (localvars is null)
throw new Exception("Local variable directive is not supported in this bytecode version");
if (aaa.Length >= 4)
{
var varii = vars[Int32.Parse(aaa[3])];
Expand Down Expand Up @@ -526,7 +528,7 @@ private static UndertaleInstruction.Reference<UndertaleVariable> ParseVariableRe
// Locate variable from either local variables, or VARI chunk
UndertaleVariable locatedVariable;
string variableName = str[strPosition..].ToString();
if (variInstanceType == UndertaleInstruction.InstanceType.Local)
if (variInstanceType == UndertaleInstruction.InstanceType.Local && data?.CodeLocals is not null)
{
locatedVariable = localvars.ContainsKey(variableName) ? localvars[variableName] : null;
}
Expand Down
8 changes: 5 additions & 3 deletions UndertaleModLib/UndertaleDataExtensionMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -174,10 +174,12 @@ public static UndertaleVariable EnsureDefined(this IList<UndertaleVariable> list

public static UndertaleVariable DefineLocal(this IList<UndertaleVariable> list, IList<UndertaleVariable> originalReferencedLocalVars, int localId, string name, IList<UndertaleString> strg, UndertaleData data)
{
bool bytecode14 = (data?.GeneralInfo?.BytecodeVersion <= 14);
if (bytecode14)
bool bytecode14 = data?.GeneralInfo?.BytecodeVersion <= 14;
if (bytecode14 || data?.CodeLocals is null)
{
UndertaleVariable search = list.Where((x) => x.Name.Content == name).FirstOrDefault();
UndertaleVariable search = list.Where((x) =>
x.Name.Content == name && (bytecode14 || x.InstanceType == UndertaleInstruction.InstanceType.Local)
).FirstOrDefault();
if (search != null)
return search;
}
Expand Down

0 comments on commit 02102c2

Please sign in to comment.