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

Add CMyFont #349

Merged
merged 4 commits into from
Dec 22, 2024
Merged
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
1 change: 1 addition & 0 deletions config/ghidra_ns_to_obj.csv
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ AsciiManager,th06::AsciiManager,th06::StageMenu
BombData,th06::BombData
BulletManager,th06::BulletManager
Chain,th06::Chain,th06::ChainElem
CMyFont,th06::CMyFont
Controller,th06::Controller
EclManager,th06::EclManager
EffectManager,th06::EffectManager
Expand Down
1 change: 1 addition & 0 deletions config/globals.csv
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ _g_NumOfFramesInputsWereHeld, 0x0069d910
_g_LastFileSize, 0x0069d914
_g_Chain, 0x0069d918
_g_GameErrorContext, 0x0069d998
_g_CMyFont, 0x0069e1a0
_g_ControllerData, 0x0069e1af
_g_TextBufferSurface, 0x0069e230
_g_ItemManager, 0x0069e268
Expand Down
3 changes: 3 additions & 0 deletions config/implemented.csv
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ th06::Chain::RunDrawChain
th06::Chain::RunCalcChain
th06::Chain::AddToCalcChain
th06::Chain::AddToDrawChain
th06::CMyFont::Init
th06::CMyFont::Print
th06::CMyFont::Clean
th06::GameWindow::InitD3dInterface
th06::Controller::GetJoystickCaps
th06::Controller::SetButtonFromControllerInputs
Expand Down
6 changes: 3 additions & 3 deletions config/mapping.csv
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,9 @@ th06::Controller::SetButtonFromControllerInputs,0x41d600,0x75,__stdcall,,unsigne
th06::Controller::GetControllerState,0x41d680,0x19e,default,,u8*
th06::Controller::GetInput,0x41d820,0x894,__stdcall,,u16
th06::Controller::ResetKeyboard,0x41e0c0,0x85,default,,void
FUN_0041e150,0x41e150,0xc0,unknown,,u8,u32,u32,u32
FUN_0041e210,0x41e210,0x4b,unknown,,u8,u32,u32,u32,u32
CDocObjectServer::ReleaseDocSite,0x41e260,0x30,__thiscall,,void,CDocObjectServer*
th06::CMyFont::Init,0x41e150,0xc0,__thiscall,,void,CMyFont*,IDirect3DDevice8*,i32,i32
th06::CMyFont::Print,0x41e210,0x4b,__thiscall,,void,CMyFont*,char*,i32,i32,unsigned long
th06::CMyFont::Clean,0x41e260,0x30,__thiscall,,void,CMyFont*
th06::FileSystem::OpenPath,0x41e290,0x1c8,__stdcall,,u8*,char*,i32
th06::FileSystem::WriteDataToFile,0x41e460,0x63,__stdcall,,i32,char*,void*,u32
th06::GameErrorContext::Log,0x41e4d0,0x14b,__stdcall,varargs,char*,GameErrorContext*,char*
Expand Down
8 changes: 8 additions & 0 deletions objdiff.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,14 @@

"reverse_fn_order": false
},
{
"name": "CMyFont",

"target_path": "build/objdiff/orig/CMyFont.obj",
"base_path": "build/objdiff/reimpl/CMyFont.obj",

"reverse_fn_order": false
},
{
"name": "Controller",

Expand Down
1 change: 1 addition & 0 deletions scripts/configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ def configure(build_type):
"GameManager",
"Chain",
"Controller",
"CMyFont",
roblabla marked this conversation as resolved.
Show resolved Hide resolved
"FileSystem",
"GameErrorContext",
"Rng",
Expand Down
54 changes: 54 additions & 0 deletions src/CMyFont.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// ----------------------------------------------------------------------------
//
// font.cpp - フォント描画部分
//
// Copyright (c) 2001 if ([email protected])
// All Rights Reserved.
//
// ----------------------------------------------------------------------------

#include "CMyFont.hpp"
#include "GameWindow.hpp"
#include "i18n.hpp"
#include <d3d8.h>

namespace th06
{

void CMyFont::Init(LPDIRECT3DDEVICE8 lpD3DDEV, int w, int h)
{
HDC hTextDC = NULL;
HFONT hFont = NULL, hOldFont = NULL;

hTextDC = CreateCompatibleDC(NULL);
hFont = CreateFont(h, w, 0, 0, FW_REGULAR, FALSE, FALSE, FALSE, SHIFTJIS_CHARSET, OUT_DEFAULT_PRECIS,
CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH, TH_FONT_NAME);
if (!hFont)
return;
hOldFont = (HFONT)SelectObject(hTextDC, hFont);

if (FAILED(D3DXCreateFont(lpD3DDEV, hFont, &m_lpFont)))
{
MessageBox(0, "D3DXCreateFontIndirect FALSE", "ok", MB_OK);
return;
}
SelectObject(hTextDC, hOldFont);
DeleteObject(hFont);
}
// ----------------------------------------------------------------------------
void CMyFont::Print(char *str, int x, int y, D3DCOLOR color)
{
RECT rect;
rect.left = x;
rect.right = GAME_WINDOW_WIDTH;
rect.top = y;
rect.bottom = GAME_WINDOW_HEIGHT;

m_lpFont->DrawText(str, -1, &rect, DT_LEFT | DT_EXPANDTABS, color);
}
// ----------------------------------------------------------------------------
void CMyFont::Clean()
{
RELEASE(m_lpFont);
}
} // namespace th06
39 changes: 39 additions & 0 deletions src/CMyFont.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// ----------------------------------------------------------------------------
//
// font.h - 文字表示
//
// Copyright (c) 2001 if ([email protected])
// All Rights Reserved.
//
// ----------------------------------------------------------------------------
#pragma once

#include <d3d8.h>
#include <d3dx8.h>

namespace th06
{

#define RELEASE(o) \
if (o) \
{ \
o->Release(); \
o = NULL; \
}

class CMyFont
{
private:
LPD3DXFONT m_lpFont;

public:
CMyFont()
{
m_lpFont = NULL;
};
virtual void Init(LPDIRECT3DDEVICE8 lpD3DDEV, int w, int h);
virtual void Print(char *str, int x, int y, D3DCOLOR color = 0xffffffff);
virtual void Clean();
};

} // namespace th06
2 changes: 2 additions & 0 deletions src/GameErrorContext.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
#include <windows.h>

#include "CMyFont.hpp"
#include "GameErrorContext.hpp"
#include <stdio.h>

namespace th06
{
DIFFABLE_STATIC(GameErrorContext, g_GameErrorContext)
DIFFABLE_STATIC(CMyFont, g_CMyFont)

const char *GameErrorContext::Log(GameErrorContext *ctx, const char *fmt, ...)
{
Expand Down