SWBFGamers

Modding for the Original SWBF1 and SWBF2 => SWBF1 Modding Tutorials => Topic started by: Dark_Phantom on October 27, 2018, 08:17:00 AM

Title: How to have 6+ units in your game
Post by: Dark_Phantom on October 27, 2018, 08:17:00 AM
Well I released a video a long time ago that it was possible, and now I'm going the tutorial route with it.  This does require modification of the .exe file, which may leave some of you wary, but all it does is change a hard-coded spawn screen limit from 5 to 6.  If you haven't seen it:
https://youtu.be/jopdQhFSHYY

The three things you have to do are this:
You need a common.lvl builder. (local link needed)
1.) Edit the ifs_pc_spawnselect.lua file and raise numslots accordingly.  If you want one extra unit (6) you raise it by one (to 5, lua generally starts at 1 but in this case starts at 0).  Replace the common.lvl in your game's folder.  Oh yeah and you probably want to do some scripting like above because your units will run off the screen.

2.) Edit/create a mission file for the level you want to use.  Mission.lvl builder here: http://www.swbfgamers.com/index.php?action=downloads;sa=view;down=319
--------->You're going to add a 6th AddUnitClass line to one or both of the teams.

3.)  Have a hex editor, I use PSPad (http://www.pspad.com/).  Find these offsets in the Battlefront.exe:  1A9985 and 1A94B2.  Change the 05 to 06 (or whatever, just remember that 0A in hex is 10, not 10) at both offsets.  If you do not wish to edit your .exe, you can do the same thing in Cheat Engine (Battlefront.exe+offset) and it will only adjust the value while the game is running.

It should work in your game now.  This is online and offline compatible as far as I know.

Notes that you need to read:
Title: Re: How to have 6+ units in your game
Post by: Giftheck on October 27, 2018, 09:11:29 AM
Nice work on this!

I wonder if the issue you found was in SWBF2 initially during development, and the 'SetClass' LUA options were added in to circumvent that.
Title: Re: How to have 6+ units in your game
Post by: Red04SWBF on October 27, 2018, 09:32:35 AM
Yeah! :D I never thought this was possible! :shrug:

By the way, should the 6th unit appear below the rest or next to them in spawn select screen?
Title: Re: How to have 6+ units in your game
Post by: Dark_Phantom on October 27, 2018, 09:37:06 AM
Psych0fred said at one point the spawn screen was done by a third party in Battlefront 1, but in 2 was done in-house.  The max number of units (12) is actually defined.  See here:

[spoiler]
Quote from: Psych0fredYes, theoretically, as long as the rest of the code wasn't dependent on the limit. In BF1 I think it was in SpawnParams.h. That's the file where the limits were set as I've pasted them from that file below. Keep in mind that spawn display screen has a memory restriction so if you load too many different models it wouldn't be able to hold them.



const int PLAYER_TEAMS = 2;   // max number of player teams

const int MAX_TEAMS = 8;       // 0 is neutral, 1 and 2 are player teams, the rest are nonplayer teams

const int MAX_CLASSES = 12;   // max number of classes per team

#ifdef PC

const int TEAM_SIZE = 200;      // allow padding for soldiers, vehicles, dead units (dulicated briefly during spawning)

const int MAX_UNITS = 450;

#else

const int TEAM_SIZE = 40;        // allow padding for soldiers, vehicles, dead units (dulicated briefly during spawning)

const int MAX_UNITS = 64;

#endif

const int MAX_DROIDS = 16;

const int MAX_ENEMIES = TEAM_SIZE;

const int MAX_FLY_UNITS = 20;
[/spoiler]

The rest of this gold mine is a discussion for another post, but you get an idea of what you're working with in regard to maximums.

@Red04 - depends on how you do the scripting.  By default yes.  My code in the video said something akin to "if numSlot = 5 then define new location" which is how you get the nicely laid out screen.  See here:
[spoiler]
Code (lua) Select
local i
for i = 0,numSlots do

local tag = format("SlotUnitName%d",i)

-- this.Info[tag] = NewIFText --the Unit's name/soldiertype/title
-- {
--- x = SlotTextOffsetX, --SlotUnitNameOffsetX , -- center-x position
--- y = SlotYOffset + i * ( boxh + textheight ), -- just touching box below (my height = 32, but is centered)
-- width = barw * 10,
---- font = fontsize,
-- halign = "left",
-- valign = "top",
-- -- textw = barw , -- usable area for text
-- texth = 32,  --boxh ,
-- font = fontsize,
-- string = "UnitTitle",
-- ColorR = 255, ColorG = 255, ColorB = 255, -- white
-- --flashy = 0,
-- rotY = 20,
-- bgleft = "headerbuttonleft",
-- bgmid = "headerbuttonmid",
-- bgright = "headerbuttonright",
--
-- textw = boxw, -- usable area for text
-- }


tag = format("SlotWindow%d",i)
--this.Info[tag] = NewBorderRect
--{
-- ZPos = 190, -- behind most
-- x = SlotUnitNameOffsetX +  65,
-- y = SlotYOffset + i * ( boxh + textheight ) + boxh,
-- width = boxw,
-- height = textheight + boxh,
-- alpha = 128,
--}

if (i<5) then       
this.Info[tag] = NewButtonWindow
{
ZPos = 200,
x=SlotUnitNameOffsetX +  SlotUnitNameOffsetX * 2.5,
y = SlotYOffset + i * ( boxh + textheight +  ScriptCB_GetFontHeight(fontsize)+10 ) + boxh ,
--ScreenRelativeX = 0.0, -- center
--ScreenRelativeY = 0.0,
width = boxw,
height = textheight + boxh,
      ----height=boxh,
titleText = "Debug Build",
rotY = leftsideRot,
font = fontsize
}     
else   
--go bonkers
     this.Info[tag] = NewButtonWindow
{
ZPos = 200,
x=SlotUnitNameOffsetX +  SlotUnitNameOffsetX * 9,
y = SlotYOffset + (i-6) * ( boxh + textheight +  ScriptCB_GetFontHeight(fontsize)+10 ) + boxh ,    ----changed from i-4(5) for fake buttons
--ScreenRelativeX = 0.0, -- center
--ScreenRelativeY = 0.0,
width = boxw,
height = textheight + boxh,
      ----height = boxh,
titleText = "ifs.profile.list",
rotY = -20,
font = fontsize
}
    end

this.Info[tag].bHotspot = 1
this.Info[tag].fHotspotW = boxw
this.Info[tag].fHotspotH = textheight + boxh

this.Info[tag].InfoText = NewIFText  --the equipment/weapon text
    { 
--x = 0, --SlotTextOffsetX ,
--y = 0, --SlotYOffset + i * ( boxh + textheight ) + ScriptCB_GetFontHeight(fontsize) + 30  ,


width = barw * 10,

halign = "hcenter",
valign = "vcenter",
textw = boxw, -- usable area for text
texth = textheight,
font = fontsize,
string = "InfoText",
ColorR = 255, ColorG = 255, ColorB = 255, -- white
--rotY = 20,
flashy = 0,
--x = -boxw,
--y = -textheight,
}

end
[/spoiler]
edit: fixed due to the fact I had 2 fake buttons in there - if anyone wants the fake button code for a player select situation I can post it.
Title: Re: How to have 6+ units in your game
Post by: Giftheck on November 03, 2018, 02:27:08 PM
I've said it before, but I'll say it again: great work on getting this stable! This might change the game for a lot of people's mods!

I wonder if it's possible to 'shrink down' the unit buttons. to all fit on one side if you want to have less than 10 units (IE like SWBF2's 9).

I'm also curious as to whether it's possible to activate the side-selector as it appears in both the console versions and in PC SWBF2 (where you get a menu before the first spawn screen asking whether you want to be on team 1, 2 or be auto-assigned). If we have to disable the spawn-screen side-selector to get this working, getting the pre-spawn side-selector might be a workaround.
Title: Re: How to have 6+ units in your game
Post by: RepComm on November 03, 2018, 11:23:01 PM
Quote from: Dark_Phantom on October 27, 2018, 08:17:00 AM

1.) ...  If you want one extra unit (6) you raise it by one (to 5, lua starts at 0).
It does?
https://stackoverflow.com/questions/2785704/why-do-lua-arraystables-start-at-1-instead-of-0

I suppose there could be some form of structure that would allow you to refer to something as the 0th index..
If lua object/map is a thing and can have numerical members like javascript can, I guess that makes sense.
Title: Re: How to have 6+ units in your game
Post by: Led on November 04, 2018, 04:06:59 AM
SWBF lua  does seem to start from zero.  But SWBF lua is non-standard.  Some features have been stripped out, too, particularly in the area of accessing system functions.
Title: Re: How to have 6+ units in your game
Post by: Dark_Phantom on November 05, 2018, 05:33:50 AM
At the very least, SWBF1 starts at 0 :)

Quote from: Giftheck on November 03, 2018, 02:27:08 PM
I've said it before, but I'll say it again: great work on getting this stable! This might change the game for a lot of people's mods!

I wonder if it's possible to 'shrink down' the unit buttons. to all fit on one side if you want to have less than 10 units (IE like SWBF2's 9).

I'm also curious as to whether it's possible to activate the side-selector as it appears in both the console versions and in PC SWBF2 (where you get a menu before the first spawn screen asking whether you want to be on team 1, 2 or be auto-assigned). If we have to disable the spawn-screen side-selector to get this working, getting the pre-spawn side-selector might be a workaround.
Shrinking down the unit buttons can be done - One of my pictures somewhere has an old version of it where I have all ten units in one column.  Sometimes the buttons didn't line up precisely with the highlighting if I remember right.

Getting that side selector working would be amazing!  I'm not going to call it an impossibility, but it seems to me that code lies in whatever "executable" the game has.  Still, it's something to look for in the future.  I hadn't really thought about it - great idea Gistech.
Title: Re: How to have 6+ units in your game
Post by: DylanRocket on November 16, 2018, 05:44:46 PM
Quote from: Dark_Phantom on October 27, 2018, 08:17:00 AM
You NEED Auto Assign for this to work properly.  Units 6 and 7 will be assigned to switching teams and you won't be able to select your unit.

In my testing, I've noticed that Unit 6 on Team 1 actually seems to work just fine without Auto Assign enabled:

[spoiler](https://i.imgur.com/23prbMr.png)[/spoiler]

Unit 6 on Team 2 does present the Team Switching issue however.
Title: Re: How to have 6+ units in your game
Post by: Giftheck on November 17, 2018, 02:52:34 AM
That is odd, surely it should work the same way. Maybe a scripting issue? It might be worth asking psych0fred. I know the spawn screen code was done third-party, but was the ifs_pc_spawnselect script? Maybe he can see something that would point to a resolution.
Title: Re: How to have 6+ units in your game
Post by: Dark_Phantom on November 17, 2018, 05:48:08 PM
Quote from: DylanRocket on November 16, 2018, 05:44:46 PM
In my testing, I've noticed that Unit 6 on Team 1 actually seems to work just fine without Auto Assign enabled:

[spoiler](https://i.imgur.com/23prbMr.png)[/spoiler]

Unit 6 on Team 2 does present the Team Switching issue however.
I had not noticed that before - great find!
Title: Re: How to have 6+ units in your game
Post by: 1ИCΘ6И17Θ on December 18, 2018, 02:47:35 AM
Now a question, would this work in multiplayer ?
Title: Re: How to have 6+ units in your game
Post by: Dark_Phantom on December 18, 2018, 05:22:59 AM
Yes, this is multiplayer compatible, as long as all clients have it.

AFAIK, you do NOT need the server executable to have this hex edit, just a mission.lua edit.  It would be in a different place in battlefront.exe, regardless, but in my testing it only matters if you pull up the spawnselect screen.
Title: Re: How to have 6+ units in your game
Post by: Giftheck on December 18, 2018, 05:35:22 AM
I think the only issue you would have is the switching teams issue ATM.
Title: Re: How to have 6+ units in your game
Post by: 1ИCΘ6И17Θ on December 19, 2018, 08:58:28 AM
Erh, I'm not complicating my life further more, my mod is stable and I upload it tonight, Battlefront's perfect and balanced as it is, and I'd rather keep my mod KISS, was just curious and therefore asked.  :P
Title: Re: How to have 6+ units in your game
Post by: Cade11 on March 19, 2021, 03:13:49 AM
Are 1A9985 and 1A94B2 still the right offsets? I am not seeing an 05 value in either spot.
Title: Re: How to have 6+ units in your game
Post by: Dark_Phantom on March 19, 2021, 04:57:29 AM
Make sure you're using the Stock 1.2 or SWBFspy exe.
I never attempted to find the offsets on the Steam/GOG version and probably never will, considering that version has extra crap to discourage it.
Title: Re: How to have 6+ units in your game
Post by: Javier on May 12, 2022, 05:00:52 PM
I did everything right but the sixth unit of team 2 won't let me choose it, it's weird, team 1 does let me select it. some help?  ???
Title: Re: How to have 6+ units in your game
Post by: wsa30h on May 13, 2022, 03:17:39 PM
please do not bump topics older than 30 days rather make a new one.
Title: Re: How to have 6+ units in your game
Post by: Giftheck on May 14, 2022, 12:41:18 AM
Quote from: Javier on May 12, 2022, 05:00:52 PMI did everything right but the sixth unit of team 2 won't let me choose it, it's weird, team 1 does let me select it. some help?  ???

To answer your question, there's something in the exe that we're assuming needs to be changed for the 6+ units to work exactly as intended, or it's hidden somewhere in the LUA script. We don't know what it is at this time.

There is technically a workaround in forcing you into a team, IIRC. But then you lose the ability to choose what team you want to play on.

For future reference, you should post a new topic in the SWBF1 Modding subforum.

Quote from: wsa30h on May 13, 2022, 03:17:39 PMplease do not bump topics older than 30 days rather make a new one.

Please don't junior moderate.
EhPortal 1.34 © 2024, WebDev