def printInfo(self): pp = PrettyPrinter() with PPWrap(pp, "Player Stats"): self.player_stats.printInfo(pp) with PPWrap(pp, "World Data"): self.worlds.printInfo(pp) with PPWrap(pp, "Player Data"): self.player_data.printInfo(pp)
def visitStatementBlockOpt_StatementMul(self, statementBlockOpt): print('{') pp.incrementTab() statementBlockOpt.statementmul.accept(self) pp.decrementTab() pp.printTab() print('}')
def visitFds_statements_withStatements(self, fds_statements): print('{') pp.incrementTab() fds_statements.inner_statement_MUL.accept(self) pp.decrementTab() pp.printTab() print('}')
def fromBinary(self, binrdr): """ Load an FCH file into memory. """ # Before we can load the data we have some validation to perform. # The file is wrapped in the following format: # # i32 data_byte_count # u8[data_byte_count] data # i32 checksum_byte_count # u8[checksum_byte_count] checksum # # The checksum is a SHA-512 of "data". The checksum is not validated # by the Valheim engine, at the time of writing. However, we're going # to validate it here if we have access to a SHA-512 algorithm. # info("Reading FCH file from disk...") byte_count = binrdr.read_i32() start_pos = binrdr.tell() # Skip the byte data for now, we'll extract the checksum first. binrdr.skip(byte_count) checksum_size = binrdr.read_i32() checksum = binrdr.read(checksum_size) # If we get here without failures, then the file is at least big enough # according to the basic check. # # Now calculate the checksum and verify the data! if _have_sha512: binrdr.push_pos(start_pos) calc_checksum = self._calculate_checksum(binrdr, byte_count) binrdr.pop_pos() if checksum != calc_checksum: pp = PrettyPrinter() pp.bytes("Disk Checksum", checksum) pp.bytes("Calculated Checksum", calc_checksum) die("Calculated checksum does not match the one loaded from " "disk!") # Checksum seems legit, lets go! binrdr.push_pos(start_pos) self.player_stats.fromBinary(binrdr) self.worlds.fromBinary(binrdr, self.player_stats.version) self.player_data.fromBinary(binrdr, self.player_stats.version) binrdr.pop_pos() info("Reading FCH file succeeded.")
def visitStatement_Global(self, statement): pp.printTab() statement._global.accept(self) print(';')
def visitStatementBlockOpt_Statement(self, statementblockopt): print() pp.incrementTab() statementblockopt.statement.accept(self) pp.decrementTab()
def visitMain_MainProgram(self, main): print('<?php') pp.incrementTab() main.mainInner.accept(self) print('?>')
def visitFuncDecStatement_Function(self, funcDecStatement): pp.printTab() print('function', end=' ') funcDecStatement.fds_id.accept(self) funcDecStatement.fds_parameter.accept(self) funcDecStatement.fds_statements.accept(self)
def visitStatementElse_Single(self, statementElse): pp.printTab() print('else',end='') statementElse.statement_BLOCK_OPT.accept(self)
def visitStatement_Break(self, statement): pp.printTab() statement._break.accept(self)
def visitStatementBlockOpt_Empty(self, statementblockopt): print('{') pp.printTab() print('}')
def visitStatement_Foreach(self, statement): pp.printTab() statement.foreach.accept(self)
def visitStatement_Die(self, statement): pp.printTab() statement.die.accept(self) print(';')
def visitStatement_Do_While(self, statement): pp.printTab() statement.dowhilee.accept(self) print(';')
def visitStatement_While(self, statement): pp.printTab() statement.whilee.accept(self)
def visitStatement_Exit(self, statement): pp.printTab() statement.exit.accept(self) print(';')
def visitStatement_Return(self, statement): pp.printTab() statement._return.accept(self)
def visitStatement_Continue(self, statement): pp.printTab() statement._continue.accept(self)
def visitDoWhileStatementSingle(self, whilestatement): print('do', end='') whilestatement.statementblockopt.accept(self) pp.printTab() print('while', end='') whilestatement.exprparentheses.accept(self)
def visitStatement_For(self, statement): pp.printTab() statement._for.accept(self)
def visitFds_statements_noStatements(self, fds_statements): print('{') pp.printTab() print('}')
def visitStatementElseIf_Mul(self, statementElseIfMul): pp.printTab() print('elseif',end='') statementElseIfMul.expr_parentheses.accept(self) statementElseIfMul.statement_BLOCK_OPT.accept(self) statementElseIfMul.statement_elseif.accept(self)
def visitStatementElseIf_Single(self, statementElseIfSingle): pp.printTab() print('elseif',end='') statementElseIfSingle.expr_parentheses.accept(self) statementElseIfSingle.statement_BLOCK_OPT.accept(self)
def toString(ast): pp = PrettyPrinter() ret = pp.toString(ast) return ret