Created
June 5, 2013 13:13
-
-
Save hoehrmann/5713747 to your computer and use it in GitHub Desktop.
Final Fantasy VII (PC) .lgp package file extractor, anno 1998.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
program LgpUnp; | |
(* Extracts Files from SquareSoft's Final Fantasy VII .LGP files *) | |
(* Copyright (c) 1998 by Bjoern Hoehrmann All rights reserved *) | |
var Index:record { Entry in the filelist at the beginning } | |
Name:array[0..19] of char; { Filename } | |
offset:longint; { FileOffset of this file } | |
res:longint; { Unused Data } | |
end; | |
FData:record { Pre File Data Entry } | |
name:array[0..19] of char; { Again Filename } | |
length:longint; { Filesize } | |
end; | |
LGPfile:file; { Input LGP File } | |
OutputFile:file; { Output ??? File } | |
anz:word; { Number of files in the lgp } | |
i:integer; { Couter Variable } | |
fullsize:longint; | |
ressize:longint; | |
buf1:array[0..29999] of byte; { Buffer for fast file extract } | |
fpos:longint; { Var to store the fileposition } | |
procedure ShowHelpScreen; { Show a little HelpScreen for dumbs. } | |
begin | |
WriteLn(' '); | |
WriteLn(' LgpUnp v1.1 Copyright (c) 1998 by Bjoern Hoehrmann'); | |
WriteLn(' ──────────────────────────────────────────────────────────────────────────────'); | |
WriteLn(' LgpUnp is a little utility to extract Files from SquareSoft''s Final Fantasy '); | |
WriteLn(' VII .Lgp files. '); | |
WriteLn(' ──────────────────────────────────────────────────────────────────────────────'); | |
WriteLn(' /? - Shows this little help screen '); | |
WriteLn(' ──────────────────────────────────────────────────────────────────────────────'); | |
WriteLn(' Usage: LGPUNP.EXE LGPFILE.LGP '); | |
WriteLn(' ──────────────────────────────────────────────────────────────────────────────'); | |
WriteLn(' I''m searching for fileformat descriptions on all FF7 FileFormats. If you can'); | |
WriteLn(' help me, send me an Email. I would be pleased '); | |
WriteLn(' For any comment or a bug report contact [email protected]. '); | |
WriteLn(' ──────────────────────────────────────────────────────────────────────────────'); | |
end; | |
begin | |
Showhelpscreen; | |
if paramcount<>1 then exit; { Check for .LGP File } | |
assign(LGPfile,Paramstr(1)); { Define the .LGP File } | |
reset(LGPfile,1); | |
seek(LGPfile,$c); { Jump to the anz-word } | |
blockread(LGPfile,anz,sizeof(anz)); { Read it } | |
seek(LGPfile,$10); { Jump to the FileIndex } | |
fpos:=filepos(LGPfile); { Store FilePos } | |
for i:=1 to anz do begin { Loop to go through the FileIndex } | |
seek(LGPfile,fpos); { Go back to the last position } | |
Blockread(LGPfile,index,sizeof(index)); { Read Index Entry } | |
if 1=1 then begin { Check if you should extract this File } | |
fpos:=filepos(LGPfile)-1; { Save New Fileposition } | |
seek(LGPfile,index.offset); { Go to the Files offset } | |
blockread(LGPfile,FData,sizeof(FData));{ Read the pre Data Entry } | |
assign(OutputFile,FData.name); { Assign the Filename } | |
rewrite(OutputFile,1); { Create the new file } | |
fullsize:=FData.length; { Define the DataSize } | |
repeat { Transfer the Data into the File} | |
if fullsize>30000 then ressize:=30000 else ressize:=fullsize; | |
BlockRead(LGPfile,buf1,ressize); | |
BlockWrite(OutputFile,buf1,ressize); | |
dec(fullsize,ressize); | |
until ressize=0; | |
close(OutputFile); { Close the Created File } | |
end; { End of this File Extraction } | |
end; { All Indexentrys were checked } | |
close(LGPfile); { Close the LGP File } | |
end. { End of this fine Proggi } | |
{ NO UNAUTHORISED MODIFIKATION, OR YOUR COMPUTER WILL EXPLODE. THANKS } | |
{ LAST EDIT: WEDNESDAY, 21ST OCTOBER 1998 } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <string.h> | |
#pragma warning(disable:4244) | |
typedef struct { | |
char name[20]; | |
long offset,res; | |
} xIndex; | |
typedef struct { | |
char name[20]; | |
long length; | |
} xFData; | |
FILE *LGPfile, *OutputFile; | |
unsigned short anz; | |
unsigned char buf1[65536]; | |
long fullsize, ressize; | |
fpos_t fpos; | |
xIndex Index; | |
xFData FData; | |
int main(int argc, char* argv[]) { | |
if ((LGPfile = fopen(argv[1], "rb+"))== NULL){ | |
printf("Cannot open input file.\n"); | |
return 1; | |
} | |
fseek(LGPfile, 0xc, SEEK_SET); | |
fread(&anz, sizeof(anz), 1, LGPfile); | |
fseek(LGPfile, 0x10, SEEK_SET); | |
fgetpos(LGPfile, &fpos); | |
fpos++; | |
for (int i=1; i <= anz; i++) { | |
fseek(LGPfile, fpos-1, SEEK_SET); | |
fread(&Index, sizeof(Index), 1, LGPfile); | |
if (1==1) { | |
fgetpos(LGPfile, &fpos); | |
fseek(LGPfile, Index.offset, SEEK_SET); | |
fread(&FData, sizeof(FData), 1, LGPfile); | |
if (strstr(_strlwr(_strdup(FData.name)),argv[2])!=0){ | |
printf("Extracting %s%s\n", FData.name,"..."); | |
OutputFile=fopen(FData.name, "wb+"); | |
fullsize=FData.length; | |
ressize=1; | |
for (;ressize!=0;) { | |
if (fullsize>sizeof(buf1)) ressize=sizeof(buf1); else ressize=fullsize; | |
fread(&buf1, ressize, 1, LGPfile); | |
fwrite(&buf1, ressize, 1, OutputFile); | |
fullsize=fullsize-ressize; | |
ressize=fullsize; | |
} | |
fclose(OutputFile); | |
}// if... | |
} | |
} | |
fclose(LGPfile); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment