public static List <GameObject> Read(Byte[] data) { unsafe { fixed(Byte *ptr = data) { Header * header = (Header *)ptr; Group * areas = (Group *)(ptr + sizeof(Header)); Group * doors = areas + header->CountAreas; Group * modules = doors + header->CountDoors; Group * objects = modules + header->CountModules; Group * end = objects + header->CountObjects; Script * scripts = (Script *)(ptr + header->ScriptsOffset); Operation *operation = (Operation *)(ptr + header->OperationsOffset); Int64 groupNumber = end - areas; Group[] groups = new Group[groupNumber]; for (Group *group = areas; group < end; group++) { groups[--groupNumber] = *group; } List <GameObject> gameObjects = new List <GameObject>(groups.Length); foreach (Group group in groups.OrderBy(g => g.Label)) { List <GameScript> objectScripts = new List <GameScript>(group.ScriptsCount + 1); for (Int32 s = 0; s <= group.ScriptsCount; s++) { Int32 scriptLabel = group.Label + s; UInt16 position = scripts->Position; scripts++; UInt16 count = (UInt16)(scripts->Position - position); Jsm.ExecutableSegment scriptSegment = MakeScript(operation + position, count); objectScripts.Add(new GameScript(scriptLabel, scriptSegment)); } gameObjects.Add(new GameObject(group.Label, objectScripts)); } return(gameObjects); } } }
public GameScript(Int32 scriptId, Jsm.ExecutableSegment segment) { ScriptId = scriptId; Segment = segment; }