def __init__(self, file, pos): super().__init__(file, pos); pos += 8 _xModes = { 0: "Center", 1: "Left", 2: "Right", } _yModes = { 0: "Center", 1: "Top", 2: "Bottom", } (self.flag, self.basePosition, self.alpha, self.flagEx, nameBytes, userDataBytes) = struct.unpack_from('>4B24s8s', file, pos); pos += 36 self.name = readString(nameBytes) self.userData = readString(userDataBytes) _printPan("\nPane name: %s" % self.name) _printPan("Pane visible:", bool(self.flag & 1)) _printPan("Pane influenced alpha:", bool((self.flag >> 1) & 1)) _printPan("Pane location adjust:", bool((self.flag >> 2) & 1)) _printPan("Pane hidden (in editor?):", bool((self.flag >> 7) & 1)) ignorePartsMagnify = bool(self.flagEx & 1) _printPan("Pane ignore parts magnify:", ignorePartsMagnify) if not ignorePartsMagnify: _printPan("Pane parts magnify influence:", bool((self.flagEx >> 1) & 1)) parentRelativeY = (self.basePosition >> 6) & 3 parentRelativeX = (self.basePosition >> 4) & 3 baseY = (self.basePosition >> 2) & 3 baseX = self.basePosition & 3 _printPan("Pane base X position:", _xModes[baseX]) _printPan("Pane base Y position:", _xModes[baseY]) _printPan("Pane parent-relative X position:", _xModes[parentRelativeX]) _printPan("Pane parent-relative Y position:", _xModes[parentRelativeY]) self.translate = struct.unpack_from('>3f', file, pos); pos += 12 self.rotate = struct.unpack_from('>3f', file, pos); pos += 12 self.scale = struct.unpack_from('>2f', file, pos); pos += 8 self.size = struct.unpack_from('>2f', file, pos); pos += 8 _printPan("Pane translation:", self.translate) _printPan("Pane rotation:", self.rotate) _printPan("Pane scale:", self.scale) _printPan("Pane size:", self.size) self.parent = None self.childList = []
def __init__(self, file, pos): initPos = pos super().__init__(file, pos); pos += 84 (self.textBufBytes, self.textStrBytes, self.materialIdx, self.fontIdx, self.textPosition, self.textAlignment, self.textBoxFlag, self.italicRatio, self.textStrOffset) = struct.unpack_from('>4H3BxfI', file, pos); pos += 20 self.readTextBoxFlag() self.textCols = [struct.unpack_from('>4B', file, pos + 4*i) for i in range(2)]; pos += 8 self.fontSize = struct.unpack_from('>2f', file, pos); pos += 8 (self.charSpace, self.lineSpace, self.textIDOffset) = struct.unpack_from('>2fI', file, pos); pos += 12 self.shadowOffset = struct.unpack_from('>2f', file, pos); pos += 8 self.shadowScale = struct.unpack_from('>2f', file, pos); pos += 8 self.shadowCols = [struct.unpack_from('>4B', file, pos + 4*i) for i in range(2)]; pos += 8 (self.shadowItalicRatio, self.perCharacterTransformOffset) = struct.unpack_from('>fI', file, pos); pos += 8 pos = initPos + self.textStrOffset if self.forceAssignTextLength: self.text = readString(file[pos:pos + self.textStrBytes], 0, 2, 'utf-16be') else: self.text = readString(file[pos:pos + self.textBufBytes], 0, 2, 'utf-16be') pos = initPos + self.textIDOffset self.textID = readString(file, pos) self.perCharacterTransform = None if self.perCharacterTransformEnabled: if self.perCharacterTransformOffset: pos = initPos + self.perCharacterTransformOffset self.perCharacterTransform = self.PerCharacterTransform(file, pos); pos += 12 if self.perCharacterTransform.hasAnimationInfo: self.perCharacterTransformAnimationInfo = FLAN.AnimationBlock.AnimationContent.AnimationInfo(file, pos) else: print("Whoopsie-daisy") self.perCharacterTransformEnabled = False
def __init__(self, file, pos, major): initPos = pos super().__init__(file, pos) pos += 8 (self.tagOrder, self.groupNum, self.nameOffset, self.groupsOffset, self.startFrame, self.endFrame, self.flag) = struct.unpack_from('>2H2I2hB', file, pos) # flag & 1 -> ANIMTAGFLAG_DESCENDINGBIND pos = initPos + self.nameOffset self.name = readString(file, pos) pos = initPos + self.groupsOffset self.groups = [] if major < 5: fmt = '>24sB3x' size = 28 else: fmt = '>33sB2x' size = 36 for _ in range(self.groupNum): self.groups.append(self.AnimationGroupRef(file, pos, fmt)) pos += size
def __init__(self, file, pos): super().__init__(file, pos) self.texNum = struct.unpack_from('>H', self.data)[0] self.textures = [] self.formats = [] if self.texNum: _printTex("Textures:") for i in range(self.texNum): pTexture = struct.unpack_from('>I', self.data, 4 * (i+1))[0] + 4 texture = readString(self.data, pTexture) format = "" assert texture[-6:] == ".bflim" texture = texture[:-6] if len(texture) > 2: if texture[-1] in 'abcdefghijklmnopqrstu' and texture[-2] == "^": format = texture[-1:] texture = texture[:-2] _printTex(texture) self.textures.append(texture) self.formats.append(format) if self.texNum: _printTex()
def parse_file(self, file_path): passport_separator = re.compile( '\n{2}') # Separates distinct passports field_separator = re.compile( ' |\n') # Separates fields within a single passport key_val_separator = re.compile( ':') # Separates the key/value pairs of a given field input_string = readString(file_path) input_list = re.split(passport_separator, input_string) for passport_string in input_list: field_list = re.split(field_separator, passport_string) passport_dict = {} for field in field_list: if not field: # bug in parsing causes empty string continue key, value = re.split(key_val_separator, field) passport_dict[key] = value try: passport = PassportAdapter(**passport_dict) if self.validate: # Part 2 passport.validate_inputs() self.valid_passports.append(passport) except TypeError as e: # This try/catch should be used with care. Could easily swallow a legitimate exception, making the # validation harder to debug. self.invalid_passports.append(passport_dict)
def __init__(self, file, pos): self.userData = readString(struct.unpack_from('>8s', file, pos)[0]); pos += 8 self.translate = struct.unpack_from('>3f', file, pos); pos += 12 self.rotate = struct.unpack_from('>3f', file, pos); pos += 12 self.scale = struct.unpack_from('>2f', file, pos); pos += 8 self.size = struct.unpack_from('>2f', file, pos); pos += 8 self.alpha = file[pos]
def __init__(self, file, pos): super().__init__(file, pos) (self.originType, self.layoutWidth, self.layoutHeight, self.partsWidth, self.partsHeight) = struct.unpack_from('>B3x4f', self.data) self.name = readString(self.data, 0x14)
def __init__(self, file, pos, major): super().__init__(file, pos); pos += 8 if major < 5: fmt = '>24sH2x' size = 28 else: fmt = '>33sxH' size = 36 (nameBytes, self.paneNum) = struct.unpack_from(fmt, file, pos); pos += size self.name = readString(nameBytes) self.panes = [] for i in range(self.paneNum): pane = readString(struct.unpack_from('>24s', file, pos + 24*i)[0]) self.panes.append(pane)
def __init__(self, file, pos): (self.nameStrOffset, self.dataOffset, self.num, self.type) = struct.unpack_from('>2IHB', file, pos) self.name = readString(file, pos + self.nameStrOffset) self.data = [] if self.dataOffset: if self.type == 0: tempPos = pos + self.dataOffset for _ in range(self.num): _string = readString(file, tempPos); tempPos += len(string) + 1 self.data.append(_string) elif self.type == 1: self.data = struct.unpack_from('>%di' % self.num, file, pos + self.dataOffset) elif self.type == 2: self.data = struct.unpack_from('>%df' % self.num, file, pos + self.dataOffset)
def __init__(self, file, pos): initPos = pos super().__init__(file, pos); pos += 84 self.propertyNum, = struct.unpack_from('>I', file, pos); pos += 4 self.magnify = struct.unpack_from('>2f', file, pos); pos += 8 self.properties = [self.PartsProperty(file, initPos, pos + 40*i) for i in range(self.propertyNum)] pos += 40 * self.propertyNum self.filename = readString(file, pos) assert self.filename
def __init__(self, file, pos): initPos = pos _types = ["Pane", "Material"] (nameBytes, self.num, self.type) = struct.unpack_from('>28s2B', file, pos) pos += 32 self.name = readString(nameBytes) #print(self.name) animInfoOffsets = struct.unpack_from('>%dI' % self.num, file, pos) self.animInfos = [] for pAnimInfo in animInfoOffsets: self.animInfos.append( self.AnimationInfo(file, initPos + pAnimInfo))
def __init__(self, file, initPos, pos): (nameBytes, self.usageFlag, self.basicUsageFlag, self.propertyOffset, self.extUserDataOffset, self.paneBasicInfoOffset) = struct.unpack_from('>24s2B2x3I', file, pos) self.name = readString(nameBytes) self.property = None if self.propertyOffset: self.property = readPane(file, initPos + self.propertyOffset) self.extUserData = None if self.extUserDataOffset: self.extUserData = FLYT.ExtUserDataList.ExtUserData(file, initPos + self.extUserDataOffset) self.basicInfo = None if self.paneBasicInfoOffset: self.basicInfo = self.PartsPaneBasicInfo(file, initPos + self.paneBasicInfoOffset)
def __init__(self, file, pos): super().__init__(file, pos) self.fontNum = struct.unpack_from('>H', self.data)[0] self.fonts = [] if self.fontNum: _printFnt("Fonts:") for i in range(self.fontNum): pFont = struct.unpack_from('>I', self.data, 4 * (i+1))[0] + 4 font = readString(self.data, pFont) assert font[-6:] == ".bffnt" font = font[:-6] _printFnt(font) self.fonts.append(font) if self.fontNum: _printFnt()
def __init__(self, file, pos): initPos = pos super().__init__(file, pos) pos += 8 (self.frameSize, self.loop, self.fileNum, self.animContNum, animContOffsetsOffset) = struct.unpack_from('>HBx2HI', file, pos) pos += 12 self.fileNames = [] self.formats = [] for i in range(self.fileNum): pFileName, = struct.unpack_from('>I', file, pos + 4 * i) fileName = readString(file, pos + pFileName) format = "" assert fileName[-6:] == ".bflim" fileName = fileName[:-6] if len(fileName) > 2: if fileName[-1] in 'abcdefghijklmnopqrstu' and fileName[ -2] == "^": format = fileName[-1:] fileName = fileName[:-2] self.fileNames.append(fileName) self.formats.append(format) pos = initPos + animContOffsetsOffset animContOffsets = struct.unpack_from('>%dI' % self.animContNum, file, pos) self.animConts = [] for pAnimCont in animContOffsets: self.animConts.append( self.AnimationContent(file, initPos + pAnimCont))
def __init__(self, file, pos): try: self.name = readString(file[pos:pos + 28]) pos += 28 except: _printMat(hex(pos)) raise Exception from None if not self.name: _printMat(hex(pos - 28)) raise Exception from None self.color0 = struct.unpack_from('>4B', file, pos); pos += 4 self.color1 = struct.unpack_from('>4B', file, pos); pos += 4 self.resNum = struct.unpack_from('>I', file, pos)[0]; pos += 4 self.readResNum() _printMat('\n%s' % self.name) _printMat("Black Color:", self.color0) _printMat("White Color:", self.color1) _printMat("Resource Flags: %s" % bin(self.resNum)) self.resTexMaps = [] for i in range(self.texNum): self.resTexMaps.append(self.TexMap(file, pos)) pos += 4 self.texSRTs = [] for i in range(self.texSRTNum): self.texSRTs.append(self.TexSRT(file, pos)) pos += 20 self.texCoordGen = [] for i in range(self.texCoordGenNum): self.texCoordGen.append(self.TexCoordGen(file, pos)) pos += 8 self.tevStages = [] for i in range(self.tevStageNum): self.tevStages.append(self.TevStage(file, pos)) pos += 4 self.alphaCompare = None if self.hasAlphaCompare: self.alphaCompare = self.AlphaCompare(file, pos) pos += 8 self.blendType = "None" self.blendMode = None if self.hasBlendMode: self.blendType = "Blend" self.blendMode = self.BlendMode(file, pos) pos += 4 self.blendModeAlpha = None if self.isSeparateBlendMode: self.blendType = "Logic" self.blendModeAlpha = self.BlendMode(file, pos, True) pos += 4 self.indirectParameter = None if self.hasIndirectParameter: self.indirectParameter = self.IndirectParameter(file, pos) pos += 12 self.projectionTexGenParameters = [] for i in range(self.projectionTexGenNum): self.projectionTexGenParameters.append(self.ProjectionTexGenParamaters(file, pos)) pos += 20 if self.hasFontShadowParameter: self.fontShadowParameter = self.FontShadowParameter(file, pos) pos += 8 numProjectionTexGen = 0 for i in range(self.texCoordGenNum): if self.texCoordGen[i].texGenSrc in [3, 4, 5]: self.texCoordGen[i].projectionTexGenParameter = self.projectionTexGenParameters[numProjectionTexGen] numProjectionTexGen += 1
def __init__(self, file, pos, major): super().__init__(file, pos) self.extUserDataList = None if major < 3: (self.controlFunctionalPaneNamesOffset, self.controlFunctionalPaneNum, self.controlFunctionalAnimNum) = struct.unpack_from('>I2H', self.data); pos = 8 self.controlUserNameOffset = 0 self.controlFunctionalPaneParameterNameOffsetsOffset = 0 self.controlFunctionalAnimParameterNameOffsetsOffset = 0 else: (self.controlUserNameOffset, self.controlFunctionalPaneNamesOffset, self.controlFunctionalPaneNum, self.controlFunctionalAnimNum, self.controlFunctionalPaneParameterNameOffsetsOffset, self.controlFunctionalAnimParameterNameOffsetsOffset) = struct.unpack_from('>2I2H2I', self.data); pos = 20 self.controlName = readString(self.data, pos) self.controlUserName = '' if self.controlUserNameOffset: pos = self.controlUserNameOffset - 8 self.controlUserName = readString(self.data, pos) if not self.controlUserName: self.controlUserName = self.controlName self.controlFunctionalPaneNames = [] if self.controlFunctionalPaneNamesOffset: pos = self.controlFunctionalPaneNamesOffset - 8 for i in range(self.controlFunctionalPaneNum): name = readString(struct.unpack_from('>24s', self.data, pos)[0]); pos += 24 self.controlFunctionalPaneNames.append(name) else: pos -= 8 self.controlFunctionalAnimNames = [] for i in range(self.controlFunctionalAnimNum): pName = pos + struct.unpack_from('>I', self.data, pos + 4*i)[0] self.controlFunctionalAnimNames.append(readString(self.data, pName)) self.controlFunctionalPaneParameterNames = [] if self.controlFunctionalPaneParameterNameOffsetsOffset: pos = self.controlFunctionalPaneParameterNameOffsetsOffset - 8 for i in range(self.controlFunctionalPaneNum): pName = pos + struct.unpack_from('>I', self.data, pos + 4*i)[0] self.controlFunctionalPaneParameterNames.append(readString(self.data, pName)) self.controlFunctionalAnimParameterNames = [] if self.controlFunctionalAnimParameterNameOffsetsOffset: pos = self.controlFunctionalAnimParameterNameOffsetsOffset - 8 for i in range(self.controlFunctionalAnimNum): pName = pos + struct.unpack_from('>I', self.data, pos + 4*i)[0] self.controlFunctionalAnimParameterNames.append(readString(self.data, pName)) if major < 3: self.controlFunctionalPaneParameterNames = self.controlFunctionalPaneNames self.controlFunctionalAnimParameterNames = self.controlFunctionalAnimNames
def __init__(self, file, pos, fmt): (nameBytes, self.flag) = struct.unpack_from(fmt, file, pos) self.name = readString(nameBytes) self.fmt = fmt
def __init__(self, file, pos): (srcPaneNameBytes, targetGroupNameBytes) = struct.unpack_from( '>25s25s', file, pos) self.srcPaneName = readString(srcPaneNameBytes) self.targetGroupName = readString(targetGroupNameBytes)
def getGroups(): return splitObjects(readString())