remake - v2

This commit is contained in:
2026-08-10 14:22:03 +02:00
parent f1a5250613
commit b0e8588bef
6 changed files with 533 additions and 39 deletions

View File

@@ -5,6 +5,7 @@
#include <cstdint>
#include <array>
#include <string>
#include <unordered_map>
#include <vector>
enum class FieldType
@@ -19,6 +20,8 @@ enum class FieldType
Int64,
UInt64,
Float,
Bytes,
StringPtr,
};
struct FieldPathSegment
@@ -45,6 +48,22 @@ struct AppliedOverride
uint8_t* address {};
FieldType type {};
uint64_t originalBits {};
std::vector<uint8_t> originalBytes;
};
struct CompiledOverrideRule
{
int id {};
int recipientSlot {-1};
int entityIndex {-1};
std::string className;
std::string fieldPath;
int32_t offset {};
int32_t size {};
FieldType type {FieldType::Int32};
std::vector<uint8_t> value;
std::string stringValue;
bool enabled {true};
};
class OverrideManager
@@ -52,6 +71,10 @@ class OverrideManager
public:
void Clear();
bool AddFromTokens(int argc, const char** argv, std::string& error);
int AddCompiledRule(int recipientSlot, int entityIndex, const char* className, const char* fieldPath, const char* type, const char* value, std::string& error);
bool RemoveRule(int id);
bool MarkRuleDirty(int id);
bool MarkEntityFieldDirty(int entityIndex, const char* className, const char* fieldPath, std::string& error);
bool AddWeaponItemDefRule(int recipientSlot, const char* target, uint16_t itemDefinitionIndex, std::string& error);
bool SetHealthMoneyTest(bool enabled, std::string& error);
bool SetHealth42Test(bool enabled, std::string& error);
@@ -60,13 +83,15 @@ public:
void Dump() const;
void SetTrace(bool value) { m_trace = value; }
bool Trace() const { return m_trace; }
size_t RuleCount() const { return m_rules.size(); }
size_t RuleCount() const { return m_rules.size() + m_compiledRules.size(); }
size_t DynamicRuleCount() const { return (m_healthMoneyTest ? 1 : 0) + (m_health42Test ? 1 : 0); }
bool Empty() const { return m_rules.empty() && !m_healthMoneyTest && !m_health42Test; }
bool Empty() const { return m_rules.empty() && m_compiledRules.empty() && !m_healthMoneyTest && !m_health42Test; }
bool Health42Test() const { return m_health42Test; }
bool TryGetHealth42Value(CPlayerSlot recipient, int& value) const;
bool HasPackedOverrides() const { return !m_compiledRules.empty() || m_health42Test; }
std::vector<AppliedOverride> ApplyForRecipient(CPlayerSlot slot);
std::vector<AppliedOverride> ApplyForPackedEntity(CPlayerSlot recipient, int entityIndex, void* entityData);
std::vector<AppliedOverride> ApplyGlobalHealth42();
int MarkPlayerHealthDirty();
void Restore(const std::vector<AppliedOverride>& applied);
@@ -76,8 +101,14 @@ private:
uintptr_t FindFirstEntityForTarget(const OverrideRule& rule) const;
uint8_t* ResolveAddress(uintptr_t entity, const OverrideRule& rule) const;
void ApplyHealthMoneyTest(CPlayerSlot slot, std::vector<AppliedOverride>& applied);
bool ResolveFieldPath(const char* className, const char* fieldPath, int32_t& offset, int32_t& size, std::string& typeName, std::string& error) const;
bool CompileValue(FieldType type, int32_t fieldSize, const char* value, std::vector<uint8_t>& out, std::string& stringValue, std::string& error) const;
void RebuildCompiledIndex();
bool MarkEntityFieldDirtyByOffset(int entityIndex, int32_t offset);
std::vector<OverrideRule> m_rules;
std::vector<CompiledOverrideRule> m_compiledRules;
std::unordered_map<int, std::vector<size_t>> m_compiledRulesByEntity;
int m_nextId {1};
bool m_trace {false};
bool m_healthMoneyTest {false};