Staredit Network > Forums > SC1 UMS Theory and Ideas > Topic: Using EUD for custom AI
Using EUD for custom AI
Dec 14 2017, 4:59 pm
By: jncraton  

Dec 14 2017, 4:59 pm jncraton Post #1



I know almost nothing about UMS map making, and until the recent SCR patch, I had never looked at EUD in any detail. However, I have been working on an improved melee map AI for over a decade off and on:

https://github.com/jncraton/bwmetaai

My AI uses the older and much more limited method of patching the internal AI scripts rather than just hooking into the game externally as BWAPI does. I like this method as it is very simple to get up and running.

Currently, using my AI in SCR requires overwriting patch_rt.mpq. I'm curious if it might be possible to build this directly into a UMS map by making use of EUD. I found this list of offsets posted recently:

https://docs.google.com/spreadsheets/d/195jZK7Ap71eO1-qdVskC2xsVl7EbNdVp0hbh7N3D38A/edit#gid=0

It lists these offsets:

0x0068C104 0x0068C108 backed by code hAIScript
0x0068C108 0x0068C10C backed by code hBWScript

It sounds like those are pointers to the start of aiscript.bin and bwscript.bin. Does anyone know if that is correct? In theory, could I write custom scripts to some scratch memory somewhere and update these pointers to point to them?

I haven't looked at how AI scripts are actually executed by SC in tremendous detail, but my assumption is that it has a program counter of some sort that points to the next AI instruction to execute. It seems probable that I'd need to be able to overwrite this address to get this working unless the PC is relative to the start of AIScript.bin. Is this offset known and accessible via the new EUD rules?

I'd love to see any work that others have done on this if there is anything available. Thanks!




Dec 14 2017, 11:19 pm trgk Post #2



See



EUD

Dec 15 2017, 12:17 pm Heinermann Post #3

SDE, BWAPI owner, hacker.

Curious, can the pointer just be modified to point to a section in the map's CHK file? Or does the data need to be overwritten entirely by triggers?




Dec 15 2017, 2:07 pm trgk Post #4



Quote from Heinermann
Curious, can the pointer just be modified to point to a section in the map's CHK file? Or does the data need to be overwritten entirely by triggers?

Some requires data copy. Some only requires pointer modification (ex: iScript).
Here we use NPA, which generates triggers that overwrite existing AIScript memory.



EUD

Dec 16 2017, 3:38 pm jncraton Post #5



This is very helpful. Thanks! It looks like at minimum this was possible in 1.16 and may be possible in SCR.

Here's what I've done so far:

- Created a basic EUD map in SCMDraft to prove to myself that I understood the basics of what this technique allows. I simply altered the game speed.

- Created a map that alters the two offsets that I mentioned in my first post. I confirmed that the alterations took place using Cheat Engine, but there was no effect on AI behavior.

I'm not entirely sure where to go from here. I wasn't able to make sense of the Korean language tools for doing this. It sounds like I will actually need to use EUD triggers to overwrite the content of aiscript.bin. This makes sense, but I'm not sure how to determine the offset to write to. Also, does anyone know if this offset is even accessible in the SCR EUD emulation?




Dec 16 2017, 3:52 pm Nekron Post #6



This is slightly off-topic, but I'm not really sure if confining yourself to EUD maps has any real benefits over using a Samase remastered .exe with AIscript/BWscript; a custom .exe is arguably as easy to run as downloading separate maps, as long as you intend for something to be single-player.




Dec 16 2017, 4:46 pm jncraton Post #7



That's a good point. The benefits of this aren't huge. Basically:

1. You could play against different AIs without restarting StarCraft
2. You could play multiplayer online against custom AIs very easily
3. You could be confident that Blizzard wouldn't ban your account

However, I'm becoming less confident that this is possible in SCR. The memory address for the aiscript.bin data appears to change between games, and doesn't seem to be relative to the death table data, so I don't think I have a way to modify it from inside the game.




Dec 16 2017, 11:48 pm Heinermann Post #8

SDE, BWAPI owner, hacker.

You could use whatever current player trick is being used by some people. You have access to the AIScript pointer, so you use the CP trick to binary copy the pointer value into the current trigger player (as value/4 - deaths_base/4) and then use deaths of terran marine for current player to write to it.




Dec 21 2017, 3:37 pm jncraton Post #9



Thanks!

I'm not sure I fully understand at this point, but it sounds like you are referring to this trick:

http://www.staredit.net/topic/16663/

I don't understand how it works just yet, but it sounds like in principle it should allow me to write to an offset relative to the AIScript pointer.




Dec 22 2017, 10:07 pm jncraton Post #10



Thanks for all of your help!

I've been able to successfully embed my custom aiscript.bin in a set of EUD triggers. Here are the maps if you'd like to try them out and/or see exactly how they work.

https://github.com/jncraton/BWMetaAI/releases

Post has been edited 1 time(s), last time on Dec 22 2017, 10:29 pm by jncraton.




Dec 26 2017, 5:25 pm Nekron Post #11



This should perhaps have been mentioned earlier, but using UMS causes all scripts to be campaing scripts instead of melee ones :P
That shouldn't be a big deal for your scripts, but it will cause differences in attack patterns and some opcode usage changes + will fix the issue where non-campaign protosss AIs (almost?) never build archons

The attacking issue (random regions instead of safest/nearest regions) is the biggest concern here since it makes lots of the attacks disorganised on maps that are not properly designed, from the AI's viewpoint

Also, was there anything more than what's already in this thread you needed to make EUD work? It could be actually pretty useful accessibility-wise for me, if I'd be able to use it on my future campaign maps




Dec 29 2017, 5:38 am jncraton Post #12



Thanks for the information. I'll definitely have to look into the melee and campaign script differences to see if this may be causing issues.

I didn't need much information other than what was in this thread. I wasn't able to find a working tool that would write the appropriate triggers for me, but I was able to get the pointer math working and scripted the large number of triggers that actually write the individual words of aiscript.bin. Here's the trigger template that I use:

https://github.com/jncraton/BWMetaAI/blob/master/docs/eud.trg

Let me know if you run into problems getting this working. I don't think it will be too difficult if you already understand EUD triggers. That was the most challenging part for me.




Jan 29 2018, 3:06 pm Nekron Post #13



Correction re:archons: Melee AI seems to train them properly under some circumstances? Using a sample script that was basically only build tech, train archons the AI merged them without a delay. Psionic storm seems to disrupt the merging, S O M E T I M E S

The conditions for military high templars to merge are (courtesy of Neiv) having 75+ energy and being in region state 4 / 5 / 8 / 9, but there's also something that lets them merge even if they're below 75 energy.

Still can't get blizzard default AIs to ever train them and haven't seen any in non-UMS JNC protoss, though - maybe just bad luck?




Aug 20 2019, 4:22 pm psyhotechnica Post #14



Quote from trgk

Where do you find NPA 5?



None.

Options
  Back to forum
Please log in to reply to this topic or to report it.
Members in this topic: None.
[03:14 am]
jjf28 -- sraw531 wrong meme, https://youtu.be/jZ6nF6JKtRc
[09:39 pm]
sraw531 -- NudeRaider
NudeRaider shouted: dont repress your anger. come to the dark side!
https://www.youtube.com/watch?v=N3Zj-hMEL-k
[06:01 pm]
NudeRaider -- me? never!
[06:01 pm]
lil-Inferno -- u
[05:14 pm]
NudeRaider -- dont repress your anger. come to the dark side!
[04:55 pm]
Dem0n -- no
[04:13 pm]
Wing Zero -- Demon stop taking my box I'm bout to rage
[2020-9-24. : 12:06 am]
lifebot -- join RPG @ US WEST
[2020-9-23. : 7:10 am]
sraw531 -- ungh, looks like im going to have to do a binary count off for death messages, they aren't properly being displayed to everybody :(
[2020-9-23. : 4:22 am]
sraw531 -- maybe I should just test what happens if you teleport(move) the command centers to a location off the map every cycle while they are flying.
Please log in to shout.


Members Online: Roy, C(a)HeK, IlyaSnopchenko, KrayZee