Jump to content

UPK Utils


wghost81

Recommended Posts

  • 2 weeks later...
  • Replies 235
  • Created
  • Last Reply

Top Posters In This Topic

Hey I think I've just found a bug. I'm using PatcherGUI 7.1

 

It looks like putting a "//" inside a %t text literal causes strange things to happen.

 

e.g.:

 1f <%t "<img src='img://LongWar.ClassIcons.sniper' height='16' width='16'>: ">

This code:

 

0f 35 <UISoldierListBase.UISoldierOption.strName> <@UISoldierOption> 00 00 10 2c 00 01 <@m_arrUIOptions>  //m_arrUIOptions[0].strName = 
70


70 // concat 
35 <UISoldierListBase.UISoldierOption.strName> <@UISoldierOption> 00 00 10 2c 00 01 <@m_arrUIOptions>


  70 // concat
1f <%t " <font color='#ffd800' size='14'>"> // sniper color
70
 1f <%t "<img src='img://LongWar.ClassIcons.sniper' height='16' width='16'>: ">
 /*
 70
1A 24 <%b 11> 12 20 <Class.XGLocalizedData> [@] <XGLocalizedData.SoldierClassNames> 00 ( 02 <XGLocalizedData.SoldierClassNames> )
1f <%t ": ">
 16
 */


 38 53 00 <.numAvailableSoldiers> // string(numAvailableSoldiers)
16
16
16
1f <%t "</font>">
16

After patching, UE Explorer decodes as follows, which is a bit of a mess:

   m_arrUIOptions[0].strName = (m_arrUIOptions[0].strName $ (" <font color='#ffd800' size='14'>" $ ("<img src='img:\\n\\t\\t  \\n\\n\\t\\t  38 53 00 <.numAvailableSoldiers> \\n\\t\\t16\\n\\t16\\n16\\n1f <%t \\"</font>" $ )))) $ numAvailableSoldiers = numAvailableSoldiers + ((m_arrUIOptions[I].iClass == 21) ? 1 : 0);

I'm working around this for now by using hex bytes for the img:// bit

Link to comment
Share on other sites

Yes, // is most probably treated as a comment, so the end of the line is removed and all the code up to the next text token ends up treated as a text.

 

I tried to do without escape characters, but it's getting increasingly hard as mods are getting increasingly complex. :) I'll think of something, so stay tuned. ;)

Link to comment
Share on other sites

Yes, // is most probably treated as a comment, so the end of the line is removed and all the code up to the next text token ends up treated as a text.

 

I tried to do without escape characters, but it's getting increasingly hard as mods are getting increasingly complex. :smile: I'll think of something, so stay tuned. :wink:

 

Hey I'm sure you'll figure it out. Anyway, thanks for making such an awesome tool. The HexToPseudoCode utility and the support for labels so that jump offsets are calculated automatically is just fantastic. I had a lot of trouble handling jumps with the first few mods I did and it's soooo much easier and quicker to develop complex mods now.

Link to comment
Share on other sites

Well, it looks like it was figured out long before me. :smile: I was thinking and I can't think of anything better than good old escape characters to guard special symbols. It'll make some of the older mods incompatible, but it should eliminate all the problems. I believe guarding inner " characters with backslash symbol will be enough. And of course, the backslash itself should also be guarded: "\"" and "\\".

Edited by wghost81
Link to comment
Share on other sites

  • 1 month later...

@WGhost81: Quick bug report with upkutils73-1.7. It fails to patch a program containing the replacement pseudocode <%t "//">. It works fine if I replace it with the hex string 2F 2F 00. The error context is:

 

Bad token: <%t "
[#label_0x07B8]
A3 00 <.I> 16
06 [@label_0x06A9]
[#label_0x07C6]
1B <AS_UpdateBlips> 00 <.Data> 16
04 0B
53

Link to comment
Share on other sites

So as someone who has never used this before and has limited HEX editing experience, how exactly do I use UPKUtils?

 

I want to find and change the time it takes to do genetic modifications and build interceptors (not firestorm, thats in default core) but reading the readme and the wiki entries just left me really confused...

 

Ideally I want to create a text file like other mods do and then apply it using patchgui

Link to comment
Share on other sites

UPKUtils is a collection of utilities for modifying .upk files, and are what PatcherGUI uses under the covers to actually apply the changes in the modfile to your .upk file. Creating the text file is the tricky bit. :)

 

The approach I usually take is to poke around in UE Explorer searching for likely strings in XComGame.upk or XComStrategyGame.upk (depending on whether it's a tactical or strategic layer thing I want to change) to try to find the function(s) that do the thing I want to change. One I find the function of interest I need to figure out if I can modify it to do what I want - can I picture writing the code to actually make the changes I need. Then, use HexToPseudoCode (one of the UPKutils utilities) to dump a template patch file for that function. You give it the function you want to modify and the .upk file it lives in and it dumps out a modfile that would replace that function with an exact copy of itself. It's great as a starting point. Then, make changes to that modfile by writing in the new hex by hand. This requires a pretty detailed knowledge of the unrealscript bytecode format, which you can get from the wiki articles. Apply the modfile and test it out in game. Then go back and scratch your head when (not if) it doesn't work and try figure out what you did wrong. Repeat until it works or you give up :)

 

That probably sounds awfully scary, but some mods are much simpler than others. E.g. just changing some values like timing constants should be *much* simpler than trying to write all new logic into a function. The process is the same: find the function that does it, dump out the template, then find the appropriate constant in the resulting modfile and change it to the value you want. Then apply with patcherGUI and see if it worked.

 

Good luck!

Link to comment
Share on other sites

tracktwo, thanks. I still haven't got around to implement escape characters for strings, that's why this one isn't working. Text after // is considered a comment and the rest of the line gets ignored. Strings in patcher are very simple entities, so while I'm working on a new version with escape characters using hex equivalent is a best solution for this type of bugs.

Link to comment
Share on other sites

wghost81, ah makes sense. I didn't even notice that was the same as a start of a comment. I'm used to languages where string literals are resolved before comments, so it wouldn't be considered a comment in that context (e.g. like in c/c++). It only came up because it exists in the .upk and HexToPseudoCode created the string literal that patchupk can't read. Took me a little while to figure out what was going on. :smile:

Edited by tracktwo
Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.

×
×
  • Create New...