Skip to content

Commit

Permalink
Add Script for auto clean OSC config file based on Hai-vr tool.
Browse files Browse the repository at this point in the history
  • Loading branch information
hchoki committed May 6, 2024
1 parent 7bf39d1 commit 675b92f
Show file tree
Hide file tree
Showing 6 changed files with 126 additions and 1 deletion.
8 changes: 8 additions & 0 deletions Packages/net.pawlygon.vrc-facetracking/Editor.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Packages/net.pawlygon.vrc-facetracking/Editor/CleanOSC.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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("*");
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Packages/net.pawlygon.vrc-facetracking/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "net.pawlygon.vrc-facetracking",
"version": "1.2.1",
"version": "1.2.2",
"displayName": "Pawlygon - VRC Facetracking",
"description": "Template to be used on models with Unified Expressions Face Tracking",
"unity": "2022.3",
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ Join our discord on [Pawlygon](https://discord.com/invite/pZew3JGpjb)
* [VRCFaceTracking](https://github.com/benaclejames/VRCFaceTracking)
* [regzo2 - OSCmooth](https://github.com/regzo2/OSCmooth)
* [Adjerry91 - FaceTracking Template](https://github.com/Adjerry91/VRCFaceTracking-Templates)
* [Hai-vr - fuck-osc-config](https://github.com/hai-vr/fuck-osc-config)

0 comments on commit 675b92f

Please sign in to comment.