Skip to content
This repository has been archived by the owner on Oct 25, 2023. It is now read-only.

Commit

Permalink
武器崩溃问题
Browse files Browse the repository at this point in the history
  • Loading branch information
huoji120 committed Oct 7, 2023
1 parent d787a7d commit 037969a
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 41 deletions.
40 changes: 40 additions & 0 deletions csgo2/hooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,39 @@ OnClientDisconnect_t original_OnClientDisconnect = NULL;
Host_Say_t original_Host_Say = NULL;
StartupServer_t origin_StartServer = NULL;
GameFrame_t origin_GameFrame = NULL;
CCSWeaponBase_Spawn_t origin_CCSWeaponBase_Spawn = NULL;

void __fastcall hook_CCSWeaponBase_Spawn(CBaseEntity* pThis, void* a2) {
const char* pszClassName = pThis->m_pEntity()->m_designerName;
LOG("Weapon spawn: %s\n", pszClassName);

origin_CCSWeaponBase_Spawn(pThis, a2);

do {
auto pWeapon = reinterpret_cast<CCSWeaponBase*>(pThis);
// Weapon could be already initialized with the correct data from
// GiveNamedItem, in that case we don't need to do anything
if (!pWeapon ||
pWeapon->m_AttributeManager()->m_Item()->m_bInitialized()) {
break;
}
if (GameWeapons::WeaponMap.find(pszClassName) ==
GameWeapons::WeaponMap.end()) {
break;
}
const auto [fullWeaponName, weaponiItemDefIndex] =
GameWeapons::WeaponMap.at(pszClassName);

LOG("Fixing a %s with index = %d and initialized = %d\n", pszClassName,
pWeapon->m_AttributeManager()->m_Item()->m_iItemDefinitionIndex(),
pWeapon->m_AttributeManager()->m_Item()->m_bInitialized());

pWeapon->m_AttributeManager()->m_Item()->m_bInitialized(true);
pWeapon->m_AttributeManager()->m_Item()->m_iItemDefinitionIndex(
weaponiItemDefIndex);
} while (false);
}

void __fastcall hook_GameFrame(void* rcx, bool simulating, bool bFirstTick,
bool bLastTick) {
/**
Expand Down Expand Up @@ -180,6 +213,13 @@ auto initMinHook() -> bool {
LOG("MH_CreateHook original_Host_Say\n");
break;
}
if (MH_CreateHook((LPVOID)Offset::FnCCSWeaponBase_Spawn,
&hook_CCSWeaponBase_Spawn,
reinterpret_cast<LPVOID*>(
&origin_CCSWeaponBase_Spawn)) != MH_OK) {
LOG("MH_CreateHook origin_CCSWeaponBase_Spawn\n");
break;
}
// 启用钩子
if (MH_EnableHook(MH_ALL_HOOKS) != MH_OK) {
LOG("MH_EnableHook \n");
Expand Down
13 changes: 11 additions & 2 deletions csgo2/native_sdk.h
Original file line number Diff line number Diff line change
Expand Up @@ -205,14 +205,16 @@ class CUtlVector_NativeSdk {
};

class CBaseEntity;


class CEntityIdentity {
public:
CBaseEntity* entity; // 0
void* dunno; // 8
int64_t unk0; // 12
int64_t unk1; // 16
const char* internalName;
const char* entityName;
const char* m_name;
const char* m_designerName;
void* unk2;
void* unk3;
void* unk4;
Expand Down Expand Up @@ -407,6 +409,8 @@ class CEconItemView {
auto GetStaticData() {
return CALL_VIRTUAL(CEconItemDefinition*, 13, this);
}
SCHEMA_FIELD(uint16_t, m_iItemDefinitionIndex)
SCHEMA_FIELD(bool, m_bInitialized)
};
class CAttributeContainer {
public:
Expand All @@ -421,6 +425,11 @@ class CEconEntity {
PSCHEMA_FIELD(CAttributeContainer, m_AttributeManager);
};

class CCSWeaponBase : public CEconEntity
{
public:
DECLARE_CLASS(CCSWeaponBase)
};
class CBasePlayerWeapon : public CEconEntity {
public:
DECLARE_CLASS(CBasePlayerWeapon);
Expand Down
6 changes: 5 additions & 1 deletion csgo2/offset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ EntityRemove_t FnEntityRemove;
UTIL_SayTextFilter_t FnUTIL_SayTextFilter;
UTIL_ClientPrintAll_t FnUTIL_ClientPrintAll;
ClientPrint_t FnClientPrint;
CCSWeaponBase_Spawn_t FnCCSWeaponBase_Spawn;
// CreateGameRuleInterFace_t FnCreateCCSGameRulesInterFace;
bool InitOffsetSuccess = false;
namespace InterFaces {
Expand Down Expand Up @@ -79,6 +80,8 @@ auto Init() -> bool {
server.FindPattern(pattern_FnClientPrint).Get(FnClientPrint);

server.FindPattern(pattern_FnUTIL_SayTextFilter).Get(FnUTIL_SayTextFilter);
server.FindPattern(pattern_CCSWeaponBase_Spawn).Get(FnCCSWeaponBase_Spawn);

InterFaces::SchemaSystem = reinterpret_cast<CSchemaSystem*>(
schemasystem.FindInterface("SchemaSystem_001").Get());
// InterFaces::GameEventManager = reinterpret_cast<IGameEventManager2*>(
Expand Down Expand Up @@ -124,6 +127,7 @@ auto Init() -> bool {
LOG("[huoji]FnGiveNamedItem : %llx \n", FnGiveNamedItem);
LOG("[huoji]FnClientPrint : %llx \n", FnClientPrint);
LOG("[huoji]FnUTIL_ClientPrintAll : %llx \n", FnUTIL_ClientPrintAll);
LOG("[huoji]FnCCSWeaponBase_Spawn : %llx \n", FnCCSWeaponBase_Spawn);

LOG("[huoji]MaxGlobals : %d \n", global::MaxPlayers);

Expand All @@ -150,7 +154,7 @@ auto Init() -> bool {
0, NULL);
// LOG("FnServerHashFunction: %llx \n", FnServerHashFunction("here",
// sizeof("here") - 1, 0x31415926));
return FnEntityRemove && FnRespawnPlayer && FnGiveNamedItem &&
return FnCCSWeaponBase_Spawn && FnEntityRemove && FnRespawnPlayer && FnGiveNamedItem &&
FnServerHashFunction && Host_SayPtr && InterFaces::IVEngineServer &&
InterFaces::GameResourceServiceServer &&
InterFaces::IServerGameClient && InterFaces::GameEventManager &&
Expand Down
4 changes: 4 additions & 0 deletions csgo2/offset.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class CEntityInstance;
class CCSPlayerPawn;
class CGameEntitySystem;
class CCSPlayerController;
class CBaseEntity;
typedef uint64_t(__fastcall* HashFunction_t)(const char*, unsigned int,
unsigned int);
typedef void(__fastcall* StateChanged_t)(void* networkTransmitComponent,
Expand All @@ -24,6 +25,7 @@ typedef void*(__fastcall* UTIL_SayTextFilter_t)(IRecipientFilter&, const char*,
CCSPlayerController*, uint64_t);
typedef void(__fastcall* UTIL_ClientPrintAll_t)(int msg_dest, const char* msg_name, const char* param1, const char* param2, const char* param3, const char* param4);
typedef void(__fastcall* ClientPrint_t)(CCSPlayerController* player, int msg_dest, const char* msg_name, const char* param1, const char* param2, const char* param3, const char* param4);
typedef void(__fastcall* CCSWeaponBase_Spawn_t)(CBaseEntity*, void*);

class CSchemaSystem;
class CGameResourceService;
Expand Down Expand Up @@ -91,6 +93,7 @@ static const auto pattern_UTIL_ClientPrintAll = THE_GAME_SIG(
"48 89 5C 24 08 48 89 6C 24 10 48 89 74 24 18 57 48 81 EC 70 01 ?? ?? 8B E9");
static const auto pattern_FnClientPrint = THE_GAME_SIG(
"48 85 C9 0F 84 ?? ?? ?? ?? 48 8B C4 48 89 58 18");
static const auto pattern_CCSWeaponBase_Spawn = THE_GAME_SIG("48 89 5C 24 08 48 89 6C 24 18 48 89 74 24 20 57 48 83 EC 30 48 8B DA 48 8B E9 E8 ?? ?? ?? ??");
extern uint64_t GameResourceServicePtr;
extern uint64_t FireEventServerSidePtr;
extern uint64_t Module_tier0;
Expand All @@ -105,6 +108,7 @@ extern EntityRemove_t FnEntityRemove;
extern UTIL_SayTextFilter_t FnUTIL_SayTextFilter;
extern UTIL_ClientPrintAll_t FnUTIL_ClientPrintAll;
extern ClientPrint_t FnClientPrint;
extern CCSWeaponBase_Spawn_t FnCCSWeaponBase_Spawn;
extern bool InitOffsetSuccess;
auto Init() -> bool;
}; // namespace Offset
75 changes: 37 additions & 38 deletions csgo2/weapon.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,44 +5,43 @@ namespace GameWeapons {

static const std::unordered_map<std::string, std::pair<std::string, int>>
WeaponMap = {
{"bizon", {"weapon_bizon", 1400}},
{"mac10", {"weapon_mac10", 1400}},
{"mp7", {"weapon_mp7", 1700}},
{"mp9", {"weapon_mp9", 1250}},
{"p90", {"weapon_p90", 2350}},
{"ump45", {"weapon_ump45", 1700}},
{"ak47", {"weapon_ak47", 2500}},
{"aug", {"weapon_aug", 3500}},
{"famas", {"weapon_famas", 2250}},
{"galilar", {"weapon_galilar", 2000}},
{"m4a4", {"weapon_m4a4", 3100}},
{"m4a1_silencer", {"weapon_m4a1_silencer", 3100}},
{"m4a1", {"weapon_m4a1_silencer", 3100}},
{"a1", {"weapon_m4a1_silencer", 3100}},
{"sg556", {"weapon_sg556", 3500}},
{"awp", {"weapon_awp", 4750}},
{"g3sg1", {"weapon_g3sg1", 5000}},
{"scar20", {"weapon_scar20", 5000}},
{"ssg08", {"weapon_ssg08", 2500}},
{"mag7", {"weapon_mag7", 2000}},
{"nova", {"weapon_nova", 1500}},
{"sawedoff", {"weapon_sawedoff", 1500}},
{"xm1014", {"weapon_xm1014", 3000}},
{"m249", {"weapon_m249", 5750}},
{"negev", {"weapon_negev", 5750}},
{"deagle", {"weapon_deagle", 700}},
{"elite", {"weapon_elite", 800}},
{"fiveseven", {"weapon_fiveseven", 500}},
{"glock", {"weapon_glock", 200}},
{"hkp2000", {"weapon_hkp2000", 200}},
{"p250", {"weapon_p250", 300}},
{"tec9", {"weapon_tec9", 500}},
{"usp_silencer", {"weapon_usp_silencer", 200}},
{"cz75a", {"weapon_cz75a", 500}},
{"revolver", {"weapon_revolver", 600}},
{"kevlar", {"item_kevlar", 600}},
{"he", {"weapon_hegrenade", 300}},
{"molotov", {"weapon_hegrenade", 850}},
{"bizon", {"weapon_bizon", 26}},
{"mac10", {"weapon_mac10", 27}},
{"mp7", {"weapon_mp7", 23}},
{"mp9", {"weapon_mp9", 34}},
{"p90", {"weapon_p90", 19}},
{"ump45", {"weapon_ump45", 24}},
{"ak47", {"weapon_ak47", 7}},
{"aug", {"weapon_aug", 8}},
{"famas", {"weapon_famas", 10}},
{"galilar", {"weapon_galilar", 13}},
{"m4a4", {"weapon_m4a1", 16}},
{"m4a1", {"weapon_m4a1_silencer", 60}},
{"sg556", {"weapon_sg556", 39}},
{"awp", {"weapon_awp", 9}},
{"g3sg1", {"weapon_g3sg1", 11}},
{"scar20", {"weapon_scar20", 38}},
{"ssg08", {"weapon_ssg08", 40}},
{"mag7", {"weapon_mag7", 29}},
{"nova", {"weapon_nova", 35}},
{"sawedoff", {"weapon_sawedoff", 29}},
{"xm1014", {"weapon_xm1014", 25}},
{"m249", {"weapon_m249", 14}},
{"negev", {"weapon_negev", 28}},
{"deagle", {"weapon_deagle", 1}},
{"elite", {"weapon_elite", 2}},
{"fiveseven", {"weapon_fiveseven", 3}},
{"glock", {"weapon_glock", 4}},
{"hkp2000", {"weapon_hkp2000", 32}},
{"p250", {"weapon_p250", 36}},
{"tec9", {"weapon_tec9", 30}},
{"usp_silencer", {"weapon_usp_silencer", 61}},
{"cz75a", {"weapon_cz75a", 63}},
{"revolver", {"weapon_revolver", 64}},
{"he", {"weapon_hegrenade", 44}},
{"molotov", {"weapon_molotov", 46}},
{"knife", {"weapon_knife", 42}}, // default CT knife
{"kevlar", {"item_kevlar", 50}},
};
auto ParseWeaponCommand(CCSPlayerController* pController,
std::string pszWeaponName) -> bool;
Expand Down

0 comments on commit 037969a

Please sign in to comment.