private void FunctionOpcodesFromExpressions(ScriptExpressionTable expressions, SortedDictionary <int, string> dict) { foreach (ScriptExpression exp in expressions.ExpressionsAsReadonly) { if (exp.Type == ScriptExpressionType.Group) { DatumIndex index = new DatumIndex(exp.Value.UintValue); ScriptExpression name = expressions.FindExpression(index); if (exp.Opcode != name.Opcode) { Console.WriteLine($"Warning: Non-matching opcodes! Call Opcode: {exp.Opcode} Function Name Opcode: {name.Opcode}"); } if (dict.TryGetValue(name.Opcode, out string funcName) && funcName != name.StringValue) { Console.WriteLine($"Warning: Duplicate opcodes! Opcode: {name.Opcode.ToString("X3")} Name: \"{name.StringValue}\"\n"); } else { dict[name.Opcode] = name.StringValue; } } } }
private ScriptExpressionTable LoadExpressions(IReader reader, StructureValueCollection values, StringTableReader stringReader) { var count = (int)values.GetInteger("number of script expressions"); uint address = values.GetInteger("script expression table address"); StructureLayout layout = _buildInfo.Layouts.GetLayout("script expression entry"); StructureValueCollection[] entries = ReflexiveReader.ReadReflexive(reader, count, address, layout, _metaArea); var result = new ScriptExpressionTable(); result.AddExpressions(entries.Select((e, i) => new ScriptExpression(e, (ushort)i, stringReader))); foreach (ScriptExpression expr in result.Where(expr => expr != null)) { expr.ResolveReferences(result); } return(result); }
private ScriptExpressionTable LoadExpressions(IReader reader, StructureValueCollection values, StringTableReader stringReader) { var stringsSize = (int)values.GetInteger("script string table size"); var count = (int)values.GetInteger("number of script expressions"); uint address = (uint)values.GetInteger("script expression table address"); long expand = _expander.Expand(address); StructureLayout layout = _buildInfo.Layouts.GetLayout("script expression element"); StructureValueCollection[] entries = TagBlockReader.ReadTagBlock(reader, count, expand, layout, _metaArea); var result = new ScriptExpressionTable(); result.AddExpressions(entries.Select((e, i) => new ScriptExpression(e, (ushort)i, stringReader, stringsSize))); foreach (ScriptExpression expr in result.Where(expr => expr != null)) { expr.ResolveReferences(result); } return(result); }
private void EngineGlobalsFromExpressions(ScriptExpressionTable expressions, SortedDictionary <int, string> dict) { foreach (ScriptExpression expr in expressions.ExpressionsAsReadonly) { if (expr.Type == ScriptExpressionType.GlobalsReference) { var bytes = BitConverter.GetBytes(expr.Value.UintValue); ushort first16 = BitConverter.ToUInt16(bytes, 2); ushort second16 = (ushort)(BitConverter.ToUInt16(bytes, 0) ^ 0x8000); if (first16 == 0xFFFF) { if (dict.TryGetValue(second16, out string global) && global != expr.StringValue) { Console.WriteLine($"Warning: Duplicate opcodes! Opcode: {second16.ToString("X3")} Name1: \"{global}\" Name2: \"{expr.StringValue}\"\n"); } else { dict[second16] = expr.StringValue; } } } } }
internal void ResolveReferences(ScriptExpressionTable allExpressions) { if (_nextIndex.IsValid) Next = allExpressions.FindExpression(_nextIndex); }
private ScriptExpressionTable LoadExpressions(IReader reader, StructureValueCollection values, StringTableReader stringReader) { var count = (int) values.GetInteger("number of script expressions"); uint address = values.GetInteger("script expression table address"); StructureLayout layout = _buildInfo.Layouts.GetLayout("script expression entry"); StructureValueCollection[] entries = ReflexiveReader.ReadReflexive(reader, count, address, layout, _metaArea); var result = new ScriptExpressionTable(); result.AddExpressions(entries.Select((e, i) => new ScriptExpression(e, (ushort) i, stringReader))); foreach (ScriptExpression expr in result.Where(expr => expr != null)) expr.ResolveReferences(result); return result; }