PDA

View Full Version : Unmatched functions between CoD



ebusiangamers
30th August 2020, 15:59
Hi, I am trying to port to libcod to CoDUO. I am in this situation where in CoD 2, the subroutine (marked as 1 in the screenshot) is a seperate function while it is a set of instructions (marked as 2) in CoDUO.

1639

Is there a way to "extract" the subroutine?

maxdamage99
1st September 2020, 07:02
There is not much code, you can describe it as your own function (translate pseudocode in C/C++)

You can analyze the function in which this section is located, it is possible to call the upper function with certain parameters, which guarantees that this piece of code is called and only it is called

Here is a translation example, simple and straightforward:
https://github.com/damage99/libcod/blob/master/gsc_player.cpp#L830


If you need to replace only a piece of code, but leave the main function unchanged, then the simplest options are to analyze the conditions and, if they match (this subroutine is called in the original) - replace it with a function call that you translated from pseudocode; if the conditions are different, just call the original function
*like this:
https://github.com/damage99/libcod/blob/master/libcod.cpp#L139
: only you need to analyze the input arguments of this function, when you understand that the required subroutine should be called, then call reworked_func(), if not, then call original_func()

ebusiangamers
2nd September 2020, 15:10
How about equivalent offset? Is there an efficient way to recover them?

maxdamage99
3rd September 2020, 06:28
How about equivalent offset? Is there an efficient way to recover them?


What do you mean? Will give an example of what you need :)

ebusiangamers
6th September 2020, 14:11
This whole thing

https://github.com/M-itch/libcod/blob/master/declarations.hpp#L2138

Mitch
6th September 2020, 16:20
How about equivalent offset? Is there an efficient way to recover them?

In CoD2, I look for a text close to a function that uses the player client address and then find the same text in other versions.
This might work depending on much difference between 2 and UO.

Edit: you might be able to find some of the addresses if you find and decode one of the player GSC functions like GetStance() or getEntityNumber and the kick function too.

ebusiangamers
19th September 2020, 14:09
In CoD2, I look for a text close to a function that uses the player client address and then find the same text in other versions.
This might work depending on much difference between 2 and UO.

Edit: you might be able to find some of the addresses if you find and decode one of the player GSC functions like GetStance() or getEntityNumber and the kick function too.

Using string work fine to find functions and offset. I search each crossref to find the bit of string that might exist in the other version. It's the huge pain in the arse when the string bit is hidden in several "parent" function away.

ebusiangamers
19th September 2020, 14:11
I come across many function with the same structure as the on on the right. The functions in the screenshot below are supposed to be "equivalent". I find a lot more like this (right). Is something wrong happening?
1640

Mitch
19th September 2020, 15:42
Using string work fine to find functions and offset. I search each crossref to find the bit of string that might exist in the other version. It's the huge pain in the arse when the string bit is hidden in several "parent" function away.

Which functions, addresses and offsets are you currently still looking for?

Edit: maybe comparing CoD1 with UO is easier.

https://github.com/riicchhaarrd/CoDExtended

Edit 2:


I come across many function with the same structure as the on on the right. The functions in the screenshot below are supposed to be "equivalent". I find a lot more like this (right). Is something wrong happening?
1640

CoD1 and UO are split into two: a binary (coduo_lnxded) and a library (game.mp.uo.i386.so).
The game library contains GSC script functions and methods.

I think the UO code in your screenshot loads the game library like in CoDExtended.

Loading the library
https://github.com/riicchhaarrd/CoDExtended/blob/stable/src/codextended.c#L257
https://github.com/riicchhaarrd/CoDExtended/blob/49e58c45645dc10811fc2bf5d64ad35dddb1db6c/src/librarymodule.c#L231

Loading the stock functions:
https://github.com/riicchhaarrd/CoDExtended/blob/stable/src/script.c#L1862
Return the stock or custom function:
https://github.com/riicchhaarrd/CoDExtended/blob/stable/src/script.c#L450