AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Snippets and Tutorials (https://forums.alliedmods.net/forumdisplay.php?f=112)
-   -   [tweak][L4D/Any?] Open models by double click (https://forums.alliedmods.net/showthread.php?t=334831)

Dragokas 10-22-2021 08:18

[tweak][L4D/Any?] Open models by double click
 
1 Attachment(s)
Purpose:

This allows you to open downloaded .mdl files in model viewer (hlmv) by just double-clicking on them.

Compatibility:
- Windows
- L4D1 / L4D2 / Maybe, other games too if you correct all paths

Installation:
1. Download archive attached, unpack appropriate folder (l4d1 or l4d2).
2. Move unpacked folder to safe place on PC where you'll not touch/not delete it.
3. Right click on hlmv_loader.vbs => Edit => Change this line:
Code:

L4d = "D:\Steam2\steamapps\common\left 4 dead"
to the full path of your game. Then, File => Save.

4a. For Windows 7 only:
- Run As Admin (RMB -> Run as Administrator) the file Assoc_Installer_Win7.bat

4b. For Windows 8/10+ only:
- Run any .mdl file
- in "Open with..." window => (scroll to bottom) => More Apps => (scroll to bottom) => Look for another App => Browse to unpacked folder and select launcher_Win10.bat
- Run any .mdl file again, mark checkbox "Always use this app", select launcher_Win10.bat from the list => OK.
- If checkbox "Always use this app" doesn't exist, you shall go a long way:
Spoiler


That's all. Good luck!

Dependency:
- Authoring Tools should be installed.

Details of what the script do:
Spoiler

Dragokas 10-24-2021 17:38

Re: [tweak][L4D/Any?] Open models by double click
 
Updated.

Quote:

Fixed: model doesn't open if path contains " " and ")".
Required: full reinstall - execute steps on association installation again.

8guawong 10-25-2021 04:37

Re: [tweak][L4D/Any?] Open models by double click
 
i'm trying to use this with csgo on windows 10
but i get

https://i.imgur.com/XS9bkzu.png

my l4d1 hlmv_loader.vbs

Code:

Option Explicit
On Error Resume Next
Dim L4d, models, materials, bin


L4d = "C:\Program Files (x86)\Steam\steamapps\common\Counter-Strike Global Offensive"


models = L4d & "\csgo\models"
materials = L4d & "\csgo\materials"
bin = L4d & "\bin"

Dim oShell, oFSO, t_model_dir, arg, model_name, model_dir, mat_src

Set oShell    = CreateObject("WScript.Shell")
Set oFSO      = CreateObject("Scripting.FileSystemObject")

arg = WScript.Arguments(0)
model_dir = oFSO.GetParentFolderName(arg)
model_name = oFSO.GetFileName(arg)
t_model_dir = models & "\- temp\v"

if oFSO.FolderExists(t_model_dir) then oFSO.DeleteFolder t_model_dir, true
if not oFSO.FolderExists(oFSO.GetParentFolderName(t_model_dir)) then oFSO.CreateFolder oFSO.GetParentFolderName(t_model_dir)
if not oFSO.FolderExists(t_model_dir) then oFSO.CreateFolder t_model_dir

oFSO.CopyFolder model_dir, t_model_dir, true

PatchFile t_model_dir & "\" & model_name, "- temp\v\" & model_name, 12, false

if oFSO.FolderExists(model_dir & "\..\materials")                                then mat_src = model_dir & "\..\materials"
if oFSO.FolderExists(model_dir & "\..\..\materials")                        then mat_src = model_dir & "\..\..\materials"
if oFSO.FolderExists(model_dir & "\..\..\..\materials")                then mat_src = model_dir & "\..\..\..\materials"
if oFSO.FolderExists(model_dir & "\..\..\..\..\materials")                then mat_src = model_dir & "\..\..\..\..\materials"
if oFSO.FolderExists(model_dir & "\..\..\..\..\..\materials")        then mat_src = model_dir & "\..\..\..\..\..\materials"

oFSO.CopyFolder mat_src, materials, true

oShell.CurrentDirectory = models
oShell.Run """" & bin & "\hlmv.exe" & """" & " -game " & """" & oFSO.GetParentFolderName(models) & """" & " " & """" & "- temp\v\" & model_name & """"


Function PatchFile(FileName, strData, Offset, Unicode)
  PatchFileArray FileName, MultiByteToBinary(strData & chr(0), Unicode), Offset
End Function

Function PatchFileArray(FileName, ByteArray, Offset)
  Const adTypeBinary = 1
  Const adSaveCreateOverWrite = 2
 
  Dim BinaryStream
  Set BinaryStream = CreateObject("ADODB.Stream")
  BinaryStream.Type = adTypeBinary
  BinaryStream.Open
  BinaryStream.LoadFromFile FileName
  BinaryStream.Position = Offset
  BinaryStream.Write ByteArray
  BinaryStream.SaveToFile FileName, adSaveCreateOverWrite
  BinaryStream.Close
End Function

Function MultiByteToBinary(MultiByte, Unicode)
  Dim RS, LMultiByte, Binary
  Const adLongVarBinary = 205
  Set RS = CreateObject("ADODB.Recordset")
  if Unicode then
        LMultiByte = LenB(MultiByte)
  else
        LMultiByte = Len(MultiByte)
  end if
  If LMultiByte > 0 Then
    RS.Fields.Append "mBinary", adLongVarBinary, LMultiByte
    RS.Open
    RS.AddNew
        if Unicode then
          RS("mBinary").AppendChunk MultiByte & ChrB(0)
        else
          RS("mBinary").AppendChunk StringToMB(MultiByte) & ChrB(0)
        end if
    RS.Update
    Binary = RS("mBinary").GetChunk(LMultiByte)
  End If
  MultiByteToBinary = Binary
End Function

Function StringToMB(S)
  Dim I, B
  For I = 1 To Len(S)
    B = B & ChrB(Asc(Mid(S, I, 1)))
  Next
  StringToMB = B
End Function

l4d2 hlmv_loader.vbs
Code:

Option Explicit
On Error Resume Next
Dim L4d, models, materials, bin


L4d = "C:\Program Files (x86)\Steam\steamapps\common\Counter-Strike Global Offensive"


models = L4d & "\csgo\models"
materials = L4d & "\csgo\materials"
bin = L4d & "\bin"

Dim oShell, oFSO, t_model_dir, arg, model_name, model_dir, mat_src

Set oShell    = CreateObject("WScript.Shell")
Set oFSO      = CreateObject("Scripting.FileSystemObject")

arg = WScript.Arguments(0)
model_dir = oFSO.GetParentFolderName(arg)
model_name = oFSO.GetFileName(arg)
t_model_dir = models & "\- temp\v"

if oFSO.FolderExists(t_model_dir) then oFSO.DeleteFolder t_model_dir, true
if not oFSO.FolderExists(oFSO.GetParentFolderName(t_model_dir)) then oFSO.CreateFolder oFSO.GetParentFolderName(t_model_dir)
if not oFSO.FolderExists(t_model_dir) then oFSO.CreateFolder t_model_dir

oFSO.CopyFolder model_dir, t_model_dir, true

PatchFile t_model_dir & "\" & model_name, "- temp\v\" & model_name, 12, false

if oFSO.FolderExists(model_dir & "\..\materials")                                then mat_src = model_dir & "\..\materials"
if oFSO.FolderExists(model_dir & "\..\..\materials")                        then mat_src = model_dir & "\..\..\materials"
if oFSO.FolderExists(model_dir & "\..\..\..\materials")                then mat_src = model_dir & "\..\..\..\materials"
if oFSO.FolderExists(model_dir & "\..\..\..\..\materials")                then mat_src = model_dir & "\..\..\..\..\materials"
if oFSO.FolderExists(model_dir & "\..\..\..\..\..\materials")        then mat_src = model_dir & "\..\..\..\..\..\materials"

oFSO.CopyFolder mat_src, materials, true

oShell.CurrentDirectory = models
oShell.Run """" & bin & "\hlmv.exe" & """" & " -game " & """" & oFSO.GetParentFolderName(models) & """" & " " & """" & "- temp\v\" & model_name & """"


Function PatchFile(FileName, strData, Offset, Unicode)
  PatchFileArray FileName, MultiByteToBinary(strData & chr(0), Unicode), Offset
End Function

Function PatchFileArray(FileName, ByteArray, Offset)
  Const adTypeBinary = 1
  Const adSaveCreateOverWrite = 2
 
  Dim BinaryStream
  Set BinaryStream = CreateObject("ADODB.Stream")
  BinaryStream.Type = adTypeBinary
  BinaryStream.Open
  BinaryStream.LoadFromFile FileName
  BinaryStream.Position = Offset
  BinaryStream.Write ByteArray
  BinaryStream.SaveToFile FileName, adSaveCreateOverWrite
  BinaryStream.Close
End Function

Function MultiByteToBinary(MultiByte, Unicode)
  Dim RS, LMultiByte, Binary
  Const adLongVarBinary = 205
  Set RS = CreateObject("ADODB.Recordset")
  if Unicode then
        LMultiByte = LenB(MultiByte)
  else
        LMultiByte = Len(MultiByte)
  end if
  If LMultiByte > 0 Then
    RS.Fields.Append "mBinary", adLongVarBinary, LMultiByte
    RS.Open
    RS.AddNew
        if Unicode then
          RS("mBinary").AppendChunk MultiByte & ChrB(0)
        else
          RS("mBinary").AppendChunk StringToMB(MultiByte) & ChrB(0)
        end if
    RS.Update
    Binary = RS("mBinary").GetChunk(LMultiByte)
  End If
  MultiByteToBinary = Binary
End Function

Function StringToMB(S)
  Dim I, B
  For I = 1 To Len(S)
    B = B & ChrB(Asc(Mid(S, I, 1)))
  Next
  StringToMB = B
End Function


Dragokas 10-25-2021 08:12

Re: [tweak][L4D/Any?] Open models by double click
 
8guawong, ah, I forgot, Microsoft broke that in Win10.
Download again and point to launcher_Win10.bat when you create an association.

Updated.
Quote:

Fixed compatibility with Windows 8/10+.

8guawong 10-25-2021 10:50

Re: [tweak][L4D/Any?] Open models by double click
 
Quote:

Originally Posted by Dragokas (Post 2761625)
8guawong, ah, I forgot, Microsoft broke that in Win10.
Download again and point to launcher_Win10.bat when you create an association.

Updated.

thanks it's working
this is very useful since hlmv for csgo does not remember the path of last model
i'm wondering for csgo should i use l4d1 or l4d2? or it doesn't matter?
btw is it normal to take a long time (maybe 10+ sec) to open up hlmv after double clicking?

Dragokas 10-25-2021 11:31

Re: [tweak][L4D/Any?] Open models by double click
 
Quote:

Originally Posted by 8guawong (Post 2761641)
i'm wondering for csgo should i use l4d1 or l4d2? or it doesn't matter?

They almost identical. It doesn't matter since you corrected all paths accordingly to csgo folder structure.
It would be good if you share your example that is surely work OK.

Quote:

Originally Posted by 8guawong (Post 2761641)
btw is it normal to take a long time (maybe 10+ sec) to open up hlmv after double clicking?

It depends on where you opened a model from. Originally, it is designed to open .mdl from stand-alone folder, like the one freshly unpacked from vpk.

If you open .mdl from some large container (like fully unpacked _dir.vpk) or perhaps, game folder itself, it firstly copy the whole "materials" folder which is huge and the operation is defaulted to "always overwrite", that's why it can takes a lot of time in your case. I'm open on ideas what can be improved and how.

8guawong 10-25-2021 11:52

Re: [tweak][L4D/Any?] Open models by double click
 
Quote:

Originally Posted by Dragokas (Post 2761650)
They almost identical. It doesn't matter since you corrected all paths accordingly to csgo folder structure.
It would be good if you share your example that is surely work OK.

ok, so i can delete either l4d1 or l4d2?
my example is in post #3

Quote:

Originally Posted by Dragokas (Post 2761650)
It depends on where you opened a model from. Originally, it is designed to open .mdl from stand-alone folder, like the one freshly unpacked from vpk.

If you open .mdl from some large container (like fully unpacked _dir.vpk) or perhaps, game folder itself, it firstly copy the whole "materials" folder which is huge and the operation is defaulted to "always overwrite", that's why it can takes a lot of time in your case. I'm open on ideas what can be improved and how.

ic... wondering will it be faster if you open next mdl it will reuse the opened hlmv? right now if you double click on 2nd mdl it opens another hlmv

fdxx 12-03-2021 02:21

Re: [tweak][L4D/Any?] Open models by double click
 
Very good tool, thank you.
It would be better if you can optimize the opening speed.

Dragokas 12-03-2021 04:30

Re: [tweak][L4D/Any?] Open models by double click
 
fdxx, I don't have performance issues. 1-2 sec. to open max.
What folder are you opening mdl from?

If that's the own game's folder, try to open from desktop? Is it solve your issue?

If no, try temporarily disable antivirus. Is it help?

Try to downoload Crowbar. Go to tab "View":
1. "Game that has model viewer" - select Left 4 Dead 1 or 2. Press "Setup Games" => Select game's steeam folder.
2. Browse... => Select mdl
3. Press "View as Replacement".
Is it fast enough?

fdxx 12-03-2021 06:24

Re: [tweak][L4D/Any?] Open models by double click
 
I opened the .mdl file directly from the desktop. I don't have antivirus.

In my case, after double-clicking the .mdl file, it will stay in the CMD window for about 4 seconds, and then the hlmv software will pop up.

Using Crowbar software, it did not improve much.

However, I only occasionally check what the model looks like, When I just look at the file name and can’t guess the model. whatever if, it’s enough for me.


All times are GMT -4. The time now is 05:11.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.