private void IAcceptConnection(Socket cli) { hsStream s = new hsStream(new NetworkStream(cli, false)); pnCli2Srv_Connect hdr = new pnCli2Srv_Connect(); hdr.Read(s); s.Close(); IAcceptConnection(cli, hdr); }
public void SetMessage(plMessage msg, hsResMgr mgr) { hsStream s = new hsStream(new MemoryStream()); s.Version = mgr.Version; if (msg != null) mgr.WriteCreatable(s, msg); fHelper.Stream = s; s.Close(); // Fill in the flags // TODO: CCR -> AllPlayers InterAgeRouting = msg.InterAgeRouting; UseRelRegions = msg.UseRelRegions; }
public static void ReadDescriptors(string path) { // TODO: EncryptedStream support if (Directory.Exists(path)) { foreach (string sdl in Directory.EnumerateFiles(path, "*.sdl")) { FileStream fs = new FileStream(Path.Combine(path, sdl), FileMode.Open, FileAccess.Read); ReadDescriptors(fs); fs.Close(); } } else if (File.Exists(path)) { FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read); hsStream s = new hsStream(fs); ReadDescriptors(fs); s.Close(); fs.Close(); } else throw new FileNotFoundException(path); }
public plStateDataRecord ParseStateRecord(byte[] record, hsResMgr mgr) { MemoryStream ms = new MemoryStream(record); hsStream s = new hsStream(ms); s.Version = mgr.Version; plStateDataRecord result = new plStateDataRecord(this); try { result.ReadStreamHeader(s, mgr); result.Read(s, mgr); } catch (Exception e) { throw new plSDLException("Failed to parse StateDataRecord", e); } finally { s.Close(); ms.Close(); } return result; }
public byte[] DumpStateRecord(plStateDataRecord record, hsResMgr mgr) { MemoryStream ms = new MemoryStream(); hsStream s = new hsStream(ms); s.Version = mgr.Version; byte[] buf = null; try { record.WriteStreamHeader(s, mgr); record.Write(s, mgr); } catch (Exception e) { throw new plSDLException("Failed to dump StateDataRecord", e); } finally { buf = ms.ToArray(); s.Close(); ms.Close(); } return buf; }
public byte[] ToArray() { // Lots of overhead for such a simple operation... // All because eap sucks MemoryStream ms = new MemoryStream(); hsStream s = new hsStream(ms); Write(s); byte[] buf = ms.ToArray(); s.Close(); ms.Close(); return buf; }
private void IReadHoldingKey(HoldingKey key) { // Prep the source stream... hsStream s = key.fStream; s.Seek(key.fOffset); // Let's dump this object into a protected stream MemoryStream ms = new MemoryStream(); ms.Write(s.ReadBytes(key.fSize), 0, key.fSize); ms.Position = 0; //Now read the creatable from that protected stream hsStream pStream = new hsStream(ms); pStream.Version = s.Version; plCreatable pCre = ReadCreatable(pStream); // Do we need to use a plHexBuffer (unimplemented data) if (pCre == null) { plHexBuffer buf = new plHexBuffer(); buf.Read(pStream, this); fObjects.Add(key.fKey, buf); plDebugLog.GetLog("ResManager").Warn(String.Format( "Unimplemented KeyedObject '{0}' in {1}", plManagedType.ClassName(key.fKey.ClassType), key.fKey.Location)); } else fObjects.Add(key.fKey, (hsKeyedObject)pCre); //Need to warn about read/size mismatch? if (ms.Length > ms.Position) plDebugLog.GetLog("ResManager").Warn( String.Format("Read Error: {0} has {1} bytes left over", key.fKey.ObjectName, (ms.Length - ms.Position))); // Clean up pStream.Close(); ms.Close(); }