Skip to content

Commit

Permalink
Fixed id issue with Mythril Clip in default data. Added in-battle sta…
Browse files Browse the repository at this point in the history
…tus, hp/mp update. Added status ailment display for both field and battle
  • Loading branch information
Shojy committed Oct 10, 2018
1 parent 8b4a6dd commit cbb5267
Show file tree
Hide file tree
Showing 40 changed files with 214 additions and 13,467 deletions.
2 changes: 1 addition & 1 deletion Tseng/Data/Default/weapons.json
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@
},

{
"Id": 4,
"Id": 48,
"Name": "Mythril Clip",
"Type": "Hairpin",
"LinkedSlots": 2,
Expand Down
1 change: 1 addition & 0 deletions Tseng/Models/Character.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@ public class Character
public Materia[] ArmletMateria { get; set; }
public bool BackRow { get; set; }
public string Status { get; set; } = "";
public string[] StatusEffects = new string[0];
}
}
1 change: 1 addition & 0 deletions Tseng/Models/Status.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ public class Status
public Character[] Party { get; set; }
public int Gil { get; set; }
public string Location { get; set; }
public bool ActiveBattle { get; set; }
}
}
77 changes: 77 additions & 0 deletions Tseng/Models/StatusEffect.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
using System;

namespace Tseng.Models
{
[Flags]
public enum StatusEffect:uint
{
None = 0x00000000,
Barrier = 0x00010000,
MBarrier = 0x00020000,
Reflect = 0x00040000,
Shield = 0x00100000,
DeathSentence = 0x00200000,
Manipulate = 0x00400000,
Berserk = 0x00800000,
Peerless = 0x01000000,
Paralyzed = 0x02000000,
Darkness = 0x04000000,

Death = 0x0001,
NearDeath = 0x0002,
Sleep = 0x0004,
Poison = 0x0008,
Sadness = 0x0010,
Fury = 0x0020,
Confusion = 0x0040,
Silence = 0x0080,
Haste = 0x0100,
Slow = 0x0200,
Stop = 0x0400,
Frog = 0x0800,
Small = 0x1000,
SlowNumb = 0x2000,
Petrify = 0x4000,
Regen = 0x8000,
}

/*
*
1111 0222
1st Part
0000 - None
0001 - Death
0002 - Near-death
0004 - Sleep
0008 - Poison
0010 - Sadness
0020 - Fury
0040 - Confusion
0080 - Silence
0100 - Haste
0200 - Slow
0400 - Stop
0800 - Frog
1000 - Small
2000 - Slow-numb
4000 - Petrify
8000 - Regen
FFFF - All Of The Above
2nd Part
000 - None
001 - Barrier
002 - MBarrier
004 - Reflect
010 - Shield
020 - Death-sentence
040 - Manipulate
080 - Berserk
100 - Peerless
200 - Paralyzed
400 - Darkness
7F7 - All Of The Above
*/
}
88 changes: 84 additions & 4 deletions Tseng/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,16 @@ public static void Main(string[] args)
StartServer(args);
}

public static Status ExtractStatusFromMap(FF7SaveMap map)
public static Status ExtractStatusFromMap(FF7SaveMap map, FF7BattleMap battleMap)
{
var status = new Status()
{
Gil = map.LiveGil,
Location = map.LiveMapName,
Party = new Character[3]
Party = new Character[3],
ActiveBattle = battleMap.IsActiveBattle
};
var party = battleMap.Party;

var chars = map.LiveParty;

Expand All @@ -65,7 +67,8 @@ public static Status ExtractStatusFromMap(FF7SaveMap map)
WeaponMateria = new Materia[8],
ArmletMateria = new Materia[8],
Face = GetFaceForCharacter(chars[i]),
BackRow = !chars[i].AtFront
BackRow = !chars[i].AtFront,

};

if ((chars[i].Flags & 0x10) == 0x10)
Expand All @@ -86,6 +89,21 @@ public static Status ExtractStatusFromMap(FF7SaveMap map)
chr.ArmletMateria[m] = MateriaDatabase.FirstOrDefault(x => x.Id == chars[i].ArmorMateria[m]);
}

var effect = (StatusEffect) chars[i].Flags;

if (battleMap.IsActiveBattle)
{
chr.CurrentHp = party[i].CurrentHp;
chr.MaxHp = party[i].MaxHp;
chr.CurrentMp = party[i].CurrentMp;
chr.MaxMp = party[i].MaxMp;
chr.Level = party[i].Level;
effect = party[i].Status;
}


chr.StatusEffects = effect.ToString()
.Split(new[] { ", " }, StringSplitOptions.RemoveEmptyEntries);
status.Party[i] = chr;
}

Expand Down Expand Up @@ -168,15 +186,23 @@ private static void StartMonitoringGame()
private static void Timer_Elapsed(object sender, ElapsedEventArgs e)
{
var bytes = MemoryReader.ReadMemory(new IntPtr(0xDBFD38), 4342);
var isBattle = MemoryReader.ReadMemory(new IntPtr(0x9A8AF8), 1).First();


var battle = MemoryReader.ReadMemory(new IntPtr(0x9AB0DC), 0x750);


//lock (SaveMap)
{
SaveMap = new FF7SaveMap(ref bytes);
BattleMap = new FF7BattleMap(ref battle, isBattle);
}

PartyStatus = ExtractStatusFromMap(SaveMap);
PartyStatus = ExtractStatusFromMap(SaveMap, BattleMap);
}

public static FF7BattleMap BattleMap { get; set; }

private static void LoadData()
{
var direInfo = new DirectoryInfo("Data");
Expand Down Expand Up @@ -306,4 +332,58 @@ private static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
.UseKestrel(opts => opts.ListenAnyIP(5000))
.UseStartup<Startup>();
}

public class FF7BattleMap
{
public FF7BattleMap(ref byte[] bytes, byte activeBattle)
{
IsActiveBattle = activeBattle == 0x01;
_map = bytes;
}

private byte[] _map;

public bool IsActiveBattle { get; set; }

private int _size = 0x68;
private int _charStart = 0x00;
private int _oppsStart = 0x01A0;

public struct Actor
{
public int CurrentHp { get; set; } // 0x2C
public int MaxHp { get; set; } // 0x30
public short CurrentMp { get; set; } // 0x28
public short MaxMp { get; set; } // 0x2A
public byte Level { get; set; } // 0x09
public StatusEffect Status { get; set; } // 0x??

}

public Actor[] Party => GetActors(_charStart, 3);
public Actor[] Opponents => GetActors(_oppsStart, 6);

private Actor[] GetActors(int start, int count)
{
var acts = new Actor[count];

for(var i = 0; i < count; ++i)
{
var offset = start + i * _size;
var a = new Actor
{
CurrentHp = BitConverter.ToInt32(_map, offset + 0x2C),
MaxHp = BitConverter.ToInt32(_map, offset + 0x30),
CurrentMp = BitConverter.ToInt16(_map, offset + 0x28),
MaxMp = BitConverter.ToInt16(_map, offset + 0x2A),
Level = _map[offset+0x09],
Status = (StatusEffect)BitConverter.ToUInt32(_map, offset + 0x00)
};
acts[i] = a;
}

return acts;
}

}
}
5 changes: 5 additions & 0 deletions Tseng/Tseng.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,9 @@
</Content>
</ItemGroup>

<ItemGroup>
<Folder Include="wwwroot\css\" />
<Folder Include="wwwroot\js\" />
</ItemGroup>

</Project>
50 changes: 43 additions & 7 deletions Tseng/Views/Home/Index.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,12 @@
color: #2ce8df !important;
}
.status {
color: #c71585;
:not(.dead) .status {
color: #c71585 !important;
}
.hp-low .current-hp {
color: #ffa500;
}
.slots {
Expand Down Expand Up @@ -146,6 +150,10 @@
visibility: hidden;
}
.status span {
display: none;
}
</style>


Expand Down Expand Up @@ -246,16 +254,19 @@


<script>
var charStatus = [];
charStatus.push([]);
charStatus.push([]);
charStatus.push([]);
var updateCharacters = function () {
$.getJSON("/Home/Data",
null,
function (data) {
console.log(data);
$('.gil').text(data.gil + ' Gil');
$('.location').text(data.location);
for (var i = 0; i < 3; ++i) {
var char = data.party[i];
var ch = $('.character:nth-child(' + (i + 1) + ')');
Expand Down Expand Up @@ -284,10 +295,15 @@
ch.find('.level').text(char.level);
ch.find('.current-hp').text(char.currentHp);
if (char.currentHp > 0 && char.currentHp < char.maxHp / 4) {
ch.addClass('hp-low');
} else {
ch.removeClass('hp-low');
}
ch.find('.max-hp').text(char.maxHp);
ch.find('.current-mp').text(char.currentMp);
ch.find('.max-mp').text(char.maxMp);
ch.find('.status').text(char.status.toUpperCase());
ch.find('.weapon')
.html(
'<img src="/images/weapon-'
Expand Down Expand Up @@ -358,6 +374,8 @@
slot.html('');
}
}
charStatus[i] = char.statusEffects;
}
})
Expand All @@ -373,9 +391,27 @@
setTimeout(cycleView, 5000);
};
var index = 0;
var cycleStatus = function() {
for (var i = 0; i < 3; ++i) {
if (charStatus[i].length == 0) {
$('.character:nth-child(' + (i + 1) + ') .status').html('');
} else {
$('.character:nth-child(' + (i + 1) + ') .status').html(charStatus[i][index % charStatus[i].length]);
}
}
++index;
if (index > 0 && index == charStatus[0].length * charStatus[1].length * charStatus[2].length) index = 0; // prevent overflowing
setTimeout(cycleStatus, 1000);
}
$(document).ready(function () {
updateCharacters();
setTimeout(cycleView, 5000);
cycleStatus();
});
</script>
12 changes: 2 additions & 10 deletions Tseng/Views/Shared/_Layout.cshtml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<html>

<head>
<title>Tseng v0.1-beta</title>
<title>Tseng v0.4-alpha</title>
<style>
body {
background: #000;
Expand Down Expand Up @@ -62,15 +62,7 @@
margin: 5px 0;
}
</style>
<environment names="Development">
<script src="~/lib/jquery/dist/jquery.js"></script>
</environment>
<environment names="Staging,Production">
<script src="https://ajax.aspnetcdn.com/ajax/jquery/jquery-2.1.4.min.js"
asp-fallback-src="~/lib/jquery/dist/jquery.min.js"
asp-fallback-test="window.jQuery">
</script>
</environment>
<script src="~/lib/jquery/dist/jquery.js"></script>

</head>

Expand Down
Loading

0 comments on commit cbb5267

Please sign in to comment.