Raised This Month: $32 Target: $400
 8% 

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


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Dragokas
Veteran Member
Join Date: Nov 2017
Location: Ukraine on fire
Old 10-22-2021 , 08:18   [tweak][L4D/Any?] Open models by double click
Reply With Quote #1

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
Attached Files
File Type: zip open_model_assoc.zip (3.9 KB, 159 views)
__________________
Expert of CMD/VBS/VB6. Malware analyst. L4D fun (Bloody Witch & FreeZone)
[My plugins] [My tools] [GitHub] [Articles] [HiJackThis+] [Donate]

Last edited by Dragokas; 10-25-2021 at 08:11.
Dragokas is offline
Dragokas
Veteran Member
Join Date: Nov 2017
Location: Ukraine on fire
Old 10-24-2021 , 17:38   Re: [tweak][L4D/Any?] Open models by double click
Reply With Quote #2

Updated.

Quote:
Fixed: model doesn't open if path contains " " and ")".
Required: full reinstall - execute steps on association installation again.
__________________
Expert of CMD/VBS/VB6. Malware analyst. L4D fun (Bloody Witch & FreeZone)
[My plugins] [My tools] [GitHub] [Articles] [HiJackThis+] [Donate]
Dragokas is offline
8guawong
AlliedModders Donor
Join Date: Dec 2013
Location: BlackMarke7
Old 10-25-2021 , 04:37   Re: [tweak][L4D/Any?] Open models by double click
Reply With Quote #3

i'm trying to use this with csgo on windows 10
but i get



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
__________________
8guawong is offline
Dragokas
Veteran Member
Join Date: Nov 2017
Location: Ukraine on fire
Old 10-25-2021 , 08:12   Re: [tweak][L4D/Any?] Open models by double click
Reply With Quote #4

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+.
__________________
Expert of CMD/VBS/VB6. Malware analyst. L4D fun (Bloody Witch & FreeZone)
[My plugins] [My tools] [GitHub] [Articles] [HiJackThis+] [Donate]

Last edited by Dragokas; 10-25-2021 at 08:14.
Dragokas is offline
8guawong
AlliedModders Donor
Join Date: Dec 2013
Location: BlackMarke7
Old 10-25-2021 , 10:50   Re: [tweak][L4D/Any?] Open models by double click
Reply With Quote #5

Quote:
Originally Posted by Dragokas View Post
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?
__________________

Last edited by 8guawong; 10-25-2021 at 10:55.
8guawong is offline
Dragokas
Veteran Member
Join Date: Nov 2017
Location: Ukraine on fire
Old 10-25-2021 , 11:31   Re: [tweak][L4D/Any?] Open models by double click
Reply With Quote #6

Quote:
Originally Posted by 8guawong View Post
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 View Post
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.
__________________
Expert of CMD/VBS/VB6. Malware analyst. L4D fun (Bloody Witch & FreeZone)
[My plugins] [My tools] [GitHub] [Articles] [HiJackThis+] [Donate]

Last edited by Dragokas; 10-25-2021 at 11:33.
Dragokas is offline
8guawong
AlliedModders Donor
Join Date: Dec 2013
Location: BlackMarke7
Old 10-25-2021 , 11:52   Re: [tweak][L4D/Any?] Open models by double click
Reply With Quote #7

Quote:
Originally Posted by Dragokas View Post
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 View Post
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
__________________
8guawong is offline
fdxx
Member
Join Date: Oct 2020
Location: 0xdeadbeef
Old 12-03-2021 , 02:21   Re: [tweak][L4D/Any?] Open models by double click
Reply With Quote #8

Very good tool, thank you.
It would be better if you can optimize the opening speed.
fdxx is offline
Dragokas
Veteran Member
Join Date: Nov 2017
Location: Ukraine on fire
Old 12-03-2021 , 04:30   Re: [tweak][L4D/Any?] Open models by double click
Reply With Quote #9

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?
__________________
Expert of CMD/VBS/VB6. Malware analyst. L4D fun (Bloody Witch & FreeZone)
[My plugins] [My tools] [GitHub] [Articles] [HiJackThis+] [Donate]

Last edited by Dragokas; 12-03-2021 at 04:33.
Dragokas is offline
fdxx
Member
Join Date: Oct 2020
Location: 0xdeadbeef
Old 12-03-2021 , 06:24   Re: [tweak][L4D/Any?] Open models by double click
Reply With Quote #10

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.
fdxx is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 04:26.


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