diff --git a/src/engine/e_msg.pas b/src/engine/e_msg.pas
index 04efb5dc07455a7a18efceaa63e085094f6f5cb9..a2ecc52e3e9a40e6a2c58dede4d26344e35847b3 100644 (file)
--- a/src/engine/e_msg.pas
+++ b/src/engine/e_msg.pas
-(* Copyright (C) DooM 2D:Forever Developers
+(* Copyright (C) Doom 2D: Forever Developers
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
function AssignBuffer(P: Pointer; N: Integer; Full: Boolean = False): Boolean;
procedure BeginReading();
function AssignBuffer(P: Pointer; N: Integer; Full: Boolean = False): Boolean;
procedure BeginReading();
+ procedure Seek(Pos: Integer);
+ procedure Skip(Size: Integer);
+ function BytesLeft(): Integer;
function ReadData(V: Pointer; N: Integer): Integer;
function ReadChar(): Char;
function ReadByte(): Byte;
function ReadData(V: Pointer; N: Integer): Integer;
function ReadChar(): Char;
function ReadByte(): Byte;
procedure Write(V: Int64); overload;
procedure Write(V: String); overload;
procedure Write(V: TMD5Digest); overload;
procedure Write(V: Int64); overload;
procedure Write(V: String); overload;
procedure Write(V: TMD5Digest); overload;
+ procedure Write(V: TMsg);
end;
type
end;
type
begin
if not OwnMemory then
raise Exception.Create('TMsg.Free: called on borrowed memory');
begin
if not OwnMemory then
raise Exception.Create('TMsg.Free: called on borrowed memory');
+ Clear();
OwnMemory := False;
FreeMem(Data);
Data := nil;
OwnMemory := False;
FreeMem(Data);
Data := nil;
CurSize := CurSize + N;
end;
CurSize := CurSize + N;
end;
+procedure TMsg.Write(V: TMsg);
+begin
+ if CurSize + V.CurSize > MaxSize then
+ begin
+ Overflow := True;
+ raise Exception.Create('TMsg.WriteData: buffer overrun!');
+ Exit;
+ end;
+ Move(V.Data^, (Data + CurSize)^, V.CurSize);
+ CurSize := CurSize + V.CurSize;
+end;
+
procedure TMsg.Write(V: Byte); overload;
begin
WriteData(@V, 1);
procedure TMsg.Write(V: Byte); overload;
begin
WriteData(@V, 1);
procedure TMsg.Write(V: ShortInt); overload;
begin
procedure TMsg.Write(V: ShortInt); overload;
begin
- WriteData(@V, 2);
+ WriteData(@V, 1);
end;
procedure TMsg.Write(V: SmallInt); overload;
begin
end;
procedure TMsg.Write(V: SmallInt); overload;
begin
- WriteData(@V, 1);
+ WriteData(@V, 2);
end;
procedure TMsg.Write(V: LongInt); overload;
end;
procedure TMsg.Write(V: LongInt); overload;
Bit := 0;
end;
Bit := 0;
end;
+procedure TMsg.Seek(Pos: Integer);
+begin
+ if Pos > CurSize then
+ raise Exception.Create('TMsg.Seek: buffer overrun!');
+ ReadCount := Pos;
+end;
+
+procedure TMsg.Skip(Size: Integer);
+begin
+ if ReadCount + Size > CurSize then
+ raise Exception.Create('TMsg.Skip: buffer overrun!');
+ ReadCount := ReadCount + Size;
+end;
+
+function TMsg.BytesLeft(): Integer;
+begin
+ Result := CurSize - ReadCount;
+end;
+
function TMsg.ReadData(V: Pointer; N: Integer): Integer;
begin
Result := 0;
function TMsg.ReadData(V: Pointer; N: Integer): Integer;
begin
Result := 0;
function TMsg.ReadShortInt(): ShortInt;
begin
Result := 0;
function TMsg.ReadShortInt(): ShortInt;
begin
Result := 0;
- ReadData(@Result, 2);
+ ReadData(@Result, 1);
end;
function TMsg.ReadSmallInt(): SmallInt;
begin
Result := 0;
end;
function TMsg.ReadSmallInt(): SmallInt;
begin
Result := 0;
- ReadData(@Result, 1);
+ ReadData(@Result, 2);
end;
function TMsg.ReadLongInt(): LongInt;
end;
function TMsg.ReadLongInt(): LongInt;