Skip to content

Commit

Permalink
Added support for Beat Saber 0.11.1. Fixed room adjust messing up ava…
Browse files Browse the repository at this point in the history
…tar positioning.
  • Loading branch information
xyonico committed Aug 3, 2018
1 parent 62e507d commit 7f9ed77
Show file tree
Hide file tree
Showing 8 changed files with 228 additions and 80 deletions.
10 changes: 8 additions & 2 deletions CustomAvatar.sln
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,17 @@ Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
0_11_2|Any CPU = 0_11_2|Any CPU
0_11_1|Any CPU = 0_11_1|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{8207B0AC-FCA6-47AA-B634-795271F4E5D0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8207B0AC-FCA6-47AA-B634-795271F4E5D0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8207B0AC-FCA6-47AA-B634-795271F4E5D0}.Debug|Any CPU.ActiveCfg = Release|Any CPU
{8207B0AC-FCA6-47AA-B634-795271F4E5D0}.Debug|Any CPU.Build.0 = Release|Any CPU
{8207B0AC-FCA6-47AA-B634-795271F4E5D0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8207B0AC-FCA6-47AA-B634-795271F4E5D0}.Release|Any CPU.Build.0 = Release|Any CPU
{8207B0AC-FCA6-47AA-B634-795271F4E5D0}.0_11_2|Any CPU.ActiveCfg = 0_11_2|Any CPU
{8207B0AC-FCA6-47AA-B634-795271F4E5D0}.0_11_2|Any CPU.Build.0 = 0_11_2|Any CPU
{8207B0AC-FCA6-47AA-B634-795271F4E5D0}.0_11_1|Any CPU.ActiveCfg = 0_11_1|Any CPU
{8207B0AC-FCA6-47AA-B634-795271F4E5D0}.0_11_1|Any CPU.Build.0 = 0_11_1|Any CPU
EndGlobalSection
EndGlobal
4 changes: 3 additions & 1 deletion CustomAvatar/AvatarBehaviour.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using UnityEngine;
using System;
using UnityEngine;

namespace CustomAvatar
{
Expand Down Expand Up @@ -38,6 +39,7 @@ private void LateUpdate()
_right.position = rightPosRot.Position;
_right.rotation = rightPosRot.Rotation;

if (_body == null) return;
_body.position = _head.position - (_head.transform.up * 0.1f);

var vel = new Vector3(_body.transform.localPosition.x - _prevBodyPos.x, 0.0f, _body.localPosition.z - _prevBodyPos.z);
Expand Down
90 changes: 90 additions & 0 deletions CustomAvatar/AvatarLoader.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
using System;
using System.Collections.Generic;
using System.IO;

namespace CustomAvatar
{
#if BS_0_11_2
public class AvatarLoader
{
private static readonly string[] AvatarExtensions =
Expand Down Expand Up @@ -44,4 +46,92 @@ private static void GetAvatarsInPath(string path, Action<FileBrowserItem[]> call
FileBrowserModel.GetContentOfDirectory(path, AvatarExtensions, callback);
}
}
#elif BS_0_11_1
public class AvatarLoader
{
private readonly List<CustomAvatar> _avatars = new List<CustomAvatar>();

public IReadOnlyList<CustomAvatar> Avatars
{
get { return _avatars; }
}

public AvatarLoader(string customAvatarsPath, Action<IReadOnlyList<CustomAvatar>> loadedCallback)
{
void AvatarPathsLoaded(FileBrowserItem[] items)
{
foreach (var item in items)
{
if (Directory.Exists(item.fullPath)) continue;
var newAvatar = new CustomAvatar(item.fullPath);
_avatars.Add(newAvatar);
}

loadedCallback(_avatars.ToArray());
}

GetAvatarsInPath(customAvatarsPath, AvatarPathsLoaded);
}

public int IndexOf(CustomAvatar customAvatar)
{
return _avatars.IndexOf(customAvatar);
}

private static void GetAvatarsInPath(string path, Action<FileBrowserItem[]> callback)
{
AvatarFileBrowserModel.Instance.GetContentOfDirectory(path, callback);
}

public class AvatarFileBrowserModel : FileBrowserModel
{
public static readonly AvatarFileBrowserModel Instance = new AvatarFileBrowserModel();

protected override FileBrowserItem[] GetContentOfDirectory(string path)
{
var list = new List<FileBrowserItem>();
var path2 = path + "\\..";
if (Path.GetFullPath(path2) != Path.GetFullPath(path))
{
list.Add(new DirectoryBrowserItem("..", Path.GetFullPath(path2)));
}
if (!CanOpenDirectory(path))
{
return list.ToArray();
}
path = Path.GetFullPath(path);
var directories = Directory.GetDirectories(path);
foreach (var path3 in directories)
{
list.Add(new DirectoryBrowserItem(Path.GetFileName(path3), Path.GetFullPath(path3)));
}
var files = Directory.GetFiles(path);
foreach (var path4 in files)
{
var a = Path.GetExtension(path4).ToLower();
if (a == ".avatar")
{
list.Add(new FileBrowserItem(Path.GetFileName(path4), Path.GetFullPath(path4)));
}
}
return list.ToArray();
}

private static bool CanOpenDirectory(string path)
{
bool result;
try
{
Directory.GetDirectories(path);
result = true;
}
catch
{
result = false;
}
return result;
}
}
}
#endif
}
28 changes: 23 additions & 5 deletions CustomAvatar/BeatSaberUtil.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
using System.Linq;
using System;
using System.Linq;
using UnityEngine;

namespace CustomAvatar
{
public static class BeatSaberUtil
{
private static MainSettingsModel _mainSettingsModel;
private static VRCenterAdjust _vrCenterAdjust;

public static MainSettingsModel MainSettingsModel
{
Expand All @@ -20,21 +22,37 @@ public static MainSettingsModel MainSettingsModel
}
}

public static VRCenterAdjust VRCenterAdjust
{
get
{
if (_vrCenterAdjust == null)
{
_vrCenterAdjust = Resources.FindObjectsOfTypeAll<VRCenterAdjust>().FirstOrDefault();
}

return _vrCenterAdjust;
}
}

public static float GetPlayerHeight()
{
return MainSettingsModel == null ? MainSettingsModel.kDefaultPlayerHeight : MainSettingsModel.playerHeight;
}

public static Vector3 GetRoomCenter()
{
return MainSettingsModel == null ? Vector3.zero : MainSettingsModel.roomCenter;
return VRCenterAdjust == null
? MainSettingsModel == null ? Vector3.zero : MainSettingsModel.roomCenter
: VRCenterAdjust.transform.position;
}

public static Quaternion GetRoomRotation()
{
return MainSettingsModel == null
? Quaternion.identity
: Quaternion.Euler(0, MainSettingsModel.roomRotation, 0);
return VRCenterAdjust == null
? MainSettingsModel == null ? Quaternion.identity :
Quaternion.Euler(0, MainSettingsModel.roomRotation, 0)
: VRCenterAdjust.transform.rotation;
}
}
}
37 changes: 34 additions & 3 deletions CustomAvatar/CustomAvatar.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,40 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == '0.11.1 Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<OutputPath>bin\0.11.1 Release\</OutputPath>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == '0.11.2 Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<OutputPath>bin\0.11.2 Release\</OutputPath>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>
</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == '0.11.1|AnyCPU' ">
<OutputPath>bin\0.11.1\</OutputPath>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == '0.11.2|AnyCPU' ">
<OutputPath>bin\0.11.2\</OutputPath>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == '0_11_2|AnyCPU' ">
<OutputPath>bin\0_11_2\</OutputPath>
<DefineConstants>BS_0_11_2</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == '0_11_1|AnyCPU' ">
<OutputPath>bin\0_11_1\</OutputPath>
<DefineConstants>BS_0_11_1</DefineConstants>
</PropertyGroup>
<ItemGroup>
<Reference Include="Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
Expand All @@ -51,6 +77,9 @@
<Reference Include="UnityEngine.AssetBundleModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
<HintPath>..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Beat Saber\Beat Saber_Data\Managed\UnityEngine.AssetBundleModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.AudioModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
<HintPath>..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Beat Saber\Beat Saber_Data\Managed\UnityEngine.AudioModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.CoreModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
<HintPath>..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Beat Saber\Beat Saber_Data\Managed\UnityEngine.CoreModule.dll</HintPath>
</Reference>
Expand Down Expand Up @@ -79,6 +108,8 @@
<Compile Include="AvatarEventsPlayer.cs" />
<Compile Include="AvatarPrefab.cs" />
<Compile Include="AvatarLoadResult.cs" />
<Compile Include="EventFilterBehaviour.cs" />
<Compile Include="EventFilters.cs" />
<Compile Include="FirstPersonAvatar.cs" />
<Compile Include="PlayerAvatarManager.cs" />
<Compile Include="AvatarSpawner.cs" />
Expand Down
41 changes: 19 additions & 22 deletions CustomAvatar/EventFilterBehaviour.cs
Original file line number Diff line number Diff line change
@@ -1,26 +1,23 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
using UnityEngine;

namespace CustomAvatar
{
[RequireComponent(typeof(EventManager))]
public class EventFilterBehaviour : MonoBehaviour
{
protected EventManager EventManager
{
get
{
if (_eventManager == null)
{
_eventManager = GetComponent<EventManager>();
}
return _eventManager;
}
}
[RequireComponent(typeof(EventManager))]
public class EventFilterBehaviour : MonoBehaviour
{
protected EventManager EventManager
{
get
{
if (_eventManager == null)
{
_eventManager = GetComponent<EventManager>();
}

private EventManager _eventManager;
}
}
return _eventManager;
}
}

private EventManager _eventManager;
}
}
Loading

0 comments on commit 7f9ed77

Please sign in to comment.