1: | <?php |
2: | |
3: | |
4: | |
5: | |
6: | |
7: | |
8: | |
9: | |
10: | |
11: | |
12: | |
13: | |
14: | |
15: | |
16: | |
17: | |
18: | |
19: | namespace GameQ\Protocols; |
20: | |
21: | use GameQ\Buffer; |
22: | use GameQ\Result; |
23: | |
24: | |
25: | |
26: | |
27: | |
28: | |
29: | |
30: | |
31: | |
32: | |
33: | class Arma3 extends Source |
34: | { |
35: | |
36: | const BASE_DLC_KART = 'Karts'; |
37: | const BASE_DLC_MARKSMEN = 'Marksmen'; |
38: | const BASE_DLC_HELI = 'Helicopters'; |
39: | const BASE_DLC_CURATOR = 'Curator'; |
40: | const BASE_DLC_EXPANSION = 'Expansion'; |
41: | const BASE_DLC_JETS = 'Jets'; |
42: | const BASE_DLC_ORANGE = 'Laws of War'; |
43: | const BASE_DLC_ARGO = 'Malden'; |
44: | const BASE_DLC_TACOPS = 'Tac-Ops'; |
45: | const BASE_DLC_TANKS = 'Tanks'; |
46: | const BASE_DLC_CONTACT = 'Contact'; |
47: | const BASE_DLC_ENOCH = 'Contact (Platform)'; |
48: | |
49: | |
50: | const BASE_DLC_AOW = 'Art of War'; |
51: | |
52: | |
53: | const CREATOR_DLC_GM = 'Global Mobilization'; |
54: | const CREATOR_DLC_VN = 'S.O.G. Prairie Fire'; |
55: | const CREATOR_DLC_CSLA = 'ČSLA - Iron Curtain'; |
56: | const CREATOR_DLC_WS = 'Western Sahara'; |
57: | |
58: | |
59: | |
60: | |
61: | |
62: | |
63: | |
64: | |
65: | protected $dlcFlags = [ |
66: | 0b0000000000000001 => self::BASE_DLC_KART, |
67: | 0b0000000000000010 => self::BASE_DLC_MARKSMEN, |
68: | 0b0000000000000100 => self::BASE_DLC_HELI, |
69: | 0b0000000000001000 => self::BASE_DLC_CURATOR, |
70: | 0b0000000000010000 => self::BASE_DLC_EXPANSION, |
71: | 0b0000000000100000 => self::BASE_DLC_JETS, |
72: | 0b0000000001000000 => self::BASE_DLC_ORANGE, |
73: | 0b0000000010000000 => self::BASE_DLC_ARGO, |
74: | 0b0000000100000000 => self::BASE_DLC_TACOPS, |
75: | 0b0000001000000000 => self::BASE_DLC_TANKS, |
76: | 0b0000010000000000 => self::BASE_DLC_CONTACT, |
77: | 0b0000100000000000 => self::BASE_DLC_ENOCH, |
78: | 0b0001000000000000 => self::BASE_DLC_AOW, |
79: | 0b0010000000000000 => 'Unknown', |
80: | 0b0100000000000000 => 'Unknown', |
81: | 0b1000000000000000 => 'Unknown', |
82: | ]; |
83: | |
84: | |
85: | |
86: | |
87: | |
88: | |
89: | protected $name = 'arma3'; |
90: | |
91: | |
92: | |
93: | |
94: | |
95: | |
96: | protected $name_long = "Arma3"; |
97: | |
98: | |
99: | |
100: | |
101: | |
102: | |
103: | protected $port_diff = 1; |
104: | |
105: | |
106: | |
107: | |
108: | |
109: | |
110: | |
111: | |
112: | |
113: | protected function processRules(Buffer $buffer) |
114: | { |
115: | |
116: | $buffer->readInt16(); |
117: | |
118: | |
119: | $data = ''; |
120: | |
121: | |
122: | while ($buffer->getLength()) { |
123: | |
124: | $buffer->readString(); |
125: | |
126: | |
127: | $data .= $buffer->readString(); |
128: | } |
129: | |
130: | |
131: | $data = str_replace(["\x01\x01", "\x01\x02", "\x01\x03"], ["\x01", "\x00", "\xFF"], $data); |
132: | |
133: | |
134: | $responseBuffer = new Buffer($data); |
135: | |
136: | |
137: | unset($buffer, $data); |
138: | |
139: | |
140: | $result = new Result(); |
141: | |
142: | |
143: | $result->add('rules_protocol_version', $responseBuffer->readInt8()); |
144: | $result->add('overflow', $responseBuffer->readInt8()); |
145: | $dlcByte = $responseBuffer->readInt8(); |
146: | $dlcByte2 = $responseBuffer->readInt8(); |
147: | $dlcBits = ($dlcByte2 << 8) | $dlcByte; |
148: | |
149: | |
150: | $difficulty = $responseBuffer->readInt8(); |
151: | |
152: | |
153: | $result->add('3rd_person', $difficulty >> 7); |
154: | $result->add('advanced_flight_mode', ($difficulty >> 6) & 1); |
155: | $result->add('difficulty_ai', ($difficulty >> 3) & 3); |
156: | $result->add('difficulty_level', $difficulty & 3); |
157: | |
158: | unset($difficulty); |
159: | |
160: | |
161: | $result->add('crosshair', $responseBuffer->readInt8()); |
162: | |
163: | |
164: | foreach ($this->dlcFlags as $dlcFlag => $dlcName) { |
165: | |
166: | if (($dlcBits & $dlcFlag) === $dlcFlag) { |
167: | |
168: | $result->addSub('dlcs', 'name', $dlcName); |
169: | $result->addSub('dlcs', 'hash', dechex($responseBuffer->readInt32())); |
170: | } |
171: | } |
172: | |
173: | |
174: | $modCount = $responseBuffer->readInt8(); |
175: | |
176: | |
177: | $result->add('mod_count', $modCount); |
178: | |
179: | |
180: | while ($modCount) { |
181: | |
182: | $result->addSub('mods', 'hash', dechex($responseBuffer->readInt32())); |
183: | |
184: | |
185: | $infoByte = $responseBuffer->readInt8(); |
186: | |
187: | |
188: | $result->addSub('mods', 'dlc', ($infoByte & 0b00010000) === 0b00010000); |
189: | |
190: | |
191: | $result->addSub('mods', 'steam_id', $responseBuffer->readInt32($infoByte & 0x0F)); |
192: | |
193: | |
194: | $result->addSub('mods', 'name', $responseBuffer->readPascalString(0, true) ?: 'Unknown'); |
195: | |
196: | --$modCount; |
197: | } |
198: | |
199: | |
200: | unset($dlcByte, $dlcByte2, $dlcBits); |
201: | |
202: | |
203: | $signatureCount = $responseBuffer->readInt8(); |
204: | $result->add('signature_count', $signatureCount); |
205: | |
206: | |
207: | $signatures = []; |
208: | |
209: | |
210: | for ($x = 0; $x < $signatureCount; $x++) { |
211: | $signatures[] = $responseBuffer->readPascalString(0, true); |
212: | } |
213: | |
214: | |
215: | $result->add('signatures', $signatures); |
216: | |
217: | unset($responseBuffer, $signatureCount, $signatures, $x); |
218: | |
219: | return $result->fetch(); |
220: | } |
221: | } |
222: | |