Skip to content

Commit 6d67341

Browse files
committed
Add new MSFS 2024 APIs
1 parent e9d3e8a commit 6d67341

9 files changed

Lines changed: 244 additions & 3 deletions

src/SimConnectConnection.ts

Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ import {
6161
ObjectId,
6262
} from './Types';
6363
import Timeout = NodeJS.Timeout;
64+
import { RecvEnumerateSimobjectAndLiveryList } from './recv/RecvEnumerateSimobjectAndLiveryList';
65+
import { RecvFlowEvent } from './recv/RecvFlowEvent';
6466

6567
type OpenPacketData = {
6668
major: number;
@@ -99,6 +101,13 @@ const openPacketData: { [key in Protocol]: OpenPacketData } = {
99101
buildMinor: 3,
100102
alias: 'HK', // "Hawk" + "Kitty"?
101103
},
104+
[Protocol.SunRise]: {
105+
major: 12,
106+
minor: 2,
107+
buildMajor: 282174,
108+
buildMinor: 999,
109+
alias: 'SR', // Unverified
110+
},
102111
};
103112

104113
interface SimConnectRecvEvents {
@@ -143,6 +152,10 @@ interface SimConnectRecvEvents {
143152
enumerateInputEventParams: (
144153
recvEnumerateInputEventParams: RecvEnumerateInputEventParams
145154
) => void;
155+
enumerateSimobjectAndLiveryList: (
156+
recvEnumerateSimobjectAndLiveryList: RecvEnumerateSimobjectAndLiveryList
157+
) => void;
158+
flowEvent: (recvFlowEvent: RecvFlowEvent) => void;
146159
}
147160

148161
type ConnectionOptions =
@@ -1687,6 +1700,149 @@ class SimConnectConnection extends EventEmitter {
16871700
return this._buildAndSend(this._beginPacket(0x56).putInt32(dataDefinitionId));
16881701
}
16891702

1703+
/**
1704+
*
1705+
* @returns sendId of packet (can be used to identify packet when exception event occurs)
1706+
*/
1707+
aICreateParkedATCAircraftEx1(
1708+
containerTitle: string,
1709+
livery: string,
1710+
tailNumber: string,
1711+
airportID: string,
1712+
dataRequestId: DataRequestId
1713+
): number {
1714+
if (this._ourProtocol < Protocol.SunRise) throw Error(SimConnectError.BadVersion);
1715+
1716+
return this._buildAndSend(
1717+
this._beginPacket(0x57)
1718+
.putString256(containerTitle)
1719+
.putString256(livery)
1720+
.putString(tailNumber, 12)
1721+
.putString(airportID, 5)
1722+
.putInt32(dataRequestId)
1723+
);
1724+
}
1725+
1726+
/**
1727+
*
1728+
* @returns sendId of packet (can be used to identify packet when exception event occurs)
1729+
*/
1730+
aICreateEnrouteATCAircraftEx1(
1731+
containerTitle: string,
1732+
livery: string,
1733+
tailNumber: string,
1734+
flightNumber: number,
1735+
flightPlanPath: string,
1736+
flightPlanPosition: number,
1737+
touchAndGo: boolean,
1738+
dataRequestId: DataRequestId
1739+
): number {
1740+
if (this._ourProtocol < Protocol.SunRise) throw Error(SimConnectError.BadVersion);
1741+
1742+
return this._buildAndSend(
1743+
this._beginPacket(0x58)
1744+
.putString256(containerTitle)
1745+
.putString256(livery)
1746+
.putString(tailNumber, 12)
1747+
.putInt32(flightNumber)
1748+
.putString(flightPlanPath, 260)
1749+
.putFloat64(flightPlanPosition)
1750+
.putInt32(touchAndGo ? 1 : 0)
1751+
.putInt32(dataRequestId)
1752+
);
1753+
}
1754+
1755+
/**
1756+
*
1757+
* @returns sendId of packet (can be used to identify packet when exception event occurs)
1758+
*/
1759+
aICreateNonATCAircraftEx1(
1760+
containerTitle: string,
1761+
livery: string,
1762+
tailNumber: string,
1763+
initPos: InitPosition,
1764+
dataRequestId: DataRequestId
1765+
): number {
1766+
if (this._ourProtocol < Protocol.SunRise) throw Error(SimConnectError.BadVersion);
1767+
1768+
const packet = this._beginPacket(0x59)
1769+
.putString256(containerTitle)
1770+
.putString256(livery)
1771+
.putString(tailNumber, 12);
1772+
1773+
initPos.writeTo(packet);
1774+
packet.putInt32(dataRequestId);
1775+
1776+
return this._buildAndSend(packet);
1777+
}
1778+
1779+
/**
1780+
*
1781+
* @returns sendId of packet (can be used to identify packet when exception event occurs)
1782+
*/
1783+
aICreateSimulatedObjectEx1(
1784+
containerTitle: string,
1785+
livery: string,
1786+
initPos: InitPosition,
1787+
dataRequestId: DataRequestId
1788+
): number {
1789+
if (this._ourProtocol < Protocol.SunRise) throw Error(SimConnectError.BadVersion);
1790+
1791+
const packet = this._beginPacket(0x5a);
1792+
1793+
packet.putString256(containerTitle);
1794+
packet.putString256(livery);
1795+
initPos.writeTo(packet);
1796+
packet.putInt32(dataRequestId);
1797+
1798+
return this._buildAndSend(packet);
1799+
}
1800+
1801+
/**
1802+
*
1803+
* @returns sendId of packet (can be used to identify packet when exception event occurs)
1804+
*/
1805+
enumerateSimObjectsAndLiveries(dataRequestId: DataRequestId, type: SimObjectType): number {
1806+
if (this._ourProtocol < Protocol.SunRise) throw Error(SimConnectError.BadVersion);
1807+
1808+
const packet = this._beginPacket(0x5b).putInt32(dataRequestId).putInt32(type);
1809+
1810+
return this._buildAndSend(packet);
1811+
}
1812+
1813+
/**
1814+
*
1815+
* @returns sendId of packet (can be used to identify packet when exception event occurs)
1816+
*/
1817+
subscribeToFlowEvent(): number {
1818+
if (this._ourProtocol < Protocol.SunRise) throw Error(SimConnectError.BadVersion);
1819+
1820+
const packet = this._beginPacket(0x5c);
1821+
return this._buildAndSend(packet);
1822+
}
1823+
1824+
/**
1825+
*
1826+
* @returns sendId of packet (can be used to identify packet when exception event occurs)
1827+
*/
1828+
unsubscribeToFlowEvent(): number {
1829+
if (this._ourProtocol < Protocol.SunRise) throw Error(SimConnectError.BadVersion);
1830+
1831+
const packet = this._beginPacket(0x5d);
1832+
return this._buildAndSend(packet);
1833+
}
1834+
1835+
/**
1836+
*
1837+
* @returns sendId of packet (can be used to identify packet when exception event occurs)
1838+
*/
1839+
requestAllFacilities(dataRequestId: DataRequestId, type: FacilityListType): number {
1840+
if (this._ourProtocol < Protocol.SunRise) throw Error(SimConnectError.BadVersion);
1841+
1842+
const packet = this._beginPacket(0x5e).putInt32(dataRequestId).putInt32(type);
1843+
return this._buildAndSend(packet);
1844+
}
1845+
16901846
close() {
16911847
if (this._openTimeout !== null) {
16921848
clearTimeout(this._openTimeout);
@@ -1833,6 +1989,15 @@ class SimConnectConnection extends EventEmitter {
18331989
case RecvID.ID_ENUMERATE_INPUT_EVENT_PARAMS:
18341990
this.emit('enumerateInputEventParams', new RecvEnumerateInputEventParams(data));
18351991
break;
1992+
case RecvID.ID_ENUMERATE_SIMOBJECT_AND_LIVERY_LIST:
1993+
this.emit(
1994+
'enumerateSimobjectAndLiveryList',
1995+
new RecvEnumerateSimobjectAndLiveryList(data)
1996+
);
1997+
break;
1998+
case RecvID.ID_FLOW_EVENT:
1999+
this.emit('flowEvent', new RecvFlowEvent(data));
2000+
break;
18362001
}
18372002
}
18382003

src/SimConnectSocket.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ enum RecvID {
4545
ID_GET_INPUT_EVENT,
4646
ID_SUBSCRIBE_INPUT_EVENT,
4747
ID_ENUMERATE_INPUT_EVENT_PARAMS,
48+
ID_ENUMERATE_SIMOBJECT_AND_LIVERY_LIST,
49+
ID_FLOW_EVENT,
4850
}
4951

5052
interface SimConnectMessage {
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { RawBuffer } from '../RawBuffer';
2+
3+
export class EnumerateSimobjectLivery {
4+
aircraftTitle: string;
5+
6+
liveryName: string;
7+
8+
constructor(data: RawBuffer) {
9+
this.aircraftTitle = data.readString256();
10+
this.liveryName = data.readString256();
11+
}
12+
}

src/enums/FacilityDataType.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ export enum FacilityDataType {
2525
PAVEMENT,
2626
APPROACHLIGHTS,
2727
VASI,
28+
VDGS,
29+
HOLDING_PATTERN,
30+
TAXI_PARKING_AIRLINE,
2831
}
2932

3033
module.exports = {

src/enums/FlowEvent.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
export enum FlowEvent {
2+
NONE,
3+
FLT_LOAD,
4+
FLT_LOADED,
5+
TELEPORT_START,
6+
TELEPORT_DONE,
7+
BACK_ON_TRACK_START,
8+
BACK_ON_TRACK_DONE,
9+
SKIP_START,
10+
SKIP_DONE,
11+
BACK_TO_MAIN_MENU,
12+
RTC_START,
13+
RTC_END,
14+
REPLAY_START,
15+
REPLAY_END,
16+
FLIGHT_START,
17+
FLIGHT_END,
18+
PLANE_CRASH,
19+
}
20+
21+
module.exports = {
22+
FlowEvent,
23+
};

src/enums/Protocol.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ export enum Protocol {
1515
* MSFS / Asobo
1616
*/
1717
KittyHawk = 0x5,
18+
/**
19+
* MSFS / Asobo, 2024
20+
*/
21+
SunRise = 0x6,
1822
}
1923

2024
module.exports = {

src/enums/SimObjectType.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@ export enum SimObjectType {
1111
BOAT,
1212
/** Specifies all AI controlled ground vehicles */
1313
GROUND,
14-
15-
/** for invalid values */
16-
INVALID,
14+
/** MSFS 2024 onwards */
15+
HOT_AIR_BALLOON,
16+
ANIMAL,
17+
USER_AVATAR,
18+
USER_CURRENT,
1719
}
1820

1921
module.exports = {
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { RecvListTemplate } from './RecvListTemplate';
2+
import { RawBuffer } from '../RawBuffer';
3+
import { EnumerateSimobjectLivery } from '../datastructures/EnumerateSimobjectLivery';
4+
5+
export class RecvEnumerateSimobjectAndLiveryList extends RecvListTemplate {
6+
simobjectLiveries: EnumerateSimobjectLivery[] = [];
7+
8+
constructor(data: RawBuffer) {
9+
super(data);
10+
11+
this.simobjectLiveries = [];
12+
for (let i = 0; i < this.arraySize; i++) {
13+
this.simobjectLiveries.push(new EnumerateSimobjectLivery(data));
14+
}
15+
}
16+
}

src/recv/RecvFlowEvent.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { RawBuffer } from '../RawBuffer';
2+
import { RecvEvent } from './RecvEvent';
3+
4+
export class RecvFlowEvent extends RecvEvent {
5+
flowEventID: number;
6+
7+
fltPath: string;
8+
9+
constructor(data: RawBuffer) {
10+
super(data);
11+
this.flowEventID = data.readInt32();
12+
this.fltPath = data.readString256();
13+
}
14+
}

0 commit comments

Comments
 (0)