It is currently 08 Sep 2025, 10:56
   
Text Size

Manalink C/ASM Dll

Discuss Upcoming Releases, Coding New Cards, Etc.
PLEASE DO NOT REPORT BUGS HERE!

Moderators: BAgate, drool66, Aswan jaguar, gmzombie, stassy, CCGHQ Admins

Re: Manalink C/ASM Dll

Postby HarryPitfall » 15 Mar 2009, 19:38

"It would be a cool thing if you guys dumped into the wiki everything you know about this pCARDINFO or card_instance_t or whatever we will call it." - I already start a thread asking for this... maybe if other people ask, something happens... for now... is have only this information about 'esi'...

CardInfoState dword [esi+0x08] <- have a dword, with tapped/summon sick and possible other flags
CardInfoSlot1 [esi+0x38] <- is a free place, used to stored information for the card (like a color when comes into play, or how many times a ability is played)
CardInfoTargetPlayer dword [esi+0x74] <- last targeted player by the card
CardInfoTargetCard dword [esi+0x78] <- last targeted card by the card
CardInfoCardColor dword [esi+0x59] <- the card color (direct from magic.exe structure i think)

also, tks lonewolf... is always good when someone point necessary corrections, and find solutions...
HarryPitfall
AI Programmer
 
Posts: 175
Joined: 31 May 2008, 00:14
Has thanked: 1 time
Been thanked: 3 times

Re: Manalink C/ASM Dll

Postby jatill » 15 Mar 2009, 19:46

guys, thanks for the code there. I'm working on chromatic star now, since it has a lot of pieces to glue together. You saved me having to write the is_tapped code. Huzzah!
jatill
DEVELOPER
 
Posts: 2118
Joined: 24 Feb 2009, 16:35
Has thanked: 5 times
Been thanked: 17 times

Re: Manalink C/ASM Dll

Postby HarryPitfall » 15 Mar 2009, 19:55

Remember that lone wolf states about esi...
Code: Select all
.GetCardInfoState:
  push ebp
  mov ebp, esp
  push esi
  mov eax, [ebp + 0x08]
  mov ecx, [ebp + 0x0c]
  call 0x401a80
  mov eax, [esi + 0x08]
  pop esi
  leave
  ret
the other function will be the same...
HarryPitfall
AI Programmer
 
Posts: 175
Joined: 31 May 2008, 00:14
Has thanked: 1 time
Been thanked: 3 times

Re: Manalink C/ASM Dll

Postby Snacko » 15 Mar 2009, 20:10

You probably should group the constants for the same thing like color / state info into enums.
Then you can do like GetCardInfoState(Player, Card) & (Status.Tapped | Status.Summoning Sickness). Probably better than an abundance of simple functions plus there's no magic constants.
Snacko
DEVELOPER
 
Posts: 826
Joined: 29 May 2008, 19:35
Has thanked: 4 times
Been thanked: 74 times

Re: Manalink C/ASM Dll

Postby jatill » 15 Mar 2009, 20:28

Readable enough for ya? Talk about self-documenting code.
Code: Select all
#include "manalink.h"

int card_chromatic_sphere(int player, int card, int event){
  if(event == EVENT_CAN_ACTIVATE){
    if( has_mana( player, COLOR_ANY, 1 ) && ! is_tapped( player, card ) ){
      return 1;
    }
  }
  else if(event == EVENT_ACTIVATE){
    tap_card( player, card);
    charge_mana( player, COLOR_COLORLESS, 1);
    kill_card( player, card, KILL_SACRIFICE);
    add_one_mana_any_color(player, card, event);
    draw_a_card(player);
  }
  return 0;
}
jatill
DEVELOPER
 
Posts: 2118
Joined: 24 Feb 2009, 16:35
Has thanked: 5 times
Been thanked: 17 times

Re: Manalink C/ASM Dll

Postby Snacko » 15 Mar 2009, 20:40

The code is wrong if you used harry's functions you need to use the bit & and not the logical &&
return GetCardInfoState(Player, Card) & 0x10;
The code looks great, but I like having the ability to test for more than 1 condition in one and. Plus I like to use enums where they make sense :)
Just a bit of code shifting instead of COLOR_ANY and COLOR_COLORLESS you get Color.ANY and Color.COLORLESS plus the compiler will say if you pass the wrong enum into the function!
Last edited by Snacko on 15 Mar 2009, 20:48, edited 1 time in total.
Snacko
DEVELOPER
 
Posts: 826
Joined: 29 May 2008, 19:35
Has thanked: 4 times
Been thanked: 74 times

Re: Manalink C/ASM Dll

Postby jatill » 15 Mar 2009, 20:48

Snacko wrote:The code is wrong if you used harry's functions you need to use the bit & and not the logical &&
return GetCardInfoState(Player, Card) & 0x10;
The code looks great, but I like having the ability to test for more than 1 condition in one and. Plus I like to use enums where they make sense :)
I did the entire is_tapped in asm, so the code is right.
jatill
DEVELOPER
 
Posts: 2118
Joined: 24 Feb 2009, 16:35
Has thanked: 5 times
Been thanked: 17 times

Re: Manalink C/ASM Dll

Postby HarryPitfall » 15 Mar 2009, 21:14

My main language is object pascal, javascript and php (these 2 are much like C in sintax)... but sometimes I did these small mistakes (and of course, correct while I test my programs and notices the bug).
I normally use sets and enums for data, is clean and very readable, and the most important... it's document itself!
Jatill, if you look into other mana artifacts, you will see that the code handles the special case if the animated... did you know? Celestial Prism have the code... much like the one that I show to you, to see if is a creature and check summon sickness too... (since if it's animated, you can't tap if it's sickness), these small cases are the great feature and headaches of magic the gathering... ;)
HarryPitfall
AI Programmer
 
Posts: 175
Joined: 31 May 2008, 00:14
Has thanked: 1 time
Been thanked: 3 times

Re: Manalink C/ASM Dll

Postby jatill » 15 Mar 2009, 21:19

HarryPitfall wrote:My main language is object pascal, javascript and php (these 2 are much like C in sintax)... but sometimes I did these small mistakes (and of course, correct while I test my programs and notices the bug).
I normally use sets and enums for data, is clean and very readable, and the most important... it's document itself!
Jatill, if you look into other mana artifacts, you will see that the code handles the special case if the animated... did you know? Celestial Prism have the code... much like the one that I show to you, to see if is a creature and check summon sickness too... (since if it's animated, you can't tap if it's sickness), these small cases are the great feature and headaches of magic the gathering... ;)
You're right that my artifact doesn't work right if animated. I skipped that code. I ran out of time today, but I'll definitely add that in next version. Why the engine wasn't written smart enough to handle that case, I'll never know.
jatill
DEVELOPER
 
Posts: 2118
Joined: 24 Feb 2009, 16:35
Has thanked: 5 times
Been thanked: 17 times

Re: Manalink C/ASM Dll

Postby Snacko » 15 Mar 2009, 21:43

@jatill
let's keep the naming convention for card functions so
Code: Select all
return card_llanowar_elves(player, card, event);
not
Code: Select all
return llanowar_elves(player, card, event);
:wink: small things but those matter too
Snacko
DEVELOPER
 
Posts: 826
Joined: 29 May 2008, 19:35
Has thanked: 4 times
Been thanked: 74 times

Re: Manalink C/ASM Dll

Postby jatill » 15 Mar 2009, 21:58

Snacko wrote:@jatill
let's keep the naming convention for card functions so
Code: Select all
return card_llanowar_elves(player, card, event);
not
Code: Select all
return llanowar_elves(player, card, event);
:wink: small things but those matter too
No objections here.
jatill
DEVELOPER
 
Posts: 2118
Joined: 24 Feb 2009, 16:35
Has thanked: 5 times
Been thanked: 17 times

Re: Manalink C/ASM Dll

Postby Snacko » 16 Mar 2009, 13:17

Already got the code to use the struct at least the known places I'm not sure about the slot1 size but the sample
Code: Select all
int card_test(int player, int card, Event event){
   cardInfo* c = get_card_info(player, card);
   c->state = 2;
   c->cardColor = 3;
   c->targetPlayer = 4;
   c->targetCard = 5;
   c->slot1 = 6;
   return 0;
}
maps to
Code: Select all
00000000 <_card_test>:
   0:   55                      push   ebp
   1:   89 e5                   mov    ebp,esp
   3:   ff 75 0c                push   DWORD PTR [ebp+0xc]
   6:   ff 75 08                push   DWORD PTR [ebp+0x8]
   9:   e8 00 00 00 00          call   e <_card_test+0xe>
   e:   c7 40 08 02 00 00 00    mov    DWORD PTR [eax+0x8],0x2
  15:   c7 40 59 03 00 00 00    mov    DWORD PTR [eax+0x59],0x3
  1c:   c7 40 74 04 00 00 00    mov    DWORD PTR [eax+0x74],0x4
  23:   c7 40 78 05 00 00 00    mov    DWORD PTR [eax+0x78],0x5
  2a:   c7 40 38 06 00 00 00    mov    DWORD PTR [eax+0x38],0x6
  31:   b8 00 00 00 00          mov    eax,0x0
  36:   c9                      leave
  37:   c3                      ret
Will wait for LoneFox to post his sources and merge it, or if he wants to merge it I can post sooner.
Snacko
DEVELOPER
 
Posts: 826
Joined: 29 May 2008, 19:35
Has thanked: 4 times
Been thanked: 74 times

Re: Manalink C/ASM Dll

Postby jatill » 16 Mar 2009, 13:24

That's a nice start. One thing that confuses me about get_card_info is that to gets certain card properties, you have to do shifting and adding. For example, here is the code to test card type. I don't understand the shifting and adding parts, I've just copied it successfully in the past :) Can you incorporate this into your structure, as well as creature type 1 and 2?

Finally, can you tell the difference between get_card_info (401A80) and get_card_info* (401a40). I haven't done the research, but they seem almost interchangeable.

Code: Select all
004DF6FF A1848C7300 mov eax, [$738c84]
004DF704 8B0D8C397A00 mov ecx, [$7a398c]
004DF70A E83123F2FF call -$ddccf ($401a40)
004DF70F 7566 jnz +$66 ($4df777)
004DF711 8B466C mov eax, [esi+$6c]
004DF714 C1E003 shl eax, 3
004DF717 8A8CC038707E00 mov cl, [eax+eax*8+$7e7038]
004DF71E F6C102 test cl, 2 <- 2 is creature in Card Type inside Magic.exe
004DF721 7454 jz +$54 ($4df777)
jatill
DEVELOPER
 
Posts: 2118
Joined: 24 Feb 2009, 16:35
Has thanked: 5 times
Been thanked: 17 times

Re: Manalink C/ASM Dll

Postby Snacko » 16 Mar 2009, 13:41

the code translates to
Code: Select all
004DF711 8B466C mov eax, [esi+$6c]
int id = c->cardID <- the id from Manalink.csv
004DF714 C1E003 shl eax, 3
004DF717 8A8CC038707E00 mov cl, [eax+eax*8+$7e7038] <- $7e7038 is the cardType base address in the cardsData array
short cardType = cardDataArray[id].type; <-- the struct from post below imported to c
if(cardType == CREATURE)
.... rest of the code
it's more of raw data pushing like
shl -> id *= 8;
eax+eax*8+$7e7038 -> base address + 9* eax = base address * 9 * 8 * id
9*8 = 72 and this is the size of the cardData structure

edit:
401A80 just gets the info
while 401a40 tests the esi+6f agains 0x80
Code: Select all
if ( [esi+6f] == 0x80){
    edx = [esi+0x8] // cardStatus
    edx &= 0x800022; 100000000000000000100010 that checks for 3 conditions
    if(edx == 0x2 ) // only tapped
         // returns with the flags registers set so we can do a jne after the call without any other comparisons
}
Last edited by Snacko on 16 Mar 2009, 15:43, edited 2 times in total.
Snacko
DEVELOPER
 
Posts: 826
Joined: 29 May 2008, 19:35
Has thanked: 4 times
Been thanked: 74 times

Re: Manalink C/ASM Dll

Postby HarryPitfall » 16 Mar 2009, 13:48

OK, i can inspect the code inside magic.exe and try to figure....
Nice work with structs snacko... this is the best approach IMHO...

And... If the data structure is 72 bytes.... can someone confirm if it's the same structure used on editor? (is pascal, but is easy to understand)

Code: Select all

  TMagicCard = Packed Record
    Case Boolean Of
      True: (
        ubSecret: Byte;
        lpName: Array[0..17] Of Char;
        lpReserved1: Array[0..16] Of Byte;
        uwID: Word;
        lpReserved2: Array[0..1] Of Byte;
        ubType: Byte;
        ubSubType: Byte;
        ubColor: Byte;
        ubCC: Array[0..2] Of Byte;
        uwPower: Word;
        uwTough: Word;
        lpReserved3: Array[0..1] Of Byte;
        lpCodePointer: Cardinal;
        uwStaticAbility: Array[0..3] Of Byte;
        uwExtraAbility: Array[0..0] Of Byte;
        lpReserved4: Array[0..10] Of Byte;
        );
      False: (
        lpRawData: Array[0..71] Of Byte;
        );
  End;
  PMagicCard = ^TMagicCard;
HarryPitfall
AI Programmer
 
Posts: 175
Joined: 31 May 2008, 00:14
Has thanked: 1 time
Been thanked: 3 times

PreviousNext

Return to Development

Who is online

Users browsing this forum: No registered users and 12 guests

Main Menu

User Menu

Our Partners


Who is online

In total there are 12 users online :: 0 registered, 0 hidden and 12 guests (based on users active over the past 10 minutes)
Most users ever online was 7303 on 15 Jul 2025, 20:46

Users browsing this forum: No registered users and 12 guests

Login Form