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

InterfacePointers::Cvar() returns nothing in x86-64-support-sourcesdk #101

Open
Be1zebub opened this issue Jan 15, 2024 · 3 comments
Open
Assignees

Comments

@Be1zebub
Copy link

it works well on master, but it returns nullptr on x86-64-support-sourcesdk

reproduce:

#include <GarrysMod/Lua/Interface.h>
#include <GarrysMod/Interfaces.hpp>
#include <GarrysMod/InterfacePointers.hpp>
#include <icvar.h>

GMOD_MODULE_OPEN() {
    ICvar* icvar = InterfacePointers::Cvar();
    if (!icvar) {
        LUA->PushSpecial(GarrysMod::Lua::SPECIAL_GLOB);
        LUA->GetField(-1, "print");
        LUA->PushString("Failed to get ICvar interface!");
        LUA->Call(1, 0);
    	LUA->Pop();
    }
    
    return 0;
}
@danielga danielga self-assigned this Jan 15, 2024
@magnalunar
Copy link
Contributor

magnalunar commented Jan 16, 2024

You need to make a little changes in the ResolveSymbol function:

template<class T>
static inline T *ResolveSymbol(
	SourceSDK::FactoryLoader &loader, const Symbol &symbol
)
{
	if( symbol.type == Symbol::Type::None )
		return nullptr;

#if defined SYSTEM_WINDOWS

	/*auto iface = reinterpret_cast<T **>( symbol_finder.Resolve(
		loader.GetModule( ), symbol.name.c_str( ), symbol.length
	) );
	return iface != nullptr ? *iface : nullptr;*/

	auto iface = reinterpret_cast<T *>( symbol_finder.Resolve(
		loader.GetModule( ), symbol.name.c_str( ), symbol.length
	) );
	return iface != nullptr ? iface : nullptr;

#elif defined SYSTEM_POSIX

	return reinterpret_cast<T *>( symbol_finder.Resolve(
		loader.GetModule( ), symbol.name.c_str( ), symbol.length
	) );

#endif

}

After this changes, the remaining interfaces will be dereferenced correctly for Windows platform.

By the way, the solution to your issue is found in the previous post.

@Be1zebub
Copy link
Author

hi, im using linux.
so its not a point.

@magnalunar
Copy link
Contributor

In that case, you should provide more information about your issue because everything works fine for me when cloning from x86-64-support-sourcesdk repository. Another way, your problem is no longer relevant.

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

3 participants