Skip to content

Commit

Permalink
Add a template for EventExt
Browse files Browse the repository at this point in the history
  • Loading branch information
Belonit committed Jan 21, 2024
1 parent d5a9018 commit 247c61a
Show file tree
Hide file tree
Showing 2 changed files with 147 additions and 0 deletions.
101 changes: 101 additions & 0 deletions src/Ext/Event/Body.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
/*
#include "Body.h"
#include <Helpers/Macro.h>
#include <EventClass.h>
bool EventExt::AddEvent()
{
return EventClass::AddEvent(*reinterpret_cast<EventClass*>(this));
}
void EventExt::RespondEvent()
{
switch (this->Type)
{
case EventTypeExt::Sample:
// Place the handler here
break;
}
}
size_t EventExt::GetDataSize(EventTypeExt type)
{
switch (type)
{
case EventTypeExt::Sample:
return sizeof(EventExt::Sample);
}
return 0;
}
bool EventExt::IsValidType(EventTypeExt type)
{
return (type >= EventTypeExt::FIRST && type <= EventTypeExt::LAST);
}
// hooks
DEFINE_HOOK(0x4C6CC8, Networking_RespondToEvent, 0x5)
{
GET(EventExt*, pEvent, ESI);
if (EventExt::IsValidType(pEvent->Type))
{
pEvent->RespondEvent();
}
return 0;
}
DEFINE_HOOK(0x64B6FE, sub_64B660_GetEventSize, 0x6)
{
const auto eventType = static_cast<EventTypeExt>(R->EDI() & 0xFF);
if (EventExt::IsValidType(eventType))
{
const size_t eventSize = EventExt::GetDataSize(eventType);
R->EDX(eventSize);
R->EBP(eventSize);
return 0x64B71D;
}
return 0;
}
DEFINE_HOOK(0x64BE7D, sub_64BDD0_GetEventSize1, 0x6)
{
const auto eventType = static_cast<EventTypeExt>(R->EDI() & 0xFF);
if (EventExt::IsValidType(eventType))
{
const size_t eventSize = EventExt::GetDataSize(eventType);
REF_STACK(size_t, eventSizeInStack, STACK_OFFSET(0xAC, -0x8C));
eventSizeInStack = eventSize;
R->ECX(eventSize);
R->EBP(eventSize);
return 0x64BE97;
}
return 0;
}
DEFINE_HOOK(0x64C30E, sub_64BDD0_GetEventSize2, 0x6)
{
const auto eventType = static_cast<EventTypeExt>(R->ESI() & 0xFF);
if (EventExt::IsValidType(eventType))
{
const size_t eventSize = EventExt::GetDataSize(eventType);
R->ECX(eventSize);
R->EBP(eventSize);
return 0x64C321;
}
return 0;
}
*/
46 changes: 46 additions & 0 deletions src/Ext/Event/Body.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#pragma once
/*
#include <cstddef>
#include <stdint.h>
enum class EventTypeExt : uint8_t
{
// Vanilla game used Events from 0x00 to 0x2F
// CnCNet reserved Events from 0x30 to 0x3F
// Ares used Events 0x60 and 0x61
Sample = 0x40, // Sample event, remove it when Phobos needs its own events
FIRST = Sample,
LAST = Sample
};
#pragma pack(push, 1)
class EventExt
{
public:
EventTypeExt Type;
bool IsExecuted;
char HouseIndex;
uint32_t Frame;
union
{
char DataBuffer[104];
struct Sample
{
char DataBuffer[104];
} Sample;
};
bool AddEvent();
void RespondEvent();
static size_t GetDataSize(EventTypeExt type);
static bool IsValidType(EventTypeExt type);
};
static_assert(sizeof(EventExt) == 111);
static_assert(offsetof(EventExt, DataBuffer) == 7);
#pragma pack(pop)
*/

0 comments on commit 247c61a

Please sign in to comment.