1. Forum moved (you can use login and pass from old forum)
  2. Many discussions moved to the bugtracker

Owerniship of buildings

Discussion in 'Game Mods' started by Paddywhacker, Jan 22, 2015.

  1. Paddywhacker

    Paddywhacker Registered

    Joined:
    Jul 18, 2014
    Messages:
    11
    Likes Received:
    0
    Best Answers:
    0
    I have been investigating who owns what buildings on the vanilla map so that I can make a tool for changing ownerships in a savegame. https://imgur.com/qii18Ye

    So far I haven't found anything in the savegame that corresponds to this data. Does anybody have any ideas?
     
  2. JonnyH

    JonnyH Well-Known Member Official Developer Administrator

    Joined:
    Jul 17, 2014
    Messages:
    184
    Likes Received:
    36
    Best Answers:
    0
    Hola!

    I already have a bit of work done figuring out where the building owners etc. are defined: the files ufodata/citymap*.bld (citymap1, 2, 3, 4 & 5 match the cities for each difficulty).

    The code to read them can be found here: https://github.com/JonnyH/OpenApoc/blob/master/game/city/building.cpp

    These are binary files, in chunks of 226 bytes (IE each building definition is 226 bytes).

    Currently known values within each of those chunks:
    0x00 uint16: Building name index
    0x02 uint16: Building position X0
    0x04 uint16: Building position X1
    0x06 uint16: Building position Y0
    0x08 uint16: Building position Y1
    0xc8 uint16: building Owner ID

    The name index and owner ID are lookup tables into the .exe. At the beginning of the c++ file linked above you can see the copy I extracted of the building names, in the organisation.cpp file in the same directory are the owners (e.g. owner '0' is X-Com, '1' is Alien, '2' is government etc.)

    I don't think you can add new names/organisations without editing the .exe (which would take a /huge/ amount of work).

    The X/Y coordinates define the area of the city that the 'building' exists - all city tiles within this rectangle are part of that building.

    There is a copy of this whole file somewhere in the savegame - you might be able to find it by searching for a chunk that doesn't change (e.g. the x/y position) of a known building. Many of the values in the 226 bytes appear to change in the savegame, and are zero in the citymapX.bld file, so that's possibly where they store other building information (e.g. if there are aliens within) for the savegame.

    If you can get the hex-editor out and start tweaking these values, I would be /very/ interested in any discoveries....

    Jonny
     
  3. Paddywhacker

    Paddywhacker Registered

    Joined:
    Jul 18, 2014
    Messages:
    11
    Likes Received:
    0
    Best Answers:
    0
  4. JonnyH

    JonnyH Well-Known Member Official Developer Administrator

    Joined:
    Jul 17, 2014
    Messages:
    184
    Likes Received:
    36
    Best Answers:
    0
    Yes, I believe the whole .bld is copied from the 'starting copy' (citymap*.bld) into the save game, then modified as needed to reflect the 'current state' on the savegame. I suggest using these values to find this 'stored' .bld copy, as I don't think they change state when stored in the save.

    The city itself is a 100x100x10 block of uint16 tile indexes in the citymap* (no extension) files. these are indexes into city.pck/city.tab (for the tile images) and citymap.dat (for some other tile metadata, which I haven't really figured out yet)
    The X/Y coordinates relate to these map tiles.
     
  5. Paddywhacker

    Paddywhacker Registered

    Joined:
    Jul 18, 2014
    Messages:
    11
    Likes Received:
    0
    Best Answers:
    0
    Thanks, I have found it by looking for repeating structure of 226 bytes. It is located at 0x017E4E in the savegame, but the structure of the records is not as expected. Byte zero is the name index, but the owner index is located at relative byte 0xC8. My experimental Winhex template is:-

    Edit:- updated.

    template "UFOAPOC Buildings"
    description "Version 1.0 23 Jan 2015"
    //
    // Patrick Sweetman
    // 23/01/2015
    //
    fixed_start 0x017E4E
    multiple 0xE2
    begin
    int16 "Name index"
    int16 "X0"
    int16 "X1"
    int16 "Y0"
    int16 "Y1"
    int16 "unknown 0A"
    int16 "unknown 0C"
    int16 "unknown 0E"
    int16 "unknown 10"
    int16 "unknown 12"
    int16 "unknown 14"
    int16 "unknown 16"
    int16 "unknown 18"
    int16 "unknown 1A"
    int16 "unknown 1C"
    int16 "unknown 1E"
    int16 "unknown 20"
    int16 "unknown 22"
    int16 "unknown 24"
    int16 "unknown 26"
    int16 "unknown 28"
    int16 "unknown 2A"
    int16 "unknown 2C"
    int16 "unknown 2E"
    int16 "unknown 30"
    int16 "unknown 32"
    int16 "unknown 34"
    int16 "unknown 36"
    int16 "unknown 38"
    int16 "unknown 3A"
    int16 "unknown 3C"
    int16 "unknown 3E"
    int16 "unknown 40"
    int16 "unknown 42"
    int16 "unknown 44"
    int16 "unknown 46"
    int16 "unknown 48"
    int16 "unknown 4A"
    int16 "unknown 4C"
    int16 "unknown 4E"
    int16 "unknown 50"
    int16 "unknown 52"
    int16 "unknown 54"
    int16 "unknown 56"
    int16 "unknown 58"
    int16 "unknown 5A"
    int16 "unknown 5C"
    int16 "unknown 5E"
    int16 "unknown 60"
    int16 "unknown 62"
    int16 "unknown 64"
    int16 "unknown 66"
    int16 "unknown 68"
    int16 "unknown 6A"
    int16 "unknown 6C"
    int16 "unknown 6E"
    int16 "unknown 70"
    int16 "unknown 72"
    int16 "unknown 74"
    int16 "unknown 76"
    int16 "unknown 78"
    int16 "unknown 7A"
    int16 "unknown 7C"
    int16 "unknown 7E"
    int16 "unknown 80"
    int16 "unknown 82"
    int16 "unknown 84"
    int16 "unknown 86"
    int16 "unknown 88"
    int16 "unknown 8A"
    int16 "unknown 8C"
    int16 "unknown 8E"
    int16 "unknown 90"
    int16 "unknown 92"
    int16 "unknown 94"
    int16 "unknown 96"
    int16 "unknown 98"
    int16 "unknown 9A"
    int16 "unknown 9C"
    int16 "unknown 9E"
    int16 "unknown A0"
    int16 "unknown A2"
    int16 "unknown A4"
    int16 "unknown A6"
    int16 "unknown A8"
    int16 "unknown AA"
    int16 "unknown AC"
    int16 "unknown AE"
    int16 "unknown B0"
    int16 "unknown B2"
    int16 "unknown B4"
    int16 "Sellable?"
    int16 "unknown B8"
    byte "Sale Price (X 2000)"
    byte "unknown BB"
    int16 "unknown BC"
    int16 "unknown BE"
    int16 "unknown C0"
    int16 "unknown C2"
    int16 "unknown C4"
    int16 "unknown C6"
    int16 "Owner"
    int16 "unknown CA"
    int16 "unknown CC"
    int16 "unknown CE"
    int16 "unknown D0"
    int16 "unknown D2"
    int16 "unknown D4"
    int16 "unknown D6"
    int16 "unknown D8"
    int16 "unknown DA"
    int16 "unknown DC"
    int16 "unknown DE"
    int16 "unknown E0"
    end
     
  6. JonnyH

    JonnyH Well-Known Member Official Developer Administrator

    Joined:
    Jul 17, 2014
    Messages:
    184
    Likes Received:
    36
    Best Answers:
    0
    Yeah, the owner is at 0xc8, I think I listed that (Sorry if it was confusing if you assumed the list I had was adjacent in memory :)
     
  7. Paddywhacker

    Paddywhacker Registered

    Joined:
    Jul 18, 2014
    Messages:
    11
    Likes Received:
    0
    Best Answers:
    0
    OK, I have updated my previous post with the template. The usassigned bytes don't seem to do anything when they are zeroed out or overwritten with 0xFF. There might be a flag for alien infiltration of the building, put I'm leaving it at that for now. Thanks for your help.
     
  8. bobucles

    bobucles Registered

    Joined:
    Sep 26, 2014
    Messages:
    169
    Likes Received:
    8
    Best Answers:
    0
    Some ideas for what that missing data might be:

    - Aliens DO have a life cycle. Eggs hatch, worms spawn, Chrysallids mutate, aliens grow old and die. Some data may be related to that.

    - Aliens DO have some kind of migration pattern. After a while in one building they can spread to other buildings. Perhaps some data pertains to that.

    - Aborted projects like VIPs, actual investigations and such may be contained there. Since they never made it in game oh well.

    - Buildings will generate vehicles seemingly at random. Perhaps some relevant data is there.

    - There may be some battlescape data such as spawn points or map type? Kinda stretching here.

    - It could just be nothing! Dead ends or an artifact of saving that never gets used for some reason.

    It may be impossible to know what the information is or if it even gets used without decompiling the exe.
     
  9. Paddywhacker

    Paddywhacker Registered

    Joined:
    Jul 18, 2014
    Messages:
    11
    Likes Received:
    0
    Best Answers:
    0
    They'll be in the savegame somewhere for sure, but not necessarily in this buildings section.

    Decompiling the exe with IDA is straight-forward. Most of it is library routines from the C compiler and the remainder is not very informative. Is there a forum thread on this topic?
     

Share This Page