Skip to content

Instantly share code, notes, and snippets.

@TheDaftRick
Forked from flibitijibibo/fnaUpdate.sh
Last active October 24, 2020 20:00
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save TheDaftRick/c7948d00203ad618861dfd11e04fb311 to your computer and use it in GitHub Desktop.
Save TheDaftRick/c7948d00203ad618861dfd11e04fb311 to your computer and use it in GitHub Desktop.
FNA update script for Terraria -requires running the game in 64bit
#!/bin/bash
# This script it outdated - please see the original for updates
#
# FNA Update Script
# Written by Ethan "flibitijibibo" Lee
# Edited by TheDaftRick
#
# Released under public domain.
# No warranty implied; use at your own risk.
#
# Linux guide:
# Place this file fnaUpdate.sh in your Terraria folder
# Open your Terraria folder in terminal and run these two commands
# chmod +x fnaUpdate.sh
# ./fnaUpdate.sh -autoarch
# Add a Non-Steam game and select Terraria.bin.x86_64 in your Terraria folder
# Use this to run Terraria (Steam will still see you running the regular version of Terraria with all Steam features working)
#
# If you want to run the 32bit version of Terraria then use this script to update FNA to 1707
# https://gist.github.com/TheDaftRick/d5e49ebbfd8f09ddfb66dc29e775ece1
#
# Run this script in the game's executable folder.
# For OSX this will be Game.app/Contents/MacOS/.
#
# This script requires the following programs:
# - git
# - make
# - dmcs, the Mono C# compiler
# Be Smart. Be Safe.
set -e
# Move to script's directory
cd "`dirname "$0"`"
# Get the system architecture
UNAME=`uname`
ARCH=`uname -m`
# Grab native libraries
curl -O fna.flibitijibibo.com/archive/fnalibs.tar.bz2
if [ "$UNAME" == "Darwin" ]; then
tar xvfj fnalibs.tar.bz2 osx
else
if [ "$ARCH" == "x86_64" ]; then
tar xvfj fnalibs.tar.bz2 lib64
else
tar xvfj fnalibs.tar.bz2 lib
fi
fi
rm fnalibs.tar.bz2 # Wouldn't want to waste disk space, would we...
# Download and build latest FNA
if [ -d "FNA" ]; then
cd FNA
git pull
git submodule update
else
git clone --recursive git://github.com/FNA-XNA/FNA.git
cd FNA
fi
sed -i 's/IntPtr mem,/byte[] mem,/g' lib/SDL2-CS/src/SDL2.cs
make release
cd ..
cp FNA/bin/Release/* .
# We out.
echo Complete!
@felipe19930
Copy link

I heard it's needed an IQ of 80+ to apply the patch successfully.

@dowttie
Copy link

dowttie commented May 28, 2020 via email

@CyberShadow
Copy link

CyberShadow commented Jun 7, 2020

Trying to get this to work on Arch Linux with the GOG version (1.4.0.5).


Problem 1, the sed invocation doesn't seem to be quite right, fails with sed: can't read s/IntPtr mem,/byte[] mem,/g: No such file or directory.
Solution, move the -i to the end (not sure if this works on macOS):

diff --git a/game/fnaUpdate.sh b/game/fnaUpdate.sh
index 57db48f..5be4d22 100755
--- a/game/fnaUpdate.sh
+++ b/game/fnaUpdate.sh
@@ -57,7 +57,7 @@ else
 	git clone --recursive git://github.com/FNA-XNA/FNA.git
 	cd FNA
 fi
-sed -i '' 's/IntPtr mem,/byte[] mem,/g' lib/SDL2-CS/src/SDL2.cs
+sed 's/IntPtr mem,/byte[] mem,/g' lib/SDL2-CS/src/SDL2.cs -i
 make release
 cd ..
 cp FNA/bin/Release/* .

Problem 2, getting the TouchInput exception ([ERROR] FATAL UNHANDLED EXCEPTION: System.TypeLoadException: Could not load type 'Microsoft.Xna.Framework.Input.Touch.TouchPanel' from assembly 'FNA, Version=20.6.0.0, Culture=neutral, PublicKeyToken=null'.).
Solution, apply guixxx's patch:

diff --git a/game/fnaUpdate.sh b/game/fnaUpdate.sh
index 5be4d22..99eb129 100755
--- a/game/fnaUpdate.sh
+++ b/game/fnaUpdate.sh
@@ -49,6 +49,7 @@ fi
 rm fnalibs.tar.bz2 # Wouldn't want to waste disk space, would we...
 
 # Download and build latest FNA
+curl -O https://gist.githubusercontent.com/guixxx/fb30995ba299fc24d67a9cd06b5e9046/raw/a9743bab74b7f8e747d74db51e4937409b00a886/fna-terraria.patch
 if [ -d "FNA" ]; then
 	cd FNA
 	git pull
@@ -58,6 +59,7 @@ else
 	cd FNA
 fi
 sed 's/IntPtr mem,/byte[] mem,/g' lib/SDL2-CS/src/SDL2.cs -i
+git apply ../fna-terraria.patch
 make release
 cd ..
 cp FNA/bin/Release/* .

Problem 3, the Mono segmentation fault (Got a SIGSEGV while executing native code.).
Solution, update the game binaries with flibitijibibo's MonoKickstart:

diff --git a/game/fnaUpdate.sh b/game/fnaUpdate.sh
index 99eb129..5d9e55c 100755
--- a/game/fnaUpdate.sh
+++ b/game/fnaUpdate.sh
@@ -64,5 +64,13 @@ make release
 cd ..
 cp FNA/bin/Release/* .
 
+if [ -d "MonoKickstart" ]; then
+	git -C MonoKickstart pull
+else
+	git clone https://github.com/flibitijibibo/MonoKickstart
+fi
+cp -v MonoKickstart/precompiled/* ./
+mv -v kick.bin.x86_64 ./Terraria.bin.x86_64
+
 # We out.
 echo Complete!
\ No newline at end of file

Problem 4, the SDL_RWFromMem crash (Exception: System.MissingMethodException: Method not found: intptr SDL2.SDL.SDL_RWFromMem(intptr,int)).

Solution: Delete the sed invocation altogether:

diff --git a/game/fnaUpdate.sh b/game/fnaUpdate.sh
index 5d9e55c..cc83aca 100755
--- a/game/fnaUpdate.sh
+++ b/game/fnaUpdate.sh
@@ -58,7 +58,6 @@ else
 	git clone --recursive git://github.com/FNA-XNA/FNA.git
 	cd FNA
 fi
-sed 's/IntPtr mem,/byte[] mem,/g' lib/SDL2-CS/src/SDL2.cs -i
 git apply ../fna-terraria.patch
 make release
 cd ..

Problem 5, Terraria now no longer crashes, but looks like this:


Solution: ??? Is this the end of the line?

@zauberparacelsus
Copy link

This doesn't seem to work with the steam version of tModLoader. When I try to start tModLoader (64bit), the game just crashes or something right away, so no game window comes up.

@Hirato
Copy link

Hirato commented Sep 9, 2020

I tried myself, managed to make it ingame and update it successfully.
There were a bunch of issues however...

  1. SDL_RWFromMem
    For this we need to make a second extern in SDL.cs
    I had this:

     /* mem refers to a void*, IntPtr to an SDL_RWops* */
     [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
     public static extern IntPtr SDL_RWFromMem(IntPtr mem, int size);
    
     /* mem refers to a void*, IntPtr to an SDL_RWops* */
     [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
     public static extern IntPtr SDL_RWFromMem(byte[] mem, int size);
    

This stems from an update for supporting SDL_image 2.0.2 over 3 years ago.

  1. Null deref in GLCallLocker
    This is a tmodloader thing - basically FNA 20.09 made some refactoring that split the graphics devices into a separate FNA3D library, so the last comaptible version is 20.08.
    tmodloader uses reflection to see and interact with some internal classes it really shouldn't as soon as the game starts.

  2. Black screen once ingame
    Not sure which one actually fixed it, but you need to compile mojoshader with some non-default flags set
    at the very least you should use -DBUILD_SHARED_LIBS='ON' -DDEPTH_CLIPPING='ON' -DFLIP_VIEWPORT='ON'
    It was probably FLIP_VIEWPORT, since the guide was going up the screen as I was flying up, rather than down.

  3. SDL init around touch and controllers
    Just delete the existing SDL and SDL_Image inside the lib64 folder, might help if you update that 'kickstart' thing too.

And with that, I was ingame with an updated FNA.
but alas, the Solar pillar still makes tmodloader blow up; I was hoping this whole foray would fix it, but it would seem I have no such luck, and will have to stick with the one it shipped with... maybe for 1.4...

@Tomsod
Copy link

Tomsod commented Oct 24, 2020

Problem 5, Terraria now no longer crashes, but looks like this:


Solution: ??? Is this the end of the line?

It's a bit off-topic, but I must thank you for providing an insight for my own problem. I've just updated from 1.4.0.5, and your screenshots are what Terraria 1.4.1.1 looks for me. Everything is flickering rectangles -- sprites, letters, cursor, everything. But now that I know it's an FNA issue, I was able to rid of this graphics glitch by downgrading FNA.dll to the one provided with 1.4.0.5, and the game seems to work fine. Not the most elegant solution, but I'll take whatever works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment