forked from runuo/runuo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathObjectPropertyList.cs
198 lines (157 loc) · 4.95 KB
/
ObjectPropertyList.cs
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
/***************************************************************************
* ObjectPropertyList.cs
* -------------------
* begin : May 1, 2002
* copyright : (C) The RunUO Software Team
* email : [email protected]
*
* $Id$
*
***************************************************************************/
/***************************************************************************
*
* 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
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
***************************************************************************/
using System;
using System.Text;
using Server;
using Server.Network;
namespace Server
{
public sealed class ObjectPropertyList : Packet
{
private IEntity m_Entity;
private int m_Hash;
private int m_Header;
private int m_Strings;
private string m_HeaderArgs;
public IEntity Entity{ get{ return m_Entity; } }
public int Hash{ get{ return 0x40000000 + m_Hash; } }
public int Header{ get{ return m_Header; } set{ m_Header = value; } }
public string HeaderArgs{ get{ return m_HeaderArgs; } set{ m_HeaderArgs = value; } }
private static bool m_Enabled = false;
public static bool Enabled{ get{ return m_Enabled; } set{ m_Enabled = value; } }
public ObjectPropertyList( IEntity e ) : base( 0xD6 )
{
EnsureCapacity( 128 );
m_Entity = e;
m_Stream.Write( (short) 1 );
m_Stream.Write( (int) e.Serial );
m_Stream.Write( (byte) 0 );
m_Stream.Write( (byte) 0 );
m_Stream.Write( (int) e.Serial );
}
public void Add( int number )
{
if ( number == 0 )
return;
AddHash( number );
if ( m_Header == 0 )
{
m_Header = number;
m_HeaderArgs = "";
}
m_Stream.Write( number );
m_Stream.Write( (short) 0 );
}
public void Terminate()
{
m_Stream.Write( (int) 0 );
m_Stream.Seek( 11, System.IO.SeekOrigin.Begin );
m_Stream.Write( (int) m_Hash );
}
private static byte[] m_Buffer = new byte[1024];
private static Encoding m_Encoding = Encoding.Unicode;
public void AddHash( int val )
{
m_Hash ^= (val & 0x3FFFFFF);
m_Hash ^= (val >> 26) & 0x3F;
}
public void Add( int number, string arguments )
{
if ( number == 0 )
return;
if ( arguments == null )
arguments = "";
if ( m_Header == 0 )
{
m_Header = number;
m_HeaderArgs = arguments;
}
AddHash( number );
AddHash( arguments.GetHashCode() );
m_Stream.Write( number );
int byteCount = m_Encoding.GetByteCount( arguments );
if ( byteCount > m_Buffer.Length )
m_Buffer = new byte[byteCount];
byteCount = m_Encoding.GetBytes( arguments, 0, arguments.Length, m_Buffer, 0 );
m_Stream.Write( (short) byteCount );
m_Stream.Write( m_Buffer, 0, byteCount );
}
public void Add( int number, string format, object arg0 )
{
Add( number, String.Format( format, arg0 ) );
}
public void Add( int number, string format, object arg0, object arg1 )
{
Add( number, String.Format( format, arg0, arg1 ) );
}
public void Add( int number, string format, object arg0, object arg1, object arg2 )
{
Add( number, String.Format( format, arg0, arg1, arg2 ) );
}
public void Add( int number, string format, params object[] args )
{
Add( number, String.Format( format, args ) );
}
// Each of these are localized to "~1_NOTHING~" which allows the string argument to be used
private static int[] m_StringNumbers = new int[]
{
1042971,
1070722
};
private int GetStringNumber()
{
return m_StringNumbers[m_Strings++ % m_StringNumbers.Length];
}
public void Add( string text )
{
Add( GetStringNumber(), text );
}
public void Add( string format, string arg0 )
{
Add( GetStringNumber(), String.Format( format, arg0 ) );
}
public void Add( string format, string arg0, string arg1 )
{
Add( GetStringNumber(), String.Format( format, arg0, arg1 ) );
}
public void Add( string format, string arg0, string arg1, string arg2 )
{
Add( GetStringNumber(), String.Format( format, arg0, arg1, arg2 ) );
}
public void Add( string format, params object[] args )
{
Add( GetStringNumber(), String.Format( format, args ) );
}
}
public sealed class OPLInfo : Packet
{
/*public OPLInfo( ObjectPropertyList list ) : base( 0xBF )
{
EnsureCapacity( 13 );
m_Stream.Write( (short) 0x10 );
m_Stream.Write( (int) list.Entity.Serial );
m_Stream.Write( (int) list.Hash );
}*/
public OPLInfo( ObjectPropertyList list ) : base( 0xDC, 9 )
{
m_Stream.Write( (int) list.Entity.Serial );
m_Stream.Write( (int) list.Hash );
}
}
}