March 28, 2024, 07:23:35 PM

Username
Password

Pages: 1 2 3 [4] 5   Go Down
Print
Author Topic: Further CTL investigation  (Read 42813 times)
0 Members and 1 Guest are viewing this topic.
olly
Global Spokesperson
*
Offline Offline

Posts: 2268



View Profile
« Reply #45 on: April 25, 2017, 08:54:47 PM »

Fantastic thanks

Smiley
Logged

and back in Nuln, the ageing Graf Berhardt smiled his secret smile of pride whenever he heard the latest tales of his eldest son's ever growing chain of glorious victories -(sothr manual)
Leilond
Ghoul
*
Offline Offline

Posts: 52


View Profile
« Reply #46 on: April 26, 2017, 08:37:39 AM »

AWESOME
Thanks everyone... I'll study it better
Logged
Leilond
Ghoul
*
Offline Offline

Posts: 52


View Profile
« Reply #47 on: April 26, 2017, 08:54:31 AM »

This new ctldis.py do not work for me
I tryed to decompile B102 and recived this

Code:
File "C:\Users\rcoletta\Desktop\ctldis\ctldis-master\ctldis-master\ctldis.py", line 531
    decompiledFunc.lines.append([opName, *newLine])
                                         ^
SyntaxError: invalid syntax
Logged
olly
Global Spokesperson
*
Offline Offline

Posts: 2268



View Profile
« Reply #48 on: April 26, 2017, 08:55:44 AM »

I had the same using Python 2.6 & 2.7 and Ghabry advised using Python 3 as it recognises the *newline

Works fine with Python 3.6.1

* CTL.jpg (484.22 KB. 2456x1034 - viewed 715 times.)

« Last Edit: April 26, 2017, 09:06:13 AM by olly » Logged

and back in Nuln, the ageing Graf Berhardt smiled his secret smile of pride whenever he heard the latest tales of his eldest son's ever growing chain of glorious victories -(sothr manual)
Leilond
Ghoul
*
Offline Offline

Posts: 52


View Profile
« Reply #49 on: April 26, 2017, 09:19:36 AM »

Perfect, thanks
Logged
Ghabry
Developer
*
Offline Offline

Posts: 1020



View Profile
« Reply #50 on: April 26, 2017, 11:28:03 AM »

The script is now python 2 compatible. Fixed two issues in it.

Leilond: In case you want to do some prettifying and you know Python take a look at line 326 where the prettifier-dict starts.

The mapping is basicly: opcodename -> [dissasembler, assembler] (so list of 2 elements)

Ignore the assembler for now, they are unused and stubs.

The API is basicly:
The dissasembler and assembler are functions that except as many arguments as the opcode arguments has (so for all prettifiers by now it's only one arg) and the return value is a list of strings with as many list elements as the opcode argument has. So quite simple API to extend.

And Prettifier.flag_prettifier(flag, Prettifier.unit_flag_1) is a helper function which takes an op-code argument as 1st argument and a lookup-dict (see Prettifier.unit_flag_1 for an example) and returns a String with all bits (if posible substituted) and delimited by "|".

Oh and the OpCodes are not up-to-date yet. I have to sync them with the latest observations of the latest days first.

More stuff I want to prettify which doesn't need BTB/ARM parsing so is faster to implement and to make the "data types" of CTL arguments more clear:

  • play (sound effects)
  • spells
  • unit types
  • btb node arguments (e.g. n1 instead of 1)
  • event arguments (e.g. e1 instead of 1, for events that are clear this could be also changed to e.g. E_Charge)
  • function arguments (e.g. f1 instead of 1)
  • control flag (though there is almost nothing known about it)
  • label resolving (should work because every enemy only has one label)
  • end_event 6844 and 3567
  • that @0xABC event marker
  • Nice to have: Annotate functions with the enemy that executes them (needs BTB & ARM parsing)

Maybe should also provide some constant for "registers", e.g. that "-278" register cuthalion uses in his code to read the unit id of a regiment Cheesy (awful hack I told him because the register functions don't do range checks. But you can only read 32bit values with this)

Shame that there is no function to write registers in registers. This way you could do arbitrary loads and abuse unit_flags for bit operations. Cheesy
« Last Edit: April 26, 2017, 11:54:18 AM by Ghabry » Logged

Leilond
Ghoul
*
Offline Offline

Posts: 52


View Profile
« Reply #51 on: April 26, 2017, 01:45:09 PM »

I don't know python language
I only understood that the translation hex=>opcode and back is done reading the "opNames" array and thus I undestood that simply adding a line like "0x5b:"unit_rout," in that array will make the code translation.

Thanks anyway
Logged
Leilond
Ghoul
*
Offline Offline

Posts: 52


View Profile
« Reply #52 on: April 26, 2017, 01:49:15 PM »

Thanks for your observations. About search and attack enemy did you see my post in this thread from 2 years ago? Based on my latest findings I'm updating the table:

Code:
                            distfunc unittype vision nth  dist uflag1 attribs op
find_enemy_uflag_attrib      0        0        0      1    100  arg2   arg3    a2
find_enemy_visible           0        0        1      1    100  0      0       a3
find_enemy_simple            1        0        0      1    100  0      0       a4
find_enemy_simple_visible    1        0        1      1    100  0      0       a5
find_enemy_unittype          0        arg2     0      1    100  0      0       a6
find_enemy_unittype_2        0        arg2     0      1    100  0      0       a7
find_enemy_nth               0        0        0      arg2 100  0      0       a8
find_enemy_nth_visible       0        0        1      arg2 100  0      0       a9
find_enemy_unittype_nth      0        arg2     0      arg3 100  0      0       aa
find_enemy_unittype_nth_2    0        arg2     0      arg3 100  0      0       ab
find_enemy_distance_uflag    4        0        0      1    arg2 arg3   0       ac

All of them generate arg1 as an event.

- distfunc: Looks like 0 is the direct (diagonal) distance, 1 just considers x or y (bounding box I guess), 4 is some smart thing that considers terrain e.g. (probably useful for archers).
- unittype: Unittype that the searched unit MUST have.
- vision: When 1 the vision of the caller is considered (worse when walking or fighting), except if you have 360° vision (spider) they always find everything
- nth: Not completly sure, my guess is the list of found regiments is sorted and then the n-th regiment is picked (where 1 = the closest)
- distance: Search distance used for the distfunc (not sure how big a 100 is)
- uflag1_xtra: Unit Flag 1 bits that searched unit most NOT have, inactive/retreating and similiar units are never found
- attribute: Attributes that the searched unit must NOT have, e.g. 4096 = engine of war
This is absolutely GREAT
This improve my chance of create smarter units A LOT

Going on studying the rest of the post
Logged
Ghabry
Developer
*
Offline Offline

Posts: 1020



View Profile
« Reply #53 on: April 27, 2017, 12:26:35 AM »

Added now all known OpCodes to ctldis and type annotated all OpCodes (still without assembler, I add the assembling during the next days). Feel free to make suggestions.

Annotation is still incomplete, more to come.

What is already in:

X() means the argument is unused
E() means the argument is an event
F() means the argument is a function

Example output:

on_event E(71)
   event_test_any_friend_collects_this_item
   iffalse
      event_test_distance_and_collect_this_item 240
      set_return_func_iftrue F(137)
   endif
   end_event Filter



.func 0
    init_unit X(128)
    clear_ctrl_flag 0x8000
    set_label 0xabc0
    #3c 240, X(0)
    set_event_handler F(14)
    set_callback 13, 29
    set_global_r_i 0, 0
    set_global_r_i 1, 0
    wait_for_deploy
    save_ip
    find_and_collect_item Treasure_Chest_100gc
    set_timer 25
    wait_for_timer
    play_self 64
    reset_call_stack
    save_ip
    do
        wait_unit_flag3_clear CollectingItem
        find_and_collect_item Treasure_Chest_100gc
        iffalse
            find_enemy_uflag_attrib E(4), 0, EngineOfWar
            iffalse
                test_unit_flag3 0x400
                iffalse
                    add_waypoint 99
                endif
            endif
        endif
        set_timer 10
        wait_for_timer
    always



on_event E(69)
   event_test_item Treasure_Chest_100gc
   iftrue
      test_event_from_enemy
      iffalse
         test_global_r_eq_i 1, 1
         iffalse
            play_self 66
            set_global_r_i 1, 1
         endif
      endif
      broadcast_event_to_friends E(17)
   endif
   event_test_unit_collects_this_item
   iftrue
      test_event_from_enemy
      iftrue
         test_can_fight_and_sender_does_not_retreat
         set_return_func_with_restart_iftrue F(127)
      else
         set_return_func F(134)
      endif
   endif
   end_event Filter


That "can fight and sender doesn't retreat" appears to make sense because 127 contains:


.func 127
    #14 4, E(-1)
    send_event_to_stored_unit E(20)
    wait_unit_flag1_clear 0x8 | 0x4000
    play_self 1
    #48
    #4f
    do
        for 2
            set_timer 10
            test_target_in_charge_range
            goto_iftrue F(129)
            wait_for_timer
            test_unit_flag1 0x10
            iftrue
                restore_ip
            endif
        next
        #49
    always

.func 129
    charge_and_send_event_to_target ; event 7
    iftrue
        play_self 2
        #14 19, E(-1)
        do
            sleep
            #b0 0
            test_unit_flag1 0x10
        whilenot ; I guess this loop tests if the charge is finished.
    endif
    goto F(134)
« Last Edit: April 27, 2017, 12:52:08 AM by Ghabry » Logged

olly
Global Spokesperson
*
Offline Offline

Posts: 2268



View Profile
« Reply #54 on: April 27, 2017, 08:19:47 AM »

Much more easy to use and follow

Smiley
Logged

and back in Nuln, the ageing Graf Berhardt smiled his secret smile of pride whenever he heard the latest tales of his eldest son's ever growing chain of glorious victories -(sothr manual)
Leilond
Ghoul
*
Offline Offline

Posts: 52


View Profile
« Reply #55 on: April 27, 2017, 08:38:42 AM »

Added now all known OpCodes to ctldis and type annotated all OpCodes (still without assembler, I add the assembling during the next days). Feel free to make suggestions.
...
Looking forward to use the new ctldis.py!!! It will make things a lot easyer!!!
Logged
Ghabry
Developer
*
Offline Offline

Posts: 1020



View Profile
« Reply #56 on: April 29, 2017, 03:02:25 AM »

Assembling works now.

Annotating should be mostly complete. There are still some empty dicts (e.g. "Voice" for all the audio stuff) or almost empty (e.g. events) dicts. Feel free to fill them and to post them here so I can add them to the script.

You find this at line 460+.

Ignore game_status and alignment, I fill them later.

Please also take a look at the new scripts and try to figure out what some Unit and Control Flags could be. I have notes about them but most of them are uncertain, so want to see others opinion before I add my flawed data.

Edit: Have to recheck arguments of type "ID. Some of them actually check the UnitID, not an incrementing number (enemy+ally). But thats just a visual issue, doesn't impact the functionality
« Last Edit: April 29, 2017, 03:13:43 AM by Ghabry » Logged

olly
Global Spokesperson
*
Offline Offline

Posts: 2268



View Profile
« Reply #57 on: April 29, 2017, 01:57:03 PM »

Awesome

Smiley
Logged

and back in Nuln, the ageing Graf Berhardt smiled his secret smile of pride whenever he heard the latest tales of his eldest son's ever growing chain of glorious victories -(sothr manual)
Ghabry
Developer
*
Offline Offline

Posts: 1020



View Profile
« Reply #58 on: April 30, 2017, 04:44:16 PM »

Updated ctldis again. Together with the latest version of the Mod selector (released today) you get the new opcode

set_deployment_limit n. Where n is obviously a number of how many units are allowed to be deployed.

Put it in .func 100 anywhere before "wait_for_deploy" obviously.
Logged

olly
Global Spokesperson
*
Offline Offline

Posts: 2268



View Profile
« Reply #59 on: April 30, 2017, 05:55:29 PM »

In the future it will be great to have predefined named scripts that fans can copy and paste such as archer unit retreat after number of hits like on mission 1.
Logged

and back in Nuln, the ageing Graf Berhardt smiled his secret smile of pride whenever he heard the latest tales of his eldest son's ever growing chain of glorious victories -(sothr manual)
Pages: 1 2 3 [4] 5   Go Up
Print
Jump to: