2017-09-23 01:00 CEST

View Issue Details Jump to Notes ]
IDProjectCategoryView StatusLast Update
0000240Cheat Enginepublic2013-04-21 20:42
Reportermgr_inz_Player 
Assigned ToDark Byte 
PrioritynormalSeverityminorReproducibilityhave not tried
StatusresolvedResolutionfixed 
Summary0000240: Lua file. "This is not a valid cheat table (buffer error)"
DescriptionIf we add checked.bmp and save table, we can not load this ct/cetrainer file later.

CE gives this error message:
"This is not a valid cheat table (buffer error)"

It happens with:
- original CE6.2
- CE from Nov2012, Jan2013 and from newest revision (r.1762)
TagsNo tags attached.
Attached Files
  • ? file icon checked.bmp (1,078 bytes) 2013-04-20 19:51 -
    ? file icon checked.bmp (1,078 bytes) 2013-04-20 19:51 +
  • patch file icon luafile.pas.patch (634 bytes) 2013-04-21 03:52 -
    Index: luafile.pas
    ===================================================================
    --- luafile.pas	(wersja 1764)
    +++ luafile.pas	(kopia robocza)
    @@ -99,9 +99,22 @@
           filedata.WriteBuffer(b^, read);
         until read=0;
     
    -  finally
    -    freemem(b);
    +  except
    +
    +    //weird zstream, use 1 byte buffer
    +    try
    +      dc.Position:=0;
    +      filedata.Free; filedata:=TMemorystream.create;
    +      repeat
    +        read:=dc.read(b^, 1);
    +        filedata.WriteBuffer(b^, read);
    +      until read=0;
    +    except
    +    end;
    +
       end;
    +
    +  freemem(b);
     end;
     
     procedure TLuafile.saveToXML(node: TDOMNode);
    
    patch file icon luafile.pas.patch (634 bytes) 2013-04-21 03:52 +
  • patch file icon fixLuaFile_V2.patch (3,252 bytes) 2013-04-21 16:27 -
    Index: luafile.pas
    ===================================================================
    --- luafile.pas	(wersja 1764)
    +++ luafile.pas	(kopia robocza)
    @@ -14,7 +14,7 @@
       public
     
         constructor create(name: string; stream: TStream);
    -    constructor createFromXML(node: TDOMNode);
    +    constructor createFromXML(node: TDOMNode; tableversion: integer=0);
         procedure saveToXML(node: TDOMNode);
         destructor destroy; override;
     
    @@ -28,7 +28,7 @@
     
     implementation
     
    -constructor TLuafile.createFromXML(node: TDOMNode);
    +constructor TLuafile.createFromXML(node: TDOMNode; tableversion: integer=0);
     var s: string;
       b: pchar;
       m: TMemorystream;
    @@ -84,23 +84,50 @@
         HexToBin(pchar(s), b, size);
       end;
     
    +  m:=tmemorystream.create;
    +  m.WriteBuffer(b^, size);
    +  m.position:=0;
    +  dc:=Tdecompressionstream.create(m, true);
     
    +  if tableversion >= 15 then
    +  begin // newer tables
    +    try
    +      size:=dc.ReadDWord();
    +      freemem(b); getmem(b, size);
    +      read:=dc.read(b^, size);
    +      filedata.WriteBuffer(b^, read);
    +    finally
    +      freemem(b);
    +    end;
    +  end
     
    +  else
     
    -  try
    -    m:=tmemorystream.create;
    -    m.WriteBuffer(b^, size);
    -    m.position:=0;
    -    dc:=Tdecompressionstream.create(m, true);
    +  begin // older tables
    +    try
     
    -    //reuse the b buffer
    -    repeat
    -      read:=dc.read(b^, maxsize);
    -      filedata.WriteBuffer(b^, read);
    -    until read=0;
     
    -  finally
    -    freemem(b);
    +      try
    +       repeat
    +         read:=dc.read(b^, maxsize);       //reuse the b buffer
    +         filedata.WriteBuffer(b^, read);
    +       until read=0;
    +      except //catch "buffer error" exception, weird zstream, use 1 byte buffer
    +       try
    +        dc.Position:=0;
    +        filedata.Free; filedata:=TMemorystream.create;
    +        repeat
    +          read:=dc.read(b^, 1);
    +          filedata.WriteBuffer(b^, read);
    +        until read=0;
    +       except // this time, ignore exception, filedata contains right data anyway
    +       end;
    +      end;
    +
    +
    +    finally
    +      freemem(b);
    +    end;
       end;
     end;
     
    @@ -122,6 +149,7 @@
       //compress the file
       m:=tmemorystream.create;
       c:=Tcompressionstream.create(clmax, m, true);
    +  c.WriteDWord(filedata.size);
       c.write(filedata.Memory^, filedata.size);
       c.free;
     
    Index: OpenSave.pas
    ===================================================================
    --- OpenSave.pas	(wersja 1764)
    +++ OpenSave.pas	(kopia robocza)
    @@ -363,10 +363,11 @@
             tempnode:=nil;
           end;
     
    +      version:=0;
           if tempnode<>nil then
           begin
             try
    -          version:=strtoint(tempnode.TextContent);
    +          version:=strtoint(tempnode.TextContent); // TableVersion
               if (version>CurrentTableVersion) then
                 showmessage('There is a newer version of Cheat Engine out. It''s recommended to use that version instead');
             except
    @@ -391,7 +392,7 @@
           for i:=0 to files.Childnodes.count-1 do
           begin
             filenode:=files.ChildNodes.item[i];
    -        lf:=TLuafile.createFromXML(filenode);
    +        lf:=TLuafile.createFromXML(filenode, version);
             mainform.LuaFiles.add(lf);
           end;
         end;
    
    patch file icon fixLuaFile_V2.patch (3,252 bytes) 2013-04-21 16:27 +
  • ? file icon luafile.pas (4,654 bytes) 2013-04-21 16:27

-Relationships
+Relationships

-Notes

~0000513

mgr_inz_Player (reporter)

Last edited: 2013-04-20 20:03

Looks like Tcompressionstream or Tdecompressionstream problem.

Not related with Ascii85, because it happens when using original CE6.2 too.

~0000514

mgr_inz_Player (reporter)

OK, I've made dirty patch. See at attached files...

~0000515

mgr_inz_Player (reporter)

I attached patch version 2.

It patches:
- OpenSave.pas
I used existing variable, "version", and I pass it to createFromXML function. TLuafile.createFromXML(filenode, version);

- luafile.pas

saveToXML function now adds uncompressed stream size (WriteDWord):
m:=tmemorystream.create;
c:=Tcompressionstream.create(clmax, m, true);
c.WriteDWord(filedata.size);
c.write(filedata.Memory^, filedata.size);
c.free;

createFromXML function has two parameters now: filenode and version

if version >= 15 it reads compressed stream like this
size:=dc.ReadDWord();
freemem(b); getmem(b, size);
read:=dc.read(b^, size);
filedata.WriteBuffer(b^, read);

otherwise, it will use old method:

read:=dc.read(b^, maxsize); //reuse the b buffer
filedata.WriteBuffer(b^, read);


But if "buffer error" exception occurs, it retry again with 1 byte buffer
read:=dc.read(b^, 1);
filedata.WriteBuffer(b^, read);

and ignores "buffer error" exception. From my short research, filedata will contain right data anyway.

I will attach luafile.pas as well (for better readability).

~0000516

Dark Byte (developer)

Fixed in the svn. It's now part of the base85 update which has a complete overhaul anyhow.
Also, no real need to add support for previous versions. The "compatible" solution to load old tables that are broken because of this is to bug out the same way
+Notes

-Issue History
Date Modified Username Field Change
2013-04-20 19:51 mgr_inz_Player New Issue
2013-04-20 19:51 mgr_inz_Player File Added: checked.bmp
2013-04-20 20:00 mgr_inz_Player Note Added: 0000513
2013-04-20 20:03 mgr_inz_Player Note Edited: 0000513
2013-04-20 20:03 mgr_inz_Player Note Edited: 0000513
2013-04-21 03:52 mgr_inz_Player File Added: luafile.pas.patch
2013-04-21 03:53 mgr_inz_Player Note Added: 0000514
2013-04-21 16:27 mgr_inz_Player Note Added: 0000515
2013-04-21 16:27 mgr_inz_Player File Added: fixLuaFile_V2.patch
2013-04-21 16:27 mgr_inz_Player File Added: luafile.pas
2013-04-21 20:42 Dark Byte Note Added: 0000516
2013-04-21 20:42 Dark Byte Status new => resolved
2013-04-21 20:42 Dark Byte Resolution open => fixed
2013-04-21 20:42 Dark Byte Assigned To => Dark Byte
+Issue History