diff --git a/src/Components/Modules/Download.cpp b/src/Components/Modules/Download.cpp index e4d14444..66de47ff 100644 --- a/src/Components/Modules/Download.cpp +++ b/src/Components/Modules/Download.cpp @@ -532,7 +532,7 @@ namespace Components "\r\n", mimeType.data(), buffer.size()); mg_send(nc, buffer.data(), static_cast(buffer.size())); - } + } else { mg_printf(nc, diff --git a/src/Components/Modules/FileSystem.cpp b/src/Components/Modules/FileSystem.cpp index f11c3c3b..779a8b6a 100644 --- a/src/Components/Modules/FileSystem.cpp +++ b/src/Components/Modules/FileSystem.cpp @@ -2,30 +2,45 @@ namespace Components { - FileSystem::File::File(std::string file) : Name(file), Handle(0) + void FileSystem::File::Read() + { + char* buffer = nullptr; + int size = Game::FS_ReadFile(this->FilePath.data(), &buffer); + + this->Buffer.clear(); + + if (size >= 0) + { + this->Buffer.append(buffer, size); + Game::FS_FreeFile(buffer); + } + } + + + FileSystem::FileReader::FileReader(std::string file) : Name(file), Handle(0) { this->Size = Game::FS_FOpenFileRead(this->Name.data(), &this->Handle, 0); } - FileSystem::File::~File() + FileSystem::FileReader::~FileReader() { - if (this->Exists()) + if (this->Exists() && this->Handle) { Game::FS_FCloseFile(this->Handle); } } - bool FileSystem::File::Exists() + bool FileSystem::FileReader::Exists() { return (this->Size > 0); } - std::string FileSystem::File::GetName() + std::string FileSystem::FileReader::GetName() { return this->Name; } - std::string FileSystem::File::GetBuffer() + std::string FileSystem::FileReader::GetBuffer() { Utils::Memory::Allocator allocator; if (!this->Exists()) return std::string(); @@ -34,7 +49,7 @@ namespace Components this->Seek(0, FS_SEEK_SET); char* buffer = allocator.AllocateArray(this->Size); - if (!FileSystem::File::Read(buffer, this->Size)) + if (!this->Read(buffer, this->Size)) { this->Seek(position, FS_SEEK_SET); return std::string(); @@ -45,7 +60,7 @@ namespace Components return std::string(buffer, this->Size); } - bool FileSystem::File::Read(void* buffer, size_t size) + bool FileSystem::FileReader::Read(void* buffer, size_t size) { if (!this->Exists() || static_cast(this->Size) < size || Game::FS_Read(buffer, size, this->Handle) != static_cast(size)) { @@ -55,7 +70,7 @@ namespace Components return true; } - void FileSystem::File::Seek(int offset, int origin) + void FileSystem::FileReader::Seek(int offset, int origin) { if (this->Exists()) { diff --git a/src/Components/Modules/FileSystem.hpp b/src/Components/Modules/FileSystem.hpp index 554710db..37b43f44 100644 --- a/src/Components/Modules/FileSystem.hpp +++ b/src/Components/Modules/FileSystem.hpp @@ -4,12 +4,29 @@ namespace Components { public: - class File + class File + { + public: + File() {}; + File(std::string file) : FilePath(file) { this->Read(); }; + + bool Exists() { return !this->Buffer.empty(); }; + std::string GetName() { return this->FilePath; }; + std::string& GetBuffer() { return this->Buffer; }; + + private: + std::string FilePath; + std::string Buffer; + + void Read(); + }; + + class FileReader { public: - File() : Size(-1), Name(), Handle(0) {}; - File(std::string file); - ~File(); + FileReader() : Size(-1), Name(), Handle(0) {}; + FileReader(std::string file); + ~FileReader(); bool Exists(); std::string GetName(); diff --git a/src/Components/Modules/ModelSurfs.cpp b/src/Components/Modules/ModelSurfs.cpp index 4b5d4db7..40433ec5 100644 --- a/src/Components/Modules/ModelSurfs.cpp +++ b/src/Components/Modules/ModelSurfs.cpp @@ -38,7 +38,7 @@ namespace Components Game::XModelSurfs* ModelSurfs::LoadXModelSurfaces(std::string name) { Utils::Memory::Allocator allocator; - FileSystem::File model(fmt::sprintf("models/%s", name.data())); + FileSystem::FileReader model(fmt::sprintf("models/%s", name.data())); if (!model.Exists()) { diff --git a/src/Components/Modules/Zones.cpp b/src/Components/Modules/Zones.cpp index 29608632..3f8df669 100644 --- a/src/Components/Modules/Zones.cpp +++ b/src/Components/Modules/Zones.cpp @@ -2,18 +2,13 @@ namespace Components { - int Zones::ZoneVersion; - - - extern bool* useEntryNames; + int Zones::ZoneVersion; Utils::Hook fxEffectLoadHook; static DWORD fxEffectStringValue[64]; static int fxEffectIndex = 0; - int ffVersion = 0; - #define VERSION_ALPHA2 316 #define VERSION_ALPHA3 318//319 @@ -52,26 +47,16 @@ namespace Components Utils::Hook fxEffectModifyHook; - bool ignoreThisFx = false; - void FxEffectModifyHookFunc(int a1, char* buffer, size_t len) { char typeNum = *(char*)(buffer + 176); //DBG(("ot %i\n", typeNum)); - if (typeNum == 2) - { - ignoreThisFx = true; - } - else if (typeNum == 3) + if (typeNum == 3) { typeNum = 2; } - else if (typeNum == 4) - { - ignoreThisFx = true; - } else if (typeNum >= 5) { typeNum -= 2; @@ -155,7 +140,7 @@ namespace Components add esp, 0Ch } - int elSize = (ffVersion == VERSION_ALPHA2) ? 364 : 360; + int elSize = (Zones::ZoneVersion == VERSION_ALPHA2) ? 364 : 360; static unsigned char tempVar[364]; memcpy(&tempVar[0], &buffer[0], 36); @@ -198,7 +183,7 @@ namespace Components void XModelLODTailHookFunc(int i) { - int elSize = (ffVersion == VERSION_ALPHA2) ? 364 : 360; + int elSize = (Zones::ZoneVersion == VERSION_ALPHA2) ? 364 : 360; i = (4 - i)/* + 1*/; // varXString = (varXModel + 0x16C - (4 * i)) // where the above function parked the new xstring @@ -234,40 +219,6 @@ namespace Components } } - Utils::Hook fxDefaultHook; - - void FxDefaultHookFunc() - { - DWORD* varFxEffectDefPtr = *(DWORD**)0x112ACC0; - - *varFxEffectDefPtr = (DWORD)Game::DB_FindXAssetHeader(Game::ASSET_TYPE_FX, "misc/missing_fx").data; - } - - void __declspec(naked) FxDefaultHookStub() - { - __asm - { - jmp FxDefaultHookFunc - } - } - - Utils::Hook xmodelDefaultHook; - - void XModelDefaultHookFunc() - { - DWORD* varXModelPtr = *(DWORD**)0x112A934; - - *varXModelPtr = (DWORD)Game::DB_FindXAssetHeader(Game::ASSET_TYPE_XMODEL, "void").data; - } - - void __declspec(naked) XModelDefaultHookStub() - { - __asm - { - jmp XModelDefaultHookFunc - } - } - Utils::Hook xsurfaceIntLoadHook; void XSurfaceIntLoadHookFunc(int a1, char* buffer, size_t len) @@ -361,7 +312,7 @@ namespace Components DWORD* varXString = (DWORD*)0x112B340; // and do the stuff - Load_Stream(1, varWeaponDef, (ffVersion >= 318) ? 3156 : 3112); + Load_Stream(1, varWeaponDef, (Zones::ZoneVersion >= 318) ? 3156 : 3112); DB_PushStreamPos(3); @@ -426,7 +377,7 @@ namespace Components Load_SndAliasCustom(*varsnd_alias_list_name); } - if (ffVersion >= 318) + if (Zones::ZoneVersion >= 318) { for (int i = 0, offset = 1184; i < 2; i++, offset += 4) { @@ -536,7 +487,7 @@ namespace Components DWORD vec2 = DB_AllocStreamPos(3); *(DWORD*)(varWeaponDef + 2556) = vec2; - Load_Stream(1, vec2, 8 * *(short*)(varWeaponDef + ((ffVersion >= 318) ? 3076 : 3040))); + Load_Stream(1, vec2, 8 * *(short*)(varWeaponDef + ((Zones::ZoneVersion >= 318) ? 3076 : 3040))); } *varXString = varWeaponDef + 2552; @@ -547,7 +498,7 @@ namespace Components DWORD vec2 = DB_AllocStreamPos(3); *(DWORD*)(varWeaponDef + 2560) = vec2; - Load_Stream(1, vec2, 8 * *(short*)(varWeaponDef + ((ffVersion >= 318) ? 3078 : 3042))); + Load_Stream(1, vec2, 8 * *(short*)(varWeaponDef + ((Zones::ZoneVersion >= 318) ? 3078 : 3042))); } *varXString = varWeaponDef + 2640; @@ -595,7 +546,7 @@ namespace Components *varsnd_alias_list_name = varWeaponDef + 2904; // 2912 Load_SndAliasCustom(*varsnd_alias_list_name); - if (ffVersion >= 318) + if (Zones::ZoneVersion >= 318) { for (int i = 0, offset = 2972; i < 6; i++, offset += 4) { @@ -976,15 +927,13 @@ namespace Components } } - void PatchMW2_FifthInfinityApply(int fileVersion, bool iw5) + void PatchMW2_FifthInfinityApply(bool iw5) { - ffVersion = fileVersion; - // physpreset size *(BYTE*)0x49CE0A = (iw5) ? 68 : 44; // XModel size - *(DWORD*)0x410D8A = (iw5) ? ((ffVersion == VERSION_ALPHA2) ? 0x16C : 0x168) : 0x130; + *(DWORD*)0x410D8A = (iw5) ? ((Zones::ZoneVersion == VERSION_ALPHA2) ? 0x16C : 0x168) : 0x130; // XSurface size *(BYTE*)0x48E84A = (iw5) ? 48 : 36; @@ -1031,16 +980,13 @@ namespace Components loadWeaponAttachHook.Install(); - if (ffVersion >= VERSION_ALPHA3) + if (Zones::ZoneVersion >= VERSION_ALPHA3) { gameWorldSpIntHook.Install(); } loadTechniquePassHook.Install(); loadStructuredDataChildArrayHook.Install(); - - //xmodelDefaultHook.Install(); - //fxDefaultHook.Install(); } else { @@ -1064,9 +1010,6 @@ namespace Components loadWeaponAttachHook.Uninstall(); - xmodelDefaultHook.Uninstall(); - fxDefaultHook.Uninstall(); - gameWorldSpIntHook.Uninstall(); loadTechniquePassHook.Uninstall(); @@ -1085,7 +1028,7 @@ namespace Components Utils::Hook::Set(0x4158FB, version); } - PatchMW2_FifthInfinityApply(version, version >= 316); + PatchMW2_FifthInfinityApply(version >= 316); AntiCheat::EmptyHash(); } @@ -1107,8 +1050,6 @@ namespace Components gameWorldSpLoadHook.Initialize(0x4F4D0D, GameWorldSpLoadHookFunc, HOOK_CALL); loadWeaponDefHook.Initialize(0x47CCD2, Load_WeaponDef_CodC, HOOK_CALL); vehicleLoadHook.Initialize(0x483DA0, VehicleLoadHookFunc, HOOK_CALL); - xmodelDefaultHook.Initialize(0x4FCAEE, XModelDefaultHookStub, HOOK_CALL); - fxDefaultHook.Initialize(0x4D9C0E, FxDefaultHookStub, HOOK_CALL); allocZoneMemoryHook.Initialize(0x415A57, AllocXZoneMemoryHookStub, HOOK_CALL); sndAliasLoadHook.Initialize(0x4F0AC8, SndAliasLoadHookFunc, HOOK_CALL); mssSoundLoadHook.Initialize(0x403A5D, MssSoundLoadHookFunc, HOOK_CALL); diff --git a/src/Components/Modules/Zones.hpp b/src/Components/Modules/Zones.hpp index 84ab67bd..dffddf5b 100644 --- a/src/Components/Modules/Zones.hpp +++ b/src/Components/Modules/Zones.hpp @@ -12,7 +12,7 @@ namespace Components static void InstallPatches(int version); - private: + //private: static int ZoneVersion; }; }