Fixed [Linux] MD2 Woes

Status
Not open for further replies.
Testing was performed using the SADX Md2 Pack from Virtual's MD2 Collection, as it's the only currently released MD2 pack for 2.1.

  1. Case Sensitivity: MD2.dat
    The terminal output tells me "Error while loading md2.dat." like a million times. This is because the file is named MD2.dat as opposed to md2.dat. Lowercasing the file solves the problem
  2. Sonic Remains a Sprite
    No errors this time, but Sonic remains a sprite. As for the other characters...
    srb20003.png
  3. "Okay, wise guy, where am I?" - Characters are invisible.
    srb20004.png

    As it turns out, the folder all the models are in is called MD2 instead of md2. Lowercasing the folder fixes the issue without even a restart
    srb20005.png
  4. Sonic STILL Remains a Sprite
    srb20006.png

    Well, time to code! I decided to compare side-by-side the startup logs of the Linux version and Windows version ran in Wine. Long story short, InitMD2() gets called in Linux before Sonic's skin is registered, leading to InitMD2() to silently fail. However, Tails's and Knuckles's models work because they are covered by AddPlayerMD2(), as their skins are defined in srb2.srb rather than hardcoded in the game's source code.
    The easiest solution is to call AddPlayerMD2() immediately after sonic's skin is registered. Here's an attached proof-of-concept patch file.
    Code:
    diff --git a/src/r_things.c b/src/r_things.c
    index afbda8d..be1eb3d 100644
    --- a/src/r_things.c
    +++ b/src/r_things.c
    @@ -2390,6 +2390,12 @@ void R_InitSkins(void)
     	skin->spritedef.numframes = sprites[SPR_PLAY].numframes;
     	skin->spritedef.spriteframes = sprites[SPR_PLAY].spriteframes;
     	ST_LoadFaceGraphics(skin->face, skin->superface, 0);
    +	
    +	//MD2 for sonic doesn't want to load in Linux.
    +#ifdef HWRENDER
    +	if (rendermode == render_opengl)
    +		HWR_AddPlayerMD2(0);
    +#endif	
     }
     
     // returns true if the skin name is found (loaded from pwad)
    srb20007.png

    Much better. And now everything is working except...
  5. Case Sensitivity Strikes Again: Thock.MD2
    Sonic is missing the thok effect.
    srb20009.png

    The line in md2.dat is "Thok Thok.md2 3.3 0.0", but the file is named Thok.MD2. CURSE YOU CASE SENSITIVITY! Renaming the file to Thok.md2 solved the problem without even a restart.
    srb20011.png

    I imagine fixing the line in md2.dat would also work, but I figured that'd require a restart.

Because properly fixing the case sensitivity issues will require major refactoring of the codebase, a simpler method is to save the following as a bash script [suggested filename: fixMD2s.sh] in the main srb2 directory, give it executable permissions, and run it. This script will resolve all of the case sensitivity issues reported here, or at the very least tell you that it can't and the reason why.
Code:
#!/bin/bash
# 
# Copyright (C) 2014 Joel "ForgiveThisNewb" Hammond
#
# Permission is hereby granted, free of charge, to any person obtaining 
# a copy of this software and associated documentation files (the 
# "Software"), to deal in the Software without restriction, including 
# without limitation the rights to use, copy, modify, merge, publish, 
# distribute, sublicense, and/or sell copies of the Software, and to 
# permit persons to whom the Software is furnished to do so, subject to 
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 
# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

# fixMD2s.sh - Version 2
# Resolves case-sensitivity issues surrounding the use of MD2 files for
#	Sonic Robo Blast 2 on Linux.

function main {
	#Fix the name of md2.dat
	if ! locateFile "md2.dat" 
	then
		echo "Script exiting due to fatal errors."
		exit;
	fi
	
	#Fix the name of the MD2 folder
	if ! locateFile "md2"
	then
		echo "Script exiting due to fatal errors."
		exit;
	fi
	
	#Process md2.dat
	processMd2Dat "md2.dat"
}

function locateFile {
	#Change the interal field seperator to not include spaces.
	#This change lasts for only this function.
	IFS="
	"
	
	#If the necessary file exists
	if [ -e "$1" ]
	then
		#echo "${1} found."
		return 0
	else
		echo "${1} not found.  Searching for case-changed variants..."
		search=(`ls -1 | grep -i ^"$1"$`)		
		
		if [[ "${#search[@]}" == "1" ]]
		then
			echo "	One result found.  Moving ${search[0]} to $1..."
			mv "${search[0]}" "$1"
			echo "	Moving on."
		elif [[ "${#search[@]}" == "0" ]]
		then
			echo "	No results found.  Create or locate a $1 file."
			return 1
		else
			echo "	${#search[@]} results found.  Manually resolve the issue."
			return 1
		fi
	fi
}

function processMd2Dat {
	#Get a list of all md2 files
	while read line
	do
		md2files[${#md2files[@]}]="`echo $line | cut -d' ' -f2`"
	done < "$1"
	
	#Ensure those files exist
	cd md2/
	for md2 in ${md2files[@]}
	do
		if ! locateFile "$md2"
		then
			echo "Script exiting due to fatal errors."
			exit
		fi
		textureFile="`echo $md2 | cut -d'.' -f1`.png"
		if ! locateFile "$textureFile"
		then
			echo "ERROR IS NOT FATAL.  Script Continuing."
			exit
		fi
	done
	cd ..
}

main

EDIT: I missed another case sensitivity issue. The rings are still using the sprite texture. Script will be updated to ensure that md2 textures are cased properly as well. Please wait.

Edit 2: Script updated to Version 2 - now checks for properly named texture files. The rings now have proper textures applied to them.
 
Last edited by a moderator:
Could you fork, commit and ask for a pull request?
Or make a commit and do 'git format-patch origin/master' to make a ####-Commit_Message.patch files?
 
Patch is attached. Remove the .txt I added so that it would upload as an attachment and it should be exactly what you wanted, and less of a hassle to me than registering a github account to do a pull request on top of fixing the bug myself and writing a script to resolve other issues.

I hate git, but at the same time I recognize it's usefulness.

EDIT: I decided to learn how to use github to make the pull request. It was made.
 

Attachments

  • 0001-Proof-of-concept-fix-for-Sonic-s-sprite-not-being-re.patch.txt
    883 bytes · Views: 197
Last edited:
Status
Not open for further replies.

Who is viewing this thread (Total: 1, Members: 0, Guests: 1)

Back
Top