Skip to content

Commit

Permalink
Remove car ownership patches
Browse files Browse the repository at this point in the history
  • Loading branch information
DaXcess committed Sep 23, 2024
1 parent 8d75508 commit 98f65f0
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 71 deletions.
45 changes: 0 additions & 45 deletions Source/Patches/CarPatches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,49 +59,4 @@ private static IEnumerable<CodeInstruction> RemovePlayerAnimations(IEnumerable<C
.RemoveInstructions(39)
.InstructionEnumeration();
}

/// <summary>
/// If we are the host, and we're dead, move the ownership to the first alive player to not interfere with the collision
/// </summary>
[HarmonyPatch(typeof(VehicleController), nameof(VehicleController.RemovePlayerControlOfVehicleServerRpc))]
[HarmonyPostfix]
private static void OnRemoveDriver(VehicleController __instance)
{
if (Plugin.Flags.HasFlag(Flags.ExperimentalDisableCarOwnershipPatch))
return;

if (!NetworkManager.Singleton.IsHost)
return;

if (!VRSession.Instance.LocalPlayer.PlayerController.isPlayerDead)
return;

var alivePlayer = StartOfRound.Instance.allPlayerScripts.FirstOrDefault(player => !player.isPlayerDead);
if (!alivePlayer)
return;

__instance.syncCarPositionInterval = 1f;
__instance.syncedPosition = Vector3.zero;
__instance.syncedRotation = Quaternion.identity;
__instance.SyncCarPhysicsToOtherClients();

__instance.NetworkObject.ChangeOwnership(alivePlayer.actualClientId);
}

/// <summary>
/// Make sure to take back ownership once we leave the level
/// </summary>
[HarmonyPatch(typeof(StartOfRound), nameof(StartOfRound.ShipHasLeft))]
[HarmonyPostfix]
private static void OnUnloadMap()
{
if (Plugin.Flags.HasFlag(Flags.ExperimentalDisableCarOwnershipPatch))
return;

if (!NetworkManager.Singleton.IsServer)
return;

foreach (var vehicle in Object.FindObjectsOfType<VehicleController>())
vehicle.NetworkObject.ChangeOwnership(StartOfRound.Instance.localPlayerController.actualClientId);
}
}
18 changes: 0 additions & 18 deletions Source/Patches/Spectating/Patches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,24 +125,6 @@ private static void OnPlayerDeath(PlayerControllerB __instance)
shipDoorLeft.GetComponent<BoxCollider>().isTrigger = true;
shipDoorRight.GetComponent<BoxCollider>().isTrigger = true;
shipDoorWall.GetComponent<BoxCollider>().isTrigger = true;

// Make sure any cars are not owned by us if we're the host
if (NetworkManager.Singleton.IsHost && !Plugin.Flags.HasFlag(Flags.ExperimentalDisableCarOwnershipPatch))
{
var alivePlayer = StartOfRound.Instance.allPlayerScripts.FirstOrDefault(player => !player.isPlayerDead);
if (alivePlayer)
{
foreach (var car in Object.FindObjectsOfType<VehicleController>().Where(car => car.IsOwner))
{
car.syncCarPositionInterval = 1f;
car.syncedPosition = Vector3.zero;
car.syncedRotation = Quaternion.identity;
car.SyncCarPhysicsToOtherClients();

car.NetworkObject.ChangeOwnership(alivePlayer.actualClientId);
}
}
}

// Of course, Nutcracker with special AI behavior
var nutcrackers = Object.FindObjectsOfType<NutcrackerEnemyAI>();
Expand Down
14 changes: 6 additions & 8 deletions Source/Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,6 @@ private void Awake()
if (args.Contains("--lcvr-item-offset-editor"))
Flags |= Flags.ItemOffsetEditor;

if (args.Contains("--lcvr-disable-car-ownership-patch"))
Flags |= Flags.ExperimentalDisableCarOwnershipPatch;

// Verify game assembly to detect compatible version
var allowUnverified = Environment.GetCommandLineArgs().Contains(SKIP_CHECKSUM_VAR);

Expand Down Expand Up @@ -154,18 +151,18 @@ private static string GetCommitHash()
catch
{
LCVR.Logger.LogWarning(
"Failed to retrieve commit hash (compiled outside of git repo?). Using placeholder.");
"Failed to retrieve commit hash (compiled outside of git repo?).");

return "badbeef";
return "unknown";
}
}

private bool VerifyGameVersion()
{
var location = Path.Combine(Paths.ManagedPath, "Assembly-CSharp.dll");
var shasum = BitConverter.ToString(Utils.ComputeHash(File.ReadAllBytes(location))).Replace("-", "");
var hash = BitConverter.ToString(Utils.ComputeHash(File.ReadAllBytes(location))).Replace("-", "");

return GAME_ASSEMBLY_HASHES.Contains(shasum);
return GAME_ASSEMBLY_HASHES.Contains(hash);
}

private bool LoadEarlyRuntimeDependencies()
Expand Down Expand Up @@ -254,6 +251,8 @@ private bool InitializeVR()
return true;
}

// ReSharper disable Unity.PerformanceAnalysis

/// <summary>
/// Modify the splash screen logo
/// </summary>
Expand Down Expand Up @@ -285,5 +284,4 @@ public enum Flags
InvalidGameAssembly = 1 << 1,
InteractableDebug = 1 << 2,
ItemOffsetEditor = 1 << 3,
ExperimentalDisableCarOwnershipPatch = 1 << 4,
}

0 comments on commit 98f65f0

Please sign in to comment.