-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEquivalentVoidPointer.java
More file actions
64 lines (62 loc) · 1.9 KB
/
Copy pathEquivalentVoidPointer.java
File metadata and controls
64 lines (62 loc) · 1.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package awpsoft.gamemodule;
public class EquivalentVoidPointer
{
public byte[] Buffer;
public int Offset;
public EquivalentVoidPointer()
{
Buffer = null;
Offset = 0;
}
public EquivalentVoidPointer(byte[] buffer)
{
Buffer = buffer;
Offset = 0;
}
public EquivalentVoidPointer(byte[] buffer, int offset)
{
Buffer = null;
Offset = offset;
}
public byte[] getBuffer() {return Buffer;}
public void setBuffer(byte[] buffer) {Buffer = buffer;}
public int getOffset() {return Offset;}
public void setOffset(int offset) {Offset = offset;}
public void skip(int numbytes) { Offset += numbytes;}
public void back(int numbytes) {Offset -= numbytes;}
public int getAvailableSize() {return Buffer.length - Offset;}
public static void memcpy(EquivalentVoidPointer dst,EquivalentVoidPointer src, int size)
{
byte[] db = dst.Buffer, sb = src.Buffer;
int dsto = dst.Offset, srco = src.Offset;
for(int i = 0; i < size; i++) db[dsto + i] = sb[srco + i];
}
public static void memset(EquivalentVoidPointer dst,byte val, int size)
{
byte[] db = dst.Buffer;
int dsto = dst.Offset;
for(int i = 0; i < size; i++) db[dsto + i] = val;
}
public static int memcmp(EquivalentVoidPointer a,EquivalentVoidPointer b, int size)
{
byte[] ab = a.Buffer, bb = b.Buffer;
int ao = a.Offset, bo = b.Offset;
for(int i = 0; i < size; i++)
{
int tmp = (int)ab[ao + i] - (int)bb[bo + i];
if(tmp != 0) return tmp;
}
return 0;
}
@Override public EquivalentVoidPointer clone()
{
try
{
return (EquivalentVoidPointer)super.clone();
}
catch (CloneNotSupportedException e)
{
return new EquivalentVoidPointer(Buffer, Offset);
}
}
}