This is eudtrg API Reference. API Reference aims to hold any information needed to use eudtrg properly. If you think that this reference lacks essential information, is too vague, is written in bad grammar, or lacks anything, feel free to contact the author using whyask37@gmail.com.
Expression is a basic calculation unit of eudtrg. Expression mean ‘Object that can be evaluated to some number’.
Expression class. Handle expressions with unknown variables. Example:
a = Forward() # some unknown variable
b = Trigger() # some unknown variable
# b's value is determined with a call of SaveMap()
c = a + 5 - b # a + 5 - b is an expression with unknown variable.
# since a, b is undetermined yet, c needs to store expression tree of
# 'a + 5 - b', such as in form of (- (+ a 5) b). Expr class can be used
# to store such expressions.
Expr class supports basic arithmetic operators: addition, subtraction, muliplication, and division. Derived class should implement following two methods.
Returns: | What the object should be evaluated to. For example, |
---|
EUDObject returns the data’s address in Starcraft Memory by default. Type of returned object should be one of int, eudtrg.RelocatableInt, or one having Evaluate method.
Returns: | Cached value of EvalImpl. |
---|
Evaluate function caches and returns the value of EvalImpl. cache token expires or no values were cached before, Evaluate recaches its value by calling EvalImpl. Cache expires with a call of SaveMap.
Returns: | List of Expr instances self depends on. |
---|---|
Raises NotImplementedError: | |
Derived class have not overridden this method. |
Base class for uploadable objects. Uploadable objects objects having data to be inserted into SC Memory. Every EUDObject corresponds to one memory chunk inside SC Memory. EUDObject creates data to put inside memory chunk.
For example, every trigger in Starcraft is just a 2408byte memory chunk. eudtrg.Trigger refers to that memory chunk, and can create 2408 byte data to put inside it.
Overrides eudtrg.Expr.EvalImpl() .
Returns: | What this object should evaluate to. Default: Address of object. |
---|
Returns: | Size of data inside SC Memory. Default: 0 |
---|
Overrides eudtrg.Expr.GetDependencyList() .
Returns: | List of Expr instances this object depends on. Default: Empty list. |
---|
Reset object address. Called after payload is successfully injected.
Called by eudtrg when address of object is fixed. You won’t need to override this function.
Writes payload(data) to buffer. Users may use:
- emitbuffer.EmitByte(b) : Emit 1 byte(b) to buffer. b should be const.
- emitbuffer.EmitWord(w) : Emit 1 word(w) to buffer. w should be const.
- emitbuffer.EmitDword(dw) : Emit 1 dword(dw) to buffer. Dword should be constant or should be placed in 4byte boundary : bytes multiple of 4 were emitted before EmitDword() call.
emitbuffer is always aligned to 4byte boundary when WritePayload is called.
Parameters: | emitbuffer – Output buffer. Write payload here. |
---|
Forward declaration for expressions. Example:
b = Forward() # Forward declaration
a = Trigger( nextptr = b ) # b is defined here, so no error occurs.
b << Trigger( nextptr = a ) # put in value later.
Forward() class can be assigned a value only once.
Assign expression to self. The object will evaluate to assigned expressions afterwards.
Raises AssertionError: | |
---|---|
|
Raises AssertionError: | |
---|---|
Forward hasn’t been assigned to any values by Assign(). |
Db object inserts binary data into starcraft memory. Db object evaluates to address where bytes are stored.
Trigger defines map logic.
Condition class.
Memory layout:
Offset Field name Position EPD Player +00 locid dword0 EPD(cond)+0 +04 player dword1 EPD(cond)+1 +08 amount dword2 EPD(cond)+2 +0C unitid dword3 EPD(cond)+3 +0E comparison +0F condtype +10 restype dword4 EPD(cond)+4 +11 flags +12 internal[2]
Action class.
Memory layout.
Offset Field Name Position EPD Player +00 locid1 dword0 EPD(act)+0 +04 strid dword1 EPD(act)+1 +08 wavid dword2 EPD(act)+2 +0C time dword3 EPD(act)+3 +10 player1 dword4 EPD(act)+4 +14 player2 dword5 EPD(act)+5 +18 unitid dword6 EPD(act)+6 +1A acttype +1B amount +1C flags dword7 EPD(act)+7 +1D internal[3]
Make condition/action disabled. >>> Disabled(SetDeaths(Player1, SetTo, 1234, ‘Terran Marine’))
Parameters: | item – Condition/Action to disable |
---|---|
Returns: | Disabled condition/action. |
Create reference to next declared trigger.
Trigger scopes are used to specify scoping into triggers. Scopes groups triggers together. Triggers in the same scope are eligable for `nextptr auto linking`_.
Creates trigger scope. Triggers inside a scope is isolated from outside. Triggers from different scope won’t have their nextptr linked implicitly. You can still link triggers in other scopes by setting nextptr explicitly. This function is used in conjunction with PopTriggerScope().
example
a = Trigger()
PushTriggerScope() ################
b = Trigger() isolated
c = Trigger() isolated
PopTriggerScope() ################
d = Trigger()
Exits trigger scope. Used in conjunction with PushTriggerScope().
Enumeration parsers are used to translate human-friendly identifiers to intergal values. Consider following condition:
Bring(Player1, AtLeast, 1, "Terran Marine", "Anywhere")
Each field is parsed by enumeration parser : player field is parsed by eudtrg.ParsePlayer() function, unit field is parsed by eudtrg.ParseUnit() function.
Player1 -> ParsePlayer(Player1) = 0
AtLeast -> ParseComparison(AtLeast) = 0
1
"Terran Marine" -> ParseUnit("Terran Marine") = 0
"Anywhere" -> ParseLocation("Anywhere") = 64
So, the condition is translated as:
1. Bring(Player1, AtLeast, 1, "Terran Marine", "Anywhere")
2. Bring(0, 0, 1, 0, 64)
3. Condition(64, 0, 1, 0, 0, 3, 0, 0)
Enumeration parsers can also be used inside user code. For instance, consider following function changing unit’s graphic to other sprite:
ChangeUnitGraphics(0, 123) # Set Terran Marine's graphics to Sprite #123.
This code can be rewritten to:
ChangeUnitGraphics(ParseUnit("Terran Marine"), 123)
Or even better, ChangeUnitGraphics function can use ParseUnit internally.
Convert [Set, Cleared] to [2, 3].
Convert score type identifier to number.
Score type | Number |
---|---|
Total | 0 |
Units | 1 |
Buildings | 2 |
UnitsAndBuildings | 3 |
Kills | 4 |
Razings | 5 |
KillsAndRazings | 6 |
Custom | 7 |
Convert [AtLeast, AtMost, Exactly] to number [0, 1, 10].
Convert [Enable, Disable, Toogle] to number [4, 5, 6]
Convert [SetTo, Add, Subtract] to number [7, 8, 9].
Convert [Move, Patrol, Attack] to number [0, 1, 2].
Convert [Ore, Gas, OreAndGas] to [0, 1, 2]
Convert [All, (other numbers)] to number [0, (as-is)].
Convert [Enemy, Ally, AlliedVictory] to number [0, 1, 2].
Convert player identifier to corresponding number.
Identifier | Number |
---|---|
P1 | 0 |
P2 | 1 |
P3 | 2 |
P4 | 3 |
P5 | 4 |
P6 | 5 |
P7 | 6 |
P8 | 7 |
P9 | 8 |
P10 | 9 |
P11 | 10 |
P12 | 11 |
Player1 | 0 |
Player2 | 1 |
Player3 | 2 |
Player4 | 3 |
Player5 | 4 |
Player6 | 5 |
Player7 | 6 |
Player8 | 7 |
Player9 | 8 |
Player10 | 9 |
Player11 | 10 |
Player12 | 11 |
CurrentPlayer | 13 |
Foes | 14 |
Allies | 15 |
NeutralPlayers | 16 |
AllPlayers | 17 |
Force1 | 18 |
Force2 | 19 |
Force3 | 20 |
Force4 | 21 |
NonAlliedVictoryPlayers | 26 |
Convert known AI Script to script ID. See eudtrg.RunAIScript() and eudtrg.RunAIScriptAt() for list of AI scripts.
Convert [Set, Clear, Toogle, Random] to [4, 5, 6, 11].
Parameters: | unitname – Unit name, with or without color characters. |
---|---|
Returns: | Corresponding Unit ID. |
Raises RuntimeError: | |
|
Parameters: | locname – Location name |
---|---|
Returns: | Corresponding location name. |
Raises RuntimeError: | |
Location name is ambigious or not defined. |
Parameters: | string – String |
---|---|
Returns: | Corresponding string number. This function creates new string if there isn’t existing one. String with same contents will have same string ID. |
Raises AssertionError: | |
String table exceeded 65536 bytes. |
Parameters: | prop (UnitProperty) – Unit property |
---|---|
Returns: | Corresponding property ID. Identical Properties will have same property ID. |
Raises AssertionError: | |
More than 64 different properties have been used. |
Full Variable table. EUDVTable stores EUDVariable objects. EUDVTable serves as a key component of trigger programming.
vt = EUDVTable(3) a, b, c = vt.GetVariables() # use a, b, c for further calculations.
EUDVTable is as itself a Trigger, so it can be executed. When EUDVTable is executed, queued calculations are processed. You can queue calculations with EUDVariable.QueueAssignTo() and its family.
Returns: | List of variables inside EUDVTable. If there is only one variable, return it. |
---|
Full variable.
Parameters: | number – Number to add. |
---|---|
Returns: | Action for adding given number to variable. |
Parameters: | number – Number to compare variable with. |
---|---|
Returns: | Condition for checking if the variable is at least given number. |
Parameters: | number – Number to compare variable with. |
---|---|
Returns: | Condition for checking if the variable is at most given number. |
Parameters: | number – Number to compare variable with. |
---|---|
Returns: | Condition for checking if the variable is at exactly given number. |
Returns: | Memory address where values are stored. |
---|
Returns: | Parent EUDVTable. |
---|
Parameters: | dest – Where to add variable value to.
|
---|---|
Returns: | List of Action needed for queueing addition. |
Parameters: | dest – Where to assign variable value to.
|
---|---|
Returns: | List of Action needed for queueing assignment. |
Parameters: | dest – Where to subtract variable value to.
|
---|---|
Returns: | List of Action needed for queueing addition. |
Warning
Subtraction won’t underflow. Subtracting values with bigger one will yield 0.
Parameters: | number – Number to assign. |
---|---|
Returns: | Action for assigning given number to variable. |
Parameters: | number – Number to subtract. |
---|---|
Returns: | Action for subtracting given number to variable. |
Warning
Subtraction won’t underflow. Subtracting values with bigger one will yield 0.
Create (varn) EUDVariables. Returned variables are not guarranted to be in the same variable table.
Parameters: | varn – Number of EUDVariables to create. |
---|---|
Returns: | List of variables. If varn is 1, then a variable is returned. |
Do multiple assignment/addition/subtraction sequentially.
Parameters: | assignpairs – List of (dst, src, modtype)
|
---|---|
Raises AssertionError: | |
Raises when:
|
Warning
Subtraction won’t underflow. Subtracting values with bigger one will yield 0.
Assigns values to variables/memory. This is just a syntax sugar for SeqCompute(). Useful for retrieving function return values after EUD Function call.
SetVariables([unitx, unity], f_dwbreak(position)[0:2])
Parameters: |
|
---|---|
Raises AssertionError: | |
Raises when:
|
Warning
Subtraction won’t underflow. Subtracting values with bigger one will yield 0.
Shortcut for EUDVTable calculation. VTProc automatically inserts nextptr manipulation triggers, so you wouldn’t have to :param actions: Actions to execute
Light variable. EUDLightVariable occupies only 4 bytes.
Parameters: | number – Number to add. |
---|---|
Returns: | Action for adding given number to variable. |
Parameters: | number – Number to compare variable with. |
---|---|
Returns: | Condition for checking if the variable is at least given number. |
Parameters: | number – Number to compare variable with. |
---|---|
Returns: | Condition for checking if the variable is at most given number. |
Parameters: | number – Number to compare variable with. |
---|---|
Returns: | Condition for checking if the variable is at exactly given number. |
Returns: | Memory address where values are stored. |
---|
Parameters: | number – Number to assign. |
---|---|
Returns: | Action for assigning given number to variable. |
Parameters: | number – Number to subtract. |
---|---|
Returns: | Action for subtracting given number to variable. |
Warning
Subtraction won’t underflow. Subtracting values with bigger one will yield 0.
Shortcut for creating trigger with only action fields specified.
Parameters: | actions – Trigger actions. |
---|
Trigger with only nextptr specified. Useful for controlling trigger execution order. Acts as jmp instruction of x86 assembly.
Parameters: | nextptr – Trigger to execute next. |
---|
Jump if conditions are met. Two triggers are executed when jumping. If jump conditions are not met, then the following triggers are executed.
Parameters: |
|
---|
Jump if conditions are not met. Two triggers are executed when jumping. If jump conditions are met, then the following triggers are executed.
Parameters: |
|
---|
Branch based on conditions.
Parameters: |
|
---|
Generates EUD Function. Usually used as decorators. EUD Function cannot be recursive.
@EUDFunc
def f_add(a, b):
ret = EUDCreateVariables(1)
SeqCompute([
(ret, SetTo, 0),
(ret, Add, a),
(ret, Add, b)
])
return ret
EUD function gets several EUDVariables as arguments, but user can use both EUDVariable and Expr for calling function.
a,b = EUDCreateVariable(2)
c = Trigger()
d = c_int
f_mul(a,b) # ok
f_mul(10, b) # ok. 10 can be implicitly converted to Expr.
f_mul(10, 20) # ok.
f_mul(a, c) # ok. Trigger is type of expression. In this case, address
# of trigger will be passed to f_mul.
f_mul(a, d) # Error. c_int is neither EUDVariable nor Expr.
EUD Function may return several return values. Return values are overwritten after every function call, so users should store it with SetVariables() or SeqCompute() if they need it.
SeqCompute(local_variable, f_function()) # store return value
f_function() # local_variable still presists its value.
If returned values won’t be used after another function call, users don’t have to store it.
var = f_function()
f_function() # var is overwritten now.
Parameters: | fdecl_func – Function to be converted into EUD function. fdecl_func recieves several EUDVariable and should return single/list of EUDVariable. |
---|
Override default behavior of SaveMap() and set starting trigger for all players.
Parameters: | playerroots – Starting trigger for each players. (List of 8 elements) Starting trigger may be None if the player won’t execute any trigger. |
---|---|
Returns: | Starting trigger for InitPlayerSwitch to work. |
Warning
You should call InitPlayerSwitch at most once.
Custom string table.
Set default string table to self. All strings used by DisplayText will be forwarded to current string table
Warning
Always call f_initeudtbl() before using this function. Always call f_reseteudtbl() after using this function.
Get string index of certain string inside string table. :param string: String to get index. :returns: String index. :raises AssertionError: String table exceeds 65536 bytes.
Restore string table address. If you used custom string table, then you should call this function before trigger loop ends.
Backup original string table address.
Convert address to EPD Player value. Use EPD() instead to convert Expr to EPD player value.
Parameters: | addr – Address to convert. |
---|---|
Returns: | EPD player corresponding to given address. |
Read dword from memory. This function can read any memory with read access. :param targetplayer: EPD Player for address to read. :returns: Memory content.
Writes value to specified address.
Parameters: |
|
---|
Break dword into words & dwords.
Parameters: | number – Number to break. |
---|---|
Returns: | w[0], w[1], b[0], b[1], b[2], b[3]
} |
rep movsd equivilant in eudtrg. Copy dwords. Faster than f_memcpy.
Parameters: |
|
---|
memcpy equivilant in eudtrg. Copy bytes.
Parameters: |
|
---|
strcpy equivilant in eudtrg. Copy C-style string.
Parameters: |
|
---|
Save template map with EUDObjects & various files.
Parameters: |
|
---|
Load template map and read various data from it.
Parameters: | fname – Path to input map. |
---|