Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions client/red4ext/src/CommandLine.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ inline std::optional<std::string> ArgumentFromCommandLineUntilNextSpace(char* co
}

inline std::optional<std::string> ParseHostFromCommandLine(char* commandLine) {
const auto needle = "--cyberverse-server-address=";
constexpr auto needle = "--cyberverse-server-address=";
constexpr auto needleLen = std::char_traits<char>::length(needle);
return ArgumentFromCommandLineUntilNextSpace(commandLine, needle, needleLen);
}

inline std::optional<uint16_t> ParsePortFromCommandLine(char* commandLine) {
const auto needle = "--cyberverse-server-port=";
constexpr auto needle = "--cyberverse-server-port=";
constexpr auto needleLen = std::char_traits<char>::length(needle);
const auto portString = ArgumentFromCommandLineUntilNextSpace(commandLine, needle, needleLen);
if (!portString.has_value())
Expand Down
9 changes: 9 additions & 0 deletions client/red4ext/src/NetworkGameSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include "PlayerActionTracker.h"
#include "PlayerSync/InterpolationData.h"
#include "Red/ClassDescriptorCompat.hpp"
#include "RED4ext/Scripting/Natives/Generated/AI/Command.hpp"
#include "RED4ext/Scripting/Natives/Generated/Vector4.hpp"
#include "RED4ext/Scripting/Natives/entEntityID.hpp"
Expand Down Expand Up @@ -74,6 +75,14 @@ class NetworkGameSystem : public Red::IGameSystem
RTTI_IMPL_ALLOCATOR();
};

namespace Red
{
template<>
class ClassDescriptorDefaultImpl<::NetworkGameSystem> : public CyberverseClassDescriptorDefaultImpl<::NetworkGameSystem>
{
};
} // namespace Red

RTTI_DEFINE_CLASS(NetworkGameSystem, {
RTTI_METHOD(EnqueueLoadLastCheckpoint);
RTTI_PROPERTY(FullyConnected);
Expand Down
12 changes: 11 additions & 1 deletion client/red4ext/src/PlayerActionTracker.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#pragma once

#include <RED4ext/RED4ext.hpp>
#include "RedLib.hpp"
#include <RedLib.hpp>

#include "Red/ClassDescriptorCompat.hpp"

#include "RED4ext/CName.hpp"
#include "RED4ext/Scripting/Natives/Generated/game/Object.hpp"
Expand All @@ -27,6 +29,14 @@ class PlayerActionTracker final : public Red::IScriptable
RTTI_IMPL_ALLOCATOR();
};

namespace Red
{
template<>
class ClassDescriptorDefaultImpl<::PlayerActionTracker> : public CyberverseClassDescriptorDefaultImpl<::PlayerActionTracker>
{
};
} // namespace Red

RTTI_DEFINE_CLASS(PlayerActionTracker, {
RTTI_METHOD(RecordPlayerAction);
RTTI_METHOD(OnShoot);
Expand Down
111 changes: 111 additions & 0 deletions client/red4ext/src/Red/ClassDescriptorCompat.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
#pragma once

#include <cstring>
#include <RedLib.hpp>

namespace Red
{
template<typename TClass>
class CyberverseClassDescriptorDefaultImpl : public ClassDescriptor<TClass>
{
const bool IsEqual(const ScriptInstance aLhs, const ScriptInstance aRhs, uint32_t a3) final // 48
{
if constexpr (Detail::IsConstructionForwarded<TClass>)
{
if (!CClass::parent->flags.isAbstract)
{
return CClass::parent->IsEqual(aLhs, aRhs, a3);
}
return false;
}
else
{
using func_t = bool (*)(CClass*, const ScriptInstance, const ScriptInstance, uint32_t);
#if defined(RED4EXT_V1_SDK_VERSION_CURRENT) || defined(RED4EXT_SDK_0_5_0)
static UniversalRelocFunc<func_t> func(RED4ext::Detail::AddressHashes::TTypedClass_IsEqual);
#else
static RelocFunc<func_t> func(RED4ext::Addresses::TTypedClass_IsEqual);
#endif
return func(this, aLhs, aRhs, a3);
}
}

void Assign(ScriptInstance aLhs, const ScriptInstance aRhs) const final // 50
{
if constexpr (Detail::IsConstructionForwarded<TClass>)
{
if (!CClass::parent->flags.isAbstract)
{
CClass::parent->Assign(aLhs, aRhs);
}
}
else if constexpr (std::is_copy_assignable_v<TClass>)
{
*reinterpret_cast<TClass*>(aLhs) = *reinterpret_cast<const TClass*>(aRhs);
}
else if constexpr (std::is_copy_constructible_v<TClass>)
{
reinterpret_cast<TClass*>(aLhs)->~TClass();
new (aLhs) TClass(*reinterpret_cast<const TClass*>(aRhs));
}
}

[[nodiscard]] Memory::IAllocator* GetAllocator() const final // B8
{
if constexpr (Detail::HasStaticAllocator<TClass>)
{
return Detail::ResolveAllocatorType<TClass>::Get();
}
else if constexpr (Detail::IsAllocationForwarded<TClass> || Detail::IsConstructionForwarded<TClass>)
{
return CClass::parent->GetAllocator();
}
else
{
return Memory::RTTIAllocator::Get();
}
}

void ConstructCls(void* aMemory) const final // D8
{
if constexpr (Detail::IsConstructionForwarded<TClass>)
{
if (!CClass::parent->flags.isAbstract)
{
CClass::parent->ConstructCls(aMemory);
}
}
else if constexpr (!std::is_abstract_v<TClass>)
{
new (aMemory) TClass();
}
}

void DestructCls(void* aMemory) const final // E0
{
if constexpr (Detail::IsConstructionForwarded<TClass>)
{
if (!CClass::parent->flags.isAbstract)
{
CClass::parent->DestructCls(aMemory);
}
}
else
{
reinterpret_cast<TClass*>(aMemory)->~TClass();
}
}

[[nodiscard]] void* AllocMemory() const final // E8
{
auto classAlignment = CClass::GetAlignment();
auto alignedSize = AlignUp(CClass::GetSize(), classAlignment);

auto allocator = GetAllocator();
auto allocResult = allocator->AllocAligned(alignedSize, classAlignment);

std::memset(allocResult.memory, 0, allocResult.size);
return allocResult.memory;
}
};
} // namespace Red
3 changes: 1 addition & 2 deletions client/red4ext/src/Utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include "RED4ext/Scripting/Natives/Generated/ent/EntityID.hpp"
#include "RED4ext/Scripting/Natives/Generated/game/Object.hpp"
#include "RED4ext/Scripting/Natives/Generated/vehicle/BaseObject.hpp"
#include "RedLib.hpp"
#include <RedLib.hpp>

namespace Cyberverse::Utils
{
Expand Down Expand Up @@ -106,4 +106,3 @@ namespace Cyberverse::Utils
return dbId;
}
}