예제 #1
0
        public static unsafe bool PullCompletedReadBuffer(FixedString128 gameSaveFilePath, byte *buffer, int bufferLength)
        {
            for (int i = 0; i < gameSaveReadFiles.Length; i++)
            {
                if (gameSaveReadFiles[i].filePath == gameSaveFilePath)
                {
                    Baselib_ErrorState errorState = new Baselib_ErrorState();
                    bool result = false;

                    UInt64 fileSize = Baselib_FileIO_SyncGetFileSize(gameSaveReadFiles[i].fileHandle, &errorState);
                    if ((errorState.code == Baselib_ErrorCode.Success) && ((int)fileSize == bufferLength))
                    {
                        Baselib_FileIO_SyncRead(gameSaveReadFiles[i].fileHandle, 0, (IntPtr)buffer, fileSize, &errorState);
                        if (errorState.code == Baselib_ErrorCode.Success)
                        {
                            result = true;
                        }
                    }

                    Baselib_FileIO_SyncClose(gameSaveReadFiles[i].fileHandle, &errorState);
                    gameSaveReadFiles.RemoveAtSwapBack(i);
                    return(result);
                }
            }

            return(false);
        }
예제 #2
0
        public static unsafe bool WriteToDisk(FixedString128 gameSaveFilePath, MemoryBinaryWriter writer)
        {
            Baselib_ErrorState errorState = new Baselib_ErrorState();

            Baselib_FileIO_SyncFile gameSaveFileHandle = Baselib_FileIO_SyncOpen(gameSaveFilePath.GetUnsafePtr(), Baselib_FileIO_OpenFlags.CreateAlways | Baselib_FileIO_OpenFlags.Write, &errorState);

            if (errorState.code != Baselib_ErrorCode.Success)
            {
                return(false);
            }

            Baselib_FileIO_SyncWrite(gameSaveFileHandle, 0, (IntPtr)writer.Data, (uint)writer.Length, &errorState);
            if (errorState.code != Baselib_ErrorCode.Success)
            {
                return(false);
            }

            Baselib_FileIO_SyncFlush(gameSaveFileHandle, &errorState);
            if (errorState.code != Baselib_ErrorCode.Success)
            {
                return(false);
            }

            // If we get this far, we'll consider the write a success because it should have been completed.
            Baselib_FileIO_SyncClose(gameSaveFileHandle, &errorState);
            return(true);
        }
예제 #3
0
        internal unsafe void SpoofInitListenInternal()
        {
            spoofInitCalled = true;
            Baselib_ErrorState errState = new Baselib_ErrorState();

            hSpoofSocket = Baselib_Socket_Create(Baselib_NetworkAddress_Family.IPv4, Baselib_Socket_Protocol.TCP, (Baselib_ErrorState *)UnsafeUtility.AddressOf(ref errState));

            if (errState.code != Baselib_ErrorCode.Success)
            {
                SpoofExitInternal();
                Assert.AreEqual(Baselib_ErrorCode.Success, errState.code, "Unable to create socket when initializing spoof player listener server");
            }

            if (errState.code == Baselib_ErrorCode.Success)
            {
                fixed(byte *bip = System.Text.Encoding.UTF8.GetBytes(spoofIp))
                {
                    Baselib_NetworkAddress_Encode((Baselib_NetworkAddress *)UnsafeUtility.AddressOf(ref hSpoofAddress), Baselib_NetworkAddress_Family.IPv4,
                                                  bip, spoofPort, (Baselib_ErrorState *)UnsafeUtility.AddressOf(ref errState));
                }
            }

            if (errState.code != Baselib_ErrorCode.Success)
            {
                SpoofExitInternal();
                Assert.AreEqual(Baselib_ErrorCode.Success, errState.code, "Unable to encode network address when initializing spoof player listener server");
            }

            if (errState.code == Baselib_ErrorCode.Success)
            {
                Baselib_Socket_Bind(hSpoofSocket, (Baselib_NetworkAddress *)UnsafeUtility.AddressOf(ref hSpoofAddress), Baselib_NetworkAddress_AddressReuse.Allow,
                                    (Baselib_ErrorState *)UnsafeUtility.AddressOf(ref errState));
            }

            if (errState.code != Baselib_ErrorCode.Success)
            {
                SpoofExitInternal();
                Assert.AreEqual(Baselib_ErrorCode.Success, errState.code, "Unable to bind socket when initializing spoof player listener server");
            }

            if (errState.code == Baselib_ErrorCode.Success)
            {
                Baselib_Socket_TCP_Listen(hSpoofSocket, (Baselib_ErrorState *)UnsafeUtility.AddressOf(ref errState));
            }

            if (errState.code != Baselib_ErrorCode.Success)
            {
                SpoofExitInternal();
                Assert.AreEqual(Baselib_ErrorCode.Success, errState.code, "Unable to initiate listen mode when initializing spoof player listener server");
            }
        }
예제 #4
0
        internal unsafe void SpoofReceiveInternal(byte *data, int numBytes)
        {
            Baselib_ErrorState errState = new Baselib_ErrorState();
            uint bytesLeft     = (uint)numBytes;
            uint bytesReceived = 0;

            while (bytesLeft > 0)
            {
                uint received = Baselib_Socket_TCP_Recv(hSpoofSocketConnected, (IntPtr)data + (int)bytesReceived, (uint)bytesLeft, (Baselib_ErrorState *)UnsafeUtility.AddressOf(ref errState));
                Assert.AreEqual(Baselib_ErrorCode.Success, errState.code);
                bytesReceived += received;
                bytesLeft     -= received;
            }
        }
예제 #5
0
        internal unsafe void SpoofAcceptInternal()
        {
            Baselib_ErrorState errState = new Baselib_ErrorState();

            hSpoofSocketConnected = Baselib_Socket_Handle_Invalid;
            var start = Time.timeAsDouble;

            while (hSpoofSocketConnected.handle == Baselib_Socket_Handle_Invalid.handle && Time.timeAsDouble - start < kConnectTime)
            {
                hSpoofSocketConnected = Baselib_Socket_TCP_Accept(hSpoofSocket, (Baselib_ErrorState *)UnsafeUtility.AddressOf(ref errState));
            }
            Assert.AreEqual(Baselib_ErrorCode.Success, errState.code, "Error accepting spoof player connection");
            Assert.IsFalse(hSpoofSocketConnected.handle == Baselib_Socket_Handle_Invalid.handle, "Unable to accept spoof player connection");
        }
예제 #6
0
        internal unsafe void SpoofSendInternal(byte *data, int numBytes)
        {
            Baselib_ErrorState errState = new Baselib_ErrorState();
            uint bytesLeft = (uint)numBytes;
            uint bytesSent = 0;

            while (bytesLeft > 0)
            {
                uint sent = Baselib_Socket_TCP_Send(hSpoofSocketConnected, (IntPtr)data + (int)bytesSent, (uint)bytesLeft, (Baselib_ErrorState *)UnsafeUtility.AddressOf(ref errState));
                if (errState.code != Baselib_ErrorCode.Success)
                {
                    Assert.AreEqual(Baselib_ErrorCode.Success, errState.code);
                }
                bytesSent += sent;
                bytesLeft -= sent;
            }
        }
예제 #7
0
        public static unsafe bool ReadFromDisk(FixedString128 gameSaveFilePath)
        {
            Baselib_ErrorState      errorState = new Baselib_ErrorState();
            Baselib_FileIO_SyncFile fileHandle = Baselib_FileIO_SyncOpen(gameSaveFilePath.GetUnsafePtr(), Baselib_FileIO_OpenFlags.Read, &errorState);

            if (errorState.code != Baselib_ErrorCode.Success)
            {
                return(false);
            }

            GameSaveFile gameSaveFile;

            gameSaveFile.filePath   = gameSaveFilePath;
            gameSaveFile.fileHandle = fileHandle;
            gameSaveReadFiles.Add(gameSaveFile);
            return(true);
        }
예제 #8
0
        public unsafe void LoadSoundClipFromDisk(EntityManager mgr, Entity e, string filePath)
        {
            DynamicBuffer <AudioClipCompressed> audioClipCompressed = mgr.GetBuffer <AudioClipCompressed>(e);

            if (audioClipCompressed.Length > 0)
            {
                return;
            }

#if UNITY_ANDROID
            var op = IOService.RequestAsyncRead(filePath);
            while (op.GetStatus() <= AsyncOp.Status.InProgress)
            {
                ;
            }

            op.GetData(out byte *data, out int sizeInBytes);
            audioClipCompressed.ResizeUninitialized(sizeInBytes);
            byte *audioClipCompressedBytes = (byte *)audioClipCompressed.GetUnsafePtr();
            for (int i = 0; i < sizeInBytes; i++)
            {
                audioClipCompressedBytes[i] = data[i];
            }

            op.Dispose();
#else
            FixedString512          filePathFixedString = new FixedString512(filePath);
            Baselib_ErrorState      errorState          = new Baselib_ErrorState();
            Baselib_FileIO_SyncFile fileHandle          = Baselib_FileIO_SyncOpen(filePathFixedString.GetUnsafePtr(), Baselib_FileIO_OpenFlags.Read, &errorState);
            if (errorState.code != Baselib_ErrorCode.Success)
            {
                return;
            }

            UInt64 fileSize = Baselib_FileIO_SyncGetFileSize(fileHandle, &errorState);
            if (fileSize > Int32.MaxValue)
            {
                Baselib_FileIO_SyncClose(fileHandle, &errorState);
                return;
            }

            audioClipCompressed.ResizeUninitialized((int)fileSize);
            UInt64 bytesRead = Baselib_FileIO_SyncRead(fileHandle, 0, (IntPtr)audioClipCompressed.GetUnsafePtr(), (ulong)audioClipCompressed.Length, &errorState);
            Baselib_FileIO_SyncClose(fileHandle, &errorState);
#endif
        }
예제 #9
0
        public static unsafe bool GetLength(FixedString128 gameSaveFilePath, int *length)
        {
            for (int i = 0; i < gameSaveReadFiles.Length; i++)
            {
                if (gameSaveReadFiles[i].filePath == gameSaveFilePath)
                {
                    Baselib_ErrorState errorState = new Baselib_ErrorState();
                    UInt64             fileSize   = Baselib_FileIO_SyncGetFileSize(gameSaveReadFiles[i].fileHandle, &errorState);
                    if ((errorState.code == Baselib_ErrorCode.Success) && (fileSize <= Int32.MaxValue))
                    {
                        *length = (int)fileSize;
                        return(true);
                    }
                }
            }

            return(false);
        }
        private unsafe void SendAndValidate(Dictionary <uint, bool> markerDefined)
#endif
        {
            Connection.TransmitAndReceive();
            Assert.IsFalse(Connection.HasSendDataQueued, "Profiler data not sent!");

            Baselib_ErrorState errState = new Baselib_ErrorState();

            byte[] buffer   = new byte[65536];
            uint   received = 0;

            fixed(byte *bufferPtr = buffer)
            {
                received = Baselib_Socket_TCP_Recv(hSpoofSocketConnected, (IntPtr)bufferPtr, (uint)buffer.Length, (Baselib_ErrorState *)UnsafeUtility.AddressOf(ref errState));
                byte *dataPtr = bufferPtr;

                while (dataPtr < bufferPtr + received)
                {
                    Connection.MessageHeader *headerPtr = (Connection.MessageHeader *)dataPtr;

                    // Parse message header
                    Assert.IsTrue(headerPtr->magicId == EditorMessageIds.kMagicNumber);
                    if (headerPtr->messageId == EditorMessageIds.kProfilerPlayerInfoMessage)
                    {
                        dataPtr += sizeof(Connection.MessageHeader) + headerPtr->bytes;
                        continue;
                    }

                    Assert.IsTrue(headerPtr->messageId == EditorMessageIds.kProfilerDataMessage);

                    // Parse message
                    byte *messagePtr = dataPtr + sizeof(Connection.MessageHeader);
                    while (messagePtr < dataPtr + headerPtr->bytes)
                    {
                        // Possibly a profiler global header first
                        bool isGlobalHeader = *(uint *)(messagePtr + 0) == ProfilerProtocolSession.kSessionGlobalHeader;
                        if (isGlobalHeader)
                        {
                            messagePtr += 36;
                        }

                        // Profiler block header
                        Assert.IsTrue(*(uint *)(messagePtr + 0) == ProfilerProtocolStream.kPacketBlockHeader);
                        int blockIndex = *(int *)(messagePtr + 4);
                        int byteSize   = *(int *)(messagePtr + 16);

                        // Profiler block body
                        switch (*(ProfilerMessageType *)(messagePtr + 20))
                        {
                        case ProfilerMessageType.ProfilerState:
                            break;

                        case ProfilerMessageType.ThreadInfo:
                            break;

#if !NET_DOTS
                        case ProfilerMessageType.MarkerInfo:
                            Assert.IsTrue(markerDefined.Add(*(uint *)(messagePtr + 24)));
                            break;

                        case ProfilerMessageType.BeginSample:
                            Assert.IsTrue(markerDefined.Contains(*(uint *)(messagePtr + 28)));
                            break;

                        case ProfilerMessageType.EndSample:
                            Assert.IsTrue(markerDefined.Contains(*(uint *)(messagePtr + 28)));
                            break;
#else
                        case ProfilerMessageType.MarkerInfo:
                            markerDefined.Add(*(uint *)(messagePtr + 24), true);
                            break;

                        case ProfilerMessageType.BeginSample:
                            Assert.IsTrue(markerDefined.ContainsKey(*(uint *)(messagePtr + 28)));
                            break;

                        case ProfilerMessageType.EndSample:
                            Assert.IsTrue(markerDefined.ContainsKey(*(uint *)(messagePtr + 28)));
                            break;
#endif
                        }

                        // Profiler block footer
                        Assert.IsTrue(*(int *)(messagePtr + 20 + byteSize + 0) == blockIndex + 1);
                        Assert.IsTrue(*(uint *)(messagePtr + 20 + byteSize + 4) == ProfilerProtocolStream.kPacketBlockFooter);

                        messagePtr += 20 + byteSize + 8;
                    }

                    dataPtr = messagePtr;
                }
            }
        }