コード例 #1
0
        public static string GenerateLocalVarDefinitions(this UndertaleCode code, IList <UndertaleVariable> vars, UndertaleCodeLocals locals)
        {
            if (code.WeirdLocalFlag)
            {
                return("");
            }
            if (locals == null)
            {
                return("; Missing code locals- possibly due to unsupported bytecode version or brand new code entry.\n");
            }

            StringBuilder sb = new StringBuilder();

            var referenced = code.FindReferencedLocalVars();

            if (locals.Name != code.Name)
            {
                throw new Exception("Name of the locals block does not match name of the code block");
            }
            foreach (var arg in locals.Locals)
            {
                sb.Append(".localvar " + arg.Index + " " + arg.Name.Content);
                var refvar = referenced.Where((x) => x.Name == arg.Name && x.VarID == arg.Index).FirstOrDefault();
                if (refvar != null)
                {
                    sb.Append(" " + vars.IndexOf(refvar));
                }
                sb.Append('\n');
            }

            return(sb.ToString());
        }
コード例 #2
0
 public CompileContext(UndertaleData data, UndertaleCode oldCode)
 {
     Data         = data;
     OriginalCode = oldCode;
     OriginalReferencedLocalVars = OriginalCode?.FindReferencedLocalVars();
 }