Skip to content

Commit

Permalink
3D Phone Booths are cool
Browse files Browse the repository at this point in the history
  • Loading branch information
Hampo committed Jul 1, 2024
1 parent 386c198 commit d95645a
Show file tree
Hide file tree
Showing 6 changed files with 140 additions and 2 deletions.
12 changes: 12 additions & 0 deletions Randomiser/3DPhoneBoothPreviewSupport.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[Miscellaneous]
; Sets the path to the background of the scene.
BackgroundPath=art\\frontend\\scrooby\\resource\\pure3d\\phonebg.p3d

; Set whether or not locked cars should be darkened.
DarkenLockedCars=1

; Set whether or not the scene is fullscreen or not (you most likely want it not to be)
FullScreen=0

; Sets the radius of the cars on the pedestal in the phonebooth
Radius=3.6
Binary file not shown.
1 change: 1 addition & 0 deletions Randomiser/Meta.ini
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ InternalName=Randomiser
Description=This mod allows for randomising various things throughout the game.
SupportsInternational=1
SupportsDemo=1
RequiredHack=3DPhoneBoothPreviewSupport
RequiredHack=CustomCarSupport
RequiredHack=CustomFiles
RequiredHack=CustomLimits
Expand Down
2 changes: 1 addition & 1 deletion Randomiser/Resources/HandleP3D.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ for moduleN=1,#Modules do

if handler and WildcardMatch(Path, handler.Path, true, true) then
GamePath = GamePath or GetGamePath(Path)
P3DFile = P3DFile or P3D.P3DFile(GamePath)
P3DFile = P3DFile or P3D.P3DFile(GamePath, true)

print("ModuleHandler", "Running P3D module: " .. module.Name)
local success, changed = pcall(handler.Callback, Path, P3DFile)
Expand Down
119 changes: 119 additions & 0 deletions Randomiser/Resources/Modules/General/PhoneBoothPreviews.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
local table_remove = table.remove

local PhoneBoothPreviews = Module("3D Phone Booth Previews", nil, 1)

PhoneBoothPreviews:AddP3DHandler("art\\frontend\\scrooby\\ingame.p3d", function(Path, P3DFile)
local FrontendProjectChunk = P3DFile:GetChunk(P3D.Identifiers.Frontend_Project)
local PhoneboothPageChunk = FrontendProjectChunk:GetChunk(P3D.Identifiers.Frontend_Page, false, "PhoneBooth.pag")

local ForegroundLayerIndex, ForegroundLayerChunk = PhoneboothPageChunk:GetChunkIndexed(P3D.Identifiers.Frontend_Layer, false, "Foreground")

PhoneboothPageChunk:AddChunk(P3D.FrontendPure3DResourceP3DChunk("3Dmodel", 1, "pure3d\\_stubs\\dummy.p3d", "dummy", "Pedestal_Camera", "", ""), ForegroundLayerIndex)
PhoneboothPageChunk:AddChunk(P3D.FrontendPure3DResourceP3DChunk("phonebg", 1, "pure3d\\_stubs\\dummy.p3d", "dummy", "Pedestal_Camera", "", ""), ForegroundLayerIndex + 1)
PhoneboothPageChunk:AddChunk(P3D.FrontendPure3DResourceP3DChunk("rewardfg", 1, "pure3d\\rewardfg.p3d", "PurchaseScene", "Pedestal_Camera", "", ""), ForegroundLayerIndex + 2)

local GroupChunk = P3D.FrontendGroupP3DChunk("3DModel", 0, 255)
ForegroundLayerChunk:AddChunk(GroupChunk)

GroupChunk:AddChunk(P3D.FrontendPure3DObjectP3DChunk("RewardBG", 1, {X = 29, Y = 145}, {X = 400, Y = 300}, {X = P3D.FrontendPure3DObjectP3DChunk.Justifications.Left, Y = P3D.FrontendPure3DObjectP3DChunk.Justifications.Top}, {A=255,R=255,G=255,B=255}, 0, 0, "phonebg"))
GroupChunk:AddChunk(P3D.FrontendPure3DObjectP3DChunk("RewardFG", 1, {X = 29, Y = 145}, {X = 400, Y = 300}, {X = P3D.FrontendPure3DObjectP3DChunk.Justifications.Left, Y = P3D.FrontendPure3DObjectP3DChunk.Justifications.Top}, {A=255,R=255,G=255,B=255}, 0, 0, "rewardfg"))
GroupChunk:AddChunk(P3D.FrontendPure3DObjectP3DChunk("PreviewWindow", 1, {X = 29, Y = 145}, {X = 400, Y = 300}, {X = P3D.FrontendPure3DObjectP3DChunk.Justifications.Left, Y = P3D.FrontendPure3DObjectP3DChunk.Justifications.Top}, {A=255,R=255,G=255,B=255}, 0, 0, "3Dmodel"))

return true
end)

local RemoveAllWheels = {
["frink_v"] = true,
["honor_v"] = true,
["hbike_v"] = true,
["witchcar"] = true,
["ship"] = true,
["mono_v"] = true,
}
local RemoveFrontWheels = {
["rocke_v"] = true,
}
PhoneBoothPreviews:AddP3DHandler("art\\frontend\\dynaload\\cars\\*.p3d", function(Path, P3DFile)
local FileName = GetFileName(Path)
local BaseFilePath = "/GameData/art/cars/" .. FileName
assert(Exists(BaseFilePath, true, false), "Loading a phonebooth preview for a car that doesn't exist. I blame Radical.")

local BaseP3DFile = P3D.P3DFile(BaseFilePath)
P3DFile.Chunks = BaseP3DFile.Chunks

--
-- Get Chunks
--

local CompositeDrawableChunk = P3DFile:GetChunk(P3D.Identifiers.Composite_Drawable)
assert(CompositeDrawableChunk, "Could not find Composite Drawable when creating a phonebooth preview.")

local CompositeDrawablePropListChunk = CompositeDrawableChunk:GetChunk(P3D.Identifiers.Composite_Drawable_Prop_List)
assert(CompositeDrawablePropListChunk, "Could not find Composite Drawable Prop List when creating a phonebooth preview.")

--
-- Remove Dummy Wheel Models (Radical hardcodedly removes these in-game)
--

if RemoveAllWheels[FileNameWithoutExtension] then
P3DUtils.RemoveChunksWithName(CompositeDrawablePropListChunk, { ["wShape0"] = true, ["wShape1"] = true, ["wShape2"] = true, ["wShape3"] = true }, P3D.Identifiers.Composite_Drawable_Prop)
elseif RemoveFrontWheels[FileNameWithoutExtension] then
P3DUtils.RemoveChunksWithName(CompositeDrawablePropListChunk, { ["wShape2"] = true, ["wShape3"] = true }, P3D.Identifiers.Composite_Drawable_Prop)
end

--
-- Remove Billboards
--

local removedBillboards = {}

for idx, chunk in P3DFile:GetChunksIndexed(P3D.Identifiers.Old_Billboard_Quad_Group, true) do
removedBillboards[chunk.Name] = true

P3DFile:RemoveChunk(idx)
end

P3DUtils.RemoveChunksWithName(CompositeDrawablePropListChunk, removedBillboards)

--
-- Remove Old Frame Controllers
--

for idx in P3DFile:GetChunksIndexed(P3D.Identifiers.Old_Frame_Controller, true) do
P3DFile:RemoveChunk(idx)
end

--
-- Remove Multi Controller Tracks
--

local MultiControllerChunk = P3DFile:GetChunk(P3D.Identifiers.Multi_Controller)

if MultiControllerChunk ~= nil then
local MultiControllerTracksChunk = MultiControllerChunk:GetChunk(P3D.Identifiers.Multi_Controller_Tracks)

if MultiControllerTracksChunk then
local Tracks = MultiControllerTracksChunk.Tracks

for i = #Tracks, 1, -1 do
if Tracks[i].Name:sub(1, 4) ~= "PTRN" then
table_remove(Tracks, i)
end
end
end
end

--
-- Replace Shiny Shaders
--

for chunk in P3DFile:GetChunks(P3D.Identifiers.Shader) do
if chunk.PddiShaderName == "environment" or chunk.PddiShaderName == "spheremap" then
chunk.PddiShaderName = "simple"
end
end

return true
end)

return PhoneBoothPreviews
8 changes: 7 additions & 1 deletion Randomiser/Resources/lib/P3D2.lua
Original file line number Diff line number Diff line change
Expand Up @@ -734,11 +734,17 @@ local function LoadP3DFileFromData(self, contents)
return setmetatable(Data, self)
end

local function LoadP3DFile(self, Path)
local function LoadP3DFile(self, Path, NewOnDoesntExist)
if Path == nil then
self.__index = self
return setmetatable({ Endian = "<", Chunks = {} }, self)
else
if not Exists(Path, true, false) then
assert(NewOnDoesntExist, "Arg #1 (Path) does not exist.")

self.__index = self
return setmetatable({ Endian = "<", Chunks = {} }, self)
end
local success, contents = pcall(ReadFile, Path)
assert(success, string.format("Failed to read file at '%s': %s", Path, contents))

Expand Down

0 comments on commit d95645a

Please sign in to comment.