[0.9.3][FIX]Resource RTE Mod + Other fixes

#1
Here's a portion of that 'be all' debug mod I thought about doing a while back. I had reading break, so I figured I'd go and write something useful.

It's pretty simple, it's just a series of wrapper functions(that I found on the B3D forums, though, they're pretty easy to write from scratch) that check to make sure that an asset exists before attempting to load it in memory. If it can't be loaded, it raises an RTE with the filename rather that waiting for the inevitable MAV when the asset needs to be used. I haven't seen the 'MAV before the game starts' in a while, so this probably isn't as useful as it would've been before I started school, but I thought I mighaswell get it done anyway.

If I wanted to be fancy, I could have the wrappers return a placeholder instead, but I think this is better overall for immediate debugging.

*Screen MAV fix:
Spoiler
Just replace

Code: Select all

temp2s=ReadString(f)
with

Code: Select all

temp2s$=ReadString(f)
In the LoadRMesh function in MapSystem.bb
*Double equip sound fix:
Spoiler
Remove the instances of

Code: Select all

PlaySound PickSFX(SelectedItem\itemtemplate\sound)
with regard to the hazmat suit, vest, finevest, and gasmask in the DrawGUI function in Main.bb

First block appears as follows:

Code: Select all

Case "hazmatsuit", "hazmatsuit2", "hazmatsuit3"
	PlaySound PickSFX(SelectedItem\itemtemplate\sound)
	If WearingHazmat Then
		Msg = "You take off the hazmat suit."
	Else
		Msg = "You put on the hazmat suit."
	EndIf
	MsgTimer = 70 * 5
	If SelectedItem\itemtemplate\tempname="hazmatsuit3" Then
		If WearingHazmat=0 Then WearingHazmat = 3 Else WearingHazmat=0
	ElseIf SelectedItem\itemtemplate\tempname="hazmatsuit2"
		If WearingHazmat=0 Then WearingHazmat = 2 Else WearingHazmat=0
	Else
		WearingHazmat = (Not WearingHazmat)
	EndIf
	SelectedItem = Null
The other items are right after the hazmat case
*Locked 1025 door fix
Spoiler
Not entirely sure if this was intended or not, but I'll post this here if anyone doesn't know how to fix it.
Remove the assignment to the locked property in

Code: Select all

r\RoomDoors[2]\AutoClose = False : r\RoomDoors[2]\open = False : r\RoomDoors[2]\locked = True
located in the room2scps case in the FillRoom function in MapSystem.bb
*Room2servers door fix
Spoiler
Put the

Code: Select all

If (e\room\angle = 0 Or e\room\angle = 180) Then
	If Abs(EntityX(Collider)-EntityX(e\room\obj,True))> 1.3 Then 
		e\EventState = 70*50
		e\Sound=0
	EndIf
Else
	If Abs(EntityZ(Collider)-EntityZ(e\room\obj,True))> 1.3 Then 
		e\EventState = 70*50
		e\Sound=0
	EndIf
EndIf	
block found inside the room2servers case in the UpdateEvents function in Main.bb inside an if construct that checks if the player is in the room.
*Document/screen loading delay
Spoiler
Remove the FreeImage call and SelectedScreen\img pointer assignment in

Code: Select all

If MouseUp1 Or MouseHit2 Then 		
	FreeImage SelectedScreen\img : SelectedScreen\img = 0 		
	SelectedScreen = Null 	
	MouseUp1 = False 	
EndIf
in Main.bb

Remove

Code: Select all

If SelectedItem\itemtemplate\img=0 Then
	If SelectedItem\itemtemplate\name = "Burnt Note" Then
		SelectedItem\itemtemplate\img = LoadImage("GFX\items\bn.it")
		SetBuffer ImageBuffer(SelectedItem\itemtemplate\img)
		Color 0,0,0
		Text 277, 469, AccessCode, True, True
		Color 255,255,255
		SetBuffer BackBuffer()
	Else
		SelectedItem\itemtemplate\img=LoadImage(SelectedItem\itemtemplate\imgpath)	
							
		ResizeImage(SelectedItem\itemtemplate\img, ImageWidth(SelectedItem\itemtemplate\img) * MenuScale, ImageHeight(SelectedItem\itemtemplate\img) * MenuScale)
	EndIf
	MaskImage(SelectedItem\itemtemplate\img, 255, 0, 255)
EndIf
In the paper case in the DrawGUI function in Main.bb leaving only the DrawImage call.

Remove

Code: Select all

If SelectedItem\itemtemplate\img=0 Then
	SelectedItem\itemtemplate\img=LoadImage(SelectedItem\itemtemplate\imgpath)	
	MaskImage(SelectedItem\itemtemplate\img, 255, 0, 255)
EndIf
in the radio and navigator cases in the same function.

Remove the paper check in

Code: Select all

If MouseHit2 Then
EntityAlpha Dark, 0.0
				
If SelectedItem\itemtemplate\tempname = "paper" Or SelectedItem\itemtemplate\tempname = "scp1025"  Then
	If SelectedItem\itemtemplate\img<>0 Then FreeImage(SelectedItem\itemtemplate\img)
	SelectedItem\itemtemplate\img=0
EndIf
				
If SelectedItem\itemtemplate\sound <> 66 Then PlaySound(PickSFX(SelectedItem\itemtemplate\sound))
        SelectedItem = Null
EndIf
in the same function. Add a keyhit check if you want tab to properly close images if you don't want to cache the images.

Put

Code: Select all

For ittemplate.ItemTemplates = Each ItemTemplates
	If ittemplate\name = "Burnt Note"
		SetBuffer ImageBuffer(ittemplate\img)
		Color 0,0,0
		Text 277, 469, AccessCode, True, True
		Color 255,255,255
		SetBuffer BackBuffer()
		Exit
	EndIf
Next
In the InitNewGame and InitLoadGame functions in Main.bb

Add

Code: Select all

If imgpath <> ""
	s\img = Loadimage_Strict("GFX\screens\"+s\imgpath)
	MaskImage s\img, 255,0,255
	ResizeImage(s\img, ImageWidth(s\img) * MenuScale, ImageHeight(s\img) * MenuScale)
EndIf
to the CreateScreens function in MapSystem.bb.

Remove

Code: Select all

s\img = Loadimage_Strict("GFX\screens\"+s\imgpath)
MaskImage s\img, 255,0,255
ResizeImage(s\img, ImageWidth(s\img) * MenuScale, ImageHeight(s\img) * MenuScale)
in the UpdateScreens function in MapSystem.bb

Add

Code: Select all

For it2.itemtemplates = Each ItemTemplates
	If it2\imgpath = imgpath And it2\img <> 0 Then it\img = CopyImage(it2\img) : Exit
Next
If imgpath <> "" And it\img = 0
	it\img = LoadImage_Strict(imgpath)
	If tempname = "paper" And name <> "Burnt Note"
		ResizeImage(it\img, ImageWidth(it\img) * MenuScale, ImageHeight(it\img) * MenuScale)
	EndIf
	MaskImage(it\img, 255, 0, 255)
EndIf
to the CreateItemTemplate function in Items.bb

Remove

Code: Select all

it\img = BurntNote
in the InitItemTemplates function in Items.bb

Note for juan/other people who give a shit about this sub-forum if they ever read this: This is more of a test than anything for anyone who has an issue with loading resources into memory during gameplay. As such, I left out a few optimizations and items, nor did I free the images in NullGame(There's a few issues with staring a game after quitting to menu, so I'm not going to bother for now) Feel free to call me out on wasting memory, but I felt using up an extra 15 megs or so of RAM is worth it.
*Failing to load gatea.rmesh or textures
Spoiler
Add

Code: Select all

CloseFile f
right before the function return in LoadRMesh in MapSystem.bb.

In the GetINIString and GetINIString2 functions in Main.bb move the CloseFile call to above the function return.

NOTE: This does not completely fix all issues with repeatedly starting/loading a game from the title screen. This is merely an obvious fix regarding leaving streams open, (It seems as if Read/Open/Write functions sometimes fail to return a handle if too many streams are left open while the handle runs out of scope) all this does is remove one entry in the set of bugs that behave in this manner.
*S-NAV Navigator Ultimate doesn't work when spawned by the console (Upload Pending)
Spoiler
Either check for the navigator type as an additional condition while checking the item state, or set the itemstate when the item is spawned in the console (like it is in Use914)
*S-NAV Navigator doesn't show map (Cannot Replicate)

*Radio doesn't allow channel changes (Cannot Replicate)

*096 Doors do not open (Cannot Replicate)

DL: http://www.mediafire.com/download/2q7ih ... IXESR2.rar

As always, feel free to post if other weird shit happens or you have discussion regarding the new runtime exceptions.
Last edited by MonocleBios on Sat Mar 29, 2014 4:06 am, edited 16 times in total.
M-x dingus-mode

Re: [0.9.3][FIX]Resource RTE Mod + Screen MAV Fix

#2
LoadRMesh also has a bug with bump mapping:

Code: Select all

If BumpEnabled And temp1s<>"" Then
	bumptex = GetBumpFromCache(temp1s)	
Else
	bumptex = 0
EndIf

If bumptex<>0 Then 
	BrushTexture brush, tex[1], 0, 0	
	BrushTexture brush, bumptex, 0, 1
	If tex[0]<>0 Then 
		BrushTexture brush, tex[0], 0, 2	
	Else
		BrushTexture brush,blankTexture,0,2
	EndIf
	
Else
	For j=0 To 1
		If tex[j]<>0 Then
			BrushTexture brush,tex[j],0,j
		Else
			BrushTexture brush,blankTexture,0,j
		EndIf
	Next				
EndIf
This part of the code breaks the texture-specific footsteps.

Instead of using the drawn mesh for collision checking, LoadRMesh makes separate meshes for efficient collision checking, in addition to making GetStepSound work properly.
The drawn mesh is a merge of all of the collision meshes. The collision meshes are hidden afterwards.

When Regalis changed bump mapping (it used to distort the diffuse textures, now it distorts the lightmaps), he decided to edit the collision meshes instead of the drawn mesh. So, GetStepSound can't find the texture it is looking for and will default to the concrete sound. To fix it, that code can be changed to:

Code: Select all

For j=0 To 1
	If tex[j]<>0 Then
		BrushTexture brush,tex[j],0,j
	Else
		BrushTexture brush,blankTexture,0,j
	EndIf
Next
Which is how it was before becoming official. And then, replace this:

Code: Select all

If BumpEnabled And 0 Then
With this:

Code: Select all

If BumpEnabled Then
To make the game edit the drawn mesh instead of the collision meshes. But this will revert bump mapping to it's old look. To fix that, just swap the lightmap texture with the diffuse texture:

Code: Select all

BrushTexture brush, tex[1], 0, 2 ;the last argument used to be 0	
BrushTexture brush, mat\Bump, 0, 1
BrushTexture brush, tex[0], 0, 0 ;the last argument used to be 2

Re: [0.9.3][FIX]Resource RTE Mod + Other fixes

#7
LORD DEATH wrote:I'll have to test it sometime. :) I did and there is an error with the map trying to read file gatea rmesh. It always happens in SCP-914s chamber. The bug fixes have NOT been put in the mirror version.
I'll take a look when I get home.
Just to clarify this occurs when you load a save made in 914's room right? I didn't know about that case when I wrote the fix.
M-x dingus-mode

Re: [0.9.3][FIX]Resource RTE Mod + Other fixes

#8
MonocleBios wrote:
LORD DEATH wrote:I'll have to test it sometime. :) I did and there is an error with the map trying to read file gatea rmesh. It always happens in SCP-914s chamber. The bug fixes have NOT been put in the mirror version.
I'll take a look when I get home.
Just to clarify this occurs when you load a save made in 914's room right? I didn't know about that case when I wrote the fix.
Yes, the incident does happen when I save inside of SCP-1914s chamber.
===============================
History is written by the victor~Winston Churchill
===============================