Refactor gamerules address retrieval
This commit is contained in:
		@@ -19,13 +19,13 @@ IGameConfig *GamerulesConfig;
 | 
				
			|||||||
IGameConfigManager *ConfigManager;
 | 
					IGameConfigManager *ConfigManager;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
HLTypeConversion TypeConversion;
 | 
					HLTypeConversion TypeConversion;
 | 
				
			||||||
void *GameRulesReferenceAddress;
 | 
					void **GameRulesAddress;
 | 
				
			||||||
void *GameRulesAddress;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
void OnAmxxAttach()
 | 
					void OnAmxxAttach()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	initialze_offsets();
 | 
						initialze_offsets();
 | 
				
			||||||
	initialize_glb_offsets();
 | 
						initialize_glb_offsets();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	MF_AddNatives(engfunc_natives);
 | 
						MF_AddNatives(engfunc_natives);
 | 
				
			||||||
	MF_AddNatives(dllfunc_natives);
 | 
						MF_AddNatives(dllfunc_natives);
 | 
				
			||||||
	MF_AddNatives(pev_natives);
 | 
						MF_AddNatives(pev_natives);
 | 
				
			||||||
@@ -35,6 +35,9 @@ void OnAmxxAttach()
 | 
				
			|||||||
	MF_AddNatives(glb_natives);
 | 
						MF_AddNatives(glb_natives);
 | 
				
			||||||
	MF_AddNatives(ext2_natives);
 | 
						MF_AddNatives(ext2_natives);
 | 
				
			||||||
	MF_AddNatives(misc_natives);
 | 
						MF_AddNatives(misc_natives);
 | 
				
			||||||
 | 
						MF_AddNatives(pdata_entities_natives);
 | 
				
			||||||
 | 
						MF_AddNatives(pdata_gamerules_natives);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	g_kvd_glb.kvd.szClassName = const_cast<char *>(g_kvd_glb.cls.chars());
 | 
						g_kvd_glb.kvd.szClassName = const_cast<char *>(g_kvd_glb.cls.chars());
 | 
				
			||||||
	g_kvd_glb.kvd.szKeyName = const_cast<char *>(g_kvd_glb.key.chars());
 | 
						g_kvd_glb.kvd.szKeyName = const_cast<char *>(g_kvd_glb.key.chars());
 | 
				
			||||||
	g_kvd_glb.kvd.szValue = const_cast<char *>(g_kvd_glb.val.chars());
 | 
						g_kvd_glb.kvd.szValue = const_cast<char *>(g_kvd_glb.val.chars());
 | 
				
			||||||
@@ -58,14 +61,19 @@ void OnAmxxAttach()
 | 
				
			|||||||
		return;
 | 
							return;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (!CommonConfig->GetAddress("g_pGameRules", &GameRulesReferenceAddress) || !GameRulesReferenceAddress)
 | 
						void *address = nullptr;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (!CommonConfig->GetAddress("g_pGameRules", &address) || !address)
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		MF_Log("get/set_gamerules_* natives have been disabled because g_pGameRules address could not be found. ");
 | 
							MF_Log("get/set_gamerules_* natives have been disabled because g_pGameRules address could not be found. ");
 | 
				
			||||||
		return;
 | 
							return;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	MF_AddNatives(pdata_entities_natives);
 | 
					#if defined(KE_WINDOWS)
 | 
				
			||||||
	MF_AddNatives(pdata_gamerules_natives);
 | 
						GameRulesAddress = *reinterpret_cast<void***>(address);
 | 
				
			||||||
 | 
					#else
 | 
				
			||||||
 | 
						GameRulesAddress = reinterpret_cast<void**>(address);
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void OnPluginsLoaded()
 | 
					void OnPluginsLoaded()
 | 
				
			||||||
@@ -97,11 +105,6 @@ void OnAmxxDetach()
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
void ServerActivate(edict_t *pEdictList, int edictCount, int clientMax)
 | 
					void ServerActivate(edict_t *pEdictList, int edictCount, int clientMax)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	if (GameRulesReferenceAddress)
 | 
					 | 
				
			||||||
	{
 | 
					 | 
				
			||||||
		GameRulesAddress = **reinterpret_cast<void***>(GameRulesReferenceAddress);
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	g_pFunctionTable_Post->pfnServerDeactivate = FMH_ServerDeactivate_Post;
 | 
						g_pFunctionTable_Post->pfnServerDeactivate = FMH_ServerDeactivate_Post;
 | 
				
			||||||
	RETURN_META(MRES_IGNORED);
 | 
						RETURN_META(MRES_IGNORED);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -80,7 +80,7 @@ extern IGameConfig *GamerulesConfig;
 | 
				
			|||||||
extern IGameConfigManager *ConfigManager;
 | 
					extern IGameConfigManager *ConfigManager;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
extern HLTypeConversion TypeConversion;
 | 
					extern HLTypeConversion TypeConversion;
 | 
				
			||||||
extern void *GameRulesAddress;
 | 
					extern void **GameRulesAddress;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#endif //_FAKEMETA_INCLUDE_H
 | 
					#endif //_FAKEMETA_INCLUDE_H
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -25,7 +25,7 @@ static cell AMX_NATIVE_CALL get_gamerules_int(AMX *amx, cell *params)
 | 
				
			|||||||
	int element = params[3];
 | 
						int element = params[3];
 | 
				
			||||||
	CHECK_DATA(data, element, BaseFieldType::Integer);
 | 
						CHECK_DATA(data, element, BaseFieldType::Integer);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return PvData::GetInt(GameRulesAddress, data, element);
 | 
						return PvData::GetInt(*GameRulesAddress, data, element);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// native set_gamerules_int(const class[], const member[], any:value, element = 0);
 | 
					// native set_gamerules_int(const class[], const member[], any:value, element = 0);
 | 
				
			||||||
@@ -45,7 +45,7 @@ static cell AMX_NATIVE_CALL set_gamerules_int(AMX *amx, cell *params)
 | 
				
			|||||||
		return 0;
 | 
							return 0;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	PvData::SetInt(GameRulesAddress, data, params[3], element);
 | 
						PvData::SetInt(*GameRulesAddress, data, params[3], element);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return 0;
 | 
						return 0;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -62,7 +62,7 @@ static cell AMX_NATIVE_CALL get_gamerules_float(AMX *amx, cell *params)
 | 
				
			|||||||
	int element = params[3];
 | 
						int element = params[3];
 | 
				
			||||||
	CHECK_DATA(data, element, BaseFieldType::Float);
 | 
						CHECK_DATA(data, element, BaseFieldType::Float);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return PvData::GetFloat(GameRulesAddress, data, element);
 | 
						return PvData::GetFloat(*GameRulesAddress, data, element);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// native set_gamerules_float(const class[], const member[], Float:value, element = 0);
 | 
					// native set_gamerules_float(const class[], const member[], Float:value, element = 0);
 | 
				
			||||||
@@ -76,7 +76,7 @@ static cell AMX_NATIVE_CALL set_gamerules_float(AMX *amx, cell *params)
 | 
				
			|||||||
	int element = params[4];
 | 
						int element = params[4];
 | 
				
			||||||
	CHECK_DATA(data, element, BaseFieldType::Float);
 | 
						CHECK_DATA(data, element, BaseFieldType::Float);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	PvData::SetFloat(GameRulesAddress, data, amx_ctof(params[3]), element);
 | 
						PvData::SetFloat(*GameRulesAddress, data, amx_ctof(params[3]), element);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return 1;
 | 
						return 1;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -93,7 +93,7 @@ static cell AMX_NATIVE_CALL get_gamerules_vector(AMX *amx, cell *params)
 | 
				
			|||||||
	int element = params[4];
 | 
						int element = params[4];
 | 
				
			||||||
	CHECK_DATA(data, element, BaseFieldType::Vector);
 | 
						CHECK_DATA(data, element, BaseFieldType::Vector);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	PvData::GetVector(GameRulesAddress, data, MF_GetAmxAddr(amx, params[3]), element);
 | 
						PvData::GetVector(*GameRulesAddress, data, MF_GetAmxAddr(amx, params[3]), element);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return 1;
 | 
						return 1;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -109,7 +109,7 @@ static cell AMX_NATIVE_CALL set_gamerules_vector(AMX *amx, cell *params)
 | 
				
			|||||||
	int element = params[4];
 | 
						int element = params[4];
 | 
				
			||||||
	CHECK_DATA(data, element, BaseFieldType::Vector);
 | 
						CHECK_DATA(data, element, BaseFieldType::Vector);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	PvData::GetVector(GameRulesAddress, data, MF_GetAmxAddr(amx, params[3]), element);
 | 
						PvData::GetVector(*GameRulesAddress, data, MF_GetAmxAddr(amx, params[3]), element);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return 1;
 | 
						return 1;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -126,7 +126,7 @@ static cell AMX_NATIVE_CALL get_gamerules_entity(AMX *amx, cell *params)
 | 
				
			|||||||
	int element = params[3];
 | 
						int element = params[3];
 | 
				
			||||||
	CHECK_DATA(data, element, BaseFieldType::Entity);
 | 
						CHECK_DATA(data, element, BaseFieldType::Entity);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return PvData::GetEntity(GameRulesAddress, data, element);
 | 
						return PvData::GetEntity(*GameRulesAddress, data, element);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// native set_gamerules_entity(const class[], const member[], value, element = 0);
 | 
					// native set_gamerules_entity(const class[], const member[], value, element = 0);
 | 
				
			||||||
@@ -147,7 +147,7 @@ static cell AMX_NATIVE_CALL set_gamerules_entity(AMX *amx, cell *params)
 | 
				
			|||||||
	int element = params[4];
 | 
						int element = params[4];
 | 
				
			||||||
	CHECK_DATA(data, element, BaseFieldType::Entity);
 | 
						CHECK_DATA(data, element, BaseFieldType::Entity);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	PvData::SetEntity(GameRulesAddress, data, params[3], element);
 | 
						PvData::SetEntity(*GameRulesAddress, data, params[3], element);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return 0;
 | 
						return 0;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -167,7 +167,7 @@ static cell AMX_NATIVE_CALL get_gamerules_string(AMX *amx, cell *params)
 | 
				
			|||||||
	auto buffer = params[3];
 | 
						auto buffer = params[3];
 | 
				
			||||||
	auto maxlen = params[4];
 | 
						auto maxlen = params[4];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	auto string = PvData::GetString(GameRulesAddress, data, element);
 | 
						auto string = PvData::GetString(*GameRulesAddress, data, element);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (data.fieldSize)
 | 
						if (data.fieldSize)
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
@@ -191,7 +191,7 @@ static cell AMX_NATIVE_CALL set_gamerules_string(AMX *amx, cell *params)
 | 
				
			|||||||
	int length;
 | 
						int length;
 | 
				
			||||||
	const char *value = MF_GetAmxString(amx, params[3], 0, &length);
 | 
						const char *value = MF_GetAmxString(amx, params[3], 0, &length);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return PvData::SetString(GameRulesAddress, data, value, length, element);
 | 
						return PvData::SetString(*GameRulesAddress, data, value, length, element);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user