Overriding Fake Console [Solved]

In this forum you will find and post information regarding the modding of Star Wars Battlefront 2. DO NOT POST MOD IDEAS/REQUESTS.

Moderator: Moderators

Post Reply
LRKfm946
Master Sergeant
Master Sergeant
Posts: 163
Joined: Sun Feb 02, 2014 6:13 pm
Projects :: Battlefront II Hunger Games
Games I'm Playing :: SWBF2 BF3
Contact:

Overriding Fake Console [Solved]

Post by LRKfm946 »

Hello everyone,

In my first Hunger Games map, I was able to prevent cheating by modifying the freecam function like so:

Code: Select all

    --save real Freecam function
    RealFreeCamFn = ScriptCB_Freecamera

    --overwrite Freecam to prevent cheaters from using it to find other people
    --REDEFINE FREE CAM FUNCTION (Thanks Zerted)
    ScriptCB_Freecamera = function(...)
      print("\nSOMEONE'S CHEATING!!!")
      print("\tKilling the player.")
      ScriptCB_PlayerSuicide(0)

      return RealFreeCamFn(unpack(arg))
    end
I'd like to do the same for executing a fake console command, but I can't find a working function that I can overwrite like I did with ScriptCB_Freecamera.
Does anyone know of a function I can use to accomplish this?
User avatar
AnthonyBF2
Sith
Sith
Posts: 1255
Joined: Wed Aug 21, 2013 3:55 pm
Projects :: PS2+PSP Overhaul

Re: Overriding Fake Console

Post by AnthonyBF2 »

You can do two things:

1) You can remove fake console completely by adding ifs_pausemenu.lua to the script in your mission.req and it will use a default pause menu with no freecam or fake console buttons.

2) If you want fake console to exist but clean out the buttons you can find fakeconsole_functions.lua somewhere on Gametoast, clean out the contents that builds buttons then put it in data_mod/common/scripts then add fakeconsole_functions to the script section of your mission.req and your mod will use that one instead of the regular script - just like pause menu trick.
LRKfm946
Master Sergeant
Master Sergeant
Posts: 163
Joined: Sun Feb 02, 2014 6:13 pm
Projects :: Battlefront II Hunger Games
Games I'm Playing :: SWBF2 BF3
Contact:

Re: Overriding Fake Console

Post by LRKfm946 »

Are those the only options? I want it to be usable up to a certain point during the match (the functions will get overwritten in a call to OnTimerExpire).
User avatar
[RDH]Zerted
Gametoast Staff
Gametoast Staff
Posts: 2982
Joined: Sun Feb 26, 2006 7:36 am
Projects :: Bos Wars AI - a RTS game
Games I'm Playing :: SWBF2 and Bos Wars
xbox live or psn: No gamertag set
Location: USA
Contact:

Re: Overriding Fake Console

Post by [RDH]Zerted »

The function call you want to intercept is to ff_AddCommand(<show>, <description>, <command>, <now>). The <now> parameter is a function which when called, returns true if that command should be displayed in the Fake Console list. Simply intercept that argument and replace it with your own function that always returns false until you want the commands displayed. Despite the documentation saying ff_AddCommand doesn't return anything, make sure your function returns whatever the call to the real ff_AddCommand returns. It's always possible some other mod also intercepted calls to ff_AddCommand and that mod could be relying on a new return value. This super easy to implement advice could save someone a ton of time debugging.

Here's the original implementation of ff_AddCommand for reference. It's defined in fakeconsole_functions.lua (added by v1.3).
Hidden/Spoiler:
[code]--
---- Description ----
-- Adds a command to the FakeConsole table
-- Note: You cannot just call this function anytime to add a command, it must
-- be called while the list is being populated for display
--
---- Parameters ----
-- show - String to display in the command list
-- description - A description of the command. Will be generated off of 'show' if value is nil
-- command - Function to run when this command is clicked
-- now - Function which describes if this command should be added to the list. Returns a true value if should be added to the list
--
---- Returns ----
-- (nothing)
--
function ff_AddCommand( show, description, command, now )
--check input
if show == nil then
print("fakeconsole_functions: AddCommand: Show is nil")
return
elseif description == nil then
--removes all spaces from the show string and prevent 'empty' names
local name = string.gsub(show, " ", "")
if name == "" then
name = "blank"
end

description = "mods.fakeconsole.description." .. name
end

--check to see if command is valid at this current time
if now ~= nil then
if not now() then
print("fakeconsole_functions: AddCommand: Not adding command: ", show)
return --don't add this command to the list
end
end

--add the given command into FakeConsole's table of commands
table.insert( gConsoleCmdList, {ShowStr=show, info=description, run=command,} )
end[/code]
If you can accomplish something without replacing a file then I suggest doing it without replacing the file. That way any future mods that come along will still be compatible with your mod.
LRKfm946
Master Sergeant
Master Sergeant
Posts: 163
Joined: Sun Feb 02, 2014 6:13 pm
Projects :: Battlefront II Hunger Games
Games I'm Playing :: SWBF2 BF3
Contact:

Re: Overriding Fake Console

Post by LRKfm946 »

This worked:

Code: Select all

    --save real Fake Console function
    RealFakeConFn = ff_AddCommand

    ff_AddCommand = function(show, description, command, now)
        now = FakeConsoleAllowed
        print("Used fake console. Add command?  ", now())
        return RealFakeConFn(show, description, command, now)
    end
You're a savior, as always Zerted! Thanks!
Post Reply