Jump to content

UPK Utils


wghost81

Recommended Posts

Thanks! I know the mods do similar things, the point is more to learn how this works than to achieve the steam changes. Also I don't think those work with LW :P

 

 

With the help of the docs, I got it to set the right virtual size. The game now crashes at mission start, not at launch :D That's progress! (i think my jump offsets are wrong, so the 'loop continue' jump is always hit, instead of conditionally)

 

One issue I had with pseudocode is that I can't seem to get struct type references to work. From the docs it seems like

35 // struct
    19 05 00 00 // field: iType
    1C 05 00 00 // struct: XGBase.TTerainTile
    00 01 // [end of struct ?]

should be replaceable with

35 // struct
    <XGBase.TTerainTile.iType> // field: iType
    <XGBase.TTerainTile> // struct: XGBase.TTerainTile
    00 01 // [end of struct ?]

but doing so causes the mod to fail to apply.

Link to comment
Share on other sites

  • Replies 235
  • Created
  • Last Reply

Top Posters In This Topic

  • 2 weeks later...

Hello !!!

 

I come here to find a solution to my problem (suggested by ellatan http://forums.nexusmods.com/index.php?/topic/1151348-modding-long-war/?p=19969544)

 

 

function int GetCapacity()
{
local int iCapacity;

iCapacity = m_iCapacity;
// End:0x43 Loop:False
if(BARRACKS().HasOTSUpgrade(1))
{
++ iCapacity;
}
// End:0x73 Loop:False
if(BARRACKS().HasOTSUpgrade(2))
{
++ iCapacity;
}
// End:0x8c Loop:False
if(m_bExtendSquadForHQAssault)
{
iCapacity = 6;
}
// End:0xa6 Loop:False
if(m_bReinforcementsForHQAssault)
{
iCapacity += 8;
}
// End:0x30b Loop:False
if(HANGAR().m_kSkyranger != none && (HANGAR().m_kSkyranger.m_kMission != none))
{
// End:0x243 Loop:False
if(ENGINEERING().IsFoundryTechResearched(37))
{
// End:0x189 Loop:False
if(HANGAR().m_kSkyranger.m_kMission.m_iMissionType == 8)
{
iCapacity += 2;
}
// End:0x1e6 Loop:False
if(HANGAR().m_kSkyranger.m_kMission.m_iMissionType == 13)
{
iCapacity += 2;
}
// End:0x243 Loop:False
if(HANGAR().m_kSkyranger.m_kMission.m_iMissionType == 10)
{
iCapacity += 4;
}
}
// End:0x29f Loop:False
if(HANGAR().m_kSkyranger.m_kMission.m_iMissionType == 5)
{
iCapacity = 4;
}
// End:0x30b Loop:False
if(HANGAR().m_kSkyranger.m_kMission.m_iMissionType != 7)
{
// End:0x30b Loop:False
if(iCapacity > 12)
{
iCapacity = 12;
}
}
}
}

 

 

 

I'd need to modify both "++ iCapacity" to "iCapacity += n"...

 

It appears it requires resizing functions instead of straight up editing hex values... an Idea how I could achieve it ???

Link to comment
Share on other sites

Is `n` a constant there? Or some variable that I don't recognize?

 

Basically I believe you'll have to do the following:

 

1. Define the logic change using mod script pseudocode (i.e. find the hex for the previous / next bits of code, replace any struct/type/var references with pseudocode references)

2. Correct all jump offsets in if statements in those functions to account for the shifted token positions. You can use the token view in ue explorer to find those - do the first step first, decompile the modified file (which will shift all your if statements in a weird way, but hold on), then take note of the token offsets of every 1. start of if 2. the first instruction *after* the if is closed, and correct the 'jump if not' at the beginning of the if statement to jump to the right token.

Link to comment
Share on other sites

Is `n` a constant there? Or some variable that I don't recognize?

n is a number: let say it is 2 for the example...

 

Basically I believe you'll have to do the following:

 

1. Define the logic change using mod script pseudocode (i.e. find the hex for the previous / next bits of code, replace any struct/type/var references with pseudocode references)

2. Correct all jump offsets in if statements in those functions to account for the shifted token positions. You can use the token view in ue explorer to find those - do the first step first, decompile the modified file (which will shift all your if statements in a weird way, but hold on), then take note of the token offsets of every 1. start of if 2. the first instruction *after* the if is closed, and correct the 'jump if not' at the beginning of the if statement to jump to the right token.

Actually, I am not such a good modder... my habits are tinkering, and learning by writing others' stuff... I understood maybe half the post...

Link to comment
Share on other sites

Okay, so there are two parts to it.

 

First, the 'simple' part is finding the hex code for the block that you want to modify, and figuring out how you need to change it so that the code does what you want instead. I don't have UE Explorer on this machine, but if you decompile that block and open the buffer for this function, you can mouseover different blocks to find the hex for the 'if(BARRACKS().HasOTSUpgrade(1)); ++iCapacity;' block.

 

To replace it with a `iCapacity = iCapacity + n` statement you'll have to figure out how to encode that statement in hex (it'll be a combination of let (0x0F <lhs> <rhs> IIRC), a reference to iCapacity for the lhs (local variable : 0x00 <.iCapacity> in pseudocode), and a plus operation for the right hand side (I don't remember the bytecode for +, but you should be able to find the bytecode for one of the `iCapacity += 2` blocks, and reuse that).

 

Once you have found both what you're replacing and know what you want to replace it with, use PatcherGUI to apply your changes to the file (see https://github.com/wghost/UPKUtils/blob/master/doc/PatchUPK_Readme.txt). If that succeeds, decompiling the file with UE Explorer should produce the code that you wanted to see.

 

However, you'll notice that all the if statements are shifted around and generally messed up. That's because an if statement in bytecode is really something like this:

 

0x07 (jump-if-false) <to-offset> <condition>

 

where to-offset is a reference to the memory offset in the function, as shown in the 'token view' in ue explorer. These locations have shifted, because your code has different size than previous ones, but all the jumps still point to the old offsets. To fix that, you'll have to correct all the to-offset so that they point to the right offsets; use UE token view to find the offset for the 'first instruction *after* the if' (so for example for the '

if(m_bExtendSquadForHQAssault)
{
iCapacity = 6;
}
' block, the 'next instruction' is the start of the next block:
if(m_bReinforcementsForHQAssault)
{
iCapacity += 8;
}).
I hope that helps. I don't think I can make this more explicit without basically writing this for you, so just try it and report back if you hit a block somewhere.
Link to comment
Share on other sites

I think I got something wrong...

 

I thought A5 00 B9 4B 00 00 means ++ icapacity and A1 00 B9 4B 00 00 2C 08 means iCapacity += 2

 

but if I replace original with mine: It wrecks everything and I can 't even find the function in UEE... :'(

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.

×
×
  • Create New...