Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Is there any way to map next C code into Perl or change it so that I can use it in Perl.

My proplem is that I do not know how to define similar Callback function in perl and then compile it to .dll Is this even possible to do ?

For the backround information: I do not know much about C programming and following C code is an interface for undocumented gamebot which behavior you can controll by editing the following header file

Cheers,
-PerlTroubler-

#ifndef BOT_H #define BOT_H // this is the only function a behavior has to implement: // extern "C" __declspec (dllexport) void CALLBACK BOT_Cmd(BOTCMD *bc) +; #define MAXUSERS 500 #define MAXBEHAVIORS 50 typedef struct { // This data should always be accurate char Name[32]; char Squad[32]; //nyi int Wins; //nyi int Losses; //nyi int Points; //nyi int Rating; //nyi char Lastship; // 1-8 for ships, 0 for spec - Only valid on // BOTCMD_ShipChange char Shiptype; // 1-8 for ships, 0 for spec // This data is updated only periodically when requested // and should only be used in response to MSG_SPECINFO short Bounty; //nyi int XCoord; //nyi int YCoord; //nyi char ShipDirection; //nyi short Energy; //nyi char Flags; //nyi char HasBall; //nyi // This data is updated only periodically when requested and should +be used // only in response to MSG_USERINFO. Some of the info like IP and MI +D // will remain constant if looked at even once, so IsKnown is set to + true // if we have this info... char IsKnown; //nyi int MID; //nyi short LastFreq; // Only valid on BOTCMD_FreqChange short Freq; char IP[16]; //nyi short AvePing,CurPing,MinPing,MaxPing; //nyi short S2CPloss,C2SPloss; //nyi // *todo* There's plenty of other info in a *info we can grab // This field is updated whenever this structure is sent to a behavi +or // and is read and stored upon return. It is the only data field tha +t // is not read only. A behavior may ignore this, or use it however i +t // wants to store data. void* Ptr; // This data is for internal use and should not be messed with at al +l. char IsValid; short UID; char SpecCnt; //nyi //char SpecList[MAXBEHAVIORS]; //nyi char InfoCnt; //nyi //char InfoList[MAXBEHAVIORS]; //nyi int PtrList[MAXBEHAVIORS]; //nyi char IsBotOp; //nyi short IgnoreTime; // in minutes // nyi int IgnoredAt; //nyi } USER_DATA; typedef struct { int Msg; // One of the #define BOTMSG_ ///// used for BOTMSG_Line /////////////////////////////////////////// +//// short uid; // user ID if its a private message short LineType; // Line Type char *Line; // pointer to text char Sound; // 0 for no sound, otherwise sound # ///// used for BOTMSG_Register /////////////////////////////////////// +//// char *Cmd; // String of command including ! char OpOnly; // Is the command for ops only? char *HelpFile; // Help Filename for this command int CmdID; // CmdID - The bot core doesn't care about this +, // the behavior should use it to uniquely ident +ify // this command. } BOTMSG; typedef struct { int Cmd; // One of the #define BOTCMD_ ///// used for BOTCMD_Init /////////////////////////////////////////// +//// HWND hwnd; // Window handle to send messages char BehaviorID; // Your Behavior's ID, save this, you need to send + it // with every BOT_MSG ///// used for all commands that have user data (except kills) /////// +//// // This is read only with the single exception of Ptr, which // is a Ptr to info for this user for this behavior. Ptr is // maintained independantly for each behavior and may contain // anything the behavior wants USER_DATA *UserData; ///// used for BOTCMD_Kill /////////////////////////////////////////// +//// USER_DATA *Killed; USER_DATA *Killer; short Bounty; ///// used for BOTCMD_Line /////////////////////////////////////////// +//// char *Line; short LineType; // see #define LINETYPE_ ///// used for BOTCMD_Cmd //////////////////////////////////////////// +//// char *CmdStr; // the text of the command - should use CmdID, its fa +ster char *Params; // parameters of the command int CmdID; // the command ID the behavior registered for this co +mmand ///// used for all commands except BOTCMD_Init /////////////////////// +//// USER_DATA *UserList; // This is the list of all users. // Its an array of USER_DATA of size MAXUSERS +. // Only records with UserList[i].IsValid==TRU +E // are valid users. ALL THIS DATA IS READ ONL +Y // AND ONLY ACCURATE FOR THIS MESSAGE. COPY // ANYTHING YOU NEED LONG TERM. } BOTCMD; // To send messages to the bot, use SendMessage with a message of WM_B +OT, // wparam set to your BotID, and lparam set to the pointer to the mess +age. // DO NOT USE POSTMESSAGE. The message structure is copied and may be // reused after SendMessage has completed #define WM_BOT 0x423 #define BOTMSG_Line 0 // Send a message #define BOTMSG_Register 1 // Register a command #define BOTMSG_LineSound 2 // Send a message with a sound #define BOTCMD_Init 0 #define BOTCMD_Entered 1 #define BOTCMD_Left 2 #define BOTCMD_Kill 3 #define BOTCMD_Line 4 #define BOTCMD_Shutdown 5 #define BOTCMD_Command 6 #define BOTCMD_Arena 7 // changing arenas, forget everything you + know // Arena name is in "Line" and is "" for +pub #define BOTCMD_Tick 8 // called every 50ms or so #define BOTCMD_Shipchange 9 #define BOTCMD_FreqChange 10 // *todo* chat, squad, rederror #define LINETYPE_Pub 2 #define LINETYPE_Macro 1 #define LINETYPE_Team 3 #define LINETYPE_AnyTeam 4 #define LINETYPE_Private 5 #define LINETYPE_CrossZone 7 // does not have user data #define LINETYPE_Arena 0 // does not have user data #define LINETYPE_Chat 9 // does not have user data #define LINETYPE_SysopMsg 8 // does not have user data #endif
Edit 2/15/02 dws for <readmore> and formatting.

Replies are listed 'Best First'.
Re: Possible or am I dreaming for Perl made dlls
by Zaxo (Archbishop) on Feb 14, 2002 at 09:24 UTC

    Inline::Struct will take care of this header ok. Where are your functions defined? Inline::C will produce a dll for perl to load, but only if you have a C compiler available.

    Update: On second look, there appear to be identifiers in the header that are not defined. You'll have to collect enough other headers that compilation can succeed.

    After Compline,
    Zaxo

Re: Possible or am I dreaming for Perl made dlls
by metadoktor (Hermit) on Feb 14, 2002 at 09:33 UTC
    This looks like a Microsoft Windows C/C++ program header file. Presumably there is also a main program that goes with this header. Why do you want to interface this to Perl?

    metadoktor

    "The doktor is in."

      This header file is interface between botcore.exe which source is not published cause the author wants keep some things in secret. Anyway the author has published this header file for other programmers so they could change the behavior of the corebot.exe.
      I try clarify this more..
      There are 4 files:
      botcore.exe <-- source not available.
      behaviors.ini <-- contains the name of compiled behavior dll file
      bot.h <-- the published header file
      botbehavior.cpp <-- C++ file which is compiled to dll. This file also includes the bot.h file
      Bot.h presents how programmer may do their own behaviors for the botcore.exe. Bot.h does not need to exsist as long ht behavior code is compiled to dll and it contains following:
      // this is the only function a behavior has to implement: // extern "C" __declspec (dllexport) void CALLBACK BOT_Cmd(BOTCMD *bc) +;
      botcore.exe is calling this callback function every 10 ms
      +----------------+ |botcore.exe | +-----+ |CORE | <-->| ini | name of dll +-------------|--+ +-----+ |Bot.h | | -- | BotCMD | | | +-------------|--+ | <-- Any Bot programmer may change |behavior.dll | | if only code is compiled into DLL | CODE | -- and it exports BOT_Cmd function +----------------+
      Like I said I am not any good with C pluss I know I could do lot of nice new bots if all these things could be done just using Perl. ...Sorry my clumsy english, I hope you figured out the proplem...
        Looks like you'll probably have to spend some $$$ to get the tool necessary to do this (i.e. PerlCtrl to create a Perl DLL), otherwise you're probably out of luck. See ActiveState's reference on creating Perl DLLs

        metadoktor

        "The doktor is in."