Skip to content

@emd4600 emd4600 released this Jul 13, 2019 · 5 commits to master since this release

Easier detouring (CppRevEng)

I've integrated my new reverse engineering library, CppRevEng into the SDK. This makes detouring easier than ever. An example:

member_detour(RenderType_detour, App::cViewer, void(int, bool)) {
	void detoured(int renderType, bool arg1) 
	{
		if (renderType == 0xF) {
			// When the game tries to use hologram, use the default render type instead
			original_function(this, 0, arg1);
		}
		else {
			original_function(this, renderType, arg1);
		}
	}
};

// In DllMain
PrepareDetours(hModule);
RenderType_detour::attach(GetAddress(App::cViewer, SetRenderType));
CommitDetours();

Editor requests

Now it's possible to enter an Editor from the code. You do so using the new Editors::EditorRequest class.

More information here.

intrusive_ptr<EditorRequest> request = new EditorRequest();
request->editorID = id("CreatureEditorExtraLarge");
request->allowSporepedia = true;
request->hasSaveButton = true;

EditorRequest::Submit(request.get());

Sporepedia requests

Now it's possible to show the Sporepedia to the player, requesting them to pick a creation. This is done using the new Sporepedia::ShopperRequest class.

More information here.

// `this` can also be whatever object that inherits from IShopperListener
Sporepedia::ShopperRequest request(this);
request.SetShopperID(id("MilitaryAirShopper"));

Simulator changes

The GetData method now also accepts subclasses. For example, you can use GetData<cCombatant>() to get all combatants (creatures, vehicles, buildings, etc). More information here.

There are also some new, useful methods:

  • PlanetModel::GetOrientation gives you the correct orientation an object must have to lay on the surface of the planet.
  • cCity::SpawnVehicle spawns a vehicle next to the given city. This is the same that the buttons do in the Civilization stage.
  • SpaceTeleportTo instantly moves the player UFO into the given planet.

GameBehaviorManager

There's also a new class, the GameBehaviorManager used to (presumably?) enable AI in Simulator objects. Or at least avoid crashes.

Graphics & Shaders

A new feature has been integrated into the graphics system: the shader load method. That's a method specific to every shader, that is executed just before any object that uses it is rendered. Now with the SDK you can replace it to load whatever you need in your shader, such as a custom generated texture.

This example makes the shader use a special texture, which shows what is currently being displayed on the screen.

BOOL LoadTvShader(RenderWare::Mesh<>* mesh)
{
	// Apparently 0x15 is used for the main render target?
	Graphics::RTT* rtt = Graphics::RenderTargetManager()->GetRTT(0x15);
	if (rtt) {
		Graphics::Renderer::SetTexture(0, rtt);
	}

	return Graphics::StandardShader::Load(mesh);
}

void ReplaceTvMaterial() {
	auto material = Graphics::MaterialManager()->GetMaterial(id("TVScreen_MainColorRTT"));
	if (material) {
		auto shader = material->states[0]->pMaterialShader;
		shader->SetLoadMethod(&LoadTvShader);
	}
}

// In your initialization function
// This adds a listener to know when initialization has finished
App::MessageManager()->AddListener([](uint32_t messageID, void* data) 
{
	ReplaceTvMaterial();
	return true;
}, { App::kMsgAppInitialized });
Assets 3
You can’t perform that action at this time.