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

Warn if Metamod is detected. Auto disable it for cstrike. #508

Merged
merged 18 commits into from
Mar 16, 2024

Conversation

khanghugo
Copy link
Contributor

@khanghugo khanghugo commented Feb 21, 2024

Closes #501

"Warn" in here means exiting the game right away. I am not sure how to do it more elegantly.

@khanghugo
Copy link
Contributor Author

Hmmm, it doesn't work on Windows. I keep getting error.
image

String manipulation in C++ is fairly arcane for me.

@SmileyAG
Copy link
Collaborator

Hmmm, it doesn't work on Windows. I keep getting error.

String manipulation in C++ is fairly arcane for me.

Well, the crucial issue with this code is actually not how you did the string manipulation, but how you declared the functions

You can only use __fastcall if you declare a member functions for Windows (e.g. CBasePlayer::TakeDamage)
In all other majority of cases, __cdecl will be your choice

Also, when you use __fastcall, you will need to specify int edx as the second parameter
edx doesn't seem to be used, so you can return any value to it (e.g. 0) in case you need to call that function

Examples:

HOOK_DECL(void, __cdecl, PM_PreventMegaBunnyJumping) // Windows, Linux

typedef void(__fastcall *_CBasePlayer__GiveNamedItem)(void *thisptr, int edx, const char *pszName); // Windows
_CBasePlayer__GiveNamedItem ORIG_CBasePlayer__GiveNamedItem;
typedef void(__cdecl *_CBasePlayer__GiveNamedItem_Linux)(void *thisptr, const char *pszName); // Linux
_CBasePlayer__GiveNamedItem_Linux ORIG_CBasePlayer__GiveNamedItem_Linux;
#ifdef _WIN32
ORIG_CBasePlayer__GiveNamedItem(classPtr, 0, HwDLL::GetInstance().GetString(iszItem));
#else
ORIG_CBasePlayer__GiveNamedItem_Linux(classPtr, HwDLL::GetInstance().GetString(iszItem));
#endif

@SmileyAG
Copy link
Collaborator

I also made a pull request with the necessary changes to that branch: khanghugo#4

@khanghugo
Copy link
Contributor Author

Thanks. Looking good.

BunnymodXT/helper_functions.cpp Outdated Show resolved Hide resolved
BunnymodXT/modules/HwDLL.cpp Outdated Show resolved Hide resolved
BunnymodXT/modules/HwDLL.cpp Outdated Show resolved Hide resolved
BunnymodXT/helper_functions.cpp Outdated Show resolved Hide resolved
BunnymodXT/helper_functions.cpp Outdated Show resolved Hide resolved
BunnymodXT/helper_functions.cpp Outdated Show resolved Hide resolved
@khanghugo
Copy link
Contributor Author

Eh, I wouldn't know really. @SmileyAG can explain that.

@SmileyAG
Copy link
Collaborator

Made appropriate changes from reviews.

And I handled most of edge cases for that request, but let know if I missed something more, he-he.

BunnymodXT/helper_functions.cpp Outdated Show resolved Hide resolved
BunnymodXT/helper_functions.cpp Show resolved Hide resolved
BunnymodXT/helper_functions.hpp Outdated Show resolved Hide resolved
BunnymodXT/stdafx.hpp Outdated Show resolved Hide resolved
…on and .c_str() wouldn't be a dangling pointer at that point

I didn't immediately release that the result was a dangling pointer, the life of which ended at the end of the condition

Of course, since we didn't allocate memory to it, after the original function is called it will still be freed, but it seems that the engine no longer uses this pointer too, and therefore we don't seem to need to store it.... So even if then it will be dangling, then specifically with this function it should not cause some issues after its call
Copy link
Owner

@YaLTeR YaLTeR left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to be sure @khanghugo could you test this still works on Linux?

@khanghugo
Copy link
Contributor Author

Works for me.

@YaLTeR YaLTeR merged commit 76aefb2 into YaLTeR:master Mar 16, 2024
7 checks passed
@YaLTeR
Copy link
Owner

YaLTeR commented Mar 16, 2024

Thanks

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.

Give an error and close the game if metamod is enabled
3 participants