Page 1 of 1

Trying to rebuild 1.3 fake console assets

Posted: Mon Oct 19, 2015 3:10 am
by AnthonyBF2
After noticing something, I had a new idea; the ability to add fake console assets as part of new mods, without actually having the original assets (as they have been lost) or using the compiled .lvl files included from the official patch release.

First I was messing around with the .lvl file extractor, I don't remember who made this tool because I downloaded it a very long time ago and I always throw away readme files.

I ran the .lvl extractor on the 3 files replaced by the 1.3 patch; ingame.lvl, shell.lvl and common.lvl
So now I have a .lub file that's the name of each script file from the 1.3 files, example; fakeconsole_functions.lub, utility_functions2.lub, etc.

Note: Will be ignoring texture files in this post as scripts is the important part of making fake console what it is.

Then I noticed:

The extracted .lub files are the exact same as the premunged files that get created after a first time munge, located in:
C:\BF2_ModTools\data_MOD\_BUILD\Common\MUNGED\PC

Example; ifs_fakeconsole.lub(an extracted file) is the same as ifs_fakeconsole.script located in the premunged folder after a first time munge.
The only difference being the file extension name.

So then I took all of the .lub extraction files, and renamed them in the .script extension, then copy/pasted and replaced them over the matching files in C:\BF2_ModTools\data_MOD\_BUILD\Common\MUNGED\PC

At this point I'm thinking that I am going to fool the munger into thinking the extractions from the official patch files are the premunge files that it made from first time munge. The next thought is that the second time munge will add the 1.3 patch items along with the standard Battlefront 2 assets as it makes new .lvl files - therefor giving us 1.3 fake console patch additions. My personal goal with this is to get Fake Console menu on the PS2 version of swbf2.

Anyway, when I do the second munge, I get some weird error about fakeconsole_functions.script located in
C:\BF2_ModTools\data_MOD\_BUILD\Common\MUNGED\PC is not a valid UCF Binary file
And it's not just this file.
If I remove that one specific file, it presents the same error on other files. It only presents the error on files that were replaced by 1.3 patch extractions.

I'll see if I can fix this and post more progress but any help/thoughts would be super great! :runaway:

Edit: Yes, I added the 1.3 patch-specific items to the .req files for shell, common and ingame so I know they're getting called in.

Re: Trying to rebuild 1.3 fake console assets

Posted: Thu Oct 22, 2015 2:56 am
by [RDH]Zerted
There should only be minor changes to ifs_fakeconsole.lua to get the v1.3 Fake Console working.
1) You need to prevent the 'console' button from being hidden in ifs_pausemenu.lua.
2) Call ff_rebuildFakeConsoleList() in ifs_fakeconsole.Enter() instead of ScriptCB_GetConsoleCmds(). I think there were other changes to Enter() but the single function replacement is basically it.
3) Load utility_functions2.lua from game_interface.lua so the FC commands can get access to a bunch of helper functions they use and track which units are loaded on the map (so their class properties can change).
4) Find the .lub that contains the Popup_Prompt and get that included (loaded from game_interface.lua?). This is probably the second hardest step and is required if you want to use any of the FC commands that ask the user for a value.
5) Mess around with ifs_fakeconsole's layout to get it working well enough on all screen resolutions (maybe not an issue on the PS2). This was one of the most annoying tasks of making v1.3.

I do have the source code to these file:
fakeconsole_functions.lua
utility_functions2.lua
ifs_era_handler.lua

I've seen UCF errors before but it's been years... Compare that .script file with other partially munged .script files.

Re: Trying to rebuild 1.3 fake console assets

Posted: Thu Oct 22, 2015 6:58 pm
by AnthonyBF2
Thanks for the reply, I do have those source files as well.

No, I am not deeply concerned about popup_prompt.

Apart from PS2 game I would like to get those bits implemented for misc. mods for the PC version.

And last thanks for the better instructions, I've still been trying to fool visualmunge into munging .lvl extractions. :mrgreen:

EDIT
Ok I've gotten fake console to be unhidden in ifs_pausemenu but I'm stuck at what to do in ifs_fakeconsole.
I really don't understand coding, and I can't make sense of what I am supposed to with ff_rebuildFakeConsoleList().

Here is default ifs_fakeconsole script, with colored part what I have been messing with, anything I do just blanks out fake console list(normally one thing for qos) and makes going back fail, having to alt-f4 out of the game.
Hidden/Spoiler:
--
-- Copyright (c) 2005 Pandemic Studios, LLC. All rights reserved.
--

-- Multiplayer game name screen.

-- Helper function. Given a layout (x,y,width, height), returns a
-- fully-built item.
function Fakeconsole_Listbox_CreateItem(layout)

local insidewidth = layout.width - 20;
-- Make a coordinate system pegged to the top-left of where the cursor would go.
local Temp = NewIFContainer {
x = layout.x - 0.5 * insidewidth, y=layout.y + 2,
bInertPos = 1,
}
local FontHeight = fakeconsole_listbox_layout.fontheight
Temp.showstr = NewIFText{
x = 10, y = FontHeight * -0.5, textw = insidewidth, texth = layout.height,
halign = "left", valign = "vcenter",
font = fakeconsole_listbox_layout.font,
ColorR= 255, ColorG = 255, ColorB = 255,
style = "normal",
nocreatebackground=1,
inert_all = 1,
}

return Temp
end

-- Helper function. For a destination item (previously created w/
-- CreateItem), fills it in with data, which may be nil (==blank it)
function Fakeconsole_Listbox_PopulateItem(Dest, Data, bSelected, iColorR, iColorG, iColorB, fAlpha)
if(Data) then
-- Contents to show. Do so.
if(gBlankListbox) then
IFText_fnSetString(Dest.showstr,"") -- reduce glyphcache usage
else
IFText_fnSetString(Dest.showstr,Data.ShowStr)
end

IFObj_fnSetColor(Dest.showstr, iColorR, iColorG, iColorB)
IFObj_fnSetAlpha(Dest.showstr, fAlpha)
end

IFObj_fnSetVis(Dest,Data) -- Show if there are contents
end

fakeconsole_listbox_layout = {
-- Height is calculated from yHeight, Spacing, showcount.
yHeight = 22,
ySpacing = 0,
showcount = 9,
font = gListboxItemFont,

width = 320,
x = 0,
slider = 1,
CreateFn = Fakeconsole_Listbox_CreateItem,
PopulateFn = Fakeconsole_Listbox_PopulateItem,
}

gConsoleCmdList = {}

ifs_fakeconsole = NewIFShellScreen {
nologo = 1,

Enter = function(this, bFwd)


-- MUST do this after AddIFScreen! This is done here, and not in
-- Enter to make the memory footprint more consistent.
fakeconsole_listbox_layout.FirstShownIdx = 1
fakeconsole_listbox_layout.SelectedIdx = 1
fakeconsole_listbox_layout.CursorIdx = 1
ScriptCB_GetConsoleCmds() -- puts contents in gConsoleCmdList


ListManager_fnFillContents(ifs_fakeconsole.listbox,gConsoleCmdList,fakeconsole_listbox_layout)
end,

Exit = function(this, bFwd)
gBlankListbox = 1
ListManager_fnFillContents(ifs_fakeconsole.listbox,gConsoleCmdList,fakeconsole_listbox_layout)
gBlankListbox = nil
end,

-- Accept button bumps the page
Input_Accept = function(this)
if(gMouseListBoxSlider) then
ListManager_fnScrollbarClick(gMouseListBoxSlider)
return
end
if(gMouseListBox) then
ScriptCB_SndPlaySound("shell_select_change")
gMouseListBox.Layout.SelectedIdx = gMouseListBox.Layout.CursorIdx
ListManager_fnFillContents(gMouseListBox,gMouseListBox.Contents,gMouseListBox.Layout)
-- return
end

if(this.CurButton == "_back") then -- Make PC work better - NM 8/5/04
this:Input_Back()
return
end

local Selection = gConsoleCmdList[fakeconsole_listbox_layout.SelectedIdx]
ScriptCB_SndPlaySound("shell_menu_enter");
ScriptCB_DoConsoleCmd(Selection.ShowStr)
ScriptCB_PopScreen()
end,

--Back button quits this screen
Input_Back = function(this)
ScriptCB_SndPlaySound("shell_menu_exit");
ScriptCB_PopScreen()
end,

Input_GeneralUp = function(this)
ListManager_fnNavUp(this.listbox,gConsoleCmdList,fakeconsole_listbox_layout)
end,
Input_GeneralDown = function(this)
ListManager_fnNavDown(this.listbox,gConsoleCmdList,fakeconsole_listbox_layout)
end,

Input_LTrigger = function(this)
ListManager_fnPageUp(this.listbox,gConsoleCmdList,fakeconsole_listbox_layout)
end,
Input_RTrigger = function(this)
ListManager_fnPageDown(this.listbox,gConsoleCmdList,fakeconsole_listbox_layout)
end,

-- No L/R functionality possible on this screen (gotta have stubs
-- here, or the base class will override)
Input_GeneralLeft = function(this)
end,
Input_GeneralRight = function(this)
end,
}

function ifs_fakeconsole_fnBuildScreen(this)
fakeconsole_listbox_layout.fontheight = ScriptCB_GetFontHeight(fakeconsole_listbox_layout.font)
fakeconsole_listbox_layout.yHeight = fakeconsole_listbox_layout.fontheight

this.listbox = NewButtonWindow {
ZPos = 200, x=0, y = 0,
ScreenRelativeX = 0.5, -- center
ScreenRelativeY = 0.48, -- middle of screen

width = fakeconsole_listbox_layout.width + 35,
height = fakeconsole_listbox_layout.showcount * (fakeconsole_listbox_layout.yHeight + fakeconsole_listbox_layout.ySpacing) + 30,
}
ListManager_fnInitList(this.listbox,fakeconsole_listbox_layout)
end

-- Set up listbox

ifs_fakeconsole_fnBuildScreen(ifs_fakeconsole)
ifs_fakeconsole_fnBuildScreen = nil

AddIFScreen(ifs_fakeconsole,"ifs_fakeconsole")
ifs_fakeconsole = DoPostDelete(ifs_fakeconsole)

Re: Trying to rebuild 1.3 fake console assets

Posted: Thu Oct 22, 2015 8:41 pm
by [RDH]Zerted
I was saying change:
ScriptCB_GetConsoleCmds() -- puts contents in gConsoleCmdList
to:
ff_rebuildFakeConsoleList()

You need to make sure fakeconsole_functions.lua and utility_functions2.lua have been loaded before you try to use them, so before ifs_fakeconsole.lua (loading them in game_interface.lua is a good place). I should have mentioned that. Adding script files to a .req isn't good enough. You still need a function call somewhere that loads those scripts. See all the ScriptCB_DoFile()s in game_interface.lua as an example.

Can you get the debug output from the PS2 version? It might be hard to get everything working without it.

Re: Trying to rebuild 1.3 fake console assets

Posted: Thu Oct 22, 2015 10:48 pm
by AnthonyBF2
I'm not modding the PS2 version at all for now, I am testing all of this on file replacements for the PC version. When I have the ability to load fake console into the default assets(meaning everything is done)all I have to do is a munge for PS2 type to get PS2 files, much easier and quicker.

I'll report back after I've tried the last bit you've instructed.



EDIT
I finally [RC Cola] got it!

Wow that was a goal I've been trying to do for some time. Thanks for all the help over the months! :mrgreen:

I'll edit this post later to explain everything I've done for future reference to help others.
For other people; if you want to add 1.3 fake console items to your own mods, your process to do is;
Hidden/Spoiler:
1) in Data_MOD\Common\Scripts edit ifs_pausemenu.lua and find this data and remove it, or comment it out, -- this will add the Fake Console button to your in-game pause menu.
this.buttons.console.hidden = gFinalBuild
if(ScriptCB_IsDedicated()) then
this.buttons.freecam.hidden = 1
-- this.buttons.lobby.hidden = 1 -- Disabled NM 7/22/04 - I think we need to show this
this.buttons.opts.hidden = 1
this.buttons.suicide.hidden = 1
elseif (ScriptCB_IsSplitscreen()) then
-- this.buttons.lobby.hidden = 1
this.buttons.exit.hidden = 1
end


2) In Data_MOD\Common\Scripts edit ifs_fakeconsole.lua and find the one line that looks like;
ScriptCB_GetConsoleCmds() -- puts contents in gConsoleCmdList
replace that with:
ff_rebuildFakeConsoleList()

3) In Data_MOD\Common edit ingame.req and add
"fakeconsole_functions"
"utility_functions2"

under "script"

4) In Data_MOD\Common\Scripts edit game_interface.lua and near the top where it says;
-- Load utility functions
Add below that line:
ScriptCB_DoFile("utility_functions2")
ScriptCB_DoFile("fakeconsole_functions")

Also I'm not sure if that's the only required location but add those 2 new DoFile lines under these bits:

if(gPlatformStr == "PC") then
ScriptCB_DoFile("ifelem_tabmanager")
ScriptCB_DoFile("ifutil_mouse")
ScriptCB_DoFile("ifelem_editbox")

and under here:

ScriptCB_DoFile("popup_yesno")
ScriptCB_DoFile("popup_yesno_large")
ScriptCB_DoFile("error_popup")
if(gPlatformStr == "PC") then
ScriptCB_DoFile("popup_loadsave2")
end

Lastly, make sure you actually have the scripts utility_functions2.lua and fakeconsole_functions.lua placed in:
Data_MOD\Common\Scripts
You can get those file's from Zerted's recovered fake console assets, I made an upload here but I'm sure there is more locations on this site that has them;
http://www.mediafire.com/download/k3ych ... Source.zip

Now you may add fake console items + your own custom scripts/commands to your own mods using a custom fake console. You can add them inside of fakeconsole_functions.lua and they will be there ingame.



EDIT2
I got a little carried away and forgot to mention that as of now everything is built and fake console now shows my custom and the old 1.3 commands but they can't be ran yet. Selecting a command just returns to main pause menu. :roll:

Re: Trying to rebuild 1.3 fake console assets

Posted: Thu Oct 22, 2015 10:51 pm
by [RDH]Zerted
anthonybf2 wrote:Now you may add fake console items + your own custom scripts/commands to your own mods using a custom fake console. You can add them inside of fakeconsole_functions.lua and they will be there ingame.
FYI: If you're only making PC mods, then you should only be using custom user scripts to add custom commands to all maps or just call the proper function from within your mission script for new commands specific to that map. The v1.3 docs include info on how to add custom FC commands properly. Munging a new Fake Consoles can lead to fragmentation and incompatible mods. The whole point of v1.3 was to reduce fragmentation by combining the shell, common, and FC mods. The 'proper' way is injecting changes from your scripts into v1.3 by wrapping function calls instead of rewriting v1.3 scripts.

What commands and what's the debug output?

Also, there's no need to double post. Edit your posts instead. Use code and hide tags too.

Re: Trying to rebuild 1.3 fake console assets

Posted: Sat Nov 14, 2015 9:42 am
by AnthonyBF2
My reason for doing this is to have the fake console abilities without having to use the 1.3 patch. Some users like to have their own copies of ingame.lvl, common.lvl and shell.lvl which are replaced by 1.3.


EDIT
Can I bump this?
It has been good progress to finally integrate fake console assets into the default game files/assets but one problem persists;

The fake console menu buttons are not actually clickable. I guess there needs to be more work done in ifs_fakeconsole.lua

What happens is that when I click a fake console command, any of them (even the blank lines) the game just returns to the main pause menu.
Even if I click outside of the fake console border (on empty screen space) it still returns back to main pause menu.

This happens in PC, PS2 and even in the PSP version of the game. Zerted, can we go over this when you see this again? Thanks.
Hidden/Spoiler:
Don't get me started on how I got fake console in the PSP version... :runaway:

Re: Trying to rebuild 1.3 fake console assets

Posted: Sat Nov 21, 2015 7:41 pm
by [RDH]Zerted
I knew there was something I was forgetting... I probably changed fake console's CreateItem and PopulateItem to hold a reference to their data's run function then called that function (using pcall to detect and control errors) when that item was clicked. That's the efficient way of doing it.

Or you can search through all the entries in gConsoleCmdList looking for the entry with a ShowStr that matches Selection.ShowStr. This is slower but you won't have to understand as much about how SWBF2 listBoxes work. You'd put this code in the InputAccept function right before ScriptCB_DoConsoleCmd. To get things to change pink or blue, check the result of the pcall and use IFObj_fnSetColor() on Selection (maybe?) similar to how the color is changed in PopulateItem.

ScriptCB_PopScreen() is what closes the screen, so remove that from InputAccept if you want to be able to select multiple commands and/or see the entry change colors (pink/blue). I forget if screens automatically close if you press Esc or if you have to add the code to do that.

Re: Trying to rebuild 1.3 fake console assets

Posted: Sun Nov 22, 2015 11:23 pm
by AnthonyBF2
I don't understand that but that may not matter since I got the old extracted scripts to insert into newly munged files(use your ifs_fakeconsole script already built), but that does lead me to another question:

Where, if any, and how many locations calls popup_prompt? Or does it just need to exist in the output .lvl file?

Re: Trying to rebuild 1.3 fake console assets

Posted: Mon Nov 23, 2015 8:56 pm
by [RDH]Zerted
anthonybf2 wrote:I don't understand that but that may not matter since I got the old extracted scripts to insert into newly munged files
That's something we could use a tutorial for. Basically InputAccept handles when the user clicks something in a list. That needed to be modified to run the custom function of the command being clicked on. Without that change, the game just tries to process the entry as a debug exe FC command. pcall is a Lua function that lets you run another function. If that function causes a crash, pcall 'catches' it and lets you handle the error instead of crashing the game.

popup_prompt is called by every FC command that asks the user for a value. I don't think it's used anywhere else. It was a completely new prompt so none of the official code uses it.

Re: Trying to rebuild 1.3 fake console assets

Posted: Mon Nov 23, 2015 9:03 pm
by AnthonyBF2
Well a tutorial for that inserting old file into new file isn't ready yet, It's partly guessing the right header to add in hex editor. I've done this to some psp missions and got them to work with a new file to prevent losing them with a new file.

I also tried this method with your ifs_fakeconsole script but then the entire fake console button inside of pause menu becomes unusable.
I don't know if this a bad edit on inserting the file or a function from the fake console/pause menu script.

I still need to take the time to insert popup_promp and maybe some other scripts into new files, again it relies on guessing the right header on hex editor. It usually looks something like this:

http://prntscr.com/9685sf

Certain bytes change in the header of just about every game script, so far I've just been randomly using headers from different scripts. I don't have a way of knowing what they really mean or what they do.