Cześć.
Zwykle radze sobie sam. Ale mam problem ponieważ dllka, którą Hookuje jest w C++. I nie bardzo radzę sobie z podstawieniem typów. Oryginalny opis rzecze to co poniżej:
/*
kailleraModifyPlayValues:
You must call this method at every frame after you retrieved values from your input devices.
This method will record/bufferize the values you send in and will manage to mix them with
the other players.
Basically, each players sends his values and receive all players values concatened.
e.g:
t - player 1 sends "867F" - player 2 sends "964F"
t+1 - player 1 receives "867F964F" - player 2 receives "867F964F"
you may want to look at the modified MAME source code available on kaillera's home page
to have a working example out of this (look in inptport.c)
Ideally, your input values should be defined like 1 bit for a given key, which has to be
unset when the key is not pressed and set when the key is pressed.
The size of the values you pass to this function is the size for ONE player's values.
Also, it must be the SAME for a given game and should be kept to a minimum (for network
speed and latency issues).
Be sure that the values parameters has enough space for receiving all inputs from all players
(8 players max.)
returns: length received or -1 on network error (player no more in the game)
*/
DLLEXP kailleraModifyPlayValues(void *values, int size);
I teraz mam taki kod pod Delphi. Do pliku zapisuje się w kolejnych wierszach wielokrotnie liczba 2
. I teraz pytania.
Czy dobrze zadeklarowałem values
jako typ PChar
? Jeśli nie, to jak powinno to wyglądać pod Delphi 7. I w jaki sposób zapisać to, co będzie zawierała ta zmienna, jako string
do pliku tekstowego z logiem?
function SaveOrAppendTextToFile(AFileName : string; InStr : string; AppendFile : boolean) : boolean;
const
Append_Arr : array[boolean] of DWORD = (CREATE_ALWAYS, OPEN_ALWAYS);
var
OutFile : THandle;
BytesWritten : DWORD;
OutFileSize : integer;
begin
OutFile := CreateFile(PChar(AFileName), GENERIC_WRITE,
FILE_SHARE_READ, nil, Append_Arr[AppendFile], FILE_ATTRIBUTE_NORMAL, 0);
Result := OutFile <> INVALID_HANDLE_VALUE;
if Result then
begin
OutFileSize := Length(InStr);
if AppendFile then
begin
FileSeek(OutFile, 0, FILE_END);
end;
WriteFile(OutFile, InStr[1], OutFileSize, BytesWritten, nil);
CloseHandle(OutFile);
end;
end;
procedure Hooked_kailleraModifyPlayValues(values : PChar; Size : integer); stdcall;
type
TOriginal_kailleraModifyPlayValues = procedure(values : PChar; Size : integer); stdcall;
var
LogFileName : string;
begin
Hook[5].UnHook;
TOriginal_kailleraModifyPlayValues(Hook[5].BaseAddr)(values, Size);
LogFileName := 'D:\test.log';
SaveOrAppendTextToFile(LogFileName, IntToStr(Size) + #13#10, FileExists(LogFileName));
Hook[5].Hook;
end;
Pytam, gdyż chcę zobaczyć w formie "namacalnej" co wysyła emulator gier, do którego kodu nie mam dostępu. A nawet jakbym miał, to pewnie był by on raczej w C++, który to język - jak wiecie - słabo toleruje. I praktycznie nie znam. Natomiast kombinacje z zapisem values na różne sposoby, powodowały, że otrzymywałem pusty string. To tyle. Z góry dziękuję za pomoc. I przykłady kodów źródlowych w Delphi pod WinAPI.