c59302102436e38a1ad715ec74df08c7e908d315
1 (* Copyright (C) DooM 2D:Forever Developers
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 3 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 {$INCLUDE e_amodes.inc}
28 Data
: array [0..BUF_SIZE
] of Byte; // îäèí áàéò ñâåðõó íà âñÿêèé ñëó÷àé
38 procedure e_Buffer_Clear(B
: pTBuffer
);
41 procedure e_Buffer_Write_Generic(B
: pTBuffer
; var V
; N
: Cardinal);
42 procedure e_Buffer_Read_Generic(B
: pTBuffer
; var V
; N
: Cardinal);
45 procedure e_Buffer_Write(B
: pTBuffer
; V
: Char); overload
;
47 procedure e_Buffer_Write(B
: pTBuffer
; V
: Byte); overload
;
48 procedure e_Buffer_Write(B
: pTBuffer
; V
: Word); overload
;
49 procedure e_Buffer_Write(B
: pTBuffer
; V
: LongWord); overload
;
51 procedure e_Buffer_Write(B
: pTBuffer
; V
: ShortInt); overload
;
52 procedure e_Buffer_Write(B
: pTBuffer
; V
: SmallInt); overload
;
53 procedure e_Buffer_Write(B
: pTBuffer
; V
: LongInt); overload
;
54 procedure e_Buffer_Write(B
: pTBuffer
; V
: Int64); overload
;
56 procedure e_Buffer_Write(B
: pTBuffer
; V
: string); overload
;
58 procedure e_Buffer_Write(B
: pTBuffer
; V
: TMD5Digest
); overload
;
61 function e_Buffer_Read_Char(B
: pTBuffer
): Char;
63 function e_Buffer_Read_Byte(B
: pTBuffer
): Byte;
64 function e_Buffer_Read_Word(B
: pTBuffer
): Word;
65 function e_Buffer_Read_LongWord(B
: pTBuffer
): LongWord;
67 function e_Buffer_Read_ShortInt(B
: pTBuffer
): ShortInt;
68 function e_Buffer_Read_SmallInt(B
: pTBuffer
): SmallInt;
69 function e_Buffer_Read_LongInt(B
: pTBuffer
): LongInt;
70 function e_Buffer_Read_Int64(B
: pTBuffer
): Int64;
72 function e_Buffer_Read_String(B
: pTBuffer
): string;
74 function e_Buffer_Read_MD5(B
: pTBuffer
): TMD5Digest
;
77 procedure e_Raw_Read_Generic(P
: Pointer; var V
; N
: Cardinal);
79 function e_Raw_Read_Char(P
: Pointer): Char;
81 function e_Raw_Read_Byte(P
: Pointer): Byte;
82 function e_Raw_Read_Word(P
: Pointer): Word;
83 function e_Raw_Read_LongWord(P
: Pointer): LongWord;
85 function e_Raw_Read_ShortInt(P
: Pointer): ShortInt;
86 function e_Raw_Read_SmallInt(P
: Pointer): SmallInt;
87 function e_Raw_Read_LongInt(P
: Pointer): LongInt;
89 function e_Raw_Read_String(P
: Pointer): string;
91 function e_Raw_Read_MD5(P
: Pointer): TMD5Digest
;
93 procedure e_Raw_Seek(I
: Cardinal);
97 uses SysUtils
, BinEditor
;
99 procedure e_Buffer_Clear(B
: pTBuffer
);
107 procedure e_Buffer_Write_Generic(B
: pTBuffer
; var V
; N
: Cardinal);
109 if (B
^.WritePos
+ N
>= BUF_SIZE
) then Exit
;
110 if (B
^.WritePos
+ N
> B
^.Len
) then
111 B
^.Len
:= B
^.WritePos
+ N
+ 1;
113 CopyMemory(Pointer(NativeUInt(Addr(B
^.Data
)) + B
^.WritePos
),
116 B
^.WritePos
:= B
^.WritePos
+ N
;
118 procedure e_Buffer_Read_Generic(B
: pTBuffer
; var V
; N
: Cardinal);
120 if (B
^.ReadPos
+ N
>= BUF_SIZE
) then Exit
;
122 CopyMemory(@V
, Pointer(NativeUInt(Addr(B
^.Data
)) + B
^.ReadPos
), N
);
124 B
^.ReadPos
:= B
^.ReadPos
+ N
;
128 procedure e_Buffer_Write(B
: pTBuffer
; V
: Char); overload
;
130 e_Buffer_Write_Generic(B
, V
, 1);
133 procedure e_Buffer_Write(B
: pTBuffer
; V
: Byte); overload
;
135 e_Buffer_Write_Generic(B
, V
, 1);
137 procedure e_Buffer_Write(B
: pTBuffer
; V
: Word); overload
;
139 e_Buffer_Write_Generic(B
, V
, 2);
141 procedure e_Buffer_Write(B
: pTBuffer
; V
: LongWord); overload
;
143 e_Buffer_Write_Generic(B
, V
, 4);
146 procedure e_Buffer_Write(B
: pTBuffer
; V
: ShortInt); overload
;
148 e_Buffer_Write_Generic(B
, V
, 1);
150 procedure e_Buffer_Write(B
: pTBuffer
; V
: SmallInt); overload
;
152 e_Buffer_Write_Generic(B
, V
, 2);
154 procedure e_Buffer_Write(B
: pTBuffer
; V
: LongInt); overload
;
156 e_Buffer_Write_Generic(B
, V
, 4);
158 procedure e_Buffer_Write(B
: pTBuffer
; V
: Int64); overload
;
160 e_Buffer_Write_Generic(B
, V
, 8);
163 procedure e_Buffer_Write(B
: pTBuffer
; V
: string); overload
;
169 e_Buffer_Write_Generic(B
, Len
, 1);
171 if (Len
= 0) then Exit
;
173 P
:= B
^.WritePos
+ Len
;
174 if (P
>= BUF_SIZE
) then
176 Len
:= BUF_SIZE
- B
^.WritePos
;
180 if (P
> B
^.Len
) then B
^.Len
:= P
;
182 CopyMemory(Pointer(NativeUInt(Addr(B
^.Data
)) + B
^.WritePos
),
188 procedure e_Buffer_Write(B
: pTBuffer
; V
: TMD5Digest
); overload
;
193 e_Buffer_Write(B
, V
[I
]);
197 function e_Buffer_Read_Char(B
: pTBuffer
): Char;
199 e_Buffer_Read_Generic(B
, Result
, 1);
202 function e_Buffer_Read_Byte(B
: pTBuffer
): Byte;
204 e_Buffer_Read_Generic(B
, Result
, 1);
206 function e_Buffer_Read_Word(B
: pTBuffer
): Word;
208 e_Buffer_Read_Generic(B
, Result
, 2);
210 function e_Buffer_Read_LongWord(B
: pTBuffer
): LongWord;
212 e_Buffer_Read_Generic(B
, Result
, 4);
215 function e_Buffer_Read_ShortInt(B
: pTBuffer
): ShortInt;
217 e_Buffer_Read_Generic(B
, Result
, 1);
219 function e_Buffer_Read_SmallInt(B
: pTBuffer
): SmallInt;
221 e_Buffer_Read_Generic(B
, Result
, 2);
223 function e_Buffer_Read_LongInt(B
: pTBuffer
): LongInt;
225 e_Buffer_Read_Generic(B
, Result
, 4);
227 function e_Buffer_Read_Int64(B
: pTBuffer
): Int64;
229 e_Buffer_Read_Generic(B
, Result
, 8);
232 function e_Buffer_Read_String(B
: pTBuffer
): string;
236 Len
:= e_Buffer_Read_Byte(B
);
238 if Len
= 0 then Exit
;
240 if B
^.ReadPos
+ Len
> B
^.Len
then
241 Len
:= B
^.Len
- B
^.ReadPos
;
243 SetLength(Result
, Len
);
244 CopyMemory(@Result
[1], Pointer(NativeUInt(Addr(B
^.Data
)) + B
^.ReadPos
), Len
);
246 B
^.ReadPos
:= B
^.ReadPos
+ Len
;
249 function e_Buffer_Read_MD5(B
: pTBuffer
): TMD5Digest
;
254 Result
[I
] := e_Buffer_Read_Byte(B
);
257 procedure e_Raw_Read_Generic(P
: Pointer; var V
; N
: Cardinal);
259 CopyMemory(@V
, Pointer(NativeUInt(P
) + RawPos
), N
);
261 RawPos
:= RawPos
+ N
;
264 function e_Raw_Read_Char(P
: Pointer): Char;
266 e_Raw_Read_Generic(P
, Result
, 1);
269 function e_Raw_Read_Byte(P
: Pointer): Byte;
271 e_Raw_Read_Generic(P
, Result
, 1);
273 function e_Raw_Read_Word(P
: Pointer): Word;
275 e_Raw_Read_Generic(P
, Result
, 2);
277 function e_Raw_Read_LongWord(P
: Pointer): LongWord;
279 e_Raw_Read_Generic(P
, Result
, 4);
282 function e_Raw_Read_ShortInt(P
: Pointer): ShortInt;
284 e_Raw_Read_Generic(P
, Result
, 1);
286 function e_Raw_Read_SmallInt(P
: Pointer): SmallInt;
288 e_Raw_Read_Generic(P
, Result
, 2);
290 function e_Raw_Read_LongInt(P
: Pointer): LongInt;
292 e_Raw_Read_Generic(P
, Result
, 4);
295 function e_Raw_Read_String(P
: Pointer): string;
299 Len
:= e_Raw_Read_Byte(P
);
301 if Len
= 0 then Exit
;
303 SetLength(Result
, Len
);
304 CopyMemory(@Result
[1], Pointer(NativeUInt(P
) + RawPos
), Len
);
306 RawPos
:= RawPos
+ Len
;
309 function e_Raw_Read_MD5(P
: Pointer): TMD5Digest
;
314 Result
[I
] := e_Raw_Read_Byte(P
);
317 procedure e_Raw_Seek(I
: Cardinal);