1. We have added a Gift Upgrades feature that allows you to gift an account upgrade to another member, just in time for the holiday season. You can see the gift option when going to the Account Upgrades screen, or on any user profile screen.
    Dismiss Notice

JCivED - a toolbox for Civilization

Discussion in 'Civ1 - General Discussions' started by darkpanda, Jan 22, 2013.

  1. kirkham7

    kirkham7 Warlord

    Joined:
    Dec 22, 2012
    Messages:
    288
    Location:
    Hayward, CA
    Building upon that thought, it would be amazing to reset the game back to the choose a civ screen without leaving the game and also have the ability to change civs in the middle of a turn without exiting and editing in an editor...
     
  2. darkpanda

    darkpanda Dark Prince

    Joined:
    Oct 28, 2007
    Messages:
    600
    Live editing of process memory? ...... That sounds like an exciting challenge... Especially since CIV's memory is laid out in a completely static way, once you found its location......i am pretty sure DOSBox keeps it that way too, and that the difference between Windows and Linux access to a live process's memory is easy to encapsulate.... Very exciting indeed - as if I didn't lack time already :S
     
  3. darkpanda

    darkpanda Dark Prince

    Joined:
    Oct 28, 2007
    Messages:
    600

    Just to let you know, I am actively working on this feature, among other things
     
  4. kirkham7

    kirkham7 Warlord

    Joined:
    Dec 22, 2012
    Messages:
    288
    Location:
    Hayward, CA
    Ah, cool. That would definitely make it easier (and more fun) to create and edit maps.
    And editing the static memory, that will provide a challenge, but one that I think you could have some fun with.
     
  5. darkpanda

    darkpanda Dark Prince

    Joined:
    Oct 28, 2007
    Messages:
    600
  6. darkpanda

    darkpanda Dark Prince

    Joined:
    Oct 28, 2007
    Messages:
    600
    And here it is!

    A small release increment for JCivED, now at version 0.0.18a, which brings a new feature for map edition, originally requested by kirkham7: select/copy/cut/paste.

    That's it! (and minor a bug fix for Starting Positions patch UI).

    As usual, everything is on JCivED's home page :)

    Have fun!
    Cheers
     
  7. Quintillus

    Quintillus Archiving Civ3 Content Supporter

    Joined:
    Mar 17, 2007
    Messages:
    6,260
    Location:
    Columbus
    lurker's comment: Nice updates, particularly the selecting-and-moving-areas-of-the-map one. I continue to be impressed by the noteable improvements you've made. The occasional updates here are the primary reason I keep the Civ1 forum visible by default, even though I don't own the game myself.

    Live editing of memory would be very interesting. I've played around with it some with Civ3, and with some success. The problem with Civ3 is that while the in-memory structure resembles the save structure, it's not entirely the same. The location of structures in memory also varies from load to load (and if you load multiple games without restarting, it gets worse, since the old game's memory is not zeroed out). Civ1 might be more predictable in this regard, and the smaller address space would make locating structures in memory much quicker even if that weren't the case.

    The theoretical brick wall I've run into is that I haven't thought of a way to allocate new memory for the running process. So, I could update existing structures just fine, and look for certain triggers to do so. Doing that is limited primarily by the fact that it would take a lot of time, which so far I've put towards other things. But what if you wanted to add a new unit to the map? How to add that memory and have it be added in a way that Civ (1 or 3) would recognize it seems like a very difficult problem to me. Not that you can't do interesting things even without that, but if you have ideas as to how to get around that, I'd be curious to hear them.
     
  8. darkpanda

    darkpanda Dark Prince

    Joined:
    Oct 28, 2007
    Messages:
    600
    For Civ 1 it is pretty clear: most of the necessary memory to run the game is allocated once and then its size and shape almost never change.
    At least the main game data is always at the same place in memory.

    For example, the entire memory necessary to store 8*128 units is statically preallocated (at ds:90F4), with empty values (00 or FF), so if you want to add a new unit, all you have to do is modify those values in the right place.

    I don't how Civ 3 is coded: newer programming languages, especially OOP who rely a lot on object instantiation, must create a significant mess in memory, but I also know that relying a lot on object instantiation is usually a bad practice performance-wise, so maybe Civ3 still has some static anchors to help...

    Anyhow, the main problem is to locate the base address of CIV.EXE (or DOSBox) in memory - from this address, all individual offsets to atomic CIV data elements are always the same.

    In fact I have played around with ProcessHacker and DOSBox+CIV1 (in Win7) and I could successfully change which CIV I was playing, right in the middle of the game (as well as some text strings here and there).

    With ProcessHacker, I was able to locate the address segments used by DOSBox, and then in DOSBox's memory, I looked up the string "MS Run-Time Library - Copyright (c) 1988, Microsoft Corp" which is at the beginning of CIV.EXE's data segment (ds:0x8).

    Besides this, I have some working samples of Java code (using JNA) to read and write an external process memory in Windows (user32 + kernel32) and in Linux (ptrace).

    So the whole thing is setting in place, but that doesn't resolve the core issue: how to find the base memory address?
     
  9. darkpanda

    darkpanda Dark Prince

    Joined:
    Oct 28, 2007
    Messages:
    600
    Not sure why you'd ever want to build a city on hills, but anyway, here it is (untested):

    Code:
            Original bytes: 83 C4 0C FF 76 0C FF 76 0A B8 [color=red]24[/color] 00 50 
             Patched bytes: 83 C4 0C FF 76 0C FF 76 0A B8 [color=blue][b]00[/b][/color] 00 50 
            Offsets:
                EN47401: [b]0x46B75[/b]
                EN47403: [b]0x46B74[/b]
                EN47404: [b]0x46374[/b]
                EN47501: [b]0x46B75[/b]
                FR47405: [b]0x48774[/b]
    
    
     
  10. darkpanda

    darkpanda Dark Prince

    Joined:
    Oct 28, 2007
    Messages:
    600
    Here it is, but as usual, untested:

    Code:
    For version [b]FR47405[/b]:
            Original bytes: FF 76 0A FF 76 08 2B C0 50 [color=red]9A 4B 16 A3 1B[/color] 
             Patched bytes: FF 76 0A FF 76 08 2B C0 50 [color=blue][b]EB 03 00 00 00[/b][/color] 
            Offsets:
                FR47405: [b]0xC1C2[/b]
    
    For version [b]EN47403[/b]:
            Original bytes: FF 76 0A FF 76 08 2B C0 50 [color=red]9A 53 16 EA 1A[/color] 
             Patched bytes: FF 76 0A FF 76 08 2B C0 50 [color=blue][b]EB 03 00 00 00[/b][/color] 
            Offsets:
                EN47403: [b]0xAFC1[/b]
    
    For version [b]EN47404[/b]:
            Original bytes: FF 76 0A FF 76 08 2B C0 50 [color=red]9A 4F 16 69 1A[/color] 
             Patched bytes: FF 76 0A FF 76 08 2B C0 50 [color=blue][b]EB 03 00 00 00[/b][/color] 
            Offsets:
                EN47404: [b]0xA7BD[/b]
    
    For versions [b]EN47401[/b] and [b]EN47501[/b]:
            Original bytes: FF 76 0A FF 76 08 2B C0 50 [color=red]9A 45 16 05 1B[/color] 
             Patched bytes: FF 76 0A FF 76 08 2B C0 50 [color=blue][b]EB 03 00 00 00[/b][/color] 
            Offsets:
                EN47401: [b]0xAF33[/b]
                EN47501: [b]0xAF33[/b]
    
    
     
  11. darkpanda

    darkpanda Dark Prince

    Joined:
    Oct 28, 2007
    Messages:
    600
    I am looking at this one, and surprisingly enough it seems quite easy...

    Although documentation states that Shakespeare Theatre should become obsolete with Electronics, does anyone know whether this is really implemented?

    When looking at the code, it seems that CIV1 doesn't care at all about Electronics, so the effect of ST presumably outlasts its discovery...

    Anyone can confirm?
     
  12. darkpanda

    darkpanda Dark Prince

    Joined:
    Oct 28, 2007
    Messages:
    600
    Here is a patch that actually increases the limit from 10 to 127, instead of removing the limit per se (untested):

    Code:
            Original bytes: 80 3C [color=red]0A[/color] 
             Patched bytes: 80 3C [color=blue][b]7F[/b][/color] 
            Offsets:
                EN47401: [b]0x5A13[/b]
                EN47403: [b]0x5A61[/b]
                EN47404: [b]0x57B3[/b]
                EN47501: [b]0x5A13[/b]
                FR47405: [b]0x5B45[/b]
    
    
     
  13. tjs282

    tjs282 Un(a)bashed immigrant

    Joined:
    May 19, 2009
    Messages:
    2,522
    Location:
    ...just here for the job/ handouts/ woman
    I know this is off-topic, but how about "when trying to play as the Chinese or Indians on the original Earth Map"? ;)

    It's been a good while since I last played CivDOS, but (IIRC) the auto-irrigation for a city (giving an extra bushel from a normally 1-wheat tile) also works when when settling on Hills -- and of course you also get the Hill-shield (but don't do like I did, and settle on Coal-Hills! D'oh!), and the city-trade. Hills therefore represent just as good a settlement prospect as Bonus-Grass or Plains during the early game, under Despot. And settling on Hills also leaves you a few more Plains-tiles available to irrigate, and/or allows you to build a few more cities within a given area (the given areas for India and China being pretty bloody poor...).

    And your Hill-town defenders (I think) also get the Hill-defence boost, which comes in useful when the Zulus, Mongols or Russians come charging at you with all those left-over Chariots they had after finishing conquering the Europeans -- or when the Aztecs invade with their Tanks :eek:
     
  14. darkpanda

    darkpanda Dark Prince

    Joined:
    Oct 28, 2007
    Messages:
    600
    You're right, there could be reasons to do it :)
    In fact I still didn't play a single game since I dived into CIV.EXE, so I tend to lose sight of gameplay considerations...
     
  15. kirkham7

    kirkham7 Warlord

    Joined:
    Dec 22, 2012
    Messages:
    288
    Location:
    Hayward, CA
    That's exactly what I was thinking, being able to have a production boost instead of food. I will be testing all that you've posted today/yesterday this evening and let you know how it goes.
     
  16. darkpanda

    darkpanda Dark Prince

    Joined:
    Oct 28, 2007
    Messages:
    600
    In case it can help, here are the corresponding XML patches, to unzip into your JCivED/patches directory: View attachment patches.zip
     
  17. darkpanda

    darkpanda Dark Prince

    Joined:
    Oct 28, 2007
    Messages:
    600
    This one was trickier because lack of space forces me to jump around to get things done without requiring heavy handed changes (such as relocation table updates). Also, because it includes a lot of version-specific offsets, I only made it work for 47x.01 so far, but at least it is tested -> now provided for all versions.
    This patch transforms terrain to Arctic instantly upon pressing SHIFT+P:

    Code:
    For versions [b]EN47401[/b] and [b]EN47501[/b]:
            Original bytes: [color=red]FF 76 D0 FF 76 D4[/color] 9A [color=red]77 15[/color] 05 1B 83 C4 [color=red]04 A8 01 74 03 E9 29 00 B8 0C 00 F7 6E CE 8B D8 B8 00 06 F7[/color] 
             Patched bytes: [color=blue][b]E9 0E 00 90 90 90[/b][/color] 9A [color=blue][b]C1 17[/b][/color] 05 1B 83 C4 [color=blue][b]08 E9 91 0D B8 02 00 50 B0 0F 50 FF 76 D0 FF 76 D4 E9 E5 FF[/b][/color] 
            Offsets:
                EN47401: [b]0x4D8A[/b]
                EN47501: [b]0x4D8A[/b]
    
    For version [b]EN47405[/b]:
            Original bytes: [color=red]FF 76 D0 FF 76 D4[/color] 9A [color=red]85 15[/color] EA 1A 83 C4 [color=red]04 A8 01 74 03 E9 29 00 B8 0C 00 F7 6E CE 8B D8 B8 00 06 F7[/color] 
             Patched bytes: [color=blue][b]E9 0E 00 90 90 90[/b][/color] 9A [color=blue][b]CF 17[/b][/color] EA 1A 83 C4 [color=blue][b]08 E9 B2 0D B8 02 00 50 B0 0F 50 FF 76 D0 FF 76 D4 E9 E5 FF[/b][/color] 
            Offsets:
                EN47405: [b]0x4DB7[/b]
    
    For version [b]EN47404[/b]:
            Original bytes: [color=red]FF 76 D0 FF 76 D4[/color] 9A [color=red]81 15[/color] 69 1A 83 C4 [color=red]04 A8 01 75 1F B8 0C 00 F7 6E CE 8B D8 B8 00 06 F7 6E 06 8B[/color] 
             Patched bytes: [color=blue][b]E9 0E 00 90 90 90[/b][/color] 9A [color=blue][b]CB 17[/b][/color] 69 1A 83 C4 [color=blue][b]08 E9 D8 0B B8 02 00 50 B0 0F 50 FF 76 D0 FF 76 D4 E9 E5 FF[/b][/color] 
            Offsets:
                EN47404: [b]0x4C6C[/b]
    
    For version [b]FR47405[/b]:
            Original bytes: [color=red]FF 76 D0 FF 76 D4[/color] 9A [color=red]7D 15[/color] A3 1B 83 C4 [color=red]04 A8 01 74 03 E9 29 00 B8 0C 00 F7 6E CE 8B D8 B8 00 06 F7[/color] 
             Patched bytes: [color=blue][b]E9 0E 00 90 90 90[/b][/color] 9A [color=blue][b]C7 17[/b][/color] A3 1B 83 C4 [color=blue][b]08 E9 B2 0D B8 02 00 50 B0 0F 50 FF 76 D0 FF 76 D4 E9 E5 FF[/b][/color] 
            Offsets:
                FR47405: [b]0x4E9B[/b]
    
    For version [b]EN47403[/b]:
            Original bytes: [color=red]FF 76 D0 FF 76 D4[/color] 9A [color=red]8B 15[/color] 68 1A 83 C4 [color=red]04 A8 01 75 1F B8 0C 00 F7 6E CE 8B D8 B8 00 06 F7 6E 06 8B[/color] 
             Patched bytes: [color=blue][b]E9 0E 00 90 90 90[/b][/color] 9A [color=blue][b]D5 17[/b][/color] 68 1A 83 C4 [color=blue][b]08 E9 D8 0B B8 02 00 50 B0 0F 50 FF 76 D0 FF 76 D4 E9 E5 FF[/b][/color] 
            Offsets:
                EN47403: [b]0x4C6C[/b]
    
    
    By the way, in the middle of the patched bytes, find the sequence 50 B0 0F 50: you can change the 0F value to obtain another terrain type, as follows:
    • 01 = Ocean
    • 02 = Forest
    • 03 = Swamp
    • 06 = Plains
    • 07 = Tundra
    • 09 = River
    • 0A = Grasslands
    • 0B = Jungle
    • 0C = Hills
    • 0D = Mountains
    • 0E = Jungle
    • 0F = Arctic
     
  18. kirkham7

    kirkham7 Warlord

    Joined:
    Dec 22, 2012
    Messages:
    288
    Location:
    Hayward, CA
    So I just noticed, it seems your program doesn't work with the unpacked exe... All the patches say not compatible with your version of civ. Do you plan on making it possible to patch an exe that is unpacked?
     
  19. darkpanda

    darkpanda Dark Prince

    Joined:
    Oct 28, 2007
    Messages:
    600
    No, I don't plan to... But you patch the packed one and then unpack it, it should work.
    The main reason is that there is no "official" unpacked version of CIV for which I could guarantee compatibility...
     
  20. kirkham7

    kirkham7 Warlord

    Joined:
    Dec 22, 2012
    Messages:
    288
    Location:
    Hayward, CA
    Yeah alright. Is there a way to repack the exe? I have made several changes on the unpacked version...
     

Share This Page