Jump to content

Package Plugins and Mods


Josh

4,264 views

 Share

Leadwerks 4 supports compressed and encrypted game files in ZIP format, but there are many different custom package formats different games use. The plugin system in Leadwerks 5 allows us to create importers for these different package formats so we can access content directly from commercial games you have installed on your computer. The example below shows how to load a VTF texture from the game Half-Life 2 directly from the game's install files.

First we need to load some plugins to deal with these weird file formats.

--Load VPK package loader plugin
local vpkloader = LoadPlugin("Plugins/VPK.dll")

--Load VTF texture loader plugin
local vtfloader = LoadPlugin("Plugins/VTF.dll")

Next we will load a single VPK package directly from the Half-Life 2 install directory. If you have Steam installed somewhere other than the default path you can change the value of the STEAM_PATH variable to load the package from somewhere else.

--Steam installation path
local STEAM_PATH = "C:/Program Files (x86)/Steam"

--Load package (Half-Life 2 must be installed)
local pkg = LoadPackage(STEAM_PATH.."/steamapps/common/Half-Life 2/hl2/hl2_textures_dir.vpk")

Now we can load content directly from the Half-Life 2 game files. Although the file specified below does not actually exist in the game folder, it will be loaded as if it was because of the VPK package we previously loaded.

--Load texture
local tex = LoadTexture("materials/building_template/buildingset040a.vtf")

Here is the result when I run the program:

Untitled.thumb.jpg.9464203d9a4f55c009fb755d582e9fe2.jpg

Now if you wanted to load all the HL2 data files when your game starts, that is easy to do too. If you place this script in the "Scripts/Start" folder all the content will be automatically made available:

local STEAM_PATH = "C:/Program Files (x86)/Steam/"
local HL2_PATH = STEAM_PATH.."steamapps/common/Half-Life 2/hl2/"

local dir = LoadDir(HL2_PATH)
local k,v
LoadedPackages = {}

for k,v in ipairs(dir) do
    local ext = Lower(ExtractExt(v))
    if ext == "vpk" then
        local pkg = LoadPackage(v)
        if pkg ~= nil then
            table.insert(LoadedPackages, pkg)
        end
    end
end

What is this good for? You can browse and view all the content in your installed games and use some assets as placeholders. Valve is pretty lenient with their IP so if your game is only published on Steam, you could probably use all the Source games textures and models. You could make a mod that replaces the original game engine but requires the game to be installed to run. It would also not be too hard to integrate these features into the new editor so that it can be used as a modding tool for different games and allow you to create new game levels.

You can get the source for this and other plugins on Github.

  • Like 5
 Share

0 Comments


Recommended Comments

Source Engine models have a lot of information in them so I don't know how easy/hard it would be.

But also, this means we can use vpks to store our game data?

Link to comment
1 hour ago, reepblue said:

Source Engine models have a lot of information in them so I don't know how easy/hard it would be.

But also, this means we can use vpks to store our game data?

Yes. I am curious why you would want to use that format?

Link to comment

I know it's not the same thing but since Leadwerks supports multiple custom password-protected zips (which I appreciate maybe even more that Steam and analytics support), you can make each zip only a few hundred megs or however small you want.

Link to comment
2 minutes ago, gamecreator said:

I know it's not the same thing but since Leadwerks supports multiple custom password-protected zips (which I appreciate maybe even more that Steam and analytics support), you can make each zip only a few hundred megs or however small you want.

I know, I plan on doing this for my project when the time comes. However, I'd need to create a way to do this automatically. Closest I got was I compiled an app that makes zip files, but I couldn't get password encryption to work. If you know of a good command line app for zip files, let me know.

Link to comment

7-zip (free) does this.  For example, here's the relevant line in an automatic batch file I created to back up a project:

"C:\Program Files\7-Zip\7z.exe" a -tzip "projectname backup.zip" "C:\Users\user\Documents\Leadwerks\Projects\projectname\" -mx9 -xr!.vs

The -xr! argument makes it so a folder is excluded from the zip.  In my case it's the .vs (Visual Studio) folder which has over a gig of Visual Studio created project files.  The exe has a lot of helpful arguments to choose from.

  • Thanks 2
Link to comment
Guest
Add a comment...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...