-
Notifications
You must be signed in to change notification settings - Fork 9
/
UnpackPAK.1sc
89 lines (84 loc) · 2.06 KB
/
UnpackPAK.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
//------------------------------------------------
//--- 010 Editor v8.0.1 Script File
//
// File:
// Authors:
// Version:
// Purpose:
// Category:
// History:
//------------------------------------------------
local uchar Buffer[10485760];
local string rootdir = FileNameGetBase(GetFileName()) + "_unpacked";
local uint type, datasize, length, count, i, level = 0;
local int offset = 0;
local string Name;
local string Path;
local int FileIndex;
local uchar FolderEnd = false;
FileIndex = GetFileNum();
Name = GetFileName();
Path = FileNameGetPath(Name) + rootdir;
MakeDir(Path); // current dir
SetWorkingDirectory(Path);
FSkip(6); // skip Header
level = ReadShort(FTell());
FSkip(20);
void fileTree(uint filecount, string folder) {
local string fp = folder;
for ( i = 0; i < filecount; ++i ) {
type = ReadByte();
FSkip(1);
if (type == 1) // file
{
datasize = ReadInt();
FSkip(4);
offset = ReadInt();
FSkip(12);
Name = ReadString(FTell());
length = ReadStringLength(FTell());
FSkip(length);
// create and save file to directory
ReadBytes(Buffer, offset, datasize);
FileNew();
WriteBytes(Buffer, 0, datasize);
FileSave(fp + "\\" + Name);
FileClose();
// back to pak file
FileSelect(FileIndex);
}
else if (type == 0) // folder
{
count = ReadInt();
FSkip(16);
Name = ReadString(FTell());
length = ReadStringLength(FTell());
//if (folder == "")
// Path = GetWorkingDirectory() + Name;
//else
Path = fp + "\\" + Name;
MakeDir(Path);
FSkip(length);
FolderEnd = false;
if (count)
fileTree(count, Path);
else
fileTree(1, Path);
}
else if (type == 2)
{
FSkip(8);
if (ReadInt() == 1)
{
if (level == 2)
{
fp = GetWorkingDirectory();
};
FSkip(9);
fileTree(1, fp);
};
FSkip(9); // skip "folder end"
}
};
};
fileTree(1, Path);