Skip to content

Commit

Permalink
remove more head
Browse files Browse the repository at this point in the history
  • Loading branch information
Abc Dr committed Jan 8, 2024
1 parent 456dcc9 commit 2d41207
Show file tree
Hide file tree
Showing 15 changed files with 26 additions and 151 deletions.
5 changes: 0 additions & 5 deletions src/angelscript/angelscriptlib.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,6 @@
#ifndef ANGELSCRIPT_H
#define ANGELSCRIPT_H

#include <stddef.h>
#ifndef _MSC_VER
#include <stdint.h>
#endif

#ifdef AS_USE_NAMESPACE
#define BEGIN_AS_NAMESPACE namespace AngelScript {
#define END_AS_NAMESPACE }
Expand Down
3 changes: 2 additions & 1 deletion src/header/CASSQLGrid.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#pragma once
#include <vector>

#include "CASBaseObject.h"
#include "CASSQLItem.h"
#include <vector>

class CBinaryStringBuilder;
class CASSQLGrid : public CASBaseGCObject{
Expand Down
2 changes: 1 addition & 1 deletion src/header/CASSQLItem.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once
#include "CASBaseObject.h"
#include <string>
#include "CASBaseObject.h"

class CBinaryStringBuilder;
class CASSQLItem : public CASBaseGCObject{
Expand Down
3 changes: 2 additions & 1 deletion src/header/CASSQLite.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#pragma once
#include "CASBaseObject.h"
#include <string>

#include "CASBaseObject.h"

struct sqlite3;
typedef int (*fnSqlCallBack)(void*[], int, char**, char**);

Expand Down
2 changes: 0 additions & 2 deletions src/header/dlldef.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#pragma once
#include "progdefs.h"

typedef struct hookitem_s {
hook_t* pHook;
void* pfnCall;
Expand Down
2 changes: 0 additions & 2 deletions src/header/enginedef.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,9 @@ enum GRAPPLE_RESULT{
PULL_TO = 2
};
typedef GRAPPLE_RESULT(SC_SERVER_DECL* fnGrappleGetMonsterType)(void* pThis, SC_SERVER_DUMMYARG void* pEntity);
GRAPPLE_RESULT SC_SERVER_DECL NewGrappleGetMonsterType(void* pThis, SC_SERVER_DUMMYARG void* pEntity);
PRIVATE_FUNCTION_EXTERN(GrappleGetMonsterType);
// SendScoreInfo
typedef void(SC_SERVER_DECL *fnSendScoreInfo)(void* pThis, SC_SERVER_DUMMYARG edict_t* eSendTarget, int iTeamID, char* szTeamName);
void SC_SERVER_DECL NewSendScoreInfo(void* pThis, SC_SERVER_DUMMYARG edict_t* eSendTarget, int iTeamID, char* szTeamName);
PRIVATE_FUNCTION_EXTERN(SendScoreInfo);
//
// SendScoreInfo
Expand Down
91 changes: 5 additions & 86 deletions src/header/signatures.h
Original file line number Diff line number Diff line change
@@ -1,93 +1,12 @@
#pragma once

#define IMPORT_FUNCTION_DEFINE(name) fn##name name;

#define IMPORT_FUNCTION_EXTERN(name) extern fn##name name;

#define PRIVATE_FUNCTION_DEFINE(name) fn##name g_pfn_##name; fn##name g_call_original_##name;

#define PRIVATE_FUNCTION_EXTERN(name) extern fn##name g_pfn_##name; extern fn##name g_call_original_##name;
#include "signatures_template.h"

#ifdef _WIN32

#define LOCATE_FROM_SIGNATURE(dll, sig) gpMetaUtilFuncs->pfnSearchPattern(dll##Base, gpMetaUtilFuncs->pfnGetImageSize(dll##Base), sig, sizeof(sig) - 1)

#define SC_SERVER_DUMMYVAR int dummy = 0;
#define SERVER_DLL_NAME "server.dll"
#else

#ifndef _ARRAYSIZE
#define _ARRAYSIZE(A) (sizeof(A)/sizeof((A)[0]))
#endif

#define LOCATE_FROM_SIGNATURE(dll, sig) DLSYM(dll##Handle, sig)

#define ENGINE_DLL_NAME "hw.so"
#define SC_SERVER_DUMMYVAR
#define SERVER_DLL_NAME "server.so"

#endif

#define IMPORT_FUNCTION_DLSYM(dll, name) name = (decltype(name))DLSYM((DLHANDLE)dll##Handle, #name);\
if (!name)\
{\
LOG_ERROR(PLID, "Failed to get " #name " from " #dll " dll !");\
return FALSE;\
}

#define FILL_FROM_SIGNATURE(dll, name) g_pfn_##name = g_call_original_##name = (decltype(g_pfn_##name))LOCATE_FROM_SIGNATURE(dll, name##_Signature);\
if (!g_pfn_##name)\
{\
LOG_ERROR(PLID, "Failed to locate " #name " from " #dll " dll !");\
return FALSE;\
}

#define FILL_FROM_SIGNATURED_CALLER_FROM_START(dll, name, offset) auto Caller_of_##name = (char *)LOCATE_FROM_SIGNATURE(dll, name##_Signature);\
if (!Caller_of_##name)\
{\
LOG_ERROR(PLID, "Failed to locate Caller of " #name " from " #dll " dll !");\
return FALSE;\
}\
g_pfn_##name = g_call_original_##name = (decltype(g_pfn_##name))gpMetaUtilFuncs->pfnGetNextCallAddr(Caller_of_##name + (offset), 1);\
if (!gpMetaUtilFuncs->pfnIsAddressInModuleRange((void *)g_pfn_##name, dll##Base))\
{\
LOG_ERROR(PLID, "Failed to locate " #name " from " #dll " dll !"); \
return FALSE; \
}

#define FILL_FROM_SIGNATURED_CALLER_FROM_END(dll, name, offset) auto Caller_of_##name = (char *)LOCATE_FROM_SIGNATURE(dll, name##_Signature);\
if (!Caller_of_##name)\
{\
LOG_ERROR(PLID, "Failed to locate Caller of " #name " from " #dll " dll !");\
return FALSE;\
}\
g_pfn_##name = g_call_original_##name = (decltype(g_pfn_##name))gpMetaUtilFuncs->pfnGetNextCallAddr(Caller_of_##name + (sizeof(name##_Signature) - 1) + (offset), 1);\
if (!gpMetaUtilFuncs->pfnIsAddressInModuleRange((void *)g_pfn_##name, dll##Base))\
{\
LOG_ERROR(PLID, "Failed to locate " #name " from " #dll " dll !"); \
return FALSE; \
}

#define VAR_FROM_SIGNATURE(dll, name) name = (decltype(name))LOCATE_FROM_SIGNATURE(dll, name##_Signature);\
if (!name)\
{\
LOG_ERROR(PLID, "Failed to locate " #name " from " #dll " dll !");\
return FALSE;\
}

#define VAR_FROM_SIGNATURE_FROM_START(dll, name, offset) auto name##_Temp = (char *)LOCATE_FROM_SIGNATURE(dll, name##_Signature);\
if (!name##_Temp)\
{\
LOG_ERROR(PLID, "Failed to locate " #name " from " #dll " dll !");\
return FALSE;\
}\
name = *(decltype(name) *)(name##_Temp + offset);

#define VAR_FROM_SIGNATURE_FROM_END(dll, name, offset) auto name##_Temp = (char *)LOCATE_FROM_SIGNATURE(dll, name##_Signature);\
if (!name##_Temp)\
{\
LOG_ERROR(PLID, "Failed to locate " #name " from " #dll " dll !");\
return FALSE;\
}\
name = *(decltype(name) *)(name##_Temp + (sizeof(name##_Signature) - 1) + offset);

#define INSTALL_INLINEHOOK(name) g_phook_##name = gpMetaUtilFuncs->pfnInlineHook((void*)g_pfn_##name, (void*)New##name, (void**)&g_call_original_##name, true)
#define UNINSTALL_HOOK(name) if(g_phook_##name) {gpMetaUtilFuncs->pfnUnHook(g_phook_##name); g_phook_##name = NULL;}

#define FILL_AND_HOOK(dll, name) FILL_FROM_SIGNATURE(dll, name);INSTALL_INLINEHOOK(name)
2 changes: 1 addition & 1 deletion src/header/utility.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#define GetEntVarsVTable(var)var==nullptr?nullptr:ENT(var)->pvPrivateData
#define OFFSET_ENTVAR 4

inline edict_t* PrivateToEdict(void* PrivateData){
constexpr edict_t* PrivateToEdict(void* PrivateData){
if (PrivateData == nullptr)
return nullptr;
return (*((entvars_t**)((char*)PrivateData + OFFSET_ENTVAR)))->pContainingEntity;
Expand Down
24 changes: 0 additions & 24 deletions src/header/vftable.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,30 +25,6 @@ typedef struct Task_s {

}Task_t;

#ifdef _WIN32

#define SC_SERVER_DECL __fastcall
#define SC_SERVER_DUMMYARG_NOCOMMA , int dummy
#define SC_SERVER_DUMMYARG int dummy,
#define SC_SERVER_PASS_DUMMYARG dummy,
#define SC_SERVER_PASS_DUMMYARG2 ,dummy
#define SC_SERVER_PASS_DUMMYARG_NOCOMMA dummy
#define SC_SERVER_DUMMYVAR int dummy = 0;
#define SERVER_DLL_NAME "server.dll"

#else

#define SC_SERVER_DECL
#define SC_SERVER_DUMMYARG_NOCOMMA
#define SC_SERVER_DUMMYARG
#define SC_SERVER_PASS_DUMMYARG
#define SC_SERVER_PASS_DUMMYARG2
#define SC_SERVER_PASS_DUMMYARG_NOCOMMA
#define SC_SERVER_DUMMYVAR
#define SERVER_DLL_NAME "server.so"

#endif

//101
typedef struct vtable_base_s {
void (SC_SERVER_DECL* PreSpawn)(void* pThis SC_SERVER_DUMMYARG_NOCOMMA) = nullptr;
Expand Down
6 changes: 3 additions & 3 deletions src/source/CASBinaryStringBuilder.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#include <extdll.h>
#include <string>
#include <bit>

#include <extdll.h>
#include "angelscript.h"

#include <meta_api.h>
#include <string>
#include <bit>
#include "CASBinaryStringBuilder.h"

CBinaryStringBuilder::CBinaryStringBuilder(){
Expand Down
3 changes: 2 additions & 1 deletion src/source/CASSQLite.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <filesystem>

#include <extdll.h>
#include <meta_api.h>
#include <filesystem>

#include "CASBinaryStringBuilder.h"
#include "CASSQLItem.h"
Expand Down
7 changes: 1 addition & 6 deletions src/source/dllapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,10 @@
*
*/

#include <extdll.h>

#include <vector>

#include <dllapi.h>
#include <extdll.h>
#include <meta_api.h>
#include <log_meta.h>

#include "signatures.h"
#include "asext_api.h"
#include "angelscript.h"
#include "vftable.h"
Expand Down
11 changes: 4 additions & 7 deletions src/source/engine_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,15 @@
* version.
*
*/

#include <extdll.h>

#include <meta_api.h>
#include <vector>
#include "signatures.h"

#include "asext_api.h"
#include "enginedef.h"
#include "signatures.h"
#include "angelscript.h"
#include "utility.h"
#include "vftable.h"
#include "dlldef.h"

#include "enginedef.h"

int SV_ModelIndex(const char* m) {
if (CVAR_GET_FLOAT("sv_fixgmr") > 0) {
Expand Down
10 changes: 3 additions & 7 deletions src/source/meta_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,16 @@
*/

#include <extdll.h> // always
#include <meta_api.h> // of course

#include "signatures.h"
#include "angelscript.h"
#include "asext_api.h"

#include <meta_api.h> // of course

#include "enginedef.h"
#include "vftable.h"
#include "dlldef.h"

#include "sdk_util.h" // UTIL_LogPrintf, etc


mBOOL dlclose_handle_invalid;

IMPORT_ASEXT_API_DEFINE();
Expand All @@ -75,8 +71,8 @@ static META_FUNCTIONS gMetaFunctionTable = {
plugin_info_t Plugin_info = {
META_INTERFACE_VERSION, // ifvers
"AngelScriptHookExt", // name
"Alpha8", // version
"2023", // date
"Alpha9", // version
"2024", // date
"Dr.Abc", // author
"https://github.com/DrAbcOfficial/asexthook", // url
"ASHEXT", // logtag, all caps please
Expand Down
6 changes: 2 additions & 4 deletions src/source/vftable.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
#include <extdll.h>
#include <map>

#include <extdll.h>
#include <meta_api.h>
#include <enginecallback.h>
#include <map>
#include "edict.h"
#include "asext_api.h"
#include "vftable.h"

Expand Down

0 comments on commit 2d41207

Please sign in to comment.