public Function(LuaFile file, LuaVersion version, BinaryReaderEx br) { if (version == LuaVersion.Lua53Smash) { ReadLua53Smash(file, br); } else if (version == LuaVersion.Lua50) { Name = LuaFile.ReadLuaString(br, version); LineDefined = br.ReadInt32(); Nups = br.ReadByte(); NumParams = br.ReadByte(); IsVarArg = br.ReadByte(); MaxStackSize = br.ReadByte(); SizeLineInfo = br.ReadInt32(); // Eat line numbers br.ReadInt32s(SizeLineInfo); LocalVarsCount = br.ReadInt32(); Locals = new Local[LocalVarsCount]; LocalMap = new Dictionary <int, List <Local> >(); for (int i = 0; i < LocalVarsCount; i++) { Locals[i] = new Local(br, version); if (!Locals[i].Name.StartsWith("(")) { if (!LocalMap.ContainsKey(Locals[i].Start)) { LocalMap[Locals[i].Start] = new List <Local>(); } LocalMap[Locals[i].Start].Add(Locals[i]); } } UpValuesCount = br.ReadInt32(); UpvalueNames = new UpvalueName[UpValuesCount]; for (int i = 0; i < UpValuesCount; i++) { UpvalueNames[i] = new UpvalueName(br, version); } int constantsCount = br.ReadInt32(); Constants = new Constant[constantsCount]; for (int i = 0; i < constantsCount; i++) { Constants[i] = new Constant(file, br, version); } int funcCount = br.ReadInt32(); ChildFunctions = new Function[funcCount]; for (int i = 0; i < funcCount; i++) { ChildFunctions[i] = new Function(file, version, br); } int bytecodeCount = br.ReadInt32(); Bytecode = br.ReadBytes(bytecodeCount * 4); } else if (version == LuaVersion.Lua51HKS) { // Thanks @horkrux for reverse engineering this br.ReadInt32(); NumParams = br.ReadUInt32(); br.ReadByte(); // Unk NumSlots = br.ReadUInt32(); br.ReadUInt32(); // unk int bytecodeCount = br.ReadInt32(); br.Pad(4); Bytecode = br.ReadBytes(bytecodeCount * 4); int constantsCount = br.ReadInt32(); ConstantsHKS = new ConstantHKS[constantsCount]; for (int i = 0; i < constantsCount; i++) { ConstantsHKS[i] = new ConstantHKS(file, br); } br.ReadInt32(); // unk br.ReadInt32(); // unk LocalVarsCount = br.ReadInt32(); UpValuesCount = br.ReadInt32(); br.ReadInt32(); // line begin br.ReadInt32(); // line end Path = ReadLuaString(br, version); Name = ReadLuaString(br, version); // Eat line numbers br.ReadInt32s(bytecodeCount); Locals = new Local[LocalVarsCount]; LocalMap = new Dictionary <int, List <Local> >(); for (int i = 0; i < LocalVarsCount; i++) { Locals[i] = new Local(br, version); if (!Locals[i].Name.StartsWith("(")) { if (!LocalMap.ContainsKey(Locals[i].Start)) { LocalMap[Locals[i].Start] = new List <Local>(); } LocalMap[Locals[i].Start].Add(Locals[i]); } } UpvalueNames = new UpvalueName[UpValuesCount]; for (int i = 0; i < UpValuesCount; i++) { UpvalueNames[i] = new UpvalueName(br, version); } int funcCount = br.ReadInt32(); ChildFunctions = new Function[funcCount]; for (int i = 0; i < funcCount; i++) { ChildFunctions[i] = new Function(file, version, br); } } }
private void ReadLua53Smash(LuaFile file, BinaryReaderEx br) { Name = LuaFile.ReadLuaString(br, LuaVersion.Lua53Smash, false); LineDefined = br.ReadInt32(); br.ReadInt32(); // last line NumParams = br.ReadByte(); IsVarArg = br.ReadByte(); MaxStackSize = br.ReadByte(); int bytecodeCount = br.ReadInt32(); Bytecode = br.ReadBytes(bytecodeCount * 4); int constantsCount = br.ReadInt32(); Constants = new Constant[constantsCount]; for (int i = 0; i < constantsCount; i++) { Constants[i] = new Constant(file, br, LuaVersion.Lua53Smash); } int upvalct = br.ReadInt32(); Upvalues = new Upvalue[upvalct]; for (int i = 0; i < upvalct; i++) { Upvalues[i] = new Upvalue(br); } int funcCount = br.ReadInt32(); ChildFunctions = new Function[funcCount]; for (int i = 0; i < funcCount; i++) { ChildFunctions[i] = new Function(file, LuaVersion.Lua53Smash, br); } SizeLineInfo = br.ReadInt32(); // Eat line numbers br.ReadInt32s(SizeLineInfo); LocalVarsCount = br.ReadInt32(); Locals = new Local[LocalVarsCount]; LocalMap = new Dictionary <int, List <Local> >(); for (int i = 0; i < LocalVarsCount; i++) { Locals[i] = new Local(br, LuaVersion.Lua53Smash); if (!Locals[i].Name.StartsWith("(")) { if (!LocalMap.ContainsKey(Locals[i].Start)) { LocalMap[Locals[i].Start] = new List <Local>(); } LocalMap[Locals[i].Start].Add(Locals[i]); } } //br.ReadUInt32(); // upval names UpValuesCount = br.ReadInt32(); UpvalueNames = new UpvalueName[UpValuesCount]; for (int i = 0; i < UpValuesCount; i++) { UpvalueNames[i] = new UpvalueName(br, LuaVersion.Lua53Smash); } }