public byte[] CreateGMLBytecode(string sCode, bool UseAUMI = false) { // By Archie EnsureDataLoaded(); var Context = UndertaleModLib.Compiler.Compiler.CompileGMLText(sCode, Data, null); // We don't need UndertaleCode using (var smStream = new MemoryStream()) { using UndertaleWriter writer = new UndertaleWriter(smStream); foreach (var Instruction in Context.ResultAssembly) { Instruction.Serialize(writer); if (Instruction.Destination != null) { uint Override = (uint)(Instruction.Destination.Target.VarID + 100000); writer.Position -= 4; writer.WriteUInt24(Override); writer.Position++; } else if (Instruction.Value is UndertaleInstruction.Reference <UndertaleVariable> && Instruction.Value != null) { uint Override = (uint)(((UndertaleInstruction.Reference <UndertaleVariable>)Instruction.Value).Target.VarID + 100000); writer.Position -= 4; writer.WriteUInt24(Override); writer.Position++; } //From AUMI, if not injected, this will fail! if (UseAUMI) { if (Instruction.Function != null) { if (Instruction.Function.Target == null) { continue; } if (Instruction.Function.Target.Name == null) { continue; } if (Instruction.Function.Target.Name.Content == null) { continue; } string Name = Instruction.Function.Target.Name.Content; byte[] NameBytes = System.Text.Encoding.ASCII.GetBytes(Name); IpcMessage_t ipMessage; IpcReply_t ipReply = new IpcReply_t(); ipMessage.FuncID = 3; // IPCID_GetFunctionByName ipMessage.Buffer = new byte[512]; Buffer.BlockCopy(NameBytes, 0, ipMessage.Buffer, 0, NameBytes.Length); SendAUMIMessage(ipMessage, ref ipReply); if (ipReply.AUMIResult != 0) // AUMI_OK { ScriptError("AUMI - Failed to find function " + Name + " - result: " + ipReply.AUMIResult.ToString()); } else { byte[] IndexBytes = new byte[4]; Buffer.BlockCopy(ipReply.Buffer, 0, IndexBytes, 0, 4); // Incompatible with old AUMI versions! Use commit ebd58007 or newer! uint Index = BitConverter.ToUInt32(IndexBytes); writer.Position -= 4; writer.WriteUInt24(Index); writer.Position++; } } } } writer.Flush(); byte[] Code = smStream.ToArray(); return(Code); } }
public void Serialize(UndertaleWriter writer) { NextOccurrenceOffset = 0xdead; writer.WriteUInt24(NextOccurrenceOffset); writer.Write((byte)Type); }