fix saving and loading luafile

add some layout options to the 3d trainer generator
This commit is contained in:
cheatengine@gmail.com 2013-04-21 17:44:27 +00:00
parent e8aeeb055b
commit 2cac9b59c7
5 changed files with 168 additions and 86 deletions

View File

@ -1,12 +1,15 @@
object frmD3DTrainerGeneratorOptions: TfrmD3DTrainerGeneratorOptions
Left = 1065
Height = 256
Height = 365
Top = 140
Width = 422
Width = 418
BorderIcons = [biSystemMenu, biMinimize]
BorderStyle = bsSingle
Caption = 'Direct3D Hook Options'
ClientHeight = 256
ClientWidth = 422
ClientHeight = 365
ClientWidth = 418
OnCreate = FormCreate
Position = poScreenCenter
LCLVersion = '1.1'
object cbUseD3DKeys: TCheckBox
Left = 8
@ -44,7 +47,6 @@ object frmD3DTrainerGeneratorOptions: TfrmD3DTrainerGeneratorOptions
Height = 23
Top = 32
Width = 112
Enabled = False
OnKeyDown = edtd3dkeysKeyDown
ReadOnly = True
TabOrder = 2
@ -55,41 +57,40 @@ object frmD3DTrainerGeneratorOptions: TfrmD3DTrainerGeneratorOptions
Top = 32
Width = 75
Caption = 'Clear'
Enabled = False
OnClick = btnClearClick
TabOrder = 3
end
object Button2: TButton
Left = 8
Left = 208
Height = 25
Top = 176
Top = 240
Width = 139
Caption = 'Set background picture'
OnClick = Button2Click
TabOrder = 4
end
object imgPreview: TImage
Left = 216
Height = 153
Top = 96
Left = 208
Height = 121
Top = 112
Width = 192
Stretch = True
end
object cbStretch: TCheckBox
Left = 8
Left = 208
Height = 19
Hint = 'If selected the background image will get resized so that cheat entries will fit inside it'#13#10'This is useful if you pick a 1x1 pixel size bitmap that you wish to stretch'
Top = 200
Top = 264
Width = 170
Caption = 'Scale the background image'
OnChange = cbStretchChange
ParentShowHint = False
ShowHint = True
TabOrder = 5
end
object Button3: TButton
Left = 8
Left = 208
Height = 25
Top = 144
Top = 288
Width = 139
Caption = 'Set Font'
OnClick = Button3Click
@ -163,23 +164,24 @@ object frmD3DTrainerGeneratorOptions: TfrmD3DTrainerGeneratorOptions
Visible = False
end
object Button4: TButton
Left = 72
Left = 176
Height = 25
Top = 224
Top = 336
Width = 75
Caption = 'Close'
OnClick = Button4Click
TabOrder = 13
end
object lblTextColor: TLabel
Left = 152
Left = 352
Height = 15
Top = 144
Top = 336
Width = 46
Caption = 'Font text'
Font.Quality = fqNonAntialiased
ParentColor = False
ParentFont = False
Visible = False
end
object cbShowHotkeys: TCheckBox
Left = 8
@ -192,9 +194,9 @@ object frmD3DTrainerGeneratorOptions: TfrmD3DTrainerGeneratorOptions
TabOrder = 15
end
object imgChecked: TImage
Left = 0
Left = 312
Height = 13
Top = 240
Top = 336
Width = 13
Picture.Data = {
1754506F727461626C654E6574776F726B47726170686963DB00000089504E47
@ -209,9 +211,9 @@ object frmD3DTrainerGeneratorOptions: TfrmD3DTrainerGeneratorOptions
Visible = False
end
object imgUnchecked: TImage
Left = 16
Left = 328
Height = 13
Top = 240
Top = 336
Width = 13
Picture.Data = {
1754506F727461626C654E6574776F726B47726170686963AB00000089504E47
@ -224,6 +226,69 @@ object frmD3DTrainerGeneratorOptions: TfrmD3DTrainerGeneratorOptions
}
Visible = False
end
object Label3: TLabel
Left = 208
Height = 15
Top = 96
Width = 107
Caption = 'Background picture:'
ParentColor = False
end
object TextOverlayImage: TImage
Left = 208
Height = 121
Top = 112
Width = 192
Transparent = True
end
object edtDistanceBetweenLines: TEdit
Left = 9
Height = 23
Top = 168
Width = 176
TabOrder = 16
Text = '4'
end
object Label4: TLabel
Left = 9
Height = 15
Top = 152
Width = 165
Caption = 'Distance between lines in pixels'
ParentColor = False
end
object Label5: TLabel
Left = 9
Height = 15
Top = 196
Width = 119
Caption = 'Text distance from top'
ParentColor = False
end
object edtDistanceFromTop: TEdit
Left = 9
Height = 23
Top = 210
Width = 176
TabOrder = 17
Text = '8'
end
object edtDistanceFromBorder: TEdit
Left = 9
Height = 23
Top = 256
Width = 176
TabOrder = 18
Text = '8'
end
object Label6: TLabel
Left = 9
Height = 15
Top = 240
Width = 136
Caption = 'Text distance from border'
ParentColor = False
end
object ColorDialog1: TColorDialog
Color = clBlack
CustomColors.Strings = (
@ -248,19 +313,19 @@ object frmD3DTrainerGeneratorOptions: TfrmD3DTrainerGeneratorOptions
'ColorS=F0FBFF'
'ColorT=A4A0A0'
)
left = 176
top = 88
left = 112
top = 320
end
object OpenPictureDialog1: TOpenPictureDialog
left = 176
top = 176
left = 72
top = 320
end
object FontDialog1: TFontDialog
Font.Quality = fqNonAntialiased
MinFontSize = 0
MaxFontSize = 0
PreviewText = 'Example'
left = 64
top = 136
left = 24
top = 320
end
end

View File

@ -18,3 +18,10 @@ TFRMD3DTRAINERGENERATOROPTIONS.CBALLOWDRAG.CAPTION=Allow user to drag trainer ar
TFRMD3DTRAINERGENERATOROPTIONS.BUTTON4.CAPTION=Close
TFRMD3DTRAINERGENERATOROPTIONS.LBLTEXTCOLOR.CAPTION=Font text
TFRMD3DTRAINERGENERATOROPTIONS.CBSHOWHOTKEYS.CAPTION=Show hotkeys
TFRMD3DTRAINERGENERATOROPTIONS.LABEL3.CAPTION=Background picture:
TFRMD3DTRAINERGENERATOROPTIONS.EDTDISTANCEBETWEENLINES.TEXT=4
TFRMD3DTRAINERGENERATOROPTIONS.LABEL4.CAPTION=Distance between lines in pixels
TFRMD3DTRAINERGENERATOROPTIONS.LABEL5.CAPTION=Text distance from top
TFRMD3DTRAINERGENERATOROPTIONS.EDTDISTANCEFROMTOP.TEXT=8
TFRMD3DTRAINERGENERATOROPTIONS.EDTDISTANCEFROMBORDER.TEXT=8
TFRMD3DTRAINERGENERATOROPTIONS.LABEL6.CAPTION=Text distance from border

View File

@ -23,13 +23,21 @@ type
cbHasCheckbox: TCheckBox;
cbAllowDrag: TCheckBox;
ColorDialog1: TColorDialog;
edtDistanceBetweenLines: TEdit;
edtDistanceFromTop: TEdit;
edtDistanceFromBorder: TEdit;
edtd3dkeys: TEdit;
FontDialog1: TFontDialog;
Label4: TLabel;
Label5: TLabel;
Label6: TLabel;
TextOverlayImage: TImage;
imgChecked: TImage;
imgUnchecked: TImage;
imgPreview: TImage;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
lblTextColor: TLabel;
OpenPictureDialog1: TOpenPictureDialog;
rbTopLeft: TRadioButton;
@ -42,6 +50,7 @@ type
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
procedure cbStretchChange(Sender: TObject);
procedure cbUseD3DKeysChange(Sender: TObject);
procedure edtd3dkeysKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
@ -76,6 +85,11 @@ begin
close;
end;
procedure TfrmD3DTrainerGeneratorOptions.cbStretchChange(Sender: TObject);
begin
imgPreview.stretch:=cbStretch.checked;
end;
procedure TfrmD3DTrainerGeneratorOptions.cbUseD3DKeysChange(Sender: TObject);
begin
edtd3dkeys.enabled:=cbUseD3DKeys.checked;
@ -125,6 +139,24 @@ begin
lblTextColor.font.Quality:=fqNonAntialiased;
end;
//reset
TextOverlayImage.Picture.Bitmap.Width:=0;
TextOverlayImage.Picture.Bitmap.Height:=0;
TextOverlayImage.Picture.Bitmap.TransparentColor:=$010101;
TextOverlayImage.Picture.Bitmap.Transparent:=true;
TextOverlayImage.Picture.Bitmap.Canvas.Brush.Color:=TextOverlayImage.Picture.Bitmap.TransparentColor;
TextOverlayImage.Picture.Bitmap.Width:=TextOverlayImage.Width;
TextOverlayImage.Picture.Bitmap.Height:=TextOverlayImage.Height;
TextOverlayImage.Picture.Bitmap.Canvas.FillRect(0,0,TextOverlayImage.Picture.Bitmap.Width, TextOverlayImage.Picture.Bitmap.Height);
TextOverlayImage.Picture.Bitmap.Canvas.font:=lblTextColor.font;
TextOverlayImage.Picture.Bitmap.Canvas.font.Quality:=fqNonAntialiased;
TextOverlayImage.picture.Bitmap.Canvas.TextOut(0,0,'Example text');
end;
end.

View File

@ -37,8 +37,6 @@ var s: string;
read: integer;
useascii85: boolean;
{ a85: TASCII85DecoderStream;
a85source: Tstringstream; }
a: TDOMNode;
begin
name:=node.NodeName;
@ -61,19 +59,6 @@ begin
maxsize:=max(65536,size);
getmem(b, maxsize);
size:=Base85ToBin(pchar(s), b);
{
a85source:=TStringStream.Create(s);
a85:=TASCII85DecoderStream.Create(a85source);
size:=a85source.Size*5 div 4;
maxsize:=max(65536,size); //64KB or the required size if that's bigger
getmem(b, size);
read:=a85.Read(b^, size);
size:=read;
a85.free;
a85source.free; }
end
else
begin
@ -93,11 +78,22 @@ begin
m.position:=0;
dc:=Tdecompressionstream.create(m, true);
//reuse the b buffer
repeat
read:=dc.read(b^, maxsize);
if useascii85 then //this ce version also added a filesize (This is why I usually don't recommend using svn builds for production work. Of coure, not many people using the svn made use of the file stuff)
begin
size:=dc.ReadDWord;
freemem(b);
getmem(b, size);
read:=dc.read(b^, size);
filedata.WriteBuffer(b^, read);
until read=0;
end
else
begin
//reuse the b buffer
repeat
read:=dc.read(b^, maxsize);
filedata.WriteBuffer(b^, read);
until read=0;
end;
finally
freemem(b);
@ -111,8 +107,6 @@ var
m: TMemorystream;
c: Tcompressionstream;
{ a85: TASCII85EncoderStream;
a85buffer: TStringStream; }
n: TDOMNode;
a: TDOMAttr;
@ -122,20 +116,13 @@ begin
//compress the file
m:=tmemorystream.create;
c:=Tcompressionstream.create(clmax, m, true);
c.WriteDWord(filedata.size);
c.write(filedata.Memory^, filedata.size);
c.free;
//convert the compressed file to an ascii85 sring
{ a85buffer:=TStringStream.create('');
a85:=TASCII85EncoderStream.Create(a85buffer);
a85.Write(m.memory^, m.size);
a85.Free;
s:=a85buffer.DataString;
a85buffer.free; }
getmem(outputastext, (m.size div 4) * 5 + 5 );
BinToBase85(pchar(m.memory), outputastext, m.size);
@ -150,22 +137,6 @@ begin
freemem(outputastext);
m.free;
{
//convert the compressed file to a hexstring
getmem(outputastext, m.size*2+1);
try
BinToHex(pchar(m.Memory), outputastext, m.Size);
outputastext[m.size*2]:=#0; //add a 0 terminator
finally
freemem(outputastext);
if m<>nil then
m.free;
end; }
end;
constructor TLuafile.create(name: string; stream: tstream);

View File

@ -1071,6 +1071,9 @@ begin
l.add('D3DHook.showHotkeys='+BoolToStr(frmD3DTrainerGeneratorOptions.cbShowHotkeys.checked, 'true', 'false'));
l.add('D3DHook.hasCheckbox='+BoolToStr(frmD3DTrainerGeneratorOptions.cbHasCheckbox.checked, 'true', 'false'));
l.add('D3DHook.stretch='+BoolToStr(frmD3DTrainerGeneratorOptions.cbStretch.checked, 'true',' false'));
l.add('D3DHook.distanceBetweenLines='+frmD3DTrainerGeneratorOptions.edtDistanceBetweenLines.text);
l.add('D3DHook.distanceFromTop='+frmD3DTrainerGeneratorOptions.edtDistanceFromTop.text);
l.add('D3DHook.distanceFromBorder='+frmD3DTrainerGeneratorOptions.edtDistanceFromBorder.text);
if frmD3DTrainerGeneratorOptions.rbTopLeft.checked then
l.add('D3DHook.position=1')
@ -1251,36 +1254,40 @@ begin
l.add('function SetD3DMenuPosition(x,y)');
l.add(' --Sets up the trainer window and position');
l.add(' --set the background position and go through the d3dcheats. Optionally also stretching the background sprite');
l.add(' local maxX=0');
l.add(' local startY=y');
l.add('');
l.add(' BackgroundSprite.X=x');
l.add(' BackgroundSprite.Y=y');
l.add(' BackgroundSprite.X=math.floor(x)');
l.add(' BackgroundSprite.Y=math.floor(y)');
l.add('');
l.add(' x=x+D3DHook.distanceFromBorder');
l.add(' y=y+D3DHook.distanceFromTop');
l.add(' for i,info in pairs(d3dcheats) do');
l.add(' local _x=x+4');
l.add(' local _x=x');
l.add(' local lineheight=info.TextSprite.Height');
l.add('');
l.add(' if D3DHook.hasCheckbox then');
l.add(' if info.CheckboxSprite.Height>lineheight then');
l.add(' lineheight=info.CheckboxSprite.Height');
l.add(' end');
l.add(' info.CheckboxSprite.X=_x');
l.add(' info.CheckboxSprite.X=math.floor(_x)');
l.add(' _x=_x+info.CheckboxSprite.Width+2');
l.add(' info.CheckboxSprite.Y=y+ (lineheight / 2) - (info.CheckboxSprite.Height /2)');
l.add(' info.CheckboxSprite.Y=math.floor(y+ (lineheight / 2) - (info.CheckboxSprite.Height /2))');
l.add(' end');
l.add(' info.TextSprite.X=_x');
l.add(' info.TextSprite.Y=y+ (lineheight / 2) - (info.TextSprite.Height /2)');
l.add(' info.TextSprite.X=math.floor(_x)');
l.add(' info.TextSprite.Y=math.floor(y+ (lineheight / 2) - (info.TextSprite.Height /2))');
l.add('');
l.add(' if maxX<info.TextSprite.X+info.TextSprite.Width+4 then');
l.add(' maxX=info.TextSprite.X+info.TextSprite.Width+4');
l.add(' end');
l.add(' y=y+lineheight+3');
l.add(' y=y+lineheight+D3DHook.distanceBetweenLines');
l.add(' end');
l.add('');
l.add(' if D3DHook.stretch then');
l.add(' BackgroundSprite.Width=maxX-x');
l.add(' BackgroundSprite.Height=y-startY');
l.add(' BackgroundSprite.Width=maxX-x+D3DHook.distanceFromBorder');
l.add(' BackgroundSprite.Height=y-startY+D3DHook.distanceFromBorder');
l.add(' end');
l.add('end');