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

Add a note to plugin developers/authors to recompile their plugins when updating the RTD plugin #105

Closed
naydef opened this issue Mar 1, 2024 · 2 comments

Comments

@naydef
Copy link

naydef commented Mar 1, 2024

I usually expect that when updating plugins that those plugins will keep compatibility when using their API, however this isn't the case here:

L 02/29/2024 - 13:19:53: [SM] Exception reported: Invalid parameter number: 4
L 02/29/2024 - 13:19:53: [SM] Blaming: Gameplay/RTD/rtd.smx
L 02/29/2024 - 13:19:53: [SM] Call stack trace:
L 02/29/2024 - 13:19:53: [SM]   [0] GetNativeCell
L 02/29/2024 - 13:19:53: [SM]   [1] Line 308, rtd/natives.sp::Native_Remove
L 02/29/2024 - 13:19:53: [SM]   [3] RTD2_Remove
L 02/29/2024 - 13:19:53: [SM]   [4] Line 2377, tf2utils::cancelRTDRoll

The code failing:
RTD2_Remove(client, RTDRemove_Custom, "Chaos Dice was used");

The plugin which relies on RTD was compiled with old include file, so It didn't have the new arguments the prototype.
So I guess what I say is either keep backward compatibility or add a note for plugin devs/server owners to recompile their plugins which use RTD plugin when they update it.

That's all.

@Phil25
Copy link
Owner

Phil25 commented Mar 1, 2024

This was an oversight on my part. Update 2.5.2 introduced additional parameters which had default values, so no code change is required when recompiling plugins, but RTD didn't account for them not being provided at all.

I will release an update in a bit that will allow use of plugins compiled with pre-2.5.2 include file. You can fix this yourself for the time being by changing the Native_Remove function like this (untested):

public int Native_Remove(Handle hPlugin, int iParams)
{
	int client = GetNativeCell(1);
	RTDRemoveReason iReason = view_as<RTDRemoveReason>(GetNativeCell(2));
	char sReason[32];

	if (iReason == RTDRemove_Custom)
		GetNativeString(3, sReason, sizeof(sReason));

-	if (!GetNativeCell(4)) // not forced
+	if (iParams >= 4 && !GetNativeCell(4)) // not forced
	{
		Perk perk = RemovePerk(client, iReason, sReason);
		return perk ? perk.Id : -1;
	}

-	int iInitiator = GetNativeCell(5);
+	int iInitiator = iParams >= 5 ? GetNativeCell(5) : 0;
	if (IsValidClient(iInitiator) && g_hRollers.GetInRoll(client) && GetForwardFunctionCount(g_hFwdCanRemove) > 0)
	{
		Call_StartForward(g_hFwdCanRemove);
		Call_PushCell(iInitiator);
		Call_PushCell(client);
		Call_PushCell(g_hRollers.GetPerk(client).Id);

		Action result = Plugin_Continue;
		Call_Finish(result);

		if (result != Plugin_Continue)
			return -1;
	}

	Perk perk = ForceRemovePerk(client, iReason, sReason, iInitiator);
	return perk ? perk.Id : -1;
}

Plugins compiled with 2.X.X version of RTD should work with any higher 2.X.X version, period. I'm sorry for introducing this bug.

@Phil25
Copy link
Owner

Phil25 commented Mar 2, 2024

Tested and fixed in 2.5.4.

@Phil25 Phil25 closed this as completed Mar 2, 2024
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

No branches or pull requests

2 participants