-
Notifications
You must be signed in to change notification settings - Fork 0
/
SmithPlugin.cpp
192 lines (131 loc) · 3.91 KB
/
SmithPlugin.cpp
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
#include <Windows.h>
#include <GdiPlus.h>
#include "smith.h"
#include <stdio.h>
using namespace Gdiplus;
SMITHCALLS *smith = nullptr;
void DoTextureExperiment(double dt, double truedt)
{
// for one, we'll use a GDI+ bitmap and do some drawing and replace the texture on kyle's back...
if(true)
{
Bitmap* bmp = new Bitmap(256, 128);
Graphics* gfx = Graphics::FromImage(bmp);
SolidBrush brsh(Color::Black);
gfx->FillRectangle(&brsh, Rect(0, 0, bmp->GetWidth(), bmp->GetHeight()));
Pen pen(Color::White, 3.0f);
gfx->DrawEllipse(&pen, Rect(30, 30, 10, 10));
delete gfx;
HBITMAP hBitmap;
bmp->GetHBITMAP(Color::Black, &hBitmap);
smith->GenerateMaterialBitmap("kybodyb.mat", "dflt.cmp", 0, false, hBitmap, NULL);
DeleteObject(hBitmap);
delete bmp;
}
// next, we'll take a pixeldata buffer and use that directly
if(true)
{
int texWidth = 128;
int texHeight = 128;
int texDepth = 24;
int stride = texWidth * (texDepth / 8);
unsigned char* pBits = new unsigned char[stride*texHeight];
for (int y = 0; y < texHeight; y++)
{
unsigned char* pDst = pBits + stride * y;
for (int x = 0; x < texWidth; x++)
{
pDst[0] = rand()%128; // b
pDst[1] = rand()%255; // g
pDst[2] = 0; // r
pDst += 3;
}
}
smith->GenerateMaterial("kybutt.mat", "dflt.cmp", 0, texWidth, texHeight, texDepth, stride, pBits, nullptr);
delete[] pBits;
}
}
extern "C" {
void __cdecl OnMainLoop(double dt, double truedt)
{
if (smith == nullptr)
return;
}
void __cdecl OnPrepareMainRender(double dt, double truedt)
{
if (smith == nullptr)
return;
DoTextureExperiment(dt, truedt);
}
void __cdecl OnLevelShutdownPreObject()
{
if (smith == nullptr)
return;
}
void __cdecl OnLevelShutdownPostObject()
{
if (smith == nullptr)
return;
}
void __cdecl OnLevelStartPreObject()
{
if (smith == nullptr)
return;
//smith->ExecuteCOG("PlaySoundLocal(\"activate02.wav\", 1.0, 0.0, 0x00);", 0, 0, 0, 0, 0, 0, 0, 0);
}
void __cdecl OnLevelStartPostObject()
{
if (smith == nullptr)
return;
//char masterColormap[16] = { 0 };
//smith->ExecuteCOG("returnex(getsectorcolormap(0));", 0, 0, 0, 0, 0, 0, 0, masterColormap);
//MessageBox(0, masterColormap, 0, 0);
//char playerModel[16];
//smith->ExecuteCOG("GetThingModel(GetLocalPlayerThing());", 0, 0, 0, 0, 0, 0, 0, playerModel);
}
int __cdecl OnExecuteCOGVerb(const char* szName, int nNumParams, const char** pszParams, char* szReturn)
{
//if (stricmp(szName, "PluginTest") == 0 && nNumParams == 1)
//{
// MessageBox(0, pszParams[0], "SmithPlugin", MB_ICONINFORMATION);
// return 1;// handled
//}
return 0;// not handled; let smith deal with it
}
int _smith_formatversion(int major, int minor)
{
return major * 100 + minor;
}
int __cdecl SmithQueryPlugin(PLUGININFO& p)
{
// fill out the details
strcpy(p.name, "Sample Plugin");
strcpy(p.author, "bahstrike");
strcpy(p.authorEmail, "[email protected]");
strcpy(p.attributions, "BAH_Strike&BAH Main Page https://bah.wtf|Leethaxxor&Leet haxxin support https://github.com/blahblah This dude did stuff.|Bobs Tacos&Excellent tacos. Kept us goin|Homie A|Homie B");
strcpy(p.desc, "mostly an example plugin project. contains demonstrations of things possible with smith engine mod development");
strcpy(p.homepageURL, "https://github.com/bahstrike/SmithPlugin");
p.ver = _smith_formatversion(1, 0);
p.smithRequiredVer = SMITHVERSION;
//p.authoritykey // leave alone if u do not have agreed-upon algorithm
return 1337;
}
GdiplusStartupInput gdiplusStartupInput;
ULONG_PTR gdiplusToken = 0;
int __cdecl InitializePlugin(SMITHCALLS* _smith)
{
smith = _smith;
GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
return 1;
}
void __cdecl ShutdownPlugin()
{
if (gdiplusToken != 0)
{
GdiplusShutdown(gdiplusToken);
gdiplusToken = 0;
}
// our smith interface is no longer valid
smith = nullptr;
}
}