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

FrankensteinTable #538

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open

Conversation

IIIaKa
Copy link
Contributor

@IIIaKa IIIaKa commented Nov 12, 2024

Adding two hooks to enable tracking and, if necessary, cancellation of wake or sleep actions for FrankensteinPet.
In vanilla, these actions are not restricted, even within another player's building privilege area.

1. The OnWakeFrankenstein hook allows tracking the wake of FrankensteinPet and, if necessary, canceling the awakening.

object OnWakeFrankenstein(FrankensteinTable table, BasePlayer player)
{
    Puts($"Player {player.displayName} is attempting to wake FrankensteinPet using FrankensteinTable({table.net.ID.Value}).");
    return null;
}

Code before:

private void WakeFrankenstein(global::BasePlayer owner)
{
	if (owner == null)
	{
		return;
	}
	if (!this.CanStartCreating(owner))
	{
		return;
	}
	this.waking = true;
	base.inventory.SetLocked(true);
	base.SendNetworkUpdateImmediate(false);
	base.StartCoroutine(this.DelayWakeFrankenstein(owner));
	base.ClientRPC(global::RpcTarget.NetworkGroup("CL_WakeFrankenstein"));
}

Code after:

private void WakeFrankenstein(global::BasePlayer owner)
{
	if (owner == null)
	{
		return;
	}
	if (!this.CanStartCreating(owner))
	{
		return;
	}
	if (Interface.CallHook("OnWakeFrankenstein", this, owner) != null)
	{
		return;
	}
	this.waking = true;
	base.inventory.SetLocked(true);
	base.SendNetworkUpdateImmediate(false);
	base.StartCoroutine(this.DelayWakeFrankenstein(owner));
	base.ClientRPC(global::RpcTarget.NetworkGroup("CL_WakeFrankenstein"));
}

2. The OnSleepFrankenstein hook allows tracking the sleep of FrankensteinPet and, if necessary, cancelling the sleep action.

object OnSleepFrankenstein(FrankensteinTable table, BasePlayer player, FrankensteinPet pet)
{
    Puts($"Player {player.userID} is attempting to sleep FrankensteinPet({pet.net.ID.Value}) using FrankensteinTable({table.net.ID.Value}).");
    return null;
}

Code before:

private void SleepFrankenstein(global::BasePlayer owner)
{
	if (!this.IsInventoryEmpty())
	{
		return;
	}
	if (owner == null)
	{
		return;
	}
	if (owner.PetEntity == null)
	{
		return;
	}
	global::FrankensteinPet frankensteinPet = owner.PetEntity as global::FrankensteinPet;
	if (frankensteinPet == null)
	{
		return;
	}
	if (Vector3.Distance(base.transform.position, frankensteinPet.transform.position) >= 5f)
	{
		return;
	}
	this.ReturnFrankensteinItems(frankensteinPet);
	global::ItemManager.DoRemoves();
	base.SendNetworkUpdateImmediate(false);
	frankensteinPet.Kill(global::BaseNetworkable.DestroyMode.None);
}

Code after:

private void SleepFrankenstein(global::BasePlayer owner)
{
	if (!this.IsInventoryEmpty())
	{
		return;
	}
	if (owner == null)
	{
		return;
	}
	if (owner.PetEntity == null)
	{
		return;
	}
	global::FrankensteinPet frankensteinPet = owner.PetEntity as global::FrankensteinPet;
	if (frankensteinPet == null)
	{
		return;
	}
	if (Vector3.Distance(base.transform.position, frankensteinPet.transform.position) >= 5f)
	{
		return;
	}
	if (Interface.CallHook("OnSleepFrankenstein", this, owner, frankensteinPet) != null)
	{
		return;
	}
	this.ReturnFrankensteinItems(frankensteinPet);
	global::ItemManager.DoRemoves();
	base.SendNetworkUpdateImmediate(false);
	frankensteinPet.Kill(global::BaseNetworkable.DestroyMode.None);
}

Adding two hooks to allow cancellation of wake or sleep for FrankensteinPet.
@MrBlue
Copy link
Member

MrBlue commented Dec 30, 2024

Is there a reason you're using Modify hooks instead of simple hooks?
If not can you please update this to use simple hooks instead?

And please make sure you're adding the hooks in the right place. You're currently adding them to the Rust.Clans.Local dll not Assembly-CSharp

@IIIaKa IIIaKa closed this Jan 2, 2025
@IIIaKa IIIaKa reopened this Jan 2, 2025
@IIIaKa
Copy link
Contributor Author

IIIaKa commented Jan 2, 2025

Made all the necessary changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants