Merge pull request #12 from Sku-111/main

added custom weapdef loading
This commit is contained in:
MatrixMMOfficial 2023-11-01 15:12:18 -04:00 committed by GitHub
commit f09eb47926
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
20 changed files with 153 additions and 55 deletions

View File

@ -41,6 +41,7 @@ BOOL WINAPI DllMain(HMODULE hModule, DWORD Reason, LPVOID lpVoid)
FILE* Dummy;
freopen_s(&Dummy, "CONOUT$", "w", stdout);
freopen_s(&Dummy, "CONIN$", "r", stdin);
SetConsoleTitleA("Donetsk Client Console");
utils::nt::library game{};
utils::nt::library user32("user32.dll");

View File

@ -21,7 +21,6 @@
#include "ini.h"
#include "json.hpp"
#include "splashscreen.hpp"
#define base g_Addrs.ModuleBase

View File

@ -4077,7 +4077,7 @@ struct __declspec(align(8)) WeaponDef
struct WeaponCompleteDef
{
const char* szInternalName;
WeaponDef weapDef;
WeaponDef* weapDef;
const char* szDisplayName;
const char* szLootTable;
scr_string_t* hideTags;

View File

@ -538,6 +538,8 @@ cmd_function_s MapRestart_f_VAR;
cmd_function_s omnvar_set_f_VAR;
cmd_function_s omnvar_dump_f_VAR;
cmd_function_s unlockall_f_VAR;
cmd_function_s dump_weapdefs_f_VAR;
cmd_function_s load_weapdef_f_VAR;
CmdArgs* cmd_args;

View File

@ -132,6 +132,8 @@ extern cmd_function_s MapRestart_f_VAR;
extern cmd_function_s omnvar_set_f_VAR;
extern cmd_function_s omnvar_dump_f_VAR;
extern cmd_function_s unlockall_f_VAR;
extern cmd_function_s dump_weapdefs_f_VAR;
extern cmd_function_s load_weapdef_f_VAR;
extern CmdArgs* cmd_args;
void* RtlAddVectoredExceptionHandler(LONG First, PVECTORED_EXCEPTION_HANDLER Handler);

View File

@ -13,7 +13,7 @@ void addCustomCmds()
Cmd_AddCommandInternal("addbot", Cmd_AddBot_f, &addbot_f_VAR);
Cmd_AddCommandInternal("addtestclient", Cmd_AddTestClient_f, &addTestClient_f_VAR);
Cmd_AddCommandInternal("ddldump", Cmd_DDLDump_f, &ddldump_f_VAR);
Cmd_AddCommandInternal("weapondefdump", Cmd_WeaponDefDump_f, &weapondefdump_f_VAR);
// Cmd_AddCommandInternal("weapondefdump", Cmd_WeaponDefDump_f, &weapondefdump_f_VAR);
//Cmd_AddCommandInternal("view_vehicle_ents", Cmd_ViewVehicleEnts_f, &view_vehicle_ents_f_VAR);
// Cmd_AddCommandInternal("save_inventory", Cmd_LoadoutSave_f, &loadout_save_f_VAR);
Cmd_AddCommandInternal("map_restart", SV_CmdsMP_MapRestart_f, &MapRestart_f_VAR);
@ -21,6 +21,8 @@ void addCustomCmds()
Cmd_AddCommandInternal("setOmnvar", Cmd_Omnvar_Set_f, &omnvar_set_f_VAR);
// Cmd_AddCommandInternal("dumpomnvars", Cmd_Omnvars_Dump_f, &omnvar_dump_f_VAR);
Cmd_AddCommandInternal("unlockAll", Cmd_UnlockAll_f, &unlockall_f_VAR);
Cmd_AddCommandInternal("dumpweapondef", Cmd_WeaponDefDump_f, &dump_weapdefs_f_VAR);
Cmd_AddCommandInternal("loadweapondef", Cmd_WeaponDef_Load_f, &load_weapdef_f_VAR);
}
void G_CmdsMP_ClientCommand_Detour(int clientNum)
@ -429,20 +431,10 @@ void Cmd_DDLDump_f()
void Cmd_WeaponDefDump_f()
{
//Globals
uintptr_t* bg_weaponCompleteDefs = reinterpret_cast<uintptr_t*>(0x14C6EC870_g);
printf("DUMPING WEAPON DEFINITIONS!!! --- \n");
for (int i = 0; i < 550; i++) {
WeaponCompleteDef* weap = reinterpret_cast<WeaponCompleteDef*>(bg_weaponCompleteDefs[i]);
if (!weap) continue;
printf("szInternalName: %s\n", weap->szInternalName);
printf("szDisplayName: %s\n", weap->szDisplayName);
if (CheatsOk(0))
{
Dump_WeaponDef();
}
printf("FINISHED WEAPON DEFINITION DUMP YAY!!! --- \n");
}
void Cmd_ViewVehicleEnts_f()
@ -467,4 +459,12 @@ void Cmd_LoadoutSave_f()
void Cmd_UnlockAll_f()
{
Cbuf_AddText("seta unlockAllItems 1");
}
void Cmd_WeaponDef_Load_f()
{
if (CheatsOk(0))
{
Load_WeaponDef();
}
}

View File

@ -36,4 +36,6 @@ void Cmd_ViewVehicleEnts_f();
void Cmd_LoadoutSave_f();
void Cmd_UnlockAll_f();
void Cmd_UnlockAll_f();
void Cmd_WeaponDef_Load_f();

View File

@ -13,6 +13,7 @@
#include "stringed.h"
#include "fastfile.h"
#include "mp_init.h"
#include "party.h"
#include "ddl.h"
#include "gamemode.h"
#include "sv_main.h"

View File

@ -2,7 +2,17 @@
bool Com_GameMode_SupportsFeature_Detour(unsigned int featureID)
{
if (featureID == 70) // TIMESCALE_TWEAKING
static dvar_t* com_timescale;
static dvar_t* timescale;
if (com_timescale == nullptr && featureID == 70)
{
com_timescale = (dvar_t*)Dvar_FindVarByName("LNOTRKNRPS");
timescale = (dvar_t*)Dvar_FindVarByName("MSNTNLNQNM");
// fixes slowmotion final killcam, but not in an ideal way
}
if (featureID == 70 && timescale->current.value != 1.0) // TIMESCALE_TWEAKING
{
return true;
}

View File

@ -177,10 +177,10 @@
<ClCompile Include="net_chan.cpp" />
<ClCompile Include="omnvars.cpp" />
<ClCompile Include="mp_init.cpp" />
<ClCompile Include="party.cpp" />
<ClCompile Include="patch.cpp" />
<ClCompile Include="screen.cpp" />
<ClCompile Include="script.cpp" />
<ClCompile Include="splashscreen.cpp" />
<ClCompile Include="stringed.cpp" />
<ClCompile Include="structs.cpp" />
<ClCompile Include="sv_main.cpp" />
@ -223,6 +223,7 @@
<ClInclude Include="net_chan.h" />
<ClInclude Include="omnvars.h" />
<ClInclude Include="mp_init.h" />
<ClInclude Include="party.h" />
<ClInclude Include="patch.h" />
<ClInclude Include="screen.h" />
<ClInclude Include="script.h" />

View File

@ -70,9 +70,6 @@
<ClCompile Include="assets.cpp">
<Filter>hook_lib\game</Filter>
</ClCompile>
<ClCompile Include="splashscreen.cpp">
<Filter>hook_lib\game</Filter>
</ClCompile>
<ClCompile Include="cmd.cpp">
<Filter>hook_lib\game</Filter>
</ClCompile>
@ -136,6 +133,9 @@
<ClCompile Include="zones.cpp">
<Filter>hook_lib\game</Filter>
</ClCompile>
<ClCompile Include="party.cpp">
<Filter>hook_lib\game</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="common\utils\binary_resource.hpp">
@ -267,5 +267,8 @@
<ClInclude Include="zones.h">
<Filter>hook_lib\game</Filter>
</ClInclude>
<ClInclude Include="party.h">
<Filter>hook_lib\game</Filter>
</ClInclude>
</ItemGroup>
</Project>

View File

@ -5,9 +5,5 @@ void CG_MainMP_Init_Detour(int localClientNum, int serverMessageNum, int serverC
{
cg_mainmp_init.stub<void>(localClientNum, serverMessageNum, serverCommandSequence, clientNum, hunkUser);
Cbuf_AddText("exec autoexec.cfg");
LoadInventory();
Cbuf_AddText("set cl_textChatEnabled 1");
}

14
hook_lib/party.cpp Normal file
View File

@ -0,0 +1,14 @@
#include "party.h"
#include "game_inc.h"
void PartyHost_StartPrivateParty_Detour(int localClientNum, int localControllerIndex, bool currentlyActive, int hostType)
{
partyhost_startprivateparty.stub<void>(localClientNum, localControllerIndex, currentlyActive, hostType);
static bool autoexec = false;
if (!autoexec)
{
Cbuf_AddText("exec autoexec.cfg");
LoadInventory();
}
}

5
hook_lib/party.h Normal file
View File

@ -0,0 +1,5 @@
#pragma once
#include "Main.hpp"
inline utils::hook::detour partyhost_startprivateparty;
void PartyHost_StartPrivateParty_Detour(int localClientNum, int localControllerIndex, bool currentlyActive, int hostType);

View File

@ -6,7 +6,6 @@ bool bFinished;
bool btoggle;
dvar_t* cl_textChatEnabled = reinterpret_cast<dvar_t*>(0x14EEB0738_g);
dvar_t* com_timescale = reinterpret_cast<dvar_t*>(0x14D3865E8_g);
uintptr_t xuid_generated;
int collision_ticker;
@ -143,6 +142,7 @@ void hooks()
cl_createdevgui.create(0x1415B2080_g, CL_CreateDevGui_Detour);
cg_mainmp_init.create(0x141792E60_g, CG_MainMP_Init_Detour);
partyhost_startprivateparty.create(0x14119F0D0_g, PartyHost_StartPrivateParty_Detour);
PM_WeaponUseAmmo.create(0x141155AF0_g, PM_WeaponUseAmmo_Detour);
@ -196,9 +196,6 @@ void patchGame()
utils::hook::nop(0x141665289_g, 5);
utils::hook::nop(0x14166567D_g, 5);
// set com_timescale dvar to read only
utils::hook::set<unsigned int>(0x1412B26CF_g, 8192);
// remove FF Header version check
// utils::hook::set<byte>(0x1411A776B_g, 0xEB);
}

View File

@ -1,7 +0,0 @@
#include "splashscreen.hpp"
byte data_buf[1] = { 0x0 };
void set_splashscreen() {
// memcpy((void*)(0x1530AD525_g), (const void*)(data_buf), 0x128BB8);
}

View File

@ -1,15 +0,0 @@
#pragma once
#include "Main.hpp"
typedef unsigned char byte;
size_t operator"" _b(size_t val);
size_t reverse_b(size_t val);
size_t reverse_b(const void* val);
size_t operator"" _g(size_t val);
size_t reverse_g(size_t val);
size_t reverse_g(const void* val);
extern byte data_buf[1];
void set_splashscreen();

View File

@ -16,9 +16,12 @@ const char* SEH_StringEd_GetString_Detour(const char* pszReference)
GamerProfile_SetDataByName(0, "hasEverPlayed_MainMenu", 1);
// LUA_MENU/MAPNAME_ANIYAH // Aniyah Palace
if (std::string(pszReference) == "LUA_MENU/MAPNAME_ANIYAH")
if (strstr(pszReference, "LUA_MENU/MAPNAME_ANIYAH"))
{
return "^1no work";
if (pszReference[23] == '\0')
{
return "^1no work";
}
}
if (strstr(pszReference, "LUA_MENU/MAPNAME_DEADZONE") ||

View File

@ -17,3 +17,81 @@ void CG_OverrideImpactEffectType(uintptr_t localClientNum, unsigned int sourceEn
fxImpactType[2] = 34;
cg_overrideimpacteffecttype.stub<__int64>(localClientNum, sourceEntityNum, fxImpactType);
}
TracerDef* GetTracerDef(const char* asset) {
TracerDef* tracerDef = DB_FindXAssetHeader(ASSET_TYPE_TRACER, asset, 0).tracerDef;
if (tracerDef) return tracerDef;
return 0;
}
void Dump_WeaponDef() {
char path[MAX_PATH + 1];
strcpy(path, Dvar_GetStringSafe("LOOQOTRNTN"));
strcat(path, "\\players\\weapondef.json");
bool inFrontend = *(bool*)(0x1459D1750_g);
if (!inFrontend) {
nlohmann::json weaponDefJson;
WeaponCompleteDef** bg_weaponCompleteDefs = (WeaponCompleteDef**)(0x14C6EC870_g);
for (int i = 0; i < 550; i++) {
WeaponCompleteDef* weap = bg_weaponCompleteDefs[i];
if (!weap) continue;
if (strstr(weap->szInternalName, "iw8") && !strstr(weap->szInternalName, "watch") && !strstr(weap->szInternalName, "execution") && !strstr(weap->szInternalName, "plyr")) {
weaponDefJson[weap->szInternalName]["vfxImpactType"] = weap->vfxImpactType;
weaponDefJson[weap->szInternalName]["ladderWeapon"] = weap->weapDef->ladderWeapon;
weaponDefJson[weap->szInternalName]["canHoldBreath"] = weap->weapDef->canHoldBreath;
weaponDefJson[weap->szInternalName]["iFireTime"] = weap->weapDef->iFireTime;
weaponDefJson[weap->szInternalName]["bBoltAction"] = weap->weapDef->bBoltAction;
weaponDefJson[weap->szInternalName]["fireType"] = weap->weapDef->fireType;
weaponDefJson[weap->szInternalName]["iStartAmmo"] = weap->weapDef->iStartAmmo;
weaponDefJson[weap->szInternalName]["iMaxAmmo"] = weap->weapDef->iMaxAmmo;
if (weap->weapDef->tracerType)
weaponDefJson[weap->szInternalName]["tracerType"] = weap->weapDef->tracerType->name;
}
}
std::ofstream JsonOut(path);
JsonOut << weaponDefJson;
}
else {
Com_SetErrorMessage("[DLL ERROR] Must be in-game to dump WeaponDef.");
}
}
void Load_WeaponDef() {
char path[MAX_PATH + 1];
strcpy(path, Dvar_GetStringSafe("LOOQOTRNTN"));
strcat(path, "\\players\\weapondef.json");
bool inFrontend = *(bool*)(0x1459D1750_g);
if (!inFrontend) {
if (file_exists(path)) {
std::ifstream jsonPath(path);
nlohmann::json weaponDefJson = nlohmann::json::parse(jsonPath);
WeaponCompleteDef** bg_weaponCompleteDefs = (WeaponCompleteDef**)(0x14C6EC870_g);
for (int i = 0; i < 550; i++) {
WeaponCompleteDef* weap = bg_weaponCompleteDefs[i];
if (!weap) continue;
if (weaponDefJson.contains(weap->szInternalName)) {
weap->vfxImpactType = weaponDefJson[weap->szInternalName]["vfxImpactType"];
weap->weapDef->ladderWeapon = weaponDefJson[weap->szInternalName]["ladderWeapon"];
weap->weapDef->canHoldBreath = weaponDefJson[weap->szInternalName]["canHoldBreath"];
weap->weapDef->iFireTime = weaponDefJson[weap->szInternalName]["iFireTime"];
weap->weapDef->bBoltAction = weaponDefJson[weap->szInternalName]["bBoltAction"];
weap->weapDef->fireType = weaponDefJson[weap->szInternalName]["fireType"];
weap->weapDef->iStartAmmo = weaponDefJson[weap->szInternalName]["iStartAmmo"];
weap->weapDef->iMaxAmmo = weaponDefJson[weap->szInternalName]["iMaxAmmo"];
if (weaponDefJson[weap->szInternalName].contains("tracerType")) {
weap->weapDef->tracerType = GetTracerDef(weaponDefJson[weap->szInternalName]["tracerType"].get<std::string>().c_str());
}
}
}
}
else {
Com_SetErrorMessage("[DLL ERROR] weapondef JSON is not present in players directory.");
}
}
else {
Com_SetErrorMessage("[DLL ERROR] Must be in-game to load custom WeaponDef.");
}
}

View File

@ -5,4 +5,10 @@ inline utils::hook::detour PM_WeaponUseAmmo;
void PM_WeaponUseAmmo_Detour(__int64 playerstate, Weapon* weapon, char a3, int a4, int hand);
inline utils::hook::detour cg_overrideimpacteffecttype;
void CG_OverrideImpactEffectType(uintptr_t localClientNum, unsigned int sourceEntityNum, int* fxImpactType);
void CG_OverrideImpactEffectType(uintptr_t localClientNum, unsigned int sourceEntityNum, int* fxImpactType);
TracerDef* GetTracerDef(const char* asset);
void Dump_WeaponDef();
void Load_WeaponDef();