Skip to content
This repository has been archived by the owner on Nov 7, 2022. It is now read-only.

Commit

Permalink
Updated to support latest VRChat, Small Futureproof
Browse files Browse the repository at this point in the history
  • Loading branch information
Kiokuu committed May 18, 2021
1 parent 2d3c63c commit 0a11345
Show file tree
Hide file tree
Showing 8 changed files with 164 additions and 67 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ bld/
[Ll]og/
[Ll]ogs/

# Build Helpers
Libs/

# Visual Studio 2015/2017 cache/options directory
.vs/
# Uncomment if you have tasks that create the project's static files in wwwroot
Expand Down
14 changes: 7 additions & 7 deletions SafetyPresets.sln
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.30225.117
VisualStudioVersion = 16.0.31229.75
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SafetyPresets", "SafetyPresets\SafetyPresets.csproj", "{D79864E5-CA35-47D2-95DB-F2AB7359B12F}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SafetyPresets", "SafetyPresets/SafetyPresets.csproj", "{CB6EBC58-FDB1-40EF-8784-0A1497FB9437}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{D79864E5-CA35-47D2-95DB-F2AB7359B12F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D79864E5-CA35-47D2-95DB-F2AB7359B12F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D79864E5-CA35-47D2-95DB-F2AB7359B12F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D79864E5-CA35-47D2-95DB-F2AB7359B12F}.Release|Any CPU.Build.0 = Release|Any CPU
{CB6EBC58-FDB1-40EF-8784-0A1497FB9437}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{CB6EBC58-FDB1-40EF-8784-0A1497FB9437}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CB6EBC58-FDB1-40EF-8784-0A1497FB9437}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CB6EBC58-FDB1-40EF-8784-0A1497FB9437}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {335A34DB-595F-4195-9684-378005CFAC12}
SolutionGuid = {2A31B023-5C50-47F8-AD78-9AE40890973E}
EndGlobalSection
EndGlobal
6 changes: 3 additions & 3 deletions SafetyPresets/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using MelonLoader;

// MelonLoader
[assembly: MelonInfo(typeof(SafetyPresets.Main), "Safety-Presets", "0.0.4", "死神#6938", "https://github.com/Kiokuu/SafetyPresets")]
[assembly: MelonInfo(typeof(SafetyPresets.Main), "Safety-Presets", "0.0.5", "Yato#4499", "https://github.com/Kiokuu/SafetyPresets")]
[assembly: MelonGame("VRChat", "VRChat")]

// General Information about an assembly is controlled through the following
Expand Down Expand Up @@ -37,5 +37,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.4")]
[assembly: AssemblyFileVersion("1.0.0.4")]
[assembly: AssemblyVersion("1.0.0.5")]
[assembly: AssemblyFileVersion("1.0.0.5")]
28 changes: 23 additions & 5 deletions SafetyPresets/SafetyHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Reflection;

using Newtonsoft.Json;

using UnityEngine;
using MelonLoader;
using VRC;
Expand All @@ -23,7 +26,21 @@ public static class Helpers
public static List<Classes.SettingsPreset> ValidPresetList()
{
return Settings.availablePresets.ActualPresets.Where(p => IsPresetValid(p.settingsPresetNum)).ToList();
}
}

private static MethodBase applySafety;

public static void DoXrefMagic()
{
MelonLogger.Msg("Beginning Xref scanning");
applySafety = typeof(FeaturePermissionManager).GetMethods().Where(
methodBase => methodBase.Name.StartsWith("Method_Public_Void_")
&& !methodBase.Name.Contains("PDM")
&& SafetyXref.CheckMethod(methodBase, "Safety Settings Changed to: "))
.First();

MelonLogger.Msg($"OnTrustSettingsChanged determined to be: {applySafety.Name}");
}

public static IList<(string presetNumber,string friendlyName)> ValidPresetIList(){
List<(string,string)> tempReturnList = new List<(string, string)>();
Expand Down Expand Up @@ -57,12 +74,12 @@ public static IEnumerator ChangeOnInstance()
LoadSafetySettings(Prefs.DoChangeInPublicsPreset());
MelonLoader.MelonLogger.Msg("Public instance -> changing safety preset.");
}
if((instanceType==ApiWorldInstance.AccessType.FriendsOnly || instanceType==ApiWorldInstance.AccessType.FriendsOfGuests) && Prefs.DoChangeInFriends)
if(instanceType==ApiWorldInstance.AccessType.FriendsOfGuests && Prefs.DoChangeInFriends)
{
LoadSafetySettings(Prefs.DoChangeInFriendsPreset());
MelonLoader.MelonLogger.Msg("Friends instance -> changing safety preset.");
}
if((instanceType==ApiWorldInstance.AccessType.InviteOnly || instanceType==ApiWorldInstance.AccessType.InvitePlus) && Prefs.DoChangeInPrivates)
if((instanceType == ApiWorldInstance.AccessType.FriendsOnly || instanceType == ApiWorldInstance.AccessType.InviteOnly || instanceType == ApiWorldInstance.AccessType.InvitePlus) && Prefs.DoChangeInPrivates)
{
LoadSafetySettings(Prefs.DoChangeInPrivatesPreset());
MelonLoader.MelonLogger.Msg("Private instance -> changing safety preset.");
Expand All @@ -73,8 +90,9 @@ public static void SaveSafetySettings(int presetNum,string name)
{
try
{

FeaturePermissionManager fManager = GameObject.Find("_Application").GetComponent<FeaturePermissionManager>();
fManager.Method_Public_Void_2(); // Apply current safety settings
applySafety.Invoke(FeaturePermissionManager.prop_FeaturePermissionManager_0, new object[] { } );
List<Classes.RankSetting> rankSettingList = new List<Classes.RankSetting>{};
foreach(Il2CppSystem.Collections.Generic.KeyValuePair<UserSocialClass,FeaturePermissionSet> rankPerm in fManager.field_Private_Dictionary_2_UserSocialClass_FeaturePermissionSet_0)
{
Expand Down Expand Up @@ -152,7 +170,7 @@ public static void LoadSafetySettings(int presetNum)
}
}
MelonLoader.MelonLogger.Msg($"Loaded safety preset -> \"{toLoadPreset.settingsPresetName}\" ({toLoadPreset.settingsPresetNum})");
fManager.Method_Public_Void_2(); // Apply Safety Settings / Reload avatars
applySafety.Invoke(FeaturePermissionManager.prop_FeaturePermissionManager_0, new object[] { });
}
catch (Exception e)
{
Expand Down
1 change: 1 addition & 0 deletions SafetyPresets/SafetyMain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public override void OnApplicationStart()
{
Settings.SetupDefaults();
Prefs.SetupPrefs();
Helpers.DoXrefMagic();
CompatChecks.CheckEnvironment();
UI.SetupUIX();
}
Expand Down
125 changes: 74 additions & 51 deletions SafetyPresets/SafetyPresets.csproj
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>d79864e5-ca35-47d2-95db-f2ab7359b12f</ProjectGuid>
<ProjectGuid>{CB6EBC58-FDB1-40EF-8784-0A1497FB9437}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>SafetyPresets</RootNamespace>
<NoStandardLibraries>false</NoStandardLibraries>
<AssemblyName>SafetyPresets</AssemblyName>
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand All @@ -21,6 +18,7 @@
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
Expand All @@ -29,72 +27,97 @@
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup>
<RootNamespace>SafetyPresets</RootNamespace>
</PropertyGroup>

<ItemGroup>
<Reference Include="Assembly-CSharp">
<HintPath>..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\VRChat\MelonLoader\Managed\Assembly-CSharp.dll</HintPath>
<Reference Include="Assembly-CSharp, Version=3.7.1.6, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\Libs\Assembly-CSharp.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="Assembly-CSharp-firstpass, Version=3.7.1.6, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\Libs\Assembly-CSharp-firstpass.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="Assembly-CSharp-firstpass">
<HintPath>..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\VRChat\MelonLoader\Managed\Assembly-CSharp-firstpass.dll</HintPath>
<Reference Include="Il2Cppmscorlib, Version=3.7.1.6, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\Libs\Il2Cppmscorlib.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="Il2Cppmscorlib">
<HintPath>..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\VRChat\MelonLoader\Managed\Il2Cppmscorlib.dll</HintPath>
<Reference Include="Il2CppSystem, Version=3.7.1.6, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\Libs\Il2CppSystem.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="MelonLoader">
<HintPath>..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\VRChat\MelonLoader\MelonLoader.dll</HintPath>
<Reference Include="MelonLoader, Version=0.3.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\Libs\MelonLoader.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.12.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
<Reference Include="Microsoft.CSharp" />
<Reference Include="Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="System.Xml" />
<Reference Include="UIExpansionKit">
<HintPath>..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\VRChat\Mods\UIExpansionKit.dll</HintPath>
</Reference>
<Reference Include="UnhollowerBaseLib">
<HintPath>..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\VRChat\MelonLoader\Managed\UnhollowerBaseLib.dll</HintPath>
</Reference>
<Reference Include="UnhollowerRuntimeLib">
<HintPath>..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\VRChat\MelonLoader\Managed\UnhollowerRuntimeLib.dll</HintPath>
</Reference>
<Reference Include="UnityEngine">
<HintPath>..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\VRChat\MelonLoader\Managed\UnityEngine.dll</HintPath>
<Reference Include="System.Xml.Linq" />
<Reference Include="UIExpansionKit, Version=0.2.5.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\Libs\UIExpansionKit.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="UnityEngine.CoreModule">
<HintPath>..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\VRChat\MelonLoader\Managed\UnityEngine.CoreModule.dll</HintPath>
<Reference Include="UnhollowerBaseLib, Version=0.4.13.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\Libs\UnhollowerBaseLib.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="UnityEngine.UI">
<HintPath>..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\VRChat\MelonLoader\Managed\UnityEngine.UI.dll</HintPath>
<Reference Include="UnhollowerRuntimeLib, Version=0.4.10.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\Libs\UnhollowerRuntimeLib.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="VRCCore-Editor">
<HintPath>..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\VRChat\MelonLoader\Managed\VRCCore-Editor.dll</HintPath>
<Reference Include="UnityEngine, Version=3.7.1.6, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\Libs\UnityEngine.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="VRCCore-Standalone">
<HintPath>..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\VRChat\MelonLoader\Managed\VRCCore-Standalone.dll</HintPath>
<Reference Include="UnityEngine.CoreModule, Version=3.7.1.6, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\Libs\UnityEngine.CoreModule.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="VRCSDK3">
<HintPath>..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\VRChat\MelonLoader\Managed\VRCSDK3.dll</HintPath>
<Reference Include="UnityEngine.UI, Version=3.7.1.6, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\Libs\UnityEngine.UI.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="VRCSDKBase">
<HintPath>..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\VRChat\MelonLoader\Managed\VRCSDKBase.dll</HintPath>
<Reference Include="VRCCore-Standalone, Version=3.7.1.6, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\Libs\VRCCore-Standalone.dll</HintPath>
<Private>False</Private>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="SafetyMain.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="SafetyClasses.cs" />
<Compile Include="SafetyCompatability.cs" />
<Compile Include="SafetyHelpers.cs" />
<Compile Include="SafetyMain.cs" />
<Compile Include="SafetyPrefs.cs" />
<Compile Include="SafetySettings.cs" />
<Compile Include="SafetyHelpers.cs" />
<Compile Include="SafetyUI.cs" />
<Compile Include="SafetyClasses.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="SafetyXref.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSHARP.Targets" />
<ProjectExtensions>
<VisualStudio AllowExistingFolder="true" />
</ProjectExtensions>
</Project>
52 changes: 52 additions & 0 deletions SafetyPresets/SafetyXref.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Reflection;
using UnhollowerRuntimeLib.XrefScans;

namespace SafetyPresets
{
class SafetyXref
{
// Yoinked with love from https://github.com/BenjaminZehowlt/DynamicBonesSafety/blob/master/DynamicBonesSafetyMod.cs
// or well, the current alternative https://github.com/loukylor/VRC-Mods/blob/main/PlayerList/Utilities/Xref.cs

public static bool CheckMethod(MethodInfo method, string match)
{
try
{
return XrefScanner.XrefScan(method)
.Where(instance => instance.Type == XrefType.Global && instance.ReadAsObject().ToString().Contains(match)).Any();
}
catch { }
return false;
}
public static bool CheckUsed(MethodInfo method, string methodName)
{
try
{
return XrefScanner.UsedBy(method)
.Where(instance => instance.TryResolve() != null && instance.TryResolve().Name.Contains(methodName)).Any();
}
catch { }
return false;
}
public static bool CheckUsing(MethodInfo method, string match, Type type)
{
foreach (XrefInstance instance in XrefScanner.XrefScan(method))
if (instance.Type == XrefType.Method)
try
{
if (instance.TryResolve().DeclaringType == type && instance.TryResolve().Name.Contains(match))
return true;
}
catch
{

}
return false;
}
}
}
2 changes: 1 addition & 1 deletion packages.config
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Newtonsoft.Json" version="12.0.3" targetFramework="net472" />
<package id="Newtonsoft.Json" version="9.0.1" targetFramework="net472" />
</packages>

0 comments on commit 0a11345

Please sign in to comment.