Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(life-index): Displays stress, fatigue, and life index #19

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 70 additions & 1 deletion MRDX.Base.Mod.Interfaces/Definitions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Runtime.InteropServices;

namespace MRDX.Base.Mod.Interfaces;

Expand Down Expand Up @@ -283,4 +284,72 @@ public enum ErrantyType : byte
Withering,
Skill,
Special
}
}

[StructLayout(LayoutKind.Explicit)]
public struct Box
{
[FieldOffset(0x0)]
public nint Next;

[FieldOffset(0x4)]
public nint Previous;

[FieldOffset(0x8)]
public nint Attribute;

[FieldOffset(0xC)]
public short XCopy;

[FieldOffset(0xE)]
public short YCopy;

[FieldOffset(0x10)]
public short X;

[FieldOffset(0x12)]
public short Y;

[FieldOffset(0x1E)]
public short Z;

[FieldOffset(0x2C)]
public short XOffset;

[FieldOffset(0x2E)]
public short YOffset;

[FieldOffset(0x40)]
public int unk1;

[FieldOffset(0x44)]
public int unk2;

[FieldOffset(0x48)]
public int unk3;
}

[StructLayout(LayoutKind.Explicit)]
public struct BoxAttribute
{
[FieldOffset(0x0)]
public byte unk1;

[FieldOffset(0x10)]
public ushort Width;

[FieldOffset(0x12)]
public ushort Height;

[FieldOffset(0x14)]
public byte R;

[FieldOffset(0x15)]
public byte G;

[FieldOffset(0x16)]
public byte B;

[FieldOffset(0x17)]
public byte IsSemiTransparent;
}
18 changes: 18 additions & 0 deletions MRDX.Base.Mod.Interfaces/IHooks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,24 @@ namespace MRDX.Base.Mod.Interfaces;
[Function(CallingConventions.Fastcall)]
public delegate int DrawIntWithHorizontalSpacing(short x, short y, int number);

[HookDef(BaseGame.Mr2, Region.Us, "55 8B EC 83 E4 F8 56 57 8B 7D 08 6A 03")]
[Function(CallingConventions.Cdecl)]
public delegate int DrawLoyalty(nint unk1);

[HookDef(BaseGame.Mr2, Region.Us, "55 8B EC 83 E4 F8 81 EC ?? ?? ?? ?? A1 ?? ?? ?? ?? 33 C4 89 84 24 ?? ?? ?? ?? 53 56 8B 75 08 8D 44 24 14")]
[Function(CallingConventions.Fastcall)]
public delegate int DrawTextWithPadding(short x, short y, nint text, short padding);

// Function that is called every tick while you're in the farm.
// Hooking this causes various UI elements in the Farm to not function for some reason.
[HookDef(BaseGame.Mr2, Region.Us, "55 8B EC 6A FF 68 ?? ?? ?? ?? 64 A1 ?? ?? ?? ?? 50 53 56 57 A1 ?? ?? ?? ?? 33 C5 50 8D 45 F4 64 A3 ?? ?? ?? ?? 8B 75 08 8B 7D 10 F6 46 0C 03 0F 84")]
[Function(CallingConventions.Cdecl)]
public delegate void DrawFarmUiElements(nint unk1, nint unk2, nint unk3);

[HookDef(BaseGame.Mr2, Region.Us, "80 79 38 01 75 38")]
[Function(CallingConventions.MicrosoftThiscall)]
public delegate void RemovesSomeUiElements(nint self);

/**
* Called when setting up the battle controls. CCtrlBattle seems to store things like the battle timer among other things.
* Its heap allocated so we can't just use a fixed memory address.
Expand Down
18 changes: 12 additions & 6 deletions MRDX.Base.Mod/BaseObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,7 @@ protected BaseObject(int baseOffset = 0)

// If no base is provided, check the class for the offset attribute for static memory locations
if (baseOffset == 0)
foreach (var offset in typeof(TParent).GetCustomAttributes().OfType<BaseOffsetAttribute>())
{
if (offset.Game != Base.Game || offset.Region != Base.Region) continue;
baseOffset = offset.Offset;
break;
}
baseOffset = BaseOffset();

BaseAddress = Base.ExeBaseAddress + baseOffset;

Expand Down Expand Up @@ -217,6 +212,17 @@ protected void WriteStrOffset(string val, int offset)
_memory.WriteRaw((nuint)(BaseAddress + offset), bytes);
}

public static int BaseOffset()
{
foreach (var offset in typeof(TParent).GetCustomAttributes().OfType<BaseOffsetAttribute>())
{
if (offset.Game != Base.Game || offset.Region != Base.Region) continue;
return offset.Offset;
}

return 0;
}


public static int Get([CallerMemberName] string propName = "")
{
Expand Down
2 changes: 1 addition & 1 deletion MRDX.Base.Mod/Game.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public Game(ModContext context)
}

[BaseOffset(BaseGame.Mr2, Region.Us, 0x97A0C)]
public IMonster Monster { get; set; } = new Monster(Get());
public IMonster Monster { get; set; } = new Monster(Get() + BaseObject<Monster>.BaseOffset());

public event IGame.MonsterChange? OnMonsterChanged;

Expand Down
149 changes: 149 additions & 0 deletions MRDX.Ui.ViewLifeIndex/.github/workflows/reloaded.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
# Script to build and publish a Reloaded Mod.
# by Sewer56

# Produces:
# - Build to Upload to GameBanana
# - Build to Upload to GitHub
# - Build to Upload to NuGet
# - Changelog

# When pushing a tag
# - Upload to GitHub Releases
# - Upload to Reloaded NuGet Repository (if GitHub Secret RELOADED_NUGET_KEY is specified)

name: Build and Publish Reloaded Mod

on:
push:
branches: [ main ]
tags:
- '*'
pull_request:
branches: [ main ]
workflow_dispatch:

env:
PUBLISH_COMMON_PATH: ./Publish/ToUpload/

PUBLISH_GAMEBANANA_PATH: ./Publish/ToUpload/GameBanana
PUBLISH_GITHUB_PATH: ./Publish/ToUpload/Generic
PUBLISH_NUGET_PATH: ./Publish/ToUpload/NuGet

PUBLISH_CHANGELOG_PATH: ./Publish/Changelog.md
PUBLISH_PATH: ./Publish

RELOADEDIIMODS: .

# Default value is official Reloaded package server.
NUGET_URL: http://packages.sewer56.moe:5000/v3/index.json

IS_RELEASE: ${{ startsWith(github.ref, 'refs/tags/') }}
RELEASE_TAG: ${{ github.ref_name }}

jobs:
build:
runs-on: windows-latest
defaults:
run:
shell: pwsh

steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
submodules: 'recursive'

- name: Setup .NET Core SDK (5.0)
uses: actions/[email protected]
with:
dotnet-version: 5.0.x

- name: Setup .NET Core SDK (6.0)
uses: actions/[email protected]
with:
dotnet-version: 6.0.x

- name: Setup Node.js
uses: actions/setup-node@v2
with:
node-version: '14'

- name: Setup AutoChangelog
run: npm install -g auto-changelog

- name: Create Changelog
run: |
[System.IO.Directory]::CreateDirectory("$env:PUBLISH_PATH")
if ($env:IS_RELEASE -eq 'true') {
auto-changelog --sort-commits date --hide-credit --template keepachangelog --commit-limit false --starting-version "$env:RELEASE_TAG" --output "$env:PUBLISH_CHANGELOG_PATH"
}
else {
auto-changelog --sort-commits date --hide-credit --template keepachangelog --commit-limit false --unreleased --output "$env:PUBLISH_CHANGELOG_PATH"
}

- name: Build
run: ./Publish.ps1 -ChangelogPath "$env:PUBLISH_CHANGELOG_PATH"

- name: Upload GitHub Release Artifact
uses: actions/[email protected]
with:
# Artifact name
name: GitHub Release
# A file, directory or wildcard pattern that describes what to upload
path: |
${{ env.PUBLISH_GITHUB_PATH }}/*

- name: Upload GameBanana Release Artifact
uses: actions/[email protected]
with:
# Artifact name
name: GameBanana Release
# A file, directory or wildcard pattern that describes what to upload
path: |
${{ env.PUBLISH_GAMEBANANA_PATH }}/*

- name: Upload NuGet Release Artifact
uses: actions/[email protected]
with:
# Artifact name
name: NuGet Release
# A file, directory or wildcard pattern that describes what to upload
path: |
${{ env.PUBLISH_NUGET_PATH }}/*

- name: Upload Changelog Artifact
uses: actions/[email protected]
with:
# Artifact name
name: Changelog
# A file, directory or wildcard pattern that describes what to upload
path: ${{ env.PUBLISH_CHANGELOG_PATH }}
retention-days: 0

- name: Upload to GitHub Releases (on Tag)
uses: softprops/[email protected]
if: env.IS_RELEASE == 'true'
with:
# Path to load note-worthy description of changes in release from
body_path: ${{ env.PUBLISH_CHANGELOG_PATH }}
# Newline-delimited list of path globs for asset files to upload
files: |
${{ env.PUBLISH_GITHUB_PATH }}/*

- name: Push to NuGet (on Tag)
env:
NUGET_KEY: ${{ secrets.RELOADED_NUGET_KEY }}
if: env.IS_RELEASE == 'true'
run: |
if ([string]::IsNullOrEmpty("$env:NUGET_KEY"))
{
Write-Host "NuGet Repository Key (GitHub Secrets -> RELOADED_NUGET_KEY) Not Specified. Skipping."
return
}

$items = Get-ChildItem -Path "$env:PUBLISH_NUGET_PATH/*.nupkg"
Foreach ($item in $items)
{
Write-Host "Pushing $item"
dotnet nuget push "$item" -k "$env:NUGET_KEY" -s "$env:NUGET_URL" --skip-duplicate
}
9 changes: 9 additions & 0 deletions MRDX.Ui.ViewLifeIndex/BuildLinked.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Set Working Directory
Split-Path $MyInvocation.MyCommand.Path | Push-Location
[Environment]::CurrentDirectory = $PWD

Remove-Item "$env:RELOADEDIIMODS/MRDX.Ui.ViewLifeIndex/*" -Force -Recurse
dotnet publish "./MRDX.Ui.ViewLifeIndex.csproj" -c Release -o "$env:RELOADEDIIMODS/MRDX.Ui.ViewLifeIndex" /p:OutputPath="./bin/Release" /p:ReloadedILLink="true"

# Restore Working Directory
Pop-Location
55 changes: 55 additions & 0 deletions MRDX.Ui.ViewLifeIndex/MRDX.Ui.ViewLifeIndex.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0-windows</TargetFramework>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
<LangVersion>10.0</LangVersion>
<Nullable>enable</Nullable>
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
<OutputPath>$(RELOADEDIIMODS)/MRDX.Ui.ViewLifeIndex</OutputPath>
<ImplicitUsings>enable</ImplicitUsings>

<!-- IL Trimming Support for Framework Dependent Apps. Unofficial.
If you set this to true, trimming will be enabled when you publish the mod.
Test trimming with: `BuildLinked.ps1` in PowerShell. -->
<ReloadedILLink>false</ReloadedILLink>
</PropertyGroup>

<ItemGroup>
<ReloadedLinkRoots Include="MRDX.Ui.ViewLifeIndex" />
<!-- Add assemblies to be trimmed. You might need to add their dependencies too! -->
<!-- <ReloadedLinkAssemblies Include="Reloaded.Memory" /> -->
</ItemGroup>

<Import Project="Reloaded.Trimming.targets" />
<Import Project="Reloaded.Checks.targets" />

<ItemGroup>
<None Remove="ModConfig.json" />
<None Remove="Publish.ps1" />
<None Remove="BuildLinked.ps1" />
<None Remove="Reloaded.Trimming.targets" />
<None Remove="Reloaded.Checks.targets" />
</ItemGroup>

<ItemGroup>
<Content Include="ModConfig.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<None Update="Preview.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>

<ItemGroup>
<PackageReference Include="Reloaded.Mod.Interfaces" Version="2.4.0" ExcludeAssets="runtime" />
<PackageReference Include="Reloaded.SharedLib.Hooks" Version="1.9.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\MRDX.Base.Mod.Interfaces\MRDX.Base.Mod.Interfaces.csproj" />
<ProjectReference Include="..\MRDX.Base.Mod\MRDX.Base.Mod.csproj" />
</ItemGroup>

</Project>
Loading
Loading