* Clears the given scriptInfo. * * @param filename The name of the file to load. * @param scriptInfo The scriptInfo to load in the script. * @param functions Pointer to the functions to call via script. * @param data Pointer to preallocated space to load data. */
| 615 | * @param data Pointer to preallocated space to load data. |
| 616 | */ |
| 617 | uint16 Script_LoadFromFile(const char *filename, ScriptInfo *scriptInfo, const ScriptFunction *functions, uint8 *data) |
| 618 | { |
| 619 | uint32 total = 0; |
| 620 | uint32 length = 0; |
| 621 | uint8 index; |
| 622 | int16 i; |
| 623 | |
| 624 | if (scriptInfo == NULL) return 0; |
| 625 | if (filename == NULL) return 0; |
| 626 | |
| 627 | Script_ClearInfo(scriptInfo); |
| 628 | |
| 629 | scriptInfo->isAllocated = (data == NULL); |
| 630 | |
| 631 | scriptInfo->functions = functions; |
| 632 | |
| 633 | if (!File_Exists(filename)) return 0; |
| 634 | |
| 635 | index = ChunkFile_Open(filename); |
| 636 | |
| 637 | length = ChunkFile_Seek(index, HTOBE32(CC_TEXT)); |
| 638 | total += length; |
| 639 | |
| 640 | if (length != 0) { |
| 641 | if (data != NULL) { |
| 642 | scriptInfo->text = (uint16 *)data; |
| 643 | data += length; |
| 644 | } else { |
| 645 | scriptInfo->text = calloc(1, length); |
| 646 | } |
| 647 | |
| 648 | ChunkFile_Read(index, HTOBE32(CC_TEXT), scriptInfo->text, length); |
| 649 | } |
| 650 | |
| 651 | length = ChunkFile_Seek(index, HTOBE32(CC_ORDR)); |
| 652 | total += length; |
| 653 | |
| 654 | if (length == 0) { |
| 655 | Script_ClearInfo(scriptInfo); |
| 656 | ChunkFile_Close(index); |
| 657 | return 0; |
| 658 | } |
| 659 | |
| 660 | if (data != NULL) { |
| 661 | scriptInfo->offsets = (uint16 *)data; |
| 662 | data += length; |
| 663 | } else { |
| 664 | scriptInfo->offsets = calloc(1, length); |
| 665 | } |
| 666 | |
| 667 | scriptInfo->offsetsCount = (length >> 1) & 0xFFFF; |
| 668 | ChunkFile_Read(index, HTOBE32(CC_ORDR), scriptInfo->offsets, length); |
| 669 | |
| 670 | for(i = 0; i < (int16)((length >> 1) & 0xFFFF); i++) { |
| 671 | scriptInfo->offsets[i] = BETOH16(scriptInfo->offsets[i]); |
| 672 | } |
| 673 | |
| 674 | length = ChunkFile_Seek(index, HTOBE32(CC_DATA)); |
no test coverage detected