Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Advertisement management without exe editing
#1
Since v2.0 is published, an advertisement function has been added. While it is usually treated as a nuisance, it can be modified to provide customized advertisement and external links.

Overview

Advertisement editing is a independent field of modification from exe editing, since it does not involve hex editing and using resource hacker. A common text editor and image editor are enough. The editing is solely done by modifying ad0.txt in data folder, and ad0.bmp in sprite/sys folder.

Note: ad1.txt is a "safe" copy of ad0.txt in the same folder, while ad1.bmp is safe copy of ad0.bmp. It is recommended to retain both safe files as backups at their original locations.

Via editing advertisement, you can change the links to desired website such as your homepage, game forum or wiki. You can change the graphics so they fit in your game. You can also feed information in the navigation panel just like vanilla LF2 using it to advertise.

P.S. There are _ad0.txt, _ad1.txt and _adinfo.txt in data folder. They are read by lf2.exe but should not be edited.

adinfo.txt dictates which adX.txt and adX.bmp is read. Refer to the adinfo.txt chapter for details.

ad0.bmp

Below is a modified ad0.bmp paired with a LF2 screen incorporated with the image. The A, B, C, D letters are added and rectangles are added to show area of reference:

[Image: rs9wApK.png]

The regions that ad0.bmp is referenced are shown with colored boundary and a number besides each of them:

1. Blinking banner on the top of screen

It uses two portions of image for blinking effect.

The external link and image can be edited, but currently no method is found to change interval of blinking.

2. Navigable panel on the right of screen

Four square image blocks on ad0.bmp are referenced to build the panel. The left/right arrows are not included in ad0.bmp but referenced from an image inside lf2.exe. You will need to use resource hacker to edit the arrows.

The yellow rectangle indicates the full area which ad0.bmp is referenced to build the panel. The letters A, B, C and D are added to indicate the positions of 4 unused slots which can be customized to show maximum of 8 panel blocks instead of the default 4.

The external link, image, probability of which image is showing when game starts, and how long will that advertisement will show until the panel retracts can be edited. There is also a gimmick that allows the default image to be blank.

3. External links at the bottom (and possibly the whole lower half) of screen

The external link, image and respective position of link can be modified. A maximum of 25 links can be placed via ba tag. All regions of links must be rectangle, also if it overlaps area of copyright claim on the bottom right corner of screen, the link provided by copyright claim will override a ba tag, therefore it's not useful to use a different url than copyright claim at its position, but you can still modify ad0.bmp to "erase" the existence of copyright claim, although you can still click it.

The green rectangle indicates the whole area which ad0.bmp is referenced for graphic for external links.

ad0.txt

A default ad0.txt (updated to last version of ads) should look like followed.

Code:
20140201 10 en
ba 0 422 132 32    ? bae
ba 132 422 132 32  ? bae
ba 264 422 132 32  ? bae
ba 396 422 132 32  ? bae
ba 528 422 132 32  ? bae
ba 660 422 132 32  ? bae
ba 0 454 132 32    ? bae
ba 132 454 132 32  ? bae
ba 264 454 132 32  ? bae
ba 396 454 132 32  ? bae
ba 528 454 132 32  ? bae
ba 660 454 132 32  ? bae
ba 0 486 132 32    ? bae
ba 132 486 132 32  ? bae
ba 264 486 132 32  ? bae
ba 396 486 132 32  ? bae
ba 528 486 132 32  ? bae
ba 660 486 132 32  ? bae
ba 0 518 462 32  http://www.ztage.com/ bae
ba 467 520 108 28  http://www.ztage.com/forum/ bae
ba 264 518 132 32  ? bae
ba 396 518 132 32  ? bae
ba 528 518 132 32  ? bae
ba 660 518 132 32  ? bae
ta 0 0 0 ? tae
ta 0 0 0 ? tae
ta 0 0 0 ? tae
ta 0 0 0 ? tae
ta 0 196 580 http://www.herofighter.com/?utm_source=lf2exe&utm_medium=cpm&utm_campaign=lf2exe tae
ta 196 198 580 http://www.littlefighter.com/figure_index.html tae
ta 198 400 580 http://www.phygame.com tae
ta 400 5800 3000 http://chickiebear.com tae
un 31 http://www.herofighter.com/?utm_source=lf2exe&utm_medium=cpm&utm_campaign=lf2exe une
y 0 100 ye
<end>

The file can be divided into 5 parts:

1. Beginning - informs about last update
2. ba tags - defines external links at the bottom (and possibly the whole lower half) of screen
3. ta tags - defines external links and appearance of the navigable panel on the right of screen
4. un tag - defines external link of blinking banner on the top of screen
5. y tag - defined vertical displacement of menu graphics and copyright claim

Beginning section

Beginning section consists of the very first line of ad0.txt:
Code:
20140201 10 en

The 8-digit number in form of YYYYMMDD indicates time of last update of advertisement system.
If the date is later than 20140201 (1 Feb, 2014), advertisement won't update because there is no patch afterwards.
To make it safe, set it to a far future time like 99991231.

The number and "en" afterwards are currently unknown of their use.

ba tags
ad0.txt consists of ba tags that define external links at the bottom half of the screen.

Although the links in vanilla LF2 are all at bottom of screen, they can be placed literally everywhere, but for convenience, I will explain how external link blocks work first.

The screen is composed of three parts: images stored in lf2.exe, images referenced from ad0.bmp and generated characters from exe code (copyright claim). As seen in the paired image, the lower rectangle covers the lower part of the screen which also blocks the upper half of copyright claim. The top of lower white rectangle indicates the upper boundary of advertisement you can place by modifying ad0.bmp. It does not mean you cannot place link blocks on the upper half, but doing so requires you to use resource hacker to replace menu images.

The link locations are managed by ad0.txt independent from ad0.bmp. As long as an appropriate image that indicates external link is placed, ad0.txt can be modified to suit the need.

Back to ba tags, they look like these:

Code:
ba 660 486 132 32  ? bae
ba 0 518 462 32  http://www.ztage.com/ bae

A ba tag starts with ba and ends with bae. It has 4 number and 1 url parameters.
The first two are x and y-axis top-left corner position of external tag, and last two are length and height of tag. The position is relative to the absolute top-left corner of the screen, not the top-left corner of green rectangle. The top-left corner of green rectangle is (0,422), which is also written on the first ba tag:

Code:
ba 0 422 132 32    ? bae

The url indicates the external link, it can instead be set to ? and disable the external link.

While the area of ba tags can overlap with each other, I have never tried on this and even so the indication that a tag is hovered on will always be a rectangle. Therefore it is better to make sure all tags do not have overlapped area. The default ad0.txt has already done this, you can enable the links and move cursor around the game screen to see how they are placed.

The position of "Advertisement:" wording above the external links is determined by the first two parameters of first enabled ba tag. It will always be above the intended position of this tag. The wording can only be edited via resource hacker, which is a better way than using ad0.txt to make it off screen, due to size limit of the wording in menu graphic inside lf2.exe.

There must be exactly 25 ba tags in ad0.txt, otherwise the whole ba tag system will fail. Make use of disabled tags (url is ?) to limit external link used.

ta tags

ta tags define external links of retractable panel at the right side of screen.

A ta tag has 3 number and 1 url parameters. The first two defines the probability of this particular advertisement being shown when game starts.

It appears the game reads the largest number out of all second parameters in ta tag (abbr maxta2nd) and rolls a rand() mod maxta2nd. If the number is between the first and second number of that ta tag, the starting advertisement will be that tag. (More precisely should be not less than first and less than second) If two or more tags are qualified to be shown, the first one in ad0.txt is always shown.

The third parameter indicates how long will the panel last before it retracts without mouse cursor moving over it. It is calculated in tick unit, that is 1/30s per frame. Therefore 30 is equivalent to 1 second. Putting it below 10 will cause the panel to glitch, quickly retracting and expanding repeatedly.

If a ta tag is disabled, the whole middle part of ad0.txt will still show all graphics in loading screen. However if the tag is disabled but forced to shown when game starts (details below) that portion of graphic will not show.

Important: All advertisement graphics will be shown in loading screen at the same time. This could become crowded if you use more than 4 panel images:
[Image: rIFcqzW.png]
The "Advertisement:" is automatically placed above the first active advertisement.

ta tags - in depth study

There are 8 ta tags but only the last 4 are typically used, the first 4 are disabled by default, but can be enabled which then use the blocks located at A, B, C and D in the paired image.

The tags can be modified to show blank image at the beginning. This requires disabling a tag despite increasing its appearance chance as much as possible.

Code:
ta 0 99999996 3000 ? tae
ta 99999996 99999997 580 http://www.herofighter.com/?utm_source=lf2exe&utm_medium=cpm&utm_campaign=lf2exe tae
ta 99999997 99999998 580 http://www.littlefighter.com/figure_index.html tae
ta 99999998 99999999 580 http://www.phygame.com tae

The first tag has 0 99999996 as probability parameter. It means it has 99999996/99999999 chance to shown when the game starts, but because it is disabled, when clicking on left/right arrow, it will not be navigable afterwards. Make sure that the disabled tag has first parameter equal to 0 so it will not fail to show blank slate.

To use all advertisement but to show blank image when game starts, put the first parameter to very high value instead. This will cause the image loading to (very probably) fail when game starts.

Code:
ta 99999996 99999997 580 http://www.herofighter.com/?utm_source=lf2exe&utm_medium=cpm&utm_campaign=lf2exe tae
ta 99999997 99999998 580 http://www.littlefighter.com/figure_index.html tae
ta 99999998 99999999 580 http://www.phygame.com tae
ta 99999995 99999999 3000 http://chickiebear.com tae

This can even be used to allow all eight advertisements to show when navigated, but show blank image at startup:
Code:
ta 99999991 99999992 90 http://1.org tae
ta 99999992 99999993 90 http://2.org tae
ta 99999993 99999994 90 http://3.org tae
ta 99999994 99999995 580 http:/41.org tae
ta 99999995 99999996 580 http://www.herofighter.com/?utm_source=lf2exe&utm_medium=cpm&utm_campaign=lf2exe tae
ta 99999996 99999997 580 http://www.littlefighter.com/figure_index.html tae
ta 99999997 99999998 580 http://www.phygame.com tae
ta 99999998 99999999 3000 http://chickiebear.com tae

Also note that you must make second parameter larger than first parameter to enable a tag.

un tag

un tag defines external link of blinking banner on the top of screen.

There is only one url parameter that is usable. The number parameter doesn't seem of any use, and it is recommended to leave it alone at 31, since if it is lower than 31, the banner will fail.

y tags

Credits to Silverthorn.

y tag has two number parameters. The second is the vertical displacement of copyright claim and the first is vertical displacement of all graphics excluding advertisement and copyright claim.

Both numbers are 0 by default. However, background image has top-left corner equivalent to top-left corner of screen (other graphics are arranged accordingly), while copyright claim is at bottom-right corner by default. Both numbers can be positive or negative, therefore copyright claim can be place out of screen, at center-right or top-right. Beware that putting -99 at any number in ad0.txt will result in a code break and prematurely end the file reading.

Unfortunately there is no tag to change x-axis position of either of them. Such x tag doesn't exist and attempting to add x tag will cause the whole advertisement system to fail.

adinfo.txt

Credits to Silverthorn.

adinfo.txt only contains a line, below is an example:

Code:
2018/11/08/19/06/46 0 10 <end>

The first date-like parameter is the last time lf2.exe has updated its advertisement, in form of YYYY/MM/DD/HH/MM/SS.

The second parameter dictates which adX.txt and adX.bmp is referenced. When the game starts, it checks if adX.bmp and adX.txt exists, where X is the second parameter. If either of them doesn't exist, they will be downloaded from the server.

Frequently asked questions
Q. What if I wanted to remove all advertisements altogether?
A. Replace all url in ad0.txt/ad1.txt with ?, and replace the whole ad0.bmp/ad1.bmp with a black (#000000) image of same size.

Q. Can I edit the copyright claim:
A. You cannot change the link even with ba tags. The only way to do this is to modify lf2.exe to change the link. However, I showed how to erase the claim visually, therefore you should be able to place other images onto it as well.

Q. Can I show an image in panel but not in loading screen, and the other way around:
A. You must make use of color masking to make images having same color as the loading screen to fool the players into believing nothing is shown in the screen. (Transparency is applied to #000000 pitch black, use it at your advantage) The other way is easy, just use resource editor to replace loading image.

Q. My game screen shows black blocks!
A. The lf2 graphics including ad0.bmp/ad1.bmp are compressed in optimized 256 color. Use an image editor to save it in RGB mode first, do your edits and then compress. Pay attention to the palette and the background color. Alternatively you can leave it alone at RGB, it doesn't bother much since modern computers loads the game at a whim.

Q. When I save ad0.bmp, it shows bad graphics! What should I do?
A. Refer to the last question, Microsoft paint has a bad habit to reset the palette if you save an optimized 256-color image into 256-color format again. Please make a copy in RGB first and compress once you have finished.

Q. I have edited and edited and nothing changed when I started the game!
A. Refer to adinfo.txt, find the second number which indicates which image will be used: 0 means ad0.txt and ad0.bmp will be used.

Q. There is no mirror images for ad0.bmp and ad1.bmp.
A. There is no need for the game to generate mirror images of advertisement.

Q. Can I make an advertisement not in a shape of rectangle?
A. Theoretically yes. You will need to align multiple ba tags for area of external link and also an image that fits will with the white rectangle bracket when cursor is hovered above it though.

Q. Does messing with advertisement make Marti unhappy?
A. You should not claim LF2 is owned and created by yourself. As a rule of thumb I retain a modified version of copyright claim in my LF2 version. Apart from this, please also support Marti and Starsky's new products.
Reply
Thanks given by: STM1993 , MangaD , Silverthorn
#2
(11-02-2018, 02:19 PM)rewlf2 Wrote:  y tags

The use of t tag is yet unknown.

Writing this up as I'm experimenting... tl;dr at the bottom.
  • In my copy of LF2, it's
    y 0 0 ye
    .
  • Position of the tags inside the exe are 4a088h for y and 4a084h for ye, respectively.
  • "data\ad0.txt" is stored at memory position 00453C68.
  • There are multiple procedures dealing with pushing ad0.txt and ad0.bmp onto the stack (5 in total, ranging from 0043c4a0 to 0043cf3a)
  • Tags of ad0.txt are parsed in the procedure starting at 0043c780. The formats for the individual tags are as follows (%d = integer, %s = string):
    - ba %d %d %d %d %s bae
    - ta %d %d %d %s tae
    - un %d %s une
    - y %d %d ye
  • the exe explicitly checks whether any of those numbers between y and ye equals -99.
  • if the first number equals -99, zeroes will be written to memory 45757c (location where the first number is stored) and 453da4 (location where the second number is stored) and the rest of the parsing (which is just looking for
    <end>
    ) is skipped. In other words, "-99" at the first position makes the exe ignore what's written between y and ye.
  • if the second number equals -99, the same will be done as with the first.
  • This behavior can actually be triggered with any number between any tag. As soon as the exe encounters a "-99", (irregardless of whether it's between ba/bae, ta/tae, un/une, or y/ye) makes it skip the rest of the file. See it as some sort of preliminary "return".
  • Back to y/ye, the exe pushes 500 (decimal) onto the stack together with "y 42 7 ye\n" (42 and 7 are my test-numbers) and runs the procedure MSVCR80.7399A00Dh (is also called with the other tags, some sort of magic going on there)
  • At this point, I'm giving up on disassembling the exe and just go over to brute force. Turns out, the first number shifts the character-image (Bat in your screenshot), menu sprites, and right ads along the y-axis (positive numbers = downwards, negative = upwards).
  • For a change, LF2 seems to be fault-tolerant (or rather, the external libraries); replacing the numbers with letters replicates the behavior of entering "0 0".
  • The second number moves the credit-lines
  • y-values in ad1.txt override those of ad0.txt. Setting the first number in ad0 to something like -77 and in ad1 to 77 will shift the content downwards by 77px.
  • correction: adinfo.txt dictates which adX.txt should be taken.
  • txt update comes from http://www.littlefighter.com/_ad/ad.php. bmp update from http://www.lf2.net/_ad/ad%s.bmp (not feeling criminal enough to figure out what %s is set to).




tl;dr-version
  • Code:
    y <vertical shift of character-bg-img, menu sprites, right ads> <vertical shift of credits-lines> ye
    shift corresponds to positive numbers going downwards.
  • a "-99" instead of any other number makes the exe skip the rest of the file. Replace the very first one (20140201, according to the last update) with it and enjoy an adfree LF2 :p As some sort of official person of a fansite dedicated to LF2, I have never said this and you have never read this :)
  • adinfo.txt dictates which adX.txt file should be taken. Refer to the second number in the file to find out.

    Tested in vanilla LF2 2.0a.
Silverthorn
~ Breaking LFE since 2008 ~


» Gallery | » Sprites | » devArt
Reply
Thanks given by: rewlf2 , STM1993
#3
y tag behavior confirmed.

adinfo.txt behaviour also confirmed, and I should add some findings.
Reply
Thanks given by:




Users browsing this thread: 1 Guest(s)