Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for "Cave Revamp" update #91

Closed
wants to merge 15 commits into from
54 changes: 27 additions & 27 deletions ComputerInterface.Commands/CommandRegistrar.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
using System;
using UnityEngine;
using Zenject;
using Photon.Pun;

namespace ComputerInterface.Commands
{
internal class CommandRegistrar : IInitializable
public class CommandRegistrar : IInitializable
{
private readonly CommandHandler _commandHandler;
private readonly CustomComputer _computer;
private CommandHandler _commandHandler;
private CustomComputer _computer;

public CommandRegistrar(CommandHandler commandHandler, CustomComputer computer)
[Inject]
public void Construct(CommandHandler commandHandler, CustomComputer computer)
{
_commandHandler = commandHandler;
_computer = computer;
Expand All @@ -29,63 +31,61 @@ public void RegisterCommands()
if (b > 0) b /= 255;

BaseGameInterface.SetColor(r, g, b);
return $"R: {r} ({args[0]})\nG: {g} ({args[1]})\nB: {b} ({args[2]})\n";
return $"Updated color:\n\nR: {r} ({args[0]})\nG: {g} ({args[1]})\nB: {b} ({args[2]})\n";
}));

// setname: setname <name>
_commandHandler.AddCommand(new Command("setname", new Type[] { null }, args =>
_commandHandler.AddCommand(new Command("setname", new Type[] { typeof(string) }, args =>
{
var newName = ((string)args[0]).ToUpper();

var result = BaseGameInterface.SetName(newName);

if (result == BaseGameInterface.WordCheckResult.Allowed) return $"Name set to {newName.Replace(" ", "")}";
else return BaseGameInterface.WordCheckResultToMessage(result);
if (result == BaseGameInterface.WordCheckResult.Allowed) return $"Updated name: {newName.Replace(" ", "")}";
else return $"Error: {BaseGameInterface.WordCheckResultToMessage(result)}";
}));

// leave: leave
// disconnects from the current room
_commandHandler.AddCommand(new Command("leave", null, args =>
{
BaseGameInterface.Disconnect();
return "Left room";
if (PhotonNetwork.InRoom)
{
BaseGameInterface.Disconnect();
return "Left room!";
}
return "You aren't currently in a room.";
}));

// join <roomId>
// join a private room
_commandHandler.AddCommand(new Command("join", new Type[] { null }, args =>
_commandHandler.AddCommand(new Command("join", new Type[] { typeof(string) }, args =>
{
var roomId = (string)args[0];

roomId = roomId.ToUpper();
var result = BaseGameInterface.JoinRoom(roomId);

if (result == BaseGameInterface.WordCheckResult.Allowed) return $"Joined {roomId}";
else return BaseGameInterface.WordCheckResultToMessage(result);
if (result == BaseGameInterface.WordCheckResult.Allowed) return $"Joining room: {roomId}";
else return $"Error: {BaseGameInterface.WordCheckResultToMessage(result)}";
}));

// cam <fp|tp>
// sets the screen camera to either first or third person
_commandHandler.AddCommand(new Command("cam", new Type[] { null }, args =>
_commandHandler.AddCommand(new Command("cam", new Type[] { typeof(string) }, args =>
{
var cam = GameObject.Find("Shoulder Camera")?.GetComponent<Camera>();
if (cam == null) return "camera not found";
var cam = GorillaTagger.Instance.thirdPersonCamera.GetComponentInChildren<Camera>();
if (cam == null) return "Error: Could not find camera";

var argString = (string)args[0];

if (argString == "fp")
{
cam.enabled = false;
return "Set to first person";
}

if (argString == "tp")
if (argString == "fp" || argString == "tp")
{
cam.enabled = true;
return "Set to third person";
cam.enabled = argString == "tp";
return $"Updated camera: {(argString == "tp" ? "Third" : "First")} person";
}

return "usage: cam <fp|tp>";
return "Invalid syntax! Use fp/tp to use the command";
}));

// setbg <r> <g> <b>
Expand All @@ -102,7 +102,7 @@ public void RegisterCommands()

_computer.SetBG(r, g, b);

return "Background set";
return $"Updated background:\n\nR: {r} ({args[0]})\nG: {g} ({args[1]})\nB: {b} ({args[2]})\n";
}));
}

Expand Down
11 changes: 10 additions & 1 deletion ComputerInterface.Commands/ComputerInterface.Commands.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<TargetFramework>netstandard2.1</TargetFramework>
</PropertyGroup>

<ItemGroup>
Expand All @@ -16,12 +16,21 @@
</ItemGroup>

<ItemGroup>
<Reference Include="Assembly-CSharp">
<HintPath>$(GameAssemblyPath)\Assembly-CSharp.dll</HintPath>
</Reference>
<Reference Include="BepInEx">
<HintPath>$(BepInExAssemblyPath)\BepInEx.dll</HintPath>
</Reference>
<Reference Include="Bepinject">
<HintPath>$(PluginsPath)\Bepinject-Auros\Bepinject.dll</HintPath>
</Reference>
<Reference Include="PhotonRealtime">
<HintPath>$(GameAssemblyPath)\PhotonRealtime.dll</HintPath>
</Reference>
<Reference Include="PhotonUnityNetworking">
<HintPath>$(GameAssemblyPath)\PhotonUnityNetworking.dll</HintPath>
</Reference>
<Reference Include="UnityEngine">
<HintPath>$(GameAssemblyPath)\UnityEngine.dll</HintPath>
</Reference>
Expand Down
14 changes: 9 additions & 5 deletions ComputerInterface/AssetsLoader.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Threading.Tasks;
Expand All @@ -14,14 +15,15 @@ internal class AssetsLoader : IDisposable
private AssetBundle _loadedBundle;
private Task _loadingTask;

private readonly Dictionary<string, Object> _assetCache = new Dictionary<string, Object>();

public async Task<T> GetAsset<T>(string name) where T : Object
{
if (_assetCache.TryGetValue(name, out var cachedObject)) return (T)cachedObject;

if (!IsLoaded)
{
if (_loadingTask == null)
{
_loadingTask = LoadBundleAsyncInternal();
}
_loadingTask ??= LoadBundleAsyncInternal();

await _loadingTask;
}
Expand All @@ -41,7 +43,9 @@ public async Task<T> GetAsset<T>(string name) where T : Object
completionSource.SetResult((T)assetBundleRequest.asset);
};

return await completionSource.Task;
var completedTask = await completionSource.Task;
_assetCache.Add(name, completedTask);
return completedTask;
}

private async Task LoadBundleAsyncInternal()
Expand Down
21 changes: 13 additions & 8 deletions ComputerInterface/BaseGameInterface.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,10 @@ public static ETurnMode GetTurnMode()

public static void SetInstrumentVolume(int value)
{
PlayerPrefs.SetFloat("instrumentVolume", value / 50f);
if (!CheckForComputer(out var computer)) return;

computer.instrumentVolume = value / 50f;
PlayerPrefs.SetFloat("instrumentVolume", computer.instrumentVolume);
PlayerPrefs.Save();
}

Expand Down Expand Up @@ -237,6 +240,13 @@ public static void SetVoiceMode(bool voiceChatOn)
computer.voiceChatOn = voiceChatOn ? "TRUE" : "FALSE";
PlayerPrefs.SetString("voiceChatOn", computer.voiceChatOn);
PlayerPrefs.Save();

if (PhotonNetwork.InRoom)
{
var GorillaAssembly = typeof(GorillaTagger).Assembly;
var ContainerType = GorillaAssembly.GetType("RigContainer");
AccessTools.Method(ContainerType, "RefreshAllRigVoices").Invoke(null, null);
}
}

public static bool GetVoiceMode()
Expand Down Expand Up @@ -276,12 +286,7 @@ public static string[] GetGroupJoinMaps()
#region Room settings

public static void Disconnect()
{
if (CheckForComputer(out var computer))
{
computer.networkController.AttemptDisconnect();
}
}
=> PhotonNetworkController.Instance.AttemptDisconnect();

public static WordCheckResult JoinRoom(string roomId)
{
Expand All @@ -294,7 +299,7 @@ public static WordCheckResult JoinRoom(string roomId)

if (roomAllowed == WordCheckResult.Allowed)
{
computer.networkController.AttemptToJoinSpecificRoom(roomId);
PhotonNetworkController.Instance.AttemptToJoinSpecificRoom(roomId);
}

return roomAllowed;
Expand Down
3 changes: 3 additions & 0 deletions ComputerInterface/CIConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
using BepInEx.Configuration;
using Bepinject;
using UnityEngine;
using ComputerInterface.Monitors;

namespace ComputerInterface
{
internal class CIConfig
{
public ConfigEntry<Color> ScreenBackgroundColor;
public ConfigEntry<MonitorType> SavedMonitorType;
public Texture BackgroundTexture;

public ConfigEntry<string> _screenBackgroundPath;
Expand All @@ -21,6 +23,7 @@ public CIConfig(BepInConfig config)
{
var file = config.Config;

SavedMonitorType = file.Bind("Appearance", "Monitor Type", MonitorType.Modern, "The preferred monitor to use in-game.");
ScreenBackgroundColor = file.Bind("Colors", "ScreenBackgroundColor", new Color(0.08f, 0.08f, 0.08f), "The background color of the screen");
_screenBackgroundPath = file.Bind("Textures", "ScreenBackgroundPath", "BepInEx/plugins/ComputerInterface/background.png", "Path to a custom screen background");
_disabledMods = file.Bind("Mod Management", "DisabledMods", "", "List of disabled mods");
Expand Down
6 changes: 3 additions & 3 deletions ComputerInterface/CommandHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,15 @@ public bool Execute(string commandString, out string messageString)
var commandStrings = commandString.Split(' ');
if (!_commands.TryGetValue(commandStrings[0], out var command))
{
messageString = "couldn't find command";
messageString = "Command not found!";
return false;
}

// check if number of arguments is correct
var argumentCount = commandStrings.Length - 1;
if (argumentCount != command.ArgumentCount)
{
messageString = $"wrong argument count\nGot {argumentCount}\nShould be {command.ArgumentCount}";
messageString = $"Incorrect number of arguments!\nGot {argumentCount}\nShould be {command.ArgumentCount}";
return false;
}

Expand All @@ -84,7 +84,7 @@ public bool Execute(string commandString, out string messageString)
}
catch
{
messageString = "arguments not in correct format";
messageString = "Incorrect arguments!\nArguments aren't in the correct format.";
return false;
}

Expand Down
10 changes: 2 additions & 8 deletions ComputerInterface/ComputerInterface.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<TargetFramework>netstandard2.1</TargetFramework>
<LangVersion>8.0</LangVersion>
</PropertyGroup>

Expand Down Expand Up @@ -33,18 +33,12 @@
<Reference Include="Bepinject">
<HintPath>$(PluginsPath)\Bepinject-Auros\Bepinject.dll</HintPath>
</Reference>
<Reference Include="Photon3Unity3D">
<HintPath>$(GameAssemblyPath)\Photon3Unity3D.dll</HintPath>
</Reference>
<Reference Include="PhotonRealtime">
<HintPath>$(GameAssemblyPath)\PhotonRealtime.dll</HintPath>
</Reference>
<Reference Include="PhotonUnityNetworking">
<HintPath>$(GameAssemblyPath)\PhotonUnityNetworking.dll</HintPath>
</Reference>
<Reference Include="PlayFab">
<HintPath>$(GameAssemblyPath)\PlayFab.dll</HintPath>
</Reference>
<Reference Include="Unity.InputSystem">
<HintPath>$(GameAssemblyPath)\Unity.InputSystem.dll</HintPath>
</Reference>
Expand Down
Loading
Loading