Author Topic: Questions regarding codebase  (Read 7808 times)

Emre

  • Member
  • Posts: 12
  • Karma: +1/-0
    • View Profile
Questions regarding codebase
« on: October 21, 2016, 04:08:03 AM »
Hi, I will probably have some questions regarding the codebase, so I will be posting them here.

I think these are leftovers from some debugging? The function that is being called has an empty body.

https://github.com/ExiguusEntertainment/AmuletsArmor/blob/master/Source/FILE.C#L151

For some reason, I am unable to read RES files. It looks like reading the binary files directly to structs is failing somehow. The second element in the index gets garbled, its name field does not have the correct information, etc. My guess is that it is probably due to struct packing issues between different compilers.
« Last Edit: October 21, 2016, 05:10:21 AM by Emre »

peewee_RotA

  • Sr. Member
  • Posts: 272
  • Karma: +8/-0
    • View Profile
Re: Questions regarding codebase
« Reply #1 on: October 21, 2016, 05:59:31 AM »
This would be a great question for LysleShields. I've not tackled anything with the RES files. But he has mentioned there being a RES packing program lying around for creating them. That might help determine what the extra bits of data are.


Last mentioned here:
http://amuletsandarmor.com/forum/index.php?topic=179.msg888#msg888

Emre

  • Member
  • Posts: 12
  • Karma: +1/-0
    • View Profile
Re: Questions regarding codebase
« Reply #2 on: October 21, 2016, 06:13:41 AM »
Yep. I hope he sees this thread.

I am basically porting A&A to OS X at the moment. Almost everything is already done by Lysle, but some issues remained (e.g. platform specific functions, includes, compiler shenanigans). I managed to compile it after pulling an all-nighter. Now it segfaults due to not being able to load resources properly.

I am also trying to target SDL2 at the moment, but since I could not see any graphics so far, I do not know if I succeeded setting up the graphics surfaces and such.

Also, I think I will be refactoring a lot of stuff. Currently moved the data from the Exe folder to some separate folders and managed to get a CMake build up for OS X. I will need to add platform-specific settings for Linux (which should be easy after OS X, it's *nix after all) and for Windows.

I had to disable some sections of the code (e.g. SOS library) as they seem to be hard to port. I was almost stuck with the assembly implementation of graphics functions as well since it seems to be MASM, but gratefully there were C alternatives using a compiler flag. Overall it's going better than I expected. I hope to provide some results soon. My only concern is the divergence of graphics branch and your mod fork with my changes, but I guess I can apply the changes over my edition.

Edit: To clarify the problem above, I am using almost completely vanilla RESOURCE.C files. The game crashes while trying to load the fonts from SAMPLE.RES.
« Last Edit: October 21, 2016, 07:06:32 AM by Emre »

Emre

  • Member
  • Posts: 12
  • Karma: +1/-0
    • View Profile
Re: Questions regarding codebase
« Reply #3 on: October 22, 2016, 08:50:05 PM »
Managed to work around the problem by implementing a custom deserializer for resources. Looks like I am getting them correctly now.

I heard the first thunder sound before crash (still no graphics :D) but I am getting non-deterministic SIGABRT crashes now. Something is off regarding memory stuff, have to figure it out.

I have also seen that some pointers are being cast to 32 bit integers and then being passed to functions, only to be converted back to pointers again. I think this won't work in 64 bit systems as the size of a pointer should be 8 bytes... Will have to change function signatures I guess.

I am afraid of introducing some bugs that I will have a very hard time of solving, but it does not work now anyway.
« Last Edit: October 23, 2016, 07:14:10 AM by Emre »

Emre

  • Member
  • Posts: 12
  • Karma: +1/-0
    • View Profile
Re: Questions regarding codebase
« Reply #4 on: October 23, 2016, 08:46:16 AM »
Figured out the issue. It was a combination of late night programming and file size issues. I was allocating memory for resource structs based on the information coming from file, which was (obviously, in hindsight) wrong, since it was built using another platform.

Oh boy. :D



Edit: Aaand hacked something together. Simple type mistake cost me a couple of hours though.



Edit 2: Somehow the pictures are not being displayed. I can see them being loaded by comparing the hex headers with SLADE, but somehow they are not drawn...



Published my fork at this address: https://github.com/emrecelikten/AmuletsArmor

Edit 3: Got it somewhat working. Keyboard doesn't really work at the moment. Mouse is barely working.

It was caused by (presumably) very old GNU C compiler-specific setting in the code where an array was initialized with one element instead of being empty, causing some memory addresses to shift by one. Therefore, if a picture was 320x200, it would become 0x320, which means no picture. GCC was silently passing that flag into the compilation.



Now character creation fails with memory corruption errors again. I think I have found the cause: https://github.com/ExiguusEntertainment/AmuletsArmor/blob/master/Source/OBJTYPE.C#L1073

This puts a 8-byte pointer to the sixth byte of a 10 byte record, overwriting the next record. Might have to rewrite sections of this, but not sure if I will see this problem in other places. There must be a way for a general solution for this kind of issues.
« Last Edit: October 24, 2016, 03:12:34 AM by Emre »

peewee_RotA

  • Sr. Member
  • Posts: 272
  • Karma: +8/-0
    • View Profile
Re: Questions regarding codebase
« Reply #5 on: October 24, 2016, 08:35:36 AM »
If you're running to SDL2 related issues, I kind of put that off in the windows version, but this was a handly explanation of what was wrong that way:
http://amuletsandarmor.com/forum/index.php?topic=168.0

If you need any help with an OSX port, somebody started one a few years ago. Might have some useful tidbits:
https://github.com/alexey-lysiuk/AmuletsArmor

Also, Great work so far. Keeep it up!

Emre

  • Member
  • Posts: 12
  • Karma: +1/-0
    • View Profile
Re: Questions regarding codebase
« Reply #6 on: October 26, 2016, 07:15:25 PM »


Items in store had mysteriously disappeared. It turns out that struct packing was not enabled in item descriptions, which caused a byte shift, which caused the item to be not found as usable for the current class.

Not anymore!