Exemple #1
0
        public static void LoadShaderPropertyDrawers(Shader shader)
        {
            string path = AssetDatabase.GetAssetPath(shader);
            string code = FileHelper.ReadFileIntoString(path);

            code = Helper.GetStringBetweenBracketsAndAfterId(code, "Properties", new char[] { '{', '}' });
            MatchCollection matchCollection = Regex.Matches(code, @"\[.*\].*(?=\()");
            Dictionary <string, string[]> property_drawers = new Dictionary <string, string[]>();

            foreach (Match match in matchCollection)
            {
                string[] drawers_or_flag_code = GetDrawersFlagsCode(match.Value);
                string   drawer_code          = GetNonFlagDrawer(drawers_or_flag_code);
                if (drawer_code == null)
                {
                    continue;
                }

                string property_name = Regex.Match(match.Value, @"(?<=\])[^\[]*$").Value.Trim();

                List <string> drawer_and_parameters = new List <string>();
                drawer_and_parameters.Add(Regex.Split(drawer_code, @"\(")[0]);

                GetDrawerParameters(drawer_code, drawer_and_parameters);

                property_drawers[property_name] = drawer_and_parameters.ToArray();
            }
            shader_property_drawers[shader] = property_drawers;
        }
        //TODO save location data on install
        //     delete location data on remove
        //     destingish between public and private modules

        private static void InitInstalledModule(Module m)
        {
            bool remove = false;

            if (Helper.ClassWithNamespaceExists(m.location_data.classname))
            {
                m.path = GetModuleDirectory(m);
                if (string.IsNullOrEmpty(m.path) == false)
                {
                    m.installed_module = Parser.ParseToObject <ModuleInfo>(FileHelper.ReadFileIntoString(FindModuleFilePath(m.path)));
                    string calced_guid = AssetDatabase.AssetPathToGUID(m.path);
                    if (m.location_data.guid != calced_guid)
                    {
                        SaveModuleLocationData(m, calced_guid);
                    }
                }
                else
                {
                    remove = true;
                }
            }
            if (remove)
            {
                FileHelper.RemoveValueFromFile(m.id, PATH.MODULES_LOCATION__DATA);
                m.location_data = null;
            }
        }
Exemple #3
0
        private string GetInstalledSDKVersionAndInitPath()
        {
            string[] guids  = AssetDatabase.FindAssets("version");
            string   path   = null;
            string   u_path = null;

            foreach (string guid in guids)
            {
                string p = AssetDatabase.GUIDToAssetPath(guid);
                if (p.Contains("VRCSDK/version"))
                {
                    path = p;
                }
                if (p.Contains("Udon/version"))
                {
                    u_path = p;
                }
            }
            if (path == null || !File.Exists(path))
            {
                return("");
            }
            sdk_path = Regex.Match(path, @".*\/").Value;
            if (u_path != null)
            {
                udon_path = Regex.Match(u_path, @".*\/").Value;
            }
            return(FileHelper.ReadFileIntoString(path));
        }
Exemple #4
0
        private static void AddDrawingDLLDefineToRSP(string rsp_path)
        {
            string rsp_data = FileHelper.ReadFileIntoString(rsp_path);

            rsp_data += RSP_DRAWING_DLL_DEFINE_CODE;
            FileHelper.WriteStringToFile(rsp_data, rsp_path);
        }
 private static void Load()
 {
     if (linked_materials == null)
     {
         linked_materials = new Dictionary <string, List <Material> >();
         string     raw    = FileHelper.ReadFileIntoString(PATH.LINKED_MATERIALS_FILE);
         string[][] parsed = Parser.ParseToObject <string[][]>(raw);
         if (parsed != null)
         {
             foreach (string[] material_cloud in parsed)
             {
                 List <Material> materials = new List <Material>();
                 for (int i = 1; i < material_cloud.Length; i++)
                 {
                     string   path = AssetDatabase.GUIDToAssetPath(material_cloud[i]);
                     Material m    = AssetDatabase.LoadAssetAtPath <Material>(path);
                     if (m != null)
                     {
                         materials.Add(m);
                     }
                 }
                 foreach (Material m in materials)
                 {
                     linked_materials.Add(GetKey(m, material_cloud[0]), materials);
                 }
             }
         }
     }
 }
Exemple #6
0
        static DRP_Main()
        {
            last_updated_file_name = FileHelper.ReadFileIntoString(DRP_LAST_UPDATED_FILE_PATH);
            clientID = Environment.GetEnvironmentVariable("DISCORD_CLIENT_ID");
            if (clientID == null)
            {
                clientID = "619838876994764800";
            }

            if (InitDiscord())
            {
                EditorApplication.update += Update;
            }
            else
            {
                EditorApplication.update += TryInitDiscord;
            }

            ModuleHandler.RegisterPreModuleRemoveFunction(delegate()
            {
                if (isRunning)
                {
                    EditorApplication.update -= Update;
                }
                else
                {
                    EditorApplication.update -= TryInitDiscord;
                }
                discord.Dispose();
            });
        }
Exemple #7
0
        private static string readShaderName(string path)
        {
            string shaderCode   = FileHelper.ReadFileIntoString(path);
            string pattern      = @"Shader *""(\w|\/|\.)+";
            string ogShaderName = Regex.Match(shaderCode, pattern).Value;

            ogShaderName = Regex.Replace(ogShaderName, @"Shader *""", "");
            return(ogShaderName);
        }
Exemple #8
0
 //load the config from file
 private static Config LoadConfig()
 {
     if (File.Exists(PATH_CONFIG_FILE))
     {
         return(JsonUtility.FromJson <Config>(FileHelper.ReadFileIntoString(PATH_CONFIG_FILE)));
     }
     new Config().save();
     return(new Config());
 }
Exemple #9
0
        private void removeProperty(string path, string property, string value)
        {
            string       shaderCode = FileHelper.ReadFileIntoString(path);
            string       pattern    = @"\r?\n.*" + Regex.Escape(property) + " ?= ?" + value;
            RegexOptions options    = RegexOptions.Multiline;

            shaderCode = Regex.Replace(shaderCode, pattern, "", options);

            FileHelper.WriteStringToFile(shaderCode, path);
        }
Exemple #10
0
        private static void addProperty(string path, string property, string value)
        {
            string       shaderCode = FileHelper.ReadFileIntoString(path);
            string       pattern    = @"Properties.*\n?\s*{";
            RegexOptions options    = RegexOptions.Multiline;

            shaderCode = Regex.Replace(shaderCode, pattern, "Properties \r\n  {" + " \r\n      " + property + "=" + value, options);

            FileHelper.WriteStringToFile(shaderCode, path);
        }
Exemple #11
0
        private static bool DoesRSPContainDrawingDLLDefine(string rsp_path)
        {
            if (!File.Exists(rsp_path))
            {
                return(false);
            }
            string rsp_data = FileHelper.ReadFileIntoString(rsp_path);

            return(Regex.Match(rsp_data, RSP_DRAWING_DLL_DEFINE_REGEX).Success);
        }
Exemple #12
0
 private static void CheckForUnregisteredInstall(Module module)
 {
     if (Helper.ClassExists(module.available_module.classname))
     {
         module.path = ResolveFilesToDirectory(module.available_module.files.ToArray());
         if (module.path != null)
         {
             module.installed_module = Parser.ParseToObject <ModuleInfo>(FileHelper.ReadFileIntoString(FindModuleFilePath(module.path)));
             SaveModuleLocationData(module, AssetDatabase.AssetPathToGUID(module.path));
         }
     }
 }
 private static void InitInstalledModule(ModuleHeader m)
 {
     if (Helper.ClassExists(m.available_module.classname))
     {
         string module_path = GetModuleDirectoryPath(m);
         string path        = module_path + "/module.json";
         if (File.Exists(path))
         {
             m.installed_module = Parser.ParseToObject <ModuleInfo>(FileHelper.ReadFileIntoString(path));
             m.path             = module_path;
         }
     }
 }
 private static void CheckForUnregisteredInstall(Module module)
 {
     //Debug.Log(module.available_module.classname + ":" + Helper.ClassWithNamespaceExists(module.available_module.classname));
     if (Helper.ClassWithNamespaceExists(module.available_module.classname))
     {
         module.path = ResolveFilesToDirectory(module.available_module.files.ToArray());
         if (string.IsNullOrEmpty(module.path) == false)
         {
             module.installed_module = Parser.ParseToObject <ModuleInfo>(FileHelper.ReadFileIntoString(FindModuleFilePath(module.path)));
             SaveModuleLocationData(module, AssetDatabase.AssetPathToGUID(module.path));
         }
     }
 }
Exemple #15
0
        public void LoadCSV(string file_name)
        {
            List <string> files = UnityHelper.FindAssetsWithFilename(file_name + ".csv");

            if (files.Count > 0)
            {
                ParseCSV(FileHelper.ReadFileIntoString(files[0]));
            }
            else
            {
                throw new System.Exception("CVS File with name \"" + file_name + "\" could not be found.");
            }
        }
Exemple #16
0
        private void revertEditor(string path)
        {
            string shaderCode = FileHelper.ReadFileIntoString(path);
            string pattern    = @"//originalEditor.*\n";
            Match  m          = Regex.Match(shaderCode, pattern);

            if (m.Success)
            {
                string orignialEditor = m.Value.Replace("//originalEditor", "");
                pattern    = @"//originalEditor.*\n.*\n";
                shaderCode = Regex.Replace(shaderCode, pattern, orignialEditor);
                FileHelper.WriteStringToFile(shaderCode, path);
            }
        }
        private static void LoadThryEditorShaders()
        {
            string data = FileHelper.ReadFileIntoString(PATH.THRY_EDITOR_SHADERS);

            if (data != "")
            {
                shaders = Parser.ParseToObject <List <ThryEditorShader> >(data);
            }
            else
            {
                SearchAllShadersForThryEditorUsage();
            }
            DeleteNull();
        }
        //copys og shader and changed render queue and name in there
        public static Shader createRenderQueueShaderIfNotExists(Shader defaultShader, int renderQueue, bool import)
        {
            string newShaderName     = ".differentQueues/" + defaultShader.name + "-queue" + renderQueue;
            Shader renderQueueShader = Shader.Find(newShaderName);

            if (renderQueueShader != null)
            {
                return(renderQueueShader);
            }

            string defaultPath      = AssetDatabase.GetAssetPath(defaultShader);
            string shaderCode       = FileHelper.ReadFileIntoString(defaultPath);
            string pattern          = @"""Queue"" ?= ?""\w+(\+\d+)?""";
            string replacementQueue = "Background+" + (renderQueue - 1000);

            if (renderQueue == 1000)
            {
                replacementQueue = "Background";
            }
            else if (renderQueue < 1000)
            {
                replacementQueue = "Background-" + (1000 - renderQueue);
            }
            shaderCode = Regex.Replace(shaderCode, pattern, "\"Queue\" = \"" + replacementQueue + "\"");
            pattern    = @"Shader *""(\w|\/|\.)+";
            string ogShaderName = Regex.Match(shaderCode, pattern).Value;

            ogShaderName = Regex.Replace(ogShaderName, @"Shader *""", "");
            string newerShaderName = ".differentQueues/" + ogShaderName + "-queue" + renderQueue;

            shaderCode = Regex.Replace(shaderCode, pattern, "Shader \"" + newerShaderName);
            pattern    = @"#include\s*""(?!(Lighting.cginc)|(AutoLight)|(UnityCG)|(UnityShaderVariables)|(HLSLSupport)|(TerrainEngine))";
            shaderCode = Regex.Replace(shaderCode, pattern, "#include \"../", RegexOptions.Multiline);
            string[] pathParts = defaultPath.Split('/');
            string   fileName  = pathParts[pathParts.Length - 1];
            string   newPath   = defaultPath.Replace(fileName, "") + "_differentQueues";

            Directory.CreateDirectory(newPath);
            newPath = newPath + "/" + fileName.Replace(".shader", "-queue" + renderQueue + ".shader");
            FileHelper.WriteStringToFile(shaderCode, newPath);
            ShaderImportFixer.scriptImportedAssetPaths.Add(newPath);
            if (import)
            {
                AssetDatabase.ImportAsset(newPath);
            }

            return(Shader.Find(newerShaderName));
        }
Exemple #19
0
        public static Animation Parse(string path)
        {
            string data = FileHelper.ReadFileIntoString(path);

            List <PPtrCurve> pPtrCurves = new List <PPtrCurve>();
            int pptrIndex;
            int lastIndex = 0;

            while ((pptrIndex = data.IndexOf("m_PPtrCurves", lastIndex)) != -1)
            {
                lastIndex = pptrIndex + 1;
                int pptrEndIndex = data.IndexOf("  m_", pptrIndex);

                int curveIndex;
                int lastCurveIndex = pptrIndex;
                //find all curves
                while ((curveIndex = data.IndexOf("  - curve:", lastCurveIndex, pptrEndIndex - lastCurveIndex)) != -1)
                {
                    lastCurveIndex = curveIndex + 1;
                    int curveEndIndex = data.IndexOf("    script: ", curveIndex);

                    PPtrCurve           curve     = new PPtrCurve();
                    List <PPtrKeyframe> keyframes = new List <PPtrKeyframe>();

                    int keyFrameIndex;
                    int lastKeyFrameIndex = curveIndex;
                    while ((keyFrameIndex = data.IndexOf("    - time:", lastKeyFrameIndex, curveEndIndex - lastKeyFrameIndex)) != -1)
                    {
                        lastKeyFrameIndex = keyFrameIndex + 1;
                        int keyFrameEndIndex = data.IndexOf("}", keyFrameIndex);

                        PPtrKeyframe keyframe = new PPtrKeyframe();
                        keyframe.time = float.Parse(data.Substring(keyFrameIndex, data.IndexOf("\n", keyFrameIndex, keyFrameEndIndex)));
                        keyframes.Add(keyframe);
                    }

                    curve.curveType = data.IndexOf("    attribute: m_Materials", lastKeyFrameIndex, curveEndIndex - lastKeyFrameIndex) != -1 ? PPtrType.Material : PPtrType.None;
                    curve.keyframes = keyframes.ToArray();
                    pPtrCurves.Add(curve);
                }
            }
            Animation animation = new Animation();

            animation.pPtrCurves = pPtrCurves.ToArray();
            Debug.Log(Parser.Serialize(animation));
            return(animation);
        }
Exemple #20
0
        private void replaceEditorInShader(string path, string newEditor)
        {
            string shaderCode = FileHelper.ReadFileIntoString(path);
            string pattern    = @"CustomEditor ?.*\n";
            Match  m          = Regex.Match(shaderCode, pattern);

            if (m.Success)
            {
                string oldEditor = "//originalEditor" + m.Value;
                shaderCode = Regex.Replace(shaderCode, pattern, oldEditor + "CustomEditor \"" + newEditor + "\"\r\n");
            }
            else
            {
                pattern = @"SubShader.*\r?\n?\s*{";
                RegexOptions options = RegexOptions.Multiline;
                shaderCode = Regex.Replace(shaderCode, pattern, "CustomEditor \"" + newEditor + "\" \r\n    SubShader \r\n  {", options);
            }

            FileHelper.WriteStringToFile(shaderCode, path);
        }
Exemple #21
0
        public static void backupSingleMaterial(Material m)
        {
            if (restoring_in_progress)
            {
                return;
            }
            string[] mats = new string[0];
            if (!File.Exists(PATH.MATERIALS_BACKUP_FILE))
            {
                File.CreateText(PATH.MATERIALS_BACKUP_FILE).Close();
            }
            else
            {
                mats = FileHelper.ReadFileIntoString(PATH.MATERIALS_BACKUP_FILE).Split(new string[] { "\n" }, System.StringSplitOptions.None);
            }
            bool   updated   = false;
            string matGuid   = AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(m.GetInstanceID()));
            string newString = "";

            for (int mat = 0; mat < mats.Length; mat++)
            {
                if (mats[mat].Contains(matGuid))
                {
                    updated    = true;
                    newString += matGuid + ":" + ShaderHelper.getDefaultShaderName(m.shader.name) + ":" + m.renderQueue + "\r\n";
                }
                else
                {
                    newString += mats[mat] + "\n";
                }
            }
            if (!updated)
            {
                newString += matGuid + ":" + ShaderHelper.getDefaultShaderName(m.shader.name) + ":" + m.renderQueue;
            }
            else
            {
                newString = newString.Substring(0, newString.LastIndexOf("\n"));
            }
            FileHelper.WriteStringToFile(newString, PATH.MATERIALS_BACKUP_FILE);
        }
        private void InitInstalledSDKVersionAndPaths()
        {
            string[] guids  = AssetDatabase.FindAssets("version");
            string   path   = null;
            string   u_path = null;

            foreach (string guid in guids)
            {
                string p = AssetDatabase.GUIDToAssetPath(guid);
                if (p.Contains("VRCSDK/version"))
                {
                    path = p;
                }
                if (p.Contains("Udon/version"))
                {
                    u_path = p;
                }
            }
            if (path == null || !File.Exists(path))
            {
                return;
            }

            sdk_information.local_sdk_path = Regex.Match(path, @".*\/").Value;
            if (u_path != null)
            {
                sdk_information.udon_path = Regex.Match(u_path, @".*\/").Value;
            }
            string persistent = PersistentData.Get("vrc_sdk_version");

            if (persistent != null)
            {
                sdk_information.installed_version = persistent;
            }
            else
            {
                sdk_information.installed_version = Regex.Replace(FileHelper.ReadFileIntoString(path), @"\n?\r", "");
            }
        }
        private static bool TestShaderForThryEditor(string path)
        {
            string code = FileHelper.ReadFileIntoString(path);

            if (ShaderUsesThryEditor(code))
            {
                ThryEditorShader shader = new ThryEditorShader();
                shader.path = path;
                Match name_match = Regex.Match(code, @"(?<=[Ss]hader)\s*\""[^\""]+(?=\""\s*{)");
                if (name_match.Success)
                {
                    shader.name = name_match.Value.TrimStart(new char[] { ' ', '"' });
                }
                Match master_label_match = Regex.Match(code, @"\[HideInInspector\]\s*shader_master_label\s*\(\s*\""[^\""]*(?=\"")");
                if (master_label_match.Success)
                {
                    shader.version = GetVersionFromMasterLabel(master_label_match.Value);
                }
                thry_editor_shaders.Add(shader);
                return(true);
            }
            return(false);
        }