/// <summary>
        /// Get the game mode. Note that this is NOT the same enum as GameStateGame.Mode, although the
        /// backing variables all match, so direct casts are possible.
        /// </summary>
        /// <param name="game"></param>
        /// <returns></returns>
        public static Mode CurrentState(this GameStateGame game)
        {
            if (game is null)
            {
                return(Mode.NullState);
            }
            Type GSGMode = game.GetType().GetNestedType("Mode", BindingFlags.NonPublic);

            // This should work on both the Patched and non-patched version of the game,
            // since we ask reflection for public and non public fields.
            return((Mode)game.GetType()
                   .GetField("mMode", instanceFlags)
                   .GetValue(game));
        }
示例#2
0
        public static void Prefix(GameStateGame __instance, out State __state)
        {
            Module mActiveModule = __instance.GetType()
                                   .GetField("mActiveModule", BindingFlags.NonPublic | BindingFlags.Instance)
                                   .GetValue(__instance) as Module;
            bool?mRenderTops = __instance.GetType()
                               .GetField("mRenderTops", BindingFlags.NonPublic | BindingFlags.Instance)
                               .GetValue(__instance) as bool?;


            if (mActiveModule.isValidPosition())
            {
                __state = new State(mActiveModule, (bool)mRenderTops);
            }
            else
            {
                __state = null;
            }
        }
        /// <summary>
        /// Get mCurrentModuleSize, or zero if game is null.
        /// </summary>
        /// <param name="game"></param>
        /// <returns></returns>
        public static int GetActiveModuleSizeIndex(this GameStateGame game)
        {
            if (game is null)
            {
                return(0);
            }

            return((int)game.GetType()
                   .GetField("mCurrentModuleSize", instanceFlags)
                   .GetValue(game));
        }
        /// <summary>
        /// Get the active module, or null if game is null.
        /// </summary>
        /// <param name="game"></param>
        /// <returns></returns>
        public static Module GetActiveModule(this GameStateGame game)
        {
            if (game is null)
            {
                return(null);
            }

            return((Module)game.GetType()
                   .GetField("mActiveModule", instanceFlags)
                   .GetValue(game));
        }
示例#5
0
        public static bool Show(string message, float time)
        {
            if (!(GameManager.getInstance().getGameState() is GameStateGame))
            {
                return(false);
            }

            GameStateGame gameState    = GameManager.getInstance().getGameState() as GameStateGame;
            MethodInfo    addToastInfo = Reflection.GetPrivateMethodOrThrow(gameState.GetType(), "addToast", true);

            Reflection.InvokeInstanceMethod(gameState, addToastInfo, new object[] { message, time });
            return(true);
        }
        public static bool Show(GuiDefinitions.Callback callback, string title, string text)
        {
            GameState gameState = GameManager.getInstance().getGameState();

            if (gameState is GameStateGame)
            {
                GuiGameOverWindow window        = new GuiGameOverWindow(callback, title, text);
                GameStateGame     gameStateGame = (GameStateGame)gameState;
                FieldInfo         mGameGuiInfo  = Reflection.GetPrivateFieldOrThrow(gameStateGame.GetType(), "mGameGui", true);
                GameGui           mGameGui      = (GameGui)Reflection.GetInstanceFieldValue(gameStateGame, mGameGuiInfo);
                mGameGui.setWindow(window);
                return(true);
            }

            if (gameState is GameStateMultiplayer)
            {
                GameStateMultiplayer gameStateMultiplayer = (GameStateMultiplayer)gameState;
                gameStateMultiplayer.ShowMessageBox(callback, title, text);
                return(true);
            }

            // Not supported
            return(false);
        }