64,639
社区成员
发帖
与我相关
我的任务
分享
program Mpq;
{$APPTYPE CONSOLE}
uses
SysUtils,
Classes
,windows
;
//Storm API
Const Storm='Storm.dll';
function SFileDestroy:LongBool;stdcall;external Storm Index 262;
function SFileOpenArchive(lpFileName: Pchar;
dwPriority: LongInt;
dwFlags: LongInt;
var hMPQ: LongWord):LongBool;stdcall;external Storm Index 266;
function SFileCloseArchive(hMPQ: LongWord):LongBool;stdcall;external Storm Index 252;
function SFileOpenFileEx(hMPQ: LongWord;
lpFileName: Pchar;
dwSearchScope: LongInt;
var hFile: LongWord): LongBool;stdcall;external Storm Index 268;
function SFileOpenFile(lpFileName: Pchar;
var hFile: LongWord): LongBool;stdcall;external Storm Index 267;
function SFileCloseFile(hFile: LongWord): LongBool;stdcall;external Storm Index 253;
function SFileGetFileSize(hFile: LongWord;
lpFileSizeHigh: LongInt{point dw null}): LongInt ;stdcall;external Storm Index 265;
function SFileReadFile(hFile: LongWord;
lpBuffe:pointer;
nNumberOfBytesToRead: LongInt;
lpNumberOfBytesRead:pointer;
lpOverlapped:pointer
): LongBool;stdcall;external Storm Index 269;
function SFileSetLocale(nNewLocale: LongWord): LongWord;stdcall;external Storm Index 272;
//主程序区
var
MyPath:string;
hmpq, //保存MPQ句柄
hf, //文件句柄
FileSize//文件大小
:LongWord;
Mem:TMemoryStream; //内存流
begin
Writeln('========================================================');
Writeln('You must type in like this:Mpq.exe MpqFileName FileName');
Writeln('For example:c:\>Mpq demo.w3m war3map.j');
Writeln('then you can extract war3map.j from demo.w3m');
Writeln('========================================================');
Writeln;
MyPath:=ExtractFilePath(ParamStr(0)); //获得自己的路径
if ((ParamStr(1)<>'')and(ParamStr(2)<>''))then //2个参数都不为空
begin
SFileDestroy; //初始化MPQ内部函数结构
SFileSetLocale($409);//设置MPQ语言
//以上2个不设置一般也没事 但是某些文件会无法读取
if SFileOpenArchive(Pchar(MyPath+(ParamStr(1))),0,0,hMPQ)then //打开Mpq文件镜像
begin
if(SFileOpenFileEx(hMPQ,Pchar(ParamStr(2)),0,hF))then //打开Mpq内部文件句柄
begin
FileSize:=SFileGetFileSize(hF,0);//获得文件大小
Mem:=TMemoryStream.Create; //创建内存流
Mem.SetSize(FileSize); //设置大小
Mem.Position:=0; //指针移动到流顶部
if SFileReadFile(hf,Mem.Memory,FileSize,nil,nil) then //读取数据到内存
begin
Mem.Position:=0; //指针移动到流顶部
Mem.SaveToFile(MyPath+"5"); //保存到文件
Writeln('File has been extract!');
end
else
begin
Writeln('Could not Read Data!');
end;
Mem.Free;
SFileCloseFile(hF);//关闭文件句柄
end
else
begin
Writeln('Could not open file in Mpq Archive!');
end;
end
else //打开失败
begin
Writeln('Could not open Mpq Archive!');
end;
SFileCloseArchive(hMPQ);//关闭MPQ句柄
end
else
begin
Writeln('You should type in command!');
end;
end.