Okay so i have an old 8-bit game that loads six .dat files for different size lightmaps.
Something along the lines of this:
const
MAX_LIGHT_COUNT = 5;
LFiles : array[0..MAX_LIGHT_COUNT] of string = (
'.\L00.dat',
'.\L01.dat',
'.\L02.dat',
'.\L03.dat',
'.\L04.dat',
'.\L05.dat'
);
type
TLights = record
Width : Integer;
Height : Integer;
PDark : PByte;
end;
var
LightArr: array[0..MAX_LIGHT_COUNT] of TLights;
Procedure InitializeLight();
var
PreviousSize: Integer;
i: Integer;
fHandle: Integer;
Width, Height: Integer;
begin
PreviousSize := 0;
for i := 0 to MAX_LIGHT_COUNT do
begin
if FileExists(LFiles[i]) then
begin
fHandle := FileOpen(LFiles[i], fmOpenRead or fmShareDenyNone);
FileRead(fHandle, Width, SizeOf(Integer));
FileRead(fHandle, Height, SizeOf(Integer));
LightArr[i].Width := Width;
LightArr[i].Height := Height;
LightArr[i].PDark := AllocMem(Width * Height + 8);
if PreviousSize < Width * Height then
FileRead(fHandle, LightArr[i].PDark^, Width * Height);
PreviousSize := Width * Height;
FileClose(fHandle);
end;
end;
end;
Now i need to create an editor for some new .dat files. I had a go basically reversing whats there and using FillChar to populate the array which just ended in a square instead of the lightmaps cirlce look which makes sense, think i am missing something very important with manipulating X, Y.
Something along the lines of:
PDark := @LightArr[i].PDark;
for Y := 0 to Height - 1 do
begin
for X := 0 to Width - 1 do
begin
// Do something with PDark
end;
end;
Which would then give me that circle look.
Download: LFiles.rar if necessary.
EDIT: Sorry Jerry if it come across that way, i wasn't expecting people to write the code for me just wanted to make sure i was going in the right direction and maybe get a little help and some other stuff to try out.
NOTE: In case people get confused the attached download isn't Source files its the .dat files the game loads. Uploaded in case people wanted to see what my binary files look like compared to theirs. Basically to compare output see if on right track ect.. I dunno lol.
This is what i tried but its missing some kind of manipulation code for the circle:
for i := 0 to MAX_LIGHT_COUNT do
begin
if FileExists(LFiles[i]) then
fHandle := FileOpen(LFiles[i], fmOpenWrite or fmShareDenyNone)
else fHandle := FileCreate(LFiles[i]);
if fHandle > 0 then
begin
Width := 196;
Height := 176;
FileWrite(fHandle, Width, SizeOf(Integer));
FileWrite(fHandle, Height, SizeOf(Integer));
LightArr[i].Width := Width;
LightArr[i].Height := Height;
LightArr[i].Fog := AllocMem(Width * Height + 8);
FillChar(LightArr[i].Fog^, LightArr[i].Width * LightArr[i].Height + 8, Width * Height);
FileWrite(fHandle, LightArr[i].Fog^, Width * Height);
FileClose(fHandle);
end;
end;
Thanks for reading.