Author Topic: Ai Research  (Read 2084 times)

Offline Eddy-B

  • Hero Member
  • *****
  • Posts: 1186
    • http://www.eddy-b.com
Ai Research
« on: November 26, 2005, 06:12:44 PM »
I did add Reseach(...) to my IUnit, but had never tested it.
When i did test it, it caused an exception..

So, i looked into it:
----
OP2 does not take the techID# as a param for the research-cmdPacket, instead it wants an array entry within it's tech array. I'll explain:

When the mission loads, after reading the techfile, op2 sorts the entire file, and stores all those techs into an array located at 015208C0.  I've already added the proper address to my "DataStructure Technology.txt". When sending a cmdPacket of type ctMoResearch, it takes 3 params in its Data property:
Code: [Select]
struct ResearchData
{
    unsigned short labID;
    unsigned short techEntry;
    unsigned short numScientists;
};
The techEntry is NOT the techID what you'd expect, but the array item number (=item offset). The list is sorted according to techID, so if you'd create a techfile with these entries (and in this order):
Quote
BEGIN_TECH "Cybernetic Teleoperation" 03401
...
BEGIN_TECH "Emergency Response Systems" 03301
...
BEGIN_TECH "Focused Microwave Projection" 03408
...
It will get sorted like this:
Code: [Select]
entry content-tech
0x00  03301
0x01  03401
0x02  03408
Note that the order is different: the lowest techID is first!
Now, to have Cybernetic Teleoperation researched, you'd use 0x01 for the techEntry property of the ResearchData struct.
Since ANY person can modify the techfiles, it is pretty useless using those numbers, because if one tech is removed or added, it might not be correct anymore...

So, i was looking for a function that "translates" the techID into a techEntry as i've dubbed it. And i found one at memory location OUTPOST2: 00472D90
It does something that shocked me: a Quicksearch - this would certainly prove that sections of code are written by different people. Compare this with what i found out about the victory/failure checking (in this same forum).


Anyway: i've updated my IUnit class, v1.2 to include this new Research function. Coders can now send a techID (as declared in EnumTechID.h) to the IUnit::Research member function.  As a side-note: when starting a research in your InitProc, it won't work, because at that point the labs are still offline. They'll be put online during the first game-cycle (4 game ticks, i believe).

1 minor change to the IUnit.h
IUnit::Research now takes an int as techID, instead of a short
Rule #1:  Eddy is always right
Rule #2: If you think he's wrong, see rule #1
--------------------

Outpost : Renegades - Eddy-B.com - Electronics Pit[/siz

Offline Leviathan

  • Hero Member
  • *****
  • Posts: 4055
Ai Research
« Reply #1 on: November 26, 2005, 06:22:05 PM »
Good work there Eddy.

Offline Hooman

  • Administrator
  • Hero Member
  • *****
  • Posts: 4955
Ai Research
« Reply #2 on: November 26, 2005, 08:29:06 PM »
Heh, I used that function in the researching AI test I posted a while back. And yeah, it was a nice surprise to see it use a binary search on the data. Btw, it uses a hidden "this" pointer of 0x0056C230 for that function.

Oh, and did you get all the fields for the tech structure? I have them all filled in except for offsets 0x48 and 0x4C. There might also be some missing info for some of the pointed to structures, but I can't remember where I wrote the info down.


I think maybe we should compare notes again. Do you add comments to the assembly in OllyDbg? I can send you my OllyDbg file. I don't suppose there is any way to merge them?


And yeah, most of the internal research functions and structures seem to use indexes rather than IDs.
 

Offline Eddy-B

  • Hero Member
  • *****
  • Posts: 1186
    • http://www.eddy-b.com
Ai Research
« Reply #3 on: November 27, 2005, 05:02:29 AM »
I did work out the "thisPointer", although it seems to be a pointer to the techs array:
Code: [Select]
pos size  desc
00   04   size of array (number of elements)
04   04   pointer to the array
« Last Edit: November 29, 2005, 02:52:15 PM by Eddy-B »
Rule #1:  Eddy is always right
Rule #2: If you think he's wrong, see rule #1
--------------------

Outpost : Renegades - Eddy-B.com - Electronics Pit[/siz

Offline Hooman

  • Administrator
  • Hero Member
  • *****
  • Posts: 4955
Ai Research
« Reply #4 on: November 27, 2005, 09:42:11 PM »
Not directly. It points to some sort of research object. (I've just referred to it as "Research" in my comments and label). That object is used by a number of routines for research functions. The first few fields in the object are the number of techs loaded from the file, and pointer to the array holding all the data. There might also have been a max tech ID in there somewhere. Anyways, I found a bunch of member functions for it, including the constructor.

Edit: Why is it that I didn't seem to notice that code part. Oh well, doubly verified results.
 
« Last Edit: November 27, 2005, 09:46:10 PM by Hooman »

Offline Eddy-B

  • Hero Member
  • *****
  • Posts: 1186
    • http://www.eddy-b.com
Ai Research
« Reply #5 on: November 29, 2005, 02:47:54 PM »
i found it - just coz i deeded it.. lol
i was testing the DoResearch (cmdPacket), and it turned out this "serial" number was the param, instead of the tech# - so i needed the routine to transform the one into the other. So i checked the one function that also needs this: MarkResearchComplete  .. and voila!  a step-by-step debug brought me there, where i wanted to be.

Anyway: the routine wants a tech number (on the stack), and returns the "serial" number in EAX
 
Rule #1:  Eddy is always right
Rule #2: If you think he's wrong, see rule #1
--------------------

Outpost : Renegades - Eddy-B.com - Electronics Pit[/siz