0

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.

Se7en
  • 33
  • 1
  • 5
  • What have you tried so far and where did it fail? You shouldn't expect people on Stack Overflow to write your code for you, you need to do your best to do it yourself, and when you get stuck on something, ask for that specific issue including the code which didn't work. This is a "fill in the blank" question which isn't usually acceptable here. – Jerry Dodge Jan 18 '14 at 00:07
  • Edited my post Jerry, hope this helps now sorry. – Se7en Jan 18 '14 at 00:53
  • Retracted my close vote. – Jerry Dodge Jan 18 '14 at 00:55
  • Why not convert it to use a flat file such as INI? – Jerry Dodge Jan 18 '14 at 00:57
  • Dunno, i only use .ini files for like Sound enabled or disabled ect.. this .dat file is like a chunk of data. 1st 8 bytes are Width and Height, rest seems PDark output. With my example in game i get a square the size of my Width and Height, with the original file i get a circle looking thing with the sides kind of shaded and middle light. – Se7en Jan 18 '14 at 01:00
  • This can be easily implemented in INI, so long as there isn't any actual binary data being saved to it. This looks like all raw text, INI can make this extremely easy. And all 5 files can be combined into 1. – Jerry Dodge Jan 18 '14 at 01:01
  • I wouldn't no where to start on converting to .ini to be honest. Would my thinking being messing with X, Y in the for loops give me the result i am looking for? Oh and 5 files are loaded like that. If i get it working and transfer to an editor i wouldn't need most of the code in there. Code is used later on hence values to LightArr[i].Width := Width ect.. – Se7en Jan 18 '14 at 01:04
  • Just adding new load/save functions with INI. For conversion purposes, keep the original DAT file loading, if the INI doesn't exist yet, then load from the DAT file, but then forcefully save a copy in the INI format and delete the original DAT files. You can combine the 5 files by using section names like *light1*, *light2*, etc. – Jerry Dodge Jan 18 '14 at 01:07
  • That's my problem, i have no Save function of this. The load part and .dat files were with the game already. I'm trying to get a Save function together so i can alter the files. With the code i did, i don't get the lightmap circle effect its just the square because that's all what i have told it to-do. I needed some kind of push in the right direction to try some other things i haven't out. Which is why i posted the 2 for loops code and asked if i had to manipulate PDark data via that way. Thanks – Se7en Jan 18 '14 at 01:08
  • Sorry I myself am not knowledgeable enough to answer your exact question, but giving a recommendation to make it much easier. Loading and saving INI format is very trivial. – Jerry Dodge Jan 18 '14 at 01:10
  • That's fine Jerry thanks for the tip :), i'll be sure to look into that when i get it working then :) – Se7en Jan 18 '14 at 01:11

0 Answers0