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

SourceMod 1.12 Migration #164

Merged
merged 6 commits into from
Oct 30, 2024
Merged

SourceMod 1.12 Migration #164

merged 6 commits into from
Oct 30, 2024

Conversation

Alienmario
Copy link
Collaborator

@Alienmario Alienmario commented Oct 25, 2024

  • updated CI + Readme
  • moved gpGlobals variable to main plugin space (unused warning)
  • fixed macros (CONF_*, assert)
  • replaced entindex-enthandle conversion stocks with natives
  • removed CookieCompat in addon_earbleed
  • replaced Cookie utils with new methodmap accessors
  • with that done, addon_killsounds will not store the default value in cookies anymore
  • turned addon_scoring into a placeholder for new implementation
  • removed obsolete timer returns

@Alienmario
Copy link
Collaborator Author

Investigating crashing on linux: https://crash.limetech.org/7afrqsdsuw4y.

@Alienmario
Copy link
Collaborator Author

Alienmario commented Oct 25, 2024

There is a regression that occurs when hooking UTIL_GetLocalPlayer on Linux.

public MRESReturn Hook_UTIL_GetLocalPlayer(Handle hReturn)
{
CBaseEntity pOverrideEntity = g_pLocalPlayerEntity[g_iLocalPlayerStackPointer];
if (pOverrideEntity.IsValid())
{
CBasePlayer pPlayer;
if (pOverrideEntity.IsClassPlayer())
{
pPlayer = view_as<CBasePlayer>(pOverrideEntity);
}
else
{
pPlayer = GetNearestPlayerPreferAlive(pOverrideEntity);
if (pPlayer == NULL_CBASEENTITY)
{
return MRES_Ignored;
}
}
// LogDebug("Overriding UTIL_GetLocalPlayer");
DHookSetReturn(hReturn, pPlayer.GetEntIndex());
return MRES_Supercede;
}
return MRES_Ignored;
}

Returning "MRES_Ignored" makes the original function crash nearby accessing of gpGlobals->maxClients.
Superceding with DHookSetReturn(hReturn, -1); return MRES_Supercede; instead does not crash.

@Alienmario
Copy link
Collaborator Author

Alienmario commented Oct 25, 2024

Minimal example test case:

lp_test.games.txt

"Games"
{
	"bms"
	{
		"Functions"
		{
			"UTIL_GetLocalPlayer"
			{
				"signature"	"UTIL_GetLocalPlayer"
				"callconv"	"cdecl"
				"return"	"cbaseentity"
			}
		}
		"Signatures"
		{
			"UTIL_GetLocalPlayer" // CBasePlayer UTIL_GetLocalPlayer(void)
			{
				"windows"	"\xA1\x2A\x2A\x2A\x2A\x8B\x40\x14\x83\xF8\x01\x7E\x2A\xA1\x2A\x2A\x2A\x2A"
				"linux" 	"@_Z19UTIL_GetLocalPlayerv"
			}
		}
	}
}

lp_test.sp

#include <sourcemod>
#include <dhooks>

#pragma newdecls required
#pragma semicolon 1

#define GAMEDATA_NAME "lp_test.games"
DynamicDetour hkUTIL_GetLocalPlayer;

public void OnPluginStart()
{
	GameData pGameConfig = LoadGameConfigFile(GAMEDATA_NAME);
	if (pGameConfig == null)
		SetFailState("Couldn't load game config: \"%s\"", GAMEDATA_NAME);
	
	hkUTIL_GetLocalPlayer = DynamicDetour.FromConf(pGameConfig, "UTIL_GetLocalPlayer");
	if (hkUTIL_GetLocalPlayer == null)
		SetFailState("Couldn't create hook");

	if (!hkUTIL_GetLocalPlayer.Enable(Hook_Pre, Hook_UTIL_GetLocalPlayer))
		SetFailState("Couldn't enable pre detour hook");

	pGameConfig.Close();
}

public MRESReturn Hook_UTIL_GetLocalPlayer(DHookReturn hReturn)
{
	PrintToServer("Hook_UTIL_GetLocalPlayer");
	return MRES_Ignored;
}

@Alienmario
Copy link
Collaborator Author

While sm devs are looking into the issue, we can target 1.12 7163, which has all the features minus the updated hooking library.

@Alienmario Alienmario requested a review from ampreeT October 28, 2024 14:12
@ampreeT
Copy link
Owner

ampreeT commented Oct 28, 2024

While sm devs are looking into the issue, we can target 1.12 7163, which has all the features minus the updated hooking library.

We'll need to update the install scripts to install the specific version of SourceMod required rather than the latest version temporarily until the hooking library is fixed.

@ampreeT
Copy link
Owner

ampreeT commented Oct 28, 2024

Looks good to me!

@Alienmario
Copy link
Collaborator Author

While sm devs are looking into the issue, we can target 1.12 7163, which has all the features minus the updated hooking library.

We'll need to update the install scripts to install the specific version of SourceMod required rather than the latest version temporarily until the hooking library is fixed.

Alright then, when you're ready, please merge this and update the scripts. Hardcoding the links should be fine.

@ampreeT ampreeT merged commit 9bcc3f2 into master Oct 30, 2024
2 checks passed
@ampreeT ampreeT deleted the sm1.12 branch October 30, 2024 00:29
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