예제 #1
0
 private void Update()
 {
     if (m_refreshMode == CacheRefreshMode.Always)
     {
         Refresh(true);
     }
     else
     {
         for (int i = 0; i < m_transforms.Count; ++i)
         {
             Transform t = m_transforms[i];
             if (t != null)
             {
                 PRS prs = m_prs[i];
                 if (prs.Position != t.position || prs.Rotation != t.rotation || prs.LocalScale != t.localScale)
                 {
                     prs.Position   = t.position;
                     prs.Rotation   = t.rotation;
                     prs.LocalScale = t.localScale;
                     Refresh(true);
                     break;
                 }
             }
         }
     }
 }
예제 #2
0
        internal static byte[] CompressPRC(byte[] data, uint key, bool big_endian)
        {
            int dprs_size = data.Length;

            data = PRS.Compress(data);
            int cprs_size = data.Length;

            PRC prc = new PRC(key);

            Array.Resize(ref data, (int)((data.Length + 3) & 0xFFFFFFFC));
            prc.CryptData(data, 0, cprs_size, big_endian);

            ByteArray ba = new ByteArray(cprs_size + 8);

            if (big_endian)
            {
                ba.Endianess = Endianess.BigEndian;
            }

            ba.Write(dprs_size);
            ba.Write(key);
            ba.Write(data, 0, cprs_size);

            return(ba.Buffer);
        }
예제 #3
0
        public byte[] Decipher(byte[] data, bool compressed)
        {
            int length = (data.Length - 4) / 8;

            byte[] enc = new byte[length * 8];

            for (int i = 0; i < length; i++)
            {
                int os1 = (i * 8) + 4;
                int os2 = i * 8;

                Buffer.BlockCopy(data, os1, enc, os2, 8);
            }

            enc = Utility.byteSwap(enc);
            enc = blowfish.Decrypt_ECB(enc);
            enc = Utility.byteSwap(enc);

            Buffer.BlockCopy(enc, 0, data, 4, enc.Length);

            if (compressed)
            {
                byte[] xor = Utility.xor(Utility.dStrip(data));
                xor = PRS.Decompress(xor);
                xor = Utility.dReplace(data, xor);

                return(xor);
            }

            return(data);
        }
예제 #4
0
 void OnPRSChange(PRS _prs)
 {
     if (prs != _prs)
     {
         return;
     }
     SetPRS(_prs);
 }
예제 #5
0
    public void Initialize(Entity _entity)
    {
        entity   = _entity;
        prs      = entity.GetComponent <PRS>();
        gameview = entity.GetComponent <GameView>();
        tr       = transform;

        Pool.AddDirtyHandler <PRS>(OnPRSChange);
        SetPRS(prs);
    }
예제 #6
0
 public void MoveTransform(PRS prs, bool useDotween, float dotweenTime = 0)
 {
     if (useDotween)
     {
         transform.DOMove(prs.pos, dotweenTime);
         transform.DOLocalRotateQuaternion(prs.rotation, dotweenTime);
         transform.DOScale(prs.scale, dotweenTime);
     }
     else
     {
         transform.position   = prs.pos;
         transform.rotation   = prs.rotation;
         transform.localScale = prs.scale;
     }
 }
예제 #7
0
        internal static byte[] DecompressPRC(byte[] data, bool big_endian)
        {
            ByteArray ba = new ByteArray(data);

            if (big_endian)
            {
                ba.Endianess = Endianess.BigEndian;
            }

            int  size = ba.ReadI32();
            uint key  = ba.ReadU32();

            byte[] result = new byte[(int)((ba.Length - 8 + 3) & 0xFFFFFFFC)];
            ba.Read(result, 0, ba.Length - 8);

            PRC prc = new PRC(key);

            prc.CryptData(result, 0, result.Length, big_endian);
            Array.Resize(ref result, size);

            result = PRS.Decompress(result);

            return(result);
        }
예제 #8
0
        static void Main(string[] args)
        {
            // defaults
            ushort SERVER_PORT          = 30000;
            ushort STARTING_CLIENT_PORT = 40000;
            ushort ENDING_CLIENT_PORT   = 40099;
            int    KEEP_ALIVE_TIMEOUT   = 10;

            try
            {
                // process command options
                // -p < service port >
                // -s < starting client port number >
                // -e < ending client port number >
                // -t < keep alive time in seconds >
                for (int i = 0; i < args.Length; i++)
                {
                    switch (args[i])
                    {
                    case "-p":
                        SERVER_PORT = Convert.ToUInt16(args[++i]);
                        break;

                    case "-s":
                        STARTING_CLIENT_PORT = Convert.ToUInt16(args[++i]);
                        break;

                    case "-e":
                        ENDING_CLIENT_PORT = Convert.ToUInt16(args[++i]);
                        break;

                    case "-t":
                        KEEP_ALIVE_TIMEOUT = Convert.ToInt16(args[++i]);
                        break;
                    }
                }

                if (STARTING_CLIENT_PORT <= SERVER_PORT || STARTING_CLIENT_PORT >= ENDING_CLIENT_PORT)
                {
                    throw new Exception("Invalid range: -p must be outside of -s to -e range and -e must be larger then -s");
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Invalid Command line Arguments");
                Console.WriteLine(ex);
                Usage();
            }


            // initialize the PRS server
            PRS prs = new PRS(STARTING_CLIENT_PORT, ENDING_CLIENT_PORT, KEEP_ALIVE_TIMEOUT);

            // create the socket for receiving messages at the server
            Socket listeningSocket = new Socket(SocketType.Dgram, ProtocolType.Udp);

            // bind the listening socket to the PRS server port
            listeningSocket.Bind(new IPEndPoint(IPAddress.Any, SERVER_PORT));

            // Process client messages

            while (!prs.Stopped)
            {
                EndPoint clientEndPoint = null;
                try
                {
                    // receive a message from a client
                    clientEndPoint = new IPEndPoint(IPAddress.Any, 0);
                    PRSMessage msg = PRSMessage.ReceiveMessage(listeningSocket, ref clientEndPoint);

                    // let the PRS handle the message
                    PRSMessage responMessage = prs.HandleMessage(msg);

                    // send response message back to client
                    responMessage.SendMessage(listeningSocket, clientEndPoint);
                }
                catch (Exception ex)
                {
                    // attempt to send a UNDEFINED_ERROR response to the client, if we know who that was
                    if (clientEndPoint != null)
                    {
                        PRSMessage errorMessage = new PRSMessage(PRSMessage.MESSAGE_TYPE.RESPONSE, "", 0, PRSMessage.STATUS.UNDEFINED_ERROR);
                    }
                }
            }

            // close the listening socket
            listeningSocket.Close();

            // wait for a keypress from the user before closing the console window
            Console.WriteLine("Press Enter to exit");
            Console.ReadKey();
        }
예제 #9
0
 void SetPRS(PRS _prs)
 {
     tr.position   = _prs.position;
     tr.rotation   = Quaternion.Euler(_prs.rotation);
     tr.localScale = _prs.scale;
 }
예제 #10
0
        static void Main(string[] args)
        {
            // defaults
            ushort SERVER_PORT          = 30000;
            ushort STARTING_CLIENT_PORT = 40000;
            ushort ENDING_CLIENT_PORT   = 40099;
            int    KEEP_ALIVE_TIMEOUT   = 10; //300

            try
            {
                // -p < service port >
                // -s < starting client port number >
                // -e < ending client port number >
                // -t < keep alive time in seconds >

                for (int i = 0; i < args.Length; i++)
                {
                    if (args[i] == "-p")
                    {
                        SERVER_PORT = ushort.Parse(args[i + 1]);
                    }
                    if (args[i] == "-s")
                    {
                        SERVER_PORT = ushort.Parse(args[i + 1]);
                    }
                    if (args[i] == "-e")
                    {
                        ENDING_CLIENT_PORT = ushort.Parse(args[i + 1]);
                    }
                    if (args[i] == "-t")
                    {
                        KEEP_ALIVE_TIMEOUT = int.Parse(args[i + 1]);
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Exception: " + ex.Message);
                Console.WriteLine(ex.StackTrace);
            }

            // initialize the PRS server
            PRS prs = new PRS(STARTING_CLIENT_PORT, ENDING_CLIENT_PORT, KEEP_ALIVE_TIMEOUT);

            // create the socket for receiving messages at the server
            Socket listeningSocket = new Socket(SocketType.Dgram, ProtocolType.Udp);

            // bind the listening socket to the PRS server port
            listeningSocket.Bind(new IPEndPoint(IPAddress.Any, SERVER_PORT));

            //
            // Process client messages
            //

            while (!prs.Stopped)
            {
                EndPoint clientEndPoint = null;
                try
                {
                    // receive a message from a client
                    clientEndPoint = new IPEndPoint(IPAddress.Any, 0);
                    PRSMessage msg = PRSMessage.ReceiveMessage(listeningSocket, ref clientEndPoint);

                    // let the PRS handle the message
                    PRSMessage response = prs.HandleMessage(msg);

                    // send response message back to client
                    response.SendMessage(listeningSocket, clientEndPoint);
                }
                catch (Exception ex)
                {
                    // attempt to send a UNDEFINED_ERROR response to the client, if we know who that was
                    if (clientEndPoint != null)
                    {
                        PRSMessage errorMsg = new PRSMessage(PRSMessage.MESSAGE_TYPE.RESPONSE, "", 0, PRSMessage.STATUS.UNDEFINED_ERROR);
                        errorMsg.SendMessage(listeningSocket, clientEndPoint);
                    }
                }
            }

            // close the listening socket
            listeningSocket.Close();
            // wait for a keypress from the user before closing the console window
            Console.WriteLine("Press Enter to exit");
            Console.ReadKey();
        }
예제 #11
0
        static void Main(string[] args)
        {
            // defaults
            ushort SERVER_PORT          = 30000;
            ushort STARTING_CLIENT_PORT = 40000;
            ushort ENDING_CLIENT_PORT   = 40099;
            int    KEEP_ALIVE_TIMEOUT   = 300;

            // process command options
            // -p < service port >
            // -s < starting client port number >
            // -e < ending client port number >
            // -t < keep alive time in seconds >

            for (int i = 0; i < args.Length; i++)
            {
                switch (args[i])
                {
                case "-p":
                {
                    SERVER_PORT = ushort.Parse(args[++i]);
                }
                break;

                case "-s":
                {
                    STARTING_CLIENT_PORT = ushort.Parse(args[++i]);
                }
                break;

                case "-e":
                {
                    ENDING_CLIENT_PORT = ushort.Parse(args[++i]);
                }
                break;

                case "-t":
                {
                    KEEP_ALIVE_TIMEOUT = int.Parse(args[++i]);
                }
                break;

                default:
                {
                    Console.WriteLine($"Error: Invalid argument - {args[i]}");
                    return;
                }
                }
            }

            // check for valid STARTING_CLIENT_PORT and ENDING_CLIENT_PORT
            if (STARTING_CLIENT_PORT >= ENDING_CLIENT_PORT ||
                STARTING_CLIENT_PORT == 0 ||
                ENDING_CLIENT_PORT == 0 ||
                STARTING_CLIENT_PORT == SERVER_PORT ||
                ENDING_CLIENT_PORT == SERVER_PORT)
            {
                Console.WriteLine("Error: Invalid starting and/or ending port(s)");
                return;
            }

            Console.WriteLine("Server starting...");
            Console.WriteLine($"\tServer port: {SERVER_PORT}");
            Console.WriteLine($"\tStarting port: {STARTING_CLIENT_PORT}");
            Console.WriteLine($"\tEnding port: {ENDING_CLIENT_PORT}");
            Console.WriteLine($"\tTimeout: {KEEP_ALIVE_TIMEOUT}");

            // initialize the PRS server
            PRS prs = new PRS(STARTING_CLIENT_PORT, ENDING_CLIENT_PORT, KEEP_ALIVE_TIMEOUT);

            // create the socket for receiving messages at the server
            Socket socket = new Socket(SocketType.Dgram, ProtocolType.Udp);

            // bind the listening socket to the PRS server port
            socket.Bind(new IPEndPoint(IPAddress.Any, SERVER_PORT));

            //
            // Process client messages
            //

            while (!prs.Stopped)
            {
                try
                {
                    // receive a message from a client
                    EndPoint   remoteEndPoint  = new IPEndPoint(IPAddress.Any, 0);
                    PRSMessage messageReceived = PRSMessage.ReceiveMessage(socket, ref remoteEndPoint);

                    // let the PRS handle the message
                    PRSMessage messageResponse = prs.HandleMessage(messageReceived);

                    // send response message back to client
                    messageResponse.SendMessage(socket, remoteEndPoint);
                }
                catch (Exception ex)
                {
                    // attempt to send a UNDEFINED_ERROR response to the client, if we know who that was
                    Console.WriteLine(ex.Message);
                }
            }

            // close the listening socket
            socket.Close();

            // wait for a keypress from the user before closing the console window
            Console.WriteLine("Press Enter to exit");
            Console.ReadKey();
        }
예제 #12
0
파일: sba.cs 프로젝트: memerdot/puyotools
        /* To simplify the process greatly, we are going to convert
         * the Storybook Archive to a new format */
        public override MemoryStream TranslateData(ref Stream stream)
        {
            try
            {
                /* Get the number of files */
                uint files = stream.ReadUInt(0x0).SwapEndian();

                /* Now create the header */
                MemoryStream data = new MemoryStream();
                data.Write(files);

                /* Write each file in the header */
                uint offset = 0xC + (files * 0x2C);
                for (int i = 0; i < files; i++)
                {
                    uint length = stream.ReadUInt(0x3C + (i * 0x30)).SwapEndian();

                    data.Write(offset); // Offset
                    data.Write(length); // Length
                    data.Write(stream.ReadString(0x10 + (i * 0x30), 36), 36); // Filename

                    /* Let's write the decompressed data */
                    uint sourceOffset     = stream.ReadUInt(0x34 + (i * 0x30)).SwapEndian();
                    uint sourceLength     = stream.ReadUInt(0x38 + (i * 0x30)).SwapEndian();
                    Stream compressedData = stream.Copy(sourceOffset, sourceLength);

                    /* Decompress the data */
                    PRS decompressor = new PRS();
                    MemoryStream decompressedData = decompressor.Decompress(ref compressedData, length);
                    if (decompressedData == null)
                        throw new Exception();

                    /* Write the data */
                    data.Position = offset;
                    data.Write(decompressedData);
                    data.Position = 0x30 + (i * 0x2C);
                    decompressedData.Close();

                    offset += length;
                }

                return data;
            }
            catch
            {
                return new MemoryStream();
            }
        }