initial commit -- v1 code

This commit is contained in:
2026-08-10 14:21:07 +02:00
commit 1ecb7f777e
25 changed files with 2472 additions and 0 deletions

81
src/overrides.h Normal file
View File

@@ -0,0 +1,81 @@
#pragma once
#include "playerslot.h"
#include <cstdint>
#include <string>
#include <vector>
enum class FieldType
{
Bool,
Int8,
UInt8,
Int16,
UInt16,
Int32,
UInt32,
Int64,
UInt64,
Float,
};
struct FieldPathSegment
{
std::string className;
std::string fieldName;
};
struct OverrideRule
{
int id {};
int recipientSlot {-1};
std::string target;
std::string className;
std::string fieldName;
std::vector<FieldPathSegment> path;
FieldType type {FieldType::Int32};
uint64_t bits {};
bool enabled {true};
};
struct AppliedOverride
{
uint8_t* address {};
FieldType type {};
uint64_t originalBits {};
};
class OverrideManager
{
public:
void Clear();
bool AddFromTokens(int argc, const char** argv, 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);
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 DynamicRuleCount() const { return (m_healthMoneyTest ? 1 : 0) + (m_health42Test ? 1 : 0); }
bool Empty() const { return m_rules.empty() && !m_healthMoneyTest && !m_health42Test; }
std::vector<AppliedOverride> ApplyForRecipient(CPlayerSlot slot);
void Restore(const std::vector<AppliedOverride>& applied);
private:
bool EntityMatches(uintptr_t entity, const OverrideRule& rule) const;
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);
void ApplyHealth42Test(CPlayerSlot slot, std::vector<AppliedOverride>& applied);
std::vector<OverrideRule> m_rules;
int m_nextId {1};
bool m_trace {false};
bool m_healthMoneyTest {false};
bool m_health42Test {false};
};
extern OverrideManager g_overrides;