private void MemoryStickInserted(Timer timer, object state)
        {
            KCallback cb = ( KCallback )state;

            // 1 = inserted, 2 = ejected
            _kernel.NotifyCallback(cb, ( uint )1);
        }
示例#2
0
        private IEnumerator LoadUIAssetBundle(string name, UILoadState openState, KCallback callback = null)
        {
            if (openState.UIResourceLoader != null)
            {
                openState.UIResourceLoader.Release(true);// now!
                Log.Info("Release UI ResourceLoader: {0}", openState.UIResourceLoader.Url);
                openState.UIResourceLoader = null;
            }

            LoadingUICount++;

            var request = new UILoadRequest();

            yield return(KResourceModule.Instance.StartCoroutine(UiBridge.LoadUIAsset(openState, request)));

            GameObject uiObj = request.Asset as GameObject;

            if (uiObj != null)
            {
                InitUIAsset(uiObj);
                // 具体加载逻辑结束

                var canvas = uiObj.GetComponent <Canvas>(); //设置Canvas的enable,减少SetActive的消耗
                if (canvas)
                {
                    canvas.enabled = false;
                }
                uiObj.name = openState.TemplateName;

                var uiBase = UiBridge.CreateUIController(uiObj, openState.TemplateName);

                if (openState.UIWindow != null)
                {
                    Log.Info("Destroy exist UI Window, maybe for reload");
                    GameObject.Destroy(openState.UIWindow.CachedGameObject);
                    openState.UIWindow = null;
                }

                openState.UIWindow = uiBase;

                uiBase.UIName = uiBase.UITemplateName = openState.TemplateName;

                UiBridge.UIObjectFilter(uiBase, uiObj);

                openState.IsLoading = false; // Load完
                openState.isOnInit  = true;
                InitWindow(openState, uiBase, openState.OpenWhenFinish, openState.OpenArgs);
            }
            else
            {
                Log.LogError("load ui {0} result.Asset not a gameobject", name);
            }

            LoadingUICount--;

            if (callback != null)
            {
                callback(null);
            }
        }
        static int _m_ReloadWindow(RealStatePtr L)
        {
            try {
                ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);


                KEngine.UI.UIModule gen_to_be_invoked = (KEngine.UI.UIModule)translator.FastGetCSObj(L, 1);



                {
                    string    _windowTemplateName = LuaAPI.lua_tostring(L, 2);
                    KCallback _callback           = translator.GetDelegate <KCallback>(L, 3);

                    UnityEngine.Coroutine gen_ret = gen_to_be_invoked.ReloadWindow(_windowTemplateName, _callback);
                    translator.Push(L, gen_ret);



                    return(1);
                }
            } catch (System.Exception gen_e) {
                return(LuaAPI.luaL_error(L, "c# exception:" + gen_e));
            }
        }
示例#4
0
        // SDK location: /user/pspthreadman.h:996
        // SDK declaration: int sceKernelReferCallbackStatus(SceUID cb, SceKernelCallbackInfo *status);
        public int sceKernelReferCallbackStatus(int cbid, int status)
        {
            KCallback cb = _kernel.GetHandle <KCallback>(cbid);

            if (cb == null)
            {
                return(-1);
            }

            unsafe
            {
                uint *pstatus = ( uint * )_memorySystem.Translate(( uint )status);
                if (*pstatus == 56)
                {
                    _kernel.WriteString(( uint )status + 4, cb.Name);
                    // Skip over name and size field
                    pstatus += 9;
                    *pstatus = cb.Thread.UID;
                    *(pstatus + 1) = cb.Address;
                    *(pstatus + 2) = cb.CommonAddress;
                    *(pstatus + 3) = cb.NotifyCount;
                    *(pstatus + 4) = cb.NotifyArguments;
                    return(0);
                }
                else
                {
                    Debug.WriteLine(string.Format("sceKernelReferCallbackStatus: expected SceKernelCallbackInfo size of 56, got {0}", *pstatus));
                    return(-1);
                }
            }
        }
示例#5
0
        // SDK location: /user/pspthreadman.h:1033
        // SDK declaration: int sceKernelGetCallbackCount(SceUID cb);
        public int sceKernelGetCallbackCount(int cbid)
        {
            KCallback cb = _kernel.GetHandle <KCallback>(cbid);

            if (cb == null)
            {
                return(-1);
            }
            return(( int )cb.NotifyCount);
        }
示例#6
0
 public void AddConnectListener(KCallback callback)
 {
     mySocket.On(SocketIOEventTypes.Connect, (a1, a2, a3) =>
     {
         Debug.Log("------------------->建立连接" + a2.Payload);
         if (callback != null)
         {
             callback();
         }
     });
 }
示例#7
0
        /// <summary>
        /// Hot reload a ui asset bundle
        /// </summary>
        /// <param name="uiTemplateName"></param>
        public UnityEngine.Coroutine ReloadWindow(string uiTemplateName, KCallback callback)
        {
            UILoadState uiState;

            UIWindows.TryGetValue(uiTemplateName, out uiState);
            if (uiState == null)
            {
                Log.Info("{0} has been destroyed", uiTemplateName);
                return(null);
            }
            return(KResourceModule.Instance.StartCoroutine(LoadUIAssetBundle(uiTemplateName, uiState)));
        }
示例#8
0
        private IEnumerator LoadUIAssetBundle(string name, UILoadState openState, KCallback callback = null)
        {
            if (openState.UIResourceLoader != null)
            {
                openState.UIResourceLoader.Release(true);// now!
                Log.Info("Release UI ResourceLoader: {0}", openState.UIResourceLoader.Url);
                openState.UIResourceLoader = null;
            }

            LoadingUICount++;

            var request = new UILoadRequest();

            yield return(KResourceModule.Instance.StartCoroutine(UiBridge.LoadUIAsset(openState, request)));

            GameObject uiObj = (GameObject)request.Asset;

            if (uiObj != null)
            {
                InitUIAsset(uiObj);
                // 具体加载逻辑结束...这段应该放到Bridge里

                uiObj.SetActive(false);
                uiObj.name = openState.TemplateName;

                var uiBase = UiBridge.CreateUIController(uiObj, openState.TemplateName);

                if (openState.UIWindow != null)
                {
                    Log.Info("Destroy exist UI Window, maybe for reload");
                    GameObject.Destroy(openState.UIWindow.CachedGameObject);
                    openState.UIWindow = null;
                }

                openState.UIWindow = uiBase;

                uiBase.UIName = uiBase.UITemplateName = openState.TemplateName;

                UiBridge.UIObjectFilter(uiBase, uiObj);

                openState.IsLoading = false; // Load完
                openState.isOnInit  = true;
                InitWindow(openState, uiBase, openState.OpenWhenFinish, openState.OpenArgs);
            }

            LoadingUICount--;

            if (callback != null)
            {
                callback(null);
            }
        }
示例#9
0
        // SDK location: /user/pspthreadman.h:1005
        // SDK declaration: int sceKernelDeleteCallback(SceUID cb);
        public int sceKernelDeleteCallback(int cbid)
        {
            KCallback cb = _kernel.GetHandle <KCallback>(cbid);

            if (cb == null)
            {
                return(-1);
            }

            _kernel.DeleteCallback(cb);

            return(0);
        }
示例#10
0
        // manual add
        public int sceUmdUnRegisterUMDCallBack(int cbid)
        {
            KCallback cb = _kernel.GetHandle <KCallback>(cbid);

            if (cb == null)
            {
                return(-1);
            }

            _kernel.Callbacks[Kernel.CallbackTypes.Umd].Remove(cb);

            return(0);
        }
示例#11
0
        // SDK location: /user/pspthreadman.h:1015
        // SDK declaration: int sceKernelNotifyCallback(SceUID cb, int arg2);
        public int sceKernelNotifyCallback(int cbid, int arg2)
        {
            KCallback cb = _kernel.GetHandle <KCallback>(cbid);

            if (cb == null)
            {
                return(-1);
            }

            _kernel.NotifyCallback(cb, ( uint )arg2);

            // Real return set by marshaller
            return(0);
        }
示例#12
0
        // SDK location: /user/psploadexec.h:49
        // SDK declaration: int sceKernelRegisterExitCallback(int cbid);
        public int sceKernelRegisterExitCallback(int cbid)
        {
            KCallback cb = _kernel.GetHandle <KCallback>(cbid);

            if (cb == null)
            {
                Log.WriteLine(Verbosity.Normal, Feature.Bios, "sceKernelRegisterExitCallback: callback ID {0} not found", cbid);
                return(-1);
            }

            _kernel.Callbacks[Kernel.CallbackTypes.Exit].Enqueue(cb);

            return(0);
        }
        public int sceKernelCreateCallback( int name, int func, int arg )
        {
            KThread thread = _kernel.ActiveThread;
            if( thread == null )
                return -1;

            KCallback cb = new KCallback( _kernel,
                _kernel.ReadString( ( uint )name ),
                thread,
                ( uint )func,
                ( uint )arg );
            _kernel.AddHandle( cb );

            return ( int )cb.UID;
        }
示例#14
0
        // SDK location: /user/pspthreadman.h:985
        // SDK declaration: int sceKernelCreateCallback(const char *name, SceKernelCallbackFunction func, void *arg);
        public int sceKernelCreateCallback(int name, int func, int arg)
        {
            KThread thread = _kernel.ActiveThread;

            if (thread == null)
            {
                return(-1);
            }

            KCallback cb = new KCallback(_kernel,
                                         _kernel.ReadString(( uint )name),
                                         thread,
                                         ( uint )func,
                                         ( uint )arg);

            _kernel.AddHandle(cb);

            return(( int )cb.UID);
        }
示例#15
0
        public void AddDisconnectListener(KCallback callback)
        {
            mySocket.On(SocketIOEventTypes.Disconnect, (a1, a2, a3) =>
            {
                Debug.Log("------------------->断开连接" + a2.Payload);
                if (callback != null)
                {
                    callback();
                }
            });
//            mySocket.On(SocketIOEventTypes.Error, (a1, a2, a3) =>
//            {
//                Debug.Log("------------------->出错了" + a2.Payload);
//                if (callback != null) callback();
//            });
//            mySocket.On(SocketIOEventTypes.Unknown, (a1, a2, a3) =>
//            {
//                Debug.Log("------------------->未知反馈" + a2.Payload);
//                if (callback != null) callback();
//            });
        }
        // SDK location: /user/pspiofilemgr.h:306
        // SDK declaration: int sceIoDevctl(const char *dev, unsigned int cmd, void *indata, int inlen, void *outdata, int outlen);
        public unsafe int sceIoDevctl(int dev, int cmd, int indata, int inlen, int outdata, int outlen)
        {
            // Usually callbacks are created right before this
            //Syscall: ThreadManForUser::sceKernelCreateCallback(08AE7638, 08A892D0, 00000000) from 0x08A87F70
            //Syscall: IoFileMgrForUser::sceIoDevctl(08AE7628, 02415821, 08027BA4, 00000004, 00000000, 00000000) from 0x08A87FAC (NI)

            // Issue the last created callback?

            string name = _kernel.ReadString(( uint )dev);

            // We only support ms for now
            if ((name != "fatms0:") &&
                (name != "mscmhc0:") &&
                (name != "ms0:"))
            {
                Log.WriteLine(Verbosity.Normal, Feature.Bios, "sceIoDevctl: device {0} not supported", name);
                return(0);
            }

            IMemoryStickDevice memoryStick = _kernel.Emulator.MemoryStick;

            Debug.Assert(memoryStick != null);

            byte *inp  = ( byte * )0;
            byte *outp = ( byte * )0;

            if (indata != 0)
            {
                inp = _memorySystem.Translate(( uint )indata);
            }
            if (outdata != 0)
            {
                outp = _memorySystem.Translate(( uint )outdata);
            }

            switch (cmd)
            {
            case 0x02425818:                            // Write free space to indata
                Debug.Assert(inlen == 4);
                {
                    uint capacity = ( uint )memoryStick.Capacity / (512 * 64);
                    uint free     = ( uint )memoryStick.Available / (512 * 64);
                    // 0 * 3 * 4 = total bytes
                    // 1 * 3 * 4 = total free bytes
                    // 2 * 3 * 4 = slightly less than total free bytes?
                    // 124958 42083 41968 512 64
                    if (indata != 0)
                    {
                        uint *p = ( uint * )_memorySystem.Translate(*( uint * )inp);
                        p[0] = capacity;                                // total
                        p[1] = free;                                    // free
                        p[2] = free - 115;
                        p[3] = 512;                                     // scalar 1
                        p[4] = 64;                                      // scalar 2
                    }
                    // Not sure if this is the right thing to do - outp seems to point to the
                    // same address as *inp
                    if (outdata != 0)
                    {
                        uint *p = ( uint * )outp;
                        p[0] = capacity;                                // total
                        p[1] = free;                                    // free
                        p[2] = free - 115;
                        p[3] = 512;                                     // scalar 1
                        p[4] = 64;                                      // scalar 2
                    }
                }
                break;

            case 0x0240D81E:                                    // Refresh directory listings - no params
                break;

            case 0x02025806:                                    // Get insertion status
                // outdata should be pointer to dword to write 1 = in, 2 = out
                Debug.Assert(outlen == 4);
                *( uint * )outp = 1;
                break;

            case 0x02015804:                                    // Some MS thing
            //Debug.Assert( inlen == 4 );
            //{
            //    uint data = *( uint* )inp;
            //}
            //break;
            case 0x02415821:                                    // Register insert/eject callback
                Debug.Assert(inlen == 4);
                {
                    //Debug.Assert( _msInsertEjectCallback == null );
                    uint cbid = *( uint * )inp;
                    _msInsertEjectCallback = _kernel.GetHandle <KCallback>(cbid);
                    if (_msInsertEjectCallback != null)
                    {
                        Log.WriteLine(Verbosity.Normal, Feature.Bios, "Registered MemoryStick insert/eject callback: {0} ({1:X8})", _msInsertEjectCallback.Name, _msInsertEjectCallback.UID);
                        _kernel.AddOneShotTimer(new KernelTimerCallback(this.MemoryStickInserted), _msInsertEjectCallback, 100);
                    }
                    else
                    {
                        Log.WriteLine(Verbosity.Critical, Feature.Bios, "sceIoDevctl: could not find callback {0} for MemoryStick insert/eject", cbid);
                    }
                }
                break;

            case 0x02415822:                                    // Unregister insert/eject callback
                Debug.Assert(inlen == 4);
                {
                    uint cbid = *( uint * )inp;
                    Debug.Assert(_msInsertEjectCallback != null);
                    Debug.Assert(_msInsertEjectCallback.UID == cbid);
                    // We may have multiple callbacks and stuff, but I don't care
                    _msInsertEjectCallback = null;
                }
                break;

            case 0x02425823:
                // Unknown - guessing wait on MS insert/eject? Forever?
                if (outp != null)
                {
                    *( uint * )outp = 1;
                }
                //return unchecked( ( int )0x80020325 );
                break;

            case DevctlActivateUmd:                     // Activate the UMD drive for real?
                // Nothing?
                break;

            default:
                Log.WriteLine(Verbosity.Normal, Feature.Bios, "sceIoDevctl: unknown command 0x" + cmd.ToString("X8") + " on device " + name);
                return(0);
            }

            return(0);
        }
        public unsafe int sceIoDevctl( int dev, int cmd, int indata, int inlen, int outdata, int outlen )
        {
            // Usually callbacks are created right before this
            //Syscall: ThreadManForUser::sceKernelCreateCallback(08AE7638, 08A892D0, 00000000) from 0x08A87F70
            //Syscall: IoFileMgrForUser::sceIoDevctl(08AE7628, 02415821, 08027BA4, 00000004, 00000000, 00000000) from 0x08A87FAC (NI)

            // Issue the last created callback?

            string name = _kernel.ReadString( ( uint )dev );
            // We only support ms for now
            if( ( name != "fatms0:" ) &&
                ( name != "mscmhc0:" ) &&
                ( name != "ms0:" ) )
            {
                Log.WriteLine( Verbosity.Normal, Feature.Bios, "sceIoDevctl: device {0} not supported", name );
                return 0;
            }

            IMemoryStickDevice memoryStick = _kernel.Emulator.MemoryStick;
            Debug.Assert( memoryStick != null );

            byte* inp = ( byte* )0;
            byte* outp = ( byte* )0;
            if( indata != 0 )
                inp = _memorySystem.Translate( ( uint )indata );
            if( outdata != 0 )
                outp = _memorySystem.Translate( ( uint )outdata );

            switch( cmd )
            {
                case 0x02425818:	// Write free space to indata
                    Debug.Assert( inlen == 4 );
                    {
                        uint capacity = ( uint )memoryStick.Capacity / ( 512 * 64 );
                        uint free = ( uint )memoryStick.Available / ( 512 * 64 );
                        // 0 * 3 * 4 = total bytes
                        // 1 * 3 * 4 = total free bytes
                        // 2 * 3 * 4 = slightly less than total free bytes?
                        // 124958 42083 41968 512 64
                        if( indata != 0 )
                        {
                            uint* p = ( uint* )_memorySystem.Translate( *( uint* )inp );
                            p[ 0 ] = capacity;	// total
                            p[ 1 ] = free;		// free
                            p[ 2 ] = free - 115;
                            p[ 3 ] = 512;	// scalar 1
                            p[ 4 ] = 64;	// scalar 2
                        }
                        // Not sure if this is the right thing to do - outp seems to point to the
                        // same address as *inp
                        if( outdata != 0 )
                        {
                            uint* p = ( uint* )outp;
                            p[ 0 ] = capacity;	// total
                            p[ 1 ] = free;		// free
                            p[ 2 ] = free - 115;
                            p[ 3 ] = 512;	// scalar 1
                            p[ 4 ] = 64;	// scalar 2
                        }
                    }
                    break;
                case 0x0240D81E:		// Refresh directory listings - no params
                    break;
                case 0x02025806:		// Get insertion status
                    // outdata should be pointer to dword to write 1 = in, 2 = out
                    Debug.Assert( outlen == 4 );
                    *( uint* )outp = 1;
                    break;
                case 0x02015804:		// Some MS thing
                    //Debug.Assert( inlen == 4 );
                    //{
                    //    uint data = *( uint* )inp;
                    //}
                    //break;
                case 0x02415821:		// Register insert/eject callback
                    Debug.Assert( inlen == 4 );
                    {
                        //Debug.Assert( _msInsertEjectCallback == null );
                        uint cbid = *( uint* )inp;
                        _msInsertEjectCallback = _kernel.GetHandle<KCallback>( cbid );
                        if( _msInsertEjectCallback != null )
                        {
                            Log.WriteLine( Verbosity.Normal, Feature.Bios, "Registered MemoryStick insert/eject callback: {0} ({1:X8})", _msInsertEjectCallback.Name, _msInsertEjectCallback.UID );
                            _kernel.AddOneShotTimer( new KernelTimerCallback( this.MemoryStickInserted ), _msInsertEjectCallback, 100 );
                        }
                        else
                            Log.WriteLine( Verbosity.Critical, Feature.Bios, "sceIoDevctl: could not find callback {0} for MemoryStick insert/eject", cbid );
                    }
                    break;
                case 0x02415822:		// Unregister insert/eject callback
                    Debug.Assert( inlen == 4 );
                    {
                        uint cbid = *( uint* )inp;
                        Debug.Assert( _msInsertEjectCallback != null );
                        Debug.Assert( _msInsertEjectCallback.UID == cbid );
                        // We may have multiple callbacks and stuff, but I don't care
                        _msInsertEjectCallback = null;
                    }
                    break;
                case 0x02425823:
                    // Unknown - guessing wait on MS insert/eject? Forever?
                    if( outp != null )
                        *( uint* )outp = 1;
                    //return unchecked( ( int )0x80020325 );
                    break;

                case DevctlActivateUmd:	// Activate the UMD drive for real?
                    // Nothing?
                    break;

                default:
                    Log.WriteLine( Verbosity.Normal, Feature.Bios, "sceIoDevctl: unknown command 0x" + cmd.ToString( "X8" ) + " on device " + name );
                    return 0;
            }

            return 0;
        }