Jump to content

UPK Utils


wghost81

Recommended Posts

LeMagos, OK, I understood. Since iCapacity += value takes more space than ++iCapacity, you'll need to rewrite the function. Either in hex code or in pseudo-code. Because there are tons of if-else statements and those have jump offsets attached to them. And jump offsets will inevitably change as you're inserting the code inside. For starters try to just reconstruct the whole function as mod script with no changes at all. And then we can mod those changes in.

Link to comment
Share on other sites

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

Top Posters In This Topic

I'm currently working on hex2pseudocode decompiler to make scripting with pseudo-codes easier. I've almost finished the decompiler but I'm kinda stuck with indentations at this point. :( I always thought highly of Eliot and UEE, but now that I've implemented partial decompilation myself, I'm starting to adore both. :) All this code formatting drives me crazy. :)

 

This is an example of how the output looks like right now:

/*(0x0000/0x0000)*/ 1B <CheckForSecondWave> 16
/*(0x000A/0x000A)*/ 19 01 <@m_kHQ> 0A 00 <NullRef> 00 1B <InitNewGame> 16
/*(0x0029/0x0021)*/ 19 01 <@m_kGeoscape> 0A 00 <NullRef> 00 1B <InitNewGame> 16
/*(0x0048/0x0038)*/ 19 01 <@m_kWorld> 0A 00 <NullRef> 00 1B <StartGame> 16
/*(0x0067/0x004F)*/ 19 01 <@m_kAI> 0A 00 <NullRef> 00 1B <InitNewGame> 16
/*(0x0086/0x0066)*/ 19 19 2E <XComGame.XComOnlineProfileSettings> 19 12 20 <Engine.Engine> 0A 00 <Engine.Engine.GetEngine.ReturnValue> 00 1C <Engine.Engine.GetEngine> 16 0A 00 <Engine.Engine.GetProfileSettings.ReturnValue> 00 1B <GetProfileSettings> 16 09 00 <XComGame.XComOnlineProfileSettings.Data> 00 01 <XComGame.XComOnlineProfileSettings.Data> 0A 00 <NullRef> 00 1B <IncGamesPlayed> 16
/*(0x00EF/0x00AF)*/ 07 [@label_0x0106] 2D 01 <@m_bDebugStart>
/*(0x00FC/0x00B8)*/     1B <DebugStuff> 16
/*(0x0106/0x00C2)*/ [#label_0x0106]
/*(0x0106/0x00C2)*/ 07 [@label_0x0181] 82 81 2D 01 <@m_bControlledStart> 16 18 0D 00 81 2D 01 <@m_bDebugStart> 16 16
/*(0x0126/0x00DA)*/     61 00 1E <%f 0.1> 16
/*(0x012E/0x00E2)*/     19 1B <GEOSCAPE> 16 0D 00 <NullRef> 00 1B <PreloadSquadIntoSkyranger> 24 01 28 16
/*(0x0151/0x0101)*/     07 [@label_0x0169] 1B <AreDropshipSoldiersStillLoading> 16
/*(0x015E/0x010E)*/         61 00 1E <%f 0.1> 16
/*(0x0166/0x0116)*/         06 [@label_0x0151]
/*(0x0169/0x0119)*/     [#label_0x0169]
/*(0x0169/0x0119)*/     07 [@label_0x0181] 1C <Core.Object.IsAsyncLoadingWrapper> 16
/*(0x0176/0x0122)*/         61 00 1E <%f 0.1> 16
/*(0x017E/0x012A)*/         06 [@label_0x0169]
/*(0x0181/0x012D)*/ [#label_0x0181]
/*(0x0181/0x012D)*/ 07 [@label_0x01AF] 19 1B <PRES> 16 0A 00 <XComHQPresentationLayer.IsBusy.ReturnValue> 00 1B <IsBusy> 16
/*(0x01A4/0x014C)*/     61 00 1E <%f 0> 16
/*(0x01AC/0x0154)*/     06 [@label_0x0181]
/*(0x01AF/0x0157)*/ [#label_0x01AF]
/*(0x01AF/0x0157)*/ 19 2E <XComGame.XComOnlineEventMgr> 19 2E <Engine.GameEngine> 12 20 <Engine.Engine> 0A 00 <Engine.Engine.GetEngine.ReturnValue> 00 1C <Engine.Engine.GetEngine> 16 09 00 <Engine.GameEngine.OnlineEventManager> 00 01 <Engine.GameEngine.OnlineEventManager> 0A 00 <NullRef> 00 1B <ResetAchievementState> 16
/*(0x020B/0x0193)*/ 07 [@label_0x0225] 2D 01 <@m_bDebugStart>
/*(0x0218/0x019C)*/     1B <GoToHQ> 16
/*(0x0222/0x01A6)*/     06 [@label_0x02B2]
/*(0x0225/0x01A9)*/ [#label_0x0225]
/*(0x0225/0x01A9)*/ 07 [@label_0x0278] 2D 01 <@m_bControlledStart>
/*(0x0232/0x01B2)*/     0F 01 <@m_kSetupPhaseManager> 1C <Engine.Actor.Spawn> 20 <Class.XGSetupPhaseManager> 17 4A 4A 4A 4A 4A 4A 16
/*(0x0256/0x01CA)*/     19 01 <@m_kSetupPhaseManager> 0A 00 <NullRef> 00 1B <StartNewGame> 16
/*(0x0275/0x01E1)*/     06 [@label_0x02B2]
/*(0x0278/0x01E4)*/ [#label_0x0278]
/*(0x0278/0x01E4)*/ 07 [@label_0x0292] 2D 01 <@m_bTutorial>
/*(0x0285/0x01ED)*/     1B <GoToTutorial> 16
/*(0x028F/0x01F7)*/     06 [@label_0x02B2]
/*(0x0292/0x01FA)*/ [#label_0x0292]
/*(0x0292/0x01FA)*/ 19 1B <GEOSCAPE> 16 0A 00 <NullRef> 00 1B <TakeFirstMission> 16
/*(0x02B2/0x0216)*/ [#label_0x02B2]
/*(0x02B2/0x0216)*/ 08
/*(0x02B3/0x0217)*/ 0C <Begin> <%u 0> <None> <%u 65535>
/*(0x02CC/0x0230)*/ 53

It is directly usable by PatcherGUI/PatchUPK. Indentations are weird for if-else (last else with no if is not indented) and for default case, but after several attempts on making it look prettier I gave up and decided it wasn't worth it.

I don't know if I'm able to generate UEE-like decompiled human-readable code to add it as comments but if I have time, I'll try to do it.

I'm about to do some more tests and after that I'll release the decompiler for everyone to use.

Link to comment
Share on other sites

And another piece of good news: seems I finally found a relatively easy solution for auto-calculating skip offsets.

 

Example:

1B <Game> 16 [@] <XGStrategy.GetDifficulty.ReturnValue> 00 ( 1B <GetDifficulty> 16 )
[@] code with no label name defined signals patcher to look for ( ) pair, calculate mem_size = mem_pos_of_) - mem_pos_of_( and replace [@] code with 2 bytes of mem_size.

 

Stacked parentheses should also be resolved properly.

 

Laziness is indeed a driving force of progress. :smile: Manual calculations are boring and I got too lazy to continue doing these. :smile:

Edited by wghost81
Link to comment
Share on other sites

Wow... absolutely awesome news with your hex2pseudocode decompiler custom tool project!

 

The analysis (and editing steps) of any UPK files (( and more importantly, specific sections of it -- like scripts! )) will just go from cumbersome to swift and direct facts at the tip of our fingers.

You'll never cease to amaze me, wGhost. This community of modders (both young recruits and experienced geniuses) owes a great deal of respect and gratitude for all that work.

Thanks, in advance! :D

Link to comment
Share on other sites

I just tried out the hex2pseudocode decompiler. It's fantastic! I rewrote an entire function in less than a minute and it came out great on UEE explorer. I just need to fix the jump offsets and it'll be perfect. Thank you so much for your hardwork , wghost81!

 

 

*edit* While I can't write pseudocode I can read it just fine. Some copy and paste magic and I had the function I wanted, haha.

Edited by Kaldreth88
Link to comment
Share on other sites

I just tried out the hex2pseudocode decompiler. It's fantastic! I rewrote an entire function in less than a minute and it came out great on UEE explorer. I just need to fix the jump offsets and it'll be perfect. Thank you so much for your hardwork , wghost81!

 

 

*edit* While I can't write pseudocode I can read it just fine. Some copy and paste magic and I had the function I wanted, haha.

Thanks for the feedback. :)

 

You don't need to fix jump offsets with pseudo-code and that's the beauty of it. :smile: All the existing jumps are already marked with labels by decompiler, you just need to use labels in your new code instead of values.

Edited by wghost81
Link to comment
Share on other sites

SpazmoJones, unicode symbols are prohibited for I'm really bad with parsing user input. :) Only ASCII symbols are allowed. Use m_strCreditsPrefix variable instead. It's defined in XComStrategyGame.int and holds "spacebucks" symbol alone.

Link to comment
Share on other sites

SpazmoJones, unicode symbols are prohibited for I'm really bad with parsing user input. :smile: Only ASCII symbols are allowed. Use m_strCreditsPrefix variable instead. It's defined in XComStrategyGame.int and holds "spacebucks" symbol alone.

It's not Unicode - it's ASCII 167. It would be nice to be able to use it in comments and for <%t> literals etc. Not a big deal if you can't fix it though.

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.

×
×
  • Create New...