generated from vrchat-community/template-package-listing
-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Script for auto clean OSC config file based on Hai-vr tool.
- Loading branch information
Showing
6 changed files
with
126 additions
and
1 deletion.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
97 changes: 97 additions & 0 deletions
97
Packages/net.pawlygon.vrc-facetracking/Editor/CleanOSC/CleanOnUploadProcessor.cs
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
using System; | ||
using System.IO; | ||
using UnityEditor; | ||
using UnityEngine; | ||
using VRC.Core; | ||
using VRC.SDK3A.Editor; | ||
using VRC.SDKBase.Editor; | ||
|
||
namespace Pawlygon.CleanOnUpload | ||
{ | ||
public class CleanOnUploadProcessor | ||
{ | ||
[InitializeOnLoadMethod] | ||
public static void RegisterCallback() | ||
{ | ||
VRCSdkControlPanel.OnSdkPanelEnable += OnSdkPanelEnable; | ||
} | ||
|
||
private static void OnSdkPanelEnable(object sender, EventArgs args) | ||
{ | ||
if (VRCSdkControlPanel.TryGetBuilder<IVRCSdkAvatarBuilderApi>(out var builder)) | ||
{ | ||
builder.OnSdkUploadSuccess += OnSdkUploadSuccess; | ||
} | ||
} | ||
|
||
private static void OnSdkUploadSuccess(object sender, string avatarId) | ||
{ | ||
Debug.Log($"Upload success, will try to remove OSC config..."); | ||
TryDeleteOscConfigFile(avatarId); | ||
} | ||
|
||
[MenuItem("Tools/!Pawlygon/Remove OSC Config File")] | ||
private static void RemoveOSCConfig() | ||
{ | ||
if (!APIUser.IsLoggedIn) | ||
{ | ||
Debug.LogError("You need to be Logged in VRChat SDK Panel."); | ||
return; | ||
} | ||
|
||
var activeObject = Selection.activeGameObject; | ||
if (activeObject == null) | ||
{ | ||
Debug.LogError("You need to select an Avatar on the Hierarchy."); | ||
return; | ||
} | ||
|
||
var pipeline = activeObject.transform.GetComponentInParent<PipelineManager>(); | ||
if (pipeline == null) | ||
{ | ||
Debug.LogError("Selected Avatar does not have a Blueprint ID."); | ||
return; | ||
} | ||
|
||
Debug.Log($"Trying to delete OSC config file of {pipeline.blueprintId}"); | ||
TryDeleteOscConfigFile(pipeline.blueprintId); | ||
} | ||
|
||
private static void TryDeleteOscConfigFile(string avatarId) | ||
{ | ||
if (string.IsNullOrEmpty(avatarId)) return; | ||
if (!APIUser.IsLoggedIn) return; | ||
|
||
var userId = APIUser.CurrentUser.id; | ||
if (ContainsPathTraversalElements(userId) || ContainsPathTraversalElements(avatarId)) | ||
{ | ||
// Prevent the remote chance of a path traversal | ||
return; | ||
} | ||
|
||
var endbit = $"/VRChat/VRChat/OSC/{userId}/Avatars/{avatarId}.json"; | ||
var oscConfigFile = $"{VRC_SdkBuilder.GetLocalLowPath()}{endbit}"; | ||
var printLocation = $"%LOCALAPPDATA%Low{endbit}"; // Doesn't print the account name to the logs | ||
if (!File.Exists(oscConfigFile)) return; | ||
|
||
var fileAttributes = File.GetAttributes(oscConfigFile); | ||
if (fileAttributes.HasFlag(FileAttributes.Directory)) return; | ||
|
||
try | ||
{ | ||
File.Delete(oscConfigFile); | ||
Debug.Log($"Removed the OSC config file located at {printLocation}"); | ||
} | ||
catch (Exception e) | ||
{ | ||
Debug.LogError($"Failed to remove the OSC config file at {printLocation}"); | ||
throw; | ||
} | ||
} | ||
|
||
private static bool ContainsPathTraversalElements(string susStr) | ||
{ | ||
return susStr.Contains("/") || susStr.Contains("\\") || susStr.Contains(".") || susStr.Contains("*"); | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
Packages/net.pawlygon.vrc-facetracking/Editor/CleanOSC/CleanOnUploadProcessor.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 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