示例#1
0
        public override void Initialize()
        {
            //* Register named functions
            mDummyFunction    = RegisterPPUFunction(0xB43518);
            appCreate         = RegisterPPUFunction(0x901B10, "appCreate");
            appInit           = RegisterPPUFunction(0x10488, "appInit");
            appUpdateEx       = RegisterPPUFunction(0x9209B0, "appUpdateEx");
            sndManGetBgm      = RegisterPPUFunction(0x6CCB8, "sndManGetBgm");
            sndManPlayBgm     = RegisterPPUFunction(0x6CF04, "sndManPlayBgm");
            seqManTransition  = RegisterPPUFunction(0x10DB4, "seqManTransition");
            taskProc_fld_main = RegisterPPUFunction(0x29BF68);

            //* Hook some functions
            mDummyFunctionHook   = mDummyFunction.Hook(DummyFunctionDetour);
            mAppUpdateExHook     = appUpdateEx.Hook(appUpdateExDetour);
            mTaskProcFldMainHook = taskProc_fld_main.Hook(taskProc_fld_mainDetour);
        }
示例#2
0
        //private ulong CallFunction( PPUFunction function, context_t* context, Action<Ptr<context_t>> setArgsAction = default)
        //{
        //    // Save context
        //    var originalContext = *context;

        //    if ( setArgsAction != default )
        //        setArgsAction( context );

        //    // Set return address to dummy function address
        //    context->cia = 0;
        //    context->lr = mDummyFunction.VirtualAddress;
        //    IFunction<PPUFunctionDelegate> currentFunction = function;
        //    var currentFunctionAddress = function.VirtualAddress;

        //    while ( true )
        //    {
        //        // Call function (which may or may not run)
        //        context->cia = 0;
        //        currentFunction.GetWrapper()( context );

        //        if ( context->cia == currentFunctionAddress )
        //        {
        //            // Function hasn't actually run (blocked by __check which sets the cia)
        //        }
        //        else if ( context->cia != mDummyFunction.VirtualAddress )
        //        {
        //            // Function was actually run (not blocked by __check), but still has more functions to execute
        //            // Get next function in call chain
        //            currentFunctionAddress = ( uint )context->lr;
        //            currentFunction = Bindings.PPUFunctions[currentFunctionAddress];
        //        }
        //        else if ( context->cia == mDummyFunction.VirtualAddress )
        //        {
        //            // Assume function was actually executed if cia is now the previously set return address
        //            break;
        //        }
        //        else
        //        {
        //            throw new NotImplementedException();
        //        }
        //    }

        //    // Save return value
        //    var returnValue = context->r3;

        //    // Restore registers
        //    Copy( context, context->gpr, originalContext.gpr );

        //    return returnValue;
        //}

        private ulong CallFunction(PPUFunction function, context_t *context, Action <Ptr <context_t> > setArgsAction = default)
        {
            // Save context
            var originalContext = *context;

            if (setArgsAction != default)
            {
                setArgsAction(context);
            }

            context->lr = mDummyFunction.VirtualAddress;
            var currentFunction = function;

            while (true)
            {
                // Call function (which may or may not run)
                context->cia = 0;
                currentFunction.GetWrapper()(context);

                // Check if our sentinel exit function has been run
                if (context->cia == 0xDEADBABE)
                {
                    break;
                }

                if (context->lr != mDummyFunction.VirtualAddress)
                {
                    // Call next function in chain
                    currentFunction = Bindings.PPUFunctions[( uint )context->lr];
                }
            }

            // Save return value
            var returnValue = context->r3;

            // Restore registers
            Copy(context, context->gpr, originalContext.gpr);

            return(returnValue);
        }