Fractal Softworks Forum

Please login or register.

Login with username, password and session length
Advanced search  

News:

Starsector 0.97a is out! (02/02/24); New blog post: Simulator Enhancements (03/13/24)

Author Topic: Converting Save Files Into Encounterable Fleets / IBB  (Read 3225 times)

Gorgonson

  • Ensign
  • *
  • Posts: 49
    • View Profile
Converting Save Files Into Encounterable Fleets / IBB
« on: April 10, 2016, 10:00:45 PM »

Hi All,

I've retired a few pilots.  They've seen their causes through to the end, or perhaps their sectors have become deadlocked and inhospitable.
I was wondering if there was any functionality to convert these save files into fleets that could appear in my future games, either associated with their commissioned faction, or as a fugitive posted on the IBB.  Are there any mods that do something similar, or are there settings or files I could modify in SS+ or Nexerelin to add this?

Thanks!
- G
Logged

xenoargh

  • Admiral
  • *****
  • Posts: 5078
  • naively breaking things!
    • View Profile
Re: Converting Save Files Into Encounterable Fleets / IBB
« Reply #1 on: April 11, 2016, 02:27:00 PM »

We could do this with a Java applet or application developed for the purpose.  But for it to be something that happens within the SS engine, we'd have to have file-writing permissions, etc., which would be potentially unsafe. 

I think this would be a very fun feature, personally-  SS could borrow from Reassembly's feature where you'd encounter fleets flown by other players, imo, so that you'd encounter crazy stuff occasionally.  But it's not a trivial thing and it's probably still too early to build a feature like that.
Logged
Please check out my SS projects :)
Xeno's Mod Pack

TJJ

  • Admiral
  • *****
  • Posts: 1905
    • View Profile
Re: Converting Save Files Into Encounterable Fleets / IBB
« Reply #2 on: April 12, 2016, 11:08:01 AM »

It might not be intended.... but we do actually have full I/O access atm.
You just have to contain all references to "java.io" within classes that are constructed via reflection. (and leapfrog the parent classloader that performs the security check)

Code
package org.tjj.starsector;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

import com.fs.starfarer.api.BaseModPlugin;
import com.fs.starfarer.api.Global;

public class IoTest extends com.fs.starfarer.api.BaseModPlugin {

private static Class fileIoClass;
private static Method readMethod;
private static Method writeMethod;

static {

byte[] fileIoClassBytes = new byte[] { -54, -2, -70, -66, 0, 0, 0, 50, 0, 49, 7, 0, 2, 1, 0, 29, 111, 114, 103,
47, 116, 106, 106, 47, 115, 116, 97, 114, 115, 101, 99, 116, 111, 114, 47, 70, 105, 108, 101, 73, 111,
73, 109, 112, 108, 7, 0, 4, 1, 0, 16, 106, 97, 118, 97, 47, 108, 97, 110, 103, 47, 79, 98, 106, 101, 99,
116, 1, 0, 6, 60, 105, 110, 105, 116, 62, 1, 0, 3, 40, 41, 86, 1, 0, 4, 67, 111, 100, 101, 10, 0, 3, 0,
9, 12, 0, 5, 0, 6, 1, 0, 15, 76, 105, 110, 101, 78, 117, 109, 98, 101, 114, 84, 97, 98, 108, 101, 1, 0,
18, 76, 111, 99, 97, 108, 86, 97, 114, 105, 97, 98, 108, 101, 84, 97, 98, 108, 101, 1, 0, 4, 116, 104,
105, 115, 1, 0, 31, 76, 111, 114, 103, 47, 116, 106, 106, 47, 115, 116, 97, 114, 115, 101, 99, 116, 111,
114, 47, 70, 105, 108, 101, 73, 111, 73, 109, 112, 108, 59, 1, 0, 4, 114, 101, 97, 100, 1, 0, 22, 40,
76, 106, 97, 118, 97, 47, 108, 97, 110, 103, 47, 83, 116, 114, 105, 110, 103, 59, 41, 91, 66, 7, 0, 17,
1, 0, 12, 106, 97, 118, 97, 47, 105, 111, 47, 70, 105, 108, 101, 10, 0, 16, 0, 19, 12, 0, 5, 0, 20, 1,
0, 21, 40, 76, 106, 97, 118, 97, 47, 108, 97, 110, 103, 47, 83, 116, 114, 105, 110, 103, 59, 41, 86, 10,
0, 16, 0, 22, 12, 0, 23, 0, 24, 1, 0, 6, 116, 111, 80, 97, 116, 104, 1, 0, 22, 40, 41, 76, 106, 97, 118,
97, 47, 110, 105, 111, 47, 102, 105, 108, 101, 47, 80, 97, 116, 104, 59, 10, 0, 26, 0, 28, 7, 0, 27, 1,
0, 19, 106, 97, 118, 97, 47, 110, 105, 111, 47, 102, 105, 108, 101, 47, 70, 105, 108, 101, 115, 12, 0,
29, 0, 30, 1, 0, 12, 114, 101, 97, 100, 65, 108, 108, 66, 121, 116, 101, 115, 1, 0, 24, 40, 76, 106, 97,
118, 97, 47, 110, 105, 111, 47, 102, 105, 108, 101, 47, 80, 97, 116, 104, 59, 41, 91, 66, 7, 0, 32, 1,
0, 19, 106, 97, 118, 97, 47, 105, 111, 47, 73, 79, 69, 120, 99, 101, 112, 116, 105, 111, 110, 1, 0, 4,
112, 97, 116, 104, 1, 0, 18, 76, 106, 97, 118, 97, 47, 108, 97, 110, 103, 47, 83, 116, 114, 105, 110,
103, 59, 1, 0, 1, 101, 1, 0, 21, 76, 106, 97, 118, 97, 47, 105, 111, 47, 73, 79, 69, 120, 99, 101, 112,
116, 105, 111, 110, 59, 1, 0, 13, 83, 116, 97, 99, 107, 77, 97, 112, 84, 97, 98, 108, 101, 1, 0, 5, 119,
114, 105, 116, 101, 1, 0, 23, 40, 76, 106, 97, 118, 97, 47, 108, 97, 110, 103, 47, 83, 116, 114, 105,
110, 103, 59, 91, 66, 41, 90, 7, 0, 41, 1, 0, 24, 106, 97, 118, 97, 47, 110, 105, 111, 47, 102, 105,
108, 101, 47, 79, 112, 101, 110, 79, 112, 116, 105, 111, 110, 10, 0, 26, 0, 43, 12, 0, 38, 0, 44, 1, 0,
71, 40, 76, 106, 97, 118, 97, 47, 110, 105, 111, 47, 102, 105, 108, 101, 47, 80, 97, 116, 104, 59, 91,
66, 91, 76, 106, 97, 118, 97, 47, 110, 105, 111, 47, 102, 105, 108, 101, 47, 79, 112, 101, 110, 79, 112,
116, 105, 111, 110, 59, 41, 76, 106, 97, 118, 97, 47, 110, 105, 111, 47, 102, 105, 108, 101, 47, 80, 97,
116, 104, 59, 1, 0, 1, 98, 1, 0, 2, 91, 66, 1, 0, 10, 83, 111, 117, 114, 99, 101, 70, 105, 108, 101, 1,
0, 15, 70, 105, 108, 101, 73, 111, 73, 109, 112, 108, 46, 106, 97, 118, 97, 0, 33, 0, 1, 0, 3, 0, 0, 0,
0, 0, 3, 0, 1, 0, 5, 0, 6, 0, 1, 0, 7, 0, 0, 0, 47, 0, 1, 0, 1, 0, 0, 0, 5, 42, -73, 0, 8, -79, 0, 0, 0,
2, 0, 10, 0, 0, 0, 6, 0, 1, 0, 0, 0, 7, 0, 11, 0, 0, 0, 12, 0, 1, 0, 0, 0, 5, 0, 12, 0, 13, 0, 0, 0, 9,
0, 14, 0, 15, 0, 1, 0, 7, 0, 0, 0, 98, 0, 3, 0, 2, 0, 0, 0, 18, -69, 0, 16, 89, 42, -73, 0, 18, -74, 0,
21, -72, 0, 25, -80, 76, 1, -80, 0, 1, 0, 0, 0, 14, 0, 15, 0, 31, 0, 3, 0, 10, 0, 0, 0, 14, 0, 3, 0, 0,
0, 11, 0, 15, 0, 12, 0, 16, 0, 13, 0, 11, 0, 0, 0, 22, 0, 2, 0, 0, 0, 18, 0, 33, 0, 34, 0, 0, 0, 16, 0,
2, 0, 35, 0, 36, 0, 1, 0, 37, 0, 0, 0, 6, 0, 1, 79, 7, 0, 31, 0, 9, 0, 38, 0, 39, 0, 1, 0, 7, 0, 0, 0,
119, 0, 3, 0, 3, 0, 0, 0, 25, -69, 0, 16, 89, 42, -73, 0, 18, -74, 0, 21, 43, 3, -67, 0, 40, -72, 0, 42,
87, 4, -84, 77, 3, -84, 0, 1, 0, 0, 0, 20, 0, 22, 0, 31, 0, 3, 0, 10, 0, 0, 0, 18, 0, 4, 0, 0, 0, 19, 0,
20, 0, 20, 0, 22, 0, 21, 0, 23, 0, 22, 0, 11, 0, 0, 0, 32, 0, 3, 0, 0, 0, 25, 0, 33, 0, 34, 0, 0, 0, 0,
0, 25, 0, 45, 0, 46, 0, 1, 0, 23, 0, 2, 0, 35, 0, 36, 0, 2, 0, 37, 0, 0, 0, 6, 0, 1, 86, 7, 0, 31, 0, 1,
0, 47, 0, 0, 0, 2, 0, 48 };

ClassLoader cl = IoTest.class.getClassLoader();

Class clc = ClassLoader.class;

java.lang.reflect.Method defineClass;
try {
defineClass = clc.getDeclaredMethod("defineClass", String.class, byte[].class, int.class, int.class);
} catch (NoSuchMethodException e) {
throw new RuntimeException("Failed finding defineClass", e);
} catch (SecurityException e) {
throw new RuntimeException("Failed finding defineClass", e);
}

defineClass.setAccessible(true);

try {
fileIoClass = (Class) defineClass.invoke(cl.getParent().getParent(), "org.tjj.starsector.FileIoImpl",
fileIoClassBytes, 0, fileIoClassBytes.length);

} catch (IllegalAccessException e) {
throw new RuntimeException("Failed definingClass", e);
} catch (IllegalArgumentException e) {
throw new RuntimeException("Failed definingClass", e);
} catch (java.lang.reflect.InvocationTargetException e) {
throw new RuntimeException("Failed definingClass", e);
}

try {
readMethod = fileIoClass.getDeclaredMethod("read", String.class);
writeMethod = fileIoClass.getDeclaredMethod("write", String.class, byte[].class);
} catch (NoSuchMethodException e) {
throw new RuntimeException("Failed finding io methods", e);
} catch (SecurityException e) {
throw new RuntimeException("Failed finding io methods", e);
}
}

public static byte[] read(String path) {
try {
return (byte[]) readMethod.invoke(null, path);
} catch (IllegalAccessException e) {
} catch (IllegalArgumentException e) {
} catch (InvocationTargetException e) {
}

return null;
}

public static boolean write(String path, byte[] b) {
try {
return (Boolean) writeMethod.invoke(null, path, b);
} catch (IllegalAccessException e) {
} catch (IllegalArgumentException e) {
} catch (InvocationTargetException e) {
}

return false;
}

public IoTest() {
if (write("Test.txt", "Yep, Sandbox bypassed".getBytes())) {
Global.getLogger(IoTest.class).info("Successfully written file");
}
}

}

The fileIoClassBytes byte[] is just the class below compiled, and then printed as bytes.

Code
package org.tjj.starsector;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;

public class FileIoImpl {

public static byte[] read(String path) {
try {
return Files.readAllBytes(new File(path).toPath());
} catch (IOException e) {
return null;
}
}

public static boolean write(String path, byte[] b) {
try {
Files.write(new File(path).toPath(), b);
return true;
} catch (IOException e) {
return false;
}
}

}

I was thinking of using this exploit as a means of creating an installer/uninstaller mod for SSME, so the SSME launch process could be identical to normal mods. (rather than having to launch from a separate shell script)

Back to the point; it's completely possible to implement what the OP is suggesting with nothing more than 'regular' modding ;D
« Last Edit: April 12, 2016, 11:32:07 AM by TJJ »
Logged

Wyvern

  • Admiral
  • *****
  • Posts: 3786
    • View Profile
Re: Converting Save Files Into Encounterable Fleets / IBB
« Reply #3 on: April 13, 2016, 11:58:27 AM »

It won't fully solve the problem, but I did a while back make a utility that allowed one to extract saved ship variants from a save file.  I posted it as an attachment rather than using any separate file sharing upload site, so it's long since been pruned from the forums, but if you think that would be useful functionality for you I can go see if I can dig the thing up.
Logged
Wyvern is 100% correct about the math.

xenoargh

  • Admiral
  • *****
  • Posts: 5078
  • naively breaking things!
    • View Profile
Re: Converting Save Files Into Encounterable Fleets / IBB
« Reply #4 on: April 13, 2016, 12:37:42 PM »

@TJJ:  LOL, I didn't suspect we could step around it that easily.  I'd sure like some form of limited IO for a few things.
Logged
Please check out my SS projects :)
Xeno's Mod Pack