It is currently 27 Apr 2024, 01:58
   
Text Size

C question -magic related

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

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

C question -magic related

Postby jatill » 24 Apr 2009, 13:07

This is addressed to Snacko, but if anyone else knows the answer, please jump in.

The magic.exe card data is being defined as a struct. How do I go about changing the struct so that the code_pointer piece actually behaves like a function pointer? (i.e. I can call it, passing in the appropriate params)?

/* Data struct */
typedef struct
{
...
uint16_t toughness;
uint16_t reserved3;
uint32_t code_pointer;
uint32_t static_ability;
...
} PACKED card_data_t;

I want to be able to do (*card_d.code_pointer)(player, card, event);, or somehting similar.
jatill
DEVELOPER
 
Posts: 2118
Joined: 24 Feb 2009, 16:35
Has thanked: 5 times
Been thanked: 17 times

Re: C question -magic related

Postby Bog Wraith » 24 Apr 2009, 14:20

May I just add, if Snacko or another programmer could also inform us if it is possible & if so, how to circumvent and break the 2000 card limit. Obviously a very important step forward for further development of ManaLink!

Thanks.
'Twas in the bogs of Cannelbrae
My mate did meet an early grave
'Twas nothing left for us to save
In the peat-filled bogs of Cannelbrae.
User avatar
Bog Wraith
Global Mod 1 (Ret)
 
Posts: 1108
Joined: 28 May 2008, 22:40
Location: Shandalar
Has thanked: 425 times
Been thanked: 153 times

Re: C question -magic related

Postby gmzombie » 25 Apr 2009, 00:13

that is what i was wonderign Bog. if we can create dll files for a particular set or cycle maybe the game wouldnt crash? i mean it dosent seem to be logical that it would crash after 2000 cards but it does. that leads me to believe that there is more of maybe a size limit on the magic exe? anyone can chime in and prove me wrong...i am not a programmer i just play one on TV.
can I maze of ith your snowstorm?

http://home.comcast.net/~gmzombie/index.html old stuff in here. don't use this stuff right now till I get time to get back into it and readjust.
gmzombie
 
Posts: 857
Joined: 26 Feb 2009, 01:05
Location: Wyoming, Mi
Has thanked: 200 times
Been thanked: 51 times

Re: C question -magic related

Postby Snacko » 25 Apr 2009, 12:20

Not sure if this does need some more voodoo in terms of conversion / calling conversion but probably does.
Code: Select all
int (*ptFunction)(float, char, char) = code_pointer;
int result1 = pt2Function    (12, 'a', 'b');
It is possible to get around the 2k card limit as it most likely only a matter of tables being full at that point. This means you need to move the tables to some new place where we can have a much higher limit. It would be best to get them around the cards definitions but god knowns why the data / code sections have been intermixed and I would touch that section. This means you most likely need to make the exe bigger, add a new data section, move the tables and extend them, then patch all the calls to the new addresses. It's basically the same (really lots of work depending on how many calls to these tables there are) as the patched shandalar I made for testing..
Snacko
DEVELOPER
 
Posts: 826
Joined: 29 May 2008, 19:35
Has thanked: 4 times
Been thanked: 74 times

Re: C question -magic related

Postby jatill » 25 Apr 2009, 12:43

Snacko wrote:It is possible to get around the 2k card limit as it most likely only a matter of tables being full at that point. This means you need to move the tables to some new place where we can have a much higher limit. It would be best to get them around the cards definitions but god knowns why the data / code sections have been intermixed and I would touch that section. This means you most likely need to make the exe bigger, add a new data section, move the tables and extend them, then patch all the calls to the new addresses. It's basically the same (really lots of work depending on how many calls to these tables there are) as the patched shandalar I made for testing..
Looking at the old magic.c, there is just one array with size 2000, so I'm guessing that's the cards array. If it is, the array is only used in a single pace in the whole code. Does that mean only one call would need to be updated?

In any case, if this is something you think you can do, we'd be most grateful for your help. If there are a lot of calls to be updated, I'll do the grunt work if you can give me specific instructions on what to do.
Thanks.
jatill
DEVELOPER
 
Posts: 2118
Joined: 24 Feb 2009, 16:35
Has thanked: 5 times
Been thanked: 17 times

Re: C question -magic related

Postby Bog Wraith » 25 Apr 2009, 14:28

Snacko wrote: It's basically the same (really lots of work depending on how many calls to these tables there are) as the patched shandalar I made for testing..
Any further news on Shandalar and if we can get our hands on a version that we can test that has some new cards in it?

If not, is it still something that you plan to work on in the near future? [-o<
'Twas in the bogs of Cannelbrae
My mate did meet an early grave
'Twas nothing left for us to save
In the peat-filled bogs of Cannelbrae.
User avatar
Bog Wraith
Global Mod 1 (Ret)
 
Posts: 1108
Joined: 28 May 2008, 22:40
Location: Shandalar
Has thanked: 425 times
Been thanked: 153 times

Re: C question -magic related

Postby Snacko » 25 Apr 2009, 14:52

At least 0x60EFDC (some storage 20 * number of cards, currently max 100 elements, pointers to strings) and 0x73BAE0 (cards data stored) have to be moved thats ~20 cross references to patch to start with.
Personally I would create a patcher with dup2 as those can be compacted to ~5 rules.

There's 0x55D0E0 which theoretically can hold items up to ~4000. There also might be other arrays less obvious to patch...

It seems the pointers to strings are already overwriting some other values, because there is only space for 100 cards...

Currently I'm very busy so I can't say I will do any of these, as for Shandalar adding new cards is as easy as editing cards1.dat ;)
I can post the IDA decompiles in a pseudo C of both loading routines for cards.dat and cards1.dat if anyone wants to work on it.
Snacko
DEVELOPER
 
Posts: 826
Joined: 29 May 2008, 19:35
Has thanked: 4 times
Been thanked: 74 times

Re: C question -magic related

Postby Bog Wraith » 25 Apr 2009, 15:23

Unfortunately, I have zero knowledge and skill for doing this, nor would I have the time to learn how.

I hope those that do, will offer their time and skills to help this along. 8)
'Twas in the bogs of Cannelbrae
My mate did meet an early grave
'Twas nothing left for us to save
In the peat-filled bogs of Cannelbrae.
User avatar
Bog Wraith
Global Mod 1 (Ret)
 
Posts: 1108
Joined: 28 May 2008, 22:40
Location: Shandalar
Has thanked: 425 times
Been thanked: 153 times

Re: C question -magic related

Postby jatill » 25 Apr 2009, 15:56

Snacko wrote:Not sure if this does need some more voodoo in terms of conversion / calling conversion but probably does.
Code: Select all
int (*ptFunction)(float, char, char) = code_pointer;
int result1 = pt2Function    (12, 'a', 'b');
That worked perfectly. Much obliged.
jatill
DEVELOPER
 
Posts: 2118
Joined: 24 Feb 2009, 16:35
Has thanked: 5 times
Been thanked: 17 times

Re: C question -magic related

Postby jatill » 25 Apr 2009, 20:58

Now here's an even more basic question. How do I write to a file? I tried:

file = fopen("debug_out.txt","a+");

and putting

#include <stdio.h>
#include <stdlib.h>

in manalink.h, but I still get undefined reference to fopen
jatill
DEVELOPER
 
Posts: 2118
Joined: 24 Feb 2009, 16:35
Has thanked: 5 times
Been thanked: 17 times

Re: C question -magic related

Postby Snacko » 25 Apr 2009, 21:30

You want to link to the same fopen as in magic.exe so need to add
_fopen = 0xXXXXXX;
to manalink.lds
where those XXXX point to the import pointer of fopen in magic.exe

Plus I would advise not to use the bulky includes and only cherry pick what you need (we don't link to the standard c library so you can't use anything but what's available in magic.exe) like
typedef struct _iobuf
{
char* _ptr;
int _cnt;
char* _base;
int _flag;
int _file;
int _charbuf;
int _bufsiz;
char* _tmpfname;
} FILE;
FILE* fopen (const char*, const char*);
to the headers and maybe just move all those c function defines to a new file like c_functions.h
Snacko
DEVELOPER
 
Posts: 826
Joined: 29 May 2008, 19:35
Has thanked: 4 times
Been thanked: 74 times

Re: C question -magic related

Postby Snacko » 27 Apr 2009, 21:37

@jatill
I've downloaded the latest source files and they're a mess.
There's a tons of warning generated, because all the functions aren't defined in the header.
There are some unneeded files like ManalinkEc.asm, ManalinkEc.def and others. Plus if you recoded the karoos into c you should move or delete the *.asm files as the linker is clueless and doesn't know which version it should link to the asm or c one. Same goes for shadow ability.
Snacko
DEVELOPER
 
Posts: 826
Joined: 29 May 2008, 19:35
Has thanked: 4 times
Been thanked: 74 times

Re: C question -magic related

Postby Tower_Mazer » 27 Apr 2009, 22:33

Snacko wrote:@jatill
I've downloaded the latest source files and they're a mess.
There's a tons of warning generated, because all the functions aren't defined in the header.
There are some unneeded files like ManalinkEc.asm, ManalinkEc.def and others. Plus if you recoded the karoos into c you should move or delete the *.asm files as the linker is clueless and doesn't know which version it should link to the asm or c one. Same goes for shadow ability.
For beginners such as myself, would having ManalinkEc.asm, ManalinkEc.def and others cause errors when using Perl to build? That seemed to be my conclusion with a lot of help from Jatill. I still get random errors sometimes and I bet I have files I don't need somewhere still.
Thank you for taking a look too bad you can't work on this project anymore. I really enjoy seeing and playing this game as it evolves. Since I've been here the project lost Harry Pitfall and after reading your post about the Shandalar progress I was kinda bummed out. Who knows though on the internet someone may come with the deeper knowledge we need and break the 2000 card limit and the adding of new cards in Shandalar. I hope so anyway.

[EDIT]
I'm not counting Jatill out I bet he will crack the limits someday because he enjoys modding more than playing (I think anyway and I'm that way) and that with his determination nothing is impossible.
User avatar
Tower_Mazer
 
Posts: 53
Joined: 15 Mar 2009, 15:59
Has thanked: 0 time
Been thanked: 0 time

Re: C question -magic related

Postby Bog Wraith » 27 Apr 2009, 23:20

I'm confident that with Snacko's help, jatill can get the 2000 card limit solved.

As for Shandalar, again, Snacko has made it seem that doing the grunt work with the cards1.dat file can get a lion's share of the work done to get all these great new cards into Shandalar. There must be a few of the guys that have done a bit of the programming here or are new to doing anything to do with it who can do this work. As I said earlier, I'm not one who has the skill or knowledge to do this, but I know that there are guys here who can. All we need is them or even one to roll up their sleeves and begin the work. I'm confident that Snacko will help anyone who poses any questions when they need any info.

There are always folks who ask if there is something that they could do to help out.
Well, here is an opportunity to greatly contribute to this awesome game and help to advance it in a huge way.
It doesn't matter how long it might take to do this. The important thing is to find the right folks who are motivated to do it and to begin the process.

Who will step up and help out jatill and the others who have done such an amazing job for all of us? I know that your out there!
'Twas in the bogs of Cannelbrae
My mate did meet an early grave
'Twas nothing left for us to save
In the peat-filled bogs of Cannelbrae.
User avatar
Bog Wraith
Global Mod 1 (Ret)
 
Posts: 1108
Joined: 28 May 2008, 22:40
Location: Shandalar
Has thanked: 425 times
Been thanked: 153 times

Re: C question -magic related

Postby Snacko » 28 Apr 2009, 08:19

@Tower_Mazer
There are overlapping functions and undefined references plus tons of warning which should be fixed. It wont compile in the current form unless at least the undefined references are fixed.
Snacko
DEVELOPER
 
Posts: 826
Joined: 29 May 2008, 19:35
Has thanked: 4 times
Been thanked: 74 times

Next

Return to Development

Who is online

Users browsing this forum: No registered users and 42 guests


Who is online

In total there are 42 users online :: 0 registered, 0 hidden and 42 guests (based on users active over the past 10 minutes)
Most users ever online was 4143 on 23 Jan 2024, 08:21

Users browsing this forum: No registered users and 42 guests

Login Form