public void Serialize(List <string> lines) { lines.RemoveAll(x => string.IsNullOrEmpty(x)); this.Clear(); for (int i = 0; i < lines.Count; i++) { string lineText = lines[i].Trim(); if (lineText.StartsWith("//")) { continue; } ACMDCommand cmd = this.ParseCMD(lines[i]); uint ident = cmd.Ident; if (this.SerializeCommands(ref i, ident, ref lines) > 0) { continue; } else { this.Add(cmd); } } }
private ACMDScript ParseEventList(uint cRC, int offset) { ACMDScript _list = new ACMDScript(cRC); ACMDCommand c; VoidPtr addr = (this._workingSource.Address + offset); // Loop through Event List. while (Util.GetWordUnsafe(addr, this.Endian) != 0x5766F889) { // Try to get command definition uint ident = (uint)Util.GetWordUnsafe(addr, this.Endian); // Get command parameters and add the command to the event list. c = new ACMDCommand(ident); for (int i = 0; i < c.ParamSpecifiers.Length; i++) { switch (c.ParamSpecifiers[i]) { case 0: c.Parameters.Add(Util.GetWordUnsafe(0x04 + (addr + (i * 4)), this.Endian)); break; case 1: c.Parameters.Add(Util.GetFloatUnsafe(0x04 + (addr + (i * 4)), this.Endian)); break; case 2: c.Parameters.Add((decimal)Util.GetWordUnsafe(0x04 + (addr + (i * 4)), this.Endian)); break; case 3: c.Parameters.Add(new FighterVariable((uint)Util.GetWordUnsafe(0x04 + (addr + (i * 4)), this.Endian))); break; default: goto case 0; } } _list.Add(c); addr += c.Size; } // If we hit a script_end command, add it to the the Event List and terminate looping. if (Util.GetWordUnsafe(addr, this.Endian) == 0x5766F889) { c = new ACMDCommand(0x5766F889); _list.Add(c); } _list.Initialize(); return(_list); }
private ACMDCommand ParseCMD(string line) { string s = line.TrimStart(); s = s.Substring(0, s.IndexOf(')')); var name = s.Substring(0, s.IndexOf('(')); var parameters = s.Substring(s.IndexOf('(') + 1).TrimEnd(')').Split(','); for (int i = 0; i < parameters.Length; i++) { string param = parameters[i]; if (param.Contains("=")) { parameters[i] = param.Remove(0, param.IndexOf("=") + 1).Trim(); } } var crc = ACMD_INFO.CMD_NAMES.Single(x => x.Value.Equals(name, StringComparison.InvariantCultureIgnoreCase)).Key; ACMDCommand cmd = new ACMDCommand(crc); for (int i = 0; i < cmd.ParamSpecifiers.Length; i++) { switch (cmd.ParamSpecifiers[i]) { case 0: if (parameters[i].StartsWith("0x")) { cmd.Parameters.Add(int.Parse(parameters[i].Substring(2), NumberStyles.HexNumber)); } else { cmd.Parameters.Add(int.Parse(parameters[i])); } break; case 1: cmd.Parameters.Add(float.Parse(parameters[i], CultureInfo.InvariantCulture)); break; case 2: cmd.Parameters.Add(decimal.Parse(parameters[i], CultureInfo.InvariantCulture)); break; case 3: cmd.Parameters.Add(new FighterVariable(parameters[i])); break; } } return(cmd); }
private int SerializeLoop(ref int Index, ref List <string> lines) { int start = Index; // Serialize all commands without counting len first // Then walk backwards to count len for goto comamnds. // This avoids problems with counting commands in conditional blocks this.Add(this.ParseCMD(lines[Index])); while (this.ParseCMD(lines[++Index]).Ident != 0x38A3EC78) { ACMDCommand tmp = this.ParseCMD(lines[Index]); if (IsCmdHandled(tmp.Ident)) { this.SerializeCommands(ref Index, tmp.Ident, ref lines); } else { this.Add(tmp); } } decimal len = 0; int gotoIndex = Index; while (gotoIndex > start) { if (lines[gotoIndex] == "}") { gotoIndex--; continue; } var cmd = this.ParseCMD(lines[gotoIndex]); len += cmd.Size / 4; gotoIndex--; } ACMDCommand endLoop = this.ParseCMD(lines[Index]); endLoop.Parameters[0] = (len - 2) / -1; this.Add(endLoop); if (lines[Index + 1].Trim() == "}") { Index++; } // Compensate for len not counting the begin_loop and goto command sizes return((int)len - 4); }
private static int CompileLoop(ref int Index, ref List <string> lines) { int start = Index; Commands.Add(CompileSingleCommand(lines[Index])); while (CompileSingleCommand(lines[++Index]).Ident != 0x38A3EC78) { ACMDCommand tmp = CompileSingleCommand(lines[Index]); if (IsCmdHandled(tmp.Ident)) { HandleSpecialCommands(ref Index, tmp.Ident, ref lines); } else { Commands.Add(tmp); } } decimal len = 0; int gotoIndex = Index; while (gotoIndex > start) { if (lines[gotoIndex] == "}") { gotoIndex--; continue; } var cmd = CompileSingleCommand(lines[gotoIndex]); len += cmd.Size / 4; gotoIndex--; } ACMDCommand endLoop = CompileSingleCommand(lines[Index]); endLoop.Parameters[0] = len / -1; Commands.Add(endLoop); if (lines[Index + 1].Trim() == "}") { Index++; } // Next line should be closing bracket, ignore and skip it return((int)len + 4); }
/// <summary> /// Compile an array of code lines. /// </summary> /// <param name="lines">Array of plaintext code lines.</param> /// <returns></returns> public static ACMDCommand[] CompileCommands(string[] lines) { var tmpList = lines.ToList().Select(x => x.Trim()).ToList(); tmpList.RemoveAll(x => string.IsNullOrWhiteSpace(x)); Commands.Clear(); for (int i = 0; i < tmpList.Count; i++) { string lineText = tmpList[i].Trim(); // Handle comments if (lineText.StartsWith("//")) { continue; } if (lineText.StartsWith("/*")) { while (tmpList[i].Trim() != "*/") { i++; } if (++i < tmpList.Count) { lineText = tmpList[i].Trim(); } else { break; } } ACMDCommand cmd = CompileSingleCommand(tmpList[i]); uint ident = cmd.Ident; if (HandleSpecialCommands(ref i, ident, ref tmpList) > 0) { continue; } else { Commands.Add(cmd); } } return(Commands.ToArray()); }
private static int CompileConditional(ref int Index, ref List <string> lines) { ACMDCommand cmd = CompileSingleCommand(lines[Index]); int len = 2; Commands.Add(cmd); while (lines[++Index].Trim() != "}") { ACMDCommand tmp = CompileSingleCommand(lines[Index]); if (IsCmdHandled(tmp.Ident)) { len += HandleSpecialCommands(ref Index, tmp.Ident, ref lines); } else { len += tmp.Size / 4; Commands.Add(tmp); } } if (lines[Index + 1] != "}") { if (CompileSingleCommand(lines[Index + 1]).Ident == 0x895B9275 && cmd.Ident == 0xA5BD4F32) { ACMDCommand tmp = CompileSingleCommand(lines[++Index]); len += tmp.Size / 4; Commands[Commands.IndexOf(cmd)].Parameters[0] = len; len -= tmp.Size / 4; HandleSpecialCommands(ref Index, tmp.Ident, ref lines); } else { Commands[Commands.IndexOf(cmd)].Parameters[0] = len; } } else { Commands[Commands.IndexOf(cmd)].Parameters[0] = len; } // Next line should be closing bracket, ignore and skip it return(len); }
private int SerializeConditional(ref int Index, ref List <string> lines) { ACMDCommand cmd = this.ParseCMD(lines[Index]); int len = 2; this.Add(cmd); while (lines[++Index].Trim() != "}") { ACMDCommand tmp = this.ParseCMD(lines[Index]); if (this.IsCmdHandled(tmp.Ident)) { len += this.SerializeCommands(ref Index, tmp.Ident, ref lines); } else { len += tmp.Size / 4; this.Add(tmp); } } if (lines[Index + 1] != "}") { if (ParseCMD(lines[Index + 1]).Ident == 0x895B9275 && cmd.Ident == 0xA5BD4F32) { ACMDCommand tmp = this.ParseCMD(lines[++Index]); len += tmp.Size / 4; this[this.IndexOf(cmd)].Parameters[0] = len; len -= tmp.Size / 4; this.SerializeCommands(ref Index, tmp.Ident, ref lines); } else { this[this.IndexOf(cmd)].Parameters[0] = len; } } else { this[this.IndexOf(cmd)].Parameters[0] = len; } return(len); }
private static int CompileConditional(ref int Index, ref List <string> lines) { ACMDCommand cmd = CompileSingleCommand(lines[Index]); int len = cmd.Size / 4; Commands.Add(cmd); while (lines[++Index].Trim() != "}") { ACMDCommand tmp = CompileSingleCommand(lines[Index]); if (IsCmdHandled(tmp.Ident)) { //recursively add the size of any nested handled statements len += HandleSpecialCommands(ref Index, tmp.Ident, ref lines); } else { len += tmp.Size / 4; Commands.Add(tmp); } } //check for Else statement. If the next command is Else, set True/False size parameter (current len + Else len) //if the True/False statements don't have an Else afterward then just set their size to current len if (lines[Index + 1] != "}" && CompileSingleCommand(lines[Index + 1]).Ident == 0x895B9275 && IsCmdCondition(cmd.Ident)) { ACMDCommand tmp = CompileSingleCommand(lines[++Index]); Commands[Commands.IndexOf(cmd)].Parameters[0] = len + tmp.Size / 4; //increment handled command length by the size of the Else statement len += HandleSpecialCommands(ref Index, tmp.Ident, ref lines); } else { Commands[Commands.IndexOf(cmd)].Parameters[0] = len; } // Next line should be closing bracket, ignore and skip it return(len); }
public int IndexOf(ACMDCommand var) { return(this._commands.IndexOf(var)); }
public bool Contains(ACMDCommand var) { return(this._commands.Contains(var)); }
public bool Remove(ACMDCommand var) { return(this._commands.Remove(var)); }
public void Add(ACMDCommand var) { this._commands.Add(var); }
public void InsertAfter(int index, ACMDCommand var) { this._commands.Insert(index + 1, var); }