aboutsummaryrefslogtreecommitdiff
path: root/Packages/com.vrchat.core.bootstrap/Editor
diff options
context:
space:
mode:
authorAlex <zuedev@gmail.com>2026-06-11 23:15:14 +0100
committerGitHub <noreply@github.com>2026-06-11 23:15:14 +0100
commit9ab4aa10b2e425df818957ffb2bc5cd6d2df4c51 (patch)
treeaa828d6eb0b8d88fe39afe12d77ca36ef81b6f56 /Packages/com.vrchat.core.bootstrap/Editor
downloadVRCog-9ab4aa10b2e425df818957ffb2bc5cd6d2df4c51.tar
VRCog-9ab4aa10b2e425df818957ffb2bc5cd6d2df4c51.tar.gz
VRCog-9ab4aa10b2e425df818957ffb2bc5cd6d2df4c51.tar.bz2
VRCog-9ab4aa10b2e425df818957ffb2bc5cd6d2df4c51.tar.xz
VRCog-9ab4aa10b2e425df818957ffb2bc5cd6d2df4c51.zip
Initial commit
Diffstat (limited to 'Packages/com.vrchat.core.bootstrap/Editor')
-rw-r--r--Packages/com.vrchat.core.bootstrap/Editor/Bootstrap.cs92
-rw-r--r--Packages/com.vrchat.core.bootstrap/Editor/Bootstrap.cs.meta11
-rw-r--r--Packages/com.vrchat.core.bootstrap/Editor/VRChat.Bootstrapper.Editor.asmdef15
-rw-r--r--Packages/com.vrchat.core.bootstrap/Editor/VRChat.Bootstrapper.Editor.asmdef.meta7
4 files changed, 125 insertions, 0 deletions
diff --git a/Packages/com.vrchat.core.bootstrap/Editor/Bootstrap.cs b/Packages/com.vrchat.core.bootstrap/Editor/Bootstrap.cs
new file mode 100644
index 0000000..e1a0917
--- /dev/null
+++ b/Packages/com.vrchat.core.bootstrap/Editor/Bootstrap.cs
@@ -0,0 +1,92 @@
+using System;
+using System.IO;
+using System.Net;
+using System.Text.RegularExpressions;
+using System.Threading.Tasks;
+using UnityEditor;
+using UnityEngine;
+
+namespace VRC.PackageManagement.Core
+{
+ public class Bootstrap
+ {
+ // JSON property names in Project Manifest
+ public const string UNITY_PACKAGES_FOLDER = "Packages";
+ public const string UNITY_MANIFEST_FILENAME = "manifest.json";
+
+ // VRC Values
+ public const string VRC_CONFIG = "https://api.vrchat.cloud/api/1/config";
+ public const string VRC_AGENT = "VCCBootstrap 1.0";
+ public const string VRC_RESOLVER_PACKAGE = "com.vrchat.core.vpm-resolver";
+
+ // Finds url for bootstrap package without using JSON
+ private static Regex _bootstrapRegex = new Regex("\"bootstrap\"\\s*:\\s*\"(.+?(?=\"))\"");
+ public static string ManifestPath => Path.Combine(Directory.GetCurrentDirectory(), UNITY_PACKAGES_FOLDER, UNITY_MANIFEST_FILENAME);
+
+ // Path where we expect the target package to exist
+ public static string ResolverPath =>
+ Path.Combine(Directory.GetCurrentDirectory(), UNITY_PACKAGES_FOLDER, VRC_RESOLVER_PACKAGE);
+
+ [InitializeOnLoadMethod]
+ public static async void CheckForRestore()
+ {
+ if (!new DirectoryInfo(ResolverPath).Exists)
+ {
+ try
+ {
+ await AddResolver();
+ }
+ catch (Exception e)
+ {
+ Debug.LogError($"Could not download and install the VPM Package Resolver - you may be missing packages. Exception: {e.Message}");
+ }
+ }
+ }
+
+ public static async Task AddResolver()
+ {
+ var configData = await GetRemoteString(VRC_CONFIG);
+ if (string.IsNullOrWhiteSpace(configData))
+ {
+ Debug.LogWarning($"Could not get VPM libraries, try again later");
+ return;
+ }
+ var bootstrapMatch = _bootstrapRegex.Match(configData);
+ if (!bootstrapMatch.Success || bootstrapMatch.Groups.Count < 2)
+ {
+ Debug.LogError($"Could not find bootstrap in config, try again later");
+ return;
+ }
+
+ var url = bootstrapMatch.Groups[1].Value;
+
+ var targetFile = Path.Combine(Path.GetTempPath(), $"resolver-{DateTime.Now.ToString("yyyyMMddTHHmmss")}.unitypackage");
+
+ // Download to dir
+ using (var client = new WebClient())
+ {
+ // Add User Agent or else CloudFlare will return 1020
+ client.Headers.Add(HttpRequestHeader.UserAgent, VRC_AGENT);
+
+ await client.DownloadFileTaskAsync(url, targetFile);
+
+ if (File.Exists(targetFile))
+ {
+ Debug.Log($"Downloaded Resolver to {targetFile}");
+ AssetDatabase.ImportPackage(targetFile, false);
+ }
+ }
+ return;
+ }
+
+ public static async Task<string> GetRemoteString(string url)
+ {
+ using (var client = new WebClient())
+ {
+ // Add User Agent or else CloudFlare will return 1020
+ client.Headers.Add(HttpRequestHeader.UserAgent, VRC_AGENT);
+ return await client.DownloadStringTaskAsync(url);
+ }
+ }
+ }
+}
diff --git a/Packages/com.vrchat.core.bootstrap/Editor/Bootstrap.cs.meta b/Packages/com.vrchat.core.bootstrap/Editor/Bootstrap.cs.meta
new file mode 100644
index 0000000..d7ac1ae
--- /dev/null
+++ b/Packages/com.vrchat.core.bootstrap/Editor/Bootstrap.cs.meta
@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: eea11c44cabdaaa43ac0a21dbbbd9824
+MonoImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Packages/com.vrchat.core.bootstrap/Editor/VRChat.Bootstrapper.Editor.asmdef b/Packages/com.vrchat.core.bootstrap/Editor/VRChat.Bootstrapper.Editor.asmdef
new file mode 100644
index 0000000..115b3e2
--- /dev/null
+++ b/Packages/com.vrchat.core.bootstrap/Editor/VRChat.Bootstrapper.Editor.asmdef
@@ -0,0 +1,15 @@
+{
+ "name": "VRChat.Bootstrapper.Editor",
+ "references": [],
+ "includePlatforms": [
+ "Editor"
+ ],
+ "excludePlatforms": [],
+ "allowUnsafeCode": false,
+ "overrideReferences": false,
+ "precompiledReferences": [],
+ "autoReferenced": true,
+ "defineConstraints": [],
+ "versionDefines": [],
+ "noEngineReferences": false
+} \ No newline at end of file
diff --git a/Packages/com.vrchat.core.bootstrap/Editor/VRChat.Bootstrapper.Editor.asmdef.meta b/Packages/com.vrchat.core.bootstrap/Editor/VRChat.Bootstrapper.Editor.asmdef.meta
new file mode 100644
index 0000000..1d60f49
--- /dev/null
+++ b/Packages/com.vrchat.core.bootstrap/Editor/VRChat.Bootstrapper.Editor.asmdef.meta
@@ -0,0 +1,7 @@
+fileFormatVersion: 2
+guid: e0d8a3ed977bd0948b99f4bce8e56a07
+AssemblyDefinitionImporter:
+ externalObjects: {}
+ userData:
+ assetBundleName:
+ assetBundleVariant: