Skip to content

Commit

Permalink
ALTV-426 Add interior API
Browse files Browse the repository at this point in the history
  • Loading branch information
Doxoh committed Oct 4, 2024
1 parent 98abdca commit dfe99cb
Show file tree
Hide file tree
Showing 7 changed files with 346 additions and 0 deletions.
7 changes: 7 additions & 0 deletions c-api/data/interior_extend_info.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#pragma once
#include "cpp-sdk/deps/alt-math/alt-math.h"

typedef struct {
alt::Position min;
alt::Position max;
} interior_extend_info_t;
39 changes: 39 additions & 0 deletions c-api/interior.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#include "interior.h"

#include "utils/macros.h"

CAPI_START()

#ifdef ALT_CLIENT_API
uint16_t Interior_GetRoomCount(uint32_t interiorId)
{
auto interior = alt::ICore::Instance().GetInterior(interiorId);
return interior->GetRoomCount();
}

uint16_t Interior_GetPortalCount(uint32_t interiorId)
{
auto interior = alt::ICore::Instance().GetInterior(interiorId);
return interior->GetPortalCount();
}

alt::Position Interior_GetPosition(uint32_t interiorId)
{
auto interior = alt::ICore::Instance().GetInterior(interiorId);
return interior->GetPosition();
}

alt::Rotation Interior_GetRotation(uint32_t interiorId)
{
auto interior = alt::ICore::Instance().GetInterior(interiorId);
return interior->GetRotation();
}

void Interior_GetEntitiesExtents(uint32_t interiorId, interior_extend_info_t& extents)
{
auto interior = alt::ICore::Instance().GetInterior(interiorId);
auto ext = interior->GetEntitiesExtents();
extents.min = ext.min;
extents.max = ext.max;
}
#endif
29 changes: 29 additions & 0 deletions c-api/interior.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#pragma once

#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wempty-body"
#pragma clang diagnostic ignored "-Wswitch"
#endif

#include "cpp-sdk/SDK.h"
#include "data/interior_extend_info.h"
#include "data/types.h"
#include "data/invoker.h"
#include "utils/export.h"

#ifdef ALT_SERVER_API
#include <CSharpResourceImpl.h>
#elif ALT_CLIENT_API
#include "../client/src/runtime/CSharpResourceImpl.h"
#endif

#ifdef __clang__
#pragma clang diagnostic pop
#endif

EXPORT_CLIENT uint16_t Interior_GetRoomCount(uint32_t interiorId);
EXPORT_CLIENT uint16_t Interior_GetPortalCount(uint32_t interiorId);
EXPORT_CLIENT alt::Position Interior_GetPosition(uint32_t interiorId);
EXPORT_CLIENT alt::Rotation Interior_GetRotation(uint32_t interiorId);
EXPORT_CLIENT void Interior_GetEntitiesExtents(uint32_t interiorId, interior_extend_info_t& extents);
106 changes: 106 additions & 0 deletions c-api/interior_portal.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
#include "interior_portal.h"

#include "cpp-sdk/script-objects/IInteriorPortal.h"
#include "utils/macros.h"

CAPI_START()

#ifdef ALT_CLIENT_API

uint16_t InteriorPortal_GetCornerCount(uint32_t interiorId, uint32_t portalIndex)
{
auto portal = GetInteriorPortal(interiorId, portalIndex);
return portal->GetCornerCount();
}

alt::Position InteriorPortal_GetCornerPosition(uint32_t interiorId, uint32_t portalIndex, uint32_t cornerIndex)
{
auto portal = GetInteriorPortal(interiorId, portalIndex);
return portal->GetCornerPosition(cornerIndex);
}

uint32_t InteriorPortal_GetRoomFrom(uint32_t interiorId, uint32_t portalIndex)
{
auto portal = GetInteriorPortal(interiorId, portalIndex);
return portal->GetRoomFrom();
}

uint32_t InteriorPortal_GetRoomTo(uint32_t interiorId, uint32_t portalIndex)
{
auto portal = GetInteriorPortal(interiorId, portalIndex);
return portal->GetRoomTo();
}

int32_t InteriorPortal_GetFlag(uint32_t interiorId, uint32_t portalIndex)
{
auto portal = GetInteriorPortal(interiorId, portalIndex);
return portal->GetFlag();
}

uint16_t InteriorPortal_GetEntityCount(uint32_t interiorId, uint32_t portalIndex)
{
auto portal = GetInteriorPortal(interiorId, portalIndex);
return portal->GetEntityCount();
}

uint32_t InteriorPortal_GetEntityArcheType(uint32_t interiorId, uint32_t portalIndex, uint32_t entityIndex)
{
auto portal = GetInteriorPortal(interiorId, portalIndex);
return portal->GetEntityArcheType(entityIndex);
}

int32_t InteriorPortal_GetEntityFlag(uint32_t interiorId, uint32_t portalIndex, uint32_t entityIndex)
{
auto portal = GetInteriorPortal(interiorId, portalIndex);
return portal->GetEntityFlag(entityIndex);
}

alt::Position InteriorPortal_GetEntityPosition(uint32_t interiorId, uint32_t portalIndex, uint32_t entityIndex)
{
auto portal = GetInteriorPortal(interiorId, portalIndex);
return portal->GetEntityPosition(entityIndex);
}

alt::Rotation InteriorPortal_GetEntityRotation(uint32_t interiorId, uint32_t portalIndex, uint32_t entityIndex)
{
auto portal = GetInteriorPortal(interiorId, portalIndex);
return portal->GetEntityRotation(entityIndex);
}

void InteriorPortal_SetCornerPosition(uint32_t interiorId, uint32_t portalIndex, uint32_t cornerIndex,
position_t position)
{
auto portal = GetInteriorPortal(interiorId, portalIndex);
portal->SetCornerPosition(cornerIndex, alt::Position(position.x, position.y, position.z));
}

void InteriorPortal_SetRoomFrom(uint32_t interiorId, uint32_t portalIndex, uint32_t roomFrom)
{
auto portal = GetInteriorPortal(interiorId, portalIndex);
portal->SetRoomFrom(roomFrom);
}

void InteriorPortal_SetRoomTo(uint32_t interiorId, uint32_t portalIndex, uint32_t roomTo)
{
auto portal = GetInteriorPortal(interiorId, portalIndex);
portal->SetRoomTo(roomTo);
}

void InteriorPortal_SetFlag(uint32_t interiorId, uint32_t portalIndex, int32_t flag)
{
auto portal = GetInteriorPortal(interiorId, portalIndex);
portal->SetFlag(flag);
}

void InteriorPortal_SetEntityFlag(uint32_t interiorId, uint32_t portalIndex, uint32_t entityIndex, int32_t flag)
{
auto portal = GetInteriorPortal(interiorId, portalIndex);
portal->SetEntityFlag(entityIndex, flag);
}

std::shared_ptr<alt::IInteriorPortal> GetInteriorPortal(uint32_t interiorId, uint32_t portalIndex)
{
auto interior = alt::ICore::Instance().GetInterior(interiorId);
return interior->GetPortalByIndex(portalIndex);
}
#endif
46 changes: 46 additions & 0 deletions c-api/interior_portal.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#pragma once

#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wempty-body"
#pragma clang diagnostic ignored "-Wswitch"
#endif

#include "cpp-sdk/SDK.h"
#include "data/interior_extend_info.h"
#include "data/types.h"
#include "data/invoker.h"
#include "utils/export.h"

#ifdef ALT_SERVER_API
#include <CSharpResourceImpl.h>
#elif ALT_CLIENT_API
#include "../client/src/runtime/CSharpResourceImpl.h"
#endif

#ifdef __clang__
#pragma clang diagnostic pop
#endif

EXPORT_CLIENT uint16_t InteriorPortal_GetCornerCount(uint32_t interiorId, uint32_t portalIndex);
EXPORT_CLIENT alt::Position InteriorPortal_GetCornerPosition(uint32_t interiorId, uint32_t portalIndex, uint32_t cornerIndex);
EXPORT_CLIENT uint32_t InteriorPortal_GetRoomFrom(uint32_t interiorId, uint32_t portalIndex);
EXPORT_CLIENT uint32_t InteriorPortal_GetRoomTo(uint32_t interiorId, uint32_t portalIndex);
EXPORT_CLIENT int32_t InteriorPortal_GetFlag(uint32_t interiorId, uint32_t portalIndex);

EXPORT_CLIENT uint16_t InteriorPortal_GetEntityCount(uint32_t interiorId, uint32_t portalIndex);
EXPORT_CLIENT uint32_t InteriorPortal_GetEntityArcheType(uint32_t interiorId, uint32_t portalIndex, uint32_t entityIndex);
EXPORT_CLIENT int32_t InteriorPortal_GetEntityFlag(uint32_t interiorId, uint32_t portalIndex, uint32_t entityIndex);
EXPORT_CLIENT alt::Position InteriorPortal_GetEntityPosition(uint32_t interiorId, uint32_t portalIndex, uint32_t entityIndex);
EXPORT_CLIENT alt::Rotation InteriorPortal_GetEntityRotation(uint32_t interiorId, uint32_t portalIndex, uint32_t entityIndex);


EXPORT_CLIENT void InteriorPortal_SetCornerPosition(uint32_t interiorId, uint32_t portalIndex, uint32_t cornerIndex, position_t position);
EXPORT_CLIENT void InteriorPortal_SetRoomFrom(uint32_t interiorId, uint32_t portalIndex, uint32_t roomFrom);
EXPORT_CLIENT void InteriorPortal_SetRoomTo(uint32_t interiorId, uint32_t portalIndex, uint32_t roomTo);
EXPORT_CLIENT void InteriorPortal_SetFlag(uint32_t interiorId, uint32_t portalIndex, int32_t flag);
EXPORT_CLIENT void InteriorPortal_SetEntityFlag(uint32_t interiorId, uint32_t portalIndex, uint32_t entityIndex, int32_t flag);

#ifdef ALT_CLIENT_API
std::shared_ptr<alt::IInteriorPortal> GetInteriorPortal(uint32_t interiorId, uint32_t portalIndex);
#endif
80 changes: 80 additions & 0 deletions c-api/interior_room.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#include "interior_room.h"

#include "cpp-sdk/script-objects/IInteriorRoom.h"
#include "utils/macros.h"
#include "utils/strings.h"

CAPI_START()

#ifdef ALT_CLIENT_API
const char* InteriorRoom_GetName(uint32_t interiorId, uint32_t roomValue, uint8_t isIndex, int32_t& size)
{
auto room = GetInteriorRoom(interiorId, roomValue, isIndex);
return AllocateString(room->GetName(), size);
}

uint32_t InteriorRoom_GetNameHash(uint32_t interiorId, uint32_t roomValue, uint8_t isIndex)
{
auto room = GetInteriorRoom(interiorId, roomValue, isIndex);
return room->GetNameHash();
}

int32_t InteriorRoom_GetFlag(uint32_t interiorId, uint32_t roomValue, uint8_t isIndex)
{
auto room = GetInteriorRoom(interiorId, roomValue, isIndex);
return room->GetFlag();
}

uint32_t InteriorRoom_GetTimecycle(uint32_t interiorId, uint32_t roomValue, uint8_t isIndex)
{
auto room = GetInteriorRoom(interiorId, roomValue, isIndex);
return room->GetTimecycle();
}

void InteriorRoom_GetExtents(uint32_t interiorId, uint32_t roomValue, uint8_t isIndex,
interior_extend_info_t& extents)
{
auto room = GetInteriorRoom(interiorId, roomValue, isIndex);
auto ext = room->GetExtents();
extents.min = ext.min;
extents.max = ext.max;
}

void InteriorRoom_SetFlag(uint32_t interiorId, uint32_t roomValue, uint8_t isIndex, int32_t flag)
{
auto room = GetInteriorRoom(interiorId, roomValue, isIndex);
room->SetFlag(flag);
}

void InteriorRoom_SetTimecycle(uint32_t interiorId, uint32_t roomValue, uint8_t isIndex, uint32_t timecycle)
{
auto room = GetInteriorRoom(interiorId, roomValue, isIndex);
room->SetTimecycle(timecycle);
}

void InteriorRoom_SetEntitiesExtents(uint32_t interiorId, uint32_t roomValue, uint8_t isIndex, position_t min,
position_t max)
{
auto room = GetInteriorRoom(interiorId, roomValue, isIndex);
alt::IInterior::ExtentInfo extentInfo;
extentInfo.min = alt::Position(min.x, min.y, min.z);
extentInfo.max = alt::Position(max.x, max.y, max.z);
room->SetExtents(extentInfo);
}

std::shared_ptr<alt::IInteriorRoom> GetInteriorRoom(uint32_t interiorId, uint32_t roomValue, uint8_t isIndex)
{
auto interior = alt::ICore::Instance().GetInterior(interiorId);
std::shared_ptr<alt::IInteriorRoom> room;
if (isIndex == 1)
{
room = interior->GetRoomByIndex(roomValue);
}
else
{
room = interior->GetRoomByHash(roomValue);
}

return room;
}
#endif
39 changes: 39 additions & 0 deletions c-api/interior_room.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#pragma once

#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wempty-body"
#pragma clang diagnostic ignored "-Wswitch"
#endif

#include "cpp-sdk/SDK.h"
#include "data/interior_extend_info.h"
#include "data/types.h"
#include "data/invoker.h"
#include "utils/export.h"

#ifdef ALT_SERVER_API
#include <CSharpResourceImpl.h>
#elif ALT_CLIENT_API
#include "../client/src/runtime/CSharpResourceImpl.h"
#endif

#ifdef __clang__
#pragma clang diagnostic pop
#endif

EXPORT_CLIENT const char* InteriorRoom_GetName(uint32_t interiorId, uint32_t roomValue, uint8_t isIndex, int32_t& size);
EXPORT_CLIENT uint32_t InteriorRoom_GetNameHash(uint32_t interiorId, uint32_t roomValue, uint8_t isIndex);
EXPORT_CLIENT int32_t InteriorRoom_GetFlag(uint32_t interiorId, uint32_t roomValue, uint8_t isIndex);
EXPORT_CLIENT uint32_t InteriorRoom_GetTimecycle(uint32_t interiorId, uint32_t roomValue, uint8_t isIndex);

EXPORT_CLIENT void InteriorRoom_GetExtents(uint32_t interiorId, uint32_t roomValue, uint8_t isIndex, interior_extend_info_t& extents);

EXPORT_CLIENT void InteriorRoom_SetFlag(uint32_t interiorId, uint32_t roomValue, uint8_t isIndex, int32_t flag);
EXPORT_CLIENT void InteriorRoom_SetTimecycle(uint32_t interiorId, uint32_t roomValue, uint8_t isIndex, uint32_t timecycle);
EXPORT_CLIENT void InteriorRoom_SetEntitiesExtents(uint32_t interiorId, uint32_t roomValue, uint8_t isIndex, position_t min, position_t max);


#ifdef ALT_CLIENT_API
std::shared_ptr<alt::IInteriorRoom> GetInteriorRoom(uint32_t interiorId, uint32_t roomValue, uint8_t isIndex);
#endif

0 comments on commit dfe99cb

Please sign in to comment.