Any functionality to draw to warcraft 2 screen? What about an array of bytes sample also. It would then be perfect to project! Thanks brother.
Yeah sure. Sorry not finding much time to document all of this.... still working 6 days a week ( and sleeping 1 day )
For an array of bytes, you can just declare the array in your source then use memcpy or CopyMemory etc. Will try to do an example later, but you can probably work that out.
Here's the game timer plugin. It demonstrates writing a string on a bitmap, then pasting that bitmap to the wc2 screen inside the display hook.
... uses:
paste_string(clock,0,0,&clockbuf[0],4,CLOCK_COLOR);
clock is the bitmap handle
(0,0) is target co-ords on the bitmap
&clockbuf[0] is the source ANSI string
4 is the font size (only supports 4 and 6 currently)
CLOCK_COLOR is the pixel value to set on the bitmap
this is done once per second to update the bitmap, then in the sccreen display hook it uses:
wc2_trans_paste(clock,CLOCK_X,CLOCK_Y);
to paste the "clock" bitmap onto the screen buffer at co-ords (CLOCK_X,CLOCK_Y)
(assumes 0 pixels are transparent)
These functions are exported from LC.dll
Have a look at lamb.h and lamb.cpp for others
Will try to document these further later.
dllmain.cpp //
/////////////////////////////////////////////////////
// Example dll for Warcraft II plugin framework //
/////////////////////////////////////////////////////
// Lambchops 2019
// *** This is a poor way of implementing a game timer.
// Shoud really be re-written to use GetSystemTime() or similar,
// but it makes for a simple example this way.
#include <windows.h>
#include <lamb.h>
// constants for the in-game screen
#define LOC_INGAME_H 1684300900
#define LOC_INGAME_O 2155905153
// display the timer here
// * using the top of mini-map to guarantee that this part
// of the screen is updated every second *
#define CLOCK_X 22
#define CLOCK_Y 24
// color for pixels on timer bitmap
#define CLOCK_COLOR 0xFE
BOOL game_timer_on = FALSE;
// count the number of game ended signals
BOOL tick_out = 0;
int game_secs = 0;
int game_mins = 0;
int game_hours = 0;
int game_days = 0;
// allocate a buffer to store timer as a string
CHAR clockbuf[16];
// create a little 32x6 bitmap to draw timer string on to
HMIBMP* clock = make_bitmap(32,6,8);
// temp storage for game "location" value supplied
// to "screen_update()" by the framework
DWORD loc;
BOOL in_game(){
// return TRUE if we are in a game
return (loc==LOC_INGAME_H||loc==LOC_INGAME_O);
}
void reset_timer(){
tick_out = 0;
game_secs = -1;
game_mins = 0;
game_hours= 0;
game_days = 0;
}
void game_tick(){
// add 1 second to game time
game_secs++;
if(game_secs==60){
game_secs=0;
game_mins++;
if(game_mins==60){
game_mins=0;
game_hours++;
if(game_hours==24){
game_hours=0;
game_days++;
}
}
}
// redraw the timer display bitmap //
wsprintf(&clockbuf[0],"%2.2d:%2.2d:%2.2d",game_hours,game_mins,game_secs);
zero_bitmap(clock);
paste_string(clock,0,0,&clockbuf[0],4,CLOCK_COLOR);
}
void CALLBACK TimerProc(HWND hwnd,UINT uMsg,UINT idEvent,DWORD dwTime){
// this is called every 1 second by the system timer we set up below
if(game_timer_on){
if(in_game()){
// update time by 1 second
game_tick();
tick_out = 0;
}else{
if(tick_out>1){
// = 3rd miss for in_game()
//( location constant appears to occasionally glitch on
// some systems - possibly a ddraw thing ?? )
// game ended
game_timer_on = FALSE;
}else{
game_tick();
tick_out++;
}
}
}else{
if(in_game()){
// game started
game_timer_on = TRUE;
reset_timer();
game_tick();
}
}
}
////// EXPORTED FUNCTIONS FOR THE FRAMEWORK TO CALL ///////
// called once at startup
extern "C" __declspec (dllexport) void w2p_init(){
// Create a timer that ticks every 1 second
SetTimer(NULL,0,1000,TimerProc);
}
// called every screen update
extern "C" __declspec (dllexport) void screen_update(DWORD location){
loc=location;
if(game_timer_on){
// paste the time display bitmap onto the game screen ( pixel 0 = transparent )
wc2_trans_paste(clock,CLOCK_X,CLOCK_Y);
}
}
BOOL APIENTRY DllMain ( HINSTANCE hInst, DWORD reason, LPVOID reserved ){ return TRUE; }
lamb.h#include <windows.h>
#ifndef _LAMB_
#define _LAMB_
extern "C" {
typedef struct hmibmp {
BITMAPFILEHEADER* pFile;
BITMAPINFOHEADER* pInfo;
RGBQUAD* pPal;
BYTE* pBits;
int width;
int height;
int bpp;
int linew;
int usage;
int size;
}HMIBMP;
}
//hmibmp.inc
extern "C" typedef HMIBMP* (__stdcall *pfnmakebmp )(int w,int h,int bpp);
extern "C" typedef void (__stdcall *pfnfreebmp )(HMIBMP* bmp);
extern "C" typedef int (__stdcall *pfnzerobmp )(HMIBMP* bmp);
extern "C" typedef void (__stdcall *pfnsavebmp )(CHAR* path,HMIBMP* bmp);
extern "C" typedef void (__stdcall *pfnsavejpg )(CHAR* path,HMIBMP* bmp,int quality);
extern "C" typedef void (__stdcall *pfnperfbmp )(HMIBMP* bmp);
extern "C" typedef void (__stdcall *pfncopyimg )(HMIBMP* src,int scrx,int srcy,int srcw,int scrh,HMIBMP* dst,int dstx,int dsty,int transp);
extern "C" typedef int (__stdcall *pfncopyfull)(HMIBMP* dstbmp,HMIBMP* srcbmp,int transp);
extern "C" typedef void (__stdcall *pfndispimg )(HDC destDC,int x,int y,int w,int h,HMIBMP* bmp,int dx,int dy,int dw,int dh);
extern "C" typedef void (__stdcall *pfnsetpal )(HMIBMP* bmp,LPVOID palette);
extern "C" typedef void (__stdcall *pfndrawrect)(HMIBMP* bmp,int x,int y,int w,int h,int color);
extern "C" typedef HMIBMP* (__stdcall *pfnsizebmp )(HMIBMP* bmp,int w,int h);
extern "C" typedef HMIBMP* (__stdcall *pfnscalebmp)(HMIBMP* bmp,int scale);
extern "C" typedef void (__stdcall *pfnsetpixel)(HMIBMP* bmp,int x,int y,int pval);
extern "C" typedef void (__stdcall *pfnpastestr)(HMIBMP* bmp,int x,int y,CHAR* lpsz,int point,int color);
extern "C" typedef void (__stdcall *pfnwc2tpast)(HMIBMP* bmp,int x,int y);
extern pfnmakebmp make_bitmap;
extern pfnfreebmp free_bitmap;
extern pfnzerobmp zero_bitmap;
extern pfnsavebmp save_bitmap;
extern pfnsavejpg save_jpeg;
extern pfnperfbmp perforate_bitmap;
extern pfncopyimg copy_image;
extern pfncopyfull copy_full_image;
extern pfndispimg display_image;
extern pfnsetpal set_palette;
extern pfndrawrect draw_rect;
extern pfnsizebmp size_bitmap;
extern pfnscalebmp scale_bitmap;
extern pfnsetpixel set_pixel;
extern pfnpastestr paste_string;
extern pfnwc2tpast wc2_trans_paste;
#endif
lamb.cpp#include <windows.h>
#include <lamb.h>
HMODULE hLambDll = LoadLibraryA("LC");
pfnmakebmp make_bitmap = (pfnmakebmp )GetProcAddress(hLambDll, "make_bitmap" );
pfnfreebmp free_bitmap = (pfnfreebmp )GetProcAddress(hLambDll, "free_bitmap" );
pfnzerobmp zero_bitmap = (pfnzerobmp )GetProcAddress(hLambDll, "zero_bitmap" );
pfnsavebmp save_bitmap = (pfnsavebmp )GetProcAddress(hLambDll, "save_bitmap" );
pfnsavejpg save_jpeg = (pfnsavejpg )GetProcAddress(hLambDll, "save_jpeg" );
pfnsizebmp size_bitmap = (pfnsizebmp )GetProcAddress(hLambDll, "size_bitmap" );
pfnscalebmp scale_bitmap = (pfnscalebmp)GetProcAddress(hLambDll, "scale_bitmap" );
pfnperfbmp perforate_bitmap = (pfnperfbmp )GetProcAddress(hLambDll, "perforate_bitmap" );
pfncopyimg copy_image = (pfncopyimg )GetProcAddress(hLambDll, "copy_image" );
pfncopyfull copy_full_image = (pfncopyfull)GetProcAddress(hLambDll, "copy_full_image" );
pfndispimg display_image = (pfndispimg )GetProcAddress(hLambDll, "display_td_image" );
pfnsetpal set_palette = (pfnsetpal )GetProcAddress(hLambDll, "set_palette" );
pfndrawrect draw_rect = (pfndrawrect)GetProcAddress(hLambDll, "draw_rect" );
pfnsetpixel set_pixel = (pfnsetpixel)GetProcAddress(hLambDll, "set_pixel" );
pfnpastestr paste_string = (pfnpastestr)GetProcAddress(hLambDll, "paste_string" );
pfnwc2tpast wc2_trans_paste = (pfnwc2tpast)GetProcAddress(hLambDll, "wc2_trans_paste" );