Last active
February 27, 2025 06:09
-
-
Save lilxyzw/82c2f24a20ab51ecfd0d8449b4f83f71 to your computer and use it in GitHub Desktop.
以前は動作していましたがセキュリティチェックの影響で動作せず。CC0で置いておくので必要に応じて編集して使ってください
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "jp.lilxyzw.unityversionfaker", | |
"rootNamespace": "", | |
"references": [ | |
"VRC.SDKBase.Editor", | |
"VRC.SDK3A.Editor" | |
], | |
"includePlatforms": [ | |
"Editor" | |
], | |
"excludePlatforms": [], | |
"allowUnsafeCode": false, | |
"overrideReferences": true, | |
"precompiledReferences": [ | |
"VRCCore-Editor.dll", | |
"VRCSDKBase.dll", | |
"VRCSDKBase-Editor.dll", | |
"0Harmony.dll" | |
], | |
"autoReferenced": false, | |
"defineConstraints": [], | |
"versionDefines": [], | |
"noEngineReferences": false | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This code is licensed under CC0 1.0 Universal. | |
// https://creativecommons.org/publicdomain/zero/1.0/ | |
#if UNITY_EDITOR && UNITY_2022_3 | |
using HarmonyLib; | |
using System.Collections.Generic; | |
using System.IO; | |
using System.Reflection; | |
using UnityEditor; | |
using UnityEngine; | |
using VRC.Core; | |
using VRC.SDKBase; | |
using VRC.SDK3A.Editor; | |
using VRC.SDKBase.Editor.Api; | |
using System.Reflection.Emit; | |
namespace jp.lilxyzw.unityversionfaker | |
{ | |
[HarmonyPatch] | |
class UnityVersionFaker : VRC.SDKBase.Editor.BuildPipeline.IVRCSDKPreprocessAvatarCallback | |
{ | |
static readonly string VERSION_CURRENT = Application.unityVersion; | |
const string VERSION_SUPPORTED = "2022.3.22f1"; | |
const BindingFlags flag = BindingFlags.NonPublic | BindingFlags.Static; | |
public int callbackOrder => 999999; | |
public bool OnPreprocessAvatar(GameObject obj) | |
{ | |
if(EditorApplication.isPlaying) return true; | |
//if(!EditorUtility.DisplayDialog("UnityVersionFaker", "VRChatが推奨する以外のUnityバージョンを使用してビルドしようとしています。いかなる問題が発生しても自己責任であり、VRChatや開発者に問い合わせず自分で解決する必要があります。ビルドを続行しますか?(このダイアログは毎回表示されます。非表示にするにはプログラム自体を編集してください)", "Yes", "No")) return false; | |
obj.GetComponent<VRC_AvatarDescriptor>().unityVersion = VERSION_SUPPORTED; | |
typeof(VRC.Tools).GetField("_unityVersion", flag).SetValue(null, UnityVersion.Parse(VERSION_SUPPORTED)); | |
(typeof(VRCApi).GetField("Headers", flag).GetValue(null) as Dictionary<string, string>)["X-Unity-Version"] = VERSION_SUPPORTED; | |
if(typeof(VRCSdkControlPanelAvatarBuilder).GetField("_instance", flag).GetValue(null) is VRCSdkControlPanelAvatarBuilder builder) | |
{ | |
builder.OnSdkBuildSuccess -= RewriteBundleHeader; | |
builder.OnSdkBuildSuccess += RewriteBundleHeader; | |
} | |
return true; | |
} | |
void RewriteBundleHeader(object sender, string path) | |
{ | |
int i = 0; | |
var bytes = new byte[64]; | |
// Copy FileInfo | |
var fi = new FileInfo(path); | |
var timeC = fi.CreationTime; | |
var timeW = fi.LastWriteTime; | |
using var fs = new FileStream(path, FileMode.Open); | |
fs.Read(bytes, 0, 64); | |
fs.Seek(0, SeekOrigin.Begin); | |
// Header - "UnityFS 5.x.x " | |
for(; i<18; i++) fs.WriteByte(bytes[i]); | |
// Header - Unity Version | |
i += System.Text.Encoding.ASCII.GetBytes(VERSION_CURRENT).Length; | |
fs.Write(System.Text.Encoding.ASCII.GetBytes(VERSION_SUPPORTED)); | |
// Header - Other | |
var a = 64 + Mathf.Min(i - (int)fs.Position, 0); | |
for(; i<a; i++) fs.WriteByte(bytes[i]); | |
fs.Close(); | |
// Revert FileInfo | |
new FileInfo(path){CreationTime = timeC, LastWriteTime = timeW}; | |
} | |
[InitializeOnLoadMethod] | |
static void DoPatching() | |
{ | |
typeof(VRC.Tools).GetField("_unityVersion", flag).SetValue(null, UnityVersion.Parse(VERSION_SUPPORTED)); | |
(typeof(VRCApi).GetField("Headers", flag).GetValue(null) as Dictionary<string, string>)["X-Unity-Version"] = VERSION_SUPPORTED; | |
new Harmony("jp.lilxyzw.unityversionfaker").PatchAll(); | |
} | |
[HarmonyPatch(typeof(VRCApi), "UploadFile"), HarmonyPrefix] | |
static void PrefixUploadFile(ref string friendlyFileName) => friendlyFileName = friendlyFileName.Replace(VERSION_CURRENT, VERSION_SUPPORTED); | |
[HarmonyPatch(typeof(Application), nameof(Application.unityVersion), MethodType.Getter), HarmonyTranspiler] | |
static IEnumerable<CodeInstruction> PatchUnityVersion(IEnumerable<CodeInstruction> instructions) | |
{ | |
yield return new(OpCodes.Ldstr, VERSION_SUPPORTED); | |
yield return new(OpCodes.Ret); | |
} | |
} | |
} | |
#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment