Пример #1
0
        private static void LoadMod(Mod mod)
        {
            if (!LoadedMods.Contains(mod))
            {
                if (mod.HasTextures)
                {
                    if (!Directory.Exists(ModsPath + "/" + mod.ID + "/Textures"))
                    {
                        Directory.CreateDirectory(ModsPath + "/" + mod.ID + "/Textures");
                    }
                }

                if (mod.HasAssetBundles)
                {
                    if (!Directory.Exists(ModsPath + "/" + mod.ID + "/AssetBundles"))
                    {
                        Directory.CreateDirectory(ModsPath + "/" + mod.ID + "/AssetBundles");
                    }
                }

                mod.OnInit();
                LoadedMods.Add(mod);
                ModLogs.Log("Loaded mod " + mod.ID);
            }
            else
            {
                ModLogs.Log("Mod " + mod.ID + " already loaded.");
            }
        }
Пример #2
0
        public static Texture2D LoadTexture(Mod mod, string fileName, bool normalMap = false)
        {
            string FilePath = ModLoader.ModsPath + "/" + mod.ID + "/Textures";

            if (!File.Exists(FilePath))
            {
                ModLogs.Log(string.Format("ERROR in LoadTexture(): File not found {0}", FilePath));
                return(null);
            }

            string Extension = Path.GetExtension(FilePath).ToLower();

            if (Extension == ".png")
            {
                Texture2D texture = new Texture2D(1, 1);
                texture.LoadImage(File.ReadAllBytes(FilePath));
                if (normalMap)
                {
                    SetNormalMap(ref texture);
                }
                return(texture);
            }
            else
            {
                ModLogs.Log(string.Format("ERROR in LoadTexture(): Texture extension not supported: {0}", Environment.NewLine));
            }
            return(null);
        }
Пример #3
0
        public static Mesh LoadOBJMesh(string fileName)
        {
            string fn = ModLoader.ModsPath + "/Meshes/" + fileName;

            if (!File.Exists(fn))
            {
                ModLogs.Log(string.Format("<b>LoadOBJ() Error:</b>{1}File not found: {0}", fn, Environment.NewLine));
                return(null);
            }
            string ext = Path.GetExtension(fn).ToLower();

            if (ext == ".obj")
            {
                OBJLoader obj  = new OBJLoader();
                Mesh      mesh = obj.ImportFile(ModLoader.ModsPath + "/Meshes/" + fileName);
                mesh.name = Path.GetFileNameWithoutExtension(fn);
                ModLogs.Log(string.Format("Loading Mesh {0}...", mesh.name));
                return(mesh);
            }
            else
            {
                ModLogs.Log(string.Format("<b>LoadOBJ() Error:</b>{0}Only (*.obj) files are supported", Environment.NewLine));
            }
            return(null);
        }
Пример #4
0
        public void Update()
        {
            if (Input.GetKeyDown(KeyCode.F12))
            {
                ModLoader.LoadedMods.Clear();

                ModLoader.LoadMods();

                ModLogs.Log("Reloaded all the mods!");
            }
        }
Пример #5
0
        static GameObject Postfix(GameObject __result)
        {
            //ModLogs.Log(__result.name);
            string[] meshConfigurations = File.ReadAllLines(ModLoader.PatchesPath + "/Parts Meshes Replacer.conf");
            foreach (string meshConfigLine in meshConfigurations)
            {
                //ModLogs.Log(__result.name);
                string[] meshConfig = meshConfigLine.Split('|');
                //ModLogs.Log("MeshConfig: " + meshConfig[0]);
                if (__result.name.Equals(meshConfig[0], StringComparison.OrdinalIgnoreCase))
                {
                    ModLogs.Log("Loading Mesh Replace " + __result.name);
                    Mesh         mesh        = AssetBundles.LoadOBJMesh(meshConfig[1]);
                    MeshFilter[] meshFilters = __result.GetComponentsInChildren <MeshFilter>(true);
                    foreach (MeshFilter meshFilter in meshFilters)
                    {
                        meshFilter.mesh = mesh;
                    }
                    //MeshFilter meshFilter = __result.GetComponent<MeshFilter>();
                    //ModLogs.Log(meshFilter.name);
                    // meshFilter.mesh = mesh;
                }
            }

            /*MeshFilter[] meshFilters = __result.GetComponentsInChildren<MeshFilter>(true);
             * foreach (MeshFilter meshFilter in meshFilters)
             * {
             *  if (meshFilter.mesh != null && typeof(Mesh).IsInstanceOfType(meshFilter.mesh))
             *  {
             *      //ModLogs.Log(meshFilter.mesh.name); - SHOWS ALL THE MESHES NAMES
             *      foreach (string meshConfigLine in meshConfigurations)
             *      {
             *          string[] meshConfig = meshConfigLine.Split('|');
             *          //ModLogs.Log(meshConfig[0] + "a.");
             *          if (meshFilter.mesh.name.Equals(meshConfig[0], StringComparison.OrdinalIgnoreCase))
             *          {
             *              //ModLogs.Log(meshConfig[0]);
             *              Mesh mesh = AssetBundles.LoadOBJMesh("titanx.obj");
             *              meshFilter.mesh = mesh;
             *              //ModLogs.Log("Replacing Mesh " + meshFilter.mesh);
             *          }
             *      }
             *  }
             * }*/
            return(__result);
        }
Пример #6
0
        public static void Init()
        {
            ModLogs.EnableLogs();

            SceneManager.sceneLoaded += OnSceneLoaded;

            if (ModLoaderLoaded || Instance)
            {
                ModLogs.Log("----- PCBSModloader is already loaded! -----\n");
                return;
            }

            GameObject ModHandler = new GameObject();

            ModHandler.AddComponent <ModLoader>();
            ModHandler.AddComponent <Textures>();
            ModHandler.AddComponent <AssetBundles>();
            Instance         = ModHandler.GetComponent <ModLoader>();
            loadTextures     = ModHandler.GetComponent <Textures>();
            loadAssetBundles = ModHandler.GetComponent <AssetBundles>();
            GameObject.DontDestroyOnLoad(ModHandler);

            ModLogs.Log("----- Initializing PCBSModloader... -----\n");
            ModLoaderLoaded = false;
            LoadedMods      = new List <Mod>();

            ModLogs.Log("Initializing harmony...");
            Harmony = HarmonyInstance.Create("com.github.harmony.pcbs.mod");

            if (!Directory.Exists(ModsPath))
            {
                Directory.CreateDirectory(ModsPath);
            }

            ModLogs.Log("Loading internal mods...");
            LoadMod(new ModUI());
            LoadMod(new ModConsole());
            //LoadMod(new Parts());

            ModLogs.Log("Loading mods...");
            LoadMods();

            ModLoaderLoaded = true;
            ModLogs.Log("Finished loading.");
        }
Пример #7
0
        public static AssetBundle LoadBundle(Mod mod, string BundleName)
        {
            string bundle = ModLoader.ModsPath + "/" + mod.ID + "/AssetBundles/" + BundleName;

            if (File.Exists(bundle))
            {
                try
                {
                    ModLogs.Log(string.Format("Loading Asset Bundle {0}...", BundleName));
                }
                catch (Exception)
                {
                }
                return(AssetBundle.LoadFromFile(bundle));
            }
            else
            {
                ModLogs.Log(string.Format("ERROR in LoadBundle(): File not found: {0}", BundleName));
                return(null);
            }
        }