aboutsummaryrefslogtreecommitdiff
path: root/api.h
blob: 878b3d08e69191c3016e8251a1c8c83491926494 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
/*
 * Copyright © 2024 Matthew Wozniak <me@woz.blue>
 *
 * Permission to use, copy, modify, and/or distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED “AS IS” AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
 * AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
 * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
 * PERFORMANCE OF THIS SOFTWARE.
 */

#ifndef ENGINEAPI_H
#define ENGINEAPI_H

#define VENGINE_SERVER_INTERFACE_VERSION "VEngineServer021"
#define VENGINE_CLIENT_INTERFACE_VERSION "VEngineClient013"
#define VENGINE_LAUNCHER_INTERFACE_VERSION "VENGINE_LAUNCHER_API_VERSION004"
#define VENGINE_TOOL_INTERFACE_VERSION	"VENGINETOOL003"
#define VENGINE_CVAR_INTERFACE_VERSION "VEngineCvar004"

#include "intdef.h"
#include "os.h"

typedef void * (*createinterface_func)(const char *name, int *ret);

struct engserver {
	struct {
		usize _pad[36];
		void (*VIRTUAL server_command)(struct engserver *this, const char *str);
	} *vt;
};

struct engclient {
	struct {
		usize _pad[75];
		void (*VIRTUAL is_playing_demo)(struct engclient *this);
		void (*VIRTUAL steampipe_is_playing_demo)(struct engclient *this);
	} *vt;
};

struct engineapi {
	struct {
		usize _pad[7];
		void *set_engine_window; 
	} *vt;
};

struct enginetools {
	struct {
		usize _pad[65];
		void *start_movie_recording;
	} *vt;
};

struct cvar {
	struct {
		usize _pad[10];
		struct concommand * (*VIRTUAL find_command)(struct cvar *this, const char *name);
	} *vt;
};

struct cmdbase {
	void **vt;
	struct cmdbase *next;
	bool registered;
	const char *name;
	const char *helpstring;
	int flags;
};

struct concommand {
	struct cmdbase base;
	void *callback;
};

struct audio_device {
	struct {
		usize _pad[22];
		void *transfer_samples;
		void *steampipe_transfer_samples;
	} *vt;
};

struct movieinfo {
	char name[256];
	int curframe;
	int type;
	int jpeg_quality;
};

// Almost no chance I need all of these, but why not.
enum image_format {
	IMAGE_FORMAT_UNKNOWN  = -1,
	IMAGE_FORMAT_RGBA8888 = 0, 
	IMAGE_FORMAT_ABGR8888, 
	IMAGE_FORMAT_RGB888, 
	IMAGE_FORMAT_BGR888,
	IMAGE_FORMAT_RGB565, 
	IMAGE_FORMAT_I8,
	IMAGE_FORMAT_IA88,
	IMAGE_FORMAT_P8,
	IMAGE_FORMAT_A8,
	IMAGE_FORMAT_RGB888_BLUESCREEN,
	IMAGE_FORMAT_BGR888_BLUESCREEN,
	IMAGE_FORMAT_ARGB8888,
	IMAGE_FORMAT_BGRA8888,
	IMAGE_FORMAT_DXT1,
	IMAGE_FORMAT_DXT3,
	IMAGE_FORMAT_DXT5,
	IMAGE_FORMAT_BGRX8888,
	IMAGE_FORMAT_BGR565,
	IMAGE_FORMAT_BGRX5551,
	IMAGE_FORMAT_BGRA4444,
	IMAGE_FORMAT_DXT1_ONEBITALPHA,
	IMAGE_FORMAT_BGRA5551,
	IMAGE_FORMAT_UV88,
	IMAGE_FORMAT_UVWQ8888,
	IMAGE_FORMAT_RGBA16161616F,
	IMAGE_FORMAT_RGBA16161616,
	IMAGE_FORMAT_UVLX8888,
	IMAGE_FORMAT_R32F, // Single-channel 32-bit floating point
	IMAGE_FORMAT_RGB323232F,
	IMAGE_FORMAT_RGBA32323232F,
	// vendor crap
	IMAGE_FORMAT_NV_DST16,
	IMAGE_FORMAT_NV_DST24,
	IMAGE_FORMAT_NV_INTZ,
	IMAGE_FORMAT_NV_RAWZ,
	IMAGE_FORMAT_ATI_DST16,
	IMAGE_FORMAT_ATI_DST24,
	IMAGE_FORMAT_NV_NULL,
	IMAGE_FORMAT_ATI2N,
	IMAGE_FORMAT_ATI1N,
	NUM_IMAGE_FORMATS
};

struct videomode {
	struct {
		usize _pad[22];
		void (*VIRTUAL write_movie_frame)(struct videomode *this,
				struct movieinfo *info);
		usize _pad2[3];
		void (*VIRTUAL steampipe_write_movie_frame)(struct videomode *this,
				struct movieinfo *info);
		void (*VIRTUAL read_screen_pixels)(struct videomode *this,
				int x, int y, int w, int h, void *buf, enum image_format fmt);
		usize _pad3;
		void (*VIRTUAL steampipe_read_screen_pixels)(struct videomode *this,
				int x, int y, int w, int h, void *buf, enum image_format fmt);
	} *vt;
};

struct demoplayer {
	struct {
		usize _pad[5];
		bool (*VIRTUAL start_playback)(struct demoplayer *this,
				const char *filename, bool as_time_demo);
		usize _pad2[11];
		void (*VIRTUAL stop_playback)(struct demoplayer *this);
		// TODO: Disable interp when in a portal bubble. This will be very
		// difficult!
		void (*VIRTUAL interpolate_viewpoint)(struct demoplayer *this);
	} *vt;
};

/* EPIC HACK:
 * Snd_WriteLinearBlastStereo16 is an inline asm function that starts with
 * 
 *	mov	ebx, snd_p
 *	mov	edi, snd_out
 *	mov	ecx, snd_linear_count
 *	mov	esi, snd_vol
 *
 * Luckily for us, these are all the things that we need!!!!
 * So, we just use the instructions as a struct.
 */
struct soundstate {
	u16 _mov_ebx;
	int **snd_p;
	u16 _mov_edi;
	short **snd_out;
	u16 _mov_ecx;
	int *snd_linear_count;
	u16 _mov_esi;
	int *snd_vol;
} __attribute__((packed));

#ifndef NO_EXTERNS
extern struct engserver *engserver;
extern struct engclient *engclient;
extern struct engineapi *engineapi;
extern struct enginetools *enginetools;
extern struct demoplayer *demoplayer;
extern struct videomode **videomode;
extern struct movieinfo *movieinfo;
extern void (*cbuf_addtext)(char *);
extern void (*snd_recordbuffer)(void);
extern struct soundstate *snd;
extern bool steampipe;
#endif

// initializes required engine apis. returns false on error.
bool api_init(bool steampipe);
bool api_find_snd_recordbuffer(void);

#endif

// vi: sw=4 ts=4 noet tw=80 cc=80