Skip to content

Commit 43f4b3d

Browse files
committed
Added big file related codes (I get segfault from .big library)
1 parent 0217b9b commit 43f4b3d

File tree

3 files changed

+120
-10
lines changed

3 files changed

+120
-10
lines changed

AboutBig.txt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
The big file decoding code is from OS BIG Editor from PPM:
2+
http://www.ppmsite.com/?go=osbigeditorinfo
3+
4+
///////////////////////////////////////////////////////////////////////////////////////
5+
////// About Open Source BIG Editor
6+
///////////////////////////////////////////////////////////////////////////////////////
7+
8+
OS BIG Editor is a program made to view BIG files and it will be able to create and edit them as well.
9+
10+
This program was created and coded by Carlos "Banshee" Muniz and the RefPack decompression was coded by Johnathan Wilson (jonwil).
11+
12+
The following people contributed to add features for this program:
13+
14+
-> Danny van Loon (Drag .BIG files and Drop in the program. He also found the Drag and Drop component used in the program - v0.5)
15+
-> Zlatko Minev (coded the TGA Viewer - v0.5)
16+
-> Stuart "Stucuk" Carey (There are several things from Voxel Section Editor III and SHP Builder that he coded and were used in this program - all versions).
17+
18+
You are free to distribute, sell, use and modify this program. However, if you distribute, sell or modify this program you must credit Banshee for coding it and jonwil for the RefPack decompression. Modifying this AboutMe file is forbidden, unless authorized by Banshee, from http://www.ppmsite.com.
19+
20+
Note: The RefPack decompression code from jonwil follows GNU General Public Liscense and programs using it must be open source. If you want to modify this program and keep the code exclusive for you, make sure you remove the RefPack decompression code and code your own.

src/BasicDataTypes.pas

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
unit BasicDataTypes;
2+
3+
interface
4+
5+
type
6+
int8 = shortint;
7+
pint8 = ^shortint;
8+
uint8 = byte;
9+
puint8 = ^byte;
10+
int16 = smallint;
11+
pint16 = ^smallint;
12+
uint16 = word;
13+
puint16 = ^word;
14+
int32 = longint;
15+
pint32 = ^longint;
16+
uint32 = longword;
17+
puint32 = ^longword;
18+
19+
20+
implementation
21+
22+
end.

src/mainform.pas

Lines changed: 78 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ interface
66

77
uses
88
Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs,
9-
StdCtrls, ExtCtrls, Process, Windows,
9+
StdCtrls, ExtCtrls, Process, Windows, jsonConf,
1010
// my additions
11-
Common, Settings;
11+
Common, Settings, BIG_File;
1212

1313
type
1414

@@ -36,6 +36,9 @@ TFormMain = class(TForm)
3636
active_mod: string; // remembers what mod is active now.
3737

3838
procedure ScanMods();
39+
function HasModAI( mod_name: string ): integer;
40+
function ScanZbigsForAI( mod_path: string ): integer;
41+
procedure ProcessMod( info : TSearchRec );
3942
procedure ScanScripts(); // scan scripts folder in the game & update UI
4043
procedure LaunchGame( mod_name:string; params: string );
4144

@@ -86,14 +89,9 @@ procedure TFormMain.ScanMods();
8689
// scan the dirs in gamedir/Mods
8790
mod_dir := IncludeTrailingPathDelimiter(settings.game_dir)+'Mods';
8891
If FindFirst( mod_dir + '\*', faAnyFile and faDirectory, info ) = 0 then
89-
begin
9092
Repeat
91-
if (info.Name <> '.') AND (info.Name <> '..') then
92-
begin
93-
ModList.Items.Add( info.Name );
94-
end;
93+
ProcessMod( info );
9594
Until FindNext(info) <> 0;
96-
end;
9795
SysUtils.FindClose( info );
9896

9997
if( ModList.Items.Count = 0 ) then
@@ -102,6 +100,78 @@ procedure TFormMain.ScanMods();
102100
ModList.ItemIndex:= 0; // select 1st item.
103101
end;
104102

103+
// Scan .zbig files in the mod dir and determine if the mod has AI.
104+
function TFormMain.HasModAI(mod_name: string): integer;
105+
var
106+
mod_path: string;
107+
mconf: TJSONConfig;
108+
begin
109+
result := 0; // by default, not have one.
110+
111+
// First, see the config file first?
112+
// Find zbigs in the game/Mods/mod_name then move it to game dir.
113+
mod_path := IncludeTrailingPathDelimiter(settings.game_dir) +
114+
'Mods\' + mod_name + '\';
115+
116+
mconf := TJSONConfig.Create(nil);
117+
mconf.Filename := mod_path + 'config.json';
118+
result := mconf.GetValue( 'has_ai', -1 );
119+
120+
// If we get -1 as result, that means,
121+
// this is the first time scanning this mod.
122+
if result = -1 then
123+
begin
124+
result := ScanZbigsForAI( mod_path );
125+
126+
// write it so that I don't have to do zbig scan again.
127+
//mconf.SetValue( 'has_ai', result );
128+
end;
129+
// else, the result read from the config is correct.
130+
131+
mconf.free;
132+
end;
133+
134+
function TFormMain.ScanZbigsForAI(mod_path: string): integer;
135+
var
136+
info: TSearchRec;
137+
big: TBIGPackage;
138+
f: TBIGFileUnit;
139+
i, cnt: integer;
140+
begin
141+
result := 0;
142+
If FindFirst( mod_path + '*.zbig', faAnyFile, info ) = 0 then
143+
144+
Repeat
145+
// Scan the contents
146+
ShowMessage( info.name );
147+
148+
big.Create;
149+
big.LoadFile( info.name );
150+
cnt := big.GetNumFiles;
151+
for i := 0 to cnt-1 do
152+
begin
153+
f := big.GetFileInfo( i );
154+
// f.Filename should be used :)
155+
end;
156+
big.Free;
157+
Until FindNext(info) <> 0;
158+
159+
SysUtils.FindClose( info );
160+
end;
161+
162+
procedure TFormMain.ProcessMod(info: TSearchRec);
163+
var
164+
has_ai: integer; // I want this to be boolean but I can't
165+
// Cant make TObject contain boolean...
166+
begin
167+
if (info.Name <> '.') AND (info.Name <> '..') then
168+
begin
169+
//ModList.Items.Add( info.Name );
170+
has_ai := HasModAI( info.Name );;
171+
ModList.AddItem( info.name, TObject( has_ai ) );
172+
end;
173+
end;
174+
105175
// Initialization of the program (?),
106176
// at least this form.
107177
procedure TFormMain.FormCreate(Sender: TObject);
@@ -148,12 +218,10 @@ procedure TFormMain.ActivateMod( mod_name: string );
148218
'Mods\' + mod_name + '\';
149219

150220
If FindFirst( mod_path + '*.zbig', faAnyFile, info ) = 0 then
151-
begin
152221
Repeat
153222
// Add them to the mod zbig files list.
154223
zbigs.Add( info.name );
155224
Until FindNext(info) <> 0;
156-
end;
157225
SysUtils.FindClose( info );
158226

159227
// For each items in zbigs, move the file to the game dir.

0 commit comments

Comments
 (0)