-
Notifications
You must be signed in to change notification settings - Fork 9
/
UnpackPAK(PB).1sc
74 lines (68 loc) · 1.8 KB
/
UnpackPAK(PB).1sc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
//------------------------------------------------
//--- 010 Editor v8.0.1 Script File
//
// File: UnpackPAK(PB).1sc
// Authors: Alexander Evdokimov
// Version: 0.1
// Purpose: Unpack Privateer’s Bounty .pak files
// File Mask: *.1sc
//
//------------------------------------------------
local uint pos, prevpos, i, k, datasize, length, FolderCount, FileCount, FileIndex = 0;
local string FileName, Path, FolderName;
local uchar Buffer[10485760];
local int offset = 0;
// set working directory
FileIndex = GetFileNum();
FileName = GetFileName();
local string rootdirname = FileNameGetBase(FileName) + "_unpacked";
Path = FileNameGetPath(FileName) + rootdirname;
MakeDir(Path);
SetWorkingDirectory(Path);
FSkip(10);
FSeek(ReadInt()); // jump to File Table
FolderCount = ReadInt();
FSkip(4);
// get file section position
prevpos = FTell();
for ( i = 0; i < FolderCount ; ++i )
{
FSkip(4);
length = ReadStringLength(FTell());
FSkip(length);
};
pos = FTell();
FSeek(prevpos);
// reading file table
local uint Folders[FolderCount];
for ( k = 0; k < FolderCount ; ++k )
{
FileCount = ReadInt();
FSkip(4);
length = ReadStringLength(FTell());
FolderName = ReadString(FTell());
FSkip(length);
MakeDir(GetWorkingDirectory() + FolderName);
prevpos = FTell();
FSeek(pos);
// unpacking to current folder
for ( i = 0; i < FileCount; ++i )
{
datasize = ReadInt();
FSkip(4);
offset = ReadInt();
FSkip(8);
length = ReadStringLength(FTell());
FileName = ReadString(FTell());
FSkip(length);
// create and save file to directory
ReadBytes(Buffer, offset, datasize);
FileNew();
WriteBytes(Buffer, 0, datasize);
FileSave(GetWorkingDirectory() + FolderName + "\\" + FileName);
FileClose();
FileSelect(FileIndex);
};
pos = FTell();
FSeek(prevpos);
};