Announcement

Collapse
No announcement yet.

Programming/scripting question

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Programming/scripting question

    So, I want to write a program or a script that does the following:

    * Contains a list of IP addresses, passwords, and game names
    * Allows the user to choose one of the game names
    * Enters the IP address and password into Civ4 (/Warlords)


    There is one way I know that would accomplish this, but inefficiently, and not significantly superior to keeping a copy/paste text file. (Select a game name, copies IP to clipboard, then manually activate Warlords, paste, go back, copy IP, go back, paste.)

    There are two ways I imagine that could accomplish this "better", one in VB and one through scripting (which I know nothing about and thus only guess this might be possible).

    1. VB: Have a program that runs in the background. Set in that program key combos for different games, i.e. ctrl-shift-1 through 9. Go into Civ4, get to the point of entering an ip, select the IP text box, hit ctrl-shift-1 or whatever; VB program automatically enters the IP (presumably via sending events to the event handler, keypressed events or whatever?) and enters "tab" and enters password for that game.

    I don't know if two things here are possible: 1. if it's possible to have a background program waiting for a particular keypress combination, and 2. if one program can send keypress events to another program (or in any given other way send information to a program that's not particularly looking out for such information).

    There are other variations I could imagine for this, but I don't really know enough of what is possible to enumerate them.

    2. Scripting: Through scripting somehow send the information to the program (like in 1.), or if that's not possible, through scripting edit (or copy) the .ini file for Civ4 that contains the default IP address. This is not particularly useful, because typically PTBS players (like me) would, well, play lots of games at the same time and probably aren't interested in restarting Civ4 from scratch for each game. But it might be marginally useful.

    Is this possible (particularly the while-civ4-is-running method(s) )? Does anyone have a suggestion for where I can find information on how to do it, if it is possible? I googled around a bit and found nothing useful to me, but I know so little about scripting and about 'windows' VB (I know VB as in inside-a-program VB, but not about affecting other programs with VB) that nothing I came up with was relevant, presumably because I don't know what to look for ...

    TIA
    <Reverend> IRC is just multiplayer notepad.
    I like your SNOOPY POSTER! - While you Wait quote.

  • #2
    What VB are you talking about? Visual Basic, VBScript or Visual Basic for Applications?

    The simplest way I can think of is by using the SendKeys function. I'm not familiar with Civ4, but I think that should work. I did something like that for Civ2 anyway.

    Write a program where you can select the game info from a list, say. It will then launch or activate Civ4, and navigate to the correct menu and type in the necessary text by sending keypresses.

    I'm not sure how to do it with that program running in the background without actually having to change focus to it while you're pressing the keyboard shortcut.


    Another way I can think of is to find the location in memory where Civ4 stores this information and directly write it to memory.
    Civilization II: maps, guides, links, scenarios, patches and utilities (+ Civ2Tech and CivEngineer)

    Comment


    • #3
      Originally posted by Mercator
      What VB are you talking about? Visual Basic, VBScript or Visual Basic for Applications?
      Or Victoria Bitter, the Australian Beer?

      Comment


      • #4
        Originally posted by Mercator
        What VB are you talking about? Visual Basic, VBScript or Visual Basic for Applications?
        Visual Basic and/or VBA, I know both. I don't know VBScript but it sounds like it's not too hard to learn from what i'd read up yesterday.

        The simplest way I can think of is by using the SendKeys function. I'm not familiar with Civ4, but I think that should work. I did something like that for Civ2 anyway.

        Write a program where you can select the game info from a list, say. It will then launch or activate Civ4, and navigate to the correct menu and type in the necessary text by sending keypresses.
        This sounds exactly right, actually ... the rest of the stuff was in case this didn't work.

        I notice MSDN mentions that it has a risk in international keyboards of doing unpredictable things - is this because it sends an interrupt basically, or is it okay as long as we're sticking to numbers and letters, and not #$^% type characters? I worry a bit since if I write this I expect international people to probably use it... but perhaps it can be modified in some way (or recompiled by an international keyboard user of whatever type is needed).

        I think FindWindow would work fine for me in terms of activating the application... actually found a MSDN page that describes this very well, it uses a program to send input to the calculator, which is roughly identical to what i'd be doing.

        I still have to figure out how to programmatically launch a program (since this would be useful also to be able to launch civ4 from this program), but that's probably a lower priority issue than using sendkeys.

        Thanks!!
        <Reverend> IRC is just multiplayer notepad.
        I like your SNOOPY POSTER! - While you Wait quote.

        Comment


        • #5
          Well, I got it to work, sort of. I get sometimes unpredictable results, I have to throw in a Monitor.wait(queue,50) in between each for a 50ms delay (there must be an easier way to use a delay rather than threading my function, but heck if I can figure it out... maybe I should have taken a course in VB or something to fill in all of my gaps of knowledge, I know some sort of advanced stuff but I'm missing a lot of relatively simple knowledge, enough that it's sometimes hard to find answers to it when it's not in an obvious place) ...

          And I get some LoaderLock issues pretty much every time I run it, hopefully those wouldn't cause a problem if the debugger weren't running, but ... we'll see when I finish it and take it out of the debugger
          <Reverend> IRC is just multiplayer notepad.
          I like your SNOOPY POSTER! - While you Wait quote.

          Comment


          • #6
            Did you check if there were entrypoints in Civ4 python code for that? Python would be handy to do such a thing.
            The Civ4 menus are coded (or rather plugged) in Python, so adding an inputbox asking for what you want at the start of the game should be possible.
            Clash of Civilization team member
            (a civ-like game whose goal is low micromanagement and good AI)
            web site http://clash.apolyton.net/frame/index.shtml and forum here on apolyton)

            Comment


            • #7
              Originally posted by snoopy369
              I notice MSDN mentions that it has a risk in international keyboards of doing unpredictable things - is this because it sends an interrupt basically, or is it okay as long as we're sticking to numbers and letters, and not #$^% type characters?
              Well, SendKeys just mimics typing. I think you'd only get into trouble with things like accented letters and special symbols that are on keyboards these days.

              I still have to figure out how to programmatically launch a program (since this would be useful also to be able to launch civ4 from this program), but that's probably a lower priority issue than using sendkeys.


              Which version of VB do you use? I'm only familiar with 6. Well, actually, it doesn't seem to matter much in this case. I mainly used the AppActivate and Shell functions. They work well enough.

              I didn't know VB did threading, and I have no idea what LoaderLock is I'm afraid... Most of my delays were in seconds. So I just used a timer and DoEvents. But VB.NET doesn't have DoEvents anymore it seems.
              Civilization II: maps, guides, links, scenarios, patches and utilities (+ Civ2Tech and CivEngineer)

              Comment


              • #8
                Yeah, I'm using VB.NET and there's no obvious timer other than with threading. I think there's something else locking things up, possibly related to Civ4 itself (it has some weird issues).

                LDiCesare, as far as I understand the MP connections and other game creation options are not python codeable. I may take a look to make sure, though.
                <Reverend> IRC is just multiplayer notepad.
                I like your SNOOPY POSTER! - While you Wait quote.

                Comment


                • #9
                  Ahh, AppActivate works the same way as the FindWindow roughly, except FindWindow has slightly more complex error checking ability I think. Shell though would be very useful for me because it would permit me to run Civ4 from scratch (though I'd have to figure out how to "wait" for it to load before doing other tasks, which I don't exactly know how to do except to wait for a specific amount of time... which varies between systems and even between startups based on cached or not, HDD spinning or not, etc. ...
                  <Reverend> IRC is just multiplayer notepad.
                  I like your SNOOPY POSTER! - While you Wait quote.

                  Comment


                  • #10
                    Woot! I've gotten it to work pretty well now... had to use some work to get Civ4 to cooperate (no hotkeys in the menus means I have to use lots of esc/esc/esc and up-up-up combos to make sure i'm on the right selection based on the unknown starting position and cursor position), but it now works (at a beginning level). I can add games to a listbox, click "connect", open Civ4 if it's not already running (or warlords), connect to the game, and save the game list for another day (and then load it).

                    Next challenge, beyond refining it, is going to be seeing if I can figure out a way to cooperate with CivStats for those of us playing PTBS games so that it can show the status of those games. I think at minimum I can pick up the details from the web page, but that seems like a lot of work when it should be easier to cooperate with the program itself; perhaps the designer can give me the info on how that might work. His program isn't all that more complex anyway than mine, excepting the network portions, so ...
                    <Reverend> IRC is just multiplayer notepad.
                    I like your SNOOPY POSTER! - While you Wait quote.

                    Comment

                    Working...
                    X