Example #1
0
        void Start()
        {
            MethodInfo   regRecf        = typeof(RaftMod).GetMethod("RegisterRecipe", BindingFlags.NonPublic | BindingFlags.Instance);
            PropertyInfo recipep        = typeof(Item).GetProperty("recipe");
            PropertyInfo convertRecipep = typeof(Item).GetProperty("convertRecipe");
            MethodInfo   initf          = typeof(Item).GetMethod("Init", BindingFlags.NonPublic | BindingFlags.Instance);

            foreach (RaftMod mod in RaftMod.Get())
            {
                if (mod.Metadata.ModName != "Raft")
                {
                    //Register all recipes into items
                    //Which is how it works... for now
                    foreach (Recipe recipe in mod.GetRecipes())
                    {
                        Item i = recipe.result;

                        if (recipep.GetValue(i, null) != null)
                        {
                            Console.WriteLine("Couldn't register recipe; \"" + recipe.ToString() + "\", it was already occupied. This is a Raft Game Architecture problem.");
                        }
                        else
                        {
                            recipep.SetValue(i, recipe, null);
                        }
                    }

                    //Register all convert recipes into items
                    //Which is how it works... for now
                    foreach (ConvertRecipe recipe in mod.GetConversions())
                    {
                        Item i = recipe.input;

                        if (convertRecipep.GetValue(i, null) != null)
                        {
                            Console.WriteLine("Couldn't register convert recipe; \"" + recipe.ToString() + "\", it was already occupied. This is a Raft Game Architecture problem.");
                        }
                        else
                        {
                            convertRecipep.SetValue(i, recipe, null);
                        }
                    }

                    foreach (Item i in mod.GetItems())
                    {
                        initf.Invoke(i, null);
                    }

                    //Register recipes
                    foreach (ConvertRecipe recipe in mod.GetConversions())
                    {
                        regRecf.Invoke(mod, new object[] { recipe });
                    }
                }
            }
        }
Example #2
0
        void UpdateSceneChange()
        {
            bool pInGame = inGame;

            inGame = GameObject.Find("_CanvasGame_New") != null;

            MethodInfo initPlayerf = typeof(Item).GetMethod("InitPlayer", BindingFlags.NonPublic | BindingFlags.Instance);

            if (!pInGame && inGame)
            {
                foreach (RaftMod mod in RaftMod.Get())
                {
                    foreach (Item item in mod.GetItems())
                    {
                        initPlayerf.Invoke(item, new object[] { PlayerHelper.GetPlayer("") });
                    }
                }
            }

            foreach (ISceneListener sceneListener in RaftMod.GetInterfaces <ISceneListener>())
            {
                SceneUpdateType sceneUpdate = SceneUpdateType.Game_join;

                if (!pInGame && inGame)
                {
                    sceneListener.OnGameJoin();
                }
                else if (pInGame && !inGame)
                {
                    sceneListener.OnGameLeave();
                    sceneUpdate = SceneUpdateType.Game_leave;
                }
                else if (pInGame && inGame)
                {
                    sceneListener.OnGameChange();
                    sceneUpdate = SceneUpdateType.Game_change;
                }
                else if (!pInGame && !inGame)
                {
                    sceneListener.OnMenuChange();
                    sceneUpdate = SceneUpdateType.Menu_change;
                }

                sceneListener.OnSceneUpdate(sceneUpdate);
            }
        }
Example #3
0
        void Start()
        {
            UpdateSceneChange();

            SceneManager.sceneLoaded += OnSceneChange;

            //Initialize mods

            MethodInfo   regRecf        = typeof(RaftMod).GetMethod("RegisterRecipe", BindingFlags.NonPublic | BindingFlags.Instance);
            PropertyInfo recipep        = typeof(Item).GetProperty("recipe");
            PropertyInfo convertRecipep = typeof(Item).GetProperty("convertRecipe");
            MethodInfo   initf          = typeof(Item).GetMethod("Init", BindingFlags.NonPublic | BindingFlags.Instance);
            MethodInfo   applyf         = typeof(Item).GetMethod("Apply", BindingFlags.NonPublic | BindingFlags.Instance);

            foreach (RaftMod mod in RaftMod.Get())
            {
                if (mod.Metadata.ModName != "Raft")
                {
                    //Register all recipes into items
                    //Which is how it works... for now
                    foreach (Recipe recipe in mod.GetRecipes())
                    {
                        Item i = recipe.result;

                        if (recipep.GetValue(i, null) != null)
                        {
                            Console.WriteLine("Couldn't register recipe; \"" + recipe.ToString() + "\", it was already occupied. This is a Raft Game Architecture problem.");
                        }
                        else
                        {
                            recipep.SetValue(i, recipe, null);
                        }
                    }

                    //Register all convert recipes into items
                    //Which is how it works... for now
                    foreach (ConvertRecipe recipe in mod.GetConversions())
                    {
                        Item i = recipe.input;

                        if (convertRecipep.GetValue(i, null) != null)
                        {
                            Console.WriteLine("Couldn't register convert recipe; \"" + recipe.ToString() + "\", it was already occupied. This is a Raft Game Architecture problem.");
                        }
                        else
                        {
                            convertRecipep.SetValue(i, recipe, null);
                        }
                    }

                    //Init all items
                    foreach (Item i in mod.GetItems())
                    {
                        initf.Invoke(i, null);
                    }

                    //Register recipes
                    foreach (ConvertRecipe recipe in mod.GetConversions())
                    {
                        regRecf.Invoke(mod, new object[] { recipe });
                    }

                    //Apply item modifications
                    foreach (ItemModification im in mod.GetItemModifications())
                    {
                        Console.WriteLine(im.owner.Metadata.ModName + ": " + im.item.fullName + "." + im.field.ToString() + " -> " + im.newValue);
                        applyf.Invoke(im.item, new object[] { im });
                    }
                }
            }
        }