Merge branch 'develop' of https://github.com/iw4x/iw4x-client into develop
This commit is contained in:
commit
d6d8b078d9
1
deps/iw4-open-formats/include/api.hpp
vendored
1
deps/iw4-open-formats/include/api.hpp
vendored
@ -4,6 +4,7 @@
|
||||
#include "iw4_native_asset.hpp"
|
||||
#include <functional>
|
||||
#include <filesystem>
|
||||
#include <unordered_set>
|
||||
|
||||
namespace iw4of
|
||||
{
|
||||
|
@ -39,6 +39,11 @@ namespace iw4of
|
||||
this->assets = assets;
|
||||
}
|
||||
|
||||
bool writes_single_file()
|
||||
{
|
||||
return writes_single_file_internal();
|
||||
}
|
||||
|
||||
std::filesystem::path get_work_path(const native::XAssetHeader& header) const;
|
||||
|
||||
virtual ~asset_interface() {}
|
||||
@ -58,6 +63,11 @@ namespace iw4of
|
||||
return {};
|
||||
};
|
||||
|
||||
virtual bool writes_single_file_internal()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
std::filesystem::path get_work_path(const std::string& asset_name) const;
|
||||
|
||||
std::filesystem::path get_work_path(const std::filesystem::path& file_path) const;
|
||||
|
@ -1114,7 +1114,7 @@ namespace iw4of::interfaces
|
||||
/*typename SourceEncoding*/ rapidjson::UTF8<>,
|
||||
/*typename TargetEncoding*/ rapidjson::UTF8<>,
|
||||
/*typename StackAllocator*/ rapidjson::CrtAllocator,
|
||||
/*unsigned writeFlags*/ rapidjson::kWriteNanAndInfFlag>
|
||||
/*unsigned writeFlags*/ rapidjson::kWriteNanAndInfNullFlag | rapidjson::kWriteNanAndInfFlag>
|
||||
writer(buff);
|
||||
writer.SetFormatOptions(rapidjson::PrettyFormatOptions::kFormatSingleLineArray);
|
||||
output.Accept(writer);
|
||||
|
@ -306,7 +306,13 @@ namespace iw4of::interfaces
|
||||
output.AddMember("elemDefs", elemTable, allocator);
|
||||
|
||||
rapidjson::StringBuffer buff;
|
||||
rapidjson::PrettyWriter<rapidjson::StringBuffer> writer(buff);
|
||||
rapidjson::PrettyWriter<
|
||||
/*typename OutputStream */ rapidjson::StringBuffer,
|
||||
/*typename SourceEncoding*/ rapidjson::UTF8<>,
|
||||
/*typename TargetEncoding*/ rapidjson::UTF8<>,
|
||||
/*typename StackAllocator*/ rapidjson::CrtAllocator,
|
||||
/*unsigned writeFlags*/ rapidjson::kWriteNanAndInfNullFlag | rapidjson::kWriteNanAndInfFlag>
|
||||
writer(buff);
|
||||
output.Accept(writer);
|
||||
|
||||
return utils::io::write_file(get_work_path(header).string(), buff.GetString());
|
||||
|
@ -636,11 +636,11 @@ namespace iw4of::interfaces
|
||||
if (clip)
|
||||
{
|
||||
assert(clip->planeCount == asset->planeCount);
|
||||
for (size_t i = 0; i < clip->planeCount; i++)
|
||||
{
|
||||
assert(0 ==
|
||||
memcmp(&clip->planes[i], &asset->dpvsPlanes.planes[i], sizeof(native::cplane_s) - sizeof(native::cplane_s::pad)));
|
||||
}
|
||||
//for (size_t i = 0; i < clip->planeCount; i++)
|
||||
//{
|
||||
// assert(0 ==
|
||||
// memcmp(&clip->planes[i], &asset->dpvsPlanes.planes[i], sizeof(native::cplane_s) - sizeof(native::cplane_s::pad)));
|
||||
//}
|
||||
|
||||
asset->dpvsPlanes.planes = clip->planes;
|
||||
}
|
||||
|
@ -209,8 +209,17 @@ namespace iw4of::interfaces
|
||||
output.AddMember("stateBitsTable", statebits_to_json_array(asset->stateBitsTable, asset->stateBitsCount, allocator), allocator);
|
||||
}
|
||||
|
||||
// Write to disk
|
||||
rapidjson::StringBuffer buff;
|
||||
rapidjson::PrettyWriter<rapidjson::StringBuffer> writer(buff);
|
||||
rapidjson::PrettyWriter<
|
||||
/*typename OutputStream */ rapidjson::StringBuffer,
|
||||
/*typename SourceEncoding*/ rapidjson::UTF8<>,
|
||||
/*typename TargetEncoding*/ rapidjson::UTF8<>,
|
||||
/*typename StackAllocator*/ rapidjson::CrtAllocator,
|
||||
/*unsigned writeFlags*/ rapidjson::kWriteNanAndInfNullFlag | rapidjson::kWriteNanAndInfFlag>
|
||||
writer(buff);
|
||||
writer.SetFormatOptions(rapidjson::PrettyFormatOptions::kFormatSingleLineArray);
|
||||
|
||||
output.Accept(writer);
|
||||
|
||||
utils::io::write_file(get_work_path(header).string(), buff.GetString());
|
||||
|
125
deps/iw4-open-formats/src/iw4-of/assets/asset_interfaces/iphyscollmap.cpp
vendored
Normal file
125
deps/iw4-open-formats/src/iw4-of/assets/asset_interfaces/iphyscollmap.cpp
vendored
Normal file
@ -0,0 +1,125 @@
|
||||
#include <std_include.hpp>
|
||||
|
||||
#include "assets/assets.hpp"
|
||||
#include "iphyscollmap.hpp"
|
||||
|
||||
#include <utils/io.hpp>
|
||||
#include <utils/string.hpp>
|
||||
|
||||
#include <utils/json.hpp>
|
||||
#include <rapidjson/prettywriter.h>
|
||||
|
||||
#define IW4X_PHYS_COLLMAP_VERSION 1
|
||||
|
||||
namespace iw4of::interfaces
|
||||
{
|
||||
bool iphyscollmap::write_internal(const native::XAssetHeader& header) const
|
||||
{
|
||||
rapidjson::Document output(rapidjson::kObjectType);
|
||||
auto& allocator = output.GetAllocator();
|
||||
|
||||
auto asset = header.physCollmap;
|
||||
assert(asset);
|
||||
|
||||
output.AddMember("version", IW4X_PHYS_COLLMAP_VERSION, allocator);
|
||||
output.AddMember("name", RAPIDJSON_STR(asset->name), allocator);
|
||||
|
||||
rapidjson::Value geoms(rapidjson::kArrayType);
|
||||
for (size_t i = 0; i < asset->count; i++)
|
||||
{
|
||||
rapidjson::Value geom_info(rapidjson::kObjectType);
|
||||
const auto geom = &asset->geoms[i];
|
||||
|
||||
{
|
||||
rapidjson::Value json_brush_wrapper(rapidjson::kObjectType);
|
||||
const auto brush_wrapper = geom->brushWrapper;
|
||||
|
||||
json_brush_wrapper.AddMember("bounds", utils::json::to_json(brush_wrapper->bounds, allocator), allocator);
|
||||
json_brush_wrapper.AddMember("planes", utils::json::to_json(brush_wrapper->planes, brush_wrapper->brush.numsides, allocator), allocator);
|
||||
|
||||
geom_info.AddMember("brushwrapper", json_brush_wrapper, allocator);
|
||||
}
|
||||
|
||||
rapidjson::Value orientation(rapidjson::kArrayType);
|
||||
for (size_t j = 0; j < 3; j++)
|
||||
{
|
||||
orientation.PushBack(utils::json::make_json_array(geom->orientation[j], 3, allocator), allocator);
|
||||
}
|
||||
|
||||
geom_info.AddMember("type", static_cast<int>(geom->type), allocator);
|
||||
geom_info.AddMember("orientation", orientation, allocator);
|
||||
geom_info.AddMember("bounds", utils::json::to_json(geom->bounds, allocator), allocator);
|
||||
}
|
||||
|
||||
rapidjson::StringBuffer buff;
|
||||
rapidjson::PrettyWriter<rapidjson::StringBuffer> writer(buff);
|
||||
output.Accept(writer);
|
||||
|
||||
const auto& dump = buff.GetString();
|
||||
|
||||
return utils::io::write_file(get_work_path(header).string(), dump);
|
||||
}
|
||||
|
||||
void* iphyscollmap::read_internal(const std::string& name) const
|
||||
{
|
||||
const auto& path = get_work_path(name).string();
|
||||
|
||||
if (utils::io::file_exists(path))
|
||||
{
|
||||
auto asset = local_allocator.allocate<native::PhysPreset>();
|
||||
rapidjson::Document physPresetJson;
|
||||
|
||||
try
|
||||
{
|
||||
const auto& content = utils::io::read_file(path);
|
||||
physPresetJson.Parse(content.data());
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
print_error("Invalid JSON for physpreset {}! {}", name, e.what());
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
// Must NOT be null!
|
||||
assert(!physPresetJson["sndAliasPrefix"].IsNull());
|
||||
|
||||
asset->name = local_allocator.duplicate_string(physPresetJson["name"].GetString());
|
||||
asset->type = physPresetJson["type"].Get<int32_t>();
|
||||
asset->bounce = physPresetJson["bounce"].Get<float>();
|
||||
asset->mass = physPresetJson["mass"].Get<float>();
|
||||
asset->friction = physPresetJson["friction"].Get<float>();
|
||||
asset->bulletForceScale = physPresetJson["bulletForceScale"].Get<float>();
|
||||
asset->explosiveForceScale = physPresetJson["explosiveForceScale"].Get<float>();
|
||||
asset->sndAliasPrefix = local_allocator.duplicate_string(physPresetJson["sndAliasPrefix"].GetString());
|
||||
asset->piecesSpreadFraction = physPresetJson["piecesSpreadFraction"].Get<float>();
|
||||
asset->piecesUpwardVelocity = physPresetJson["piecesUpwardVelocity"].Get<float>();
|
||||
asset->tempDefaultToCylinder = physPresetJson["tempDefaultToCylinder"].Get<bool>();
|
||||
asset->perSurfaceSndAlias = physPresetJson["perSurfaceSndAlias"].Get<bool>();
|
||||
|
||||
assert(asset->mass > FLT_EPSILON);
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
print_error("Malformed JSON for physpreset {}! {}", name, e.what());
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return asset;
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::filesystem::path iphyscollmap::get_file_name(const std::string& basename) const
|
||||
{
|
||||
return std::format("{}.iw4x.json", basename);
|
||||
}
|
||||
|
||||
std::filesystem::path iphyscollmap::get_folder_name() const
|
||||
{
|
||||
return "physcollmap";
|
||||
}
|
||||
|
||||
} // namespace iw4of::interfaces
|
30
deps/iw4-open-formats/src/iw4-of/assets/asset_interfaces/iphyscollmap.hpp
vendored
Normal file
30
deps/iw4-open-formats/src/iw4-of/assets/asset_interfaces/iphyscollmap.hpp
vendored
Normal file
@ -0,0 +1,30 @@
|
||||
#pragma once
|
||||
|
||||
#include <utils/stream.hpp>
|
||||
#include "assets/asset_interface.hpp"
|
||||
|
||||
namespace iw4of::interfaces
|
||||
{
|
||||
struct iphyscollmap : asset_interface
|
||||
{
|
||||
public:
|
||||
iphyscollmap(const iw4of::assets* assets)
|
||||
: asset_interface(assets)
|
||||
{
|
||||
}
|
||||
|
||||
protected:
|
||||
bool write_internal(const native::XAssetHeader& header) const override;
|
||||
void* read_internal(const std::string& name) const override;
|
||||
std::filesystem::path get_file_name(const std::string& basename) const override;
|
||||
std::filesystem::path get_folder_name() const override;
|
||||
|
||||
private:
|
||||
void write(const native::XSurfaceCollisionTree* entry, utils::stream* buffer) const;
|
||||
void write(const native::XSurface* surf, utils::stream* buffer) const;
|
||||
void write(const native::XModelSurfs* asset, utils::stream* buffer) const;
|
||||
void read(native::XSurfaceCollisionTree* entry, utils::stream::reader* reader) const;
|
||||
void read(native::XSurface* asset, utils::stream::reader* reader) const;
|
||||
void read(native::XModelSurfs* asset, utils::stream::reader* reader) const;
|
||||
};
|
||||
} // namespace iw4of::interfaces
|
@ -222,6 +222,7 @@ namespace iw4of::interfaces
|
||||
}
|
||||
else
|
||||
{
|
||||
print_error("Could not find animtree {}\n", animtree_name);
|
||||
assert(false);
|
||||
}
|
||||
}
|
||||
|
@ -427,8 +427,16 @@ namespace iw4of::interfaces
|
||||
output.AddMember("count", ents->count, allocator);
|
||||
output.AddMember("head", head, allocator);
|
||||
|
||||
// Write to disk
|
||||
rapidjson::StringBuffer buff;
|
||||
rapidjson::PrettyWriter<rapidjson::StringBuffer> writer(buff);
|
||||
rapidjson::PrettyWriter<
|
||||
/*typename OutputStream */ rapidjson::StringBuffer,
|
||||
/*typename SourceEncoding*/ rapidjson::UTF8<>,
|
||||
/*typename TargetEncoding*/ rapidjson::UTF8<>,
|
||||
/*typename StackAllocator*/ rapidjson::CrtAllocator,
|
||||
/*unsigned writeFlags*/ rapidjson::kWriteNanAndInfFlag>
|
||||
writer(buff);
|
||||
writer.SetFormatOptions(rapidjson::PrettyFormatOptions::kFormatSingleLineArray);
|
||||
output.Accept(writer);
|
||||
|
||||
const auto& dump = buff.GetString();
|
||||
|
@ -90,8 +90,15 @@ namespace iw4of::interfaces
|
||||
|
||||
output.AddMember("knots", knots_array, allocator);
|
||||
|
||||
// Write to disk
|
||||
rapidjson::StringBuffer buff;
|
||||
rapidjson::PrettyWriter<rapidjson::StringBuffer> writer(buff);
|
||||
rapidjson::PrettyWriter<
|
||||
/*typename OutputStream */ rapidjson::StringBuffer,
|
||||
/*typename SourceEncoding*/ rapidjson::UTF8<>,
|
||||
/*typename TargetEncoding*/ rapidjson::UTF8<>,
|
||||
/*typename StackAllocator*/ rapidjson::CrtAllocator,
|
||||
/*unsigned writeFlags*/ rapidjson::kWriteNanAndInfFlag>
|
||||
writer(buff);
|
||||
writer.SetFormatOptions(rapidjson::PrettyFormatOptions::kFormatSingleLineArray);
|
||||
|
||||
output.Accept(writer);
|
||||
|
@ -114,7 +114,7 @@ namespace iw4of::interfaces
|
||||
/*typename SourceEncoding*/ rapidjson::UTF8<>,
|
||||
/*typename TargetEncoding*/ rapidjson::UTF8<>,
|
||||
/*typename StackAllocator*/ rapidjson::CrtAllocator,
|
||||
/*unsigned writeFlags*/ rapidjson::kWriteNanAndInfFlag
|
||||
/*unsigned writeFlags*/ rapidjson::kWriteNanAndInfNullFlag | rapidjson::kWriteNanAndInfFlag
|
||||
>
|
||||
writer(buff);
|
||||
|
||||
@ -461,7 +461,7 @@ namespace iw4of::interfaces
|
||||
/*typename SourceEncoding*/ rapidjson::UTF8<>,
|
||||
/*typename TargetEncoding*/ rapidjson::UTF8<>,
|
||||
/*typename StackAllocator*/ rapidjson::CrtAllocator,
|
||||
/*unsigned writeFlags*/ rapidjson::kWriteNanAndInfFlag
|
||||
/*unsigned writeFlags*/ rapidjson::kWriteNanAndInfNullFlag
|
||||
>
|
||||
writer(buff);
|
||||
|
||||
|
@ -24,7 +24,16 @@ namespace iw4of
|
||||
if (check_type_is_supported(iw4_int_type))
|
||||
{
|
||||
const auto& path = asset_interfaces[iw4_int_type]->get_work_path({header});
|
||||
if (can_write(path))
|
||||
const bool writes_in_single_file = asset_interfaces[iw4_int_type]->writes_single_file();
|
||||
|
||||
if (writes_in_single_file && !written_assets.contains(path.string()))
|
||||
{
|
||||
// We have never written this file but it exists on disk, so we destroy it because
|
||||
// we will be appending to it in the future
|
||||
std::filesystem::remove(path);
|
||||
}
|
||||
|
||||
if (writes_in_single_file || can_write(path))
|
||||
{
|
||||
bool written = asset_interfaces[iw4_int_type]->write<T>(header);
|
||||
|
||||
|
@ -315,7 +315,10 @@ namespace Components
|
||||
Friends::LoggedOn = (Steam::Proxy::SteamUser_ && Steam::Proxy::SteamUser_->LoggedOn());
|
||||
if (!Steam::Proxy::SteamFriends) return;
|
||||
|
||||
if (Game::Sys_IsMainThread())
|
||||
{
|
||||
Game::UI_UpdateArenas();
|
||||
}
|
||||
|
||||
int count = Steam::Proxy::SteamFriends->GetFriendCount(4);
|
||||
|
||||
|
@ -262,6 +262,8 @@ namespace Components
|
||||
{
|
||||
const auto* g_log = (*Game::g_log) ? (*Game::g_log)->current.string : "";
|
||||
|
||||
if (g_log) // This can be null - has happened before
|
||||
{
|
||||
if (std::strcmp(g_log, file) == 0)
|
||||
{
|
||||
if (std::strcmp(folder, "userraw") != 0)
|
||||
@ -273,6 +275,7 @@ namespace Components
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
__declspec(naked) void Logger::BuildOSPath_Stub()
|
||||
{
|
||||
@ -419,8 +422,31 @@ namespace Components
|
||||
});
|
||||
}
|
||||
|
||||
void PrintAliasError(Game::conChannel_t channel, const char* originalMsg, const char* soundName, const char* lastErrorStr)
|
||||
{
|
||||
// We add a bit more info and we clear the sound stream when it happens
|
||||
// to avoid spamming the error
|
||||
const auto newMsg = std::format("{}Make sure you have the 'miles' folder in your game directory! Otherwise MP3 and other codecs will be unavailable.\n", originalMsg);
|
||||
Game::Com_PrintError(channel, newMsg.c_str(), soundName, lastErrorStr);
|
||||
|
||||
for (size_t i = 0; i < ARRAYSIZE(Game::milesGlobal->streamReadInfo); i++)
|
||||
{
|
||||
if (0 == std::strncmp(Game::milesGlobal->streamReadInfo[i].path, soundName, ARRAYSIZE(Game::milesGlobal->streamReadInfo[i].path)))
|
||||
{
|
||||
Game::milesGlobal->streamReadInfo[i].path[0] = '\x00'; // This kills it and make sure it doesn't get played again for now
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Logger::Logger()
|
||||
{
|
||||
// Print sound aliases errors
|
||||
if (!Dedicated::IsEnabled())
|
||||
{
|
||||
Utils::Hook(0x64BA67, PrintAliasError, HOOK_CALL).install()->quick();
|
||||
}
|
||||
|
||||
Utils::Hook(0x642139, BuildOSPath_Stub, HOOK_JUMP).install()->quick();
|
||||
|
||||
Scheduler::Loop(Frame, Scheduler::Pipeline::SERVER);
|
||||
|
@ -23,12 +23,12 @@ namespace Components
|
||||
|
||||
static void Print(const std::string_view& fmt)
|
||||
{
|
||||
PrintInternal(Game::CON_CHANNEL_DONT_FILTER, fmt, std::make_format_args(0));
|
||||
PrintInternal(Game::CON_CHANNEL_DONT_FILTER, fmt, std::make_format_args());
|
||||
}
|
||||
|
||||
static void Print(Game::conChannel_t channel, const std::string_view& fmt)
|
||||
{
|
||||
PrintInternal(channel, fmt, std::make_format_args(0));
|
||||
PrintInternal(channel, fmt, std::make_format_args());
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
@ -47,7 +47,7 @@ namespace Components
|
||||
|
||||
static void Error(Game::errorParm_t error, const std::string_view& fmt)
|
||||
{
|
||||
ErrorInternal(error, fmt, std::make_format_args(0));
|
||||
ErrorInternal(error, fmt, std::make_format_args());
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
@ -59,7 +59,7 @@ namespace Components
|
||||
|
||||
static void Warning(Game::conChannel_t channel, const std::string_view& fmt)
|
||||
{
|
||||
WarningInternal(channel, fmt, std::make_format_args(0));
|
||||
WarningInternal(channel, fmt, std::make_format_args());
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
@ -71,7 +71,7 @@ namespace Components
|
||||
|
||||
static void PrintError(Game::conChannel_t channel, const std::string_view& fmt)
|
||||
{
|
||||
PrintErrorInternal(channel, fmt, std::make_format_args(0));
|
||||
PrintErrorInternal(channel, fmt, std::make_format_args());
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
@ -83,7 +83,7 @@ namespace Components
|
||||
|
||||
static void PrintFail2Ban(const std::string_view& fmt)
|
||||
{
|
||||
PrintFail2BanInternal(fmt, std::make_format_args(0));
|
||||
PrintFail2BanInternal(fmt, std::make_format_args());
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
|
@ -103,7 +103,7 @@ namespace Components
|
||||
|
||||
const char* Maps::LoadArenaFileStub(const char* name, char* buffer, int size)
|
||||
{
|
||||
std::string data = RawFiles::ReadRawFile(name, buffer, size);
|
||||
std::string data;
|
||||
|
||||
if (Maps::UserMap.isValid())
|
||||
{
|
||||
@ -116,6 +116,10 @@ namespace Components
|
||||
data = Utils::IO::ReadFile(arena);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
data = RawFiles::ReadRawFile(name, buffer, size);
|
||||
}
|
||||
|
||||
strncpy_s(buffer, size, data.data(), _TRUNCATE);
|
||||
return buffer;
|
||||
@ -314,6 +318,28 @@ namespace Components
|
||||
}
|
||||
}
|
||||
|
||||
void Maps::ForceRefreshArenas()
|
||||
{
|
||||
if (Game::Sys_IsMainThread())
|
||||
{
|
||||
if (*Game::g_quitRequested)
|
||||
{
|
||||
// No need to refresh if we're exiting the game
|
||||
return;
|
||||
}
|
||||
|
||||
Game::sharedUiInfo_t* uiInfo = reinterpret_cast<Game::sharedUiInfo_t*>(0x62E4B78);
|
||||
uiInfo->updateArenas = 1;
|
||||
Game::UI_UpdateArenas();
|
||||
}
|
||||
else
|
||||
{
|
||||
// Dangerous!!
|
||||
assert(false && "Arenas refreshed from wrong thread??");
|
||||
Logger::Print("Tried to refresh arenas from a thread that is NOT the main thread!! This could have lead to a crash. Please report this bug and how you got it!");
|
||||
}
|
||||
}
|
||||
|
||||
// TODO : Remove hook entirely?
|
||||
void Maps::GetBSPName(char* buffer, size_t size, const char* format, const char* mapname)
|
||||
{
|
||||
@ -845,12 +871,6 @@ namespace Components
|
||||
// Load usermap arena file
|
||||
Utils::Hook(0x630A88, Maps::LoadArenaFileStub, HOOK_CALL).install()->quick();
|
||||
|
||||
// Always refresh arena when loading or unloading a zone
|
||||
Utils::Hook::Nop(0x485017, 2);
|
||||
Utils::Hook::Nop(0x4BDFB7, 2); // Unknown
|
||||
Utils::Hook::Nop(0x45ED6F, 2); // loadGameInfo
|
||||
Utils::Hook::Nop(0x4A5888, 2); // UI_InitOnceForAllClients
|
||||
|
||||
// Allow hiding specific smodels
|
||||
Utils::Hook(0x50E67C, Maps::HideModelStub, HOOK_CALL).install()->quick();
|
||||
|
||||
|
@ -13,7 +13,7 @@ namespace Components
|
||||
{
|
||||
ZeroMemory(&this->searchPath, sizeof this->searchPath);
|
||||
this->hash = Maps::GetUsermapHash(this->mapname);
|
||||
Game::UI_UpdateArenas();
|
||||
Maps::ForceRefreshArenas();
|
||||
}
|
||||
|
||||
~UserMapContainer()
|
||||
@ -29,7 +29,10 @@ namespace Components
|
||||
{
|
||||
bool wasValid = this->isValid();
|
||||
this->mapname.clear();
|
||||
if (wasValid) Game::UI_UpdateArenas();
|
||||
if (wasValid)
|
||||
{
|
||||
Maps::ForceRefreshArenas();
|
||||
}
|
||||
}
|
||||
|
||||
void loadIwd();
|
||||
@ -95,6 +98,8 @@ namespace Components
|
||||
|
||||
static Dvar::Var RListSModels;
|
||||
|
||||
static void ForceRefreshArenas();
|
||||
|
||||
static void GetBSPName(char* buffer, size_t size, const char* format, const char* mapname);
|
||||
static void LoadAssetRestrict(Game::XAssetType type, Game::XAssetHeader asset, const std::string& name, bool* restrict);
|
||||
static void LoadMapZones(Game::XZoneInfo *zoneInfo, unsigned int zoneCount, int sync);
|
||||
|
@ -3,6 +3,8 @@
|
||||
|
||||
namespace Components
|
||||
{
|
||||
constexpr auto BASE_PLAYERSTATS_VERSION = 155;
|
||||
|
||||
Utils::Memory::Allocator StructuredData::MemAllocator;
|
||||
|
||||
const char* StructuredData::EnumTranslation[COUNT] =
|
||||
@ -26,6 +28,11 @@ namespace Components
|
||||
{
|
||||
if (!data || type >= StructuredData::PlayerDataType::COUNT) return;
|
||||
|
||||
// Reallocate them before patching
|
||||
Game::StructuredDataEnum* newEnums = MemAllocator.allocateArray<Game::StructuredDataEnum>(data->enumCount);
|
||||
std::memcpy(newEnums, data->enums, sizeof(Game::StructuredDataEnum) * data->enumCount);
|
||||
data->enums = newEnums;
|
||||
|
||||
Game::StructuredDataEnum* dataEnum = &data->enums[type];
|
||||
|
||||
// Build index-sorted data vector
|
||||
@ -86,24 +93,53 @@ namespace Components
|
||||
}
|
||||
|
||||
void StructuredData::PatchCustomClassLimit(Game::StructuredDataDef* data, int count)
|
||||
{
|
||||
constexpr auto CLASS_ARRAY = 5;
|
||||
const auto originalClassCount = data->indexedArrays[CLASS_ARRAY].arraySize;
|
||||
|
||||
if (count != originalClassCount)
|
||||
{
|
||||
const int customClassSize = 64;
|
||||
|
||||
for (int i = 0; i < data->structs[0].propertyCount; ++i)
|
||||
// We need to recreate the struct list cause it's used in order definitions
|
||||
auto newStructs = StructuredData::MemAllocator.allocateArray<Game::StructuredDataStruct>(data->structCount);
|
||||
std::memcpy(newStructs, data->structs, data->structCount * sizeof(Game::StructuredDataStruct));
|
||||
data->structs = newStructs;
|
||||
|
||||
constexpr auto structIndex = 0;
|
||||
{
|
||||
// 3003 is the offset of the customClasses structure
|
||||
if (data->structs[0].properties[i].offset >= 3643)
|
||||
auto strct = &data->structs[structIndex];
|
||||
|
||||
auto newProperties = StructuredData::MemAllocator.allocateArray<Game::StructuredDataStructProperty>(strct->propertyCount);
|
||||
std::memcpy(newProperties, strct->properties, strct->propertyCount * sizeof(Game::StructuredDataStructProperty));
|
||||
strct->properties = newProperties;
|
||||
|
||||
for (int propertyIndex = 0; propertyIndex < strct->propertyCount; ++propertyIndex)
|
||||
{
|
||||
// 3643 is the offset of the customClasses structure
|
||||
if (strct->properties[propertyIndex].offset >= 3643)
|
||||
{
|
||||
// -10 because 10 is the default amount of custom classes.
|
||||
data->structs[0].properties[i].offset += ((count - 10) * customClassSize);
|
||||
strct->properties[propertyIndex].offset += ((count - originalClassCount) * customClassSize);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// update structure size
|
||||
data->size += ((count - 10) * customClassSize);
|
||||
data->size += ((count - originalClassCount) * customClassSize);
|
||||
|
||||
// Update amount of custom classes
|
||||
data->indexedArrays[5].arraySize = count;
|
||||
if (data->indexedArrays[CLASS_ARRAY].arraySize != count)
|
||||
{
|
||||
// We need to recreate the whole array - this reference could be reused accross definitions
|
||||
auto newIndexedArray = StructuredData::MemAllocator.allocateArray<Game::StructuredDataIndexedArray>(data->indexedArrayCount);
|
||||
std::memcpy(newIndexedArray, data->indexedArrays, data->indexedArrayCount * sizeof(Game::StructuredDataIndexedArray));
|
||||
data->indexedArrays = newIndexedArray;
|
||||
|
||||
// Add classes
|
||||
data->indexedArrays[CLASS_ARRAY].arraySize = count;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void StructuredData::PatchAdditionalData(Game::StructuredDataDef* data, std::unordered_map<std::string, std::string>& patches)
|
||||
@ -119,27 +155,45 @@ namespace Components
|
||||
|
||||
bool StructuredData::UpdateVersionOffsets(Game::StructuredDataDefSet* set, Game::StructuredDataBuffer* buffer, Game::StructuredDataDef* whatever)
|
||||
{
|
||||
Game::StructuredDataDef* newDef = &set->defs[0];
|
||||
Game::StructuredDataDef* oldDef = &set->defs[0];
|
||||
|
||||
for (unsigned int i = 0; i < set->defCount; ++i)
|
||||
if (set->defCount > 1)
|
||||
{
|
||||
if (newDef->version < set->defs[i].version)
|
||||
{
|
||||
newDef = &set->defs[i];
|
||||
}
|
||||
int bufferVersion = *reinterpret_cast<int*>(buffer->data);
|
||||
|
||||
if (set->defs[i].version == *reinterpret_cast<int*>(buffer->data))
|
||||
for (size_t i = 0; i < set->defCount; i++)
|
||||
{
|
||||
oldDef = &set->defs[i];
|
||||
}
|
||||
if (set->defs[i].version == bufferVersion)
|
||||
{
|
||||
if (i == 0)
|
||||
{
|
||||
// No update to conduct
|
||||
}
|
||||
else
|
||||
{
|
||||
Game::StructuredDataDef* newDef = &set->defs[i - 1];
|
||||
Game::StructuredDataDef* oldDef = &set->defs[i];
|
||||
|
||||
if (newDef->version >= 159 && oldDef->version <= 158)
|
||||
if (newDef->version == 159 && oldDef->version <= 158)
|
||||
{
|
||||
// this should move the data 320 bytes infront
|
||||
std::memmove(&buffer->data[3963], &buffer->data[3643], oldDef->size - 3643);
|
||||
}
|
||||
else if (newDef->version > 159 && false)
|
||||
{
|
||||
// 159 cannot be translated upwards and it's hard to say why
|
||||
// Reading it fails in various ways
|
||||
// might be the funky class bump...?
|
||||
|
||||
Command::Execute("setPlayerData prestige 10");
|
||||
Command::Execute("setPlayerData experience 2516000");
|
||||
}
|
||||
|
||||
return Utils::Hook::Call<bool(void*, void*, void*)>(0x456830)(set, buffer, whatever);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return Utils::Hook::Call<bool(void*, void*, void*)>(0x456830)(set, buffer, whatever);
|
||||
}
|
||||
|
||||
// StructuredData_UpdateVersion
|
||||
return Utils::Hook::Call<bool(void*, void*, void*)>(0x456830)(set, buffer, whatever);
|
||||
@ -182,7 +236,7 @@ namespace Components
|
||||
return;
|
||||
}
|
||||
|
||||
if (data->defs[0].version != 155)
|
||||
if (data->defs[0].version != BASE_PLAYERSTATS_VERSION)
|
||||
{
|
||||
Logger::Error(Game::ERR_FATAL, "Initial PlayerDataDef is not version 155, patching not possible!");
|
||||
return;
|
||||
@ -262,16 +316,10 @@ namespace Components
|
||||
auto* newData = StructuredData::MemAllocator.allocateArray<Game::StructuredDataDef>(data->defCount + patchDefinitions.size());
|
||||
std::memcpy(&newData[patchDefinitions.size()], data->defs, sizeof Game::StructuredDataDef * data->defCount);
|
||||
|
||||
// Prepare the buffers
|
||||
// Set the versions
|
||||
for (unsigned int i = 0; i < patchDefinitions.size(); ++i)
|
||||
{
|
||||
std::memcpy(&newData[i], data->defs, sizeof Game::StructuredDataDef);
|
||||
newData[i].version = (patchDefinitions.size() - i) + 155;
|
||||
|
||||
// Reallocate the enum array
|
||||
auto* newEnums = StructuredData::MemAllocator.allocateArray<Game::StructuredDataEnum>(data->defs->enumCount);
|
||||
std::memcpy(newEnums, data->defs->enums, sizeof Game::StructuredDataEnum * data->defs->enumCount);
|
||||
newData[i].enums = newEnums;
|
||||
newData[i].version = (patchDefinitions.size() - i) + BASE_PLAYERSTATS_VERSION;
|
||||
}
|
||||
|
||||
// Apply new data
|
||||
@ -279,10 +327,18 @@ namespace Components
|
||||
data->defCount += patchDefinitions.size();
|
||||
|
||||
// Patch the definition
|
||||
for (unsigned int i = 0; i < data->defCount; ++i)
|
||||
for (int i = data->defCount - 1; i >= 0; --i)
|
||||
{
|
||||
// No need to patch version 155
|
||||
if (newData[i].version == 155) continue;
|
||||
if (newData[i].version == BASE_PLAYERSTATS_VERSION)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// We start from the previous one
|
||||
const auto version = newData[i].version;
|
||||
data->defs[i] = data->defs[i + 1];
|
||||
newData[i].version = version;
|
||||
|
||||
if (patchDefinitions.contains(newData[i].version))
|
||||
{
|
||||
|
@ -2,11 +2,14 @@
|
||||
#include "ClientCommand.hpp"
|
||||
#include "MapRotation.hpp"
|
||||
#include "Vote.hpp"
|
||||
#include "Events.hpp"
|
||||
|
||||
using namespace Utils::String;
|
||||
|
||||
namespace Components
|
||||
{
|
||||
Dvar::Var Vote::SV_VotesRequired;
|
||||
|
||||
std::unordered_map<std::string, Vote::CommandHandler> Vote::VoteCommands =
|
||||
{
|
||||
{"map_restart", HandleMapRestart},
|
||||
@ -37,6 +40,17 @@ namespace Components
|
||||
Game::SV_SetConfigstring(Game::CS_VOTE_NO, VA("%i", Game::level->voteNo));
|
||||
}
|
||||
|
||||
int Vote::VotesRequired()
|
||||
{
|
||||
auto votesRequired = Vote::SV_VotesRequired.get<int>();
|
||||
|
||||
if (votesRequired > 0)
|
||||
{
|
||||
return votesRequired;
|
||||
}
|
||||
return Game::level->numConnectedClients / 2 + 1;
|
||||
}
|
||||
|
||||
bool Vote::IsInvalidVoteString(const std::string& input)
|
||||
{
|
||||
static const char* separators[] = { "\n", "\r", ";" };
|
||||
@ -204,7 +218,7 @@ namespace Components
|
||||
return;
|
||||
}
|
||||
|
||||
if (Game::level->numConnectedClients < 2)
|
||||
if (Game::level->numConnectedClients < VotesRequired())
|
||||
{
|
||||
Game::SV_GameSendServerCommand(ent - Game::g_entities, Game::SV_CMD_CAN_IGNORE, VA("%c \"GAME_VOTINGNOTENOUGHPLAYERS\"", 0x65));
|
||||
return;
|
||||
@ -218,7 +232,7 @@ namespace Components
|
||||
return;
|
||||
}
|
||||
|
||||
if (ent->client->sess.voteCount >= 3)
|
||||
if (ent->client->sess.voteCount >= VotesRequired())
|
||||
{
|
||||
Game::SV_GameSendServerCommand(ent - Game::g_entities, Game::SV_CMD_CAN_IGNORE, VA("%c \"GAME_MAXVOTESCALLED\"", 0x65));
|
||||
return;
|
||||
@ -321,6 +335,10 @@ namespace Components
|
||||
// Replicate g_allowVote
|
||||
Utils::Hook::Set<std::uint32_t>(0x5E3A4F, Game::DVAR_INTERNAL | Game::DVAR_CODINFO);
|
||||
|
||||
Events::OnDvarInit([]{
|
||||
Vote::SV_VotesRequired = Game::Dvar_RegisterInt("sv_votesRequired", 0, 0, 18, Game::DVAR_NONE, "Set the amount of votes required for a vote to pass.\n0 = (players / 2) + 1");
|
||||
});
|
||||
|
||||
ClientCommand::Add("callvote", Cmd_CallVote_f);
|
||||
ClientCommand::Add("vote", Cmd_Vote_f);
|
||||
|
||||
|
@ -11,11 +11,14 @@ namespace Components
|
||||
using CommandHandler = std::function<bool(const Game::gentity_s* ent, const Command::ServerParams* params)>;
|
||||
static std::unordered_map<std::string, CommandHandler> VoteCommands;
|
||||
|
||||
static Dvar::Var SV_VotesRequired;
|
||||
|
||||
static constexpr auto* CallVoteDesc = "%c \"GAME_VOTECOMMANDSARE\x15 map_restart, map_rotate, map <mapname>, g_gametype <typename>, typemap <typename> <mapname>, "
|
||||
"kick <player>, tempBanUser <player>\"";
|
||||
|
||||
static void DisplayVote(const Game::gentity_s* ent);
|
||||
static bool IsInvalidVoteString(const std::string& input);
|
||||
static int VotesRequired();
|
||||
|
||||
static bool HandleMapRestart(const Game::gentity_s* ent, const Command::ServerParams* params);
|
||||
static bool HandleMapRotate(const Game::gentity_s* ent, const Command::ServerParams* params);
|
||||
|
@ -17,10 +17,13 @@ namespace Game
|
||||
G_DebugLineWithDuration_t G_DebugLineWithDuration = G_DebugLineWithDuration_t(0x4C3280);
|
||||
|
||||
gentity_s* g_entities = reinterpret_cast<gentity_s*>(0x18835D8);
|
||||
bool* g_quitRequested = reinterpret_cast<bool*>(0x649FB61);
|
||||
|
||||
NetField* clientStateFields = reinterpret_cast<Game::NetField*>(0x741E40);
|
||||
size_t clientStateFieldsCount = Utils::Hook::Get<size_t>(0x7433C8);
|
||||
|
||||
MssLocal* milesGlobal = reinterpret_cast<MssLocal*>(0x649A1A0);
|
||||
|
||||
const char* origErrorMsg = reinterpret_cast<const char*>(0x79B124);
|
||||
|
||||
XModel* G_GetModel(const int index)
|
||||
|
@ -52,10 +52,13 @@ namespace Game
|
||||
constexpr std::size_t MAX_GENTITIES = 2048;
|
||||
constexpr std::size_t ENTITYNUM_NONE = MAX_GENTITIES - 1;
|
||||
extern gentity_s* g_entities;
|
||||
extern bool* g_quitRequested;
|
||||
|
||||
// This does not belong anywhere else
|
||||
extern NetField* clientStateFields;
|
||||
extern size_t clientStateFieldsCount;
|
||||
extern MssLocal* milesGlobal;
|
||||
|
||||
|
||||
extern const char* origErrorMsg;
|
||||
|
||||
|
@ -5519,6 +5519,32 @@ namespace Game
|
||||
StructuredDataEnumEntry* entries;
|
||||
};
|
||||
|
||||
enum LookupResultDataType
|
||||
{
|
||||
LOOKUP_RESULT_INT = 0x0,
|
||||
LOOKUP_RESULT_BOOL = 0x1,
|
||||
LOOKUP_RESULT_STRING = 0x2,
|
||||
LOOKUP_RESULT_FLOAT = 0x3,
|
||||
LOOKUP_RESULT_SHORT = 0x4,
|
||||
};
|
||||
|
||||
enum LookupState
|
||||
{
|
||||
LOOKUP_IN_PROGRESS = 0x0,
|
||||
LOOKUP_FINISHED = 0x1,
|
||||
LOOKUP_ERROR = 0x2,
|
||||
};
|
||||
|
||||
enum LookupError
|
||||
{
|
||||
LOOKUP_ERROR_NONE = 0x0,
|
||||
LOOKUP_ERROR_WRONG_DATA_TYPE = 0x1,
|
||||
LOOKUP_ERROR_INDEX_OUTSIDE_BOUNDS = 0x2,
|
||||
LOOKUP_ERROR_INVALID_STRUCT_PROPERTY = 0x3,
|
||||
LOOKUP_ERROR_INVALID_ENUM_VALUE = 0x4,
|
||||
LOOKUP_ERROR_COUNT = 0x5,
|
||||
};
|
||||
|
||||
enum StructuredDataTypeCategory
|
||||
{
|
||||
DATA_INT = 0x0,
|
||||
@ -5594,6 +5620,15 @@ namespace Game
|
||||
unsigned int size;
|
||||
};
|
||||
|
||||
|
||||
struct StructuredDataLookup
|
||||
{
|
||||
StructuredDataDef* def;
|
||||
StructuredDataType* type;
|
||||
unsigned int offset;
|
||||
LookupError error;
|
||||
};
|
||||
|
||||
struct StructuredDataDefSet
|
||||
{
|
||||
const char* name;
|
||||
@ -11101,6 +11136,159 @@ namespace Game
|
||||
FFD_USER_MAP = 0x2,
|
||||
};
|
||||
|
||||
struct ASISTAGE
|
||||
{
|
||||
int(__stdcall* ASI_stream_open)(unsigned int, int(__stdcall*)(unsigned int, void*, int, int), unsigned int);
|
||||
int(__stdcall* ASI_stream_process)(int, void*, int);
|
||||
int(__stdcall* ASI_stream_seek)(int, int);
|
||||
int(__stdcall* ASI_stream_close)(int);
|
||||
int(__stdcall* ASI_stream_property)(int, unsigned int, void*, const void*, void*);
|
||||
unsigned int INPUT_BIT_RATE;
|
||||
unsigned int INPUT_SAMPLE_RATE;
|
||||
unsigned int INPUT_BITS;
|
||||
unsigned int INPUT_CHANNELS;
|
||||
unsigned int OUTPUT_BIT_RATE;
|
||||
unsigned int OUTPUT_SAMPLE_RATE;
|
||||
unsigned int OUTPUT_BITS;
|
||||
unsigned int OUTPUT_CHANNELS;
|
||||
unsigned int OUTPUT_RESERVOIR;
|
||||
unsigned int POSITION;
|
||||
unsigned int PERCENT_DONE;
|
||||
unsigned int MIN_INPUT_BLOCK_SIZE;
|
||||
unsigned int RAW_RATE;
|
||||
unsigned int RAW_BITS;
|
||||
unsigned int RAW_CHANNELS;
|
||||
unsigned int REQUESTED_RATE;
|
||||
unsigned int REQUESTED_BITS;
|
||||
unsigned int REQUESTED_CHANS;
|
||||
unsigned int STREAM_SEEK_POS;
|
||||
unsigned int DATA_START_OFFSET;
|
||||
unsigned int DATA_LEN;
|
||||
int stream;
|
||||
};
|
||||
|
||||
struct _STREAM
|
||||
{
|
||||
int block_oriented;
|
||||
int using_ASI;
|
||||
ASISTAGE* ASI;
|
||||
void* samp;
|
||||
unsigned int fileh;
|
||||
char* bufs[3];
|
||||
unsigned int bufsizes[3];
|
||||
int reset_ASI[3];
|
||||
int reset_seek_pos[3];
|
||||
int bufstart[3];
|
||||
void* asyncs[3];
|
||||
int loadedbufstart[2];
|
||||
int loadedorder[2];
|
||||
int loadorder;
|
||||
int bufsize;
|
||||
int readsize;
|
||||
unsigned int buf1;
|
||||
int size1;
|
||||
unsigned int buf2;
|
||||
int size2;
|
||||
unsigned int buf3;
|
||||
int size3;
|
||||
unsigned int datarate;
|
||||
int filerate;
|
||||
int filetype;
|
||||
unsigned int fileflags;
|
||||
int totallen;
|
||||
int substart;
|
||||
int sublen;
|
||||
int subpadding;
|
||||
unsigned int blocksize;
|
||||
int padding;
|
||||
int padded;
|
||||
int loadedsome;
|
||||
unsigned int startpos;
|
||||
unsigned int totalread;
|
||||
unsigned int loopsleft;
|
||||
unsigned int error;
|
||||
int preload;
|
||||
unsigned int preloadpos;
|
||||
int noback;
|
||||
int alldone;
|
||||
int primeamount;
|
||||
int readatleast;
|
||||
int playcontrol;
|
||||
void(__stdcall* callback)(_STREAM*);
|
||||
int user_data[8];
|
||||
void* next;
|
||||
int autostreaming;
|
||||
int docallback;
|
||||
};
|
||||
|
||||
enum SND_EQTYPE
|
||||
{
|
||||
SND_EQTYPE_FIRST = 0x0,
|
||||
SND_EQTYPE_LOWPASS = 0x0,
|
||||
SND_EQTYPE_HIGHPASS = 0x1,
|
||||
SND_EQTYPE_LOWSHELF = 0x2,
|
||||
SND_EQTYPE_HIGHSHELF = 0x3,
|
||||
SND_EQTYPE_BELL = 0x4,
|
||||
SND_EQTYPE_LAST = 0x4,
|
||||
SND_EQTYPE_COUNT = 0x5,
|
||||
SND_EQTYPE_INVALID = 0x5,
|
||||
};
|
||||
|
||||
struct __declspec(align(4)) SndEqParams
|
||||
{
|
||||
SND_EQTYPE type;
|
||||
float gain;
|
||||
float freq;
|
||||
float q;
|
||||
bool enabled;
|
||||
};
|
||||
|
||||
struct MssEqInfo
|
||||
{
|
||||
SndEqParams params[3][64];
|
||||
};
|
||||
|
||||
struct MssFileHandle
|
||||
{
|
||||
unsigned int id;
|
||||
MssFileHandle* next;
|
||||
int handle;
|
||||
char fileName[128];
|
||||
unsigned int hashCode;
|
||||
int offset;
|
||||
int fileOffset;
|
||||
int fileLength;
|
||||
};
|
||||
|
||||
struct __declspec(align(4)) MssStreamReadInfo
|
||||
{
|
||||
char path[256];
|
||||
int timeshift;
|
||||
float fraction;
|
||||
int startDelay;
|
||||
_STREAM* handle;
|
||||
bool readError;
|
||||
};
|
||||
|
||||
struct MssLocal
|
||||
{
|
||||
struct _DIG_DRIVER* driver;
|
||||
struct _SAMPLE* handle_sample[40];
|
||||
_STREAM* handle_stream[12];
|
||||
bool voiceEqDisabled[52];
|
||||
MssEqInfo eq[2];
|
||||
float eqLerp;
|
||||
unsigned int eqFilter;
|
||||
int currentRoomtype;
|
||||
MssFileHandle fileHandle[12];
|
||||
MssFileHandle* freeFileHandle;
|
||||
bool isMultiChannel;
|
||||
float realVolume[12];
|
||||
int playbackRate[52];
|
||||
MssStreamReadInfo streamReadInfo[12];
|
||||
};
|
||||
|
||||
|
||||
#pragma endregion
|
||||
|
||||
#ifndef IDA
|
||||
|
Loading…
Reference in New Issue
Block a user